[llvm-branch-commits] [llvm-branch] r115844 - /llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp

Gabor Greif ggreif at gmail.com
Wed Oct 6 14:34:07 PDT 2010


Author: ggreif
Date: Wed Oct  6 16:34:07 2010
New Revision: 115844

URL: http://llvm.org/viewvc/llvm-project?rev=115844&view=rev
Log:
prepare for the elimination of the switch: almost there

Modified:
    llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp

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=115844&r1=115843&r2=115844&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:34:07 2010
@@ -879,7 +879,7 @@
 ChopOffSwitchLeg(SwitchInst *I, Value *OrigCondition, ConstantInt *Val,
                  BasicBlock *Old, const char *CmpName, const char *BlockName,
                  CmpInst::Predicate Crit = CmpInst::ICMP_EQ,
-								 ConstantInt *Against = 0) {
+                 ConstantInt *Against = 0) {
   if (!Against) Against = Val;
 
   if (unsigned Leg = I->findCaseValue(Val)) {
@@ -938,10 +938,20 @@
         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)) {
-					}
+          ConstantInt *T(cast<ConstantInt>(ConstantInt::get(Ty, Top)));
+          if (BasicBlock *New3 = ChopOffSwitchLeg(I, OrigCondition, T, New2,
+                                                  "top?", "nz.bottom", CmpInst::ICMP_UGT, Mid)) {
+            // The bottom value remains.
+            APInt Bottom(Top);
+            Bottom.clear(Mask.getBitWidth() - 1 - KnownZeroInverted.countLeadingZeros());
+            ConstantInt *Bot(cast<ConstantInt>(ConstantInt::get(Ty, Bottom)));
+            if (unsigned BottomLeg = I->findCaseValue(Bot)) {
+              // Replace nz.bottom BB with found leg.
+            } else {
+              // Otherwise with default leg.
+              assert(0);
+            }
+          }
         }
         return true;
       }





More information about the llvm-branch-commits mailing list