[llvm-branch-commits] [llvm-branch] r115828 - 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 13:31:25 PDT 2010
Author: ggreif
Date: Wed Oct 6 15:31:25 2010
New Revision: 115828
URL: http://llvm.org/viewvc/llvm-project?rev=115828&view=rev
Log:
clean up and give branches more sensible names
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=115828&r1=115827&r2=115828&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 15:31:25 2010
@@ -875,12 +875,14 @@
return MadeChange;
}
-BasicBlock *ChopOffSwitchLeg(SwitchInst *I, Value *OrigCondition, ConstantInt *Val,
- BasicBlock *Old, const char *CmpName) {
+static BasicBlock*
+ChopOffSwitchLeg(SwitchInst *I, Value *OrigCondition, ConstantInt *Val,
+ BasicBlock *Old, const char *CmpName, const char *BlockName,
+ CmpInst::Predicate Crit = CmpInst::ICMP_EQ) {
if (unsigned Leg = I->findCaseValue(Val)) {
- BasicBlock *New = Old->splitBasicBlock(I, Old->getName()+".switch");
+ BasicBlock *New = Old->splitBasicBlock(I, BlockName);
Old->getTerminator()->eraseFromParent();
- Instruction *Cmp = new ICmpInst(*Old, CmpInst::ICMP_EQ, OrigCondition, Val, CmpName);
+ Instruction *Cmp = new ICmpInst(*Old, Crit, OrigCondition, Val, CmpName);
BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
I->removeCase(Leg);
return New;
@@ -918,15 +920,7 @@
if (BinaryOperator *A = dyn_cast<BinaryOperator>(condition)) {
if (A->getOpcode() == Instruction::And) {
ConstantInt *Zero(cast<ConstantInt>(ConstantInt::get(Ty, 0)));
- if (BasicBlock *New = ChopOffSwitchLeg(I, OrigCondition, Zero, Old, "tst")) {
- /*
- if (unsigned Leg = I->findCaseValue(Zero)) {
- BasicBlock *New = Old->splitBasicBlock(I, Old->getName()+".switch");
- Old->getTerminator()->eraseFromParent();
- Instruction *Cmp = new ICmpInst(*Old, CmpInst::ICMP_EQ, OrigCondition, Zero, "tst");
- BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
- I->removeCase(Leg);*/
-
+ if (BasicBlock *New = ChopOffSwitchLeg(I, OrigCondition, Zero, Old, "tst", "nz")) {
APInt Mask(cast<IntegerType>(Ty)->getMask());
APInt KnownZero(Mask.getBitWidth(), 0), KnownOne(Mask.getBitWidth(), 0);
ComputeMaskedBits(OrigCondition, Mask, KnownZero, KnownOne);
@@ -939,16 +933,8 @@
Middle.clear(KnownZeroInverted.countTrailingZeros());
ConstantInt *Mid(cast<ConstantInt>(ConstantInt::get(Ty, Middle)));
- if (BasicBlock *New2 = ChopOffSwitchLeg(I, OrigCondition, Mid, New, "mid?")) {
+ if (BasicBlock *New2 = ChopOffSwitchLeg(I, OrigCondition, Mid, New, "mid?", "nz.non-middle")) {
}
- /*
- if (unsigned MidLeg = I->findCaseValue(Mid)) {
- BasicBlock *New2 = New->splitBasicBlock(I, New->getName()+".switch2");
- New->getTerminator()->eraseFromParent();
- Instruction *MidCmp = new ICmpInst(*New, CmpInst::ICMP_EQ, OrigCondition, Mid, "mid?");
- BranchInst::Create(I->getSuccessor(MidLeg), New2, MidCmp, New);
- I->removeCase(MidLeg);
- }*/
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=115828&r1=115827&r2=115828&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 15:31:25 2010
@@ -17,14 +17,14 @@
%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 %tailrecurse.switch
+;; CHECK-NEXT: br i1 %tst, label %sw.bb, label %nz
i32 0, label %sw.bb
-;; CHECK: tailrecurse.switch:
+;; CHECK: nz:
;; CHECK-NEXT: %"mid?" = icmp eq i32 %conv, 2
-;; CHECK-NEXT: br i1 %"mid?", label %sw.bb8, label %tailrecurse.switch.switch2
+;; CHECK-NEXT: br i1 %"mid?", label %sw.bb8, label %nz.non-middle
-;; CHECK: tailrecurse.switch.switch2:
+;; CHECK: nz.non-middle:
;; CHECK-NEXT: switch i32 %conv, label %sw.epilog
;; CHECK-NEXT: i32 1, label %sw.bb
i32 1, label %sw.bb
More information about the llvm-branch-commits
mailing list