reapply my recent change that disables a piece of the switch formation

work, but fixes 400.perlbmk.

llvm-svn: 121749
This commit is contained in:
Chris Lattner 2010-12-14 05:57:30 +00:00
parent 72eff18ae4
commit 5a9d59d918
2 changed files with 14 additions and 7 deletions

View File

@ -1515,7 +1515,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
AddPredecessorToBlock(FalseDest, PredBlock, BB); AddPredecessorToBlock(FalseDest, PredBlock, BB);
PBI->setSuccessor(1, FalseDest); PBI->setSuccessor(1, FalseDest);
} }
return SimplifyCFG(PBI->getParent()) | true; return true;
} }
return false; return false;
} }
@ -1905,17 +1905,25 @@ static bool SimplifyBranchOnICmpChain(BranchInst *BI, const TargetData *TD) {
BasicBlock *BB = BI->getParent(); 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 // 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 // then we evaluate them with an explicit branch first. Split the block
// right before the condbr to handle it. // right before the condbr to handle it.
if (ExtraCase) { if (ExtraCase) {
return false; DEBUG(dbgs() << " ** 'icmp' chain unhandled condition: " << *ExtraCase
<< '\n');
BasicBlock *NewBB = BB->splitBasicBlock(BI, "switch.early.test"); BasicBlock *NewBB = BB->splitBasicBlock(BI, "switch.early.test");
// Remove the uncond branch added to the old block. // Remove the uncond branch added to the old block.
TerminatorInst *OldTI = BB->getTerminator(); 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(); OldTI->eraseFromParent();
// If there are PHI nodes in EdgeBB, then we need to add a new entry to them // If there are PHI nodes in EdgeBB, then we need to add a new entry to them
@ -1955,6 +1963,7 @@ static bool SimplifyBranchOnICmpChain(BranchInst *BI, const TargetData *TD) {
// Erase the old branch instruction. // Erase the old branch instruction.
EraseTerminatorInstAndDCECond(BI); EraseTerminatorInstAndDCECond(BI);
return true; return true;
} }
@ -2410,8 +2419,7 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
if (BI->isUnconditional()) { if (BI->isUnconditional()) {
if (SimplifyUncondBranch(BI)) return true; if (SimplifyUncondBranch(BI)) return true;
} else { } else {
if (SimplifyCondBranch(BI)) if (SimplifyCondBranch(BI)) return true;
return true;
} }
} else if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { } else if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
if (SimplifyReturn(RI)) return true; if (SimplifyReturn(RI)) return true;

View File

@ -1,5 +1,4 @@
; RUN: opt < %s -simplifycfg -S | FileCheck %s ; RUN: opt < %s -simplifycfg -S | FileCheck %s
; XFAIL: *
declare void @foo1() declare void @foo1()
@ -257,7 +256,7 @@ lor.end: ; preds = %lor.rhs, %lor.lhs.f
; HECK: %cmp = icmp ult i8 %c, 33 ; HECK: %cmp = icmp ult i8 %c, 33
; HECK: br i1 %cmp, label %lor.end, label %switch.early.test ; 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: switch i8 %c, label %lor.rhs [
; HECK: i8 46, label %lor.end ; HECK: i8 46, label %lor.end
; HECK: i8 44, label %lor.end ; HECK: i8 44, label %lor.end