AddPredecessorToBlock(FalseDest, PredBlock, BB);
PBI->setSuccessor(1, FalseDest);
}
- return SimplifyCFG(PBI->getParent()) | true;
+ return true;
}
return false;
}
BasicBlock *BB = BI->getParent();
+ DEBUG(dbgs() << "CONVERTING 'icmp' CHAIN with " << Values.size()
+ << " cases into SWITCH. BB is:\n" << *BB);
+
// If there are any extra values that couldn't be folded into the switch
// then we evaluate them with an explicit branch first. Split the block
// right before the condbr to handle it.
if (ExtraCase) {
- return false;
+ DEBUG(dbgs() << " ** 'icmp' chain unhandled condition: " << *ExtraCase
+ << '\n');
BasicBlock *NewBB = BB->splitBasicBlock(BI, "switch.early.test");
// Remove the uncond branch added to the old block.
TerminatorInst *OldTI = BB->getTerminator();
- BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI);
+ if (TrueWhenEqual)
+ BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI);
+ else
+ BranchInst::Create(NewBB, EdgeBB, ExtraCase, OldTI);
+
OldTI->eraseFromParent();
// If there are PHI nodes in EdgeBB, then we need to add a new entry to them
// Erase the old branch instruction.
EraseTerminatorInstAndDCECond(BI);
+
return true;
}
if (BI->isUnconditional()) {
if (SimplifyUncondBranch(BI)) return true;
} else {
- if (SimplifyCondBranch(BI))
- return true;
+ if (SimplifyCondBranch(BI)) return true;
}
} else if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
if (SimplifyReturn(RI)) return true;
; RUN: opt < %s -simplifycfg -S | FileCheck %s
-; XFAIL: *
declare void @foo1()
; HECK: %cmp = icmp ult i8 %c, 33
; HECK: br i1 %cmp, label %lor.end, label %switch.early.test
-; HECK: switch.early.test:
+; CHECK: switch.early.test:
; HECK: switch i8 %c, label %lor.rhs [
; HECK: i8 46, label %lor.end
; HECK: i8 44, label %lor.end