[llvm-branch-commits] [llvm-branch] r115839 - in /llvm/branches/ggreif/switch-opts: lib/Transforms/Scalar/CodeGenPrepare.cpp test/CodeGen/X86/switch-and.ll
Gabor Greif
ggreif at gmail.com
Wed Oct 6 14:14:41 PDT 2010
Author: ggreif
Date: Wed Oct 6 16:14:40 2010
New Revision: 115839
URL: http://llvm.org/viewvc/llvm-project?rev=115839&view=rev
Log:
get rid of top value in switch by doing an UGT comparison against the middle value; update testcase
Modified:
llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp
llvm/branches/ggreif/switch-opts/test/CodeGen/X86/switch-and.ll
Modified: llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=115839&r1=115838&r2=115839&view=diff
==============================================================================
--- llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp Wed Oct 6 16:14:40 2010
@@ -878,11 +878,14 @@
static BasicBlock*
ChopOffSwitchLeg(SwitchInst *I, Value *OrigCondition, ConstantInt *Val,
BasicBlock *Old, const char *CmpName, const char *BlockName,
- CmpInst::Predicate Crit = CmpInst::ICMP_EQ) {
+ CmpInst::Predicate Crit = CmpInst::ICMP_EQ,
+ ConstantInt *Against = 0) {
+ if (!Against) Against = Val;
+
if (unsigned Leg = I->findCaseValue(Val)) {
BasicBlock *New = Old->splitBasicBlock(I, BlockName);
Old->getTerminator()->eraseFromParent();
- Instruction *Cmp = new ICmpInst(*Old, Crit, OrigCondition, Val, CmpName);
+ Instruction *Cmp = new ICmpInst(*Old, Crit, OrigCondition, Against, CmpName);
BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
I->removeCase(Leg);
return New;
@@ -929,11 +932,16 @@
if (unknown > 2) return true;
unknown += KnownOne.countPopulation();
if (unknown > 2) return true;
- APInt Middle(KnownZeroInverted | KnownOne);
+ APInt Top(KnownZeroInverted | KnownOne);
+ APInt Middle(Top);
Middle.clear(KnownZeroInverted.countTrailingZeros());
ConstantInt *Mid(cast<ConstantInt>(ConstantInt::get(Ty, Middle)));
if (BasicBlock *New2 = ChopOffSwitchLeg(I, OrigCondition, Mid, New, "mid?", "nz.non-middle")) {
+ ConstantInt *T(cast<ConstantInt>(ConstantInt::get(Ty, Top)));
+ if (BasicBlock *New3 = ChopOffSwitchLeg(I, OrigCondition, T, New2,
+ "top?", "nz.bottom", CmpInst::ICMP_UGT, Mid)) {
+ }
}
return true;
}
Modified: llvm/branches/ggreif/switch-opts/test/CodeGen/X86/switch-and.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/switch-opts/test/CodeGen/X86/switch-and.ll?rev=115839&r1=115838&r2=115839&view=diff
==============================================================================
--- llvm/branches/ggreif/switch-opts/test/CodeGen/X86/switch-and.ll (original)
+++ llvm/branches/ggreif/switch-opts/test/CodeGen/X86/switch-and.ll Wed Oct 6 16:14:40 2010
@@ -16,6 +16,7 @@
%and = and i64 %0, 3
%conv = trunc i64 %and to i32
switch i32 %conv, label %sw.epilog [
+
;; CHECK: %tst = icmp eq i32 %conv, 0
;; CHECK-NEXT: br i1 %tst, label %sw.bb, label %nz
i32 0, label %sw.bb
@@ -25,10 +26,13 @@
;; CHECK-NEXT: br i1 %"mid?", label %sw.bb8, label %nz.non-middle
;; CHECK: nz.non-middle:
+;; CHECK-NEXT: %"top?" = icmp ugt i32 %conv, 2
+;; CHECK-NEXT: br i1 %"top?", label %sw.bb6, label %nz.bottom
+
+;; CHECK: nz.bottom:
;; CHECK-NEXT: switch i32 %conv, label %sw.epilog
;; CHECK-NEXT: i32 1, label %sw.bb
i32 1, label %sw.bb
-;; CHECK-NEXT: i32 3, label %sw.bb6
i32 3, label %sw.bb6
i32 2, label %sw.bb8
;; CHECK-NEXT: ]
More information about the llvm-branch-commits
mailing list