[llvm-commits] [llvm] r121695 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/switch_create.ll
Chris Lattner
sabre at nondot.org
Mon Dec 13 00:12:20 PST 2010
Author: lattner
Date: Mon Dec 13 02:12:19 2010
New Revision: 121695
URL: http://llvm.org/viewvc/llvm-project?rev=121695&view=rev
Log:
reinstate my patch: the miscompile was caused by an inverted branch in the
'and' case.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=121695&r1=121694&r2=121695&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Dec 13 02:12:19 2010
@@ -1909,13 +1909,15 @@
// 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();
- BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI);
+ if (TrueWhenEqual)
+ BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI);
+ else
+ BranchInst::Create(NewBB, EdgeBB, ExtraCase, OldTI);
+
OldTI->eraseFromParent();
// If there are PHI nodes in EdgeBB, then we need to add a new entry to them
@@ -1955,6 +1957,7 @@
// Erase the old branch instruction.
EraseTerminatorInstAndDCECond(BI);
+
return true;
}
Modified: llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll?rev=121695&r1=121694&r2=121695&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch_create.ll Mon Dec 13 02:12:19 2010
@@ -168,13 +168,13 @@
ret void
; CHECK: @test7
-; 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: ]
+; 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: ]
}
define i32 @test8(i8 zeroext %c, i32 %x, i1 %C) nounwind ssp noredzone {
@@ -197,12 +197,12 @@
ret i32 0
; CHECK: @test8
-; 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 ]
+; 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 ]
}
;; This is "Example 7" from http://blog.regehr.org/archives/320
@@ -254,20 +254,41 @@
; CHECK: @test9
; CHECK: %cmp = icmp ult i8 %c, 33
-; HECK: br i1 %cmp, label %lor.end, label %switch.early.test
+; CHECK: 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: ]
+; 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: ]
}
+define i32 @test10(i32 %mode, i1 %Cond) {
+ %A = icmp ne i32 %mode, 0
+ %B = icmp ne i32 %mode, 51
+ %C = and i1 %A, %B
+ %D = and i1 %C, %Cond
+ br i1 %D, label %T, label %F
+T:
+ ret i32 123
+F:
+ ret i32 324
+
+; CHECK: @test10
+; CHECK: br i1 %Cond, label %switch.early.test, label %F
+; CHECK:switch.early.test:
+; CHECK: switch i32 %mode, label %T [
+; CHECK: i32 51, label %F
+; CHECK: i32 0, label %F
+; CHECK: ]
+}
+
+
More information about the llvm-commits
mailing list