Completely disable the optimization I added in r121680 until
authorChris Lattner <sabre@nondot.org>
Mon, 13 Dec 2010 07:41:29 +0000 (07:41 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 13 Dec 2010 07:41:29 +0000 (07:41 +0000)
I can track down a miscompile.  This should bring the buildbots
back to life

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121693 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/switch_create.ll

index 18c2905a546c7596aae44905368f57717cc77037..d7a6ea4655aa8f2ef333304404d098159651f6c9 100644 (file)
@@ -331,8 +331,8 @@ GatherConstantCompares(Value *V, std::vector<ConstantInt*> &Vals, Value *&Extra,
                                             isEQ)) {
       if (LHS == RHS)
         return LHS;
+      Vals.resize(NumVals);
     }
-    Vals.resize(NumVals);
 
     // The RHS of the or/and can't be folded in and we haven't used "Extra" yet,
     // set it and return success.
@@ -348,12 +348,13 @@ GatherConstantCompares(Value *V, std::vector<ConstantInt*> &Vals, Value *&Extra,
   // If the LHS can't be folded in, but Extra is available and RHS can, try to
   // use LHS as Extra.
   if (Extra == 0 || Extra == I->getOperand(0)) {
+    Value *OldExtra = Extra;
     Extra = I->getOperand(0);
     if (Value *RHS = GatherConstantCompares(I->getOperand(1), Vals, Extra, TD,
                                             isEQ))
       return RHS;
-    Vals.resize(NumValsBeforeLHS);
-    Extra = 0;
+    assert(Vals.size() == NumValsBeforeLHS);
+    Extra = OldExtra;
   }
   
   return 0;
@@ -1908,6 +1909,8 @@ static bool SimplifyBranchOnICmpChain(BranchInst *BI, const TargetData *TD) {
   // then we evaluate them with an explicit branch first.  Split the block
   // right before the condbr to handle it.
   if (ExtraCase) {
+    return false;
+    
     BasicBlock *NewBB = BB->splitBasicBlock(BI, "switch.early.test");
     // Remove the uncond branch added to the old block.
     TerminatorInst *OldTI = BB->getTerminator();
index ce82936c31f9c4350deec13c934e36b8d8c77ddd..2f0dc94c08f088c7f628e30753b36f8ddce5486c 100644 (file)
@@ -168,13 +168,13 @@ if.end:                                           ; preds = %entry
   ret void
   
 ; CHECK: @test7
-; CHECK:   %cmp = icmp ult i32 %x, 32
-; CHECK:   br i1 %cmp, label %if.then, label %switch.early.test
-; CHECK: switch.early.test:
-; CHECK:   switch i8 %c, label %if.end [
-; CHECK:     i8 99, label %if.then
-; CHECK:     i8 97, label %if.then
-; CHECK:   ]
+; HECK:   %cmp = icmp ult i32 %x, 32
+; HECK:   br i1 %cmp, label %if.then, label %switch.early.test
+; HECK: switch.early.test:
+; HECK:   switch i8 %c, label %if.end [
+; HECK:     i8 99, label %if.then
+; HECK:     i8 97, label %if.then
+; HECK:   ]
 }
 
 define i32 @test8(i8 zeroext %c, i32 %x, i1 %C) nounwind ssp noredzone {
@@ -197,14 +197,15 @@ if.end:                                           ; preds = %entry
   ret i32 0
   
 ; CHECK: @test8
-; CHECK: switch.early.test:
-; CHECK:   switch i8 %c, label %if.end [
-; CHECK:     i8 99, label %if.then
-; CHECK:     i8 97, label %if.then
-; CHECK:   ]
-; CHECK:   %A = phi i32 [ 0, %entry ], [ 42, %switch.early.test ], [ 42, %N ], [ 42, %switch.early.test ]
+; HECK: switch.early.test:
+; HECK:   switch i8 %c, label %if.end [
+; HECK:     i8 99, label %if.then
+; HECK:     i8 97, label %if.then
+; HECK:   ]
+; HECK:   %A = phi i32 [ 0, %entry ], [ 42, %switch.early.test ], [ 42, %N ], [ 42, %switch.early.test ]
 }
 
+;; This is "Example 7" from http://blog.regehr.org/archives/320
 define i32 @test9(i8 zeroext %c) nounwind ssp noredzone {
 entry:
   %cmp = icmp ult i8 %c, 33
@@ -253,20 +254,20 @@ lor.end:                                          ; preds = %lor.rhs, %lor.lhs.f
   
 ; CHECK: @test9
 ; CHECK:   %cmp = icmp ult i8 %c, 33
-; CHECK:   br i1 %cmp, label %lor.end, label %switch.early.test
-
-; CHECK: switch.early.test:
-; CHECK:   switch i8 %c, label %lor.rhs [
-; CHECK:     i8 46, label %lor.end
-; CHECK:     i8 44, label %lor.end
-; CHECK:     i8 58, label %lor.end
-; CHECK:     i8 59, label %lor.end
-; CHECK:     i8 60, label %lor.end
-; CHECK:     i8 62, label %lor.end
-; CHECK:     i8 34, label %lor.end
-; CHECK:     i8 92, label %lor.end
-; CHECK:     i8 39, label %lor.end
-; CHECK:   ]
+; HECK:   br i1 %cmp, label %lor.end, label %switch.early.test
+
+; HECK: switch.early.test:
+; HECK:   switch i8 %c, label %lor.rhs [
+; HECK:     i8 46, label %lor.end
+; HECK:     i8 44, label %lor.end
+; HECK:     i8 58, label %lor.end
+; HECK:     i8 59, label %lor.end
+; HECK:     i8 60, label %lor.end
+; HECK:     i8 62, label %lor.end
+; HECK:     i8 34, label %lor.end
+; HECK:     i8 92, label %lor.end
+; HECK:     i8 39, label %lor.end
+; HECK:   ]
 }