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

Gabor Greif ggreif at gmail.com
Wed Oct 6 16:51:34 PDT 2010


Author: ggreif
Date: Wed Oct  6 18:51:34 2010
New Revision: 115873

URL: http://llvm.org/viewvc/llvm-project?rev=115873&view=rev
Log:
generalize 'leg-chopper' to pick default dest when value not encountered; fails CodeGen/PowerPC/2008-02-05-LiveIntervalsAssert.ll :-(

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=115873&r1=115872&r2=115873&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 18:51:34 2010
@@ -882,15 +882,20 @@
                  ConstantInt *Against = 0) {
   if (!Against) Against = Val;
 
+  BasicBlock *New = Old->splitBasicBlock(I, BlockName);        
+  TerminatorInst *OldBranch = Old->getTerminator();
+  Instruction *Cmp = new ICmpInst(*Old, Crit, OrigCondition, Against, CmpName);
+
   if (unsigned Leg = I->findCaseValue(Val)) {
-    BasicBlock *New = Old->splitBasicBlock(I, BlockName);        
-    Old->getTerminator()->eraseFromParent();
-    Instruction *Cmp = new ICmpInst(*Old, Crit, OrigCondition, Against, CmpName);
     BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
     I->removeCase(Leg);
-    return New;
+  } else {
+    BranchInst::Create(I->getDefaultDest(), New, Cmp, Old);
   }
-  return 0;
+
+  OldBranch->replaceAllUsesWith(Old->getTerminator());
+  OldBranch->eraseFromParent();
+  return New;
 }
 
 static bool OptimizeSwitchInst(SwitchInst *I, Value *OrigCondition) {





More information about the llvm-branch-commits mailing list