[llvm-commits] [llvm] r121749 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/switch_create.ll
Chris Lattner
sabre at nondot.org
Mon Dec 13 21:57:30 PST 2010
Author: lattner
Date: Mon Dec 13 23:57:30 2010
New Revision: 121749
URL: http://llvm.org/viewvc/llvm-project?rev=121749&view=rev
Log:
reapply my recent change that disables a piece of the switch formation
work, but fixes 400.perlbmk.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=121749&r1=121748&r2=121749&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Dec 13 23:57:30 2010
@@ -1515,7 +1515,7 @@
AddPredecessorToBlock(FalseDest, PredBlock, BB);
PBI->setSuccessor(1, FalseDest);
}
- return SimplifyCFG(PBI->getParent()) | true;
+ return true;
}
return false;
}
@@ -1905,17 +1905,25 @@
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
@@ -1955,6 +1963,7 @@
// Erase the old branch instruction.
EraseTerminatorInstAndDCECond(BI);
+
return true;
}
@@ -2410,8 +2419,7 @@
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;
Modified: llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll?rev=121749&r1=121748&r2=121749&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll Mon Dec 13 23:57:30 2010
@@ -1,5 +1,4 @@
; RUN: opt < %s -simplifycfg -S | FileCheck %s
-; XFAIL: *
declare void @foo1()
@@ -257,7 +256,7 @@
; 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
More information about the llvm-commits
mailing list