Add SwiftShader dump from Feb 6 2013
diff --git a/src/LLVM/test/Transforms/ADCE/2002-01-31-UseStuckAround.ll b/src/LLVM/test/Transforms/ADCE/2002-01-31-UseStuckAround.ll
new file mode 100644
index 0000000..d23c9ba
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-01-31-UseStuckAround.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -adce
+
+define i32 @"main"(i32 %argc) {
+ br label %2
+
+ %retval = phi i32 [ %argc, %2 ] ; <i32> [#uses=2]
+ %two = add i32 %retval, %retval ; <i32> [#uses=1]
+ ret i32 %two
+
+ br label %1
+}
diff --git a/src/LLVM/test/Transforms/ADCE/2002-05-22-PHITest.ll b/src/LLVM/test/Transforms/ADCE/2002-05-22-PHITest.ll
new file mode 100644
index 0000000..e0fc5dc
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-05-22-PHITest.ll
@@ -0,0 +1,16 @@
+; It is illegal to remove BB1 because it will mess up the PHI node!
+;
+; RUN: opt < %s -adce -S | grep BB1
+
+define i32 @test(i1 %C, i32 %A, i32 %B) {
+; <label>:0
+ br i1 %C, label %BB1, label %BB2
+
+BB1: ; preds = %0
+ br label %BB2
+
+BB2: ; preds = %BB1, %0
+ %R = phi i32 [ %A, %0 ], [ %B, %BB1 ] ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2002-05-23-ZeroArgPHITest.ll b/src/LLVM/test/Transforms/ADCE/2002-05-23-ZeroArgPHITest.ll
new file mode 100644
index 0000000..1a63f9f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-05-23-ZeroArgPHITest.ll
@@ -0,0 +1,32 @@
+; This testcase contains a entire loop that should be removed. The only thing
+; left is the store instruction in BB0. The problem this testcase was running
+; into was that when the reg109 PHI was getting zero predecessors, it was
+; removed even though there were uses still around. Now the uses are filled
+; in with a dummy value before the PHI is deleted.
+;
+; RUN: opt < %s -adce
+
+ %node_t = type { double*, %node_t*, %node_t**, double**, double*, i32, i32 }
+
+define void @localize_local(%node_t* %nodelist) {
+bb0:
+ %nodelist.upgrd.1 = alloca %node_t* ; <%node_t**> [#uses=2]
+ store %node_t* %nodelist, %node_t** %nodelist.upgrd.1
+ br label %bb1
+
+bb1: ; preds = %bb0
+ %reg107 = load %node_t** %nodelist.upgrd.1 ; <%node_t*> [#uses=2]
+ %cond211 = icmp eq %node_t* %reg107, null ; <i1> [#uses=1]
+ br i1 %cond211, label %bb3, label %bb2
+
+bb2: ; preds = %bb2, %bb1
+ %reg109 = phi %node_t* [ %reg110, %bb2 ], [ %reg107, %bb1 ] ; <%node_t*> [#uses=1]
+ %reg212 = getelementptr %node_t* %reg109, i64 0, i32 1 ; <%node_t**> [#uses=1]
+ %reg110 = load %node_t** %reg212 ; <%node_t*> [#uses=2]
+ %cond213 = icmp ne %node_t* %reg110, null ; <i1> [#uses=1]
+ br i1 %cond213, label %bb2, label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash-distilled.ll b/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash-distilled.ll
new file mode 100644
index 0000000..44a9f91
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash-distilled.ll
@@ -0,0 +1,17 @@
+; This testcase is a distilled form of: 2002-05-28-Crash.ll
+
+; RUN: opt < %s -adce
+
+define float @test(i32 %i) {
+ %F = sitofp i32 %i to float ; <float> [#uses=1]
+ %I = bitcast i32 %i to i32 ; <i32> [#uses=1]
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %B = icmp ne i32 %I, 0 ; <i1> [#uses=1]
+ br i1 %B, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ ret float %F
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash.ll b/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash.ll
new file mode 100644
index 0000000..c9b21f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-05-28-Crash.ll
@@ -0,0 +1,54 @@
+; This testcase is distilled from the GNU rx package. The loop should be
+; removed but causes a problem when ADCE does. The source function is:
+; int rx_bitset_empty (int size, rx_Bitset set) {
+; int x;
+; RX_subset s;
+; s = set[0];
+; set[0] = 1;
+; for (x = rx_bitset_numb_subsets(size) - 1; !set[x]; --x)
+; ;
+; set[0] = s;
+; return !s;
+;}
+;
+; RUN: opt < %s -adce
+
+define i32 @rx_bitset_empty(i32 %size, i32* %set) {
+bb1:
+ %reg110 = load i32* %set ; <i32> [#uses=2]
+ store i32 1, i32* %set
+ %cast112 = sext i32 %size to i64 ; <i64> [#uses=1]
+ %reg113 = add i64 %cast112, 31 ; <i64> [#uses=1]
+ %reg114 = lshr i64 %reg113, 5 ; <i64> [#uses=2]
+ %cast109 = trunc i64 %reg114 to i32 ; <i32> [#uses=1]
+ %reg129 = add i32 %cast109, -1 ; <i32> [#uses=1]
+ %reg114-idxcast = trunc i64 %reg114 to i32 ; <i32> [#uses=1]
+ %reg114-idxcast-offset = add i32 %reg114-idxcast, 1073741823 ; <i32> [#uses=1]
+ %reg114-idxcast-offset.upgrd.1 = zext i32 %reg114-idxcast-offset to i64 ; <i64> [#uses=1]
+ %reg124 = getelementptr i32* %set, i64 %reg114-idxcast-offset.upgrd.1 ; <i32*> [#uses=1]
+ %reg125 = load i32* %reg124 ; <i32> [#uses=1]
+ %cond232 = icmp ne i32 %reg125, 0 ; <i1> [#uses=1]
+ br i1 %cond232, label %bb3, label %bb2
+
+bb2: ; preds = %bb2, %bb1
+ %cann-indvar = phi i32 [ 0, %bb1 ], [ %add1-indvar, %bb2 ] ; <i32> [#uses=2]
+ %reg130-scale = mul i32 %cann-indvar, -1 ; <i32> [#uses=1]
+ %reg130 = add i32 %reg130-scale, %reg129 ; <i32> [#uses=1]
+ %add1-indvar = add i32 %cann-indvar, 1 ; <i32> [#uses=1]
+ %reg130-idxcast = bitcast i32 %reg130 to i32 ; <i32> [#uses=1]
+ %reg130-idxcast-offset = add i32 %reg130-idxcast, 1073741823 ; <i32> [#uses=1]
+ %reg130-idxcast-offset.upgrd.2 = zext i32 %reg130-idxcast-offset to i64 ; <i64> [#uses=1]
+ %reg118 = getelementptr i32* %set, i64 %reg130-idxcast-offset.upgrd.2 ; <i32*> [#uses=1]
+ %reg119 = load i32* %reg118 ; <i32> [#uses=1]
+ %cond233 = icmp eq i32 %reg119, 0 ; <i1> [#uses=1]
+ br i1 %cond233, label %bb2, label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ store i32 %reg110, i32* %set
+ %cast126 = zext i32 %reg110 to i64 ; <i64> [#uses=1]
+ %reg127 = add i64 %cast126, -1 ; <i64> [#uses=1]
+ %reg128 = lshr i64 %reg127, 63 ; <i64> [#uses=1]
+ %cast120 = trunc i64 %reg128 to i32 ; <i32> [#uses=1]
+ ret i32 %cast120
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2002-07-17-AssertionFailure.ll b/src/LLVM/test/Transforms/ADCE/2002-07-17-AssertionFailure.ll
new file mode 100644
index 0000000..fd71ead
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-07-17-AssertionFailure.ll
@@ -0,0 +1,13 @@
+; This testcase fails because ADCE does not correctly delete the chain of
+; three instructions that are dead here. Ironically there were a dead basic
+; block in this function, it would work fine, but that would be the part we
+; have to fix now, wouldn't it....
+;
+; RUN: opt < %s -adce
+
+define void @foo(i8* %reg5481) {
+ %cast611 = bitcast i8* %reg5481 to i8** ; <i8**> [#uses=1]
+ %reg162 = load i8** %cast611 ; <i8*> [#uses=1]
+ ptrtoint i8* %reg162 to i32 ; <i32>:1 [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ADCE/2002-07-17-PHIAssertion.ll b/src/LLVM/test/Transforms/ADCE/2002-07-17-PHIAssertion.ll
new file mode 100644
index 0000000..7d72a03
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-07-17-PHIAssertion.ll
@@ -0,0 +1,48 @@
+; This testcase was extracted from the gzip SPEC benchmark
+;
+; RUN: opt < %s -adce
+
+@bk = external global i32 ; <i32*> [#uses=2]
+@hufts = external global i32 ; <i32*> [#uses=1]
+
+define i32 @inflate() {
+bb0:
+ br label %bb2
+
+bb2: ; preds = %bb6, %bb0
+ %reg128 = phi i32 [ %reg130, %bb6 ], [ 0, %bb0 ] ; <i32> [#uses=2]
+ br i1 true, label %bb4, label %bb3
+
+bb3: ; preds = %bb2
+ br label %UnifiedExitNode
+
+bb4: ; preds = %bb2
+ %reg117 = load i32* @hufts ; <i32> [#uses=2]
+ %cond241 = icmp ule i32 %reg117, %reg128 ; <i1> [#uses=1]
+ br i1 %cond241, label %bb6, label %bb5
+
+bb5: ; preds = %bb4
+ br label %bb6
+
+bb6: ; preds = %bb5, %bb4
+ %reg130 = phi i32 [ %reg117, %bb5 ], [ %reg128, %bb4 ] ; <i32> [#uses=1]
+ br i1 false, label %bb2, label %bb7
+
+bb7: ; preds = %bb6
+ %reg126 = load i32* @bk ; <i32> [#uses=1]
+ %cond247 = icmp ule i32 %reg126, 7 ; <i1> [#uses=1]
+ br i1 %cond247, label %bb9, label %bb8
+
+bb8: ; preds = %bb8, %bb7
+ %reg119 = load i32* @bk ; <i32> [#uses=1]
+ %cond256 = icmp ugt i32 %reg119, 7 ; <i1> [#uses=1]
+ br i1 %cond256, label %bb8, label %bb9
+
+bb9: ; preds = %bb8, %bb7
+ br label %UnifiedExitNode
+
+UnifiedExitNode: ; preds = %bb9, %bb3
+ %UnifiedRetVal = phi i32 [ 7, %bb3 ], [ 0, %bb9 ] ; <i32> [#uses=1]
+ ret i32 %UnifiedRetVal
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2002-07-29-Segfault.ll b/src/LLVM/test/Transforms/ADCE/2002-07-29-Segfault.ll
new file mode 100644
index 0000000..2783b5d
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2002-07-29-Segfault.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -adce -disable-output
+
+define void @test() {
+ br label %BB3
+
+BB3: ; preds = %BB3, %0
+ br label %BB3
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-01-22-PredecessorProblem.ll b/src/LLVM/test/Transforms/ADCE/2003-01-22-PredecessorProblem.ll
new file mode 100644
index 0000000..8c676b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-01-22-PredecessorProblem.ll
@@ -0,0 +1,25 @@
+; Testcase reduced from 197.parser by bugpoint
+; RUN: opt < %s -adce
+
+define void @conjunction_prune() {
+; <label>:0
+ br label %bb19
+
+bb19: ; preds = %bb23, %bb22, %0
+ %reg205 = phi i8* [ null, %bb22 ], [ null, %bb23 ], [ null, %0 ] ; <i8*> [#uses=1]
+ br i1 false, label %bb21, label %bb22
+
+bb21: ; preds = %bb19
+ %cast455 = bitcast i8* %reg205 to i8** ; <i8**> [#uses=0]
+ br label %bb22
+
+bb22: ; preds = %bb21, %bb19
+ br i1 false, label %bb19, label %bb23
+
+bb23: ; preds = %bb22
+ br i1 false, label %bb19, label %bb28
+
+bb28: ; preds = %bb23
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-04-25-PHIPostDominateProblem.ll b/src/LLVM/test/Transforms/ADCE/2003-04-25-PHIPostDominateProblem.ll
new file mode 100644
index 0000000..8e4a60e
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-04-25-PHIPostDominateProblem.ll
@@ -0,0 +1,35 @@
+; THis testcase caused an assertion failure because a PHI node did not have
+; entries for it's postdominator. But I think this can only happen when the
+; PHI node is dead, so we just avoid patching up dead PHI nodes.
+
+; RUN: opt < %s -adce
+
+target datalayout = "e-p:32:32"
+
+define void @dead_test8() {
+entry:
+ br label %loopentry
+
+loopentry: ; preds = %endif, %entry
+ %k.1 = phi i32 [ %k.0, %endif ], [ 0, %entry ] ; <i32> [#uses=1]
+ br i1 false, label %no_exit, label %return
+
+no_exit: ; preds = %loopentry
+ br i1 false, label %then, label %else
+
+then: ; preds = %no_exit
+ br label %endif
+
+else: ; preds = %no_exit
+ %dec = add i32 %k.1, -1 ; <i32> [#uses=1]
+ br label %endif
+
+endif: ; preds = %else, %then
+ %k.0 = phi i32 [ %dec, %else ], [ 0, %then ] ; <i32> [#uses=1]
+ store i32 2, i32* null
+ br label %loopentry
+
+return: ; preds = %loopentry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-06-11-InvalidCFG.ll b/src/LLVM/test/Transforms/ADCE/2003-06-11-InvalidCFG.ll
new file mode 100644
index 0000000..63d6eae
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-06-11-InvalidCFG.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -adce -disable-output
+
+@G = external global i32* ; <i32**> [#uses=1]
+
+declare void @Fn(i32*)
+
+define i32 @main(i32 %argc.1, i8** %argv.1) {
+entry:
+ br label %endif.42
+
+endif.42: ; preds = %shortcirc_done.12, %then.66, %endif.42, %entry
+ br i1 false, label %endif.65, label %endif.42
+
+then.66: ; preds = %shortcirc_done.12
+ call void @Fn( i32* %tmp.2846 )
+ br label %endif.42
+
+endif.65: ; preds = %endif.42
+ %tmp.2846 = load i32** @G ; <i32*> [#uses=1]
+ br i1 false, label %shortcirc_next.12, label %shortcirc_done.12
+
+shortcirc_next.12: ; preds = %endif.65
+ br label %shortcirc_done.12
+
+shortcirc_done.12: ; preds = %shortcirc_next.12, %endif.65
+ br i1 false, label %then.66, label %endif.42
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-06-24-BadSuccessor.ll b/src/LLVM/test/Transforms/ADCE/2003-06-24-BadSuccessor.ll
new file mode 100644
index 0000000..23c76e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-06-24-BadSuccessor.ll
@@ -0,0 +1,91 @@
+; RUN: opt < %s -adce -disable-output
+target datalayout = "e-p:32:32"
+ %struct..CppObjTypeDesc = type { i32, i16, i16 }
+ %struct..TypeToken = type { i32, i16, i16 }
+
+define i32 @C_ReFaxToDb() {
+entry:
+ br i1 false, label %endif.0, label %then.0
+
+then.0: ; preds = %entry
+ ret i32 0
+
+endif.0: ; preds = %entry
+ br i1 false, label %then.11, label %then.4
+
+then.4: ; preds = %endif.0
+ ret i32 0
+
+then.11: ; preds = %endif.0
+ br i1 false, label %loopentry.0, label %else.2
+
+loopentry.0: ; preds = %loopentry.1, %endif.14, %then.11
+ br i1 false, label %endif.14, label %loopexit.0
+
+endif.14: ; preds = %loopentry.0
+ br i1 false, label %loopentry.1, label %loopentry.0
+
+loopentry.1: ; preds = %then.53, %endif.14
+ %SubArrays.10 = phi i32* [ %SubArrays.8, %then.53 ], [ null, %endif.14 ] ; <i32*> [#uses=3]
+ br i1 false, label %no_exit.1, label %loopentry.0
+
+no_exit.1: ; preds = %loopentry.1
+ switch i32 0, label %label.17 [
+ i32 2, label %label.11
+ i32 19, label %label.10
+ ]
+
+label.10: ; preds = %no_exit.1
+ br i1 false, label %then.43, label %endif.43
+
+then.43: ; preds = %label.10
+ br i1 false, label %then.44, label %endif.44
+
+then.44: ; preds = %then.43
+ br i1 false, label %shortcirc_next.4, label %endif.45
+
+shortcirc_next.4: ; preds = %then.44
+ br i1 false, label %no_exit.2, label %loopexit.2
+
+no_exit.2: ; preds = %shortcirc_next.4
+ %tmp.897 = getelementptr i32* %SubArrays.10, i64 0 ; <i32*> [#uses=1]
+ %tmp.899 = load i32* %tmp.897 ; <i32> [#uses=1]
+ store i32 %tmp.899, i32* null
+ ret i32 0
+
+loopexit.2: ; preds = %shortcirc_next.4
+ ret i32 0
+
+endif.45: ; preds = %then.44
+ ret i32 0
+
+endif.44: ; preds = %then.43
+ ret i32 0
+
+endif.43: ; preds = %label.10
+ ret i32 0
+
+label.11: ; preds = %no_exit.1
+ ret i32 0
+
+label.17: ; preds = %no_exit.1
+ br i1 false, label %then.53, label %shortcirc_next.7
+
+shortcirc_next.7: ; preds = %label.17
+ br i1 false, label %then.53, label %shortcirc_next.8
+
+shortcirc_next.8: ; preds = %shortcirc_next.7
+ ret i32 0
+
+then.53: ; preds = %shortcirc_next.7, %label.17
+ %SubArrays.8 = phi i32* [ %SubArrays.10, %shortcirc_next.7 ], [ %SubArrays.10, %label.17 ] ; <i32*> [#uses=1]
+ %tmp.1023 = load i32* null ; <i32> [#uses=1]
+ switch i32 %tmp.1023, label %loopentry.1 [
+ ]
+
+loopexit.0: ; preds = %loopentry.0
+ ret i32 0
+
+else.2: ; preds = %then.11
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ADCE/2003-06-24-BasicFunctionality.ll b/src/LLVM/test/Transforms/ADCE/2003-06-24-BasicFunctionality.ll
new file mode 100644
index 0000000..84487e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-06-24-BasicFunctionality.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -adce -simplifycfg -S | not grep then:
+
+define void @dead_test8(i32* %data.1, i32 %idx.1) {
+entry:
+ %tmp.1 = load i32* %data.1 ; <i32> [#uses=2]
+ %tmp.41 = icmp sgt i32 %tmp.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp.41, label %no_exit.preheader, label %return
+
+no_exit.preheader: ; preds = %entry
+ %tmp.11 = getelementptr i32* %data.1, i64 1 ; <i32*> [#uses=1]
+ %tmp.22-idxcast = sext i32 %idx.1 to i64 ; <i64> [#uses=1]
+ %tmp.28 = getelementptr i32* %data.1, i64 %tmp.22-idxcast ; <i32*> [#uses=1]
+ br label %no_exit
+
+no_exit: ; preds = %endif, %no_exit.preheader
+ %k.1 = phi i32 [ %k.0, %endif ], [ 0, %no_exit.preheader ] ; <i32> [#uses=3]
+ %i.0 = phi i32 [ %inc.1, %endif ], [ 0, %no_exit.preheader ] ; <i32> [#uses=1]
+ %tmp.12 = load i32* %tmp.11 ; <i32> [#uses=1]
+ %tmp.14 = sub i32 0, %tmp.12 ; <i32> [#uses=1]
+ %tmp.161 = icmp ne i32 %k.1, %tmp.14 ; <i1> [#uses=1]
+ br i1 %tmp.161, label %then, label %else
+
+then: ; preds = %no_exit
+ %inc.0 = add i32 %k.1, 1 ; <i32> [#uses=1]
+ br label %endif
+
+else: ; preds = %no_exit
+ %dec = add i32 %k.1, -1 ; <i32> [#uses=1]
+ br label %endif
+
+endif: ; preds = %else, %then
+ %k.0 = phi i32 [ %dec, %else ], [ %inc.0, %then ] ; <i32> [#uses=1]
+ store i32 2, i32* %tmp.28
+ %inc.1 = add i32 %i.0, 1 ; <i32> [#uses=2]
+ %tmp.4 = icmp slt i32 %inc.1, %tmp.1 ; <i1> [#uses=1]
+ br i1 %tmp.4, label %no_exit, label %return
+
+return: ; preds = %endif, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-09-10-UnwindInstFail.ll b/src/LLVM/test/Transforms/ADCE/2003-09-10-UnwindInstFail.ll
new file mode 100644
index 0000000..03bc879
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-09-10-UnwindInstFail.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -adce -disable-output
+
+define void @test() {
+ br i1 false, label %then, label %endif
+
+then: ; preds = %0
+ invoke void null( i8* null )
+ to label %invoke_cont unwind label %invoke_catch
+
+invoke_catch: ; preds = %then
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %exn
+
+invoke_cont: ; preds = %then
+ ret void
+
+endif: ; preds = %0
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/ADCE/2003-09-15-InfLoopCrash.ll b/src/LLVM/test/Transforms/ADCE/2003-09-15-InfLoopCrash.ll
new file mode 100644
index 0000000..0da9f95
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-09-15-InfLoopCrash.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -adce -disable-output
+
+define i32 @main() {
+ br label %loop
+
+loop: ; preds = %loop, %0
+ br label %loop
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2003-11-16-MissingPostDominanceInfo.ll b/src/LLVM/test/Transforms/ADCE/2003-11-16-MissingPostDominanceInfo.ll
new file mode 100644
index 0000000..be00dc7
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2003-11-16-MissingPostDominanceInfo.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -adce -simplifycfg -S | grep call
+declare void @exit(i32)
+
+define i32 @main(i32 %argc) {
+ %C = icmp eq i32 %argc, 1 ; <i1> [#uses=2]
+ br i1 %C, label %Cond, label %Done
+
+Cond: ; preds = %0
+ br i1 %C, label %Loop, label %Done
+
+Loop: ; preds = %Loop, %Cond
+ call void @exit( i32 0 )
+ br label %Loop
+
+Done: ; preds = %Cond, %0
+ ret i32 1
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2004-05-04-UnreachableBlock.ll b/src/LLVM/test/Transforms/ADCE/2004-05-04-UnreachableBlock.ll
new file mode 100644
index 0000000..f57c167
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2004-05-04-UnreachableBlock.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -adce -disable-output
+
+define void @test() {
+entry:
+ br label %UnifiedReturnBlock
+
+UnifiedReturnBlock: ; preds = %invoke_catch.0, %entry
+ ret void
+
+invoke_catch.0: ; No predecessors!
+ br i1 false, label %UnifiedUnwindBlock, label %UnifiedReturnBlock
+
+UnifiedUnwindBlock: ; preds = %invoke_catch.0
+ unreachable
+}
+
diff --git a/src/LLVM/test/Transforms/ADCE/2005-02-17-PHI-Invoke-Crash.ll b/src/LLVM/test/Transforms/ADCE/2005-02-17-PHI-Invoke-Crash.ll
new file mode 100644
index 0000000..1924488
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/2005-02-17-PHI-Invoke-Crash.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -adce -disable-output
+
+declare void @strlen()
+
+declare void @_ZN10QByteArray6resizeEi()
+
+declare void @q_atomic_decrement()
+
+define void @_ZNK10QByteArray13leftJustifiedEicb() {
+entry:
+ invoke void @strlen( )
+ to label %tmp.3.i.noexc unwind label %invoke_catch.0
+
+tmp.3.i.noexc: ; preds = %entry
+ br i1 false, label %then.0, label %else.0
+
+invoke_catch.0: ; preds = %entry
+ %exn.0 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ invoke void @q_atomic_decrement( )
+ to label %tmp.1.i.i183.noexc unwind label %terminate
+
+tmp.1.i.i183.noexc: ; preds = %invoke_catch.0
+ ret void
+
+then.0: ; preds = %tmp.3.i.noexc
+ invoke void @_ZN10QByteArray6resizeEi( )
+ to label %invoke_cont.1 unwind label %invoke_catch.1
+
+invoke_catch.1: ; preds = %then.0
+ %exn.1 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ invoke void @q_atomic_decrement( )
+ to label %tmp.1.i.i162.noexc unwind label %terminate
+
+tmp.1.i.i162.noexc: ; preds = %invoke_catch.1
+ ret void
+
+invoke_cont.1: ; preds = %then.0
+ ret void
+
+else.0: ; preds = %tmp.3.i.noexc
+ ret void
+
+terminate: ; preds = %invoke_catch.1, %invoke_catch.0
+ %dbg.0.1 = phi { }* [ null, %invoke_catch.1 ], [ null, %invoke_catch.0 ] ; <{ }*> [#uses=0]
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/ADCE/basictest.ll b/src/LLVM/test/Transforms/ADCE/basictest.ll
new file mode 100644
index 0000000..9bcec9a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/basictest.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -adce -simplifycfg | llvm-dis
+
+define i32 @Test(i32 %A, i32 %B) {
+BB1:
+ br label %BB4
+
+BB2: ; No predecessors!
+ br label %BB3
+
+BB3: ; preds = %BB4, %BB2
+ %ret = phi i32 [ %X, %BB4 ], [ %B, %BB2 ] ; <i32> [#uses=1]
+ ret i32 %ret
+
+BB4: ; preds = %BB1
+ %X = phi i32 [ %A, %BB1 ] ; <i32> [#uses=1]
+ br label %BB3
+}
+
+
diff --git a/src/LLVM/test/Transforms/ADCE/basictest1.ll b/src/LLVM/test/Transforms/ADCE/basictest1.ll
new file mode 100644
index 0000000..80d03fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/basictest1.ll
@@ -0,0 +1,97 @@
+; RUN: opt < %s -adce -simplifycfg | llvm-dis
+%FILE = type { i32, i8*, i8*, i8, i8, i32, i32, i32 }
+ %spec_fd_t = type { i32, i32, i32, i8* }
+@__iob = external global [20 x %FILE] ; <[20 x %FILE]*> [#uses=1]
+@dbglvl = global i32 4 ; <i32*> [#uses=3]
+@spec_fd = external global [3 x %spec_fd_t] ; <[3 x %spec_fd_t]*> [#uses=4]
+@.LC9 = internal global [34 x i8] c"spec_read: fd=%d, > MAX_SPEC_FD!\0A\00" ; <[34 x i8]*> [#uses=1]
+@.LC10 = internal global [4 x i8] c"EOF\00" ; <[4 x i8]*> [#uses=1]
+@.LC11 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+@.LC12 = internal global [17 x i8] c"spec_getc: %d = \00" ; <[17 x i8]*> [#uses=1]
+
+declare i32 @fprintf(%FILE*, i8*, ...)
+
+declare void @exit(i32)
+
+declare i32 @remove(i8*)
+
+declare i32 @fputc(i32, %FILE*)
+
+declare i32 @fwrite(i8*, i32, i32, %FILE*)
+
+declare void @perror(i8*)
+
+define i32 @spec_getc(i32 %fd) {
+ %reg109 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond266 = icmp sle i32 %reg109, 4 ; <i1> [#uses=1]
+ br i1 %cond266, label %bb3, label %bb2
+
+bb2: ; preds = %0
+ %cast273 = getelementptr [17 x i8]* @.LC12, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb3
+
+bb3: ; preds = %bb2, %0
+ %cond267 = icmp sle i32 %fd, 3 ; <i1> [#uses=1]
+ br i1 %cond267, label %bb5, label %bb4
+
+bb4: ; preds = %bb3
+ %reg111 = getelementptr [20 x %FILE]* @__iob, i64 0, i64 1, i32 3 ; <i8*> [#uses=1]
+ %cast274 = getelementptr [34 x i8]* @.LC9, i64 0, i64 0 ; <i8*> [#uses=0]
+ %cast282 = bitcast i8* %reg111 to %FILE* ; <%FILE*> [#uses=0]
+ call void @exit( i32 1 )
+ br label %UnifiedExitNode
+
+bb5: ; preds = %bb3
+ %reg107-idxcast1 = sext i32 %fd to i64 ; <i64> [#uses=2]
+ %reg107-idxcast2 = sext i32 %fd to i64 ; <i64> [#uses=1]
+ %reg1311 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast2 ; <%spec_fd_t*> [#uses=1]
+ %idx1 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <i32*> [#uses=1]
+ %reg1321 = load i32* %idx1 ; <i32> [#uses=3]
+ %idx2 = getelementptr %spec_fd_t* %reg1311, i64 0, i32 1 ; <i32*> [#uses=1]
+ %reg1331 = load i32* %idx2 ; <i32> [#uses=1]
+ %cond270 = icmp slt i32 %reg1321, %reg1331 ; <i1> [#uses=1]
+ br i1 %cond270, label %bb9, label %bb6
+
+bb6: ; preds = %bb5
+ %reg134 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond271 = icmp sle i32 %reg134, 4 ; <i1> [#uses=1]
+ br i1 %cond271, label %bb8, label %bb7
+
+bb7: ; preds = %bb6
+ %cast277 = getelementptr [4 x i8]* @.LC10, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb6
+ br label %UnifiedExitNode
+
+bb9: ; preds = %bb5
+ %reg107-idxcast3 = sext i32 %fd to i64 ; <i64> [#uses=1]
+ %idx3 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast3, i32 3 ; <i8**> [#uses=1]
+ %reg1601 = load i8** %idx3 ; <i8*> [#uses=1]
+ %reg132-idxcast1 = sext i32 %reg1321 to i64 ; <i64> [#uses=1]
+ %idx4 = getelementptr i8* %reg1601, i64 %reg132-idxcast1 ; <i8*> [#uses=1]
+ %reg1621 = load i8* %idx4 ; <i8> [#uses=2]
+ %cast108 = zext i8 %reg1621 to i64 ; <i64> [#uses=0]
+ %reg157 = add i32 %reg1321, 1 ; <i32> [#uses=1]
+ %idx5 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <i32*> [#uses=1]
+ store i32 %reg157, i32* %idx5
+ %reg163 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond272 = icmp sle i32 %reg163, 4 ; <i1> [#uses=1]
+ br i1 %cond272, label %bb11, label %bb10
+
+bb10: ; preds = %bb9
+ %cast279 = getelementptr [4 x i8]* @.LC11, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb11
+
+bb11: ; preds = %bb10, %bb9
+ %cast291 = zext i8 %reg1621 to i32 ; <i32> [#uses=1]
+ br label %UnifiedExitNode
+
+UnifiedExitNode: ; preds = %bb11, %bb8, %bb4
+ %UnifiedRetVal = phi i32 [ 42, %bb4 ], [ -1, %bb8 ], [ %cast291, %bb11 ] ; <i32> [#uses=1]
+ ret i32 %UnifiedRetVal
+}
+
+declare i32 @puts(i8*)
+
+declare i32 @printf(i8*, ...)
diff --git a/src/LLVM/test/Transforms/ADCE/basictest2.ll b/src/LLVM/test/Transforms/ADCE/basictest2.ll
new file mode 100644
index 0000000..540a1c2
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/basictest2.ll
@@ -0,0 +1,97 @@
+; RUN: opt < %s -adce -simplifycfg | llvm-dis
+ %FILE = type { i32, i8*, i8*, i8, i8, i32, i32, i32 }
+ %spec_fd_t = type { i32, i32, i32, i8* }
+@__iob = external global [20 x %FILE] ; <[20 x %FILE]*> [#uses=1]
+@dbglvl = global i32 4 ; <i32*> [#uses=3]
+@spec_fd = external global [3 x %spec_fd_t] ; <[3 x %spec_fd_t]*> [#uses=4]
+@.LC9 = internal global [34 x i8] c"spec_read: fd=%d, > MAX_SPEC_FD!\0A\00" ; <[34 x i8]*> [#uses=1]
+@.LC10 = internal global [4 x i8] c"EOF\00" ; <[4 x i8]*> [#uses=1]
+@.LC11 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+@.LC12 = internal global [17 x i8] c"spec_getc: %d = \00" ; <[17 x i8]*> [#uses=1]
+
+declare i32 @fprintf(%FILE*, i8*, ...)
+
+declare void @exit(i32)
+
+declare i32 @remove(i8*)
+
+declare i32 @fputc(i32, %FILE*)
+
+declare i32 @fwrite(i8*, i32, i32, %FILE*)
+
+declare void @perror(i8*)
+
+define i32 @spec_getc(i32 %fd) {
+ %reg109 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond266 = icmp sle i32 %reg109, 4 ; <i1> [#uses=1]
+ br i1 %cond266, label %bb3, label %bb2
+
+bb2: ; preds = %0
+ %cast273 = getelementptr [17 x i8]* @.LC12, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb3
+
+bb3: ; preds = %bb2, %0
+ %cond267 = icmp sle i32 %fd, 3 ; <i1> [#uses=0]
+ br label %bb5
+
+bb4: ; No predecessors!
+ %reg111 = getelementptr [20 x %FILE]* @__iob, i64 0, i64 1, i32 3 ; <i8*> [#uses=1]
+ %cast274 = getelementptr [34 x i8]* @.LC9, i64 0, i64 0 ; <i8*> [#uses=0]
+ %cast282 = bitcast i8* %reg111 to %FILE* ; <%FILE*> [#uses=0]
+ call void @exit( i32 1 )
+ br label %UnifiedExitNode
+
+bb5: ; preds = %bb3
+ %reg107-idxcast1 = sext i32 %fd to i64 ; <i64> [#uses=2]
+ %reg107-idxcast2 = sext i32 %fd to i64 ; <i64> [#uses=1]
+ %reg1311 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast2 ; <%spec_fd_t*> [#uses=1]
+ %idx1 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <i32*> [#uses=1]
+ %reg1321 = load i32* %idx1 ; <i32> [#uses=3]
+ %idx2 = getelementptr %spec_fd_t* %reg1311, i64 0, i32 1 ; <i32*> [#uses=1]
+ %reg1331 = load i32* %idx2 ; <i32> [#uses=1]
+ %cond270 = icmp slt i32 %reg1321, %reg1331 ; <i1> [#uses=1]
+ br i1 %cond270, label %bb9, label %bb6
+
+bb6: ; preds = %bb5
+ %reg134 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond271 = icmp sle i32 %reg134, 4 ; <i1> [#uses=1]
+ br i1 %cond271, label %bb8, label %bb7
+
+bb7: ; preds = %bb6
+ %cast277 = getelementptr [4 x i8]* @.LC10, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb6
+ br label %UnifiedExitNode
+
+bb9: ; preds = %bb5
+ %reg107-idxcast3 = sext i32 %fd to i64 ; <i64> [#uses=1]
+ %idx3 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast3, i32 3 ; <i8**> [#uses=1]
+ %reg1601 = load i8** %idx3 ; <i8*> [#uses=1]
+ %reg132-idxcast1 = sext i32 %reg1321 to i64 ; <i64> [#uses=1]
+ %idx4 = getelementptr i8* %reg1601, i64 %reg132-idxcast1 ; <i8*> [#uses=1]
+ %reg1621 = load i8* %idx4 ; <i8> [#uses=2]
+ %cast108 = zext i8 %reg1621 to i64 ; <i64> [#uses=0]
+ %reg157 = add i32 %reg1321, 1 ; <i32> [#uses=1]
+ %idx5 = getelementptr [3 x %spec_fd_t]* @spec_fd, i64 0, i64 %reg107-idxcast1, i32 2 ; <i32*> [#uses=1]
+ store i32 %reg157, i32* %idx5
+ %reg163 = load i32* @dbglvl ; <i32> [#uses=1]
+ %cond272 = icmp sle i32 %reg163, 4 ; <i1> [#uses=1]
+ br i1 %cond272, label %bb11, label %bb10
+
+bb10: ; preds = %bb9
+ %cast279 = getelementptr [4 x i8]* @.LC11, i64 0, i64 0 ; <i8*> [#uses=0]
+ br label %bb11
+
+bb11: ; preds = %bb10, %bb9
+ %cast291 = zext i8 %reg1621 to i32 ; <i32> [#uses=1]
+ br label %UnifiedExitNode
+
+UnifiedExitNode: ; preds = %bb11, %bb8, %bb4
+ %UnifiedRetVal = phi i32 [ 42, %bb4 ], [ -1, %bb8 ], [ %cast291, %bb11 ] ; <i32> [#uses=1]
+ ret i32 %UnifiedRetVal
+}
+
+declare i32 @puts(i8*)
+
+declare i32 @printf(i8*, ...)
diff --git a/src/LLVM/test/Transforms/ADCE/dce_pure_call.ll b/src/LLVM/test/Transforms/ADCE/dce_pure_call.ll
new file mode 100644
index 0000000..dcc50fc
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/dce_pure_call.ll
@@ -0,0 +1,8 @@
+; RUN: opt -adce -S < %s | not grep call
+
+declare i32 @strlen(i8*) readonly nounwind
+
+define void @test() {
+ call i32 @strlen( i8* null ) ; <i32>:1 [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ADCE/dce_pure_invoke.ll b/src/LLVM/test/Transforms/ADCE/dce_pure_invoke.ll
new file mode 100644
index 0000000..3d01b05
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/dce_pure_invoke.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -adce -S | grep null
+
+declare i32 @strlen(i8*) readnone
+
+define i32 @test() {
+ ; invoke of pure function should not be deleted!
+ invoke i32 @strlen( i8* null ) readnone
+ to label %Cont unwind label %Other ; <i32>:1 [#uses=0]
+
+Cont: ; preds = %0
+ ret i32 0
+
+Other: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 1
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/ADCE/dg.exp b/src/LLVM/test/Transforms/ADCE/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/ADCE/unreachable-function.ll b/src/LLVM/test/Transforms/ADCE/unreachable-function.ll
new file mode 100644
index 0000000..0673698
--- /dev/null
+++ b/src/LLVM/test/Transforms/ADCE/unreachable-function.ll
@@ -0,0 +1,5 @@
+; RUN: opt < %s -adce -disable-output
+
+define void @test() {
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll b/src/LLVM/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll
new file mode 100644
index 0000000..e740b29
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/2008-02-01-ReturnAttrs.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -argpromotion -S | grep nounwind | count 2
+
+define internal i32 @deref(i32* %x) nounwind {
+entry:
+ %tmp2 = load i32* %x, align 4 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @f(i32 %x) {
+entry:
+ %x_addr = alloca i32 ; <i32*> [#uses=2]
+ store i32 %x, i32* %x_addr, align 4
+ %tmp1 = call i32 @deref( i32* %x_addr ) nounwind ; <i32> [#uses=1]
+ ret i32 %tmp1
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/2008-07-02-array-indexing.ll b/src/LLVM/test/Transforms/ArgumentPromotion/2008-07-02-array-indexing.ll
new file mode 100644
index 0000000..d7d5eb5
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/2008-07-02-array-indexing.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -argpromotion -S > %t
+; RUN: cat %t | grep {define.*@callee(.*i32\\*}
+; PR2498
+
+; This test tries to convince argpromotion about promoting the load from %A + 2,
+; because there is a load of %A in the entry block
+define internal i32 @callee(i1 %C, i32* %A) {
+entry:
+ ; Unconditonally load the element at %A
+ %A.0 = load i32* %A
+ br i1 %C, label %T, label %F
+T:
+ ret i32 %A.0
+F:
+ ; Load the element at offset two from %A. This should not be promoted!
+ %A.2 = getelementptr i32* %A, i32 2
+ %R = load i32* %A.2
+ ret i32 %R
+}
+
+define i32 @foo() {
+ %X = call i32 @callee(i1 false, i32* null) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-07-CGUpdate.ll b/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-07-CGUpdate.ll
new file mode 100644
index 0000000..7ee6654
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-07-CGUpdate.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -inline -argpromotion -disable-output
+
+define internal fastcc i32 @hash(i32* %ts, i32 %mod) nounwind {
+entry:
+ unreachable
+}
+
+define void @encode(i32* %m, i32* %ts, i32* %new) nounwind {
+entry:
+ %0 = call fastcc i32 @hash( i32* %ts, i32 0 ) nounwind ; <i32> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-08-CGUpdateSelfEdge.ll b/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-08-CGUpdateSelfEdge.ll
new file mode 100644
index 0000000..aff917c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/2008-09-08-CGUpdateSelfEdge.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -argpromotion -disable-output
+
+define internal fastcc i32 @term_SharingList(i32* %Term, i32* %List) nounwind {
+entry:
+ br i1 false, label %bb, label %bb5
+
+bb: ; preds = %entry
+ %0 = call fastcc i32 @term_SharingList( i32* null, i32* %List ) nounwind ; <i32> [#uses=0]
+ unreachable
+
+bb5: ; preds = %entry
+ ret i32 0
+}
+
+define i32 @term_Sharing(i32* %Term) nounwind {
+entry:
+ br i1 false, label %bb.i, label %bb14
+
+bb.i: ; preds = %entry
+ %0 = call fastcc i32 @term_SharingList( i32* null, i32* null ) nounwind ; <i32> [#uses=0]
+ ret i32 1
+
+bb14: ; preds = %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/aggregate-promote.ll b/src/LLVM/test/Transforms/ArgumentPromotion/aggregate-promote.ll
new file mode 100644
index 0000000..5bcc024
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/aggregate-promote.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -argpromotion -instcombine -S | not grep load
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+%QuadTy = type { i32, i32, i32, i32 }
+@G = constant %QuadTy {
+ i32 0,
+ i32 0,
+ i32 17,
+ i32 25 } ; <%QuadTy*> [#uses=1]
+
+define internal i32 @test(%QuadTy* %P) {
+ %A = getelementptr %QuadTy* %P, i64 0, i32 3 ; <i32*> [#uses=1]
+ %B = getelementptr %QuadTy* %P, i64 0, i32 2 ; <i32*> [#uses=1]
+ %a = load i32* %A ; <i32> [#uses=1]
+ %b = load i32* %B ; <i32> [#uses=1]
+ %V = add i32 %a, %b ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define i32 @caller() {
+ %V = call i32 @test( %QuadTy* @G ) ; <i32> [#uses=1]
+ ret i32 %V
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/attrs.ll b/src/LLVM/test/Transforms/ArgumentPromotion/attrs.ll
new file mode 100644
index 0000000..49c0750
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/attrs.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -argpromotion -S | grep zeroext
+
+ %struct.ss = type { i32, i64 }
+
+define internal void @f(%struct.ss* byval %b, i32* byval %X, i32 %i) nounwind {
+entry:
+ %tmp = getelementptr %struct.ss* %b, i32 0, i32 0
+ %tmp1 = load i32* %tmp, align 4
+ %tmp2 = add i32 %tmp1, 1
+ store i32 %tmp2, i32* %tmp, align 4
+
+ store i32 0, i32* %X
+ ret void
+}
+
+define i32 @test(i32* %X) {
+entry:
+ %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
+ %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp1, align 8
+ %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
+ store i64 2, i64* %tmp4, align 4
+ call void @f( %struct.ss* byval %S, i32* byval %X, i32 zeroext 0)
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/basictest.ll b/src/LLVM/test/Transforms/ArgumentPromotion/basictest.ll
new file mode 100644
index 0000000..20179dd
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/basictest.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -basicaa -argpromotion -mem2reg -S | not grep alloca
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+define internal i32 @test(i32* %X, i32* %Y) {
+ %A = load i32* %X ; <i32> [#uses=1]
+ %B = load i32* %Y ; <i32> [#uses=1]
+ %C = add i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define internal i32 @caller(i32* %B) {
+ %A = alloca i32 ; <i32*> [#uses=2]
+ store i32 1, i32* %A
+ %C = call i32 @test( i32* %A, i32* %B ) ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @callercaller() {
+ %B = alloca i32 ; <i32*> [#uses=2]
+ store i32 2, i32* %B
+ %X = call i32 @caller( i32* %B ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/byval-2.ll b/src/LLVM/test/Transforms/ArgumentPromotion/byval-2.ll
new file mode 100644
index 0000000..bd62c68
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/byval-2.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -argpromotion -S | grep -F {i32* byval} | count 2
+; Argpromote + scalarrepl should change this to passing the two integers by value.
+
+ %struct.ss = type { i32, i64 }
+
+define internal void @f(%struct.ss* byval %b, i32* byval %X) nounwind {
+entry:
+ %tmp = getelementptr %struct.ss* %b, i32 0, i32 0
+ %tmp1 = load i32* %tmp, align 4
+ %tmp2 = add i32 %tmp1, 1
+ store i32 %tmp2, i32* %tmp, align 4
+
+ store i32 0, i32* %X
+ ret void
+}
+
+define i32 @test(i32* %X) {
+entry:
+ %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
+ %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp1, align 8
+ %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
+ store i64 2, i64* %tmp4, align 4
+ call void @f( %struct.ss* byval %S, i32* byval %X)
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/byval.ll b/src/LLVM/test/Transforms/ArgumentPromotion/byval.ll
new file mode 100644
index 0000000..44b26fc
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/byval.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -argpromotion -scalarrepl -S | not grep load
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+; Argpromote + scalarrepl should change this to passing the two integers by value.
+
+ %struct.ss = type { i32, i64 }
+
+define internal void @f(%struct.ss* byval %b) nounwind {
+entry:
+ %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
+ %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
+ store i32 %tmp2, i32* %tmp, align 4
+ ret void
+}
+
+define i32 @main() nounwind {
+entry:
+ %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
+ %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp1, align 8
+ %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
+ store i64 2, i64* %tmp4, align 4
+ call void @f( %struct.ss* byval %S ) nounwind
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/callgraph-update.ll b/src/LLVM/test/Transforms/ArgumentPromotion/callgraph-update.ll
new file mode 100644
index 0000000..989043d
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/callgraph-update.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -argpromotion -simplifycfg -constmerge | llvm-dis
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+%struct.VEC2 = type { double, double, double }
+%struct.VERTEX = type { %struct.VEC2, %struct.VERTEX*, %struct.VERTEX* }
+%struct.edge_rec = type { %struct.VERTEX*, %struct.edge_rec*, i32, i8* }
+
+declare %struct.edge_rec* @alloc_edge() nounwind ssp
+
+define i64 @build_delaunay(%struct.VERTEX* %tree, %struct.VERTEX* %extra) nounwind ssp {
+entry:
+ br i1 undef, label %bb11, label %bb12
+
+bb11: ; preds = %bb10
+ %a = call %struct.edge_rec* @alloc_edge() nounwind ; <%struct.edge_rec*> [#uses=0]
+ ret i64 123
+
+bb12: ; preds = %bb10
+ %b = call %struct.edge_rec* @alloc_edge() nounwind ; <%struct.edge_rec*> [#uses=1]
+ %c = ptrtoint %struct.edge_rec* %b to i64
+ ret i64 %c
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/chained.ll b/src/LLVM/test/Transforms/ArgumentPromotion/chained.ll
new file mode 100644
index 0000000..2c500ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/chained.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -argpromotion -instcombine -S | not grep load
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@G1 = constant i32 0 ; <i32*> [#uses=1]
+@G2 = constant i32* @G1 ; <i32**> [#uses=1]
+
+define internal i32 @test(i32** %X) {
+ %Y = load i32** %X ; <i32*> [#uses=1]
+ %X.upgrd.1 = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %X.upgrd.1
+}
+
+define i32 @caller(i32** %P) {
+ %X = call i32 @test( i32** @G2 ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/control-flow.ll b/src/LLVM/test/Transforms/ArgumentPromotion/control-flow.ll
new file mode 100644
index 0000000..722c1ca
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/control-flow.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -argpromotion -S | \
+; RUN: not grep {load i32\* null}
+
+define internal i32 @callee(i1 %C, i32* %P) {
+ br i1 %C, label %T, label %F
+
+T: ; preds = %0
+ ret i32 17
+
+F: ; preds = %0
+ %X = load i32* %P ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+define i32 @foo() {
+ %X = call i32 @callee( i1 true, i32* null ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/control-flow2.ll b/src/LLVM/test/Transforms/ArgumentPromotion/control-flow2.ll
new file mode 100644
index 0000000..59b4733
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/control-flow2.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -argpromotion -S | \
+; RUN: grep {load i32\\* %A}
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+define internal i32 @callee(i1 %C, i32* %P) {
+ br i1 %C, label %T, label %F
+
+T: ; preds = %0
+ ret i32 17
+
+F: ; preds = %0
+ %X = load i32* %P ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+define i32 @foo() {
+ %A = alloca i32 ; <i32*> [#uses=2]
+ store i32 17, i32* %A
+ %X = call i32 @callee( i1 false, i32* %A ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/crash.ll b/src/LLVM/test/Transforms/ArgumentPromotion/crash.ll
new file mode 100644
index 0000000..fed002a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/crash.ll
@@ -0,0 +1,59 @@
+; rdar://7879828
+; RUN: opt -inline -argpromotion %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define void @foo() {
+ invoke void @foo2()
+ to label %if.end432 unwind label %for.end520
+
+if.end432:
+ unreachable
+
+for.end520:
+ unreachable
+}
+
+define internal void @foo2() ssp {
+ %call7 = call fastcc i8* @foo3(i1 (i8*)* @foo4)
+ %call58 = call fastcc i8* @foo3(i1 (i8*)* @foo5)
+ unreachable
+}
+
+define internal fastcc i8* @foo3(i1 (i8*)* %Pred) {
+entry:
+ unreachable
+}
+
+define internal i1 @foo4(i8* %O) nounwind {
+entry:
+ %call = call zeroext i1 @foo5(i8* %O) ; <i1> [#uses=0]
+ unreachable
+}
+
+define internal i1 @foo5(i8* %O) nounwind {
+entry:
+ ret i1 undef
+}
+
+
+; PR8932 - infinite promotion.
+%0 = type { %0* }
+
+define i32 @test2(i32 %a) {
+init:
+ %0 = alloca %0
+ %1 = alloca %0
+ %2 = call i32 @"clay_assign(Chain, Chain)"(%0* %0, %0* %1)
+ ret i32 0
+}
+
+define internal i32 @"clay_assign(Chain, Chain)"(%0* %c, %0* %d) {
+init:
+ %0 = getelementptr %0* %d, i32 0, i32 0
+ %1 = load %0** %0
+ %2 = getelementptr %0* %c, i32 0, i32 0
+ %3 = load %0** %2
+ %4 = call i32 @"clay_assign(Chain, Chain)"(%0* %3, %0* %1)
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/dg.exp b/src/LLVM/test/Transforms/ArgumentPromotion/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/ArgumentPromotion/pr3085.ll b/src/LLVM/test/Transforms/ArgumentPromotion/pr3085.ll
new file mode 100644
index 0000000..3048c60
--- /dev/null
+++ b/src/LLVM/test/Transforms/ArgumentPromotion/pr3085.ll
@@ -0,0 +1,1944 @@
+; RUN: opt < %s -disable-output -loop-extract-single -loop-rotate -loop-reduce -argpromotion
+; PR 3085
+
+ %struct.Lit = type { i8 }
+
+define fastcc %struct.Lit* @import_lit(i32 %lit) nounwind {
+entry:
+ br i1 false, label %bb, label %bb1
+
+bb: ; preds = %entry
+ unreachable
+
+bb1: ; preds = %entry
+ br label %bb3
+
+bb2: ; preds = %bb3
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ br i1 false, label %bb2, label %bb6
+
+bb6: ; preds = %bb3
+ br i1 false, label %bb.i.i, label %bb1.i.i
+
+bb.i.i: ; preds = %bb6
+ br label %int2lit.exit
+
+bb1.i.i: ; preds = %bb6
+ br label %int2lit.exit
+
+int2lit.exit: ; preds = %bb1.i.i, %bb.i.i
+ ret %struct.Lit* null
+}
+
+define fastcc i32 @picosat_main(i32 %argc, i8** %argv) nounwind {
+entry:
+ br i1 false, label %bb.i, label %picosat_time_stamp.exit
+
+bb.i: ; preds = %entry
+ br label %picosat_time_stamp.exit
+
+picosat_time_stamp.exit: ; preds = %bb.i, %entry
+ br label %bb108
+
+bb: ; preds = %bb108
+ br i1 false, label %bb1, label %bb2
+
+bb1: ; preds = %bb
+ br label %bb106
+
+bb2: ; preds = %bb
+ br i1 false, label %bb3, label %bb4
+
+bb3: ; preds = %bb2
+ br label %bb106
+
+bb4: ; preds = %bb2
+ br i1 false, label %bb5, label %bb6
+
+bb5: ; preds = %bb4
+ br label %bb106
+
+bb6: ; preds = %bb4
+ br i1 false, label %bb7, label %bb8
+
+bb7: ; preds = %bb6
+ br label %bb106
+
+bb8: ; preds = %bb6
+ br i1 false, label %bb106, label %bb10
+
+bb10: ; preds = %bb8
+ br i1 false, label %bb106, label %bb12
+
+bb12: ; preds = %bb10
+ br i1 false, label %bb106, label %bb14
+
+bb14: ; preds = %bb12
+ br i1 false, label %bb15, label %bb19
+
+bb15: ; preds = %bb14
+ br i1 false, label %bb16, label %bb17
+
+bb16: ; preds = %bb15
+ br label %bb106
+
+bb17: ; preds = %bb15
+ br label %bb106
+
+bb19: ; preds = %bb14
+ br i1 false, label %bb20, label %bb28
+
+bb20: ; preds = %bb19
+ br i1 false, label %bb21, label %bb22
+
+bb21: ; preds = %bb20
+ br label %bb106
+
+bb22: ; preds = %bb20
+ br i1 false, label %bb106, label %bb24
+
+bb24: ; preds = %bb22
+ br i1 false, label %bb106, label %bb26
+
+bb26: ; preds = %bb24
+ br label %bb106
+
+bb28: ; preds = %bb19
+ br i1 false, label %bb29, label %bb35
+
+bb29: ; preds = %bb28
+ br i1 false, label %bb30, label %bb31
+
+bb30: ; preds = %bb29
+ br label %bb106
+
+bb31: ; preds = %bb29
+ br i1 false, label %bb32, label %bb33
+
+bb32: ; preds = %bb31
+ br label %bb106
+
+bb33: ; preds = %bb31
+ br label %bb106
+
+bb35: ; preds = %bb28
+ br i1 false, label %bb36, label %bb40
+
+bb36: ; preds = %bb35
+ br i1 false, label %bb37, label %bb38
+
+bb37: ; preds = %bb36
+ br label %bb106
+
+bb38: ; preds = %bb36
+ br label %bb106
+
+bb40: ; preds = %bb35
+ br i1 false, label %bb41, label %bb49
+
+bb41: ; preds = %bb40
+ br i1 false, label %bb43, label %bb42
+
+bb42: ; preds = %bb41
+ br label %bb106
+
+bb43: ; preds = %bb41
+ br i1 false, label %bb44, label %bb45
+
+bb44: ; preds = %bb43
+ br label %bb106
+
+bb45: ; preds = %bb43
+ br i1 false, label %bb46, label %bb47
+
+bb46: ; preds = %bb45
+ br label %bb106
+
+bb47: ; preds = %bb45
+ br label %bb106
+
+bb49: ; preds = %bb40
+ br i1 false, label %bb50, label %bb56
+
+bb50: ; preds = %bb49
+ br i1 false, label %bb52, label %bb51
+
+bb51: ; preds = %bb50
+ br label %bb106
+
+bb52: ; preds = %bb50
+ br i1 false, label %bb53, label %bb54
+
+bb53: ; preds = %bb52
+ br label %bb106
+
+bb54: ; preds = %bb52
+ br label %bb106
+
+bb56: ; preds = %bb49
+ br i1 false, label %bb57, label %bb63
+
+bb57: ; preds = %bb56
+ br i1 false, label %bb59, label %bb58
+
+bb58: ; preds = %bb57
+ br label %bb106
+
+bb59: ; preds = %bb57
+ br i1 false, label %bb60, label %bb61
+
+bb60: ; preds = %bb59
+ br label %bb106
+
+bb61: ; preds = %bb59
+ br label %bb106
+
+bb63: ; preds = %bb56
+ br i1 false, label %bb64, label %bb70
+
+bb64: ; preds = %bb63
+ br i1 false, label %bb66, label %bb65
+
+bb65: ; preds = %bb64
+ br label %bb106
+
+bb66: ; preds = %bb64
+ br i1 false, label %bb67, label %bb68
+
+bb67: ; preds = %bb66
+ br label %bb106
+
+bb68: ; preds = %bb66
+ br label %bb106
+
+bb70: ; preds = %bb63
+ br i1 false, label %bb71, label %bb79
+
+bb71: ; preds = %bb70
+ br i1 false, label %bb73, label %bb72
+
+bb72: ; preds = %bb71
+ br label %bb106
+
+bb73: ; preds = %bb71
+ br i1 false, label %bb74, label %bb75
+
+bb74: ; preds = %bb73
+ br label %bb106
+
+bb75: ; preds = %bb73
+ br i1 false, label %bb76, label %bb77
+
+bb76: ; preds = %bb75
+ br label %bb106
+
+bb77: ; preds = %bb75
+ br label %bb106
+
+bb79: ; preds = %bb70
+ br i1 false, label %bb80, label %bb86
+
+bb80: ; preds = %bb79
+ br i1 false, label %bb82, label %bb81
+
+bb81: ; preds = %bb80
+ br label %bb106
+
+bb82: ; preds = %bb80
+ br i1 false, label %bb83, label %bb84
+
+bb83: ; preds = %bb82
+ br label %bb106
+
+bb84: ; preds = %bb82
+ br label %bb106
+
+bb86: ; preds = %bb79
+ br i1 false, label %bb87, label %bb93
+
+bb87: ; preds = %bb86
+ br i1 false, label %bb89, label %bb88
+
+bb88: ; preds = %bb87
+ br label %bb106
+
+bb89: ; preds = %bb87
+ br i1 false, label %bb90, label %bb91
+
+bb90: ; preds = %bb89
+ br label %bb106
+
+bb91: ; preds = %bb89
+ br label %bb106
+
+bb93: ; preds = %bb86
+ br i1 false, label %bb94, label %bb95
+
+bb94: ; preds = %bb93
+ br label %bb106
+
+bb95: ; preds = %bb93
+ br i1 false, label %bb98, label %bb97
+
+bb97: ; preds = %bb95
+ br label %bb106
+
+bb98: ; preds = %bb95
+ br i1 false, label %bb103, label %bb1.i24
+
+bb1.i24: ; preds = %bb98
+ br i1 false, label %bb99, label %bb103
+
+bb99: ; preds = %bb1.i24
+ br i1 false, label %bb101, label %bb100
+
+bb100: ; preds = %bb99
+ br label %bb102
+
+bb101: ; preds = %bb99
+ br label %bb102
+
+bb102: ; preds = %bb101, %bb100
+ br label %bb106
+
+bb103: ; preds = %bb1.i24, %bb98
+ br i1 false, label %bb104, label %bb105
+
+bb104: ; preds = %bb103
+ br label %bb106
+
+bb105: ; preds = %bb103
+ br label %bb106
+
+bb106: ; preds = %bb105, %bb104, %bb102, %bb97, %bb94, %bb91, %bb90, %bb88, %bb84, %bb83, %bb81, %bb77, %bb76, %bb74, %bb72, %bb68, %bb67, %bb65, %bb61, %bb60, %bb58, %bb54, %bb53, %bb51, %bb47, %bb46, %bb44, %bb42, %bb38, %bb37, %bb33, %bb32, %bb30, %bb26, %bb24, %bb22, %bb21, %bb17, %bb16, %bb12, %bb10, %bb8, %bb7, %bb5, %bb3, %bb1
+ br i1 false, label %bb108, label %bb110
+
+bb108: ; preds = %bb106, %picosat_time_stamp.exit
+ br i1 false, label %bb, label %bb110
+
+bb110: ; preds = %bb108, %bb106
+ br i1 false, label %bb112, label %bb171
+
+bb112: ; preds = %bb110
+ br i1 false, label %bb114, label %bb113
+
+bb113: ; preds = %bb112
+ br label %bb114
+
+bb114: ; preds = %bb113, %bb112
+ br i1 false, label %bb.i.i35, label %bb1.i.i36
+
+bb.i.i35: ; preds = %bb114
+ unreachable
+
+bb1.i.i36: ; preds = %bb114
+ br i1 false, label %bb5.i.i.i41, label %bb6.i.i.i42
+
+bb5.i.i.i41: ; preds = %bb1.i.i36
+ unreachable
+
+bb6.i.i.i42: ; preds = %bb1.i.i36
+ br i1 false, label %bb7.i.i.i43, label %bb8.i.i.i44
+
+bb7.i.i.i43: ; preds = %bb6.i.i.i42
+ br label %bb8.i.i.i44
+
+bb8.i.i.i44: ; preds = %bb7.i.i.i43, %bb6.i.i.i42
+ br i1 false, label %picosat_init.exit, label %bb14.i.i
+
+bb14.i.i: ; preds = %bb8.i.i.i44
+ br label %picosat_init.exit
+
+picosat_init.exit: ; preds = %bb14.i.i, %bb8.i.i.i44
+ br i1 false, label %bb116, label %bb115
+
+bb115: ; preds = %picosat_init.exit
+ br label %bb116
+
+bb116: ; preds = %bb115, %picosat_init.exit
+ br i1 false, label %bb119, label %bb118
+
+bb118: ; preds = %bb116
+ br label %bb119
+
+bb119: ; preds = %bb118, %bb116
+ br i1 false, label %bb121, label %bb120
+
+bb120: ; preds = %bb119
+ br label %bb121
+
+bb121: ; preds = %bb120, %bb119
+ br i1 false, label %bb126, label %bb122
+
+bb122: ; preds = %bb121
+ br label %bb126
+
+bb126: ; preds = %bb122, %bb121
+ br i1 false, label %bb128, label %bb127
+
+bb127: ; preds = %bb126
+ br label %bb128
+
+bb128: ; preds = %bb127, %bb126
+ br label %SKIP_COMMENTS.i
+
+SKIP_COMMENTS.i.loopexit: ; preds = %bb.i149, %bb.i149
+ br label %SKIP_COMMENTS.i.backedge
+
+SKIP_COMMENTS.i: ; preds = %SKIP_COMMENTS.i.backedge, %bb128
+ br i1 false, label %bb.i149.preheader, label %bb3.i152
+
+bb.i149.preheader: ; preds = %SKIP_COMMENTS.i
+ br label %bb.i149
+
+bb.i149: ; preds = %bb.i149, %bb.i149.preheader
+ switch i32 0, label %bb.i149 [
+ i32 -1, label %SKIP_COMMENTS.i.loopexit
+ i32 10, label %SKIP_COMMENTS.i.loopexit
+ ]
+
+bb3.i152: ; preds = %SKIP_COMMENTS.i
+ br i1 false, label %bb4.i153, label %SKIP_COMMENTS.i.backedge
+
+SKIP_COMMENTS.i.backedge: ; preds = %bb3.i152, %SKIP_COMMENTS.i.loopexit
+ br label %SKIP_COMMENTS.i
+
+bb4.i153: ; preds = %bb3.i152
+ br i1 false, label %bb5.i154, label %bb129
+
+bb5.i154: ; preds = %bb4.i153
+ br i1 false, label %bb129, label %bb6.i155.preheader
+
+bb6.i155.preheader: ; preds = %bb5.i154
+ br label %bb6.i155
+
+bb6.i155: ; preds = %bb6.i155, %bb6.i155.preheader
+ br i1 false, label %bb7.i156, label %bb6.i155
+
+bb7.i156: ; preds = %bb6.i155
+ br i1 false, label %bb8.i157, label %bb129
+
+bb8.i157: ; preds = %bb7.i156
+ br i1 false, label %bb9.i158, label %bb129
+
+bb9.i158: ; preds = %bb8.i157
+ br i1 false, label %bb10.i159, label %bb129
+
+bb10.i159: ; preds = %bb9.i158
+ br i1 false, label %bb129, label %bb11.i160.preheader
+
+bb11.i160.preheader: ; preds = %bb10.i159
+ br label %bb11.i160
+
+bb11.i160: ; preds = %bb11.i160, %bb11.i160.preheader
+ br i1 false, label %bb12.i161, label %bb11.i160
+
+bb12.i161: ; preds = %bb11.i160
+ br i1 false, label %bb129, label %bb15.i165.preheader
+
+bb15.i165.preheader: ; preds = %bb12.i161
+ br label %bb15.i165
+
+bb14.i163: ; preds = %bb15.i165
+ br label %bb15.i165
+
+bb15.i165: ; preds = %bb14.i163, %bb15.i165.preheader
+ br i1 false, label %bb16.i166, label %bb14.i163
+
+bb16.i166: ; preds = %bb15.i165
+ br i1 false, label %bb129, label %bb17.i167.preheader
+
+bb17.i167.preheader: ; preds = %bb16.i166
+ br label %bb17.i167
+
+bb17.i167: ; preds = %bb17.i167, %bb17.i167.preheader
+ br i1 false, label %bb18.i168, label %bb17.i167
+
+bb18.i168: ; preds = %bb17.i167
+ br i1 false, label %bb129, label %bb21.i172.preheader
+
+bb21.i172.preheader: ; preds = %bb18.i168
+ br label %bb21.i172
+
+bb20.i170: ; preds = %bb21.i172
+ br label %bb21.i172
+
+bb21.i172: ; preds = %bb20.i170, %bb21.i172.preheader
+ br i1 false, label %bb22.i173, label %bb20.i170
+
+bb22.i173: ; preds = %bb21.i172
+ br i1 false, label %bb24.i175, label %bb129
+
+bb24.i175: ; preds = %bb22.i173
+ br i1 false, label %bb26.i180, label %bb25.i176
+
+bb25.i176: ; preds = %bb24.i175
+ br label %bb26.i180
+
+bb26.i180: ; preds = %bb25.i176, %bb24.i175
+ br i1 false, label %bb.i.i181, label %bb3.i.i184.preheader
+
+bb.i.i181: ; preds = %bb26.i180
+ br label %bb3.i.i184.preheader
+
+bb3.i.i184.preheader: ; preds = %bb.i.i181, %bb26.i180
+ br label %bb3.i.i184
+
+bb2.i.i183: ; preds = %bb3.i.i184
+ br label %bb3.i.i184
+
+bb3.i.i184: ; preds = %bb2.i.i183, %bb3.i.i184.preheader
+ br i1 false, label %bb2.i.i183, label %bb4.i.i185
+
+bb4.i.i185: ; preds = %bb3.i.i184
+ br i1 false, label %bb.i.i.i186, label %picosat_adjust.exit.i
+
+bb.i.i.i186: ; preds = %bb4.i.i185
+ br label %picosat_adjust.exit.i
+
+picosat_adjust.exit.i: ; preds = %bb.i.i.i186, %bb4.i.i185
+ br i1 false, label %bb28.i188, label %bb27.i187
+
+bb27.i187: ; preds = %picosat_adjust.exit.i
+ br label %bb28.i188
+
+bb28.i188: ; preds = %bb27.i187, %picosat_adjust.exit.i
+ br label %READ_LITERAL.i.outer
+
+READ_LITERAL.i.outer: ; preds = %READ_LITERAL.i.outer.backedge, %bb28.i188
+ br label %READ_LITERAL.i
+
+READ_LITERAL.i.loopexit: ; preds = %bb29.i189, %bb29.i189
+ br label %READ_LITERAL.i.backedge
+
+READ_LITERAL.i: ; preds = %READ_LITERAL.i.backedge, %READ_LITERAL.i.outer
+ switch i32 0, label %bb39.i199 [
+ i32 99, label %bb29.i189.preheader
+ i32 -1, label %bb33.i193
+ ]
+
+bb29.i189.preheader: ; preds = %READ_LITERAL.i
+ br label %bb29.i189
+
+bb29.i189: ; preds = %bb29.i189, %bb29.i189.preheader
+ switch i32 0, label %bb29.i189 [
+ i32 -1, label %READ_LITERAL.i.loopexit
+ i32 10, label %READ_LITERAL.i.loopexit
+ ]
+
+bb33.i193: ; preds = %READ_LITERAL.i
+ br i1 false, label %bb35.i195, label %parse.exit
+
+bb35.i195: ; preds = %bb33.i193
+ br i1 false, label %bb38.i198, label %parse.exit
+
+bb38.i198: ; preds = %bb35.i195
+ br label %parse.exit
+
+bb39.i199: ; preds = %READ_LITERAL.i
+ br i1 false, label %bb40.i200, label %READ_LITERAL.i.backedge
+
+READ_LITERAL.i.backedge: ; preds = %bb39.i199, %READ_LITERAL.i.loopexit
+ br label %READ_LITERAL.i
+
+bb40.i200: ; preds = %bb39.i199
+ br i1 false, label %bb41.i201, label %bb42.i202
+
+bb41.i201: ; preds = %bb40.i200
+ br label %bb42.i202
+
+bb42.i202: ; preds = %bb41.i201, %bb40.i200
+ br i1 false, label %parse.exit.loopexit, label %bb46.i.preheader
+
+bb46.i.preheader: ; preds = %bb42.i202
+ br label %bb46.i
+
+bb45.i: ; preds = %bb46.i
+ br label %bb46.i
+
+bb46.i: ; preds = %bb45.i, %bb46.i.preheader
+ br i1 false, label %bb47.i, label %bb45.i
+
+bb47.i: ; preds = %bb46.i
+ br i1 false, label %parse.exit.loopexit, label %bb50.i
+
+bb50.i: ; preds = %bb47.i
+ br i1 false, label %bb55.i, label %bb51.i
+
+bb51.i: ; preds = %bb50.i
+ br i1 false, label %parse.exit.loopexit, label %bb54.i
+
+bb54.i: ; preds = %bb51.i
+ br label %bb56.i
+
+bb55.i: ; preds = %bb50.i
+ br label %bb56.i
+
+bb56.i: ; preds = %bb55.i, %bb54.i
+ br i1 false, label %bb3.i11.i, label %bb.i8.i
+
+bb.i8.i: ; preds = %bb56.i
+ br i1 false, label %bb1.i9.i, label %bb3.i11.i
+
+bb1.i9.i: ; preds = %bb.i8.i
+ br i1 false, label %bb3.i11.i, label %bb2.i10.i
+
+bb2.i10.i: ; preds = %bb1.i9.i
+ unreachable
+
+bb3.i11.i: ; preds = %bb1.i9.i, %bb.i8.i, %bb56.i
+ br i1 false, label %bb7.i.i208, label %bb6.i.i207
+
+bb6.i.i207: ; preds = %bb3.i11.i
+ br label %READ_LITERAL.i.outer.backedge
+
+bb7.i.i208: ; preds = %bb3.i11.i
+ br i1 false, label %bb53.i.i.i.i.preheader, label %bb.i.i.i.i210.preheader
+
+bb.i.i.i.i210.preheader: ; preds = %bb7.i.i208
+ br label %bb.i.i.i.i210
+
+bb.i.i.i.i210: ; preds = %bb.i.i.i.i210.backedge, %bb.i.i.i.i210.preheader
+ br i1 false, label %bb17.i.i.i.i, label %bb18.i.i.i.i
+
+bb17.i.i.i.i: ; preds = %bb.i.i.i.i210
+ br label %bb18.i.i.i.i
+
+bb18.i.i.i.i: ; preds = %bb17.i.i.i.i, %bb.i.i.i.i210
+ br i1 false, label %bb19.i.i.i.i, label %bb20.i.i.i.i
+
+bb19.i.i.i.i: ; preds = %bb18.i.i.i.i
+ br label %bb20.i.i.i.i
+
+bb20.i.i.i.i: ; preds = %bb19.i.i.i.i, %bb18.i.i.i.i
+ br i1 false, label %bb21.i.i.i.i, label %bb22.i.i.i.i
+
+bb21.i.i.i.i: ; preds = %bb20.i.i.i.i
+ br label %bb22.i.i.i.i
+
+bb22.i.i.i.i: ; preds = %bb21.i.i.i.i, %bb20.i.i.i.i
+ br label %bb23.i.i.i.i.outer
+
+bb23.i.i.i.i.outer: ; preds = %bb28.i.i.i.i, %bb22.i.i.i.i
+ br label %bb23.i.i.i.i
+
+bb23.i.i.i.i: ; preds = %bb23.i.i.i.i, %bb23.i.i.i.i.outer
+ br i1 false, label %bb23.i.i.i.i, label %bb26.i.i.i.i.preheader
+
+bb26.i.i.i.i.preheader: ; preds = %bb23.i.i.i.i
+ br label %bb26.i.i.i.i
+
+bb26.i.i.i.i: ; preds = %bb26.i.i.i.i, %bb26.i.i.i.i.preheader
+ br i1 false, label %bb27.i.i.i.i, label %bb26.i.i.i.i
+
+bb27.i.i.i.i: ; preds = %bb26.i.i.i.i
+ br i1 false, label %bb28.i.i.i.i, label %bb29.i.i.i.i
+
+bb28.i.i.i.i: ; preds = %bb27.i.i.i.i
+ br label %bb23.i.i.i.i.outer
+
+bb29.i.i.i.i: ; preds = %bb27.i.i.i.i
+ br i1 false, label %bb33.i.i.i.i, label %bb44.i.i.i.i
+
+bb33.i.i.i.i: ; preds = %bb29.i.i.i.i
+ br i1 false, label %bb34.i.i.i.i, label %bb38.i.i.i.i
+
+bb34.i.i.i.i: ; preds = %bb33.i.i.i.i
+ br i1 false, label %bb37.i.i.i.i, label %bb35.i.i.i.i
+
+bb35.i.i.i.i: ; preds = %bb34.i.i.i.i
+ br label %bb37.i.i.i.i
+
+bb37.i.i.i.i: ; preds = %bb35.i.i.i.i, %bb34.i.i.i.i
+ br label %bb38.i.i.i.i
+
+bb38.i.i.i.i: ; preds = %bb37.i.i.i.i, %bb33.i.i.i.i
+ br i1 false, label %bb39.i.i.i.i, label %bb43.i.i.i.i
+
+bb39.i.i.i.i: ; preds = %bb38.i.i.i.i
+ br i1 false, label %bb42.i.i.i.i, label %bb40.i.i.i.i
+
+bb40.i.i.i.i: ; preds = %bb39.i.i.i.i
+ br label %bb42.i.i.i.i
+
+bb42.i.i.i.i: ; preds = %bb40.i.i.i.i, %bb39.i.i.i.i
+ br label %bb43.i.i.i.i
+
+bb43.i.i.i.i: ; preds = %bb42.i.i.i.i, %bb38.i.i.i.i
+ br label %bb.i.i.i.i210.backedge
+
+bb.i.i.i.i210.backedge: ; preds = %bb47.i.i.i.i, %bb44.i.i.i.i, %bb43.i.i.i.i
+ br label %bb.i.i.i.i210
+
+bb44.i.i.i.i: ; preds = %bb29.i.i.i.i
+ br i1 false, label %bb.i.i.i.i210.backedge, label %bb46.i.i.i.i
+
+bb46.i.i.i.i: ; preds = %bb44.i.i.i.i
+ br i1 false, label %bb47.i.i.i.i, label %bb53.i.i.i.i.preheader.loopexit
+
+bb53.i.i.i.i.preheader.loopexit: ; preds = %bb46.i.i.i.i
+ br label %bb53.i.i.i.i.preheader
+
+bb53.i.i.i.i.preheader: ; preds = %bb53.i.i.i.i.preheader.loopexit, %bb7.i.i208
+ br label %bb53.i.i.i.i
+
+bb47.i.i.i.i: ; preds = %bb46.i.i.i.i
+ br label %bb.i.i.i.i210.backedge
+
+bb50.i.i.i.i: ; preds = %bb53.i.i.i.i
+ br i1 false, label %bb51.i.i.i.i, label %bb52.i.i.i.i
+
+bb51.i.i.i.i: ; preds = %bb50.i.i.i.i
+ br label %bb52.i.i.i.i
+
+bb52.i.i.i.i: ; preds = %bb51.i.i.i.i, %bb50.i.i.i.i
+ br label %bb53.i.i.i.i
+
+bb53.i.i.i.i: ; preds = %bb52.i.i.i.i, %bb53.i.i.i.i.preheader
+ br i1 false, label %bb50.i.i.i.i, label %bb59.i.i.i.i.preheader
+
+bb59.i.i.i.i.preheader: ; preds = %bb53.i.i.i.i
+ br label %bb59.i.i.i.i
+
+bb55.i.i.i.i: ; preds = %bb59.i.i.i.i
+ br label %bb57.i.i.i.i
+
+bb56.i.i.i.i: ; preds = %bb57.i.i.i.i
+ br label %bb57.i.i.i.i
+
+bb57.i.i.i.i: ; preds = %bb56.i.i.i.i, %bb55.i.i.i.i
+ br i1 false, label %bb56.i.i.i.i, label %bb58.i.i.i.i
+
+bb58.i.i.i.i: ; preds = %bb57.i.i.i.i
+ br label %bb59.i.i.i.i
+
+bb59.i.i.i.i: ; preds = %bb58.i.i.i.i, %bb59.i.i.i.i.preheader
+ br i1 false, label %bb60.i.i.i.i, label %bb55.i.i.i.i
+
+bb60.i.i.i.i: ; preds = %bb59.i.i.i.i
+ br label %bb69.i.i.i.i
+
+bb61.i.i.i.i: ; preds = %bb69.i.i.i.i
+ br i1 false, label %bb68.i.i.i.i, label %bb62.i.i.i.i
+
+bb62.i.i.i.i: ; preds = %bb61.i.i.i.i
+ br i1 false, label %bb63.i.i.i.i, label %bb65.i.i.i.i
+
+bb63.i.i.i.i: ; preds = %bb62.i.i.i.i
+ br i1 false, label %bb.i.i12.i, label %bb65.i.i.i.i
+
+bb65.i.i.i.i: ; preds = %bb63.i.i.i.i, %bb62.i.i.i.i
+ br i1 false, label %bb.i.i12.i, label %bb67.i.i.i.i
+
+bb67.i.i.i.i: ; preds = %bb65.i.i.i.i
+ br label %bb68.i.i.i.i
+
+bb68.i.i.i.i: ; preds = %bb67.i.i.i.i, %bb61.i.i.i.i
+ br label %bb69.i.i.i.i
+
+bb69.i.i.i.i: ; preds = %bb68.i.i.i.i, %bb60.i.i.i.i
+ br i1 false, label %bb61.i.i.i.i, label %bb70.i.i.i.i
+
+bb70.i.i.i.i: ; preds = %bb69.i.i.i.i
+ br label %READ_LITERAL.i.outer.backedge
+
+bb.i.i12.i: ; preds = %bb65.i.i.i.i, %bb63.i.i.i.i
+ br i1 false, label %bb1.i.i.i213, label %bb5.i.i.i218
+
+bb1.i.i.i213: ; preds = %bb.i.i12.i
+ br i1 false, label %bb4.i.i.i217, label %bb2.i.i.i214
+
+bb2.i.i.i214: ; preds = %bb1.i.i.i213
+ br label %bb4.i.i.i217
+
+bb4.i.i.i217: ; preds = %bb2.i.i.i214, %bb1.i.i.i213
+ br label %bb5.i.i.i218
+
+bb5.i.i.i218: ; preds = %bb4.i.i.i217, %bb.i.i12.i
+ br label %READ_LITERAL.i.outer.backedge
+
+READ_LITERAL.i.outer.backedge: ; preds = %bb5.i.i.i218, %bb70.i.i.i.i, %bb6.i.i207
+ br label %READ_LITERAL.i.outer
+
+parse.exit.loopexit: ; preds = %bb51.i, %bb47.i, %bb42.i202
+ br label %parse.exit
+
+parse.exit: ; preds = %parse.exit.loopexit, %bb38.i198, %bb35.i195, %bb33.i193
+ br i1 false, label %bb130, label %bb129
+
+bb129: ; preds = %parse.exit, %bb22.i173, %bb18.i168, %bb16.i166, %bb12.i161, %bb10.i159, %bb9.i158, %bb8.i157, %bb7.i156, %bb5.i154, %bb4.i153
+ br label %bb170
+
+bb130: ; preds = %parse.exit
+ br i1 false, label %bb143, label %bb142.preheader
+
+bb142.preheader: ; preds = %bb130
+ br label %bb142
+
+bb132: ; preds = %bb142
+ br i1 false, label %bb137, label %bb133
+
+bb133: ; preds = %bb132
+ br i1 false, label %bb137, label %bb134
+
+bb134: ; preds = %bb133
+ br i1 false, label %bb137, label %bb135
+
+bb135: ; preds = %bb134
+ br i1 false, label %bb137, label %bb136
+
+bb136: ; preds = %bb135
+ br i1 false, label %bb137, label %bb138
+
+bb137: ; preds = %bb136, %bb135, %bb134, %bb133, %bb132
+ br label %bb141
+
+bb138: ; preds = %bb136
+ br i1 false, label %bb139, label %bb141
+
+bb139: ; preds = %bb138
+ br i1 false, label %bb2.i126, label %picosat_assume.exit
+
+bb2.i126: ; preds = %bb139
+ br i1 false, label %bb5.i130, label %bb3.i127
+
+bb3.i127: ; preds = %bb2.i126
+ br label %bb5.i130
+
+bb5.i130: ; preds = %bb3.i127, %bb2.i126
+ br label %picosat_assume.exit
+
+picosat_assume.exit: ; preds = %bb5.i130, %bb139
+ br i1 false, label %bb141, label %bb140
+
+bb140: ; preds = %picosat_assume.exit
+ br label %bb141
+
+bb141: ; preds = %bb140, %picosat_assume.exit, %bb138, %bb137
+ br label %bb142
+
+bb142: ; preds = %bb141, %bb142.preheader
+ br i1 false, label %bb132, label %bb143.loopexit
+
+bb143.loopexit: ; preds = %bb142
+ br label %bb143
+
+bb143: ; preds = %bb143.loopexit, %bb130
+ br i1 false, label %bb145, label %bb144
+
+bb144: ; preds = %bb143
+ br label %bb11.i
+
+bb5.i114: ; preds = %bb11.i
+ br label %bb11.i
+
+bb11.i: ; preds = %bb5.i114, %bb144
+ br i1 false, label %bb12.i, label %bb5.i114
+
+bb12.i: ; preds = %bb11.i
+ br i1 false, label %bb.i.i.i118, label %bb1.i.i.i119
+
+bb.i.i.i118: ; preds = %bb12.i
+ br label %int2lit.exit.i
+
+bb1.i.i.i119: ; preds = %bb12.i
+ br label %int2lit.exit.i
+
+int2lit.exit.i: ; preds = %bb1.i.i.i119, %bb.i.i.i118
+ br label %bb19.i
+
+bb13.i: ; preds = %bb19.i
+ br label %bb17.i
+
+bb14.i: ; preds = %bb17.i
+ br label %bb17.i
+
+bb17.i: ; preds = %bb14.i, %bb13.i
+ br i1 false, label %bb14.i, label %bb18.i
+
+bb18.i: ; preds = %bb17.i
+ br label %bb19.i
+
+bb19.i: ; preds = %bb18.i, %int2lit.exit.i
+ br i1 false, label %bb20.i, label %bb13.i
+
+bb20.i: ; preds = %bb19.i
+ br label %bb33.i
+
+bb24.i: ; preds = %bb33.i
+ br i1 false, label %bb29.i, label %bb25.i
+
+bb25.i: ; preds = %bb24.i
+ br label %bb27.i
+
+bb26.i: ; preds = %bb27.i
+ br label %bb27.i
+
+bb27.i: ; preds = %bb26.i, %bb25.i
+ br i1 false, label %bb26.i, label %bb28.i
+
+bb28.i: ; preds = %bb27.i
+ br label %bb29.i
+
+bb29.i: ; preds = %bb28.i, %bb24.i
+ br label %bb33.i
+
+bb33.i: ; preds = %bb29.i, %bb20.i
+ br i1 false, label %bb34.i, label %bb24.i
+
+bb34.i: ; preds = %bb33.i
+ br i1 false, label %bb.i.i58.i, label %bb1.i.i59.i
+
+bb.i.i58.i: ; preds = %bb34.i
+ br label %int2lit.exit63.i
+
+bb1.i.i59.i: ; preds = %bb34.i
+ br label %int2lit.exit63.i
+
+int2lit.exit63.i: ; preds = %bb1.i.i59.i, %bb.i.i58.i
+ br label %bb41.i
+
+bb35.i: ; preds = %bb41.i
+ br label %bb39.i
+
+bb36.i: ; preds = %bb39.i
+ br i1 false, label %bb38.i, label %bb37.i
+
+bb37.i: ; preds = %bb36.i
+ br label %bb38.i
+
+bb38.i: ; preds = %bb37.i, %bb36.i
+ br label %bb39.i
+
+bb39.i: ; preds = %bb38.i, %bb35.i
+ br i1 false, label %bb36.i, label %bb40.i
+
+bb40.i: ; preds = %bb39.i
+ br label %bb41.i
+
+bb41.i: ; preds = %bb40.i, %int2lit.exit63.i
+ br i1 false, label %bb42.i, label %bb35.i
+
+bb42.i: ; preds = %bb41.i
+ br label %bb44.i
+
+bb43.i: ; preds = %bb44.i
+ br label %bb44.i
+
+bb44.i: ; preds = %bb43.i, %bb42.i
+ br i1 false, label %bb43.i, label %picosat_print.exit
+
+picosat_print.exit: ; preds = %bb44.i
+ br label %bb167
+
+bb145: ; preds = %bb143
+ br i1 false, label %bb147, label %bb146
+
+bb146: ; preds = %bb145
+ br label %bb147
+
+bb147: ; preds = %bb146, %bb145
+ br i1 false, label %bb149, label %bb148
+
+bb148: ; preds = %bb147
+ br label %bb149
+
+bb149: ; preds = %bb148, %bb147
+ br i1 false, label %bb.i54, label %bb1.i55
+
+bb.i54: ; preds = %bb149
+ unreachable
+
+bb1.i55: ; preds = %bb149
+ br i1 false, label %bb.i.i56, label %bb1.i.i57
+
+bb.i.i56: ; preds = %bb1.i55
+ br label %bb1.i.i57
+
+bb1.i.i57: ; preds = %bb.i.i56, %bb1.i55
+ br i1 false, label %bb3.i.i59, label %bb2.i.i58
+
+bb2.i.i58: ; preds = %bb1.i.i57
+ br label %bb3.i.i59
+
+bb3.i.i59: ; preds = %bb2.i.i58, %bb1.i.i57
+ br i1 false, label %bb5.i.i61, label %sat.exit.i
+
+bb5.i.i61: ; preds = %bb3.i.i59
+ br i1 false, label %bb6.i.i65, label %bb1.i.i.i63
+
+bb1.i.i.i63: ; preds = %bb5.i.i61
+ br i1 false, label %sat.exit.i, label %bb6.i.i65
+
+bb6.i.i65: ; preds = %bb1.i.i.i63, %bb5.i.i61
+ br i1 false, label %bb8.i.i67, label %bb7.i.i66
+
+bb7.i.i66: ; preds = %bb6.i.i65
+ br label %bb8.i.i67
+
+bb8.i.i67: ; preds = %bb7.i.i66, %bb6.i.i65
+ br i1 false, label %bb10.i.i69, label %sat.exit.i
+
+bb10.i.i69: ; preds = %bb8.i.i67
+ br i1 false, label %bb11.i.i70, label %bb1.i61.i.i
+
+bb1.i61.i.i: ; preds = %bb10.i.i69
+ br i1 false, label %sat.exit.i, label %bb11.i.i70
+
+bb11.i.i70: ; preds = %bb1.i61.i.i, %bb10.i.i69
+ br label %bb13.i.i71.outer
+
+bb13.i.i71.outer: ; preds = %bb42.i.i, %bb11.i.i70
+ br label %bb13.i.i71
+
+bb13.i.i71: ; preds = %bb13.i.i71.backedge, %bb13.i.i71.outer
+ br i1 false, label %bb14.i.i72, label %bb15.i.i73
+
+bb14.i.i72: ; preds = %bb13.i.i71
+ br label %bb15.i.i73
+
+bb15.i.i73: ; preds = %bb14.i.i72, %bb13.i.i71
+ br i1 false, label %bb19.i.i, label %bb16.i.i
+
+bb16.i.i: ; preds = %bb15.i.i73
+ br i1 false, label %bb.i.i79.i.i, label %incincs.exit.i.i
+
+bb.i.i79.i.i: ; preds = %bb16.i.i
+ br label %bb4.i.i.i85.i.i
+
+bb.i.i.i80.i.i: ; preds = %bb4.i.i.i85.i.i
+ br i1 false, label %bb3.i.i.i83.i.i, label %bb1.i.i.i81.i.i
+
+bb1.i.i.i81.i.i: ; preds = %bb.i.i.i80.i.i
+ br i1 false, label %bb2.i.i.i82.i.i, label %bb3.i.i.i83.i.i
+
+bb2.i.i.i82.i.i: ; preds = %bb1.i.i.i81.i.i
+ br label %bb3.i.i.i83.i.i
+
+bb3.i.i.i83.i.i: ; preds = %bb2.i.i.i82.i.i, %bb1.i.i.i81.i.i, %bb.i.i.i80.i.i
+ br label %bb4.i.i.i85.i.i
+
+bb4.i.i.i85.i.i: ; preds = %bb3.i.i.i83.i.i, %bb.i.i79.i.i
+ br i1 false, label %crescore.exit.i.i.i.i, label %bb.i.i.i80.i.i
+
+crescore.exit.i.i.i.i: ; preds = %bb4.i.i.i85.i.i
+ br label %incincs.exit.i.i
+
+incincs.exit.i.i: ; preds = %crescore.exit.i.i.i.i, %bb16.i.i
+ br i1 false, label %bb13.i.i71.backedge, label %sat.exit.i.loopexit.loopexit
+
+bb13.i.i71.backedge: ; preds = %bb1.i55.i.i, %bb28.i.i, %incincs.exit.i.i
+ br label %bb13.i.i71
+
+bb19.i.i: ; preds = %bb15.i.i73
+ br i1 false, label %bb20.i.i, label %bb1.i68.i.i
+
+bb1.i68.i.i: ; preds = %bb19.i.i
+ br i1 false, label %sat.exit.i.loopexit.loopexit, label %bb20.i.i
+
+bb20.i.i: ; preds = %bb1.i68.i.i, %bb19.i.i
+ br i1 false, label %bb24.i.i, label %bb21.i.i
+
+bb21.i.i: ; preds = %bb20.i.i
+ br i1 false, label %bb22.i.i, label %bb24.i.i
+
+bb22.i.i: ; preds = %bb21.i.i
+ br i1 false, label %bb23.i.i, label %bb24.i.i
+
+bb23.i.i: ; preds = %bb22.i.i
+ br label %bb24.i.i
+
+bb24.i.i: ; preds = %bb23.i.i, %bb22.i.i, %bb21.i.i, %bb20.i.i
+ br i1 false, label %bb26.i.i, label %sat.exit.i.loopexit.loopexit
+
+bb26.i.i: ; preds = %bb24.i.i
+ br i1 false, label %bb27.i.i, label %bb33.i.i.loopexit
+
+bb27.i.i: ; preds = %bb26.i.i
+ br i1 false, label %bb33.i.i.loopexit, label %bb28.i.i
+
+bb28.i.i: ; preds = %bb27.i.i
+ br i1 false, label %bb1.i55.i.i, label %bb13.i.i71.backedge
+
+bb1.i55.i.i: ; preds = %bb28.i.i
+ br i1 false, label %bb29.i.i, label %bb13.i.i71.backedge
+
+bb29.i.i: ; preds = %bb1.i55.i.i
+ br i1 false, label %bb31.i.i, label %sat.exit.i.loopexit.loopexit2
+
+bb31.i.i: ; preds = %bb29.i.i
+ br i1 false, label %bb33.i.i, label %bb1.i48.i.i
+
+bb1.i48.i.i: ; preds = %bb31.i.i
+ br i1 false, label %sat.exit.i.loopexit.loopexit2, label %bb33.i.i
+
+bb33.i.i.loopexit: ; preds = %bb27.i.i, %bb26.i.i
+ br label %bb33.i.i
+
+bb33.i.i: ; preds = %bb33.i.i.loopexit, %bb1.i48.i.i, %bb31.i.i
+ br i1 false, label %bb34.i.i, label %bb35.i.i
+
+bb34.i.i: ; preds = %bb33.i.i
+ br i1 false, label %bb35.i.i, label %bb2.i44.i.i76
+
+bb2.i44.i.i76: ; preds = %bb34.i.i
+ br label %bb35.i.i
+
+bb35.i.i: ; preds = %bb2.i44.i.i76, %bb34.i.i, %bb33.i.i
+ br i1 false, label %bb1.i37.i.i, label %bb.i35.i.i
+
+bb.i35.i.i: ; preds = %bb35.i.i
+ br label %bb36.i.i
+
+bb1.i37.i.i: ; preds = %bb35.i.i
+ br i1 false, label %bb37.i.i, label %bb36.i.i
+
+bb36.i.i: ; preds = %bb1.i37.i.i, %bb.i35.i.i
+ br label %bb25.i23.i.i
+
+bb.i18.i.i: ; preds = %bb25.i23.i.i
+ br i1 false, label %bb24.i22.i.i, label %bb22.i19.i.i
+
+bb22.i19.i.i: ; preds = %bb.i18.i.i
+ br label %bb24.i22.i.i
+
+bb24.i22.i.i: ; preds = %bb22.i19.i.i, %bb.i18.i.i
+ br label %bb25.i23.i.i
+
+bb25.i23.i.i: ; preds = %bb24.i22.i.i, %bb36.i.i
+ br i1 false, label %bb.i18.i.i, label %bb26.i24.i.i
+
+bb26.i24.i.i: ; preds = %bb25.i23.i.i
+ br i1 false, label %bb27.i25.i.i, label %bb32.i.i.i
+
+bb27.i25.i.i: ; preds = %bb26.i24.i.i
+ br label %bb32.i.i.i
+
+bb32.i.i.i: ; preds = %bb27.i25.i.i, %bb26.i24.i.i
+ br label %bb64.i.i.i
+
+bb33.i.i.i: ; preds = %bb64.i.i.i
+ br i1 false, label %bb60.i.i.i, label %bb34.i.i.i
+
+bb34.i.i.i: ; preds = %bb33.i.i.i
+ br i1 false, label %bb38.i.i.i, label %bb60.i.i.i
+
+bb38.i.i.i: ; preds = %bb34.i.i.i
+ br i1 false, label %bb39.i.i.i, label %bb48.i.i.i
+
+bb39.i.i.i: ; preds = %bb38.i.i.i
+ br i1 false, label %bb48.i.i.i, label %bb40.i.i.i
+
+bb40.i.i.i: ; preds = %bb39.i.i.i
+ br i1 false, label %bb60.i.i.i, label %bb45.i.i.i
+
+bb45.i.i.i: ; preds = %bb40.i.i.i
+ br label %bb60.i.i.i
+
+bb48.i.i.i: ; preds = %bb39.i.i.i, %bb38.i.i.i
+ br i1 false, label %bb53.i.i.i, label %bb60.i.i.i
+
+bb53.i.i.i: ; preds = %bb48.i.i.i
+ br i1 false, label %bb60.i.i.i, label %bb58.i.i.i
+
+bb58.i.i.i: ; preds = %bb53.i.i.i
+ br i1 false, label %bb59.i.i.i, label %bb60.i.i.i
+
+bb59.i.i.i: ; preds = %bb58.i.i.i
+ br label %bb60.i.i.i
+
+bb60.i.i.i: ; preds = %bb59.i.i.i, %bb58.i.i.i, %bb53.i.i.i, %bb48.i.i.i, %bb45.i.i.i, %bb40.i.i.i, %bb34.i.i.i, %bb33.i.i.i
+ %lcollect.i.i.i.1 = phi i32 [ %lcollect.i.i.i.2, %bb34.i.i.i ], [ %lcollect.i.i.i.2, %bb48.i.i.i ], [ %lcollect.i.i.i.2, %bb58.i.i.i ], [ %lcollect.i.i.i.2, %bb59.i.i.i ], [ %lcollect.i.i.i.2, %bb53.i.i.i ], [ %lcollect.i.i.i.2, %bb33.i.i.i ], [ %lcollect.i.i.i.2, %bb40.i.i.i ], [ 0, %bb45.i.i.i ] ; <i32> [#uses=1]
+ br label %bb64.i.i.i
+
+bb64.i.i.i: ; preds = %bb60.i.i.i, %bb32.i.i.i
+ %lcollect.i.i.i.2 = phi i32 [ 0, %bb32.i.i.i ], [ %lcollect.i.i.i.1, %bb60.i.i.i ] ; <i32> [#uses=8]
+ br i1 false, label %bb65.i.i.i, label %bb33.i.i.i
+
+bb65.i.i.i: ; preds = %bb64.i.i.i
+ br i1 false, label %bb103.i.i.i.preheader, label %bb66.i.i.i.preheader
+
+bb66.i.i.i.preheader: ; preds = %bb65.i.i.i
+ br label %bb66.i.i.i
+
+bb66.i.i.i: ; preds = %bb66.i.i.i.backedge, %bb66.i.i.i.preheader
+ br i1 false, label %bb67.i.i.i, label %bb68.i.i.i
+
+bb67.i.i.i: ; preds = %bb66.i.i.i
+ br label %bb68.i.i.i
+
+bb68.i.i.i: ; preds = %bb67.i.i.i, %bb66.i.i.i
+ br i1 false, label %bb69.i.i.i, label %bb70.i.i.i
+
+bb69.i.i.i: ; preds = %bb68.i.i.i
+ br label %bb70.i.i.i
+
+bb70.i.i.i: ; preds = %bb69.i.i.i, %bb68.i.i.i
+ br i1 false, label %bb71.i.i.i, label %bb72.i.i.i
+
+bb71.i.i.i: ; preds = %bb70.i.i.i
+ br label %bb72.i.i.i
+
+bb72.i.i.i: ; preds = %bb71.i.i.i, %bb70.i.i.i
+ br label %bb73.i.i.i.outer
+
+bb73.i.i.i.outer: ; preds = %bb78.i.i.i, %bb72.i.i.i
+ br label %bb73.i.i.i
+
+bb73.i.i.i: ; preds = %bb73.i.i.i, %bb73.i.i.i.outer
+ br i1 false, label %bb73.i.i.i, label %bb76.i.i.i.preheader
+
+bb76.i.i.i.preheader: ; preds = %bb73.i.i.i
+ br label %bb76.i.i.i
+
+bb76.i.i.i: ; preds = %bb76.i.i.i, %bb76.i.i.i.preheader
+ br i1 false, label %bb77.i.i.i, label %bb76.i.i.i
+
+bb77.i.i.i: ; preds = %bb76.i.i.i
+ br i1 false, label %bb78.i.i.i, label %bb79.i.i.i
+
+bb78.i.i.i: ; preds = %bb77.i.i.i
+ br label %bb73.i.i.i.outer
+
+bb79.i.i.i: ; preds = %bb77.i.i.i
+ br i1 false, label %bb83.i.i.i, label %bb94.i.i.i
+
+bb83.i.i.i: ; preds = %bb79.i.i.i
+ br i1 false, label %bb84.i.i.i, label %bb88.i.i.i
+
+bb84.i.i.i: ; preds = %bb83.i.i.i
+ br i1 false, label %bb87.i.i.i, label %bb85.i.i.i
+
+bb85.i.i.i: ; preds = %bb84.i.i.i
+ br label %bb87.i.i.i
+
+bb87.i.i.i: ; preds = %bb85.i.i.i, %bb84.i.i.i
+ br label %bb88.i.i.i
+
+bb88.i.i.i: ; preds = %bb87.i.i.i, %bb83.i.i.i
+ br i1 false, label %bb89.i.i.i, label %bb93.i.i.i
+
+bb89.i.i.i: ; preds = %bb88.i.i.i
+ br i1 false, label %bb92.i.i.i, label %bb90.i.i.i
+
+bb90.i.i.i: ; preds = %bb89.i.i.i
+ br label %bb92.i.i.i
+
+bb92.i.i.i: ; preds = %bb90.i.i.i, %bb89.i.i.i
+ br label %bb93.i.i.i
+
+bb93.i.i.i: ; preds = %bb92.i.i.i, %bb88.i.i.i
+ br label %bb66.i.i.i.backedge
+
+bb66.i.i.i.backedge: ; preds = %bb97.i.i.i, %bb94.i.i.i, %bb93.i.i.i
+ br label %bb66.i.i.i
+
+bb94.i.i.i: ; preds = %bb79.i.i.i
+ br i1 false, label %bb66.i.i.i.backedge, label %bb96.i.i.i
+
+bb96.i.i.i: ; preds = %bb94.i.i.i
+ br i1 false, label %bb97.i.i.i, label %bb103.i.i.i.preheader.loopexit
+
+bb103.i.i.i.preheader.loopexit: ; preds = %bb96.i.i.i
+ br label %bb103.i.i.i.preheader
+
+bb103.i.i.i.preheader: ; preds = %bb103.i.i.i.preheader.loopexit, %bb65.i.i.i
+ br label %bb103.i.i.i
+
+bb97.i.i.i: ; preds = %bb96.i.i.i
+ br label %bb66.i.i.i.backedge
+
+bb100.i.i.i: ; preds = %bb103.i.i.i
+ br i1 false, label %bb101.i.i.i, label %bb102.i.i.i
+
+bb101.i.i.i: ; preds = %bb100.i.i.i
+ br label %bb102.i.i.i
+
+bb102.i.i.i: ; preds = %bb101.i.i.i, %bb100.i.i.i
+ br label %bb103.i.i.i
+
+bb103.i.i.i: ; preds = %bb102.i.i.i, %bb103.i.i.i.preheader
+ br i1 false, label %bb100.i.i.i, label %bb109.i.i.i.preheader
+
+bb109.i.i.i.preheader: ; preds = %bb103.i.i.i
+ br label %bb109.i.i.i
+
+bb105.i.i.i: ; preds = %bb109.i.i.i
+ br label %bb107.i.i.i
+
+bb106.i.i.i: ; preds = %bb107.i.i.i
+ br label %bb107.i.i.i
+
+bb107.i.i.i: ; preds = %bb106.i.i.i, %bb105.i.i.i
+ br i1 false, label %bb106.i.i.i, label %bb108.i.i.i
+
+bb108.i.i.i: ; preds = %bb107.i.i.i
+ br label %bb109.i.i.i
+
+bb109.i.i.i: ; preds = %bb108.i.i.i, %bb109.i.i.i.preheader
+ br i1 false, label %bb110.i.i.i, label %bb105.i.i.i
+
+bb110.i.i.i: ; preds = %bb109.i.i.i
+ %0 = sub i32 0, %lcollect.i.i.i.2 ; <i32> [#uses=1]
+ %1 = add i32 %0, 1 ; <i32> [#uses=1]
+ br label %bb113.i.i.i
+
+bb111.i.i.i: ; preds = %bb113.i.i.i
+ br i1 false, label %bb114.i.i.i, label %bb113.i.i.i
+
+bb113.i.i.i: ; preds = %bb111.i.i.i, %bb110.i.i.i
+ br i1 false, label %bb111.i.i.i, label %bb114.i.i.i
+
+bb114.i.i.i: ; preds = %bb113.i.i.i, %bb111.i.i.i
+ %2 = lshr i32 %1, 1 ; <i32> [#uses=2]
+ br i1 false, label %bb116.i.i.i, label %bb124.i.i.i
+
+bb116.i.i.i: ; preds = %bb114.i.i.i
+ br i1 false, label %bb117.i.i.i.preheader, label %bb122.i.i.i.preheader
+
+bb122.i.i.i.preheader: ; preds = %bb116.i.i.i
+ br label %bb122.i.i.i
+
+bb117.i.i.i.preheader: ; preds = %bb116.i.i.i
+ br label %bb117.i.i.i
+
+bb117.i.i.i: ; preds = %bb118.i.i.i, %bb117.i.i.i.preheader
+ %target.i.i.i.1 = phi i32 [ %3, %bb118.i.i.i ], [ %2, %bb117.i.i.i.preheader ] ; <i32> [#uses=1]
+ %3 = add i32 %target.i.i.i.1, 1 ; <i32> [#uses=2]
+ br i1 false, label %bb118.i.i.i, label %bb124.i.i.i.loopexit
+
+bb118.i.i.i: ; preds = %bb117.i.i.i
+ br i1 false, label %bb117.i.i.i, label %bb124.i.i.i.loopexit
+
+bb122.i.i.i: ; preds = %bb123.i.i.i, %bb122.i.i.i.preheader
+ %target.i.i.i.2 = phi i32 [ %4, %bb123.i.i.i ], [ %2, %bb122.i.i.i.preheader ] ; <i32> [#uses=2]
+ br i1 false, label %bb124.i.i.i.loopexit1, label %bb123.i.i.i
+
+bb123.i.i.i: ; preds = %bb122.i.i.i
+ %4 = add i32 %target.i.i.i.2, -1 ; <i32> [#uses=1]
+ br i1 false, label %bb122.i.i.i, label %bb124.i.i.i.loopexit1
+
+bb124.i.i.i.loopexit: ; preds = %bb118.i.i.i, %bb117.i.i.i
+ br label %bb124.i.i.i
+
+bb124.i.i.i.loopexit1: ; preds = %bb123.i.i.i, %bb122.i.i.i
+ br label %bb124.i.i.i
+
+bb124.i.i.i: ; preds = %bb124.i.i.i.loopexit1, %bb124.i.i.i.loopexit, %bb114.i.i.i
+ %target.i.i.i.0 = phi i32 [ 0, %bb114.i.i.i ], [ %3, %bb124.i.i.i.loopexit ], [ %target.i.i.i.2, %bb124.i.i.i.loopexit1 ] ; <i32> [#uses=0]
+ br label %bb132.i.i.i.outer
+
+bb125.i.i.i: ; preds = %bb132.i.i.i
+ br i1 false, label %bb132.i.i.i, label %bb130.i.i.i
+
+bb130.i.i.i: ; preds = %bb125.i.i.i
+ br label %bb132.i.i.i.outer
+
+bb132.i.i.i.outer: ; preds = %bb130.i.i.i, %bb124.i.i.i
+ br label %bb132.i.i.i
+
+bb132.i.i.i: ; preds = %bb132.i.i.i.outer, %bb125.i.i.i
+ br i1 false, label %bb125.i.i.i, label %bb133.i.i.i
+
+bb133.i.i.i: ; preds = %bb132.i.i.i
+ br i1 false, label %bb136.i.i.i, label %bb134.i.i.i
+
+bb134.i.i.i: ; preds = %bb133.i.i.i
+ br i1 false, label %bb136.i.i.i, label %bb135.i.i.i
+
+bb135.i.i.i: ; preds = %bb134.i.i.i
+ br label %bb136.i.i.i
+
+bb136.i.i.i: ; preds = %bb135.i.i.i, %bb134.i.i.i, %bb133.i.i.i
+ br i1 false, label %bb137.i.i.i, label %bb37.i.i
+
+bb137.i.i.i: ; preds = %bb136.i.i.i
+ br label %bb37.i.i
+
+bb37.i.i: ; preds = %bb137.i.i.i, %bb136.i.i.i, %bb1.i37.i.i
+ br i1 false, label %bb40.i.i, label %bb38.i.i
+
+bb38.i.i: ; preds = %bb37.i.i
+ br i1 false, label %bb39.i.i, label %bb40.i.i
+
+bb39.i.i: ; preds = %bb38.i.i
+ br i1 false, label %bb17.i.i.i, label %bb3.i12.i.i
+
+bb3.i12.i.i: ; preds = %bb39.i.i
+ br label %bb5.i14.i.i
+
+bb5.i14.i.i: ; preds = %bb8.i.i.i79, %bb3.i12.i.i
+ br i1 false, label %bb6.i15.i.i, label %bb9.i.i.i80
+
+bb6.i15.i.i: ; preds = %bb5.i14.i.i
+ br i1 false, label %bb7.i.i.i78, label %bb9.i.i.i80
+
+bb7.i.i.i78: ; preds = %bb6.i15.i.i
+ br i1 false, label %bb9.i.i.i80, label %bb8.i.i.i79
+
+bb8.i.i.i79: ; preds = %bb7.i.i.i78
+ br i1 false, label %bb9.i.i.i80, label %bb5.i14.i.i
+
+bb9.i.i.i80: ; preds = %bb8.i.i.i79, %bb7.i.i.i78, %bb6.i15.i.i, %bb5.i14.i.i
+ br i1 false, label %bb16.i.i.i, label %bb10.i.i.i81
+
+bb10.i.i.i81: ; preds = %bb9.i.i.i80
+ br i1 false, label %bb11.i.i.i, label %bb15.i.i.i
+
+bb11.i.i.i: ; preds = %bb10.i.i.i81
+ br i1 false, label %bb16.i.i.i, label %bb15.i.i.i
+
+bb15.i.i.i: ; preds = %bb11.i.i.i, %bb10.i.i.i81
+ br label %bb16.i.i.i
+
+bb16.i.i.i: ; preds = %bb15.i.i.i, %bb11.i.i.i, %bb9.i.i.i80
+ br label %bb17.i.i.i
+
+bb17.i.i.i: ; preds = %bb16.i.i.i, %bb39.i.i
+ br i1 false, label %bb18.i.i.i, label %bb25.i.i.i
+
+bb18.i.i.i: ; preds = %bb17.i.i.i
+ br i1 false, label %bb24.i.i.i, label %bb23.i.i.i
+
+bb23.i.i.i: ; preds = %bb18.i.i.i
+ br label %bb24.i.i.i
+
+bb24.i.i.i: ; preds = %bb23.i.i.i, %bb18.i.i.i
+ br label %bb29.i.i.i
+
+bb25.i.i.i: ; preds = %bb17.i.i.i
+ br i1 false, label %bb29.i.i.i, label %bb27.i.i.i
+
+bb27.i.i.i: ; preds = %bb25.i.i.i
+ br i1 false, label %bb29.i.i.i, label %bb28.i.i.i
+
+bb28.i.i.i: ; preds = %bb27.i.i.i
+ br i1 false, label %bb29.i.i.i, label %bb.i4.i.i.i
+
+bb.i4.i.i.i: ; preds = %bb28.i.i.i
+ br i1 false, label %bb4.i.i16.i.i, label %bb29.i.i.i
+
+bb4.i.i16.i.i: ; preds = %bb.i4.i.i.i
+ br label %bb29.i.i.i
+
+bb29.i.i.i: ; preds = %bb4.i.i16.i.i, %bb.i4.i.i.i, %bb28.i.i.i, %bb27.i.i.i, %bb25.i.i.i, %bb24.i.i.i
+ br label %bb40.i.i
+
+bb40.i.i: ; preds = %bb29.i.i.i, %bb38.i.i, %bb37.i.i
+ br i1 false, label %bb9.i.i.i.i.preheader, label %bb2.i.i.i87
+
+bb9.i.i.i.i.preheader: ; preds = %bb40.i.i
+ br label %bb9.i.i.i.i
+
+bb.i.i.i.i84: ; preds = %bb9.i.i.i.i
+ switch i8 0, label %bb8.i.i.i.i [
+ i8 -1, label %bb1.i.i.i.i85
+ i8 1, label %bb9.i.i.i.i
+ ]
+
+bb1.i.i.i.i85: ; preds = %bb.i.i.i.i84
+ br i1 false, label %bb5.i.i.i.i, label %bb2.i.i.i87
+
+bb5.i.i.i.i: ; preds = %bb1.i.i.i.i85
+ br label %bb2.i.i.i87
+
+bb8.i.i.i.i: ; preds = %bb.i.i.i.i84
+ br i1 false, label %bb2.i.i.i87, label %bb6.i.i.i95
+
+bb9.i.i.i.i: ; preds = %bb.i.i.i.i84, %bb9.i.i.i.i.preheader
+ br i1 false, label %bb.i.i.i.i84, label %bb10.i.i.i.i
+
+bb10.i.i.i.i: ; preds = %bb9.i.i.i.i
+ br label %bb2.i.i.i87
+
+bb2.i.i.i87: ; preds = %bb10.i.i.i.i, %bb8.i.i.i.i, %bb5.i.i.i.i, %bb1.i.i.i.i85, %bb40.i.i
+ br i1 false, label %bb3.i.i.i88, label %decide.exit.i.i
+
+bb3.i.i.i88: ; preds = %bb2.i.i.i87
+ br i1 false, label %bb4.i.i.i90, label %bb1.i23.i.i.i
+
+bb1.i23.i.i.i: ; preds = %bb3.i.i.i88
+ br i1 false, label %decide.exit.i.i, label %bb4.i.i.i90
+
+bb4.i.i.i90: ; preds = %bb1.i23.i.i.i, %bb3.i.i.i88
+ br i1 false, label %bb1.i9.i.i.i, label %bb5.i.i.i94
+
+bb1.i9.i.i.i: ; preds = %bb4.i.i.i90
+ br i1 false, label %bb.i.i27.i.i.i.i, label %bb1.i.i28.i.i.i.i
+
+bb.i.i27.i.i.i.i: ; preds = %bb1.i9.i.i.i
+ br label %int2lit.exit32.i.i.i.i
+
+bb1.i.i28.i.i.i.i: ; preds = %bb1.i9.i.i.i
+ br label %int2lit.exit32.i.i.i.i
+
+int2lit.exit32.i.i.i.i: ; preds = %bb1.i.i28.i.i.i.i, %bb.i.i27.i.i.i.i
+ br i1 false, label %bb8.i19.i.i.i, label %bb2.i.i.i.i91
+
+bb2.i.i.i.i91: ; preds = %int2lit.exit32.i.i.i.i
+ br label %bb4.i.i.i.i
+
+bb3.i.i.i.i92: ; preds = %gcd.exit.i.i.i.i
+ br label %bb4.i.i.i.i
+
+bb4.i.i.i.i: ; preds = %bb3.i.i.i.i92, %bb2.i.i.i.i91
+ br label %bb3.i.i13.i.i.i
+
+bb2.i.i12.i.i.i: ; preds = %bb3.i.i13.i.i.i
+ br label %bb3.i.i13.i.i.i
+
+bb3.i.i13.i.i.i: ; preds = %bb2.i.i12.i.i.i, %bb4.i.i.i.i
+ br i1 false, label %gcd.exit.i.i.i.i, label %bb2.i.i12.i.i.i
+
+gcd.exit.i.i.i.i: ; preds = %bb3.i.i13.i.i.i
+ br i1 false, label %bb5.i14.i.i.i.preheader, label %bb3.i.i.i.i92
+
+bb5.i14.i.i.i.preheader: ; preds = %gcd.exit.i.i.i.i
+ br label %bb5.i14.i.i.i
+
+bb5.i14.i.i.i: ; preds = %int2lit.exit.i.i.i.i, %bb5.i14.i.i.i.preheader
+ br i1 false, label %bb.i.i.i17.i.i.i, label %bb1.i.i.i18.i.i.i
+
+bb.i.i.i17.i.i.i: ; preds = %bb5.i14.i.i.i
+ br label %int2lit.exit.i.i.i.i
+
+bb1.i.i.i18.i.i.i: ; preds = %bb5.i14.i.i.i
+ br label %int2lit.exit.i.i.i.i
+
+int2lit.exit.i.i.i.i: ; preds = %bb1.i.i.i18.i.i.i, %bb.i.i.i17.i.i.i
+ br i1 false, label %bb8.i19.i.i.i.loopexit, label %bb5.i14.i.i.i
+
+bb8.i19.i.i.i.loopexit: ; preds = %int2lit.exit.i.i.i.i
+ br label %bb8.i19.i.i.i
+
+bb8.i19.i.i.i: ; preds = %bb8.i19.i.i.i.loopexit, %int2lit.exit32.i.i.i.i
+ br i1 false, label %bb5.i.i.i94, label %bb6.i.i.i95
+
+bb5.i.i.i94: ; preds = %bb8.i19.i.i.i, %bb4.i.i.i90
+ br label %bb.i2.i.i.i
+
+bb.i2.i.i.i: ; preds = %hpop.exit.i.i.i.i, %bb5.i.i.i94
+ br i1 false, label %hpop.exit.i.i.i.i, label %bb1.i.i.i.i.i
+
+bb1.i.i.i.i.i: ; preds = %bb.i2.i.i.i
+ br label %bb2.i.i.i.i.i
+
+bb2.i.i.i.i.i: ; preds = %bb11.i.i.i.i.i, %bb1.i.i.i.i.i
+ br i1 false, label %bb3.i.i.i.i.i, label %bb12.i.i.i.i.i
+
+bb3.i.i.i.i.i: ; preds = %bb2.i.i.i.i.i
+ br i1 false, label %bb4.i.i.i.i.i, label %bb1.i.i.i.i.i.i
+
+bb1.i.i.i.i.i.i: ; preds = %bb3.i.i.i.i.i
+ br i1 false, label %bb8.i.i.i.i.i, label %bb3.i.i.i.i.i.i
+
+bb3.i.i.i.i.i.i: ; preds = %bb1.i.i.i.i.i.i
+ br i1 false, label %bb4.i.i.i.i.i, label %bb8.i.i.i.i.i
+
+bb4.i.i.i.i.i: ; preds = %bb3.i.i.i.i.i.i, %bb3.i.i.i.i.i
+ br i1 false, label %bb5.i.i.i.i.i, label %bb11.i.i.i.i.i
+
+bb5.i.i.i.i.i: ; preds = %bb4.i.i.i.i.i
+ br i1 false, label %bb6.i.i.i.i.i, label %bb1.i21.i.i.i.i.i
+
+bb1.i21.i.i.i.i.i: ; preds = %bb5.i.i.i.i.i
+ br i1 false, label %bb11.i.i.i.i.i, label %bb3.i24.i.i.i.i.i
+
+bb3.i24.i.i.i.i.i: ; preds = %bb1.i21.i.i.i.i.i
+ br i1 false, label %bb6.i.i.i.i.i, label %bb11.i.i.i.i.i
+
+bb6.i.i.i.i.i: ; preds = %bb3.i24.i.i.i.i.i, %bb5.i.i.i.i.i
+ br label %bb11.i.i.i.i.i
+
+bb8.i.i.i.i.i: ; preds = %bb3.i.i.i.i.i.i, %bb1.i.i.i.i.i.i
+ br i1 false, label %bb9.i.i.i.i.i, label %bb12.i.i.i.i.i
+
+bb9.i.i.i.i.i: ; preds = %bb8.i.i.i.i.i
+ br i1 false, label %bb11.i.i.i.i.i, label %bb1.i8.i.i.i.i.i
+
+bb1.i8.i.i.i.i.i: ; preds = %bb9.i.i.i.i.i
+ br i1 false, label %bb12.i.i.i.i.i, label %bb3.i11.i.i.i.i.i
+
+bb3.i11.i.i.i.i.i: ; preds = %bb1.i8.i.i.i.i.i
+ br i1 false, label %bb11.i.i.i.i.i, label %bb12.i.i.i.i.i
+
+bb11.i.i.i.i.i: ; preds = %bb3.i11.i.i.i.i.i, %bb9.i.i.i.i.i, %bb6.i.i.i.i.i, %bb3.i24.i.i.i.i.i, %bb1.i21.i.i.i.i.i, %bb4.i.i.i.i.i
+ br label %bb2.i.i.i.i.i
+
+bb12.i.i.i.i.i: ; preds = %bb3.i11.i.i.i.i.i, %bb1.i8.i.i.i.i.i, %bb8.i.i.i.i.i, %bb2.i.i.i.i.i
+ br label %hpop.exit.i.i.i.i
+
+hpop.exit.i.i.i.i: ; preds = %bb12.i.i.i.i.i, %bb.i2.i.i.i
+ br i1 false, label %sdecide.exit.i.i.i, label %bb.i2.i.i.i
+
+sdecide.exit.i.i.i: ; preds = %hpop.exit.i.i.i.i
+ br label %bb6.i.i.i95
+
+bb6.i.i.i95: ; preds = %sdecide.exit.i.i.i, %bb8.i19.i.i.i, %bb8.i.i.i.i
+ br label %decide.exit.i.i
+
+decide.exit.i.i: ; preds = %bb6.i.i.i95, %bb1.i23.i.i.i, %bb2.i.i.i87
+ br i1 false, label %bb42.i.i, label %sat.exit.i.loopexit.loopexit2
+
+bb42.i.i: ; preds = %decide.exit.i.i
+ br label %bb13.i.i71.outer
+
+sat.exit.i.loopexit.loopexit: ; preds = %bb24.i.i, %bb1.i68.i.i, %incincs.exit.i.i
+ br label %sat.exit.i.loopexit
+
+sat.exit.i.loopexit.loopexit2: ; preds = %decide.exit.i.i, %bb1.i48.i.i, %bb29.i.i
+ br label %sat.exit.i.loopexit
+
+sat.exit.i.loopexit: ; preds = %sat.exit.i.loopexit.loopexit2, %sat.exit.i.loopexit.loopexit
+ br label %sat.exit.i
+
+sat.exit.i: ; preds = %sat.exit.i.loopexit, %bb1.i61.i.i, %bb8.i.i67, %bb1.i.i.i63, %bb3.i.i59
+ br i1 false, label %bb7.i, label %bb2.i96
+
+bb2.i96: ; preds = %sat.exit.i
+ switch i32 0, label %bb5.i99 [
+ i32 10, label %bb4.i98
+ i32 20, label %bb6.i100
+ ]
+
+bb4.i98: ; preds = %bb2.i96
+ br label %bb6.i100
+
+bb5.i99: ; preds = %bb2.i96
+ br label %bb6.i100
+
+bb6.i100: ; preds = %bb5.i99, %bb4.i98, %bb2.i96
+ br label %bb7.i
+
+bb7.i: ; preds = %bb6.i100, %sat.exit.i
+ br i1 false, label %bb.i1.i, label %picosat_sat.exit
+
+bb.i1.i: ; preds = %bb7.i
+ br label %picosat_sat.exit
+
+picosat_sat.exit: ; preds = %bb.i1.i, %bb7.i
+ switch i32 0, label %bb166 [
+ i32 20, label %bb150
+ i32 10, label %bb163
+ ]
+
+bb150: ; preds = %picosat_sat.exit
+ br i1 false, label %bb152, label %bb151
+
+bb151: ; preds = %bb150
+ br label %bb152
+
+bb152: ; preds = %bb151, %bb150
+ br i1 false, label %bb154, label %bb153
+
+bb153: ; preds = %bb152
+ br label %bb154
+
+bb154: ; preds = %bb153, %bb152
+ br i1 false, label %bb157, label %bb156
+
+bb156: ; preds = %bb154
+ br label %bb157
+
+bb157: ; preds = %bb156, %bb154
+ br i1 false, label %bb159, label %bb158
+
+bb158: ; preds = %bb157
+ br label %bb159
+
+bb159: ; preds = %bb158, %bb157
+ br i1 false, label %bb167, label %bb160
+
+bb160: ; preds = %bb159
+ br label %bb167
+
+bb163: ; preds = %picosat_sat.exit
+ br i1 false, label %bb167, label %bb164
+
+bb164: ; preds = %bb163
+ br label %bb4.i
+
+bb.i11: ; preds = %bb4.i
+ br i1 false, label %bb.i.i12, label %bb1.i.i14
+
+bb.i.i12: ; preds = %bb.i11
+ unreachable
+
+bb1.i.i14: ; preds = %bb.i11
+ br i1 false, label %bb3.i.i16, label %bb2.i.i15
+
+bb2.i.i15: ; preds = %bb1.i.i14
+ unreachable
+
+bb3.i.i16: ; preds = %bb1.i.i14
+ br i1 false, label %bb3.i, label %bb7.i.i
+
+bb7.i.i: ; preds = %bb3.i.i16
+ br i1 false, label %bb.i.i.i.i17, label %bb1.i.i.i.i18
+
+bb.i.i.i.i17: ; preds = %bb7.i.i
+ br label %int2lit.exit.i.i
+
+bb1.i.i.i.i18: ; preds = %bb7.i.i
+ br label %int2lit.exit.i.i
+
+int2lit.exit.i.i: ; preds = %bb1.i.i.i.i18, %bb.i.i.i.i17
+ br i1 false, label %bb3.i, label %bb9.i.i
+
+bb9.i.i: ; preds = %int2lit.exit.i.i
+ br label %bb3.i
+
+bb3.i: ; preds = %bb9.i.i, %int2lit.exit.i.i, %bb3.i.i16
+ br label %bb4.i
+
+bb4.i: ; preds = %bb3.i, %bb164
+ br i1 false, label %bb5.i, label %bb.i11
+
+bb5.i: ; preds = %bb4.i
+ br i1 false, label %bb6.i, label %bb167
+
+bb6.i: ; preds = %bb5.i
+ br label %bb167
+
+bb166: ; preds = %picosat_sat.exit
+ br label %bb167
+
+bb167: ; preds = %bb166, %bb6.i, %bb5.i, %bb163, %bb160, %bb159, %picosat_print.exit
+ br i1 false, label %bb168, label %bb170
+
+bb168: ; preds = %bb167
+ br i1 false, label %bb170, label %bb169
+
+bb169: ; preds = %bb168
+ br i1 false, label %bb.i7, label %picosat_time_stamp.exit9
+
+bb.i7: ; preds = %bb169
+ br label %picosat_time_stamp.exit9
+
+picosat_time_stamp.exit9: ; preds = %bb.i7, %bb169
+ br label %bb170
+
+bb170: ; preds = %picosat_time_stamp.exit9, %bb168, %bb167, %bb129
+ br i1 false, label %bb.i.i3, label %picosat_leave.exit
+
+bb.i.i3: ; preds = %bb170
+ br label %picosat_leave.exit
+
+picosat_leave.exit: ; preds = %bb.i.i3, %bb170
+ br i1 false, label %bb1.i.i, label %bb.i.i
+
+bb.i.i: ; preds = %picosat_leave.exit
+ unreachable
+
+bb1.i.i: ; preds = %picosat_leave.exit
+ br label %bb9.i.i.i
+
+bb3.i.i.i: ; preds = %bb9.i.i.i
+ br i1 false, label %bb5.i.i.i, label %bb4.i.i.i
+
+bb4.i.i.i: ; preds = %bb3.i.i.i
+ br label %bb5.i.i.i
+
+bb5.i.i.i: ; preds = %bb4.i.i.i, %bb3.i.i.i
+ br label %bb9.i.i.i
+
+bb9.i.i.i: ; preds = %bb5.i.i.i, %bb1.i.i
+ br i1 false, label %bb10.i.i.i, label %bb3.i.i.i
+
+bb10.i.i.i: ; preds = %bb9.i.i.i
+ br i1 false, label %delete.exit.i.i.i, label %bb1.i.i.i.i
+
+bb1.i.i.i.i: ; preds = %bb10.i.i.i
+ br label %delete.exit.i.i.i
+
+delete.exit.i.i.i: ; preds = %bb1.i.i.i.i, %bb10.i.i.i
+ br i1 false, label %delete_clauses.exit.i.i, label %bb1.i7.i.i.i
+
+bb1.i7.i.i.i: ; preds = %delete.exit.i.i.i
+ br label %delete_clauses.exit.i.i
+
+delete_clauses.exit.i.i: ; preds = %bb1.i7.i.i.i, %delete.exit.i.i.i
+ br label %bb3.i.i
+
+bb2.i.i: ; preds = %bb3.i.i
+ br i1 false, label %lrelease.exit.i.i, label %bb1.i.i23.i.i
+
+bb1.i.i23.i.i: ; preds = %bb2.i.i
+ br label %lrelease.exit.i.i
+
+lrelease.exit.i.i: ; preds = %bb1.i.i23.i.i, %bb2.i.i
+ br label %bb3.i.i
+
+bb3.i.i: ; preds = %lrelease.exit.i.i, %delete_clauses.exit.i.i
+ br i1 false, label %bb4.i.i, label %bb2.i.i
+
+bb4.i.i: ; preds = %bb3.i.i
+ br i1 false, label %delete.exit214.i.i, label %bb1.i208.i.i
+
+bb1.i208.i.i: ; preds = %bb4.i.i
+ br label %delete.exit214.i.i
+
+delete.exit214.i.i: ; preds = %bb1.i208.i.i, %bb4.i.i
+ br i1 false, label %delete.exit203.i.i, label %bb1.i197.i.i
+
+bb1.i197.i.i: ; preds = %delete.exit214.i.i
+ br label %delete.exit203.i.i
+
+delete.exit203.i.i: ; preds = %bb1.i197.i.i, %delete.exit214.i.i
+ br i1 false, label %delete.exit192.i.i, label %bb1.i186.i.i
+
+bb1.i186.i.i: ; preds = %delete.exit203.i.i
+ br label %delete.exit192.i.i
+
+delete.exit192.i.i: ; preds = %bb1.i186.i.i, %delete.exit203.i.i
+ br i1 false, label %delete.exit181.i.i, label %bb1.i175.i.i
+
+bb1.i175.i.i: ; preds = %delete.exit192.i.i
+ br label %delete.exit181.i.i
+
+delete.exit181.i.i: ; preds = %bb1.i175.i.i, %delete.exit192.i.i
+ br i1 false, label %delete.exit170.i.i, label %bb1.i164.i.i
+
+bb1.i164.i.i: ; preds = %delete.exit181.i.i
+ br label %delete.exit170.i.i
+
+delete.exit170.i.i: ; preds = %bb1.i164.i.i, %delete.exit181.i.i
+ br i1 false, label %delete.exit159.i.i, label %bb1.i153.i.i
+
+bb1.i153.i.i: ; preds = %delete.exit170.i.i
+ br label %delete.exit159.i.i
+
+delete.exit159.i.i: ; preds = %bb1.i153.i.i, %delete.exit170.i.i
+ br i1 false, label %delete.exit148.i.i, label %bb1.i142.i.i
+
+bb1.i142.i.i: ; preds = %delete.exit159.i.i
+ br label %delete.exit148.i.i
+
+delete.exit148.i.i: ; preds = %bb1.i142.i.i, %delete.exit159.i.i
+ br i1 false, label %delete.exit137.i.i, label %bb1.i131.i.i
+
+bb1.i131.i.i: ; preds = %delete.exit148.i.i
+ br label %delete.exit137.i.i
+
+delete.exit137.i.i: ; preds = %bb1.i131.i.i, %delete.exit148.i.i
+ br i1 false, label %delete.exit126.i.i, label %bb1.i120.i.i
+
+bb1.i120.i.i: ; preds = %delete.exit137.i.i
+ br label %delete.exit126.i.i
+
+delete.exit126.i.i: ; preds = %bb1.i120.i.i, %delete.exit137.i.i
+ br i1 false, label %delete.exit115.i.i, label %bb1.i109.i.i
+
+bb1.i109.i.i: ; preds = %delete.exit126.i.i
+ br label %delete.exit115.i.i
+
+delete.exit115.i.i: ; preds = %bb1.i109.i.i, %delete.exit126.i.i
+ br i1 false, label %delete.exit104.i.i, label %bb1.i98.i.i
+
+bb1.i98.i.i: ; preds = %delete.exit115.i.i
+ br label %delete.exit104.i.i
+
+delete.exit104.i.i: ; preds = %bb1.i98.i.i, %delete.exit115.i.i
+ br i1 false, label %delete.exit93.i.i, label %bb1.i87.i.i
+
+bb1.i87.i.i: ; preds = %delete.exit104.i.i
+ br label %delete.exit93.i.i
+
+delete.exit93.i.i: ; preds = %bb1.i87.i.i, %delete.exit104.i.i
+ br i1 false, label %delete.exit82.i.i, label %bb1.i76.i.i
+
+bb1.i76.i.i: ; preds = %delete.exit93.i.i
+ br label %delete.exit82.i.i
+
+delete.exit82.i.i: ; preds = %bb1.i76.i.i, %delete.exit93.i.i
+ br i1 false, label %delete.exit71.i.i, label %bb1.i65.i.i
+
+bb1.i65.i.i: ; preds = %delete.exit82.i.i
+ br label %delete.exit71.i.i
+
+delete.exit71.i.i: ; preds = %bb1.i65.i.i, %delete.exit82.i.i
+ br i1 false, label %delete.exit60.i.i, label %bb1.i54.i.i
+
+bb1.i54.i.i: ; preds = %delete.exit71.i.i
+ br label %delete.exit60.i.i
+
+delete.exit60.i.i: ; preds = %bb1.i54.i.i, %delete.exit71.i.i
+ br i1 false, label %delete.exit38.i.i, label %bb1.i32.i.i
+
+bb1.i32.i.i: ; preds = %delete.exit60.i.i
+ br label %delete.exit38.i.i
+
+delete.exit38.i.i: ; preds = %bb1.i32.i.i, %delete.exit60.i.i
+ br i1 false, label %delete.exit18.i.i, label %bb1.i12.i.i
+
+bb1.i12.i.i: ; preds = %delete.exit38.i.i
+ br label %delete.exit18.i.i
+
+delete.exit18.i.i: ; preds = %bb1.i12.i.i, %delete.exit38.i.i
+ br i1 false, label %picosat_reset.exit, label %bb1.i2.i.i
+
+bb1.i2.i.i: ; preds = %delete.exit18.i.i
+ br label %picosat_reset.exit
+
+picosat_reset.exit: ; preds = %bb1.i2.i.i, %delete.exit18.i.i
+ br label %bb171
+
+bb171: ; preds = %picosat_reset.exit, %bb110
+ br i1 false, label %bb173, label %bb172
+
+bb172: ; preds = %bb171
+ br label %bb173
+
+bb173: ; preds = %bb172, %bb171
+ br i1 false, label %bb175, label %bb174
+
+bb174: ; preds = %bb173
+ br label %bb175
+
+bb175: ; preds = %bb174, %bb173
+ br i1 false, label %bb177, label %bb176
+
+bb176: ; preds = %bb175
+ br label %bb177
+
+bb177: ; preds = %bb176, %bb175
+ br i1 false, label %bb179, label %bb178
+
+bb178: ; preds = %bb177
+ ret i32 0
+
+bb179: ; preds = %bb177
+ ret i32 0
+}
+
+define i32 @main(i32 %argc, i8** %argv) nounwind {
+entry:
+ br label %bb2
+
+bb: ; preds = %bb2
+ br i1 false, label %bb3, label %bb2
+
+bb2: ; preds = %bb, %entry
+ br i1 false, label %bb5.loopexit, label %bb
+
+bb3: ; preds = %bb
+ br i1 false, label %bb5, label %bb4
+
+bb4: ; preds = %bb3
+ br label %bb5
+
+bb5.loopexit: ; preds = %bb2
+ br label %bb5
+
+bb5: ; preds = %bb5.loopexit, %bb4, %bb3
+ %0 = call fastcc i32 @picosat_main(i32 %argc, i8** %argv) nounwind ; <i32> [#uses=2]
+ br i1 false, label %bb7, label %bb6
+
+bb6: ; preds = %bb5
+ ret i32 %0
+
+bb7: ; preds = %bb5
+ ret i32 %0
+}
diff --git a/src/LLVM/test/Transforms/BlockPlacement/basictest.ll b/src/LLVM/test/Transforms/BlockPlacement/basictest.ll
new file mode 100644
index 0000000..f7a5533
--- /dev/null
+++ b/src/LLVM/test/Transforms/BlockPlacement/basictest.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -block-placement -disable-output -print-function 2> /dev/null
+
+define i32 @test() {
+ br i1 true, label %X, label %Y
+
+A: ; preds = %Y, %X
+ ret i32 0
+
+X: ; preds = %0
+ br label %A
+
+Y: ; preds = %0
+ br label %A
+}
+
diff --git a/src/LLVM/test/Transforms/BlockPlacement/dg.exp b/src/LLVM/test/Transforms/BlockPlacement/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/BlockPlacement/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/BranchFolding/2007-10-19-InlineAsmDirectives.ll b/src/LLVM/test/Transforms/BranchFolding/2007-10-19-InlineAsmDirectives.ll
new file mode 100644
index 0000000..9d82819
--- /dev/null
+++ b/src/LLVM/test/Transforms/BranchFolding/2007-10-19-InlineAsmDirectives.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -std-compile-opts -o - | llc -o - | grep bork_directive | wc -l | grep 2
+
+;; We don't want branch folding to fold asm directives.
+
+define void @bork(i32 %param) {
+entry:
+ %tmp = icmp eq i32 %param, 0
+ br i1 %tmp, label %cond_true, label %cond_false
+
+cond_true:
+ call void asm sideeffect ".bork_directive /* ${0:c}:${1:c} */", "i,i,~{dirflag},~{fpsr},~{flags}"( i32 37, i32 927 )
+ ret void
+
+cond_false:
+ call void asm sideeffect ".foo_directive ${0:c}:${1:c}", "i,i,~{dirflag},~{fpsr},~{flags}"( i32 37, i32 927 )
+ call void asm sideeffect ".bork_directive /* ${0:c}:${1:c} */", "i,i,~{dirflag},~{fpsr},~{flags}"( i32 37, i32 927 )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-13-LoopExtractorCrash.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-13-LoopExtractorCrash.ll
new file mode 100644
index 0000000..fcd19ae
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-13-LoopExtractorCrash.ll
@@ -0,0 +1,75 @@
+; RUN: opt < %s -loop-extract -disable-output
+
+define void @solve() {
+entry:
+ br label %loopentry.0
+
+loopentry.0: ; preds = %endif.0, %entry
+ br i1 false, label %no_exit.0, label %loopexit.0
+
+no_exit.0: ; preds = %loopentry.0
+ br i1 false, label %then.0, label %endif.0
+
+then.0: ; preds = %no_exit.0
+ br i1 false, label %shortcirc_done, label %shortcirc_next
+
+shortcirc_next: ; preds = %then.0
+ br label %shortcirc_done
+
+shortcirc_done: ; preds = %shortcirc_next, %then.0
+ br i1 false, label %then.1, label %endif.1
+
+then.1: ; preds = %shortcirc_done
+ br i1 false, label %cond_true, label %cond_false
+
+cond_true: ; preds = %then.1
+ br label %cond_continue
+
+cond_false: ; preds = %then.1
+ br label %cond_continue
+
+cond_continue: ; preds = %cond_false, %cond_true
+ br label %return
+
+after_ret.0: ; No predecessors!
+ br label %endif.1
+
+endif.1: ; preds = %after_ret.0, %shortcirc_done
+ br label %endif.0
+
+endif.0: ; preds = %endif.1, %no_exit.0
+ br label %loopentry.0
+
+loopexit.0: ; preds = %loopentry.0
+ br i1 false, label %then.2, label %endif.2
+
+then.2: ; preds = %loopexit.0
+ br i1 false, label %then.3, label %endif.3
+
+then.3: ; preds = %then.2
+ br label %return
+
+after_ret.1: ; No predecessors!
+ br label %endif.3
+
+endif.3: ; preds = %after_ret.1, %then.2
+ br label %endif.2
+
+endif.2: ; preds = %endif.3, %loopexit.0
+ br label %loopentry.1
+
+loopentry.1: ; preds = %no_exit.1, %endif.2
+ br i1 false, label %no_exit.1, label %loopexit.1
+
+no_exit.1: ; preds = %loopentry.1
+ br label %loopentry.1
+
+loopexit.1: ; preds = %loopentry.1
+ br label %return
+
+after_ret.2: ; No predecessors!
+ br label %return
+
+return: ; preds = %after_ret.2, %loopexit.1, %then.3, %cond_continue
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-DominanceProblem.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-DominanceProblem.ll
new file mode 100644
index 0000000..c00a58a
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-DominanceProblem.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -loop-extract -disable-output
+; This testcase is failing the loop extractor because not all exit blocks
+; are dominated by all of the live-outs.
+
+define i32 @ab(i32 %alpha, i32 %beta) {
+entry:
+ br label %loopentry.1.preheader
+
+loopentry.1.preheader: ; preds = %entry
+ br label %loopentry.1
+
+loopentry.1: ; preds = %no_exit.1, %loopentry.1.preheader
+ br i1 false, label %no_exit.1, label %loopexit.0.loopexit1
+
+no_exit.1: ; preds = %loopentry.1
+ %tmp.53 = load i32* null ; <i32> [#uses=1]
+ br i1 false, label %shortcirc_next.2, label %loopentry.1
+
+shortcirc_next.2: ; preds = %no_exit.1
+ %tmp.563 = call i32 @wins( i32 0, i32 %tmp.53, i32 3 ) ; <i32> [#uses=0]
+ ret i32 0
+
+loopexit.0.loopexit1: ; preds = %loopentry.1
+ br label %loopexit.0
+
+loopexit.0: ; preds = %loopexit.0.loopexit1
+ ret i32 0
+}
+
+declare i32 @wins(i32, i32, i32)
+
+declare i16 @ab_code()
+
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-NoSwitchSupport.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-NoSwitchSupport.ll
new file mode 100644
index 0000000..5384724
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-14-NoSwitchSupport.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -loop-extract-single -disable-output
+
+define void @ab() {
+entry:
+ br label %codeReplTail
+
+then.1: ; preds = %codeReplTail
+ br label %loopentry.1
+
+loopentry.1: ; preds = %no_exit.1, %then.1
+ br i1 false, label %no_exit.1, label %loopexit.0.loopexit1
+
+no_exit.1: ; preds = %loopentry.1
+ br label %loopentry.1
+
+loopexit.0.loopexit: ; preds = %codeReplTail
+ ret void
+
+loopexit.0.loopexit1: ; preds = %loopentry.1
+ ret void
+
+codeReplTail: ; preds = %codeReplTail, %entry
+ switch i16 0, label %codeReplTail [
+ i16 0, label %loopexit.0.loopexit
+ i16 1, label %then.1
+ ]
+}
+
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-MissedLiveIns.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-MissedLiveIns.ll
new file mode 100644
index 0000000..471e607
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-MissedLiveIns.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -loop-extract -disable-output
+
+define void @sendMTFValues() {
+entry:
+ br i1 false, label %then.1, label %endif.1
+
+then.1: ; preds = %entry
+ br i1 false, label %loopentry.6.preheader, label %else.0
+
+endif.1: ; preds = %entry
+ ret void
+
+else.0: ; preds = %then.1
+ ret void
+
+loopentry.6.preheader: ; preds = %then.1
+ br i1 false, label %endif.7.preheader, label %loopexit.9
+
+endif.7.preheader: ; preds = %loopentry.6.preheader
+ %tmp.183 = add i32 0, -1 ; <i32> [#uses=1]
+ br label %endif.7
+
+endif.7: ; preds = %loopexit.15, %endif.7.preheader
+ br i1 false, label %loopentry.10, label %loopentry.12
+
+loopentry.10: ; preds = %endif.7
+ br label %loopentry.12
+
+loopentry.12: ; preds = %loopentry.10, %endif.7
+ %ge.2.1 = phi i32 [ 0, %loopentry.10 ], [ %tmp.183, %endif.7 ] ; <i32> [#uses=0]
+ br i1 false, label %loopexit.14, label %no_exit.11
+
+no_exit.11: ; preds = %loopentry.12
+ ret void
+
+loopexit.14: ; preds = %loopentry.12
+ br i1 false, label %loopexit.15, label %no_exit.14
+
+no_exit.14: ; preds = %loopexit.14
+ ret void
+
+loopexit.15: ; preds = %loopexit.14
+ br i1 false, label %endif.7, label %loopexit.9
+
+loopexit.9: ; preds = %loopexit.15, %loopentry.6.preheader
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll
new file mode 100644
index 0000000..493c24a
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -loop-extract -disable-output
+
+define void @maketree() {
+entry:
+ br i1 false, label %no_exit.1, label %loopexit.0
+
+no_exit.1: ; preds = %endif, %expandbox.entry, %entry
+ br i1 false, label %endif, label %expandbox.entry
+
+expandbox.entry: ; preds = %no_exit.1
+ br i1 false, label %loopexit.1, label %no_exit.1
+
+endif: ; preds = %no_exit.1
+ br i1 false, label %loopexit.1, label %no_exit.1
+
+loopexit.1: ; preds = %endif, %expandbox.entry
+ %ic.i.0.0.4 = phi i32 [ 0, %expandbox.entry ], [ 0, %endif ] ; <i32> [#uses=0]
+ ret void
+
+loopexit.0: ; preds = %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-03-18-InvokeHandling.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-03-18-InvokeHandling.ll
new file mode 100644
index 0000000..43e2a94
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-03-18-InvokeHandling.ll
@@ -0,0 +1,198 @@
+; RUN: opt < %s -loop-extract -disable-output
+
+declare i32 @_IO_getc()
+
+declare void @__errno_location()
+
+define void @yylex() {
+entry:
+ switch i32 0, label %label.126 [
+ i32 0, label %return
+ i32 61, label %combine
+ i32 33, label %combine
+ i32 94, label %combine
+ i32 37, label %combine
+ i32 47, label %combine
+ i32 42, label %combine
+ i32 62, label %combine
+ i32 60, label %combine
+ i32 58, label %combine
+ i32 124, label %combine
+ i32 38, label %combine
+ i32 45, label %combine
+ i32 43, label %combine
+ i32 34, label %string_constant
+ i32 39, label %char_constant
+ i32 46, label %loopexit.2
+ i32 57, label %loopexit.2
+ i32 56, label %loopexit.2
+ i32 55, label %loopexit.2
+ i32 54, label %loopexit.2
+ i32 53, label %loopexit.2
+ i32 52, label %loopexit.2
+ i32 51, label %loopexit.2
+ i32 50, label %loopexit.2
+ i32 49, label %loopexit.2
+ i32 48, label %loopexit.2
+ i32 95, label %letter
+ i32 122, label %letter
+ i32 121, label %letter
+ i32 120, label %letter
+ i32 119, label %letter
+ i32 118, label %letter
+ i32 117, label %letter
+ i32 116, label %letter
+ i32 115, label %letter
+ i32 114, label %letter
+ i32 113, label %letter
+ i32 112, label %letter
+ i32 111, label %letter
+ i32 110, label %letter
+ i32 109, label %letter
+ i32 108, label %letter
+ i32 107, label %letter
+ i32 106, label %letter
+ i32 105, label %letter
+ i32 104, label %letter
+ i32 103, label %letter
+ i32 102, label %letter
+ i32 101, label %letter
+ i32 100, label %letter
+ i32 99, label %letter
+ i32 98, label %letter
+ i32 97, label %letter
+ i32 90, label %letter
+ i32 89, label %letter
+ i32 88, label %letter
+ i32 87, label %letter
+ i32 86, label %letter
+ i32 85, label %letter
+ i32 84, label %letter
+ i32 83, label %letter
+ i32 82, label %letter
+ i32 81, label %letter
+ i32 80, label %letter
+ i32 79, label %letter
+ i32 78, label %letter
+ i32 77, label %letter
+ i32 75, label %letter
+ i32 74, label %letter
+ i32 73, label %letter
+ i32 72, label %letter
+ i32 71, label %letter
+ i32 70, label %letter
+ i32 69, label %letter
+ i32 68, label %letter
+ i32 67, label %letter
+ i32 66, label %letter
+ i32 65, label %letter
+ i32 64, label %label.13
+ i32 76, label %label.12
+ i32 36, label %label.11
+ i32 -1, label %label.10
+ ]
+
+label.10: ; preds = %entry
+ ret void
+
+label.11: ; preds = %entry
+ ret void
+
+label.12: ; preds = %entry
+ ret void
+
+label.13: ; preds = %entry
+ ret void
+
+letter: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry
+ ret void
+
+loopexit.2: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry
+ switch i32 0, label %shortcirc_next.14 [
+ i32 48, label %then.20
+ i32 46, label %endif.38
+ ]
+
+then.20: ; preds = %loopexit.2
+ switch i32 0, label %else.4 [
+ i32 120, label %then.21
+ i32 88, label %then.21
+ ]
+
+then.21: ; preds = %then.20, %then.20
+ ret void
+
+else.4: ; preds = %then.20
+ ret void
+
+shortcirc_next.14: ; preds = %loopexit.2
+ ret void
+
+endif.38: ; preds = %loopexit.2
+ br i1 false, label %then.40, label %then.39
+
+then.39: ; preds = %endif.38
+ ret void
+
+then.40: ; preds = %endif.38
+ invoke void @__errno_location( )
+ to label %switchexit.2 unwind label %LongJmpBlkPre
+
+loopentry.6: ; preds = %endif.52
+ switch i32 0, label %switchexit.2 [
+ i32 73, label %label.82
+ i32 105, label %label.82
+ i32 76, label %label.80
+ i32 108, label %label.80
+ i32 70, label %label.78
+ i32 102, label %label.78
+ ]
+
+label.78: ; preds = %loopentry.6, %loopentry.6
+ ret void
+
+label.80: ; preds = %loopentry.6, %loopentry.6
+ ret void
+
+label.82: ; preds = %loopentry.6, %loopentry.6
+ %c.0.15.5 = phi i32 [ %tmp.79417, %loopentry.6 ], [ %tmp.79417, %loopentry.6 ] ; <i32> [#uses=0]
+ ret void
+
+switchexit.2: ; preds = %loopentry.6, %then.40
+ br i1 false, label %endif.51, label %loopexit.6
+
+endif.51: ; preds = %switchexit.2
+ br i1 false, label %endif.52, label %then.52
+
+then.52: ; preds = %endif.51
+ ret void
+
+endif.52: ; preds = %endif.51
+ %tmp.79417 = invoke i32 @_IO_getc( )
+ to label %loopentry.6 unwind label %LongJmpBlkPre ; <i32> [#uses=2]
+
+loopexit.6: ; preds = %switchexit.2
+ ret void
+
+char_constant: ; preds = %entry
+ ret void
+
+string_constant: ; preds = %entry
+ ret void
+
+combine: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry
+ ret void
+
+label.126: ; preds = %entry
+ ret void
+
+return: ; preds = %entry
+ ret void
+
+LongJmpBlkPre: ; preds = %endif.52, %then.40
+ %exn = landingpad { i8*, i32 } personality i32 (...)* @__gcc_personality_v0
+ catch i8* null
+ ret void
+}
+
+declare i32 @__gcc_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-08-12-BlockExtractPHI.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-08-12-BlockExtractPHI.ll
new file mode 100644
index 0000000..1798198
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-08-12-BlockExtractPHI.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -extract-blocks -disable-output
+
+define void @test1() {
+no_exit.0.i:
+ br i1 false, label %yylex.entry, label %yylex.entry
+
+yylex.entry: ; preds = %no_exit.0.i, %no_exit.0.i
+ %tmp.1027 = phi i32 [ 0, %no_exit.0.i ], [ 0, %no_exit.0.i ] ; <i32> [#uses=0]
+ ret void
+}
+
+define void @test2() {
+no_exit.0.i:
+ switch i32 0, label %yylex.entry [
+ i32 0, label %yylex.entry
+ i32 1, label %foo
+ ]
+
+yylex.entry: ; preds = %no_exit.0.i, %no_exit.0.i
+ %tmp.1027 = phi i32 [ 0, %no_exit.0.i ], [ 0, %no_exit.0.i ] ; <i32> [#uses=0]
+ ret void
+
+foo: ; preds = %no_exit.0.i
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/CodeExtractor/2004-11-12-InvokeExtract.ll b/src/LLVM/test/Transforms/CodeExtractor/2004-11-12-InvokeExtract.ll
new file mode 100644
index 0000000..a537c61
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/2004-11-12-InvokeExtract.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -extract-blocks -disable-output
+define i32 @foo() {
+ br label %EB
+
+EB: ; preds = %0
+ %V = invoke i32 @foo( )
+ to label %Cont unwind label %Unw ; <i32> [#uses=1]
+
+Cont: ; preds = %EB
+ ret i32 %V
+
+Unw: ; preds = %EB
+ %exn = landingpad { i8*, i32 } personality i32 (...)* @__gcc_personality_v0
+ catch i8* null
+ resume { i8*, i32 } %exn
+}
+
+declare i32 @__gcc_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/CodeExtractor/dg.exp b/src/LLVM/test/Transforms/CodeExtractor/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeExtractor/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/CodeGenPrepare/2008-11-24-RAUW-Self.ll b/src/LLVM/test/Transforms/CodeGenPrepare/2008-11-24-RAUW-Self.ll
new file mode 100644
index 0000000..1995c7f
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeGenPrepare/2008-11-24-RAUW-Self.ll
@@ -0,0 +1,511 @@
+; RUN: opt < %s -codegenprepare | llvm-dis
+; PR3113
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define fastcc i32 @ascii2flt(i8* %str) nounwind {
+entry:
+ br label %bb2.i
+
+bb2.i: ; preds = %bb4.i.bb2.i_crit_edge, %entry
+ br i1 false, label %bb4.i, label %base2flt.exit
+
+bb4.i: ; preds = %bb2.i
+ br i1 false, label %bb11.i, label %bb4.i.bb2.i_crit_edge
+
+bb4.i.bb2.i_crit_edge: ; preds = %bb4.i
+ br label %bb2.i
+
+bb11.i: ; preds = %bb4.i
+ br label %bb11.i.base2flt.exit204_crit_edge
+
+bb11.i.base2flt.exit204_crit_edge: ; preds = %bb11.i
+ br label %base2flt.exit204
+
+bb11.i.bb7.i197_crit_edge: ; No predecessors!
+ br label %bb7.i197
+
+base2flt.exit: ; preds = %bb2.i
+ br label %base2flt.exit.base2flt.exit204_crit_edge
+
+base2flt.exit.base2flt.exit204_crit_edge: ; preds = %base2flt.exit
+ br label %base2flt.exit204
+
+base2flt.exit.bb7.i197_crit_edge: ; No predecessors!
+ br label %bb7.i197
+
+bb10.i196: ; preds = %bb7.i197
+ br label %bb10.i196.base2flt.exit204_crit_edge
+
+bb10.i196.base2flt.exit204_crit_edge: ; preds = %bb7.i197, %bb10.i196
+ br label %base2flt.exit204
+
+bb10.i196.bb7.i197_crit_edge: ; No predecessors!
+ br label %bb7.i197
+
+bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge, %base2flt.exit.bb7.i197_crit_edge, %bb11.i.bb7.i197_crit_edge
+ %.reg2mem.0 = phi i32 [ 0, %base2flt.exit.bb7.i197_crit_edge ], [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ], [ 0, %bb11.i.bb7.i197_crit_edge ] ; <i32> [#uses=1]
+ br i1 undef, label %bb10.i196.base2flt.exit204_crit_edge, label %bb10.i196
+
+base2flt.exit204: ; preds = %bb10.i196.base2flt.exit204_crit_edge, %base2flt.exit.base2flt.exit204_crit_edge, %bb11.i.base2flt.exit204_crit_edge
+ br i1 false, label %base2flt.exit204.bb8_crit_edge, label %bb
+
+base2flt.exit204.bb8_crit_edge: ; preds = %base2flt.exit204
+ br label %bb8
+
+bb: ; preds = %base2flt.exit204
+ br i1 false, label %bb.bb18_crit_edge, label %bb1.i
+
+bb.bb18_crit_edge: ; preds = %bb9, %bb
+ br label %bb18
+
+bb1.i: ; preds = %bb
+ br i1 false, label %bb1.i.bb7_crit_edge, label %bb1.i158
+
+bb1.i.bb7_crit_edge.loopexit: ; preds = %bb2.i164
+ br label %bb1.i.bb7_crit_edge
+
+bb1.i.bb7_crit_edge: ; preds = %bb1.i.bb7_crit_edge.loopexit, %bb1.i
+ br label %bb7.preheader
+
+bb1.i158: ; preds = %bb1.i
+ br i1 false, label %bb1.i158.bb10.i179_crit_edge, label %bb1.i158.bb2.i164_crit_edge
+
+bb1.i158.bb2.i164_crit_edge: ; preds = %bb1.i158
+ br label %bb2.i164
+
+bb1.i158.bb10.i179_crit_edge: ; preds = %bb1.i158
+ br label %bb10.i179
+
+bb2.i164: ; preds = %bb4.i166.bb2.i164_crit_edge, %bb1.i158.bb2.i164_crit_edge
+ br i1 false, label %bb4.i166, label %bb1.i.bb7_crit_edge.loopexit
+
+bb4.i166: ; preds = %bb2.i164
+ br i1 false, label %bb4.i166.bb11.i172_crit_edge, label %bb4.i166.bb2.i164_crit_edge
+
+bb4.i166.bb2.i164_crit_edge: ; preds = %bb4.i166
+ br label %bb2.i164
+
+bb4.i166.bb11.i172_crit_edge: ; preds = %bb4.i166
+ br label %bb11.i172
+
+bb11.i172: ; preds = %bb10.i179.bb11.i172_crit_edge, %bb4.i166.bb11.i172_crit_edge
+ br label %bb7.preheader
+
+bb10.i179: ; preds = %bb9.i182, %bb1.i158.bb10.i179_crit_edge
+ br i1 false, label %bb7.i180, label %bb10.i179.bb11.i172_crit_edge
+
+bb10.i179.bb11.i172_crit_edge: ; preds = %bb10.i179
+ br label %bb11.i172
+
+bb7.i180: ; preds = %bb10.i179
+ br i1 false, label %bb7.i180.bb7_crit_edge, label %bb9.i182
+
+bb7.i180.bb7_crit_edge: ; preds = %bb7.i180
+ br label %bb7.preheader
+
+bb7.preheader: ; preds = %bb7.i180.bb7_crit_edge, %bb11.i172, %bb1.i.bb7_crit_edge
+ br label %bb7
+
+bb9.i182: ; preds = %bb7.i180
+ br label %bb10.i179
+
+bb7: ; preds = %addflt.exit114, %bb7.preheader
+ switch i8 0, label %bb4 [
+ i8 0, label %bb7.bb8_crit_edge
+ i8 46, label %bb7.bb8_crit_edge
+ ]
+
+bb7.bb8_crit_edge: ; preds = %bb7, %bb7
+ br label %bb8
+
+bb4: ; preds = %bb7
+ br i1 false, label %bb18.loopexit1, label %bb1.i5
+
+bb1.i5: ; preds = %bb4
+ br i1 false, label %bb1.i5.mulflt.exit157_crit_edge, label %bb3.i147
+
+bb1.i5.mulflt.exit157_crit_edge: ; preds = %bb5.i148, %bb1.i5
+ br label %mulflt.exit157
+
+bb3.i147: ; preds = %bb1.i5
+ br i1 false, label %bb3.i147.mulflt.exit157_crit_edge, label %bb5.i148
+
+bb3.i147.mulflt.exit157_crit_edge: ; preds = %bb8.i150, %bb3.i147
+ br label %mulflt.exit157
+
+bb5.i148: ; preds = %bb3.i147
+ br i1 false, label %bb1.i5.mulflt.exit157_crit_edge, label %bb7.i149
+
+bb7.i149: ; preds = %bb5.i148
+ br i1 false, label %bb8.i150, label %bb7.i149.bb12.i154_crit_edge
+
+bb7.i149.bb12.i154_crit_edge: ; preds = %bb7.i149
+ br label %bb12.i154
+
+bb8.i150: ; preds = %bb7.i149
+ br i1 false, label %bb3.i147.mulflt.exit157_crit_edge, label %bb10.i151
+
+bb10.i151: ; preds = %bb8.i150
+ br label %bb12.i154
+
+bb12.i154: ; preds = %bb10.i151, %bb7.i149.bb12.i154_crit_edge
+ br label %mulflt.exit157
+
+mulflt.exit157: ; preds = %bb12.i154, %bb3.i147.mulflt.exit157_crit_edge, %bb1.i5.mulflt.exit157_crit_edge
+ br i1 false, label %mulflt.exit157.base2flt.exit144_crit_edge, label %bb1.i115
+
+mulflt.exit157.base2flt.exit144_crit_edge.loopexit: ; preds = %bb2.i121
+ br label %mulflt.exit157.base2flt.exit144_crit_edge
+
+mulflt.exit157.base2flt.exit144_crit_edge: ; preds = %mulflt.exit157.base2flt.exit144_crit_edge.loopexit, %mulflt.exit157
+ br label %base2flt.exit144
+
+bb1.i115: ; preds = %mulflt.exit157
+ br i1 false, label %bb1.i115.bb10.i136_crit_edge, label %bb1.i115.bb2.i121_crit_edge
+
+bb1.i115.bb2.i121_crit_edge: ; preds = %bb1.i115
+ br label %bb2.i121
+
+bb1.i115.bb10.i136_crit_edge: ; preds = %bb1.i115
+ br label %bb10.i136
+
+bb2.i121: ; preds = %bb4.i123.bb2.i121_crit_edge, %bb1.i115.bb2.i121_crit_edge
+ br i1 false, label %bb4.i123, label %mulflt.exit157.base2flt.exit144_crit_edge.loopexit
+
+bb4.i123: ; preds = %bb2.i121
+ br i1 false, label %bb4.i123.bb11.i129_crit_edge, label %bb4.i123.bb2.i121_crit_edge
+
+bb4.i123.bb2.i121_crit_edge: ; preds = %bb4.i123
+ br label %bb2.i121
+
+bb4.i123.bb11.i129_crit_edge: ; preds = %bb4.i123
+ br label %bb11.i129
+
+bb11.i129: ; preds = %bb10.i136.bb11.i129_crit_edge, %bb4.i123.bb11.i129_crit_edge
+ br label %base2flt.exit144
+
+bb10.i136: ; preds = %bb9.i139, %bb1.i115.bb10.i136_crit_edge
+ br i1 false, label %bb7.i137, label %bb10.i136.bb11.i129_crit_edge
+
+bb10.i136.bb11.i129_crit_edge: ; preds = %bb10.i136
+ br label %bb11.i129
+
+bb7.i137: ; preds = %bb10.i136
+ br i1 false, label %bb7.i137.base2flt.exit144_crit_edge, label %bb9.i139
+
+bb7.i137.base2flt.exit144_crit_edge: ; preds = %bb7.i137
+ br label %base2flt.exit144
+
+bb9.i139: ; preds = %bb7.i137
+ br label %bb10.i136
+
+base2flt.exit144: ; preds = %bb7.i137.base2flt.exit144_crit_edge, %bb11.i129, %mulflt.exit157.base2flt.exit144_crit_edge
+ br i1 false, label %base2flt.exit144.addflt.exit114_crit_edge, label %bb3.i105
+
+base2flt.exit144.addflt.exit114_crit_edge: ; preds = %bb3.i105, %base2flt.exit144
+ br label %addflt.exit114
+
+bb3.i105: ; preds = %base2flt.exit144
+ br i1 false, label %base2flt.exit144.addflt.exit114_crit_edge, label %bb5.i106
+
+bb5.i106: ; preds = %bb3.i105
+ br i1 false, label %bb5.i106.bb9.i111_crit_edge, label %bb6.i107
+
+bb5.i106.bb9.i111_crit_edge: ; preds = %bb5.i106
+ br label %bb9.i111
+
+bb6.i107: ; preds = %bb5.i106
+ br i1 false, label %bb6.i107.addflt.exit114_crit_edge, label %bb8.i108
+
+bb6.i107.addflt.exit114_crit_edge: ; preds = %bb6.i107
+ br label %addflt.exit114
+
+bb8.i108: ; preds = %bb6.i107
+ br label %bb9.i111
+
+bb9.i111: ; preds = %bb8.i108, %bb5.i106.bb9.i111_crit_edge
+ br label %addflt.exit114
+
+addflt.exit114: ; preds = %bb9.i111, %bb6.i107.addflt.exit114_crit_edge, %base2flt.exit144.addflt.exit114_crit_edge
+ br label %bb7
+
+bb18.loopexit1: ; preds = %bb4
+ ret i32 -1
+
+bb18: ; preds = %bb8.bb18_crit_edge, %bb.bb18_crit_edge
+ ret i32 0
+
+bb8: ; preds = %bb7.bb8_crit_edge, %base2flt.exit204.bb8_crit_edge
+ br i1 false, label %bb9, label %bb8.bb18_crit_edge
+
+bb8.bb18_crit_edge: ; preds = %bb8
+ br label %bb18
+
+bb9: ; preds = %bb8
+ br i1 false, label %bb.bb18_crit_edge, label %bb1.i13
+
+bb1.i13: ; preds = %bb9
+ br i1 false, label %bb1.i13.base2flt.exit102_crit_edge, label %bb1.i73
+
+bb1.i13.base2flt.exit102_crit_edge.loopexit: ; preds = %bb2.i79
+ br label %bb1.i13.base2flt.exit102_crit_edge
+
+bb1.i13.base2flt.exit102_crit_edge: ; preds = %bb1.i13.base2flt.exit102_crit_edge.loopexit, %bb1.i13
+ br label %base2flt.exit102
+
+bb1.i73: ; preds = %bb1.i13
+ br i1 false, label %bb1.i73.bb10.i94_crit_edge, label %bb1.i73.bb2.i79_crit_edge
+
+bb1.i73.bb2.i79_crit_edge: ; preds = %bb1.i73
+ br label %bb2.i79
+
+bb1.i73.bb10.i94_crit_edge: ; preds = %bb1.i73
+ br label %bb10.i94
+
+bb2.i79: ; preds = %bb4.i81.bb2.i79_crit_edge, %bb1.i73.bb2.i79_crit_edge
+ br i1 false, label %bb4.i81, label %bb1.i13.base2flt.exit102_crit_edge.loopexit
+
+bb4.i81: ; preds = %bb2.i79
+ br i1 false, label %bb4.i81.bb11.i87_crit_edge, label %bb4.i81.bb2.i79_crit_edge
+
+bb4.i81.bb2.i79_crit_edge: ; preds = %bb4.i81
+ br label %bb2.i79
+
+bb4.i81.bb11.i87_crit_edge: ; preds = %bb4.i81
+ br label %bb11.i87
+
+bb11.i87: ; preds = %bb10.i94.bb11.i87_crit_edge, %bb4.i81.bb11.i87_crit_edge
+ br label %base2flt.exit102
+
+bb10.i94: ; preds = %bb9.i97, %bb1.i73.bb10.i94_crit_edge
+ br i1 false, label %bb7.i95, label %bb10.i94.bb11.i87_crit_edge
+
+bb10.i94.bb11.i87_crit_edge: ; preds = %bb10.i94
+ br label %bb11.i87
+
+bb7.i95: ; preds = %bb10.i94
+ br i1 false, label %bb7.i95.base2flt.exit102_crit_edge, label %bb9.i97
+
+bb7.i95.base2flt.exit102_crit_edge: ; preds = %bb7.i95
+ br label %base2flt.exit102
+
+bb9.i97: ; preds = %bb7.i95
+ br label %bb10.i94
+
+base2flt.exit102: ; preds = %bb7.i95.base2flt.exit102_crit_edge, %bb11.i87, %bb1.i13.base2flt.exit102_crit_edge
+ br i1 false, label %base2flt.exit102.mulflt.exit72_crit_edge, label %bb3.i62
+
+base2flt.exit102.mulflt.exit72_crit_edge: ; preds = %bb5.i63, %base2flt.exit102
+ br label %mulflt.exit72
+
+bb3.i62: ; preds = %base2flt.exit102
+ br i1 false, label %bb3.i62.mulflt.exit72_crit_edge, label %bb5.i63
+
+bb3.i62.mulflt.exit72_crit_edge: ; preds = %bb8.i65, %bb3.i62
+ br label %mulflt.exit72
+
+bb5.i63: ; preds = %bb3.i62
+ br i1 false, label %base2flt.exit102.mulflt.exit72_crit_edge, label %bb7.i64
+
+bb7.i64: ; preds = %bb5.i63
+ br i1 false, label %bb8.i65, label %bb7.i64.bb12.i69_crit_edge
+
+bb7.i64.bb12.i69_crit_edge: ; preds = %bb7.i64
+ br label %bb12.i69
+
+bb8.i65: ; preds = %bb7.i64
+ br i1 false, label %bb3.i62.mulflt.exit72_crit_edge, label %bb10.i66
+
+bb10.i66: ; preds = %bb8.i65
+ br label %bb12.i69
+
+bb12.i69: ; preds = %bb10.i66, %bb7.i64.bb12.i69_crit_edge
+ br label %mulflt.exit72
+
+mulflt.exit72: ; preds = %bb12.i69, %bb3.i62.mulflt.exit72_crit_edge, %base2flt.exit102.mulflt.exit72_crit_edge
+ br i1 false, label %mulflt.exit72.bb10.i58_crit_edge, label %bb3.i50
+
+mulflt.exit72.bb10.i58_crit_edge: ; preds = %bb3.i50, %mulflt.exit72
+ br label %bb10.i58
+
+bb3.i50: ; preds = %mulflt.exit72
+ br i1 false, label %mulflt.exit72.bb10.i58_crit_edge, label %bb5.i51
+
+bb5.i51: ; preds = %bb3.i50
+ br i1 false, label %bb5.i51.bb9.i56_crit_edge, label %bb6.i52
+
+bb5.i51.bb9.i56_crit_edge: ; preds = %bb5.i51
+ br label %bb9.i56
+
+bb6.i52: ; preds = %bb5.i51
+ br i1 false, label %bb6.i52.bb10.i58_crit_edge, label %bb8.i53
+
+bb6.i52.bb10.i58_crit_edge: ; preds = %bb6.i52
+ br label %bb10.i58
+
+bb8.i53: ; preds = %bb6.i52
+ br label %bb9.i56
+
+bb9.i56: ; preds = %bb8.i53, %bb5.i51.bb9.i56_crit_edge
+ br label %bb15.preheader
+
+bb10.i58: ; preds = %bb6.i52.bb10.i58_crit_edge, %mulflt.exit72.bb10.i58_crit_edge
+ br label %bb15.preheader
+
+bb15.preheader: ; preds = %bb10.i58, %bb9.i56
+ br label %bb15
+
+bb15: ; preds = %addflt.exit, %bb15.preheader
+ br i1 false, label %bb15.bb18.loopexit_crit_edge, label %bb12
+
+bb15.bb18.loopexit_crit_edge: ; preds = %bb15
+ br label %bb18.loopexit
+
+bb12: ; preds = %bb15
+ br i1 false, label %bb12.bb18.loopexit_crit_edge, label %bb1.i21
+
+bb12.bb18.loopexit_crit_edge: ; preds = %bb12
+ br label %bb18.loopexit
+
+bb1.i21: ; preds = %bb12
+ br i1 false, label %bb1.i21.mulflt.exit47_crit_edge, label %bb3.i37
+
+bb1.i21.mulflt.exit47_crit_edge: ; preds = %bb5.i38, %bb1.i21
+ br label %mulflt.exit47
+
+bb3.i37: ; preds = %bb1.i21
+ br i1 false, label %bb3.i37.mulflt.exit47_crit_edge, label %bb5.i38
+
+bb3.i37.mulflt.exit47_crit_edge: ; preds = %bb8.i40, %bb3.i37
+ br label %mulflt.exit47
+
+bb5.i38: ; preds = %bb3.i37
+ br i1 false, label %bb1.i21.mulflt.exit47_crit_edge, label %bb7.i39
+
+bb7.i39: ; preds = %bb5.i38
+ br i1 false, label %bb8.i40, label %bb7.i39.bb12.i44_crit_edge
+
+bb7.i39.bb12.i44_crit_edge: ; preds = %bb7.i39
+ br label %bb12.i44
+
+bb8.i40: ; preds = %bb7.i39
+ br i1 false, label %bb3.i37.mulflt.exit47_crit_edge, label %bb10.i41
+
+bb10.i41: ; preds = %bb8.i40
+ br label %bb12.i44
+
+bb12.i44: ; preds = %bb10.i41, %bb7.i39.bb12.i44_crit_edge
+ br label %mulflt.exit47
+
+mulflt.exit47: ; preds = %bb12.i44, %bb3.i37.mulflt.exit47_crit_edge, %bb1.i21.mulflt.exit47_crit_edge
+ br i1 false, label %mulflt.exit47.base2flt.exit34_crit_edge, label %bb1.i15
+
+mulflt.exit47.base2flt.exit34_crit_edge.loopexit: ; preds = %bb2.i20
+ br label %mulflt.exit47.base2flt.exit34_crit_edge
+
+mulflt.exit47.base2flt.exit34_crit_edge: ; preds = %mulflt.exit47.base2flt.exit34_crit_edge.loopexit, %mulflt.exit47
+ br label %base2flt.exit34
+
+bb1.i15: ; preds = %mulflt.exit47
+ br i1 false, label %bb1.i15.bb10.i31_crit_edge, label %bb1.i15.bb2.i20_crit_edge
+
+bb1.i15.bb2.i20_crit_edge: ; preds = %bb1.i15
+ br label %bb2.i20
+
+bb1.i15.bb10.i31_crit_edge: ; preds = %bb1.i15
+ br label %bb10.i31
+
+bb2.i20: ; preds = %bb4.i22.bb2.i20_crit_edge, %bb1.i15.bb2.i20_crit_edge
+ br i1 false, label %bb4.i22, label %mulflt.exit47.base2flt.exit34_crit_edge.loopexit
+
+bb4.i22: ; preds = %bb2.i20
+ br i1 false, label %bb4.i22.bb11.i28_crit_edge, label %bb4.i22.bb2.i20_crit_edge
+
+bb4.i22.bb2.i20_crit_edge: ; preds = %bb4.i22
+ br label %bb2.i20
+
+bb4.i22.bb11.i28_crit_edge: ; preds = %bb4.i22
+ br label %bb11.i28
+
+bb11.i28: ; preds = %bb10.i31.bb11.i28_crit_edge, %bb4.i22.bb11.i28_crit_edge
+ br label %base2flt.exit34
+
+bb10.i31: ; preds = %bb9.i33, %bb1.i15.bb10.i31_crit_edge
+ br i1 false, label %bb7.i32, label %bb10.i31.bb11.i28_crit_edge
+
+bb10.i31.bb11.i28_crit_edge: ; preds = %bb10.i31
+ br label %bb11.i28
+
+bb7.i32: ; preds = %bb10.i31
+ br i1 false, label %bb7.i32.base2flt.exit34_crit_edge, label %bb9.i33
+
+bb7.i32.base2flt.exit34_crit_edge: ; preds = %bb7.i32
+ br label %base2flt.exit34
+
+bb9.i33: ; preds = %bb7.i32
+ br label %bb10.i31
+
+base2flt.exit34: ; preds = %bb7.i32.base2flt.exit34_crit_edge, %bb11.i28, %mulflt.exit47.base2flt.exit34_crit_edge
+ br i1 false, label %base2flt.exit34.mulflt.exit_crit_edge, label %bb3.i9
+
+base2flt.exit34.mulflt.exit_crit_edge: ; preds = %bb5.i10, %base2flt.exit34
+ br label %mulflt.exit
+
+bb3.i9: ; preds = %base2flt.exit34
+ br i1 false, label %bb3.i9.mulflt.exit_crit_edge, label %bb5.i10
+
+bb3.i9.mulflt.exit_crit_edge: ; preds = %bb8.i11, %bb3.i9
+ br label %mulflt.exit
+
+bb5.i10: ; preds = %bb3.i9
+ br i1 false, label %base2flt.exit34.mulflt.exit_crit_edge, label %bb7.i
+
+bb7.i: ; preds = %bb5.i10
+ br i1 false, label %bb8.i11, label %bb7.i.bb12.i_crit_edge
+
+bb7.i.bb12.i_crit_edge: ; preds = %bb7.i
+ br label %bb12.i
+
+bb8.i11: ; preds = %bb7.i
+ br i1 false, label %bb3.i9.mulflt.exit_crit_edge, label %bb10.i12
+
+bb10.i12: ; preds = %bb8.i11
+ br label %bb12.i
+
+bb12.i: ; preds = %bb10.i12, %bb7.i.bb12.i_crit_edge
+ br label %mulflt.exit
+
+mulflt.exit: ; preds = %bb12.i, %bb3.i9.mulflt.exit_crit_edge, %base2flt.exit34.mulflt.exit_crit_edge
+ br i1 false, label %mulflt.exit.addflt.exit_crit_edge, label %bb3.i
+
+mulflt.exit.addflt.exit_crit_edge: ; preds = %bb3.i, %mulflt.exit
+ br label %addflt.exit
+
+bb3.i: ; preds = %mulflt.exit
+ br i1 false, label %mulflt.exit.addflt.exit_crit_edge, label %bb5.i
+
+bb5.i: ; preds = %bb3.i
+ br i1 false, label %bb5.i.bb9.i_crit_edge, label %bb6.i
+
+bb5.i.bb9.i_crit_edge: ; preds = %bb5.i
+ br label %bb9.i
+
+bb6.i: ; preds = %bb5.i
+ br i1 false, label %bb6.i.addflt.exit_crit_edge, label %bb8.i
+
+bb6.i.addflt.exit_crit_edge: ; preds = %bb6.i
+ br label %addflt.exit
+
+bb8.i: ; preds = %bb6.i
+ br label %bb9.i
+
+bb9.i: ; preds = %bb8.i, %bb5.i.bb9.i_crit_edge
+ br label %addflt.exit
+
+addflt.exit: ; preds = %bb9.i, %bb6.i.addflt.exit_crit_edge, %mulflt.exit.addflt.exit_crit_edge
+ br label %bb15
+
+bb18.loopexit: ; preds = %bb12.bb18.loopexit_crit_edge, %bb15.bb18.loopexit_crit_edge
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/CodeGenPrepare/basic.ll b/src/LLVM/test/Transforms/CodeGenPrepare/basic.ll
new file mode 100644
index 0000000..ebf10f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeGenPrepare/basic.ll
@@ -0,0 +1,30 @@
+; RUN: opt -codegenprepare %s -S -o - | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; CHECK: @test1
+; objectsize should fold to a constant, which causes the branch to fold to an
+; uncond branch.
+; rdar://8785296
+define i32 @test1(i8* %ptr) nounwind ssp noredzone align 2 {
+entry:
+ %0 = tail call i64 @llvm.objectsize.i64(i8* %ptr, i1 false)
+ %1 = icmp ugt i64 %0, 3
+ br i1 %1, label %T, label %trap
+
+; CHECK: entry:
+; CHECK-NEXT: br label %T
+
+trap: ; preds = %0, %entry
+ tail call void @llvm.trap() noreturn nounwind
+ unreachable
+
+T:
+; CHECK: ret i32 4
+ ret i32 4
+}
+
+declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readonly
+
+declare void @llvm.trap() nounwind
diff --git a/src/LLVM/test/Transforms/CodeGenPrepare/dg.exp b/src/LLVM/test/Transforms/CodeGenPrepare/dg.exp
new file mode 100644
index 0000000..de42dad
--- /dev/null
+++ b/src/LLVM/test/Transforms/CodeGenPrepare/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.ll]]
diff --git a/src/LLVM/test/Transforms/ConstProp/2002-05-03-DivideByZeroException.ll b/src/LLVM/test/Transforms/ConstProp/2002-05-03-DivideByZeroException.ll
new file mode 100644
index 0000000..2ad6309
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2002-05-03-DivideByZeroException.ll
@@ -0,0 +1,15 @@
+; Make sure that the constant propogator doesn't divide by zero!
+;
+; RUN: opt < %s -constprop
+;
+
+define i32 @test() {
+ %R = sdiv i32 12, 0 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i32 @test2() {
+ %R = srem i32 12, 0 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2002-05-03-NotOperator.ll b/src/LLVM/test/Transforms/ConstProp/2002-05-03-NotOperator.ll
new file mode 100644
index 0000000..481e244
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2002-05-03-NotOperator.ll
@@ -0,0 +1,19 @@
+; This bug has to do with the fact that constant propagation was implemented in
+; terms of _logical_ not (! in C) instead of _bitwise_ not (~ in C). This was
+; due to a spec change.
+
+; Fix #2: The unary not instruction now no longer exists. Change to xor.
+
+; RUN: opt < %s -constprop -S | \
+; RUN: not grep {i32 0}
+
+define i32 @test1() {
+ %R = xor i32 123, -1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i32 @test2() {
+ %R = xor i32 -123, -1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2002-09-03-SetCC-Bools.ll b/src/LLVM/test/Transforms/ConstProp/2002-09-03-SetCC-Bools.ll
new file mode 100644
index 0000000..08b7178
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2002-09-03-SetCC-Bools.ll
@@ -0,0 +1,20 @@
+; SetCC on boolean values was not implemented!
+
+; RUN: opt < %s -constprop -die -S | \
+; RUN: not grep set
+
+define i1 @test1() {
+ %A = icmp ule i1 true, false ; <i1> [#uses=1]
+ %B = icmp uge i1 true, false ; <i1> [#uses=1]
+ %C = icmp ult i1 false, true ; <i1> [#uses=1]
+ %D = icmp ugt i1 true, false ; <i1> [#uses=1]
+ %E = icmp eq i1 false, false ; <i1> [#uses=1]
+ %F = icmp ne i1 false, true ; <i1> [#uses=1]
+ %G = and i1 %A, %B ; <i1> [#uses=1]
+ %H = and i1 %C, %D ; <i1> [#uses=1]
+ %I = and i1 %E, %F ; <i1> [#uses=1]
+ %J = and i1 %G, %H ; <i1> [#uses=1]
+ %K = and i1 %I, %J ; <i1> [#uses=1]
+ ret i1 %K
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2003-05-12-DivideError.ll b/src/LLVM/test/Transforms/ConstProp/2003-05-12-DivideError.ll
new file mode 100644
index 0000000..022d44a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2003-05-12-DivideError.ll
@@ -0,0 +1,15 @@
+; Make sure that the constant propagator doesn't cause a sigfpe
+;
+; RUN: opt < %s -constprop
+;
+
+define i32 @test() {
+ %R = sdiv i32 -2147483648, -1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i32 @test2() {
+ %R = srem i32 -2147483648, -1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2005-01-28-SetCCGEP.ll b/src/LLVM/test/Transforms/ConstProp/2005-01-28-SetCCGEP.ll
new file mode 100644
index 0000000..192ed8c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2005-01-28-SetCCGEP.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -constprop -S | \
+; RUN: not grep {ret i1 false}
+
+@b = external global [2 x { }] ; <[2 x { }]*> [#uses=2]
+
+define i1 @f() {
+ %tmp.2 = icmp eq { }* getelementptr ([2 x { }]* @b, i32 0, i32 0), getelementptr ([2 x { }]* @b, i32 0, i32 1) ; <i1> [#uses=1]
+ ret i1 %tmp.2
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2006-11-30-vector-cast.ll b/src/LLVM/test/Transforms/ConstProp/2006-11-30-vector-cast.ll
new file mode 100644
index 0000000..5d0ab76
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2006-11-30-vector-cast.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -constprop -S | \
+; RUN: grep {i32 -1}
+; RUN: opt < %s -constprop -S | \
+; RUN: not grep zeroinitializer
+
+define <4 x i32> @test() {
+ %tmp40 = bitcast <2 x i64> bitcast (<4 x i32> < i32 0, i32 0, i32 -1, i32 0 > to <2 x i64>) to <4 x i32>; <<4 x i32>> [#uses=1]
+ ret <4 x i32> %tmp40
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2006-12-01-TruncBoolBug.ll b/src/LLVM/test/Transforms/ConstProp/2006-12-01-TruncBoolBug.ll
new file mode 100644
index 0000000..b76535f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2006-12-01-TruncBoolBug.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {ret i1 false}
+define i1 @test() {
+ %X = trunc i32 320 to i1 ; <i1> [#uses=1]
+ ret i1 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2006-12-01-bool-casts.ll b/src/LLVM/test/Transforms/ConstProp/2006-12-01-bool-casts.ll
new file mode 100644
index 0000000..a0f5307
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2006-12-01-bool-casts.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -constprop -S | \
+; RUN: grep {ret i32 -1}
+; RUN: opt < %s -constprop -S | \
+; RUN: grep {ret i32 1}
+
+define i32 @test1() {
+ %A = sext i1 true to i32 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
+define i32 @test2() {
+ %A = zext i1 true to i32 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2007-02-05-BitCast.ll b/src/LLVM/test/Transforms/ConstProp/2007-02-05-BitCast.ll
new file mode 100644
index 0000000..0a0e66c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2007-02-05-BitCast.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -constprop -S | grep 1065353216
+
+define i32 @test() {
+ %A = bitcast float 1.000000e+00 to i32 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2007-02-23-sdiv.ll b/src/LLVM/test/Transforms/ConstProp/2007-02-23-sdiv.ll
new file mode 100644
index 0000000..89a06bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2007-02-23-sdiv.ll
@@ -0,0 +1,5 @@
+; RUN: llvm-as < %s | llvm-dis | grep {global i32 0}
+; PR1215
+
+@G = global i32 sdiv (i32 0, i32 -1)
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2007-11-23-cttz.ll b/src/LLVM/test/Transforms/ConstProp/2007-11-23-cttz.ll
new file mode 100644
index 0000000..37cda30
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2007-11-23-cttz.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -constprop -S | grep {ret i13 13}
+; PR1816
+declare i13 @llvm.cttz.i13(i13)
+
+define i13 @test() {
+ %X = call i13 @llvm.cttz.i13(i13 0)
+ ret i13 %X
+}
diff --git a/src/LLVM/test/Transforms/ConstProp/2008-07-07-VectorCompare.ll b/src/LLVM/test/Transforms/ConstProp/2008-07-07-VectorCompare.ll
new file mode 100644
index 0000000..fd54954
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2008-07-07-VectorCompare.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -constprop -disable-output
+; PR2529
+define <4 x i1> @test1(i32 %argc, i8** %argv) {
+entry:
+ %foo = icmp slt <4 x i32> undef, <i32 14, i32 undef, i32 undef, i32 undef>
+ ret <4 x i1> %foo
+}
+
+define <4 x i1> @test2(i32 %argc, i8** %argv) {
+entry:
+ %foo = icmp slt <4 x i32> <i32 undef, i32 undef, i32 undef, i32
+undef>, <i32 undef, i32 undef, i32 undef, i32 undef>
+ ret <4 x i1> %foo
+}
+
+
+define <4 x i1> @test3() {
+ %foo = fcmp ueq <4 x float> <float 0.0, float 0.0, float 0.0, float
+undef>, <float 1.0, float 1.0, float 1.0, float undef>
+ ret <4 x i1> %foo
+}
+
+define <4 x i1> @test4() {
+ %foo = fcmp ueq <4 x float> <float 0.0, float 0.0, float 0.0, float 0.0>, <float 1.0, float 1.0, float 1.0, float 0.0>
+
+ ret <4 x i1> %foo
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll b/src/LLVM/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll
new file mode 100644
index 0000000..3322605
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2009-06-20-constexpr-zero-lhs.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s | llvm-dis | not grep ptrtoint
+; PR4424
+@G = external global i32
+@test1 = constant i32 sdiv (i32 0, i32 ptrtoint (i32* @G to i32))
+@test2 = constant i32 udiv (i32 0, i32 ptrtoint (i32* @G to i32))
+@test3 = constant i32 srem (i32 0, i32 ptrtoint (i32* @G to i32))
+@test4 = constant i32 urem (i32 0, i32 ptrtoint (i32* @G to i32))
+@test5 = constant i32 lshr (i32 0, i32 ptrtoint (i32* @G to i32))
+@test6 = constant i32 ashr (i32 0, i32 ptrtoint (i32* @G to i32))
+@test7 = constant i32 shl (i32 0, i32 ptrtoint (i32* @G to i32))
+
diff --git a/src/LLVM/test/Transforms/ConstProp/2009-09-01-GEP-Crash.ll b/src/LLVM/test/Transforms/ConstProp/2009-09-01-GEP-Crash.ll
new file mode 100644
index 0000000..fc7ff90
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/2009-09-01-GEP-Crash.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -constprop | llvm-dis
+; PR4848
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%0 = type { %struct.anon }
+%1 = type { %0, %2, [24 x i8] }
+%2 = type <{ %3, %3 }>
+%3 = type { %struct.hrtimer_cpu_base*, i32, %struct.rb_root, %struct.rb_node*, %struct.pgprot, i64 ()*, [16 x i8] }
+%struct.anon = type { }
+%struct.hrtimer_clock_base = type { %struct.hrtimer_cpu_base*, i32, %struct.rb_root, %struct.rb_node*, %struct.pgprot, i64 ()*, %struct.pgprot, %struct.pgprot }
+%struct.hrtimer_cpu_base = type { %0, [2 x %struct.hrtimer_clock_base], %struct.pgprot, i32, i64 }
+%struct.pgprot = type { i64 }
+%struct.rb_node = type { i64, %struct.rb_node*, %struct.rb_node* }
+%struct.rb_root = type { %struct.rb_node* }
+
+@per_cpu__hrtimer_bases = external global %1, align 8 ; <%1*> [#uses=1]
+
+define void @init_hrtimers_cpu(i32 %cpu) nounwind noredzone section ".cpuinit.text" {
+entry:
+ %tmp3 = getelementptr %struct.hrtimer_cpu_base* bitcast (%1* @per_cpu__hrtimer_bases to %struct.hrtimer_cpu_base*), i32 0, i32 0 ; <%0*> [#uses=1]
+ %tmp5 = bitcast %0* %tmp3 to i8* ; <i8*> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/ConstProp/basictest.ll b/src/LLVM/test/Transforms/ConstProp/basictest.ll
new file mode 100644
index 0000000..598498e
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/basictest.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -constprop -die -S | FileCheck %s
+
+; This is a basic sanity check for constant propagation. The add instruction
+; should be eliminated.
+define i32 @test1(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+
+BB1:
+ %Val = add i32 0, 0
+ br label %BB3
+
+BB2:
+ br label %BB3
+
+BB3:
+; CHECK: @test1
+; CHECK: %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
+ %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ]
+ ret i32 %Ret
+}
+
+
+; PR6197
+define i1 @test2(i8* %f) nounwind {
+entry:
+ %V = icmp ne i8* blockaddress(@test2, %bb), null
+ br label %bb
+bb:
+ ret i1 %V
+
+; CHECK: @test2
+; CHECK: ret i1 true
+}
+
+define i1 @TNAN() {
+; CHECK: @TNAN
+; CHECK: ret i1 true
+ %A = fcmp uno double 0x7FF8000000000000, 1.000000e+00
+ %B = fcmp uno double 1.230000e+02, 1.000000e+00
+ %C = or i1 %A, %B
+ ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/ConstProp/bitcast.ll b/src/LLVM/test/Transforms/ConstProp/bitcast.ll
new file mode 100644
index 0000000..53239c7
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/bitcast.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+; PR2165
+
+define <1 x i64> @test1() {
+ %A = bitcast i64 63 to <1 x i64>
+ ret <1 x i64> %A
+; CHECK: @test1
+; CHECK: ret <1 x i64> <i64 63>
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/bswap.ll b/src/LLVM/test/Transforms/ConstProp/bswap.ll
new file mode 100644
index 0000000..6fd8b1c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/bswap.ll
@@ -0,0 +1,25 @@
+; bswap should be constant folded when it is passed a constant argument
+
+; RUN: opt < %s -constprop -S | not grep call
+
+declare i16 @llvm.bswap.i16(i16)
+
+declare i32 @llvm.bswap.i32(i32)
+
+declare i64 @llvm.bswap.i64(i64)
+
+define i16 @W() {
+ %Z = call i16 @llvm.bswap.i16( i16 1 ) ; <i16> [#uses=1]
+ ret i16 %Z
+}
+
+define i32 @X() {
+ %Z = call i32 @llvm.bswap.i32( i32 1 ) ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i64 @Y() {
+ %Z = call i64 @llvm.bswap.i64( i64 1 ) ; <i64> [#uses=1]
+ ret i64 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/calls.ll b/src/LLVM/test/Transforms/ConstProp/calls.ll
new file mode 100644
index 0000000..11d86c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/calls.ll
@@ -0,0 +1,61 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+declare double @cos(double)
+
+declare double @sin(double)
+
+declare double @tan(double)
+
+declare double @sqrt(double)
+declare double @exp2(double)
+
+define double @T() {
+; CHECK: @T
+; CHECK-NOT: call
+; CHECK: ret
+ %A = call double @cos(double 0.000000e+00)
+ %B = call double @sin(double 0.000000e+00)
+ %a = fadd double %A, %B
+ %C = call double @tan(double 0.000000e+00)
+ %b = fadd double %a, %C
+ %D = call double @sqrt(double 4.000000e+00)
+ %c = fadd double %b, %D
+
+ ; PR9315
+ %E = call double @exp2(double 4.0)
+ %d = fadd double %c, %E
+ ret double %d
+}
+
+define i1 @test_sse_cvt() nounwind readnone {
+; CHECK: @test_sse_cvt
+; CHECK-NOT: call
+; CHECK: ret i1 true
+entry:
+ %i0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
+ %i1 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
+ %i2 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
+ %i3 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> <float 1.75, float undef, float undef, float undef>) nounwind
+ %i4 = call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> <double 1.75, double undef>) nounwind
+ %i5 = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> <double 1.75, double undef>) nounwind
+ %i6 = call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> <double 1.75, double undef>) nounwind
+ %i7 = call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> <double 1.75, double undef>) nounwind
+ %sum11 = add i32 %i0, %i1
+ %sum12 = add i32 %i4, %i5
+ %sum1 = add i32 %sum11, %sum12
+ %sum21 = add i64 %i2, %i3
+ %sum22 = add i64 %i6, %i7
+ %sum2 = add i64 %sum21, %sum22
+ %sum1.sext = sext i32 %sum1 to i64
+ %b = icmp eq i64 %sum1.sext, %sum2
+ ret i1 %b
+}
+
+declare i32 @llvm.x86.sse.cvtss2si(<4 x float>) nounwind readnone
+declare i32 @llvm.x86.sse.cvttss2si(<4 x float>) nounwind readnone
+declare i64 @llvm.x86.sse.cvtss2si64(<4 x float>) nounwind readnone
+declare i64 @llvm.x86.sse.cvttss2si64(<4 x float>) nounwind readnone
+declare i32 @llvm.x86.sse2.cvtsd2si(<2 x double>) nounwind readnone
+declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) nounwind readnone
+declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>) nounwind readnone
+declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>) nounwind readnone
diff --git a/src/LLVM/test/Transforms/ConstProp/constant-expr.ll b/src/LLVM/test/Transforms/ConstProp/constant-expr.ll
new file mode 100644
index 0000000..1088fa6
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/constant-expr.ll
@@ -0,0 +1,111 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+@X = external global i8
+@Y = external global i8
+@Z = external global i8
+
+@A = global i1 add (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @A = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+@B = global i1 sub (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z)), align 2
+; CHECK: @B = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+@C = global i1 mul (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @C = global i1 and (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+
+@D = global i1 sdiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @D = global i1 icmp ult (i8* @X, i8* @Y)
+@E = global i1 udiv (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @E = global i1 icmp ult (i8* @X, i8* @Y)
+@F = global i1 srem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @F = global i1 false
+@G = global i1 urem (i1 icmp ult (i8* @X, i8* @Y), i1 icmp ult (i8* @X, i8* @Z))
+; CHECK: @G = global i1 false
+
+@H = global i1 icmp ule (i32* bitcast (i8* @X to i32*), i32* bitcast (i8* @Y to i32*))
+; CHECK: @H = global i1 icmp ule (i8* @X, i8* @Y)
+
+@I = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 false)
+; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y)
+@J = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 true)
+; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y)
+
+@K = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false)
+; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y)
+@L = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true)
+; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y)
+@M = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 true)
+; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y)
+@N = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 false)
+; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y)
+
+@O = global i1 icmp eq (i32 zext (i1 icmp ult (i8* @X, i8* @Y) to i32), i32 0)
+; CHECK: @O = global i1 icmp uge (i8* @X, i8* @Y)
+
+
+
+; PR5176
+
+; CHECK: @T1 = global i1 true
+@T1 = global i1 icmp eq (i64 and (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64), i64 1), i64 0)
+
+; CHECK: @T2 = global i1* @B
+@T2 = global i1* inttoptr (i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 192)), i256 192) to i64), i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 192)), i256 128) to i64)) to i1*)
+
+; CHECK: @T3 = global i64 add (i64 ptrtoint (i1* @B to i64), i64 -1)
+@T3 = global i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64), i64 -1)
+
+; CHECK: @T4 = global i1* @B
+@T4 = global i1* inttoptr (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 64) to i64) to i1*)
+
+; CHECK: @T5 = global i1* @A
+@T5 = global i1* inttoptr (i64 add (i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 192) to i64), i64 trunc (i256 lshr (i256 or (i256 and (i256 and (i256 shl (i256 zext (i64 ptrtoint (i1* @B to i64) to i256), i256 64), i256 -6277101735386680763495507056286727952638980837032266301441), i256 6277101735386680763835789423207666416102355444464034512895), i256 shl (i256 zext (i64 ptrtoint (i1* @A to i64) to i256), i256 192)), i256 128) to i64)) to i1*)
+
+
+
+; PR6096
+
+; No check line. This used to crash llvm-as.
+@T6 = global <2 x i1> fcmp ole (<2 x float> fdiv (<2 x float> undef, <2 x float> <float 1.000000e+00, float 1.000000e+00>), <2 x float> zeroinitializer)
+
+
+; PR9011
+
+@pr9011_1 = constant <4 x i32> zext (<4 x i8> zeroinitializer to <4 x i32>)
+; CHECK: pr9011_1 = constant <4 x i32> zeroinitializer
+@pr9011_2 = constant <4 x i32> sext (<4 x i8> zeroinitializer to <4 x i32>)
+; CHECK: pr9011_2 = constant <4 x i32> zeroinitializer
+@pr9011_3 = constant <4 x i32> bitcast (<16 x i8> zeroinitializer to <4 x i32>)
+; CHECK: pr9011_3 = constant <4 x i32> zeroinitializer
+@pr9011_4 = constant <4 x float> uitofp (<4 x i8> zeroinitializer to <4 x float>)
+; CHECK: pr9011_4 = constant <4 x float> zeroinitializer
+@pr9011_5 = constant <4 x float> sitofp (<4 x i8> zeroinitializer to <4 x float>)
+; CHECK: pr9011_5 = constant <4 x float> zeroinitializer
+@pr9011_6 = constant <4 x i32> fptosi (<4 x float> zeroinitializer to <4 x i32>)
+; CHECK: pr9011_6 = constant <4 x i32> zeroinitializer
+@pr9011_7 = constant <4 x i32> fptoui (<4 x float> zeroinitializer to <4 x i32>)
+; CHECK: pr9011_7 = constant <4 x i32> zeroinitializer
+@pr9011_8 = constant <4 x float> fptrunc (<4 x double> zeroinitializer to <4 x float>)
+; CHECK: pr9011_8 = constant <4 x float> zeroinitializer
+@pr9011_9 = constant <4 x double> fpext (<4 x float> zeroinitializer to <4 x double>)
+; CHECK: pr9011_9 = constant <4 x double> zeroinitializer
+
+@pr9011_10 = constant <4 x double> bitcast (i256 0 to <4 x double>)
+; CHECK: pr9011_10 = constant <4 x double> zeroinitializer
+@pr9011_11 = constant <4 x float> bitcast (i128 0 to <4 x float>)
+; CHECK: pr9011_11 = constant <4 x float> zeroinitializer
+@pr9011_12 = constant <4 x i32> bitcast (i128 0 to <4 x i32>)
+; CHECK: pr9011_12 = constant <4 x i32> zeroinitializer
+@pr9011_13 = constant i256 bitcast (<4 x double> zeroinitializer to i256)
+; CHECK: pr9011_13 = constant i256 0
+@pr9011_14 = constant i128 bitcast (<4 x float> zeroinitializer to i128)
+; CHECK: pr9011_14 = constant i128 0
+@pr9011_15 = constant i128 bitcast (<4 x i32> zeroinitializer to i128)
+; CHECK: pr9011_15 = constant i128 0
+
+@select = internal constant
+ i32 select (i1 icmp ult (i32 ptrtoint (i8* @X to i32),
+ i32 ptrtoint (i8* @Y to i32)),
+ i32 select (i1 icmp ult (i32 ptrtoint (i8* @X to i32),
+ i32 ptrtoint (i8* @Y to i32)),
+ i32 10, i32 20),
+ i32 30)
+; CHECK: select = internal constant i32 select {{.*}} i32 10, i32 30
diff --git a/src/LLVM/test/Transforms/ConstProp/dg.exp b/src/LLVM/test/Transforms/ConstProp/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/ConstProp/div-zero.ll b/src/LLVM/test/Transforms/ConstProp/div-zero.ll
new file mode 100644
index 0000000..f78a34f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/div-zero.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | grep {ret i32 0}
+; PR4424
+declare void @ext()
+
+define i32 @foo(i32 %ptr) {
+entry:
+ %zero = sub i32 %ptr, %ptr ; <i32> [#uses=1]
+ %div_zero = sdiv i32 %zero, ptrtoint (i32* getelementptr (i32* null,
+i32 1) to i32) ; <i32> [#uses=1]
+ ret i32 %div_zero
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/extractvalue.ll b/src/LLVM/test/Transforms/ConstProp/extractvalue.ll
new file mode 100644
index 0000000..f947b22
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/extractvalue.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+%struct = type { i32, [4 x i8] }
+
+define i32 @test1() {
+ %A = extractvalue %struct { i32 2, [4 x i8] c"foo\00" }, 0
+ ret i32 %A
+; CHECK: @test1
+; CHECK: ret i32 2
+}
+
+define i8 @test2() {
+ %A = extractvalue %struct { i32 2, [4 x i8] c"foo\00" }, 1, 2
+ ret i8 %A
+; CHECK: @test2
+; CHECK: ret i8 111
+}
+
+define i32 @test3() {
+ %A = extractvalue [3 x %struct] [ %struct { i32 0, [4 x i8] c"aaaa" }, %struct { i32 1, [4 x i8] c"bbbb" }, %struct { i32 2, [4 x i8] c"cccc" } ], 1, 0
+ ret i32 %A
+; CHECK: @test3
+; CHECK: ret i32 1
+}
+
+define i32 @zeroinitializer-test1() {
+ %A = extractvalue %struct zeroinitializer, 0
+ ret i32 %A
+; CHECK: @zeroinitializer-test1
+; CHECK: ret i32 0
+}
+
+define i8 @zeroinitializer-test2() {
+ %A = extractvalue %struct zeroinitializer, 1, 2
+ ret i8 %A
+; CHECK: @zeroinitializer-test2
+; CHECK: ret i8 0
+}
+
+define i32 @zeroinitializer-test3() {
+ %A = extractvalue [3 x %struct] zeroinitializer, 1, 0
+ ret i32 %A
+; CHECK: @zeroinitializer-test3
+; CHECK: ret i32 0
+}
+
+define i32 @undef-test1() {
+ %A = extractvalue %struct undef, 0
+ ret i32 %A
+; CHECK: @undef-test1
+; CHECK: ret i32 undef
+}
+
+define i8 @undef-test2() {
+ %A = extractvalue %struct undef, 1, 2
+ ret i8 %A
+; CHECK: @undef-test2
+; CHECK: ret i8 undef
+}
+
+define i32 @undef-test3() {
+ %A = extractvalue [3 x %struct] undef, 1, 0
+ ret i32 %A
+; CHECK: @undef-test3
+; CHECK: ret i32 undef
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/float-to-ptr-cast.ll b/src/LLVM/test/Transforms/ConstProp/float-to-ptr-cast.ll
new file mode 100644
index 0000000..f60af45
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/float-to-ptr-cast.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+define i32* @test1() {
+ %X = inttoptr i64 0 to i32* ; <i32*> [#uses=1]
+ ret i32* %X
+}
+
+; CHECK: ret i32* null
+
+define i32* @test2() {
+ ret i32* null
+}
+
+; CHECK: ret i32* null
+
diff --git a/src/LLVM/test/Transforms/ConstProp/insertvalue.ll b/src/LLVM/test/Transforms/ConstProp/insertvalue.ll
new file mode 100644
index 0000000..a4b7bb1
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/insertvalue.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+%struct = type { i32, [4 x i8] }
+
+define %struct @test1() {
+ %A = insertvalue %struct { i32 2, [4 x i8] c"foo\00" }, i32 1, 0
+ ret %struct %A
+; CHECK: @test1
+; CHECK: ret %struct { i32 1, [4 x i8] c"foo\00" }
+}
+
+define %struct @test2() {
+ %A = insertvalue %struct { i32 2, [4 x i8] c"foo\00" }, i8 1, 1, 2
+ ret %struct %A
+; CHECK: @test2
+; CHECK: ret %struct { i32 2, [4 x i8] c"fo\01\00" }
+}
+
+define [3 x %struct] @test3() {
+ %A = insertvalue [3 x %struct] [ %struct { i32 0, [4 x i8] c"aaaa" }, %struct { i32 1, [4 x i8] c"bbbb" }, %struct { i32 2, [4 x i8] c"cccc" } ], i32 -1, 1, 0
+ ret [3 x %struct] %A
+; CHECK: @test3
+; CHECK:ret [3 x %struct] [%struct { i32 0, [4 x i8] c"aaaa" }, %struct { i32 -1, [4 x i8] c"bbbb" }, %struct { i32 2, [4 x i8] c"cccc" }]
+}
+
+define %struct @zeroinitializer-test1() {
+ %A = insertvalue %struct zeroinitializer, i32 1, 0
+ ret %struct %A
+; CHECK: @zeroinitializer-test1
+; CHECK: ret %struct { i32 1, [4 x i8] zeroinitializer }
+}
+
+define %struct @zeroinitializer-test2() {
+ %A = insertvalue %struct zeroinitializer, i8 1, 1, 2
+ ret %struct %A
+; CHECK: @zeroinitializer-test2
+; CHECK: ret %struct { i32 0, [4 x i8] c"\00\00\01\00" }
+}
+
+define [3 x %struct] @zeroinitializer-test3() {
+ %A = insertvalue [3 x %struct] zeroinitializer, i32 1, 1, 0
+ ret [3 x %struct] %A
+; CHECK: @zeroinitializer-test3
+; CHECK: ret [3 x %struct] [%struct zeroinitializer, %struct { i32 1, [4 x i8] zeroinitializer }, %struct zeroinitializer]
+}
+
+define %struct @undef-test1() {
+ %A = insertvalue %struct undef, i32 1, 0
+ ret %struct %A
+; CHECK: @undef-test1
+; CHECK: ret %struct { i32 1, [4 x i8] undef }
+}
+
+define %struct @undef-test2() {
+ %A = insertvalue %struct undef, i8 0, 1, 2
+ ret %struct %A
+; CHECK: @undef-test2
+; CHECK: ret %struct { i32 undef, [4 x i8] [i8 undef, i8 undef, i8 0, i8 undef] }
+}
+
+define [3 x %struct] @undef-test3() {
+ %A = insertvalue [3 x %struct] undef, i32 0, 1, 0
+ ret [3 x %struct] %A
+; CHECK: @undef-test3
+; CHECK: ret [3 x %struct] [%struct undef, %struct { i32 0, [4 x i8] undef }, %struct undef]
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/loads.ll b/src/LLVM/test/Transforms/ConstProp/loads.ll
new file mode 100644
index 0000000..74d80aa
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/loads.ll
@@ -0,0 +1,139 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+@g1 = constant {{i32,i8},i32} {{i32,i8} { i32 -559038737, i8 186 }, i32 -889275714 }
+@g2 = constant double 1.0
+@g3 = constant {i64, i64} { i64 123, i64 112312312 }
+
+; Simple load
+define i32 @test1() {
+ %r = load i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0)
+ ret i32 %r
+; CHECK: @test1
+; CHECK: ret i32 -559038737
+}
+
+; PR3152
+; Load of first 16 bits of 32-bit value.
+define i16 @test2() {
+ %r = load i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*)
+ ret i16 %r
+
+; CHECK: @test2
+; CHECK: ret i16 -16657
+}
+
+; Load of second 16 bits of 32-bit value.
+define i16 @test3() {
+ %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1)
+ ret i16 %r
+
+; CHECK: @test3
+; CHECK: ret i16 -8531
+}
+
+; Load of 8 bit field + tail padding.
+define i16 @test4() {
+ %r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 2)
+ ret i16 %r
+; CHECK: @test4
+; CHECK: ret i16 186
+}
+
+; Load of double bits.
+define i64 @test6() {
+ %r = load i64* bitcast(double* @g2 to i64*)
+ ret i64 %r
+
+; CHECK: @test6
+; CHECK: ret i64 4607182418800017408
+}
+
+; Load of double bits.
+define i16 @test7() {
+ %r = load i16* bitcast(double* @g2 to i16*)
+ ret i16 %r
+
+; CHECK: @test7
+; CHECK: ret i16 0
+}
+
+; Double load.
+define double @test8() {
+ %r = load double* bitcast({{i32,i8},i32}* @g1 to double*)
+ ret double %r
+
+; CHECK: @test8
+; CHECK: ret double 0xBADEADBEEF
+}
+
+
+; i128 load.
+define i128 @test9() {
+ %r = load i128* bitcast({i64, i64}* @g3 to i128*)
+ ret i128 %r
+
+; CHECK: @test9
+; CHECK: ret i128 2071796475790618158476296315
+}
+
+; vector load.
+define <2 x i64> @test10() {
+ %r = load <2 x i64>* bitcast({i64, i64}* @g3 to <2 x i64>*)
+ ret <2 x i64> %r
+
+; CHECK: @test10
+; CHECK: ret <2 x i64> <i64 123, i64 112312312>
+}
+
+
+; PR5287
+@g4 = internal constant { i8, i8 } { i8 -95, i8 8 }
+
+define i16 @test11() nounwind {
+entry:
+ %a = load i16* bitcast ({ i8, i8 }* @g4 to i16*)
+ ret i16 %a
+
+; CHECK: @test11
+; CHECK: ret i16 2209
+}
+
+
+; PR5551
+@test12g = private constant [6 x i8] c"a\00b\00\00\00"
+
+define i16 @test12() {
+ %a = load i16* getelementptr inbounds ([3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1)
+ ret i16 %a
+; CHECK: @test12
+; CHECK: ret i16 98
+}
+
+
+; PR5978
+@g5 = constant i8 4
+define i1 @test13() {
+ %A = load i1* bitcast (i8* @g5 to i1*)
+ ret i1 %A
+; CHECK: @test13
+; CHECK: ret i1 false
+}
+
+@g6 = constant [2 x i8*] [i8* inttoptr (i64 1 to i8*), i8* inttoptr (i64 2 to i8*)]
+define i64 @test14() nounwind {
+entry:
+ %tmp = load i64* bitcast ([2 x i8*]* @g6 to i64*)
+ ret i64 %tmp
+; CHECK: @test14
+; CHECK: ret i64 1
+}
+
+define i64 @test15() nounwind {
+entry:
+ %tmp = load i64* bitcast (i8** getelementptr inbounds ([2 x i8*]* @g6, i32 0, i64 1) to i64*)
+ ret i64 %tmp
+; CHECK: @test15
+; CHECK: ret i64 2
+}
diff --git a/src/LLVM/test/Transforms/ConstProp/logicaltest.ll b/src/LLVM/test/Transforms/ConstProp/logicaltest.ll
new file mode 100644
index 0000000..c8a9985
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/logicaltest.ll
@@ -0,0 +1,35 @@
+; Ensure constant propagation of logical instructions is working correctly.
+
+; RUN: opt < %s -constprop -die -S | FileCheck %s
+; CHECK-NOT: {{and|or|xor}}
+
+define i32 @test1() {
+ %R = and i32 4, 1234 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i1 @test1.upgrd.1() {
+ %R = and i1 true, false ; <i1> [#uses=1]
+ ret i1 %R
+}
+
+define i32 @test2() {
+ %R = or i32 4, 1234 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i1 @test2.upgrd.2() {
+ %R = or i1 true, false ; <i1> [#uses=1]
+ ret i1 %R
+}
+
+define i32 @test3() {
+ %R = xor i32 4, 1234 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i1 @test3.upgrd.3() {
+ %R = xor i1 true, false ; <i1> [#uses=1]
+ ret i1 %R
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/overflow-ops.ll b/src/LLVM/test/Transforms/ConstProp/overflow-ops.ll
new file mode 100644
index 0000000..849bf9e
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/overflow-ops.ll
@@ -0,0 +1,207 @@
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+
+declare {i8, i1} @llvm.uadd.with.overflow.i8(i8, i8)
+declare {i8, i1} @llvm.usub.with.overflow.i8(i8, i8)
+declare {i8, i1} @llvm.umul.with.overflow.i8(i8, i8)
+
+declare {i8, i1} @llvm.sadd.with.overflow.i8(i8, i8)
+declare {i8, i1} @llvm.ssub.with.overflow.i8(i8, i8)
+declare {i8, i1} @llvm.smul.with.overflow.i8(i8, i8)
+
+;;-----------------------------
+;; uadd
+;;-----------------------------
+
+define {i8, i1} @uadd_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 42, i8 100)
+ ret {i8, i1} %t
+
+; CHECK: @uadd_1
+; CHECK: ret { i8, i1 } { i8 -114, i1 false }
+}
+
+define {i8, i1} @uadd_2() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 142, i8 120)
+ ret {i8, i1} %t
+
+; CHECK: @uadd_2
+; CHECK: ret { i8, i1 } { i8 6, i1 true }
+}
+
+;;-----------------------------
+;; usub
+;;-----------------------------
+
+define {i8, i1} @usub_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.usub.with.overflow.i8(i8 4, i8 2)
+ ret {i8, i1} %t
+
+; CHECK: @usub_1
+; CHECK: ret { i8, i1 } { i8 2, i1 false }
+}
+
+define {i8, i1} @usub_2() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.usub.with.overflow.i8(i8 4, i8 6)
+ ret {i8, i1} %t
+
+; CHECK: @usub_2
+; CHECK: ret { i8, i1 } { i8 -2, i1 true }
+}
+
+;;-----------------------------
+;; umul
+;;-----------------------------
+
+define {i8, i1} @umul_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.umul.with.overflow.i8(i8 100, i8 3)
+ ret {i8, i1} %t
+
+; CHECK: @umul_1
+; CHECK: ret { i8, i1 } { i8 44, i1 true }
+}
+
+define {i8, i1} @umul_2() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.umul.with.overflow.i8(i8 100, i8 2)
+ ret {i8, i1} %t
+
+; CHECK: @umul_2
+; CHECK: ret { i8, i1 } { i8 -56, i1 false }
+}
+
+;;-----------------------------
+;; sadd
+;;-----------------------------
+
+define {i8, i1} @sadd_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 42, i8 2)
+ ret {i8, i1} %t
+
+; CHECK: @sadd_1
+; CHECK: ret { i8, i1 } { i8 44, i1 false }
+}
+
+define {i8, i1} @sadd_2() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 120, i8 10)
+ ret {i8, i1} %t
+
+; CHECK: @sadd_2
+; CHECK: ret { i8, i1 } { i8 -126, i1 true }
+}
+
+define {i8, i1} @sadd_3() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 -120, i8 10)
+ ret {i8, i1} %t
+
+; CHECK: @sadd_3
+; CHECK: ret { i8, i1 } { i8 -110, i1 false }
+}
+
+define {i8, i1} @sadd_4() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 -120, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @sadd_4
+; CHECK: ret { i8, i1 } { i8 126, i1 true }
+}
+
+define {i8, i1} @sadd_5() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 2, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @sadd_5
+; CHECK: ret { i8, i1 } { i8 -8, i1 false }
+}
+
+
+;;-----------------------------
+;; ssub
+;;-----------------------------
+
+define {i8, i1} @ssub_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 4, i8 2)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_1
+; CHECK: ret { i8, i1 } { i8 2, i1 false }
+}
+
+define {i8, i1} @ssub_2() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 4, i8 6)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_2
+; CHECK: ret { i8, i1 } { i8 -2, i1 false }
+}
+
+define {i8, i1} @ssub_3() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 -10, i8 120)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_3
+; CHECK: ret { i8, i1 } { i8 126, i1 true }
+}
+
+define {i8, i1} @ssub_3b() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 -10, i8 10)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_3b
+; CHECK: ret { i8, i1 } { i8 -20, i1 false }
+}
+
+define {i8, i1} @ssub_4() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 120, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_4
+; CHECK: ret { i8, i1 } { i8 -126, i1 true }
+}
+
+define {i8, i1} @ssub_4b() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 20, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_4b
+; CHECK: ret { i8, i1 } { i8 30, i1 false }
+}
+
+define {i8, i1} @ssub_5() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 -20, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @ssub_5
+; CHECK: ret { i8, i1 } { i8 -10, i1 false }
+}
+
+;;-----------------------------
+;; smul
+;;-----------------------------
+
+; rdar://8501501
+define {i8, i1} @smul_1() nounwind {
+entry:
+ %t = call {i8, i1} @llvm.smul.with.overflow.i8(i8 -20, i8 -10)
+ ret {i8, i1} %t
+
+; CHECK: @smul_1
+; CHECK: ret { i8, i1 } { i8 -56, i1 true }
+}
diff --git a/src/LLVM/test/Transforms/ConstProp/phi.ll b/src/LLVM/test/Transforms/ConstProp/phi.ll
new file mode 100644
index 0000000..18b4803
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/phi.ll
@@ -0,0 +1,17 @@
+; This is a basic sanity check for constant propagation. The add instruction
+; should be eliminated.
+
+; RUN: opt < %s -constprop -die -S | not grep phi
+
+define i32 @test(i1 %B) {
+BB0:
+ br i1 %B, label %BB1, label %BB3
+
+BB1: ; preds = %BB0
+ br label %BB3
+
+BB3: ; preds = %BB1, %BB0
+ %Ret = phi i32 [ 1, %BB0 ], [ 1, %BB1 ] ; <i32> [#uses=1]
+ ret i32 %Ret
+}
+
diff --git a/src/LLVM/test/Transforms/ConstProp/remtest.ll b/src/LLVM/test/Transforms/ConstProp/remtest.ll
new file mode 100644
index 0000000..e1ea6c3
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstProp/remtest.ll
@@ -0,0 +1,24 @@
+; Ensure constant propagation of remainder instructions is working correctly.
+
+; RUN: opt < %s -constprop -die -S | not grep rem
+
+define i32 @test1() {
+ %R = srem i32 4, 3 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i32 @test2() {
+ %R = srem i32 123, -23 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define float @test3() {
+ %R = frem float 0x4028E66660000000, 0x405ECDA1C0000000 ; <float> [#uses=1]
+ ret float %R
+}
+
+define double @test4() {
+ %R = frem double 0x4073833BEE07AFF8, 0x4028AAABB2A0D19C ; <double> [#uses=1]
+ ret double %R
+}
+
diff --git a/src/LLVM/test/Transforms/ConstantMerge/2002-09-23-CPR-Update.ll b/src/LLVM/test/Transforms/ConstantMerge/2002-09-23-CPR-Update.ll
new file mode 100644
index 0000000..bab169a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/2002-09-23-CPR-Update.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -constmerge > /dev/null
+
+@foo.upgrd.1 = internal constant { i32 } { i32 7 } ; <{ i32 }*> [#uses=1]
+@bar = internal constant { i32 } { i32 7 } ; <{ i32 }*> [#uses=1]
+
+declare i32 @test(i32*)
+
+define void @foo() {
+ call i32 @test( i32* getelementptr ({ i32 }* @foo.upgrd.1, i64 0, i32 0) ) ; <i32>:1 [#uses=0]
+ call i32 @test( i32* getelementptr ({ i32 }* @bar, i64 0, i32 0) ) ; <i32>:2 [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/ConstantMerge/2003-10-28-MergeExternalConstants.ll b/src/LLVM/test/Transforms/ConstantMerge/2003-10-28-MergeExternalConstants.ll
new file mode 100644
index 0000000..cb76083
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/2003-10-28-MergeExternalConstants.ll
@@ -0,0 +1,7 @@
+; RUN: opt -S -constmerge %s | FileCheck %s
+
+; CHECK: @foo = constant i32 6
+; CHECK: @bar = constant i32 6
+@foo = constant i32 6 ; <i32*> [#uses=0]
+@bar = constant i32 6 ; <i32*> [#uses=0]
+
diff --git a/src/LLVM/test/Transforms/ConstantMerge/2011-01-15-EitherOrder.ll b/src/LLVM/test/Transforms/ConstantMerge/2011-01-15-EitherOrder.ll
new file mode 100644
index 0000000..f561daf
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/2011-01-15-EitherOrder.ll
@@ -0,0 +1,18 @@
+; RUN: opt -constmerge %s -S -o - | FileCheck %s
+; PR8978
+
+declare i32 @zed(%struct.foobar*, %struct.foobar*)
+
+%struct.foobar = type { i32 }
+; CHECK: bar.d
+@bar.d = unnamed_addr constant %struct.foobar zeroinitializer, align 4
+; CHECK-NOT: foo.d
+@foo.d = internal constant %struct.foobar zeroinitializer, align 4
+define i32 @main() nounwind ssp {
+entry:
+; CHECK: bar.d
+ %call2 = tail call i32 @zed(%struct.foobar* @foo.d, %struct.foobar* @bar.d)
+nounwind
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/ConstantMerge/dg.exp b/src/LLVM/test/Transforms/ConstantMerge/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/ConstantMerge/dont-merge.ll b/src/LLVM/test/Transforms/ConstantMerge/dont-merge.ll
new file mode 100644
index 0000000..7d983de
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/dont-merge.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -constmerge -S | FileCheck %s
+
+; Don't merge constants with specified sections.
+
+@T1G1 = internal constant i32 1, section "foo"
+@T1G2 = internal constant i32 1, section "bar"
+@T1G3 = internal constant i32 1, section "bar"
+
+; CHECK: @T1G1
+; CHECK: @T1G2
+; CHECK: @T1G3
+
+define void @test1(i32** %P1, i32** %P2, i32** %P3) {
+ store i32* @T1G1, i32** %P1
+ store i32* @T1G2, i32** %P2
+ store i32* @T1G3, i32** %P3
+ ret void
+}
+
+@T2a = internal constant i32 224
+@T2b = internal addrspace(30) constant i32 224
+
+; CHECK: @T2a
+; CHECK: @T2b
+
+define void @test2(i32** %P1, i32 addrspace(30)** %P2) {
+ store i32* @T2a, i32** %P1
+ store i32 addrspace(30)* @T2b, i32 addrspace(30)** %P2
+ ret void
+}
+
+; PR8144 - Don't merge globals marked attribute(used)
+; CHECK: @T3A =
+; CHECK: @T3B =
+
+@T3A = internal constant i32 0
+@T3B = internal constant i32 0
+@llvm.used = appending global [2 x i32*] [i32* @T3A, i32* @T3B], section
+"llvm.metadata"
+
+define void @test3() {
+ call void asm sideeffect "T3A, T3B",""() ; invisible use of T3A and T3B
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ConstantMerge/merge-both.ll b/src/LLVM/test/Transforms/ConstantMerge/merge-both.ll
new file mode 100644
index 0000000..b71eb43
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/merge-both.ll
@@ -0,0 +1,39 @@
+; RUN: opt -constmerge %s -S -o - | FileCheck %s
+; Test that in one run var3 is merged into var2 and var1 into var4.
+; Test that we merge @var5 and @var6 into one with the higher alignment, and
+; don't merge var7/var8 into var5/var6.
+
+declare void @zed(%struct.foobar*, %struct.foobar*)
+
+%struct.foobar = type { i32 }
+
+@var1 = internal constant %struct.foobar { i32 2 }
+@var2 = unnamed_addr constant %struct.foobar { i32 2 }
+@var3 = internal constant %struct.foobar { i32 2 }
+@var4 = unnamed_addr constant %struct.foobar { i32 2 }
+
+; CHECK: %struct.foobar = type { i32 }
+; CHECK-NOT: @
+; CHECK: @var2 = constant %struct.foobar { i32 2 }
+; CHECK-NEXT: @var4 = constant %struct.foobar { i32 2 }
+
+declare void @helper([16 x i8]*)
+@var5 = internal constant [16 x i8] c"foo1bar2foo3bar\00", align 16
+@var6 = private unnamed_addr constant [16 x i8] c"foo1bar2foo3bar\00", align 1
+@var7 = internal constant [16 x i8] c"foo1bar2foo3bar\00"
+@var8 = private unnamed_addr constant [16 x i8] c"foo1bar2foo3bar\00"
+
+; CHECK-NEXT: @var6 = private constant [16 x i8] c"foo1bar2foo3bar\00", align 16
+; CHECK-NEXT: @var8 = private constant [16 x i8] c"foo1bar2foo3bar\00"
+
+define i32 @main() {
+entry:
+ call void @zed(%struct.foobar* @var1, %struct.foobar* @var2)
+ call void @zed(%struct.foobar* @var3, %struct.foobar* @var4)
+ call void @helper([16 x i8]* @var5)
+ call void @helper([16 x i8]* @var6)
+ call void @helper([16 x i8]* @var7)
+ call void @helper([16 x i8]* @var8)
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/ConstantMerge/unnamed-addr.ll b/src/LLVM/test/Transforms/ConstantMerge/unnamed-addr.ll
new file mode 100644
index 0000000..2410083
--- /dev/null
+++ b/src/LLVM/test/Transforms/ConstantMerge/unnamed-addr.ll
@@ -0,0 +1,40 @@
+; RUN: opt -constmerge %s -S -o - | FileCheck %s
+; Test which corresponding x and y are merged and that unnamed_addr
+; is correctly set.
+
+declare void @zed(%struct.foobar*, %struct.foobar*)
+
+%struct.foobar = type { i32 }
+
+@test1.x = internal constant %struct.foobar { i32 1 }
+@test1.y = constant %struct.foobar { i32 1 }
+
+@test2.x = internal constant %struct.foobar { i32 2 }
+@test2.y = unnamed_addr constant %struct.foobar { i32 2 }
+
+@test3.x = internal unnamed_addr constant %struct.foobar { i32 3 }
+@test3.y = constant %struct.foobar { i32 3 }
+
+@test4.x = internal unnamed_addr constant %struct.foobar { i32 4 }
+@test4.y = unnamed_addr constant %struct.foobar { i32 4 }
+
+
+; CHECK: %struct.foobar = type { i32 }
+; CHECK-NOT: @
+; CHECK: @test1.x = internal constant %struct.foobar { i32 1 }
+; CHECK-NEXT: @test1.y = constant %struct.foobar { i32 1 }
+; CHECK-NEXT: @test2.y = constant %struct.foobar { i32 2 }
+; CHECK-NEXT: @test3.y = constant %struct.foobar { i32 3 }
+; CHECK-NEXT: @test4.y = unnamed_addr constant %struct.foobar { i32 4 }
+; CHECK-NOT: @
+; CHECK: declare void @zed(%struct.foobar*, %struct.foobar*)
+
+define i32 @main() {
+entry:
+ call void @zed(%struct.foobar* @test1.x, %struct.foobar* @test1.y)
+ call void @zed(%struct.foobar* @test2.x, %struct.foobar* @test2.y)
+ call void @zed(%struct.foobar* @test3.x, %struct.foobar* @test3.y)
+ call void @zed(%struct.foobar* @test4.x, %struct.foobar* @test4.y)
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-02-Trunc.ll b/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-02-Trunc.ll
new file mode 100644
index 0000000..fef5b85
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-02-Trunc.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S < %s -correlated-propagation | FileCheck %s
+
+; CHECK: @test
+define i16 @test(i32 %a, i1 %b) {
+entry:
+ %c = icmp eq i32 %a, 0
+ br i1 %c, label %left, label %right
+
+right:
+ %d = trunc i32 %a to i1
+ br label %merge
+
+left:
+ br i1 %b, label %merge, label %other
+
+other:
+ ret i16 23
+
+merge:
+ %f = phi i1 [%b, %left], [%d, %right]
+; CHECK: select i1 %f, i16 1, i16 0
+ %h = select i1 %f, i16 1, i16 0
+; CHECK: ret i16 %h
+ ret i16 %h
+}
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-26-MergeConstantRange.ll b/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-26-MergeConstantRange.ll
new file mode 100644
index 0000000..9ccc787
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/2010-09-26-MergeConstantRange.ll
@@ -0,0 +1,82 @@
+; RUN: opt < %s -jump-threading -correlated-propagation
+
+%struct.S2 = type {}
+
+@g_128 = external global %struct.S2, align 1
+@g_106 = external global i16, align 2
+
+define void @int328(i16 signext %p_82) noreturn nounwind ssp {
+entry:
+ %tobool3 = icmp eq i16 %p_82, 0
+ br label %for.cond.outer
+
+for.cond.outer: ; preds = %for.cond.loopexit, %entry
+ br label %for.cond
+
+for.cond.loopexit: ; preds = %bb.nph, %for.cond9.preheader
+ br label %for.cond.outer
+
+for.cond.loopexit4.us-lcssa: ; preds = %if.then
+ br label %for.cond.loopexit4
+
+for.cond.loopexit4: ; preds = %for.cond.loopexit4.us-lcssa.us, %for.cond.loopexit4.us-lcssa
+ br label %for.cond.backedge
+
+for.cond: ; preds = %for.cond.backedge, %for.cond.outer
+ br i1 %tobool3, label %for.cond.split.us, label %for.cond.for.cond.split_crit_edge
+
+for.cond.for.cond.split_crit_edge: ; preds = %for.cond
+ br label %lbl_133
+
+for.cond.split.us: ; preds = %for.cond
+ br label %lbl_133.us
+
+lbl_133.us: ; preds = %lbl_134.us, %for.cond.split.us
+ br i1 undef, label %if.else14.us-lcssa.us, label %if.then.us
+
+lbl_134.us: ; preds = %if.then.us
+ br i1 icmp eq (i16 ptrtoint (%struct.S2* @g_128 to i16), i16 0), label %for.cond9.preheader.us-lcssa.us, label %lbl_133.us
+
+if.then.us: ; preds = %lbl_133.us
+ br i1 true, label %for.cond.loopexit4.us-lcssa.us, label %lbl_134.us
+
+if.else14.us-lcssa.us: ; preds = %lbl_133.us
+ br label %if.else14
+
+for.cond9.preheader.us-lcssa.us: ; preds = %lbl_134.us
+ br label %for.cond9.preheader
+
+for.cond.loopexit4.us-lcssa.us: ; preds = %if.then.us
+ br label %for.cond.loopexit4
+
+lbl_133: ; preds = %lbl_134, %for.cond.for.cond.split_crit_edge
+ %l_109.0 = phi i16 [ 0, %for.cond.for.cond.split_crit_edge ], [ ptrtoint (%struct.S2* @g_128 to i16), %lbl_134 ]
+ %tobool = icmp eq i32 undef, 0
+ br i1 %tobool, label %if.else14.us-lcssa, label %if.then
+
+if.then: ; preds = %lbl_133
+ br i1 false, label %for.cond.loopexit4.us-lcssa, label %lbl_134
+
+lbl_134: ; preds = %if.then
+ br i1 icmp eq (i16 ptrtoint (%struct.S2* @g_128 to i16), i16 0), label %for.cond9.preheader.us-lcssa, label %lbl_133
+
+for.cond9.preheader.us-lcssa: ; preds = %lbl_134
+ br label %for.cond9.preheader
+
+for.cond9.preheader: ; preds = %for.cond9.preheader.us-lcssa, %for.cond9.preheader.us-lcssa.us
+ br i1 undef, label %bb.nph, label %for.cond.loopexit
+
+bb.nph: ; preds = %for.cond9.preheader
+ br label %for.cond.loopexit
+
+if.else14.us-lcssa: ; preds = %lbl_133
+ br label %if.else14
+
+if.else14: ; preds = %if.else14.us-lcssa, %if.else14.us-lcssa.us
+ %l_109.0.lcssa = phi i16 [ %l_109.0, %if.else14.us-lcssa ], [ 0, %if.else14.us-lcssa.us ]
+ store i16 undef, i16* @g_106, align 2
+ br label %for.cond.backedge
+
+for.cond.backedge: ; preds = %if.else14, %for.cond.loopexit4
+ br label %for.cond
+}
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/basic.ll b/src/LLVM/test/Transforms/CorrelatedValuePropagation/basic.ll
new file mode 100644
index 0000000..270c048
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/basic.ll
@@ -0,0 +1,82 @@
+; RUN: opt < %s -correlated-propagation -S | FileCheck %s
+; PR2581
+
+; CHECK: @test1
+define i32 @test1(i1 %C) nounwind {
+ br i1 %C, label %exit, label %body
+
+body: ; preds = %0
+; CHECK-NOT: select
+ %A = select i1 %C, i32 10, i32 11 ; <i32> [#uses=1]
+; CHECK: ret i32 11
+ ret i32 %A
+
+exit: ; preds = %0
+; CHECK: ret i32 10
+ ret i32 10
+}
+
+; PR4420
+declare i1 @ext()
+; CHECK: @test2
+define i1 @test2() {
+entry:
+ %cond = tail call i1 @ext() ; <i1> [#uses=2]
+ br i1 %cond, label %bb1, label %bb2
+
+bb1: ; preds = %entry
+ %cond2 = tail call i1 @ext() ; <i1> [#uses=1]
+ br i1 %cond2, label %bb3, label %bb2
+
+bb2: ; preds = %bb1, %entry
+; CHECK-NOT: phi i1
+ %cond_merge = phi i1 [ %cond, %entry ], [ false, %bb1 ] ; <i1> [#uses=1]
+; CHECK: ret i1 false
+ ret i1 %cond_merge
+
+bb3: ; preds = %bb1
+ %res = tail call i1 @ext() ; <i1> [#uses=1]
+; CHECK: ret i1 %res
+ ret i1 %res
+}
+
+; PR4855
+@gv = internal constant i8 7
+; CHECK: @test3
+define i8 @test3(i8* %a) nounwind {
+entry:
+ %cond = icmp eq i8* %a, @gv
+ br i1 %cond, label %bb2, label %bb
+
+bb: ; preds = %entry
+ ret i8 0
+
+bb2: ; preds = %entry
+; CHECK: %should_be_const = load i8* @gv
+ %should_be_const = load i8* %a
+ ret i8 %should_be_const
+}
+
+; PR1757
+; CHECK: @test4
+define i32 @test4(i32) {
+EntryBlock:
+; CHECK: icmp sgt i32 %0, 2
+ %.demorgan = icmp sgt i32 %0, 2
+ br i1 %.demorgan, label %GreaterThanTwo, label %LessThanOrEqualToTwo
+
+GreaterThanTwo:
+; CHECK-NOT: icmp eq i32 %0, 2
+ icmp eq i32 %0, 2
+; CHECK: br i1 false
+ br i1 %1, label %Impossible, label %NotTwoAndGreaterThanTwo
+
+NotTwoAndGreaterThanTwo:
+ ret i32 2
+
+Impossible:
+ ret i32 1
+
+LessThanOrEqualToTwo:
+ ret i32 0
+}
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/crash.ll b/src/LLVM/test/Transforms/CorrelatedValuePropagation/crash.ll
new file mode 100644
index 0000000..80c43d0
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/crash.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -correlated-propagation
+
+; PR8161
+define void @test1() nounwind ssp {
+entry:
+ br label %for.end
+
+for.cond.us.us: ; preds = %for.cond.us.us
+ %cmp6.i.us.us = icmp sgt i32 1, 0
+ %lor.ext.i.us.us = zext i1 %cmp6.i.us.us to i32
+ %lor.ext.add.i.us.us = select i1 %cmp6.i.us.us, i32 %lor.ext.i.us.us, i32 undef
+ %conv.i.us.us = trunc i32 %lor.ext.add.i.us.us to i16
+ %sext.us.us = shl i16 %conv.i.us.us, 8
+ %conv6.us.us = ashr i16 %sext.us.us, 8
+ %and.us.us = and i16 %conv6.us.us, %and.us.us
+ br i1 false, label %for.end, label %for.cond.us.us
+
+for.end: ; preds = %for.cond.us, %for.cond.us.us, %entry
+ ret void
+}
+
+; PR 8790
+define void @test2() nounwind ssp {
+entry:
+ br label %func_29.exit
+
+sdf.exit.i:
+ %l_44.1.mux.i = select i1 %tobool5.not.i, i8 %l_44.1.mux.i, i8 1
+ br label %srf.exit.i
+
+srf.exit.i:
+ %tobool5.not.i = icmp ne i8 undef, 0
+ br i1 %tobool5.not.i, label %sdf.exit.i, label %func_29.exit
+
+func_29.exit:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/dg.exp b/src/LLVM/test/Transforms/CorrelatedValuePropagation/dg.exp
new file mode 100644
index 0000000..de42dad
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.ll]]
diff --git a/src/LLVM/test/Transforms/CorrelatedValuePropagation/non-null.ll b/src/LLVM/test/Transforms/CorrelatedValuePropagation/non-null.ll
new file mode 100644
index 0000000..b14abd8
--- /dev/null
+++ b/src/LLVM/test/Transforms/CorrelatedValuePropagation/non-null.ll
@@ -0,0 +1,103 @@
+; RUN: opt < %s -correlated-propagation -S | FileCheck %s
+
+define void @test1(i8* %ptr) {
+; CHECK: test1
+ %A = load i8* %ptr
+ br label %bb
+bb:
+ icmp ne i8* %ptr, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+define void @test2(i8* %ptr) {
+; CHECK: test2
+ store i8 0, i8* %ptr
+ br label %bb
+bb:
+ icmp ne i8* %ptr, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+define void @test3() {
+; CHECK: test3
+ %ptr = alloca i8
+ br label %bb
+bb:
+ icmp ne i8* %ptr, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
+define void @test4(i8* %dest, i8* %src) {
+; CHECK: test4
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1, i32 1, i1 false)
+ br label %bb
+bb:
+ icmp ne i8* %dest, null
+ icmp ne i8* %src, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
+define void @test5(i8* %dest, i8* %src) {
+; CHECK: test5
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1, i32 1, i1 false)
+ br label %bb
+bb:
+ icmp ne i8* %dest, null
+ icmp ne i8* %src, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1)
+define void @test6(i8* %dest) {
+; CHECK: test6
+ call void @llvm.memset.p0i8.i32(i8* %dest, i8 255, i32 1, i32 1, i1 false)
+ br label %bb
+bb:
+ icmp ne i8* %dest, null
+; CHECK-NOT: icmp
+ ret void
+}
+
+define void @test7(i8* %dest, i8* %src, i32 %len) {
+; CHECK: test7
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i32 1, i1 false)
+ br label %bb
+bb:
+ %KEEP1 = icmp ne i8* %dest, null
+; CHECK: KEEP1
+ %KEEP2 = icmp ne i8* %src, null
+; CHECK: KEEP2
+ ret void
+}
+
+declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1) *, i8 addrspace(1) *, i32, i32, i1)
+define void @test8(i8 addrspace(1) * %dest, i8 addrspace(1) * %src) {
+; CHECK: test8
+ call void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1) * %dest, i8 addrspace(1) * %src, i32 1, i32 1, i1 false)
+ br label %bb
+bb:
+ %KEEP1 = icmp ne i8 addrspace(1) * %dest, null
+; CHECK: KEEP1
+ %KEEP2 = icmp ne i8 addrspace(1) * %src, null
+; CHECK: KEEP2
+ ret void
+}
+
+define void @test9(i8* %dest, i8* %src) {
+; CHECK: test9
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1, i32 1, i1 true)
+ br label %bb
+bb:
+ %KEEP1 = icmp ne i8* %dest, null
+; CHECK: KEEP1
+ %KEEP2 = icmp ne i8* %src, null
+; CHECK: KEEP2
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2006-06-27-struct-ret.ll b/src/LLVM/test/Transforms/DeadArgElim/2006-06-27-struct-ret.ll
new file mode 100644
index 0000000..793c59f
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2006-06-27-struct-ret.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -deadargelim -disable-output
+
+define internal void @build_delaunay({ i32 }* sret %agg.result) {
+ ret void
+}
+
+define void @test() {
+ call void @build_delaunay( { i32 }* sret null )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2007-02-07-FuncRename.ll b/src/LLVM/test/Transforms/DeadArgElim/2007-02-07-FuncRename.ll
new file mode 100644
index 0000000..5b69179
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2007-02-07-FuncRename.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -deadargelim -S | grep {@test(}
+; RUN: opt < %s -deadargelim -S | not grep dead
+
+define internal i32 @test(i32 %X, i32 %dead) {
+ ret i32 %X
+}
+
+define i32 @caller() {
+ %A = call i32 @test(i32 123, i32 456)
+ ret i32 %A
+}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2007-10-18-VarargsReturn.ll b/src/LLVM/test/Transforms/DeadArgElim/2007-10-18-VarargsReturn.ll
new file mode 100644
index 0000000..d4edce9
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2007-10-18-VarargsReturn.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -deadargelim -S | not grep {ret i32 0}
+; PR1735
+
+define internal i32 @test(i32 %A, ...) {
+ ret i32 %A
+}
+
+define i32 @foo() {
+ %A = call i32(i32, ...)* @test(i32 1)
+ ret i32 %A
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll b/src/LLVM/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll
new file mode 100644
index 0000000..7c6c575
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2007-12-20-ParamAttrs.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -deadargelim -S > %t
+; RUN: cat %t | grep nounwind | count 2
+; RUN: cat %t | grep signext | count 2
+; RUN: cat %t | not grep inreg
+; RUN: cat %t | not grep zeroext
+; RUN: cat %t | not grep byval
+
+ %struct = type { }
+
+@g = global i8 0
+
+define internal zeroext i8 @foo(i8* inreg %p, i8 signext %y, ... ) nounwind {
+ store i8 %y, i8* @g
+ ret i8 0
+}
+
+define i32 @bar() {
+ %A = call zeroext i8(i8*, i8, ...)* @foo(i8* inreg null, i8 signext 1, %struct* byval null ) nounwind
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2008-01-16-VarargsParamAttrs.ll b/src/LLVM/test/Transforms/DeadArgElim/2008-01-16-VarargsParamAttrs.ll
new file mode 100644
index 0000000..93282f7
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2008-01-16-VarargsParamAttrs.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -deadargelim -S | grep byval
+
+ %struct.point = type { double, double }
+@pts = global [4 x %struct.point] [ %struct.point { double 1.000000e+00, double 2.000000e+00 }, %struct.point { double 3.000000e+00, double 4.000000e+00 }, %struct.point { double 5.000000e+00, double 6.000000e+00 }, %struct.point { double 7.000000e+00, double 8.000000e+00 } ], align 32 ; <[4 x %struct.point]*> [#uses=1]
+
+define internal i32 @va1(i32 %nargs, ...) {
+entry:
+ %pi = alloca %struct.point ; <%struct.point*> [#uses=0]
+ %args = alloca i8* ; <i8**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %args1 = bitcast i8** %args to i8* ; <i8*> [#uses=1]
+ call void @llvm.va_start( i8* %args1 )
+ %args41 = bitcast i8** %args to i8* ; <i8*> [#uses=1]
+ call void @llvm.va_end( i8* %args41 )
+ ret i32 undef
+}
+
+declare void @llvm.va_start(i8*) nounwind
+
+declare void @llvm.va_end(i8*) nounwind
+
+define i32 @main() {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp = getelementptr [4 x %struct.point]* @pts, i32 0, i32 0 ; <%struct.point*> [#uses=1]
+ %tmp1 = call i32 (i32, ...)* @va1( i32 1, %struct.point* byval %tmp ) nounwind ; <i32> [#uses=0]
+ call void @exit( i32 0 ) noreturn nounwind
+ unreachable
+}
+
+declare void @exit(i32) noreturn nounwind
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2008-06-23-DeadAfterLive.ll b/src/LLVM/test/Transforms/DeadArgElim/2008-06-23-DeadAfterLive.ll
new file mode 100644
index 0000000..858c935
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2008-06-23-DeadAfterLive.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -deadargelim -die -S > %t
+; RUN: cat %t | grep 123
+
+; This test tries to catch wrongful removal of return values for a specific case
+; that was breaking llvm-gcc builds.
+
+; This function has a live return value, it is used by @alive.
+define internal i32 @test5() {
+ ret i32 123
+}
+
+; This function doesn't use the return value @test5 and tries to lure DAE into
+; marking @test5's return value dead because only this call is unused.
+define i32 @dead() {
+ %DEAD = call i32 @test5()
+ ret i32 0
+}
+
+; This function ensures the retval of @test5 is live.
+define i32 @alive() {
+ %LIVE = call i32 @test5()
+ ret i32 %LIVE
+}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll b/src/LLVM/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll
new file mode 100644
index 0000000..fc25dac
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2009-03-17-MRE-Invoke.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -deadargelim | llvm-dis
+; PR3807
+
+define internal { i32, i32 } @foo() {
+ ret {i32,i32} {i32 42, i32 4}
+}
+
+define i32 @bar() {
+ %x = invoke {i32,i32} @foo() to label %T unwind label %T2
+T:
+ %y = extractvalue {i32,i32} %x, 1
+ ret i32 %y
+T2:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+define i32 @bar2() {
+entry:
+ %x = invoke {i32,i32} @foo() to label %T unwind label %T2
+T:
+ %PN = phi i32 [0, %entry]
+ %y = extractvalue {i32,i32} %x, 1
+ ret i32 %y
+T2:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll b/src/LLVM/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll
new file mode 100644
index 0000000..2f820ba
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/2010-04-30-DbgInfo.ll
@@ -0,0 +1,68 @@
+; RUN: opt -S -deadargelim < %s | FileCheck %s
+
+@.str = private constant [1 x i8] zeroinitializer, align 1 ; <[1 x i8]*> [#uses=1]
+
+define i8* @vfs_addname(i8* %name, i32 %len, i32 %hash, i32 %flags) nounwind ssp {
+entry:
+ call void @llvm.dbg.value(metadata !{i8* %name}, i64 0, metadata !0)
+ call void @llvm.dbg.value(metadata !{i32 %len}, i64 0, metadata !10)
+ call void @llvm.dbg.value(metadata !{i32 %hash}, i64 0, metadata !11)
+ call void @llvm.dbg.value(metadata !{i32 %flags}, i64 0, metadata !12)
+; CHECK: call fastcc i8* @add_name_internal(i8* %name, i32 %hash) nounwind, !dbg !13
+ %0 = call fastcc i8* @add_name_internal(i8* %name, i32 %len, i32 %hash, i8 zeroext 0, i32 %flags) nounwind, !dbg !13 ; <i8*> [#uses=1]
+ ret i8* %0, !dbg !13
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+define internal fastcc i8* @add_name_internal(i8* %name, i32 %len, i32 %hash, i8 zeroext %extra, i32 %flags) nounwind noinline ssp {
+entry:
+ call void @llvm.dbg.value(metadata !{i8* %name}, i64 0, metadata !15)
+ call void @llvm.dbg.value(metadata !{i32 %len}, i64 0, metadata !20)
+ call void @llvm.dbg.value(metadata !{i32 %hash}, i64 0, metadata !21)
+ call void @llvm.dbg.value(metadata !{i8 %extra}, i64 0, metadata !22)
+ call void @llvm.dbg.value(metadata !{i32 %flags}, i64 0, metadata !23)
+ %0 = icmp eq i32 %hash, 0, !dbg !24 ; <i1> [#uses=1]
+ br i1 %0, label %bb, label %bb1, !dbg !24
+
+bb: ; preds = %entry
+ br label %bb2, !dbg !26
+
+bb1: ; preds = %entry
+ br label %bb2, !dbg !27
+
+bb2: ; preds = %bb1, %bb
+ %.0 = phi i8* [ getelementptr inbounds ([1 x i8]* @.str, i64 0, i64 0), %bb ], [ %name, %bb1 ] ; <i8*> [#uses=1]
+ ret i8* %.0, !dbg !27
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!0 = metadata !{i32 524545, metadata !1, metadata !"name", metadata !2, i32 8, metadata !6} ; [ DW_TAG_arg_variable ]
+!1 = metadata !{i32 524334, i32 0, metadata !2, metadata !"vfs_addname", metadata !"vfs_addname", metadata !"vfs_addname", metadata !2, i32 12, metadata !4, i1 false, i1 true, i32 0, i32 0, null, i1 false} ; [ DW_TAG_subprogram ]
+!2 = metadata !{i32 524329, metadata !"tail.c", metadata !"/Users/echeng/LLVM/radars/r7927803/", metadata !3} ; [ DW_TAG_file_type ]
+!3 = metadata !{i32 524305, i32 0, i32 1, metadata !"tail.c", metadata !"/Users/echeng/LLVM/radars/r7927803/", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build 9999)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!4 = metadata !{i32 524309, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !5, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!5 = metadata !{metadata !6, metadata !6, metadata !9, metadata !9, metadata !9}
+!6 = metadata !{i32 524303, metadata !2, metadata !"", metadata !2, i32 0, i64 64, i64 64, i64 0, i32 0, metadata !7} ; [ DW_TAG_pointer_type ]
+!7 = metadata !{i32 524326, metadata !2, metadata !"", metadata !2, i32 0, i64 8, i64 8, i64 0, i32 0, metadata !8} ; [ DW_TAG_const_type ]
+!8 = metadata !{i32 524324, metadata !2, metadata !"char", metadata !2, i32 0, i64 8, i64 8, i64 0, i32 0, i32 6} ; [ DW_TAG_base_type ]
+!9 = metadata !{i32 524324, metadata !2, metadata !"unsigned int", metadata !2, i32 0, i64 32, i64 32, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ]
+!10 = metadata !{i32 524545, metadata !1, metadata !"len", metadata !2, i32 9, metadata !9} ; [ DW_TAG_arg_variable ]
+!11 = metadata !{i32 524545, metadata !1, metadata !"hash", metadata !2, i32 10, metadata !9} ; [ DW_TAG_arg_variable ]
+!12 = metadata !{i32 524545, metadata !1, metadata !"flags", metadata !2, i32 11, metadata !9} ; [ DW_TAG_arg_variable ]
+!13 = metadata !{i32 13, i32 0, metadata !14, null}
+!14 = metadata !{i32 524299, metadata !1, i32 12, i32 0} ; [ DW_TAG_lexical_block ]
+!15 = metadata !{i32 524545, metadata !16, metadata !"name", metadata !2, i32 17, metadata !6} ; [ DW_TAG_arg_variable ]
+!16 = metadata !{i32 524334, i32 0, metadata !2, metadata !"add_name_internal", metadata !"add_name_internal", metadata !"add_name_internal", metadata !2, i32 22, metadata !17, i1 true, i1 true, i32 0, i32 0, null, i1 false} ; [ DW_TAG_subprogram ]
+!17 = metadata !{i32 524309, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !18, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!18 = metadata !{metadata !6, metadata !6, metadata !9, metadata !9, metadata !19, metadata !9}
+!19 = metadata !{i32 524324, metadata !2, metadata !"unsigned char", metadata !2, i32 0, i64 8, i64 8, i64 0, i32 0, i32 8} ; [ DW_TAG_base_type ]
+!20 = metadata !{i32 524545, metadata !16, metadata !"len", metadata !2, i32 18, metadata !9} ; [ DW_TAG_arg_variable ]
+!21 = metadata !{i32 524545, metadata !16, metadata !"hash", metadata !2, i32 19, metadata !9} ; [ DW_TAG_arg_variable ]
+!22 = metadata !{i32 524545, metadata !16, metadata !"extra", metadata !2, i32 20, metadata !19} ; [ DW_TAG_arg_variable ]
+!23 = metadata !{i32 524545, metadata !16, metadata !"flags", metadata !2, i32 21, metadata !9} ; [ DW_TAG_arg_variable ]
+!24 = metadata !{i32 23, i32 0, metadata !25, null}
+!25 = metadata !{i32 524299, metadata !16, i32 22, i32 0} ; [ DW_TAG_lexical_block ]
+!26 = metadata !{i32 24, i32 0, metadata !25, null}
+!27 = metadata !{i32 26, i32 0, metadata !25, null}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/basictest.ll b/src/LLVM/test/Transforms/DeadArgElim/basictest.ll
new file mode 100644
index 0000000..0e01333
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/basictest.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -deadargelim -S | not grep DEADARG
+
+; test - an obviously dead argument
+define internal i32 @test(i32 %v, i32 %DEADARG1, i32* %p) {
+ store i32 %v, i32* %p
+ ret i32 %v
+}
+
+; hardertest - an argument which is only used by a call of a function with a
+; dead argument.
+define internal i32 @hardertest(i32 %DEADARG2) {
+ %p = alloca i32 ; <i32*> [#uses=1]
+ %V = call i32 @test( i32 5, i32 %DEADARG2, i32* %p ) ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+; evenhardertest - recursive dead argument...
+define internal void @evenhardertest(i32 %DEADARG3) {
+ call void @evenhardertest( i32 %DEADARG3 )
+ ret void
+}
+
+define internal void @needarg(i32 %TEST) {
+ call i32 @needarg2( i32 %TEST ) ; <i32>:1 [#uses=0]
+ ret void
+}
+
+define internal i32 @needarg2(i32 %TEST) {
+ ret i32 %TEST
+}
+
+define internal void @needarg3(i32 %TEST3) {
+ call void @needarg( i32 %TEST3 )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/canon.ll b/src/LLVM/test/Transforms/DeadArgElim/canon.ll
new file mode 100644
index 0000000..11cd482
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/canon.ll
@@ -0,0 +1,24 @@
+; This test shows a few canonicalizations made by deadargelim
+; RUN: opt < %s -deadargelim -S > %t
+; This test should remove {} and replace it with void
+; RUN: cat %t | grep {define internal void @test}
+; This test shouls replace the {i32} return value with just i32
+; RUN: cat %t | grep {define internal i32 @test2}
+
+define internal {} @test() {
+ ret {} undef
+}
+
+define internal {i32} @test2() {
+ ret {i32} undef
+}
+
+define void @caller() {
+ call {} @test()
+ %X = call {i32} @test2()
+ %Y = extractvalue {i32} %X, 0
+ call void @user(i32 %Y, {i32} %X)
+ ret void
+}
+
+declare void @user(i32, {i32})
diff --git a/src/LLVM/test/Transforms/DeadArgElim/dead_vaargs.ll b/src/LLVM/test/Transforms/DeadArgElim/dead_vaargs.ll
new file mode 100644
index 0000000..c9e6f95
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/dead_vaargs.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -deadargelim -S | not grep 47
+; RUN: opt < %s -deadargelim -S | not grep 1.0
+
+define i32 @bar(i32 %A) {
+ %tmp4 = tail call i32 (i32, ...)* @foo( i32 %A, i32 %A, i32 %A, i32 %A, i64 47, double 1.000000e+00 ) ; <i32> [#uses=1]
+ ret i32 %tmp4
+}
+
+define internal i32 @foo(i32 %X, ...) {
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/deadexternal.ll b/src/LLVM/test/Transforms/DeadArgElim/deadexternal.ll
new file mode 100644
index 0000000..b2d63ec
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/deadexternal.ll
@@ -0,0 +1,52 @@
+; RUN: opt -deadargelim -S %s | FileCheck %s
+
+define void @test(i32) {
+ ret void
+}
+
+define void @foo() {
+ call void @test(i32 0)
+ ret void
+; CHECK: @foo
+; CHECK: i32 undef
+}
+
+define void @f(i32 %X) {
+entry:
+ tail call void @sideeffect() nounwind
+ ret void
+}
+
+declare void @sideeffect()
+
+define void @g(i32 %n) {
+entry:
+ %add = add nsw i32 %n, 1
+; CHECK: tail call void @f(i32 undef)
+ tail call void @f(i32 %add)
+ ret void
+}
+
+define void @h() {
+entry:
+ %i = alloca i32, align 4
+ volatile store i32 10, i32* %i, align 4
+; CHECK: %tmp = load volatile i32* %i, align 4
+; CHECK-next: call void @f(i32 undef)
+ %tmp = volatile load i32* %i, align 4
+ call void @f(i32 %tmp)
+ ret void
+}
+
+; Check that callers are not transformed for weak definitions.
+define weak i32 @weak_f(i32 %x) nounwind {
+entry:
+ ret i32 0
+}
+define void @weak_f_caller() nounwind {
+entry:
+; CHECK: call i32 @weak_f(i32 10)
+ %call = tail call i32 @weak_f(i32 10)
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/deadretval.ll b/src/LLVM/test/Transforms/DeadArgElim/deadretval.ll
new file mode 100644
index 0000000..8f804d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/deadretval.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -deadargelim -S | not grep DEAD
+
+; Dead arg only used by dead retval
+define internal i32 @test(i32 %DEADARG) {
+ ret i32 %DEADARG
+}
+
+define i32 @test2(i32 %A) {
+ %DEAD = call i32 @test( i32 %A ) ; <i32> [#uses=0]
+ ret i32 123
+}
+
+define i32 @test3() {
+ %X = call i32 @test2( i32 3232 ) ; <i32> [#uses=1]
+ %Y = add i32 %X, -123 ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/deadretval2.ll b/src/LLVM/test/Transforms/DeadArgElim/deadretval2.ll
new file mode 100644
index 0000000..6d2fd4b
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/deadretval2.ll
@@ -0,0 +1,59 @@
+; RUN: opt < %s -deadargelim -die -S > %t
+; RUN: cat %t | not grep DEAD
+; RUN: cat %t | grep LIVE | count 4
+
+@P = external global i32 ; <i32*> [#uses=1]
+
+; Dead arg only used by dead retval
+define internal i32 @test(i32 %DEADARG) {
+ ret i32 %DEADARG
+}
+
+define internal i32 @test2(i32 %DEADARG) {
+ %DEADRETVAL = call i32 @test( i32 %DEADARG ) ; <i32> [#uses=1]
+ ret i32 %DEADRETVAL
+}
+
+define void @test3(i32 %X) {
+ %DEADRETVAL = call i32 @test2( i32 %X ) ; <i32> [#uses=0]
+ ret void
+}
+
+define internal i32 @foo() {
+ %DEAD = load i32* @P ; <i32> [#uses=1]
+ ret i32 %DEAD
+}
+
+define internal i32 @id(i32 %X) {
+ ret i32 %X
+}
+
+define void @test4() {
+ %DEAD = call i32 @foo( ) ; <i32> [#uses=1]
+ %DEAD2 = call i32 @id( i32 %DEAD ) ; <i32> [#uses=0]
+ ret void
+}
+
+; These test if returning another functions return value properly marks that
+; other function's return value as live. We do this twice, with the functions in
+; different orders (ie, first the caller, than the callee and first the callee
+; and then the caller) since DAE processes functions one by one and handles
+; these cases slightly different.
+
+define internal i32 @test5() {
+ ret i32 123
+}
+
+define i32 @test6() {
+ %LIVE = call i32 @test5()
+ ret i32 %LIVE
+}
+
+define i32 @test7() {
+ %LIVE = call i32 @test8()
+ ret i32 %LIVE
+}
+
+define internal i32 @test8() {
+ ret i32 124
+}
diff --git a/src/LLVM/test/Transforms/DeadArgElim/dg.exp b/src/LLVM/test/Transforms/DeadArgElim/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/DeadArgElim/keepalive.ll b/src/LLVM/test/Transforms/DeadArgElim/keepalive.ll
new file mode 100644
index 0000000..4d6aae3
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/keepalive.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -deadargelim -S > %t
+; RUN: grep {define internal zeroext i32 @test1() nounwind} %t
+; RUN: grep {define internal <{ i32, i32 }> @test2} %t
+
+%Ty = type <{ i32, i32 }>
+
+; Check if the pass doesn't modify anything that doesn't need changing. We feed
+; an unused argument to each function to lure it into changing _something_ about
+; the function and then changing too much.
+
+; This checks if the return value attributes are not removed
+define internal zeroext i32 @test1(i32 %DEADARG1) nounwind {
+ ret i32 1
+}
+
+; This checks if the struct doesn't get non-packed
+define internal <{ i32, i32 }> @test2(i32 %DEADARG1) {
+ ret <{ i32, i32 }> <{ i32 1, i32 2 }>
+}
+
+; We use this external function to make sure the return values don't become dead
+declare void @user(i32, <{ i32, i32 }>)
+
+define void @caller() {
+ %B = call i32 @test1(i32 1)
+ %C = call <{ i32, i32 }> @test2(i32 2)
+ call void @user(i32 %B, <{ i32, i32 }> %C)
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/DeadArgElim/multdeadretval.ll b/src/LLVM/test/Transforms/DeadArgElim/multdeadretval.ll
new file mode 100644
index 0000000..68d96ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadArgElim/multdeadretval.ll
@@ -0,0 +1,68 @@
+; This test sees if return values (and arguments) are properly removed when they
+; are unused. All unused values are typed i16, so we can easily check. We also
+; run instcombine to fold insert/extractvalue chains and we run dce to clean up
+; any remaining dead stuff.
+; RUN: opt < %s -deadargelim -instcombine -dce -S | not grep i16
+
+define internal {i16, i32} @test(i16 %DEADARG) {
+ %A = insertvalue {i16,i32} undef, i16 1, 0
+ %B = insertvalue {i16,i32} %A, i32 1001, 1
+ ret {i16,i32} %B
+}
+
+define internal {i32, i16} @test2() {
+ %DEAD = call i16 @test4()
+ %A = insertvalue {i32,i16} undef, i32 1, 0
+ %B = insertvalue {i32,i16} %A, i16 %DEAD, 1
+ ret {i32,i16} %B
+}
+
+; Dead argument, used to check if the second result of test2 is dead even when
+; it's used as a dead argument
+define internal i32 @test3(i16 %A) {
+ %ret = call {i16, i32} @test( i16 %A ) ; <i32> [#uses=0]
+ %DEAD = extractvalue {i16, i32} %ret, 0
+ %LIVE = extractvalue {i16, i32} %ret, 1
+ ret i32 %LIVE
+}
+
+define internal i16 @test4() {
+ ret i16 0
+}
+
+; Multiple return values, multiple live return values
+define internal {i32, i32, i16} @test5() {
+ %A = insertvalue {i32,i32,i16} undef, i32 1, 0
+ %B = insertvalue {i32,i32,i16} %A, i32 2, 1
+ %C = insertvalue {i32,i32,i16} %B, i16 3, 2
+ ret {i32, i32, i16} %C
+}
+
+; Nested return values
+define internal {{i32}, {i16, i16}} @test6() {
+ %A = insertvalue {{i32}, {i16, i16}} undef, i32 1, 0, 0
+ %B = insertvalue {{i32}, {i16, i16}} %A, i16 2, 1, 0
+ %C = insertvalue {{i32}, {i16, i16}} %B, i16 3, 1, 1
+ ret {{i32}, {i16, i16}} %C
+}
+
+define i32 @main() {
+ %ret = call {i32, i16} @test2() ; <i32> [#uses=1]
+ %LIVE = extractvalue {i32, i16} %ret, 0
+ %DEAD = extractvalue {i32, i16} %ret, 1
+ %Y = add i32 %LIVE, -123 ; <i32> [#uses=1]
+ %LIVE2 = call i32 @test3(i16 %DEAD) ; <i32> [#uses=1]
+ %Z = add i32 %LIVE2, %Y ; <i32> [#uses=1]
+ %ret1 = call { i32, i32, i16 } @test5 ()
+ %LIVE3 = extractvalue { i32, i32, i16} %ret1, 0
+ %LIVE4 = extractvalue { i32, i32, i16} %ret1, 1
+ %DEAD2 = extractvalue { i32, i32, i16} %ret1, 2
+ %V = add i32 %LIVE3, %LIVE4
+ %W = add i32 %Z, %V
+ %ret2 = call { { i32 }, { i16, i16 } } @test6 ()
+ %LIVE5 = extractvalue { { i32 }, { i16, i16 } } %ret2, 0, 0
+ %DEAD3 = extractvalue { { i32 }, { i16, i16 } } %ret2, 1, 0
+ %DEAD4 = extractvalue { { i32 }, { i16, i16 } } %ret2, 1, 1
+ %Q = add i32 %W, %LIVE5
+ ret i32 %Q
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/2011-03-25-DSEMiscompile.ll b/src/LLVM/test/Transforms/DeadStoreElimination/2011-03-25-DSEMiscompile.ll
new file mode 100644
index 0000000..079eec4
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/2011-03-25-DSEMiscompile.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -basicaa -dse -S | FileCheck %s
+; PR9561
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.8"
+
+@A = external global [0 x i32]
+
+declare cc10 void @Func2(i32*, i32*, i32*, i32)
+
+define cc10 void @Func1(i32* noalias %Arg1, i32* noalias %Arg2, i32* %Arg3, i32 %Arg4) {
+entry:
+ store i32 add (i32 ptrtoint ([0 x i32]* @A to i32), i32 1), i32* %Arg2
+; CHECK: store i32 add (i32 ptrtoint ([0 x i32]* @A to i32), i32 1), i32* %Arg2
+ %ln2gz = getelementptr i32* %Arg1, i32 14
+ %ln2gA = bitcast i32* %ln2gz to double*
+ %ln2gB = load double* %ln2gA
+ %ln2gD = getelementptr i32* %Arg2, i32 -3
+ %ln2gE = bitcast i32* %ln2gD to double*
+ store double %ln2gB, double* %ln2gE
+; CHECK: store double %ln2gB, double* %ln2gE
+ tail call cc10 void @Func2(i32* %Arg1, i32* %Arg2, i32* %Arg3, i32 %Arg4) nounwind
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-EndOfFunction.ll b/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-EndOfFunction.ll
new file mode 100644
index 0000000..c5cc101
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-EndOfFunction.ll
@@ -0,0 +1,27 @@
+; RUN: opt -dse -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin"
+
+%"class.std::auto_ptr" = type { i32* }
+
+; CHECK: @_Z3foov
+define void @_Z3foov(%"class.std::auto_ptr"* noalias nocapture sret %agg.result) uwtable ssp {
+_ZNSt8auto_ptrIiED1Ev.exit:
+ %temp.lvalue = alloca %"class.std::auto_ptr", align 8
+ call void @_Z3barv(%"class.std::auto_ptr"* sret %temp.lvalue)
+ %_M_ptr.i.i = getelementptr inbounds %"class.std::auto_ptr"* %temp.lvalue, i64 0, i32 0
+ %tmp.i.i = load i32** %_M_ptr.i.i, align 8, !tbaa !0
+; CHECK-NOT: store i32* null
+ store i32* null, i32** %_M_ptr.i.i, align 8, !tbaa !0
+ %_M_ptr.i.i4 = getelementptr inbounds %"class.std::auto_ptr"* %agg.result, i64 0, i32 0
+ store i32* %tmp.i.i, i32** %_M_ptr.i.i4, align 8, !tbaa !0
+; CHECK: ret void
+ ret void
+}
+
+declare void @_Z3barv(%"class.std::auto_ptr"* sret)
+
+!0 = metadata !{metadata !"any pointer", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-MemCpy.ll b/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-MemCpy.ll
new file mode 100644
index 0000000..22b8786
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/2011-09-06-MemCpy.ll
@@ -0,0 +1,85 @@
+; RUN: opt -dse -S < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-f128:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.pair.162 = type { %struct.BasicBlock*, i32, [4 x i8] }
+%struct.BasicBlock = type { %struct.Value, %struct.ilist_node.24, %struct.iplist.22, %struct.Function* }
+%struct.Value = type { i32 (...)**, i8, i8, i16, %struct.Type*, %struct.Use*, %struct.StringMapEntry* }
+%struct.Type = type { %struct.LLVMContext*, i8, [3 x i8], i32, {}* }
+%struct.LLVMContext = type { %struct.LLVMContextImpl* }
+%struct.LLVMContextImpl = type opaque
+%struct.Use = type { %struct.Value*, %struct.Use*, %struct.PointerIntPair }
+%struct.PointerIntPair = type { i64 }
+%struct.StringMapEntry = type opaque
+%struct.ilist_node.24 = type { %struct.ilist_half_node.23, %struct.BasicBlock* }
+%struct.ilist_half_node.23 = type { %struct.BasicBlock* }
+%struct.iplist.22 = type { %struct.ilist_traits.21, %struct.Instruction* }
+%struct.ilist_traits.21 = type { %struct.ilist_half_node.25 }
+%struct.ilist_half_node.25 = type { %struct.Instruction* }
+%struct.Instruction = type { [52 x i8], %struct.ilist_node.26, %struct.BasicBlock*, %struct.DebugLoc }
+%struct.ilist_node.26 = type { %struct.ilist_half_node.25, %struct.Instruction* }
+%struct.DebugLoc = type { i32, i32 }
+%struct.Function = type { %struct.GlobalValue, %struct.ilist_node.14, %struct.iplist.4, %struct.iplist, %struct.ValueSymbolTable*, %struct.AttrListPtr }
+%struct.GlobalValue = type <{ [52 x i8], [4 x i8], %struct.Module*, i8, i16, [5 x i8], %struct.basic_string }>
+%struct.Module = type { %struct.LLVMContext*, %struct.iplist.20, %struct.iplist.16, %struct.iplist.12, %struct.vector.2, %struct.ilist, %struct.basic_string, %struct.ValueSymbolTable*, %struct.OwningPtr, %struct.basic_string, %struct.basic_string, %struct.basic_string, i8* }
+%struct.iplist.20 = type { %struct.ilist_traits.19, %struct.GlobalVariable* }
+%struct.ilist_traits.19 = type { %struct.ilist_node.18 }
+%struct.ilist_node.18 = type { %struct.ilist_half_node.17, %struct.GlobalVariable* }
+%struct.ilist_half_node.17 = type { %struct.GlobalVariable* }
+%struct.GlobalVariable = type { %struct.GlobalValue, %struct.ilist_node.18, i8, [7 x i8] }
+%struct.iplist.16 = type { %struct.ilist_traits.15, %struct.Function* }
+%struct.ilist_traits.15 = type { %struct.ilist_node.14 }
+%struct.ilist_node.14 = type { %struct.ilist_half_node.13, %struct.Function* }
+%struct.ilist_half_node.13 = type { %struct.Function* }
+%struct.iplist.12 = type { %struct.ilist_traits.11, %struct.GlobalAlias* }
+%struct.ilist_traits.11 = type { %struct.ilist_node.10 }
+%struct.ilist_node.10 = type { %struct.ilist_half_node.9, %struct.GlobalAlias* }
+%struct.ilist_half_node.9 = type { %struct.GlobalAlias* }
+%struct.GlobalAlias = type { %struct.GlobalValue, %struct.ilist_node.10 }
+%struct.vector.2 = type { %struct._Vector_base.1 }
+%struct._Vector_base.1 = type { %struct._Vector_impl.0 }
+%struct._Vector_impl.0 = type { %struct.basic_string*, %struct.basic_string*, %struct.basic_string* }
+%struct.basic_string = type { %struct._Alloc_hider }
+%struct._Alloc_hider = type { i8* }
+%struct.ilist = type { %struct.iplist.8 }
+%struct.iplist.8 = type { %struct.ilist_traits.7, %struct.NamedMDNode* }
+%struct.ilist_traits.7 = type { %struct.ilist_node.6 }
+%struct.ilist_node.6 = type { %struct.ilist_half_node.5, %struct.NamedMDNode* }
+%struct.ilist_half_node.5 = type { %struct.NamedMDNode* }
+%struct.NamedMDNode = type { %struct.ilist_node.6, %struct.basic_string, %struct.Module*, i8* }
+%struct.ValueSymbolTable = type opaque
+%struct.OwningPtr = type { %struct.GVMaterializer* }
+%struct.GVMaterializer = type opaque
+%struct.iplist.4 = type { %struct.ilist_traits.3, %struct.BasicBlock* }
+%struct.ilist_traits.3 = type { %struct.ilist_half_node.23 }
+%struct.iplist = type { %struct.ilist_traits, %struct.Argument* }
+%struct.ilist_traits = type { %struct.ilist_half_node }
+%struct.ilist_half_node = type { %struct.Argument* }
+%struct.Argument = type { %struct.Value, %struct.ilist_node, %struct.Function* }
+%struct.ilist_node = type { %struct.ilist_half_node, %struct.Argument* }
+%struct.AttrListPtr = type { %struct.AttributeListImpl* }
+%struct.AttributeListImpl = type opaque
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+; CHECK: _ZSt9iter_swapIPSt4pairIPN4llvm10BasicBlockEjES5_EvT_T0_
+; CHECK: store
+; CHECK: ret void
+define void @_ZSt9iter_swapIPSt4pairIPN4llvm10BasicBlockEjES5_EvT_T0_(%struct.pair.162* %__a, %struct.pair.162* %__b) nounwind uwtable inlinehint {
+entry:
+ %memtmp = alloca %struct.pair.162, align 8
+ %0 = getelementptr inbounds %struct.pair.162* %memtmp, i64 0, i32 0
+ %1 = getelementptr inbounds %struct.pair.162* %__a, i64 0, i32 0
+ %2 = load %struct.BasicBlock** %1, align 8
+ store %struct.BasicBlock* %2, %struct.BasicBlock** %0, align 8
+ %3 = getelementptr inbounds %struct.pair.162* %memtmp, i64 0, i32 1
+ %4 = getelementptr inbounds %struct.pair.162* %__a, i64 0, i32 1
+ %5 = load i32* %4, align 4
+ store i32 %5, i32* %3, align 8
+ %6 = bitcast %struct.pair.162* %__a to i8*
+ %7 = bitcast %struct.pair.162* %__b to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %6, i8* %7, i64 12, i32 1, i1 false)
+ %8 = bitcast %struct.pair.162* %memtmp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %7, i8* %8, i64 12, i32 1, i1 false)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/PartialStore.ll b/src/LLVM/test/Transforms/DeadStoreElimination/PartialStore.ll
new file mode 100644
index 0000000..314ea58
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/PartialStore.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -basicaa -dse -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+; Ensure that the dead store is deleted in this case. It is wholely
+; overwritten by the second store.
+define void @test1(i32 *%V) {
+ %V2 = bitcast i32* %V to i8* ; <i8*> [#uses=1]
+ store i8 0, i8* %V2
+ store i32 1234567, i32* %V
+ ret void
+; CHECK: @test1
+; CHECK-NEXT: store i32 1234567
+}
+
+; Note that we could do better by merging the two stores into one.
+define void @test2(i32* %P) {
+; CHECK: @test2
+ store i32 0, i32* %P
+; CHECK: store i32
+ %Q = bitcast i32* %P to i16*
+ store i16 1, i16* %Q
+; CHECK: store i16
+ ret void
+}
+
+
+define i32 @test3(double %__x) {
+; CHECK: @test3
+; CHECK: store double
+ %__u = alloca { [3 x i32] }
+ %tmp.1 = bitcast { [3 x i32] }* %__u to double*
+ store double %__x, double* %tmp.1
+ %tmp.4 = getelementptr { [3 x i32] }* %__u, i32 0, i32 0, i32 1
+ %tmp.5 = load i32* %tmp.4
+ %tmp.6 = icmp slt i32 %tmp.5, 0
+ %tmp.7 = zext i1 %tmp.6 to i32
+ ret i32 %tmp.7
+}
+
+; PR6043
+define void @test4(i8* %P) {
+; CHECK: @test4
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: store double
+
+ store i8 19, i8* %P ;; dead
+ %A = getelementptr i8* %P, i32 3
+
+ store i8 42, i8* %A ;; dead
+
+ %Q = bitcast i8* %P to double*
+ store double 0.0, double* %Q
+ ret void
+}
+
+; PR8657
+declare void @test5a(i32*)
+define void @test5(i32 %i) nounwind ssp {
+ %A = alloca i32
+ %B = bitcast i32* %A to i8*
+ %C = getelementptr i8* %B, i32 %i
+ store i8 10, i8* %C ;; Dead store to variable index.
+ store i32 20, i32* %A
+
+ call void @test5a(i32* %A)
+ ret void
+; CHECK: @test5(
+; CHECK-NEXT: alloca
+; CHECK-NEXT: store i32 20
+; CHECK-NEXT: call void @test5a
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/atomic.ll b/src/LLVM/test/Transforms/DeadStoreElimination/atomic.ll
new file mode 100644
index 0000000..2e84298
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/atomic.ll
@@ -0,0 +1,107 @@
+; RUN: opt -basicaa -dse -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+; Sanity tests for atomic stores.
+; Note that it turns out essentially every transformation DSE does is legal on
+; atomic ops, just some transformations are not allowed across them.
+
+@x = common global i32 0, align 4
+@y = common global i32 0, align 4
+
+declare void @randomop(i32*)
+
+; DSE across unordered store (allowed)
+define void @test1() nounwind uwtable ssp {
+; CHECK: test1
+; CHECK-NOT: store i32 0
+; CHECK: store i32 1
+entry:
+ store i32 0, i32* @x
+ store atomic i32 0, i32* @y unordered, align 4
+ store i32 1, i32* @x
+ ret void
+}
+
+; DSE across seq_cst load (allowed in theory; not implemented ATM)
+define i32 @test2() nounwind uwtable ssp {
+; CHECK: test2
+; CHECK: store i32 0
+; CHECK: store i32 1
+entry:
+ store i32 0, i32* @x
+ %x = load atomic i32* @y seq_cst, align 4
+ store i32 1, i32* @x
+ ret i32 %x
+}
+
+; DSE across seq_cst store (store before atomic store must not be removed)
+define void @test3() nounwind uwtable ssp {
+; CHECK: test3
+; CHECK: store i32
+; CHECK: store atomic i32 2
+entry:
+ store i32 0, i32* @x
+ store atomic i32 2, i32* @y seq_cst, align 4
+ store i32 1, i32* @x
+ ret void
+}
+
+; DSE remove unordered store (allowed)
+define void @test4() nounwind uwtable ssp {
+; CHECK: test4
+; CHECK-NOT: store atomic
+; CHECK: store i32 1
+entry:
+ store atomic i32 0, i32* @x unordered, align 4
+ store i32 1, i32* @x
+ ret void
+}
+
+; DSE unordered store overwriting non-atomic store (allowed)
+define void @test5() nounwind uwtable ssp {
+; CHECK: test5
+; CHECK: store atomic i32 1
+entry:
+ store i32 0, i32* @x
+ store atomic i32 1, i32* @x unordered, align 4
+ ret void
+}
+
+; DSE no-op unordered atomic store (allowed)
+define void @test6() nounwind uwtable ssp {
+; CHECK: test6
+; CHECK-NOT: store
+; CHECK: ret void
+entry:
+ %x = load atomic i32* @x unordered, align 4
+ store atomic i32 %x, i32* @x unordered, align 4
+ ret void
+}
+
+; DSE seq_cst store (be conservative; DSE doesn't have infrastructure
+; to reason about atomic operations).
+define void @test7() nounwind uwtable ssp {
+; CHECK: test7
+; CHECK: store atomic
+entry:
+ %a = alloca i32
+ store atomic i32 0, i32* %a seq_cst, align 4
+ ret void
+}
+
+; DSE and seq_cst load (be conservative; DSE doesn't have infrastructure
+; to reason about atomic operations).
+define i32 @test8() nounwind uwtable ssp {
+; CHECK: test8
+; CHECK: store
+; CHECK: load atomic
+entry:
+ %a = alloca i32
+ call void @randomop(i32* %a)
+ store i32 0, i32* %a, align 4
+ %x = load atomic i32* @x seq_cst, align 4
+ ret i32 %x
+}
+
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/const-pointers.ll b/src/LLVM/test/Transforms/DeadStoreElimination/const-pointers.ll
new file mode 100644
index 0000000..7d57804
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/const-pointers.ll
@@ -0,0 +1,39 @@
+; RUN: opt %s -basicaa -dse -S | FileCheck %s
+
+%t = type { i32 }
+
+@g = global i32 42
+
+define void @test1(%t* noalias %pp) {
+ %p = getelementptr inbounds %t* %pp, i32 0, i32 0
+
+ store i32 1, i32* %p; <-- This is dead
+ %x = load i32* inttoptr (i32 12345 to i32*)
+ store i32 %x, i32* %p
+ ret void
+; CHECK: define void @test1
+; CHECK: store
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+define void @test3() {
+ store i32 1, i32* @g; <-- This is dead.
+ store i32 42, i32* @g
+ ret void
+; CHECK: define void @test3
+; CHECK: store
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+define void @test4(i32* %p) {
+ store i32 1, i32* %p
+ %x = load i32* @g; <-- %p and @g could alias
+ store i32 %x, i32* %p
+ ret void
+; CHECK: define void @test4
+; CHECK: store
+; CHECK: store
+; CHECK: ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/crash.ll b/src/LLVM/test/Transforms/DeadStoreElimination/crash.ll
new file mode 100644
index 0000000..148695f
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/crash.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -basicaa -dse -S
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+@g80 = external global i8 ; <i8*> [#uses=3]
+
+declare signext i8 @foo(i8 signext, i8 signext) nounwind readnone ssp
+
+declare i32 @func68(i32) nounwind readonly ssp
+
+; PR4815
+define void @test1(i32 %int32p54) noreturn nounwind ssp {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %storemerge = phi i8 [ %2, %bb ], [ 1, %entry ] ; <i8> [#uses=1]
+ store i8 %storemerge, i8* @g80
+ %0 = tail call i32 @func68(i32 1) nounwind ssp ; <i32> [#uses=1]
+ %1 = trunc i32 %0 to i8 ; <i8> [#uses=1]
+ store i8 %1, i8* @g80, align 1
+ store i8 undef, i8* @g80, align 1
+ %2 = tail call signext i8 @foo(i8 signext undef, i8 signext 1) nounwind ; <i8> [#uses=1]
+ br label %bb
+}
+
+define fastcc i32 @test2() nounwind ssp {
+bb14: ; preds = %bb4
+ %0 = bitcast i8* undef to i8** ; <i8**> [#uses=1]
+ %1 = getelementptr inbounds i8** %0, i64 undef ; <i8**> [#uses=1]
+ %2 = bitcast i8** %1 to i16* ; <i16*> [#uses=2]
+ %3 = getelementptr inbounds i16* %2, i64 undef ; <i16*> [#uses=1]
+ %4 = bitcast i16* %3 to i8* ; <i8*> [#uses=1]
+ %5 = getelementptr inbounds i8* %4, i64 undef ; <i8*> [#uses=1]
+ %6 = getelementptr inbounds i16* %2, i64 undef ; <i16*> [#uses=1]
+ store i16 undef, i16* %6, align 2
+ %7 = getelementptr inbounds i8* %5, i64 undef ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %7, i8* undef, i64 undef, i32 1, i1 false)
+ unreachable
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+
+; rdar://7635088
+define i32 @test3() {
+entry:
+ ret i32 0
+
+dead:
+ %P2 = getelementptr i32 *%P2, i32 52
+ %Q2 = getelementptr i32 *%Q2, i32 52
+ store i32 4, i32* %P2
+ store i32 4, i32* %Q2
+ br label %dead
+}
+
+
+; PR3141
+%struct.ada__tags__dispatch_table = type { [1 x i32] }
+%struct.f393a00_1__object = type { %struct.ada__tags__dispatch_table*, i8 }
+%struct.f393a00_2__windmill = type { %struct.f393a00_1__object, i16 }
+
+define void @test4(%struct.f393a00_2__windmill* %a, %struct.f393a00_2__windmill* %b) {
+entry:
+ %t = alloca %struct.f393a00_2__windmill ; <%struct.f393a00_2__windmill*> [#uses=1]
+ %0 = getelementptr %struct.f393a00_2__windmill* %t, i32 0, i32 0, i32 0 ; <%struct.ada__tags__dispatch_table**> [#uses=1]
+ %1 = load %struct.ada__tags__dispatch_table** null, align 4 ; <%struct.ada__tags__dispatch_table*> [#uses=1]
+ %2 = load %struct.ada__tags__dispatch_table** %0, align 8 ; <%struct.ada__tags__dispatch_table*> [#uses=1]
+ store %struct.ada__tags__dispatch_table* %2, %struct.ada__tags__dispatch_table** null, align 4
+ store %struct.ada__tags__dispatch_table* %1, %struct.ada__tags__dispatch_table** null, align 4
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/dg.exp b/src/LLVM/test/Transforms/DeadStoreElimination/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/free.ll b/src/LLVM/test/Transforms/DeadStoreElimination/free.ll
new file mode 100644
index 0000000..b8909cf
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/free.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -basicaa -dse -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+; CHECK: @test
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: @free
+; CHECK-NEXT: ret void
+define void @test(i32* %Q, i32* %P) {
+ %DEAD = load i32* %Q ; <i32> [#uses=1]
+ store i32 %DEAD, i32* %P
+ %1 = bitcast i32* %P to i8*
+ tail call void @free(i8* %1)
+ ret void
+}
+
+; CHECK: @test2
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: @free
+; CHECK-NEXT: ret void
+define void @test2({i32, i32}* %P) {
+ %Q = getelementptr {i32, i32} *%P, i32 0, i32 1
+ store i32 4, i32* %Q
+ %1 = bitcast {i32, i32}* %P to i8*
+ tail call void @free(i8* %1)
+ ret void
+}
+
+; CHECK: @test4
+; CHECK-NOT: store
+; CHECK: ret void
+define void @test4() {
+ %m = call i8* @malloc(i64 24)
+ store i8 0, i8* %m
+ %m1 = getelementptr i8* %m, i64 1
+ store i8 1, i8* %m1
+ call void @free(i8* %m)
+ ret void
+}
+
+declare void @free(i8*)
+declare i8* @malloc(i64)
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/lifetime.ll b/src/LLVM/test/Transforms/DeadStoreElimination/lifetime.ll
new file mode 100644
index 0000000..6785653
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/lifetime.ll
@@ -0,0 +1,37 @@
+; RUN: opt -S -basicaa -dse < %s | FileCheck %s
+
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
+declare void @llvm.memset.p0i8.i8(i8* nocapture, i8, i8, i32, i1) nounwind
+
+define void @test1() {
+; CHECK: @test1
+ %A = alloca i8
+
+ store i8 0, i8* %A ;; Written to by memset
+ call void @llvm.lifetime.end(i64 1, i8* %A)
+; CHECK: lifetime.end
+
+ call void @llvm.memset.p0i8.i8(i8* %A, i8 0, i8 -1, i32 0, i1 false)
+; CHECK-NOT: memset
+
+ ret void
+; CHECK: ret void
+}
+
+define void @test2(i32* %P) {
+; CHECK: test2
+ %Q = getelementptr i32* %P, i32 1
+ %R = bitcast i32* %Q to i8*
+ call void @llvm.lifetime.start(i64 4, i8* %R)
+; CHECK: lifetime.start
+ store i32 0, i32* %Q ;; This store is dead.
+; CHECK-NOT: store
+ call void @llvm.lifetime.end(i64 4, i8* %R)
+; CHECK: lifetime.end
+ ret void
+}
+
+
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/memintrinsics.ll b/src/LLVM/test/Transforms/DeadStoreElimination/memintrinsics.ll
new file mode 100644
index 0000000..d5c5365
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/memintrinsics.ll
@@ -0,0 +1,47 @@
+; RUN: opt -S -dse < %s | FileCheck %s
+
+declare void @llvm.memcpy.p0i8.p0i8.i8(i8* nocapture, i8* nocapture, i8, i32, i1) nounwind
+declare void @llvm.memmove.p0i8.p0i8.i8(i8* nocapture, i8* nocapture, i8, i32, i1) nounwind
+declare void @llvm.memset.p0i8.i8(i8* nocapture, i8, i8, i32, i1) nounwind
+
+define void @test1() {
+; CHECK: @test1
+ %A = alloca i8
+ %B = alloca i8
+
+ store i8 0, i8* %A ;; Written to by memcpy
+; CHECK-NOT: store
+
+ call void @llvm.memcpy.p0i8.p0i8.i8(i8* %A, i8* %B, i8 -1, i32 0, i1 false)
+
+ ret void
+; CHECK: ret void
+}
+
+define void @test2() {
+; CHECK: @test2
+ %A = alloca i8
+ %B = alloca i8
+
+ store i8 0, i8* %A ;; Written to by memmove
+; CHECK-NOT: store
+
+ call void @llvm.memmove.p0i8.p0i8.i8(i8* %A, i8* %B, i8 -1, i32 0, i1 false)
+
+ ret void
+; CHECK: ret void
+}
+
+define void @test3() {
+; CHECK: @test3
+ %A = alloca i8
+ %B = alloca i8
+
+ store i8 0, i8* %A ;; Written to by memset
+; CHECK-NOT: store
+
+ call void @llvm.memset.p0i8.i8(i8* %A, i8 0, i8 -1, i32 0, i1 false)
+
+ ret void
+; CHECK: ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/no-targetdata.ll b/src/LLVM/test/Transforms/DeadStoreElimination/no-targetdata.ll
new file mode 100644
index 0000000..6c7f940
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/no-targetdata.ll
@@ -0,0 +1,15 @@
+; RUN: opt %s -basicaa -dse -S | FileCheck %s
+
+declare void @test1f()
+
+define void @test1(i32* noalias %p) {
+ store i32 1, i32* %p
+ call void @test1f()
+ store i32 2, i32 *%p
+ ret void
+; CHECK: define void @test1
+; CHECK-NOT: store
+; CHECK-NEXT: call void
+; CHECK-NEXT: store i32 2
+; CHECK-NEXT: ret void
+}
diff --git a/src/LLVM/test/Transforms/DeadStoreElimination/simple.ll b/src/LLVM/test/Transforms/DeadStoreElimination/simple.ll
new file mode 100644
index 0000000..f22cf0c
--- /dev/null
+++ b/src/LLVM/test/Transforms/DeadStoreElimination/simple.ll
@@ -0,0 +1,253 @@
+; RUN: opt < %s -basicaa -dse -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare i8* @llvm.init.trampoline(i8*, i8*, i8*)
+
+define void @test1(i32* %Q, i32* %P) {
+ %DEAD = load i32* %Q
+ store i32 %DEAD, i32* %P
+ store i32 0, i32* %P
+ ret void
+; CHECK: @test1
+; CHECK-NEXT: store i32 0, i32* %P
+; CHECK-NEXT: ret void
+}
+
+; PR8576 - Should delete store of 10 even though p/q are may aliases.
+define void @test2(i32 *%p, i32 *%q) {
+ store i32 10, i32* %p, align 4
+ store i32 20, i32* %q, align 4
+ store i32 30, i32* %p, align 4
+ ret void
+; CHECK: @test2
+; CHECK-NEXT: store i32 20
+}
+
+
+; PR8677
+@g = global i32 1
+
+define i32 @test3(i32* %g_addr) nounwind {
+; CHECK: @test3
+; CHECK: load i32* %g_addr
+ %g_value = load i32* %g_addr, align 4
+ store i32 -1, i32* @g, align 4
+ store i32 %g_value, i32* %g_addr, align 4
+ %tmp3 = load i32* @g, align 4
+ ret i32 %tmp3
+}
+
+
+define void @test4(i32* %Q) {
+ %a = load i32* %Q
+ store volatile i32 %a, i32* %Q
+ ret void
+; CHECK: @test4
+; CHECK-NEXT: load i32
+; CHECK-NEXT: store volatile
+; CHECK-NEXT: ret void
+}
+
+define void @test5(i32* %Q) {
+ %a = load volatile i32* %Q
+ store i32 %a, i32* %Q
+ ret void
+; CHECK: @test5
+; CHECK-NEXT: load volatile
+; CHECK-NEXT: ret void
+}
+
+; Should delete store of 10 even though memset is a may-store to P (P and Q may
+; alias).
+define void @test6(i32 *%p, i8 *%q) {
+ store i32 10, i32* %p, align 4 ;; dead.
+ call void @llvm.memset.p0i8.i64(i8* %q, i8 42, i64 900, i32 1, i1 false)
+ store i32 30, i32* %p, align 4
+ ret void
+; CHECK: @test6
+; CHECK-NEXT: call void @llvm.memset
+}
+
+; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
+; alias).
+define void @test7(i32 *%p, i8 *%q, i8* noalias %r) {
+ store i32 10, i32* %p, align 4 ;; dead.
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %q, i8* %r, i64 900, i32 1, i1 false)
+ store i32 30, i32* %p, align 4
+ ret void
+; CHECK: @test7
+; CHECK-NEXT: call void @llvm.memcpy
+}
+
+; Do not delete stores that are only partially killed.
+define i32 @test8() {
+ %V = alloca i32
+ store i32 1234567, i32* %V
+ %V2 = bitcast i32* %V to i8*
+ store i8 0, i8* %V2
+ %X = load i32* %V
+ ret i32 %X
+
+; CHECK: @test8
+; CHECK: store i32 1234567
+}
+
+
+; Test for byval handling.
+%struct.x = type { i32, i32, i32, i32 }
+define void @test9(%struct.x* byval %a) nounwind {
+ %tmp2 = getelementptr %struct.x* %a, i32 0, i32 0
+ store i32 1, i32* %tmp2, align 4
+ ret void
+; CHECK: @test9
+; CHECK-NEXT: ret void
+}
+
+; va_arg has fuzzy dependence, the store shouldn't be zapped.
+define double @test10(i8* %X) {
+ %X_addr = alloca i8*
+ store i8* %X, i8** %X_addr
+ %tmp.0 = va_arg i8** %X_addr, double
+ ret double %tmp.0
+; CHECK: @test10
+; CHECK: store
+}
+
+
+; DSE should delete the dead trampoline.
+declare void @test11f()
+define void @test11() {
+; CHECK: @test11
+ %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
+; CHECK-NOT: alloca
+ %cast = getelementptr [10 x i8]* %storage, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tramp = call i8* @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; <i8*> [#uses=1]
+; CHECK-NOT: trampoline
+ ret void
+; CHECK: ret void
+}
+
+
+; PR2599 - load -> store to same address.
+define void @test12({ i32, i32 }* %x) nounwind {
+ %tmp4 = getelementptr { i32, i32 }* %x, i32 0, i32 0
+ %tmp5 = load i32* %tmp4, align 4
+ %tmp7 = getelementptr { i32, i32 }* %x, i32 0, i32 1
+ %tmp8 = load i32* %tmp7, align 4
+ %tmp17 = sub i32 0, %tmp8
+ store i32 %tmp5, i32* %tmp4, align 4
+ store i32 %tmp17, i32* %tmp7, align 4
+ ret void
+; CHECK: @test12
+; CHECK-NOT: tmp5
+; CHECK: ret void
+}
+
+
+; %P doesn't escape, the DEAD instructions should be removed.
+declare void @test13f()
+define i32* @test13() {
+ %p = tail call i8* @malloc(i32 4)
+ %P = bitcast i8* %p to i32*
+ %DEAD = load i32* %P
+ %DEAD2 = add i32 %DEAD, 1
+ store i32 %DEAD2, i32* %P
+ call void @test13f( )
+ store i32 0, i32* %P
+ ret i32* %P
+; CHECK: @test13()
+; CHECK-NEXT: malloc
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: call void
+}
+
+declare noalias i8* @malloc(i32)
+
+
+
+define void @test14(i32* %Q) {
+ %P = alloca i32
+ %DEAD = load i32* %Q
+ store i32 %DEAD, i32* %P
+ ret void
+
+; CHECK: @test14
+; CHECK-NEXT: ret void
+}
+
+
+; PR8701
+
+;; Fully dead overwrite of memcpy.
+define void @test15(i8* %P, i8* %Q) nounwind ssp {
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test15
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret
+}
+
+;; Full overwrite of smaller memcpy.
+define void @test16(i8* %P, i8* %Q) nounwind ssp {
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 8, i32 1, i1 false)
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test16
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret
+}
+
+;; Overwrite of memset by memcpy.
+define void @test17(i8* %P, i8* noalias %Q) nounwind ssp {
+ tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i32 1, i1 false)
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test17
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret
+}
+
+; Should not delete the volatile memset.
+define void @test17v(i8* %P, i8* %Q) nounwind ssp {
+ tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i32 1, i1 true)
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test17v
+; CHECK-NEXT: call void @llvm.memset
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret
+}
+
+; PR8728
+; Do not delete instruction where possible situation is:
+; A = B
+; A = A
+define void @test18(i8* %P, i8* %Q, i8* %R) nounwind ssp {
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test18
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret
+}
+
+
+; The store here is not dead because the byval call reads it.
+declare void @test19f({i32}* byval align 4 %P)
+
+define void @test19({i32} * nocapture byval align 4 %arg5) nounwind ssp {
+bb:
+ %tmp7 = getelementptr inbounds {i32}* %arg5, i32 0, i32 0
+ store i32 912, i32* %tmp7
+ call void @test19f({i32}* byval align 4 %arg5)
+ ret void
+
+; CHECK: @test19(
+; CHECK: store i32 912
+; CHECK: call void @test19f
+}
+
diff --git a/src/LLVM/test/Transforms/EarlyCSE/basic.ll b/src/LLVM/test/Transforms/EarlyCSE/basic.ll
new file mode 100644
index 0000000..57b1697
--- /dev/null
+++ b/src/LLVM/test/Transforms/EarlyCSE/basic.ll
@@ -0,0 +1,121 @@
+; RUN: opt < %s -S -early-cse | FileCheck %s
+
+
+; CHECK: @test1
+define void @test1(i8 %V, i32 *%P) {
+ %A = bitcast i64 42 to double ;; dead
+ %B = add i32 4, 19 ;; constant folds
+ store i32 %B, i32* %P
+ ; CHECK-NEXT: store i32 23, i32* %P
+
+ %C = zext i8 %V to i32
+ %D = zext i8 %V to i32 ;; CSE
+ volatile store i32 %C, i32* %P
+ volatile store i32 %D, i32* %P
+ ; CHECK-NEXT: %C = zext i8 %V to i32
+ ; CHECK-NEXT: store volatile i32 %C
+ ; CHECK-NEXT: store volatile i32 %C
+
+ %E = add i32 %C, %C
+ %F = add i32 %C, %C
+ volatile store i32 %E, i32* %P
+ volatile store i32 %F, i32* %P
+ ; CHECK-NEXT: %E = add i32 %C, %C
+ ; CHECK-NEXT: store volatile i32 %E
+ ; CHECK-NEXT: store volatile i32 %E
+
+ %G = add nuw i32 %C, %C ;; not a CSE with E
+ volatile store i32 %G, i32* %P
+ ; CHECK-NEXT: %G = add nuw i32 %C, %C
+ ; CHECK-NEXT: store volatile i32 %G
+ ret void
+}
+
+
+;; Simple load value numbering.
+; CHECK: @test2
+define i32 @test2(i32 *%P) {
+ %V1 = load i32* %P
+ %V2 = load i32* %P
+ %Diff = sub i32 %V1, %V2
+ ret i32 %Diff
+ ; CHECK: ret i32 0
+}
+
+;; Cross block load value numbering.
+; CHECK: @test3
+define i32 @test3(i32 *%P, i1 %Cond) {
+ %V1 = load i32* %P
+ br i1 %Cond, label %T, label %F
+T:
+ store i32 4, i32* %P
+ ret i32 42
+F:
+ %V2 = load i32* %P
+ %Diff = sub i32 %V1, %V2
+ ret i32 %Diff
+ ; CHECK: F:
+ ; CHECK: ret i32 0
+}
+
+;; Cross block load value numbering stops when stores happen.
+; CHECK: @test4
+define i32 @test4(i32 *%P, i1 %Cond) {
+ %V1 = load i32* %P
+ br i1 %Cond, label %T, label %F
+T:
+ ret i32 42
+F:
+ ; Clobbers V1
+ store i32 42, i32* %P
+
+ %V2 = load i32* %P
+ %Diff = sub i32 %V1, %V2
+ ret i32 %Diff
+ ; CHECK: F:
+ ; CHECK: ret i32 %Diff
+}
+
+declare i32 @func(i32 *%P) readonly
+
+;; Simple call CSE'ing.
+; CHECK: @test5
+define i32 @test5(i32 *%P) {
+ %V1 = call i32 @func(i32* %P)
+ %V2 = call i32 @func(i32* %P)
+ %Diff = sub i32 %V1, %V2
+ ret i32 %Diff
+ ; CHECK: ret i32 0
+}
+
+;; Trivial Store->load forwarding
+; CHECK: @test6
+define i32 @test6(i32 *%P) {
+ store i32 42, i32* %P
+ %V1 = load i32* %P
+ ret i32 %V1
+ ; CHECK: ret i32 42
+}
+
+;; Trivial dead store elimination.
+; CHECK: @test7
+define void @test7(i32 *%P) {
+ store i32 42, i32* %P
+ store i32 45, i32* %P
+ ret void
+ ; CHECK-NEXT: store i32 45
+ ; CHECK-NEXT: ret void
+}
+
+;; Readnone functions aren't invalidated by stores.
+; CHECK: @test8
+define i32 @test8(i32 *%P) {
+ %V1 = call i32 @func(i32* %P) readnone
+ store i32 4, i32* %P
+ %V2 = call i32 @func(i32* %P) readnone
+ %Diff = sub i32 %V1, %V2
+ ret i32 %Diff
+ ; CHECK: ret i32 0
+}
+
+
diff --git a/src/LLVM/test/Transforms/EarlyCSE/dg.exp b/src/LLVM/test/Transforms/EarlyCSE/dg.exp
new file mode 100644
index 0000000..de42dad
--- /dev/null
+++ b/src/LLVM/test/Transforms/EarlyCSE/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.ll]]
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll
new file mode 100644
index 0000000..b0aecfa
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -functionattrs -S | grep readnone
+
+define i32 @a() {
+ %tmp = call i32 @b( ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+define i32 @b() {
+ %tmp = call i32 @a( ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll
new file mode 100644
index 0000000..946453f
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -basicaa -functionattrs -S | grep readnone | count 4
+@x = global i32 0
+
+declare i32 @e() readnone
+
+define i32 @f() {
+ %tmp = call i32 @e( ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+define i32 @g() readonly {
+ ret i32 0
+}
+
+define i32 @h() readnone {
+ %tmp = load i32* @x ; <i32> [#uses=1]
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll
new file mode 100644
index 0000000..22eca13
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -basicaa -functionattrs -S | grep readonly | count 2
+
+define i32 @f() {
+entry:
+ %tmp = call i32 @e( ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+declare i32 @e() readonly
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll
new file mode 100644
index 0000000..85df09e
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -functionattrs -S | not grep read
+; PR2792
+
+@g = global i32 0 ; <i32*> [#uses=1]
+
+define i32 @f() {
+ %t = volatile load i32* @g ; <i32> [#uses=1]
+ ret i32 %t
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll
new file mode 100644
index 0000000..9655da4
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -basicaa -functionattrs -S | grep readnone
+
+@s = external constant i8 ; <i8*> [#uses=1]
+
+define i8 @f() {
+ %tmp = load i8* @s ; <i8> [#uses=1]
+ ret i8 %tmp
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll b/src/LLVM/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll
new file mode 100644
index 0000000..e2bab19
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll
@@ -0,0 +1,105 @@
+; RUN: opt < %s -functionattrs -S | not grep {nocapture *%%q}
+; RUN: opt < %s -functionattrs -S | grep {nocapture *%%p} | count 6
+@g = global i32* null ; <i32**> [#uses=1]
+
+define i32* @c1(i32* %q) {
+ ret i32* %q
+}
+
+define void @c2(i32* %q) {
+ store i32* %q, i32** @g
+ ret void
+}
+
+define void @c3(i32* %q) {
+ call void @c2(i32* %q)
+ ret void
+}
+
+define i1 @c4(i32* %q, i32 %bitno) {
+ %tmp = ptrtoint i32* %q to i32
+ %tmp2 = lshr i32 %tmp, %bitno
+ %bit = trunc i32 %tmp2 to i1
+ br i1 %bit, label %l1, label %l0
+l0:
+ ret i1 0 ; escaping value not caught by def-use chaining.
+l1:
+ ret i1 1 ; escaping value not caught by def-use chaining.
+}
+
+@lookup_table = global [2 x i1] [ i1 0, i1 1 ]
+
+define i1 @c5(i32* %q, i32 %bitno) {
+ %tmp = ptrtoint i32* %q to i32
+ %tmp2 = lshr i32 %tmp, %bitno
+ %bit = and i32 %tmp2, 1
+ ; subtle escape mechanism follows
+ %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
+ %val = load i1* %lookup
+ ret i1 %val
+}
+
+declare void @throw_if_bit_set(i8*, i8) readonly
+define i1 @c6(i8* %q, i8 %bit) {
+ invoke void @throw_if_bit_set(i8* %q, i8 %bit)
+ to label %ret0 unwind label %ret1
+ret0:
+ ret i1 0
+ret1:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i1 1
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
+ %tmp = ptrtoint i32* %q to i32
+ %tmp2 = lshr i32 %tmp, %bitno
+ %bit = and i32 %tmp2, 1
+ %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
+ ret i1* %lookup
+}
+
+define i1 @c7(i32* %q, i32 %bitno) {
+ %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
+ %val = load i1* %ptr
+ ret i1 %val
+}
+
+
+define i32 @nc1(i32* %q, i32* %p, i1 %b) {
+e:
+ br label %l
+l:
+ %x = phi i32* [ %p, %e ]
+ %y = phi i32* [ %q, %e ]
+ %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
+ %tmp2 = select i1 %b, i32* %tmp, i32* %y
+ %val = load i32* %tmp2 ; <i32> [#uses=1]
+ store i32 0, i32* %tmp
+ store i32* %y, i32** @g
+ ret i32 %val
+}
+
+define void @nc2(i32* %p, i32* %q) {
+ %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
+ ret void
+}
+
+define void @nc3(void ()* %p) {
+ call void %p()
+ ret void
+}
+
+declare void @external(i8*) readonly nounwind
+define void @nc4(i8* %p) {
+ call void @external(i8* %p)
+ ret void
+}
+
+define void @nc5(void (i8*)* %f, i8* %p) {
+ call void %f(i8* %p) readonly nounwind
+ call void %f(i8* nocapture %p)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll b/src/LLVM/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll
new file mode 100644
index 0000000..7ef5f06
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -functionattrs -S | not grep {nocapture *%%q}
+; RUN: opt < %s -functionattrs -S | grep {nocapture *%%p}
+
+define i32* @a(i32** %p) {
+ %tmp = load i32** %p
+ ret i32* %tmp
+}
+
+define i32* @b(i32 *%q) {
+ %mem = alloca i32*
+ store i32* %q, i32** %mem
+ %tmp = call i32* @a(i32** %mem)
+ ret i32* %tmp
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/2010-10-30-volatile.ll b/src/LLVM/test/Transforms/FunctionAttrs/2010-10-30-volatile.ll
new file mode 100644
index 0000000..f21fabc
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/2010-10-30-volatile.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -functionattrs -S | FileCheck %s
+; PR8279
+
+@g = constant i32 1
+
+define void @foo() {
+; CHECK: void @foo() {
+ %tmp = volatile load i32* @g
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/atomic.ll b/src/LLVM/test/Transforms/FunctionAttrs/atomic.ll
new file mode 100644
index 0000000..7c2bff7
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/atomic.ll
@@ -0,0 +1,21 @@
+; RUN: opt -basicaa -functionattrs -S < %s | FileCheck %s
+
+; Atomic load/store to local doesn't affect whether a function is
+; readnone/readonly.
+define i32 @test1(i32 %x) uwtable ssp {
+; CHECK: define i32 @test1(i32 %x) uwtable readnone ssp {
+entry:
+ %x.addr = alloca i32, align 4
+ store atomic i32 %x, i32* %x.addr seq_cst, align 4
+ %r = load atomic i32* %x.addr seq_cst, align 4
+ ret i32 %r
+}
+
+; A function with an Acquire load is not readonly.
+define i32 @test2(i32* %x) uwtable ssp {
+; CHECK: define i32 @test2(i32* nocapture %x) uwtable ssp {
+entry:
+ %r = load atomic i32* %x seq_cst, align 4
+ ret i32 %r
+}
+
diff --git a/src/LLVM/test/Transforms/FunctionAttrs/dg.exp b/src/LLVM/test/Transforms/FunctionAttrs/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/FunctionAttrs/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-25-DominatedLoop.ll b/src/LLVM/test/Transforms/GVN/2007-07-25-DominatedLoop.ll
new file mode 100644
index 0000000..ad580ce
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-25-DominatedLoop.ll
@@ -0,0 +1,86 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+ %struct.PerlInterpreter = type { i8 }
+@PL_sv_count = external global i32 ; <i32*> [#uses=2]
+
+define void @perl_destruct(%struct.PerlInterpreter* %sv_interp) {
+entry:
+ br i1 false, label %cond_next25, label %cond_true16
+
+cond_true16: ; preds = %entry
+ ret void
+
+cond_next25: ; preds = %entry
+ br i1 false, label %cond_next33, label %cond_true32
+
+cond_true32: ; preds = %cond_next25
+ ret void
+
+cond_next33: ; preds = %cond_next25
+ br i1 false, label %cond_next61, label %cond_true.i46
+
+cond_true.i46: ; preds = %cond_next33
+ ret void
+
+cond_next61: ; preds = %cond_next33
+ br i1 false, label %cond_next69, label %cond_true66
+
+cond_true66: ; preds = %cond_next61
+ ret void
+
+cond_next69: ; preds = %cond_next61
+ br i1 false, label %Perl_safefree.exit52, label %cond_true.i50
+
+cond_true.i50: ; preds = %cond_next69
+ ret void
+
+Perl_safefree.exit52: ; preds = %cond_next69
+ br i1 false, label %cond_next80, label %cond_true77
+
+cond_true77: ; preds = %Perl_safefree.exit52
+ ret void
+
+cond_next80: ; preds = %Perl_safefree.exit52
+ br i1 false, label %Perl_safefree.exit56, label %cond_true.i54
+
+cond_true.i54: ; preds = %cond_next80
+ ret void
+
+Perl_safefree.exit56: ; preds = %cond_next80
+ br i1 false, label %Perl_safefree.exit60, label %cond_true.i58
+
+cond_true.i58: ; preds = %Perl_safefree.exit56
+ ret void
+
+Perl_safefree.exit60: ; preds = %Perl_safefree.exit56
+ br i1 false, label %Perl_safefree.exit64, label %cond_true.i62
+
+cond_true.i62: ; preds = %Perl_safefree.exit60
+ ret void
+
+Perl_safefree.exit64: ; preds = %Perl_safefree.exit60
+ br i1 false, label %Perl_safefree.exit68, label %cond_true.i66
+
+cond_true.i66: ; preds = %Perl_safefree.exit64
+ ret void
+
+Perl_safefree.exit68: ; preds = %Perl_safefree.exit64
+ br i1 false, label %cond_next150, label %cond_true23.i
+
+cond_true23.i: ; preds = %Perl_safefree.exit68
+ ret void
+
+cond_next150: ; preds = %Perl_safefree.exit68
+ %tmp16092 = load i32* @PL_sv_count, align 4 ; <i32> [#uses=0]
+ br label %cond_next165
+
+bb157: ; preds = %cond_next165
+ %tmp158 = load i32* @PL_sv_count, align 4 ; <i32> [#uses=0]
+ br label %cond_next165
+
+cond_next165: ; preds = %bb157, %cond_next150
+ br i1 false, label %bb171, label %bb157
+
+bb171: ; preds = %cond_next165
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-25-InfiniteLoop.ll b/src/LLVM/test/Transforms/GVN/2007-07-25-InfiniteLoop.ll
new file mode 100644
index 0000000..9983374
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-25-InfiniteLoop.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -basicaa -gvn -S | not grep {tmp10 =}
+
+ %struct.INT2 = type { i32, i32 }
+@blkshifts = external global %struct.INT2* ; <%struct.INT2**> [#uses=2]
+
+define i32 @xcompact() {
+entry:
+ store %struct.INT2* null, %struct.INT2** @blkshifts, align 4
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %tmp10 = load %struct.INT2** @blkshifts, align 4 ; <%struct.INT2*> [#uses=0]
+ br label %bb
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-25-Loop.ll b/src/LLVM/test/Transforms/GVN/2007-07-25-Loop.ll
new file mode 100644
index 0000000..6a9f58e
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-25-Loop.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+ %struct.s_segment_inf = type { float, i32, i16, i16, float, float, i32, float, float }
+
+define void @print_arch(i8* %arch_file, i32 %route_type, i64 %det_routing_arch.0.0, i64 %det_routing_arch.0.1, i64 %det_routing_arch.0.2, i64 %det_routing_arch.0.3, i64 %det_routing_arch.0.4, %struct.s_segment_inf* %segment_inf, i64 %timing_inf.0.0, i64 %timing_inf.0.1, i64 %timing_inf.0.2, i64 %timing_inf.0.3, i64 %timing_inf.0.4, i32 %timing_inf.1) {
+entry:
+ br i1 false, label %bb278, label %bb344
+
+bb278: ; preds = %bb278, %entry
+ br i1 false, label %bb278, label %bb344
+
+bb344: ; preds = %bb278, %entry
+ %tmp38758 = load i16* null, align 2 ; <i16> [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-25-NestedLoop.ll b/src/LLVM/test/Transforms/GVN/2007-07-25-NestedLoop.ll
new file mode 100644
index 0000000..c6d7750
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-25-NestedLoop.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+ %struct.TypHeader = type { i32, %struct.TypHeader**, [3 x i8], i8 }
+
+define %struct.TypHeader* @LtRec(%struct.TypHeader* %hdL, %struct.TypHeader* %hdR) {
+entry:
+ br i1 false, label %bb556.preheader, label %bb534.preheader
+
+bb534.preheader: ; preds = %entry
+ ret %struct.TypHeader* null
+
+bb556.preheader: ; preds = %entry
+ %tmp56119 = getelementptr %struct.TypHeader* %hdR, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp56220 = load i32* %tmp56119 ; <i32> [#uses=0]
+ br i1 false, label %bb.nph23, label %bb675.preheader
+
+bb.nph23: ; preds = %bb556.preheader
+ ret %struct.TypHeader* null
+
+bb656: ; preds = %bb675.outer, %bb656
+ %tmp678 = load i32* %tmp677 ; <i32> [#uses=0]
+ br i1 false, label %bb684, label %bb656
+
+bb684: ; preds = %bb675.outer, %bb656
+ br i1 false, label %bb924.preheader, label %bb675.outer
+
+bb675.outer: ; preds = %bb675.preheader, %bb684
+ %tmp67812 = load i32* %tmp67711 ; <i32> [#uses=0]
+ br i1 false, label %bb684, label %bb656
+
+bb675.preheader: ; preds = %bb556.preheader
+ %tmp67711 = getelementptr %struct.TypHeader* %hdR, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp677 = getelementptr %struct.TypHeader* %hdR, i32 0, i32 0 ; <i32*> [#uses=1]
+ br label %bb675.outer
+
+bb924.preheader: ; preds = %bb684
+ ret %struct.TypHeader* null
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-25-SinglePredecessor.ll b/src/LLVM/test/Transforms/GVN/2007-07-25-SinglePredecessor.ll
new file mode 100644
index 0000000..ecff657
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-25-SinglePredecessor.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+ %struct.ggBRDF = type { i32 (...)** }
+ %struct.ggBox3 = type { %struct.ggPoint3, %struct.ggPoint3 }
+ %struct.ggMaterialRecord = type { %struct.ggPoint2, %struct.ggBox3, %struct.ggBox3, %struct.ggSpectrum, %struct.ggSpectrum, %struct.ggSpectrum, %struct.ggBRDF*, i32, i32, i32, i32 }
+ %struct.ggONB3 = type { %struct.ggPoint3, %struct.ggPoint3, %struct.ggPoint3 }
+ %struct.ggPoint2 = type { [2 x double] }
+ %struct.ggPoint3 = type { [3 x double] }
+ %struct.ggSpectrum = type { [8 x float] }
+ %struct.mrViewingHitRecord = type { double, %struct.ggPoint3, %struct.ggONB3, %struct.ggPoint2, double, %struct.ggSpectrum, %struct.ggSpectrum, i32, i32, i32, i32 }
+ %struct.mrXEllipticalCylinder = type { %struct.ggBRDF, float, float, float, float, float, float }
+
+define i32 @_ZNK21mrZEllipticalCylinder10viewingHitERK6ggRay3dddR18mrViewingHitRecordR16ggMaterialRecord(%struct.mrXEllipticalCylinder* %this, %struct.ggBox3* %ray, double %unnamed_arg, double %tmin, double %tmax, %struct.mrViewingHitRecord* %VHR, %struct.ggMaterialRecord* %unnamed_arg2) {
+entry:
+ %tmp80.i = getelementptr %struct.mrViewingHitRecord* %VHR, i32 0, i32 1, i32 0, i32 0 ; <double*> [#uses=1]
+ store double 0.000000e+00, double* %tmp80.i
+ br i1 false, label %return, label %cond_next.i
+
+cond_next.i: ; preds = %entry
+ br i1 false, label %return, label %cond_true
+
+cond_true: ; preds = %cond_next.i
+ %tmp3.i8 = getelementptr %struct.mrViewingHitRecord* %VHR, i32 0, i32 1, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp46 = load double* %tmp3.i8 ; <double> [#uses=0]
+ ret i32 1
+
+return: ; preds = %cond_next.i, %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll b/src/LLVM/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
new file mode 100644
index 0000000..a1cc008
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+@last = external global [65 x i32*]
+
+define i32 @NextRootMove(i32 %wtm) {
+entry:
+ %A = alloca i32*
+ %tmp17618 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
+ store i32* %tmp17618, i32** %A
+; CHECK: entry:
+; CHECK-NEXT: alloca i32
+; CHECK-NEXT: %tmp17618 = load
+; CHECK-NOT: load
+; CHECK-NOT: phi
+ br label %cond_true116
+
+cond_true116:
+ br i1 false, label %cond_true128, label %cond_true145
+
+cond_true128:
+ %tmp17625 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
+ store i32* %tmp17625, i32** %A
+ br i1 false, label %bb98.backedge, label %return.loopexit
+
+bb98.backedge:
+ br label %cond_true116
+
+cond_true145:
+ %tmp17631 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
+ store i32* %tmp17631, i32** %A
+ br i1 false, label %bb98.backedge, label %return.loopexit
+
+return.loopexit:
+ br label %return
+
+return:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-26-NonRedundant.ll b/src/LLVM/test/Transforms/GVN/2007-07-26-NonRedundant.ll
new file mode 100644
index 0000000..7579e8a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-26-NonRedundant.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+@bsLive = external global i32 ; <i32*> [#uses=2]
+
+define i32 @bsR(i32 %n) {
+entry:
+ br i1 false, label %cond_next, label %bb19
+
+cond_next: ; preds = %entry
+ store i32 0, i32* @bsLive, align 4
+ br label %bb19
+
+bb19: ; preds = %cond_next, %entry
+ %tmp29 = load i32* @bsLive, align 4 ; <i32> [#uses=0]
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-26-PhiErasure.ll b/src/LLVM/test/Transforms/GVN/2007-07-26-PhiErasure.ll
new file mode 100644
index 0000000..d898ab8
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-26-PhiErasure.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -gvn -S | not grep phi
+
+ %struct..0anon = type { i32 }
+ %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+ %struct.__sFILEX = type opaque
+ %struct.__sbuf = type { i8*, i32 }
+ %struct.rtx_def = type { i16, i8, i8, [1 x %struct..0anon] }
+@n_spills = external global i32 ; <i32*> [#uses=2]
+
+define i32 @reload(%struct.rtx_def* %first, i32 %global, %struct.FILE* %dumpfile) {
+cond_next2835.1: ; preds = %cond_next2861
+ %tmp2922 = load i32* @n_spills, align 4 ; <i32> [#uses=0]
+ br label %bb2928
+
+bb2928: ; preds = %cond_next2835.1, %cond_next2943
+ br i1 false, label %cond_next2943, label %cond_true2935
+
+cond_true2935: ; preds = %bb2928
+ br label %cond_next2943
+
+cond_next2943: ; preds = %cond_true2935, %bb2928
+ br i1 false, label %bb2982.preheader, label %bb2928
+
+bb2982.preheader: ; preds = %cond_next2943
+ %tmp298316 = load i32* @n_spills, align 4 ; <i32> [#uses=0]
+ ret i32 %tmp298316
+
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-30-PredIDom.ll b/src/LLVM/test/Transforms/GVN/2007-07-30-PredIDom.ll
new file mode 100644
index 0000000..5cb6bb3
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-30-PredIDom.ll
@@ -0,0 +1,274 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+ %"struct.Block::$_16" = type { i32 }
+ %struct.Exp = type { %struct.Exp_*, i32, i32, i32, %struct.Exp*, %struct.Exp*, %"struct.Exp::$_10", %"struct.Block::$_16", %"struct.Exp::$_12" }
+ %"struct.Exp::$_10" = type { %struct.Exp* }
+ %"struct.Exp::$_12" = type { %struct.Exp** }
+ %struct.Exp_ = type { i32, i32, i32, i32, %struct.Id* }
+ %struct.Id = type { i8*, i32, i32, i32, %"struct.Id::$_13" }
+ %"struct.Id::$_13" = type { double }
+
+define i8* @_ZN3Exp8toStringEj(%struct.Exp* %this, i32 %nextpc) {
+entry:
+ switch i32 0, label %bb970 [
+ i32 1, label %bb
+ i32 2, label %bb39
+ i32 3, label %bb195
+ i32 4, label %bb270
+ i32 5, label %bb418
+ i32 6, label %bb633
+ i32 7, label %bb810
+ i32 8, label %bb882
+ i32 9, label %bb925
+ ]
+
+bb: ; preds = %entry
+ store i8* null, i8** null
+ br label %return
+
+bb39: ; preds = %entry
+ br i1 false, label %cond_true, label %cond_false132
+
+cond_true: ; preds = %bb39
+ br i1 false, label %cond_true73, label %cond_false
+
+cond_true73: ; preds = %cond_true
+ br i1 false, label %cond_true108, label %cond_next
+
+cond_true108: ; preds = %cond_true73
+ br label %cond_next
+
+cond_next: ; preds = %cond_true108, %cond_true73
+ br label %cond_next131
+
+cond_false: ; preds = %cond_true
+ br label %cond_next131
+
+cond_next131: ; preds = %cond_false, %cond_next
+ br label %cond_next141
+
+cond_false132: ; preds = %bb39
+ br label %cond_next141
+
+cond_next141: ; preds = %cond_false132, %cond_next131
+ br i1 false, label %cond_true169, label %cond_false175
+
+cond_true169: ; preds = %cond_next141
+ br label %cond_next181
+
+cond_false175: ; preds = %cond_next141
+ br label %cond_next181
+
+cond_next181: ; preds = %cond_false175, %cond_true169
+ br i1 false, label %cond_true189, label %cond_next191
+
+cond_true189: ; preds = %cond_next181
+ br label %cond_next191
+
+cond_next191: ; preds = %cond_true189, %cond_next181
+ store i8* null, i8** null
+ br label %return
+
+bb195: ; preds = %entry
+ br i1 false, label %cond_true248, label %cond_false250
+
+cond_true248: ; preds = %bb195
+ br label %cond_next252
+
+cond_false250: ; preds = %bb195
+ br label %cond_next252
+
+cond_next252: ; preds = %cond_false250, %cond_true248
+ br i1 false, label %cond_true265, label %cond_next267
+
+cond_true265: ; preds = %cond_next252
+ br label %cond_next267
+
+cond_next267: ; preds = %cond_true265, %cond_next252
+ store i8* null, i8** null
+ br label %return
+
+bb270: ; preds = %entry
+ br i1 false, label %cond_true338, label %cond_false340
+
+cond_true338: ; preds = %bb270
+ br label %cond_next342
+
+cond_false340: ; preds = %bb270
+ br label %cond_next342
+
+cond_next342: ; preds = %cond_false340, %cond_true338
+ br i1 false, label %cond_true362, label %cond_false364
+
+cond_true362: ; preds = %cond_next342
+ br label %cond_next366
+
+cond_false364: ; preds = %cond_next342
+ br label %cond_next366
+
+cond_next366: ; preds = %cond_false364, %cond_true362
+ br i1 false, label %cond_true393, label %cond_next395
+
+cond_true393: ; preds = %cond_next366
+ br label %cond_next395
+
+cond_next395: ; preds = %cond_true393, %cond_next366
+ br i1 false, label %cond_true406, label %cond_next408
+
+cond_true406: ; preds = %cond_next395
+ br label %cond_next408
+
+cond_next408: ; preds = %cond_true406, %cond_next395
+ br i1 false, label %cond_true413, label %cond_next415
+
+cond_true413: ; preds = %cond_next408
+ br label %cond_next415
+
+cond_next415: ; preds = %cond_true413, %cond_next408
+ store i8* null, i8** null
+ br label %return
+
+bb418: ; preds = %entry
+ br i1 false, label %cond_true512, label %cond_false514
+
+cond_true512: ; preds = %bb418
+ br label %cond_next516
+
+cond_false514: ; preds = %bb418
+ br label %cond_next516
+
+cond_next516: ; preds = %cond_false514, %cond_true512
+ br i1 false, label %cond_true536, label %cond_false538
+
+cond_true536: ; preds = %cond_next516
+ br label %cond_next540
+
+cond_false538: ; preds = %cond_next516
+ br label %cond_next540
+
+cond_next540: ; preds = %cond_false538, %cond_true536
+ br i1 false, label %cond_true560, label %cond_false562
+
+cond_true560: ; preds = %cond_next540
+ br label %cond_next564
+
+cond_false562: ; preds = %cond_next540
+ br label %cond_next564
+
+cond_next564: ; preds = %cond_false562, %cond_true560
+ br i1 false, label %cond_true597, label %cond_next599
+
+cond_true597: ; preds = %cond_next564
+ br label %cond_next599
+
+cond_next599: ; preds = %cond_true597, %cond_next564
+ br i1 false, label %cond_true614, label %cond_next616
+
+cond_true614: ; preds = %cond_next599
+ br label %cond_next616
+
+cond_next616: ; preds = %cond_true614, %cond_next599
+ br i1 false, label %cond_true621, label %cond_next623
+
+cond_true621: ; preds = %cond_next616
+ br label %cond_next623
+
+cond_next623: ; preds = %cond_true621, %cond_next616
+ br i1 false, label %cond_true628, label %cond_next630
+
+cond_true628: ; preds = %cond_next623
+ br label %cond_next630
+
+cond_next630: ; preds = %cond_true628, %cond_next623
+ store i8* null, i8** null
+ br label %return
+
+bb633: ; preds = %entry
+ br i1 false, label %cond_true667, label %cond_next669
+
+cond_true667: ; preds = %bb633
+ br label %cond_next669
+
+cond_next669: ; preds = %cond_true667, %bb633
+ br i1 false, label %cond_true678, label %cond_next791
+
+cond_true678: ; preds = %cond_next669
+ br label %bb735
+
+bb679: ; preds = %bb735
+ br i1 false, label %cond_true729, label %cond_next731
+
+cond_true729: ; preds = %bb679
+ br label %cond_next731
+
+cond_next731: ; preds = %cond_true729, %bb679
+ br label %bb735
+
+bb735: ; preds = %cond_next731, %cond_true678
+ br i1 false, label %bb679, label %bb743
+
+bb743: ; preds = %bb735
+ br i1 false, label %cond_true788, label %cond_next790
+
+cond_true788: ; preds = %bb743
+ br label %cond_next790
+
+cond_next790: ; preds = %cond_true788, %bb743
+ br label %cond_next791
+
+cond_next791: ; preds = %cond_next790, %cond_next669
+ br i1 false, label %cond_true805, label %cond_next807
+
+cond_true805: ; preds = %cond_next791
+ br label %cond_next807
+
+cond_next807: ; preds = %cond_true805, %cond_next791
+ store i8* null, i8** null
+ br label %return
+
+bb810: ; preds = %entry
+ br i1 false, label %cond_true870, label %cond_next872
+
+cond_true870: ; preds = %bb810
+ br label %cond_next872
+
+cond_next872: ; preds = %cond_true870, %bb810
+ br i1 false, label %cond_true877, label %cond_next879
+
+cond_true877: ; preds = %cond_next872
+ br label %cond_next879
+
+cond_next879: ; preds = %cond_true877, %cond_next872
+ store i8* null, i8** null
+ br label %return
+
+bb882: ; preds = %entry
+ br i1 false, label %cond_true920, label %cond_next922
+
+cond_true920: ; preds = %bb882
+ br label %cond_next922
+
+cond_next922: ; preds = %cond_true920, %bb882
+ store i8* null, i8** null
+ br label %return
+
+bb925: ; preds = %entry
+ br i1 false, label %cond_true965, label %cond_next967
+
+cond_true965: ; preds = %bb925
+ br label %cond_next967
+
+cond_next967: ; preds = %cond_true965, %bb925
+ store i8* null, i8** null
+ br label %return
+
+bb970: ; preds = %entry
+ unreachable
+ ; No predecessors!
+ store i8* null, i8** null
+ br label %return
+
+return: ; preds = %0, %cond_next967, %cond_next922, %cond_next879, %cond_next807, %cond_next630, %cond_next415, %cond_next267, %cond_next191, %bb
+ %retval980 = load i8** null ; <i8*> [#uses=1]
+ ret i8* %retval980
+}
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-31-NoDomInherit.ll b/src/LLVM/test/Transforms/GVN/2007-07-31-NoDomInherit.ll
new file mode 100644
index 0000000..f2c0012
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-31-NoDomInherit.ll
@@ -0,0 +1,313 @@
+; RUN: opt < %s -basicaa -gvn -S | grep {tmp47 = phi i32 }
+
+ %struct.anon = type { i32 (i32, i32, i32)*, i32, i32, [3 x i32], i8*, i8*, i8* }
+@debug = external constant i32 ; <i32*> [#uses=0]
+@counters = external constant i32 ; <i32*> [#uses=1]
+@trialx = external global [17 x i32] ; <[17 x i32]*> [#uses=1]
+@dummy1 = external global [7 x i32] ; <[7 x i32]*> [#uses=0]
+@dummy2 = external global [4 x i32] ; <[4 x i32]*> [#uses=0]
+@unacceptable = external global i32 ; <i32*> [#uses=0]
+@isa = external global [13 x %struct.anon] ; <[13 x %struct.anon]*> [#uses=3]
+@.str = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str1 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str2 = external constant [1 x i8] ; <[1 x i8]*> [#uses=0]
+@.str3 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str4 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str5 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str6 = external constant [2 x i8] ; <[2 x i8]*> [#uses=0]
+@.str7 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str8 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str9 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str10 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str11 = external constant [2 x i8] ; <[2 x i8]*> [#uses=0]
+@.str12 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str13 = external constant [2 x i8] ; <[2 x i8]*> [#uses=0]
+@.str14 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@.str15 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@.str16 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str17 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str18 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str19 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str20 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str21 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str22 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str23 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@.str24 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str25 = external constant [6 x i8] ; <[6 x i8]*> [#uses=0]
+@.str26 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@.str27 = external constant [6 x i8] ; <[6 x i8]*> [#uses=0]
+@r = external global [17 x i32] ; <[17 x i32]*> [#uses=0]
+@.str28 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str29 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@pgm = external global [5 x { i32, [3 x i32] }] ; <[5 x { i32, [3 x i32] }]*> [#uses=4]
+@.str30 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str31 = external constant [13 x i8] ; <[13 x i8]*> [#uses=0]
+@.str32 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str33 = external constant [4 x i8] ; <[4 x i8]*> [#uses=0]
+@.str34 = external constant [20 x i8] ; <[20 x i8]*> [#uses=0]
+@numi = external global i32 ; <i32*> [#uses=7]
+@.str35 = external constant [10 x i8] ; <[10 x i8]*> [#uses=0]
+@counter = external global [5 x i32] ; <[5 x i32]*> [#uses=2]
+@itrialx.2510 = external global i32 ; <i32*> [#uses=0]
+@.str36 = external constant [43 x i8] ; <[43 x i8]*> [#uses=0]
+@.str37 = external constant [42 x i8] ; <[42 x i8]*> [#uses=0]
+@corr_result = external global i32 ; <i32*> [#uses=0]
+@.str38 = external constant [3 x i8] ; <[3 x i8]*> [#uses=0]
+@.str39 = external constant [5 x i8] ; <[5 x i8]*> [#uses=0]
+@.str40 = external constant [47 x i8] ; <[47 x i8]*> [#uses=0]
+@correct_result = external global [17 x i32] ; <[17 x i32]*> [#uses=1]
+@.str41 = external constant [46 x i8] ; <[46 x i8]*> [#uses=0]
+@.str42 = external constant [32 x i8] ; <[32 x i8]*> [#uses=0]
+@.str43 = external constant [44 x i8] ; <[44 x i8]*> [#uses=1]
+@.str44 = external constant [21 x i8] ; <[21 x i8]*> [#uses=1]
+@.str45 = external constant [12 x i8] ; <[12 x i8]*> [#uses=1]
+@.str46 = external constant [5 x i8] ; <[5 x i8]*> [#uses=1]
+@.str47 = external constant [12 x i8] ; <[12 x i8]*> [#uses=1]
+
+declare i32 @neg(i32, i32, i32)
+
+declare i32 @Not(i32, i32, i32)
+
+declare i32 @pop(i32, i32, i32)
+
+declare i32 @nlz(i32, i32, i32)
+
+declare i32 @rev(i32, i32, i32)
+
+declare i32 @add(i32, i32, i32)
+
+declare i32 @sub(i32, i32, i32)
+
+declare i32 @mul(i32, i32, i32)
+
+declare i32 @divide(i32, i32, i32)
+
+declare i32 @divu(i32, i32, i32)
+
+declare i32 @And(i32, i32, i32)
+
+declare i32 @Or(i32, i32, i32)
+
+declare i32 @Xor(i32, i32, i32)
+
+declare i32 @rotl(i32, i32, i32)
+
+declare i32 @shl(i32, i32, i32)
+
+declare i32 @shr(i32, i32, i32)
+
+declare i32 @shrs(i32, i32, i32)
+
+declare i32 @cmpeq(i32, i32, i32)
+
+declare i32 @cmplt(i32, i32, i32)
+
+declare i32 @cmpltu(i32, i32, i32)
+
+declare i32 @seleq(i32, i32, i32)
+
+declare i32 @sellt(i32, i32, i32)
+
+declare i32 @selle(i32, i32, i32)
+
+declare void @print_expr(i32)
+
+declare i32 @printf(i8*, ...)
+
+declare i32 @putchar(i32)
+
+declare void @print_pgm()
+
+declare void @simulate_one_instruction(i32)
+
+declare i32 @check(i32)
+
+declare i32 @puts(i8*)
+
+declare void @fix_operands(i32)
+
+declare void @abort()
+
+declare i32 @increment()
+
+declare i32 @search()
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %argc_addr = alloca i32 ; <i32*> [#uses=1]
+ %argv_addr = alloca i8** ; <i8***> [#uses=1]
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %i = alloca i32, align 4 ; <i32*> [#uses=21]
+ %num_sol = alloca i32, align 4 ; <i32*> [#uses=4]
+ %total = alloca i32, align 4 ; <i32*> [#uses=4]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %argc, i32* %argc_addr
+ store i8** %argv, i8*** %argv_addr
+ store i32 0, i32* %num_sol
+ store i32 1, i32* @numi
+ br label %bb91
+
+bb: ; preds = %cond_next97
+ %tmp1 = load i32* @numi ; <i32> [#uses=1]
+ %tmp2 = getelementptr [44 x i8]* @.str43, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp3 = call i32 (i8*, ...)* @printf( i8* %tmp2, i32 %tmp1 ) ; <i32> [#uses=0]
+ store i32 0, i32* %i
+ br label %bb13
+
+bb4: ; preds = %bb13
+ %tmp5 = load i32* %i ; <i32> [#uses=1]
+ %tmp6 = load i32* %i ; <i32> [#uses=1]
+ %tmp7 = getelementptr [17 x i32]* @trialx, i32 0, i32 %tmp6 ; <i32*> [#uses=1]
+ %tmp8 = load i32* %tmp7 ; <i32> [#uses=1]
+ %tmp9 = call i32 @userfun( i32 %tmp8 ) ; <i32> [#uses=1]
+ %tmp10 = getelementptr [17 x i32]* @correct_result, i32 0, i32 %tmp5 ; <i32*> [#uses=1]
+ store i32 %tmp9, i32* %tmp10
+ %tmp11 = load i32* %i ; <i32> [#uses=1]
+ %tmp12 = add i32 %tmp11, 1 ; <i32> [#uses=1]
+ store i32 %tmp12, i32* %i
+ br label %bb13
+
+bb13: ; preds = %bb4, %bb
+ %tmp14 = load i32* %i ; <i32> [#uses=1]
+ %tmp15 = icmp sle i32 %tmp14, 16 ; <i1> [#uses=1]
+ %tmp1516 = zext i1 %tmp15 to i32 ; <i32> [#uses=1]
+ %toBool = icmp ne i32 %tmp1516, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb4, label %bb17
+
+bb17: ; preds = %bb13
+ store i32 0, i32* %i
+ br label %bb49
+
+bb18: ; preds = %bb49
+ %tmp19 = load i32* %i ; <i32> [#uses=1]
+ %tmp20 = getelementptr [5 x { i32, [3 x i32] }]* @pgm, i32 0, i32 %tmp19 ; <{ i32, [3 x i32] }*> [#uses=1]
+ %tmp21 = getelementptr { i32, [3 x i32] }* %tmp20, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp21
+ %tmp22 = load i32* %i ; <i32> [#uses=1]
+ %tmp23 = getelementptr [13 x %struct.anon]* @isa, i32 0, i32 0 ; <%struct.anon*> [#uses=1]
+ %tmp24 = getelementptr %struct.anon* %tmp23, i32 0, i32 3 ; <[3 x i32]*> [#uses=1]
+ %tmp25 = getelementptr [3 x i32]* %tmp24, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp26 = load i32* %tmp25 ; <i32> [#uses=1]
+ %tmp27 = getelementptr [5 x { i32, [3 x i32] }]* @pgm, i32 0, i32 %tmp22 ; <{ i32, [3 x i32] }*> [#uses=1]
+ %tmp28 = getelementptr { i32, [3 x i32] }* %tmp27, i32 0, i32 1 ; <[3 x i32]*> [#uses=1]
+ %tmp29 = getelementptr [3 x i32]* %tmp28, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %tmp26, i32* %tmp29
+ %tmp30 = load i32* %i ; <i32> [#uses=1]
+ %tmp31 = getelementptr [13 x %struct.anon]* @isa, i32 0, i32 0 ; <%struct.anon*> [#uses=1]
+ %tmp32 = getelementptr %struct.anon* %tmp31, i32 0, i32 3 ; <[3 x i32]*> [#uses=1]
+ %tmp33 = getelementptr [3 x i32]* %tmp32, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp34 = load i32* %tmp33 ; <i32> [#uses=1]
+ %tmp35 = getelementptr [5 x { i32, [3 x i32] }]* @pgm, i32 0, i32 %tmp30 ; <{ i32, [3 x i32] }*> [#uses=1]
+ %tmp36 = getelementptr { i32, [3 x i32] }* %tmp35, i32 0, i32 1 ; <[3 x i32]*> [#uses=1]
+ %tmp37 = getelementptr [3 x i32]* %tmp36, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 %tmp34, i32* %tmp37
+ %tmp38 = load i32* %i ; <i32> [#uses=1]
+ %tmp39 = getelementptr [13 x %struct.anon]* @isa, i32 0, i32 0 ; <%struct.anon*> [#uses=1]
+ %tmp40 = getelementptr %struct.anon* %tmp39, i32 0, i32 3 ; <[3 x i32]*> [#uses=1]
+ %tmp41 = getelementptr [3 x i32]* %tmp40, i32 0, i32 2 ; <i32*> [#uses=1]
+ %tmp42 = load i32* %tmp41 ; <i32> [#uses=1]
+ %tmp43 = getelementptr [5 x { i32, [3 x i32] }]* @pgm, i32 0, i32 %tmp38 ; <{ i32, [3 x i32] }*> [#uses=1]
+ %tmp44 = getelementptr { i32, [3 x i32] }* %tmp43, i32 0, i32 1 ; <[3 x i32]*> [#uses=1]
+ %tmp45 = getelementptr [3 x i32]* %tmp44, i32 0, i32 2 ; <i32*> [#uses=1]
+ store i32 %tmp42, i32* %tmp45
+ %tmp46 = load i32* %i ; <i32> [#uses=1]
+ call void @fix_operands( i32 %tmp46 )
+ %tmp47 = load i32* %i ; <i32> [#uses=1]
+ %tmp48 = add i32 %tmp47, 1 ; <i32> [#uses=1]
+ store i32 %tmp48, i32* %i
+ br label %bb49
+
+bb49: ; preds = %bb18, %bb17
+ %tmp50 = load i32* @numi ; <i32> [#uses=1]
+ %tmp51 = load i32* %i ; <i32> [#uses=1]
+ %tmp52 = icmp slt i32 %tmp51, %tmp50 ; <i1> [#uses=1]
+ %tmp5253 = zext i1 %tmp52 to i32 ; <i32> [#uses=1]
+ %toBool54 = icmp ne i32 %tmp5253, 0 ; <i1> [#uses=1]
+ br i1 %toBool54, label %bb18, label %bb55
+
+bb55: ; preds = %bb49
+ %tmp56 = call i32 @search( ) ; <i32> [#uses=1]
+ store i32 %tmp56, i32* %num_sol
+ %tmp57 = getelementptr [21 x i8]* @.str44, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp58 = load i32* %num_sol ; <i32> [#uses=1]
+ %tmp59 = call i32 (i8*, ...)* @printf( i8* %tmp57, i32 %tmp58 ) ; <i32> [#uses=0]
+ %tmp60 = load i32* @counters ; <i32> [#uses=1]
+ %tmp61 = icmp ne i32 %tmp60, 0 ; <i1> [#uses=1]
+ %tmp6162 = zext i1 %tmp61 to i32 ; <i32> [#uses=1]
+ %toBool63 = icmp ne i32 %tmp6162, 0 ; <i1> [#uses=1]
+ br i1 %toBool63, label %cond_true, label %cond_next
+
+cond_true: ; preds = %bb55
+ store i32 0, i32* %total
+ %tmp64 = getelementptr [12 x i8]* @.str45, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp65 = call i32 (i8*, ...)* @printf( i8* %tmp64 ) ; <i32> [#uses=0]
+ store i32 0, i32* %i
+ br label %bb79
+
+bb66: ; preds = %bb79
+ %tmp67 = load i32* %i ; <i32> [#uses=1]
+ %tmp68 = getelementptr [5 x i32]* @counter, i32 0, i32 %tmp67 ; <i32*> [#uses=1]
+ %tmp69 = load i32* %tmp68 ; <i32> [#uses=1]
+ %tmp70 = getelementptr [5 x i8]* @.str46, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp71 = call i32 (i8*, ...)* @printf( i8* %tmp70, i32 %tmp69 ) ; <i32> [#uses=0]
+ %tmp72 = load i32* %i ; <i32> [#uses=1]
+ %tmp73 = getelementptr [5 x i32]* @counter, i32 0, i32 %tmp72 ; <i32*> [#uses=1]
+ %tmp74 = load i32* %tmp73 ; <i32> [#uses=1]
+ %tmp75 = load i32* %total ; <i32> [#uses=1]
+ %tmp76 = add i32 %tmp74, %tmp75 ; <i32> [#uses=1]
+ store i32 %tmp76, i32* %total
+ %tmp77 = load i32* %i ; <i32> [#uses=1]
+ %tmp78 = add i32 %tmp77, 1 ; <i32> [#uses=1]
+ store i32 %tmp78, i32* %i
+ br label %bb79
+
+bb79: ; preds = %bb66, %cond_true
+ %tmp80 = load i32* @numi ; <i32> [#uses=1]
+ %tmp81 = load i32* %i ; <i32> [#uses=1]
+ %tmp82 = icmp slt i32 %tmp81, %tmp80 ; <i1> [#uses=1]
+ %tmp8283 = zext i1 %tmp82 to i32 ; <i32> [#uses=1]
+ %toBool84 = icmp ne i32 %tmp8283, 0 ; <i1> [#uses=1]
+ br i1 %toBool84, label %bb66, label %bb85
+
+bb85: ; preds = %bb79
+ %tmp86 = getelementptr [12 x i8]* @.str47, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp87 = load i32* %total ; <i32> [#uses=1]
+ %tmp88 = call i32 (i8*, ...)* @printf( i8* %tmp86, i32 %tmp87 ) ; <i32> [#uses=0]
+ br label %cond_next
+
+cond_next: ; preds = %bb85, %bb55
+ %tmp89 = load i32* @numi ; <i32> [#uses=1]
+ %tmp90 = add i32 %tmp89, 1 ; <i32> [#uses=1]
+ store i32 %tmp90, i32* @numi
+ br label %bb91
+
+bb91: ; preds = %cond_next, %entry
+ %tmp92 = load i32* @numi ; <i32> [#uses=1]
+ %tmp93 = icmp sgt i32 %tmp92, 5 ; <i1> [#uses=1]
+ %tmp9394 = zext i1 %tmp93 to i32 ; <i32> [#uses=1]
+ %toBool95 = icmp ne i32 %tmp9394, 0 ; <i1> [#uses=1]
+ br i1 %toBool95, label %cond_true96, label %cond_next97
+
+cond_true96: ; preds = %bb91
+ br label %bb102
+
+cond_next97: ; preds = %bb91
+ %tmp98 = load i32* %num_sol ; <i32> [#uses=1]
+ %tmp99 = icmp eq i32 %tmp98, 0 ; <i1> [#uses=1]
+ %tmp99100 = zext i1 %tmp99 to i32 ; <i32> [#uses=1]
+ %toBool101 = icmp ne i32 %tmp99100, 0 ; <i1> [#uses=1]
+ br i1 %toBool101, label %bb, label %bb102
+
+bb102: ; preds = %cond_next97, %cond_true96
+ store i32 0, i32* %tmp
+ %tmp103 = load i32* %tmp ; <i32> [#uses=1]
+ store i32 %tmp103, i32* %retval
+ br label %return
+
+return: ; preds = %bb102
+ %retval104 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval104
+}
+
+declare i32 @userfun(i32)
diff --git a/src/LLVM/test/Transforms/GVN/2007-07-31-RedundantPhi.ll b/src/LLVM/test/Transforms/GVN/2007-07-31-RedundantPhi.ll
new file mode 100644
index 0000000..a570e35
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2007-07-31-RedundantPhi.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -basicaa -gvn -S | not grep {tmp701 =}
+
+@img_width = external global i16 ; <i16*> [#uses=2]
+
+define i32 @smpUMHEXBipredIntegerPelBlockMotionSearch(i16* %cur_pic, i16 signext %ref, i32 %list, i32 %pic_pix_x, i32 %pic_pix_y, i32 %blocktype, i16 signext %pred_mv_x1, i16 signext %pred_mv_y1, i16 signext %pred_mv_x2, i16 signext %pred_mv_y2, i16* %mv_x, i16* %mv_y, i16* %s_mv_x, i16* %s_mv_y, i32 %search_range, i32 %min_mcost, i32 %lambda_factor) {
+cond_next143: ; preds = %entry
+ store i16 0, i16* @img_width, align 2
+ br i1 false, label %cond_next449, label %cond_false434
+
+cond_false434: ; preds = %cond_true415
+ br label %cond_next449
+
+cond_next449: ; preds = %cond_false434, %cond_true415
+ br i1 false, label %cond_next698, label %cond_false470
+
+cond_false470: ; preds = %cond_next449
+ br label %cond_next698
+
+cond_next698: ; preds = %cond_true492
+ %tmp701 = load i16* @img_width, align 2 ; <i16> [#uses=0]
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-02-12-UndefLoad.ll b/src/LLVM/test/Transforms/GVN/2008-02-12-UndefLoad.ll
new file mode 100644
index 0000000..de2aa61
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-02-12-UndefLoad.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -gvn -S | not grep load
+; PR1996
+
+%struct.anon = type { i32, i8, i8, i8, i8 }
+
+define i32 @a() {
+entry:
+ %c = alloca %struct.anon ; <%struct.anon*> [#uses=2]
+ %tmp = getelementptr %struct.anon* %c, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp1 = getelementptr i32* %tmp, i32 1 ; <i32*> [#uses=2]
+ %tmp2 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ %tmp3 = or i32 %tmp2, 11 ; <i32> [#uses=1]
+ %tmp4 = and i32 %tmp3, -21 ; <i32> [#uses=1]
+ store i32 %tmp4, i32* %tmp1, align 4
+ %call = call i32 (...)* @x( %struct.anon* %c ) ; <i32> [#uses=0]
+ ret i32 undef
+}
+
+
+declare i32 @x(...)
diff --git a/src/LLVM/test/Transforms/GVN/2008-02-13-NewPHI.ll b/src/LLVM/test/Transforms/GVN/2008-02-13-NewPHI.ll
new file mode 100644
index 0000000..80b519d
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-02-13-NewPHI.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -gvn
+; PR2032
+
+define i32 @sscal(i32 %n, double %sa1, float* %sx, i32 %incx) {
+entry:
+ %sx_addr = alloca float* ; <float**> [#uses=3]
+ store float* %sx, float** %sx_addr, align 4
+ br label %bb33
+
+bb: ; preds = %bb33
+ %tmp27 = load float** %sx_addr, align 4 ; <float*> [#uses=1]
+ store float 0.000000e+00, float* %tmp27, align 4
+ store float* null, float** %sx_addr, align 4
+ br label %bb33
+
+bb33: ; preds = %bb, %entry
+ br i1 false, label %bb, label %return
+
+return: ; preds = %bb33
+ %retval59 = load i32* null, align 4 ; <i32> [#uses=1]
+ ret i32 %retval59
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-07-02-Unreachable.ll b/src/LLVM/test/Transforms/GVN/2008-07-02-Unreachable.ll
new file mode 100644
index 0000000..407940b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-07-02-Unreachable.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -basicaa -gvn -S | grep {ret i8 \[%\]tmp3}
+; PR2503
+
+@g_3 = external global i8 ; <i8*> [#uses=2]
+
+define i8 @func_1() nounwind {
+entry:
+ %A = alloca i8
+ br i1 false, label %ifelse, label %ifthen
+
+ifthen: ; preds = %entry
+ br label %ifend
+
+ifelse: ; preds = %entry
+ %tmp3 = load i8* @g_3 ; <i8> [#uses=0]
+ store i8 %tmp3, i8* %A
+ br label %forcond.thread
+
+forcond.thread: ; preds = %ifelse
+ br label %afterfor
+
+forcond: ; preds = %forinc
+ br i1 false, label %afterfor, label %forbody
+
+forbody: ; preds = %forcond
+ br label %forinc
+
+forinc: ; preds = %forbody
+ br label %forcond
+
+afterfor: ; preds = %forcond, %forcond.thread
+ %tmp10 = load i8* @g_3 ; <i8> [#uses=0]
+ ret i8 %tmp10
+
+ifend: ; preds = %afterfor, %ifthen
+ ret i8 0
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-12-09-SelfRemove.ll b/src/LLVM/test/Transforms/GVN/2008-12-09-SelfRemove.ll
new file mode 100644
index 0000000..c6833e3
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-12-09-SelfRemove.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -gvn -S | grep getelementptr | count 1
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.5"
+ %struct.anon = type { i8*, i32 }
+ %struct.d_print_info = type { i32, i8*, i32, i32, %struct.d_print_template*, %struct.d_print_mod*, i32 }
+ %struct.d_print_mod = type { %struct.d_print_mod*, %struct.demangle_component*, i32, %struct.d_print_template* }
+ %struct.d_print_template = type { %struct.d_print_template*, %struct.demangle_component* }
+ %struct.demangle_component = type { i32, { %struct.anon } }
+
+define void @d_print_mod_list(%struct.d_print_info* %dpi, %struct.d_print_mod* %mods, i32 %suffix) nounwind {
+entry:
+ %0 = getelementptr %struct.d_print_info* %dpi, i32 0, i32 1 ; <i8**> [#uses=1]
+ br i1 false, label %return, label %bb
+
+bb: ; preds = %entry
+ %1 = load i8** %0, align 4 ; <i8*> [#uses=0]
+ %2 = getelementptr %struct.d_print_info* %dpi, i32 0, i32 1 ; <i8**> [#uses=0]
+ br label %bb21
+
+bb21: ; preds = %bb21, %bb
+ br label %bb21
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-12-12-RLE-Crash.ll b/src/LLVM/test/Transforms/GVN/2008-12-12-RLE-Crash.ll
new file mode 100644
index 0000000..da67ee7
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-12-12-RLE-Crash.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -gvn | llvm-dis
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i32 @main(i32 %argc, i8** %argv) nounwind {
+entry:
+ br label %bb84
+
+bb41: ; preds = %bb82
+ %tmp = load i8* %opt.0, align 1 ; <i8> [#uses=0]
+ %tmp1 = getelementptr i8* %opt.0, i32 1 ; <i8*> [#uses=2]
+ switch i32 0, label %bb81 [
+ i32 102, label %bb82
+ i32 110, label %bb79
+ i32 118, label %bb80
+ ]
+
+bb79: ; preds = %bb41
+ br label %bb82
+
+bb80: ; preds = %bb41
+ ret i32 0
+
+bb81: ; preds = %bb41
+ ret i32 1
+
+bb82: ; preds = %bb84, %bb79, %bb41
+ %opt.0 = phi i8* [ %tmp3, %bb84 ], [ %tmp1, %bb79 ], [ %tmp1, %bb41 ] ; <i8*> [#uses=3]
+ %tmp2 = load i8* %opt.0, align 1 ; <i8> [#uses=0]
+ br i1 false, label %bb84, label %bb41
+
+bb84: ; preds = %bb82, %entry
+ %tmp3 = getelementptr i8* null, i32 1 ; <i8*> [#uses=1]
+ br label %bb82
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-12-14-rle-reanalyze.ll b/src/LLVM/test/Transforms/GVN/2008-12-14-rle-reanalyze.ll
new file mode 100644
index 0000000..41f76c8
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-12-14-rle-reanalyze.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -gvn | llvm-dis
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+@sort_value = external global [256 x i32], align 32 ; <[256 x i32]*> [#uses=2]
+
+define i32 @Quiesce(i32 %alpha, i32 %beta, i32 %wtm, i32 %ply) nounwind {
+entry:
+ br label %bb22
+
+bb22: ; preds = %bb23, %bb22, %entry
+ br i1 false, label %bb23, label %bb22
+
+bb23: ; preds = %bb23, %bb22
+ %sortv.233 = phi i32* [ getelementptr ([256 x i32]* @sort_value, i32 0, i32 0), %bb22 ], [ %sortv.2, %bb23 ] ; <i32*> [#uses=1]
+ %0 = load i32* %sortv.233, align 4 ; <i32> [#uses=0]
+ %sortv.2 = getelementptr [256 x i32]* @sort_value, i32 0, i32 0 ; <i32*> [#uses=1]
+ br i1 false, label %bb23, label %bb22
+}
diff --git a/src/LLVM/test/Transforms/GVN/2008-12-15-CacheVisited.ll b/src/LLVM/test/Transforms/GVN/2008-12-15-CacheVisited.ll
new file mode 100644
index 0000000..0a63f3f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2008-12-15-CacheVisited.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -gvn | llvm-dis
+; Cached results must be added to and verified against the visited sets.
+; PR3217
+
+define fastcc void @gen_field_die(i32* %decl) nounwind {
+entry:
+ br i1 false, label %bb203, label %bb202
+
+bb202: ; preds = %entry
+ unreachable
+
+bb203: ; preds = %entry
+ %tmp = getelementptr i32* %decl, i32 1 ; <i32*> [#uses=1]
+ %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=0]
+ br i1 false, label %bb207, label %bb204
+
+bb204: ; preds = %bb203
+ %tmp2 = getelementptr i32* %decl, i32 1 ; <i32*> [#uses=1]
+ br label %bb208
+
+bb207: ; preds = %bb203
+ br label %bb208
+
+bb208: ; preds = %bb207, %bb204
+ %iftmp.1374.0.in = phi i32* [ null, %bb207 ], [ %tmp2, %bb204 ] ; <i32*> [#uses=1]
+ %iftmp.1374.0 = load i32* %iftmp.1374.0.in ; <i32> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-01-21-SortInvalidation.ll b/src/LLVM/test/Transforms/GVN/2009-01-21-SortInvalidation.ll
new file mode 100644
index 0000000..3677593
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-01-21-SortInvalidation.ll
@@ -0,0 +1,55 @@
+; RUN: opt < %s -gvn | llvm-dis
+; PR3358
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.re_pattern_buffer = type { i8*, i64, i64, i64, i8*, i8*, i64, i8 }
+ %struct.re_registers = type { i32, i32*, i32* }
+
+define fastcc i32 @byte_re_match_2_internal(%struct.re_pattern_buffer* nocapture %bufp, i8* %string1, i32 %size1, i8* %string2, i32 %size2, i32 %pos, %struct.re_registers* %regs, i32 %stop) nounwind {
+entry:
+ br label %bb159
+
+succeed_label: ; preds = %bb159
+ ret i32 0
+
+bb159: ; preds = %bb664, %bb554, %bb159, %bb159, %bb159, %entry
+ %d.0 = phi i8* [ null, %entry ], [ %d.0, %bb159 ], [ %d.0, %bb554 ], [ %d.0, %bb159 ], [ %d.0, %bb159 ], [ %d.12, %bb664 ] ; <i8*> [#uses=5]
+ switch i32 0, label %bb661 [
+ i32 0, label %bb159
+ i32 1, label %succeed_label
+ i32 13, label %bb159
+ i32 14, label %bb159
+ i32 16, label %bb411
+ i32 24, label %bb622
+ i32 28, label %bb543
+ ]
+
+bb411: ; preds = %bb411, %bb159
+ br label %bb411
+
+bb543: ; preds = %bb159
+ br i1 false, label %bb549, label %bb550
+
+bb549: ; preds = %bb543
+ br label %bb554
+
+bb550: ; preds = %bb543
+ br i1 false, label %bb554, label %bb552
+
+bb552: ; preds = %bb550
+ %0 = load i8* %d.0, align 8 ; <i8> [#uses=0]
+ br label %bb554
+
+bb554: ; preds = %bb552, %bb550, %bb549
+ br i1 false, label %bb159, label %bb661
+
+bb622: ; preds = %bb622, %bb159
+ br label %bb622
+
+bb661: ; preds = %bb554, %bb159
+ %d.12 = select i1 false, i8* null, i8* null ; <i8*> [#uses=1]
+ br label %bb664
+
+bb664: ; preds = %bb664, %bb661
+ br i1 false, label %bb159, label %bb664
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-01-22-SortInvalidation.ll b/src/LLVM/test/Transforms/GVN/2009-01-22-SortInvalidation.ll
new file mode 100644
index 0000000..95690a5
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-01-22-SortInvalidation.ll
@@ -0,0 +1,100 @@
+; RUN: opt < %s -gvn | llvm-dis
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+ %struct..4sPragmaType = type { i8*, i32 }
+ %struct.AggInfo = type { i8, i8, i32, %struct.ExprList*, i32, %struct.AggInfo_col*, i32, i32, i32, %struct.AggInfo_func*, i32, i32 }
+ %struct.AggInfo_col = type { %struct.Table*, i32, i32, i32, i32, %struct.Expr* }
+ %struct.AggInfo_func = type { %struct.Expr*, %struct.FuncDef*, i32, i32 }
+ %struct.AuxData = type { i8*, void (i8*)* }
+ %struct.Bitvec = type { i32, i32, i32, { [125 x i32] } }
+ %struct.BtCursor = type { %struct.Btree*, %struct.BtShared*, %struct.BtCursor*, %struct.BtCursor*, i32 (i8*, i32, i8*, i32, i8*)*, i8*, i32, %struct.MemPage*, i32, %struct.CellInfo, i8, i8, i8*, i64, i32, i8, i32* }
+ %struct.BtLock = type { %struct.Btree*, i32, i8, %struct.BtLock* }
+ %struct.BtShared = type { %struct.Pager*, %struct.sqlite3*, %struct.BtCursor*, %struct.MemPage*, i8, i8, i8, i8, i8, i8, i8, i8, i32, i16, i16, i32, i32, i32, i32, i8, i32, i8*, void (i8*)*, %struct.sqlite3_mutex*, %struct.BusyHandler, i32, %struct.BtShared*, %struct.BtLock*, %struct.Btree* }
+ %struct.Btree = type { %struct.sqlite3*, %struct.BtShared*, i8, i8, i8, i32, %struct.Btree*, %struct.Btree* }
+ %struct.BtreeMutexArray = type { i32, [11 x %struct.Btree*] }
+ %struct.BusyHandler = type { i32 (i8*, i32)*, i8*, i32 }
+ %struct.CellInfo = type { i8*, i64, i32, i32, i16, i16, i16, i16 }
+ %struct.CollSeq = type { i8*, i8, i8, i8*, i32 (i8*, i32, i8*, i32, i8*)*, void (i8*)* }
+ %struct.Column = type { i8*, %struct.Expr*, i8*, i8*, i8, i8, i8, i8 }
+ %struct.Context = type { i64, i32, %struct.Fifo }
+ %struct.CountCtx = type { i64 }
+ %struct.Cursor = type { %struct.BtCursor*, i32, i64, i64, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i64, %struct.Btree*, i32, i8*, i64, i8*, %struct.KeyInfo*, i32, i64, %struct.sqlite3_vtab_cursor*, %struct.sqlite3_module*, i32, i32, i32*, i32*, i8* }
+ %struct.Db = type { i8*, %struct.Btree*, i8, i8, i8*, void (i8*)*, %struct.Schema* }
+ %struct.Expr = type { i8, i8, i16, %struct.CollSeq*, %struct.Expr*, %struct.Expr*, %struct.ExprList*, %struct..4sPragmaType, %struct..4sPragmaType, i32, i32, %struct.AggInfo*, i32, i32, %struct.Select*, %struct.Table*, i32 }
+ %struct.ExprList = type { i32, i32, i32, %struct.ExprList_item* }
+ %struct.ExprList_item = type { %struct.Expr*, i8*, i8, i8, i8 }
+ %struct.FKey = type { %struct.Table*, %struct.FKey*, i8*, %struct.FKey*, i32, %struct.sColMap*, i8, i8, i8, i8 }
+ %struct.Fifo = type { i32, %struct.FifoPage*, %struct.FifoPage* }
+ %struct.FifoPage = type { i32, i32, i32, %struct.FifoPage*, [1 x i64] }
+ %struct.FuncDef = type { i16, i8, i8, i8, i8*, %struct.FuncDef*, void (%struct.sqlite3_context*, i32, %struct.Mem**)*, void (%struct.sqlite3_context*, i32, %struct.Mem**)*, void (%struct.sqlite3_context*)*, [1 x i8] }
+ %struct.Hash = type { i8, i8, i32, i32, %struct.HashElem*, %struct._ht* }
+ %struct.HashElem = type { %struct.HashElem*, %struct.HashElem*, i8*, i8*, i32 }
+ %struct.IdList = type { %struct..4sPragmaType*, i32, i32 }
+ %struct.Index = type { i8*, i32, i32*, i32*, %struct.Table*, i32, i8, i8, i8*, %struct.Index*, %struct.Schema*, i8*, i8** }
+ %struct.KeyInfo = type { %struct.sqlite3*, i8, i8, i8, i32, i8*, [1 x %struct.CollSeq*] }
+ %struct.Mem = type { %struct.CountCtx, double, %struct.sqlite3*, i8*, i32, i16, i8, i8, void (i8*)* }
+ %struct.MemPage = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i16, i16, i16, i16, i16, [5 x %struct._OvflCell], %struct.BtShared*, i8*, %struct.PgHdr*, i32, %struct.MemPage* }
+ %struct.Module = type { %struct.sqlite3_module*, i8*, i8*, void (i8*)* }
+ %struct.Op = type { i8, i8, i8, i8, i32, i32, i32, { i32 } }
+ %struct.Pager = type { %struct.sqlite3_vfs*, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.Bitvec*, %struct.Bitvec*, i8*, i8*, i8*, i8*, %struct.sqlite3_file*, %struct.sqlite3_file*, %struct.sqlite3_file*, %struct.BusyHandler*, %struct.PagerLruList, %struct.PgHdr*, %struct.PgHdr*, %struct.PgHdr*, i64, i64, i64, i64, i64, i32, void (%struct.PgHdr*, i32)*, void (%struct.PgHdr*, i32)*, i32, %struct.PgHdr**, i8*, [16 x i8] }
+ %struct.PagerLruLink = type { %struct.PgHdr*, %struct.PgHdr* }
+ %struct.PagerLruList = type { %struct.PgHdr*, %struct.PgHdr*, %struct.PgHdr* }
+ %struct.Parse = type { %struct.sqlite3*, i32, i8*, %struct.Vdbe*, i8, i8, i8, i8, i8, i8, i8, [8 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [12 x i32], i32, %struct.TableLock*, i32, i32, i32, i32, i32, %struct.Expr**, i8, %struct..4sPragmaType, %struct..4sPragmaType, %struct..4sPragmaType, i8*, i8*, %struct.Table*, %struct.Trigger*, %struct.TriggerStack*, i8*, %struct..4sPragmaType, i8, %struct.Table*, i32 }
+ %struct.PgHdr = type { %struct.Pager*, i32, %struct.PgHdr*, %struct.PgHdr*, %struct.PagerLruLink, %struct.PgHdr*, i8, i8, i8, i8, i8, i16, %struct.PgHdr*, %struct.PgHdr*, i8* }
+ %struct.Schema = type { i32, %struct.Hash, %struct.Hash, %struct.Hash, %struct.Hash, %struct.Table*, i8, i8, i16, i32, %struct.sqlite3* }
+ %struct.Select = type { %struct.ExprList*, i8, i8, i8, i8, i8, i8, i8, %struct.SrcList*, %struct.Expr*, %struct.ExprList*, %struct.Expr*, %struct.ExprList*, %struct.Select*, %struct.Select*, %struct.Select*, %struct.Expr*, %struct.Expr*, i32, i32, [3 x i32] }
+ %struct.SrcList = type { i16, i16, [1 x %struct.SrcList_item] }
+ %struct.SrcList_item = type { i8*, i8*, i8*, %struct.Table*, %struct.Select*, i8, i8, i32, %struct.Expr*, %struct.IdList*, i64 }
+ %struct.Table = type { i8*, i32, %struct.Column*, i32, %struct.Index*, i32, %struct.Select*, i32, %struct.Trigger*, %struct.FKey*, i8*, %struct.Expr*, i32, i8, i8, i8, i8, i8, i8, i8, %struct.Module*, %struct.sqlite3_vtab*, i32, i8**, %struct.Schema* }
+ %struct.TableLock = type { i32, i32, i8, i8* }
+ %struct.Trigger = type { i8*, i8*, i8, i8, %struct.Expr*, %struct.IdList*, %struct..4sPragmaType, %struct.Schema*, %struct.Schema*, %struct.TriggerStep*, %struct.Trigger* }
+ %struct.TriggerStack = type { %struct.Table*, i32, i32, i32, i32, i32, i32, %struct.Trigger*, %struct.TriggerStack* }
+ %struct.TriggerStep = type { i32, i32, %struct.Trigger*, %struct.Select*, %struct..4sPragmaType, %struct.Expr*, %struct.ExprList*, %struct.IdList*, %struct.TriggerStep*, %struct.TriggerStep* }
+ %struct.Vdbe = type { %struct.sqlite3*, %struct.Vdbe*, %struct.Vdbe*, i32, i32, %struct.Op*, i32, i32, i32*, %struct.Mem**, %struct.Mem*, i32, %struct.Cursor**, i32, %struct.Mem*, i8**, i32, i32, i32, %struct.Mem*, i32, i32, %struct.Fifo, i32, i32, %struct.Context*, i32, i32, i32, i32, i32, [25 x i32], i32, i32, i8**, i8*, %struct.Mem*, i8, i8, i8, i8, i8, i8, i32, i64, i32, %struct.BtreeMutexArray, i32, i8*, i32 }
+ %struct.VdbeFunc = type { %struct.FuncDef*, i32, [1 x %struct.AuxData] }
+ %struct._OvflCell = type { i8*, i16 }
+ %struct._ht = type { i32, %struct.HashElem* }
+ %struct.anon = type { double }
+ %struct.sColMap = type { i32, i8* }
+ %struct.sqlite3 = type { %struct.sqlite3_vfs*, i32, %struct.Db*, i32, i32, i32, i32, i8, i8, i8, i8, i32, %struct.CollSeq*, i64, i64, i32, i32, i32, %struct.sqlite3_mutex*, %struct.sqlite3InitInfo, i32, i8**, %struct.Vdbe*, i32, void (i8*, i8*)*, i8*, void (i8*, i8*, i64)*, i8*, i8*, i32 (i8*)*, i8*, void (i8*)*, i8*, void (i8*, i32, i8*, i8*, i64)*, void (i8*, %struct.sqlite3*, i32, i8*)*, void (i8*, %struct.sqlite3*, i32, i8*)*, i8*, %struct.Mem*, i8*, i8*, %struct.anon, i32 (i8*, i32, i8*, i8*, i8*, i8*)*, i8*, i32 (i8*)*, i8*, i32, %struct.Hash, %struct.Table*, %struct.sqlite3_vtab**, i32, %struct.Hash, %struct.Hash, %struct.BusyHandler, i32, [2 x %struct.Db], i8 }
+ %struct.sqlite3InitInfo = type { i32, i32, i8 }
+ %struct.sqlite3_context = type { %struct.FuncDef*, %struct.VdbeFunc*, %struct.Mem, %struct.Mem*, i32, %struct.CollSeq* }
+ %struct.sqlite3_file = type { %struct.sqlite3_io_methods* }
+ %struct.sqlite3_index_constraint = type { i32, i8, i8, i32 }
+ %struct.sqlite3_index_constraint_usage = type { i32, i8 }
+ %struct.sqlite3_index_info = type { i32, %struct.sqlite3_index_constraint*, i32, %struct.sqlite3_index_constraint_usage*, %struct.sqlite3_index_constraint_usage*, i32, i8*, i32, i32, double }
+ %struct.sqlite3_io_methods = type { i32, i32 (%struct.sqlite3_file*)*, i32 (%struct.sqlite3_file*, i8*, i32, i64)*, i32 (%struct.sqlite3_file*, i8*, i32, i64)*, i32 (%struct.sqlite3_file*, i64)*, i32 (%struct.sqlite3_file*, i32)*, i32 (%struct.sqlite3_file*, i64*)*, i32 (%struct.sqlite3_file*, i32)*, i32 (%struct.sqlite3_file*, i32)*, i32 (%struct.sqlite3_file*)*, i32 (%struct.sqlite3_file*, i32, i8*)*, i32 (%struct.sqlite3_file*)*, i32 (%struct.sqlite3_file*)* }
+ %struct.sqlite3_module = type { i32, i32 (%struct.sqlite3*, i8*, i32, i8**, %struct.sqlite3_vtab**, i8**)*, i32 (%struct.sqlite3*, i8*, i32, i8**, %struct.sqlite3_vtab**, i8**)*, i32 (%struct.sqlite3_vtab*, %struct.sqlite3_index_info*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*, %struct.sqlite3_vtab_cursor**)*, i32 (%struct.sqlite3_vtab_cursor*)*, i32 (%struct.sqlite3_vtab_cursor*, i32, i8*, i32, %struct.Mem**)*, i32 (%struct.sqlite3_vtab_cursor*)*, i32 (%struct.sqlite3_vtab_cursor*)*, i32 (%struct.sqlite3_vtab_cursor*, %struct.sqlite3_context*, i32)*, i32 (%struct.sqlite3_vtab_cursor*, i64*)*, i32 (%struct.sqlite3_vtab*, i32, %struct.Mem**, i64*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*)*, i32 (%struct.sqlite3_vtab*, i32, i8*, void (%struct.sqlite3_context*, i32, %struct.Mem**)**, i8**)*, i32 (%struct.sqlite3_vtab*, i8*)* }
+ %struct.sqlite3_mutex = type opaque
+ %struct.sqlite3_vfs = type { i32, i32, i32, %struct.sqlite3_vfs*, i8*, i8*, i32 (%struct.sqlite3_vfs*, i8*, %struct.sqlite3_file*, i32, i32*)*, i32 (%struct.sqlite3_vfs*, i8*, i32)*, i32 (%struct.sqlite3_vfs*, i8*, i32)*, i32 (%struct.sqlite3_vfs*, i32, i8*)*, i32 (%struct.sqlite3_vfs*, i8*, i32, i8*)*, i8* (%struct.sqlite3_vfs*, i8*)*, void (%struct.sqlite3_vfs*, i32, i8*)*, i8* (%struct.sqlite3_vfs*, i8*, i8*)*, void (%struct.sqlite3_vfs*, i8*)*, i32 (%struct.sqlite3_vfs*, i32, i8*)*, i32 (%struct.sqlite3_vfs*, i32)*, i32 (%struct.sqlite3_vfs*, double*)* }
+ %struct.sqlite3_vtab = type { %struct.sqlite3_module*, i32, i8* }
+ %struct.sqlite3_vtab_cursor = type { %struct.sqlite3_vtab* }
+
+define fastcc void @sqlite3Insert(%struct.Parse* %pParse, %struct.SrcList* %pTabList, %struct.ExprList* %pList, %struct.Select* %pSelect, %struct.IdList* %pColumn, i32 %onError) nounwind {
+entry:
+ br i1 false, label %bb54, label %bb69.loopexit
+
+bb54: ; preds = %entry
+ br label %bb69.loopexit
+
+bb59: ; preds = %bb63.preheader
+ %0 = load %struct..4sPragmaType** %3, align 4 ; <%struct..4sPragmaType*> [#uses=0]
+ br label %bb65
+
+bb65: ; preds = %bb63.preheader, %bb59
+ %1 = load %struct..4sPragmaType** %4, align 4 ; <%struct..4sPragmaType*> [#uses=0]
+ br i1 false, label %bb67, label %bb63.preheader
+
+bb67: ; preds = %bb65
+ %2 = getelementptr %struct.IdList* %pColumn, i32 0, i32 0 ; <%struct..4sPragmaType**> [#uses=0]
+ unreachable
+
+bb69.loopexit: ; preds = %bb54, %entry
+ %3 = getelementptr %struct.IdList* %pColumn, i32 0, i32 0 ; <%struct..4sPragmaType**> [#uses=1]
+ %4 = getelementptr %struct.IdList* %pColumn, i32 0, i32 0 ; <%struct..4sPragmaType**> [#uses=1]
+ br label %bb63.preheader
+
+bb63.preheader: ; preds = %bb69.loopexit, %bb65
+ br i1 false, label %bb59, label %bb65
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll b/src/LLVM/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll
new file mode 100644
index 0000000..c2d57a1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-02-17-LoadPRECrash.ll
@@ -0,0 +1,193 @@
+; RUN: opt < %s -gvn -enable-load-pre -disable-output
+
+ %struct.VEC_rtx_base = type { i32, i32, [1 x %struct.rtx_def*] }
+ %struct.VEC_rtx_gc = type { %struct.VEC_rtx_base }
+ %struct.block_symbol = type { [3 x %struct.cgraph_rtl_info], %struct.object_block*, i64 }
+ %struct.cgraph_rtl_info = type { i32 }
+ %struct.object_block = type { %struct.section*, i32, i64, %struct.VEC_rtx_gc*, %struct.VEC_rtx_gc* }
+ %struct.rtvec_def = type { i32, [1 x %struct.rtx_def*] }
+ %struct.rtx_def = type { i16, i8, i8, %struct.u }
+ %struct.section = type { %struct.unnamed_section }
+ %struct.u = type { %struct.block_symbol }
+ %struct.unnamed_section = type { %struct.cgraph_rtl_info, void (i8*)*, i8*, %struct.section* }
+
+declare %struct.rtvec_def* @gen_rtvec(i32, ...)
+
+declare %struct.rtx_def* @plus_constant(%struct.rtx_def*, i64)
+
+declare %struct.rtx_def* @gen_rtx_fmt_Ei(i32, i32, %struct.rtvec_def*, i32)
+
+declare i32 @local_symbolic_operand(%struct.rtx_def*, i32)
+
+define %struct.rtx_def* @legitimize_pic_address(%struct.rtx_def* %orig, %struct.rtx_def* %reg) nounwind {
+entry:
+ %addr = alloca %struct.rtx_def* ; <%struct.rtx_def**> [#uses=5]
+ %iftmp.1532 = alloca %struct.rtx_def* ; <%struct.rtx_def**> [#uses=3]
+ store %struct.rtx_def* %orig, %struct.rtx_def** null
+ %0 = load %struct.rtx_def** null, align 4 ; <%struct.rtx_def*> [#uses=0]
+ br i1 false, label %bb96, label %bb59
+
+bb59: ; preds = %entry
+ %1 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1]
+ %2 = call i32 @local_symbolic_operand(%struct.rtx_def* %1, i32 0) nounwind ; <i32> [#uses=0]
+ br i1 false, label %bb96, label %bb63
+
+bb63: ; preds = %bb59
+ br i1 false, label %bb64, label %bb74
+
+bb64: ; preds = %bb63
+ br i1 false, label %bb72, label %bb65
+
+bb65: ; preds = %bb64
+ br label %bb72
+
+bb72: ; preds = %bb65, %bb64
+ br label %bb74
+
+bb74: ; preds = %bb72, %bb63
+ br i1 false, label %bb75, label %bb76
+
+bb75: ; preds = %bb74
+ br label %bb76
+
+bb76: ; preds = %bb75, %bb74
+ br i1 false, label %bb77, label %bb84
+
+bb77: ; preds = %bb76
+ %3 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 0 ; <%struct.cgraph_rtl_info*> [#uses=0]
+ unreachable
+
+bb84: ; preds = %bb76
+ br i1 false, label %bb85, label %bb86
+
+bb85: ; preds = %bb84
+ br label %bb87
+
+bb86: ; preds = %bb84
+ br label %bb87
+
+bb87: ; preds = %bb86, %bb85
+ %4 = call %struct.rtx_def* @gen_rtx_fmt_Ei(i32 16, i32 0, %struct.rtvec_def* null, i32 1) nounwind ; <%struct.rtx_def*> [#uses=0]
+ br i1 false, label %bb89, label %bb90
+
+bb89: ; preds = %bb87
+ br label %bb91
+
+bb90: ; preds = %bb87
+ br label %bb91
+
+bb91: ; preds = %bb90, %bb89
+ br i1 false, label %bb92, label %bb93
+
+bb92: ; preds = %bb91
+ br label %bb94
+
+bb93: ; preds = %bb91
+ br label %bb94
+
+bb94: ; preds = %bb93, %bb92
+ unreachable
+
+bb96: ; preds = %bb59, %entry
+ %5 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1]
+ %6 = getelementptr %struct.rtx_def* %5, i32 0, i32 0 ; <i16*> [#uses=1]
+ %7 = load i16* %6, align 2 ; <i16> [#uses=0]
+ br i1 false, label %bb147, label %bb97
+
+bb97: ; preds = %bb96
+ %8 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=0]
+ br i1 false, label %bb147, label %bb99
+
+bb99: ; preds = %bb97
+ unreachable
+
+bb147: ; preds = %bb97, %bb96
+ %9 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=1]
+ %10 = getelementptr %struct.rtx_def* %9, i32 0, i32 0 ; <i16*> [#uses=1]
+ %11 = load i16* %10, align 2 ; <i16> [#uses=0]
+ br i1 false, label %bb164, label %bb148
+
+bb148: ; preds = %bb147
+ br i1 false, label %bb164, label %bb149
+
+bb149: ; preds = %bb148
+ br i1 false, label %bb150, label %bb152
+
+bb150: ; preds = %bb149
+ unreachable
+
+bb152: ; preds = %bb149
+ br label %bb164
+
+bb164: ; preds = %bb152, %bb148, %bb147
+ %12 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 1 ; <%struct.cgraph_rtl_info*> [#uses=0]
+ br i1 false, label %bb165, label %bb166
+
+bb165: ; preds = %bb164
+ br label %bb167
+
+bb166: ; preds = %bb164
+ br label %bb167
+
+bb167: ; preds = %bb166, %bb165
+ br i1 false, label %bb211, label %bb168
+
+bb168: ; preds = %bb167
+ br i1 false, label %bb211, label %bb170
+
+bb170: ; preds = %bb168
+ br i1 false, label %bb172, label %bb181
+
+bb172: ; preds = %bb170
+ br i1 false, label %bb179, label %bb174
+
+bb174: ; preds = %bb172
+ br i1 false, label %bb177, label %bb175
+
+bb175: ; preds = %bb174
+ br i1 false, label %bb177, label %bb176
+
+bb176: ; preds = %bb175
+ br label %bb178
+
+bb177: ; preds = %bb175, %bb174
+ br label %bb178
+
+bb178: ; preds = %bb177, %bb176
+ br label %bb180
+
+bb179: ; preds = %bb172
+ br label %bb180
+
+bb180: ; preds = %bb179, %bb178
+ br label %bb181
+
+bb181: ; preds = %bb180, %bb170
+ %13 = call %struct.rtvec_def* (i32, ...)* @gen_rtvec(i32 1, %struct.rtx_def* null) nounwind ; <%struct.rtvec_def*> [#uses=0]
+ unreachable
+
+bb211: ; preds = %bb168, %bb167
+ %14 = load %struct.rtx_def** %addr, align 4 ; <%struct.rtx_def*> [#uses=0]
+ %15 = getelementptr [1 x %struct.cgraph_rtl_info]* null, i32 0, i32 0 ; <%struct.cgraph_rtl_info*> [#uses=0]
+ store %struct.rtx_def* null, %struct.rtx_def** null, align 4
+ br i1 false, label %bb212, label %bb213
+
+bb212: ; preds = %bb211
+ store %struct.rtx_def* null, %struct.rtx_def** %iftmp.1532, align 4
+ br label %bb214
+
+bb213: ; preds = %bb211
+ store %struct.rtx_def* null, %struct.rtx_def** %iftmp.1532, align 4
+ br label %bb214
+
+bb214: ; preds = %bb213, %bb212
+ %16 = bitcast %struct.block_symbol* null to [1 x %struct.cgraph_rtl_info]* ; <[1 x %struct.cgraph_rtl_info]*> [#uses=1]
+ %17 = getelementptr [1 x %struct.cgraph_rtl_info]* %16, i32 0, i32 1 ; <%struct.cgraph_rtl_info*> [#uses=0]
+ %18 = load %struct.rtx_def** %iftmp.1532, align 4 ; <%struct.rtx_def*> [#uses=0]
+ %19 = getelementptr %struct.rtx_def* null, i32 0, i32 3 ; <%struct.u*> [#uses=1]
+ %20 = getelementptr %struct.u* %19, i32 0, i32 0 ; <%struct.block_symbol*> [#uses=1]
+ %21 = bitcast %struct.block_symbol* %20 to [1 x i64]* ; <[1 x i64]*> [#uses=1]
+ %22 = getelementptr [1 x i64]* %21, i32 0, i32 0 ; <i64*> [#uses=0]
+ %23 = call %struct.rtx_def* @plus_constant(%struct.rtx_def* null, i64 0) nounwind ; <%struct.rtx_def*> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-03-10-PREOnVoid.ll b/src/LLVM/test/Transforms/GVN/2009-03-10-PREOnVoid.ll
new file mode 100644
index 0000000..89d6a5f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-03-10-PREOnVoid.ll
@@ -0,0 +1,82 @@
+; RUN: opt < %s -gvn -disable-output
+; PR3775
+
+; ModuleID = 'bugpoint-reduced-simplified.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %"struct.__gnu_cxx::hash<void*>" = type <{ i8 }>
+ %struct.__sched_param = type { i32 }
+ %struct._pthread_descr_struct = type opaque
+ %struct.pthread_attr_t = type { i32, i32, %struct.__sched_param, i32, i32, i32, i32, i8*, i32 }
+ %struct.pthread_mutex_t = type { i32, i32, %struct._pthread_descr_struct*, i32, %llvm.dbg.anchor.type }
+ %"struct.std::_Rb_tree<void*,std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > >,std::_Select1st<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,std::less<void*>,std::allocator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > > >" = type { %"struct.std::_Rb_tree<void*,std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > >,std::_Select1st<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,std::less<void*>,std::allocator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > > >::_Rb_tree_impl<std::less<void*>,false>" }
+ %"struct.std::_Rb_tree<void*,std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > >,std::_Select1st<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,std::less<void*>,std::allocator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > > >::_Rb_tree_impl<std::less<void*>,false>" = type { %"struct.__gnu_cxx::hash<void*>", %"struct.std::_Rb_tree_node_base", i32 }
+ %"struct.std::_Rb_tree_iterator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >" = type { %"struct.std::_Rb_tree_node_base"* }
+ %"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* }
+ %"struct.std::pair<std::_Rb_tree_iterator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,bool>" = type { %"struct.std::_Rb_tree_iterator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >", i8 }
+ %"struct.std::pair<void* const,void*>" = type { i8*, i8* }
+
+@_ZL20__gthrw_pthread_oncePiPFvvE = alias weak i32 (i32*, void ()*)* @pthread_once ; <i32 (i32*, void ()*)*> [#uses=0]
+@_ZL27__gthrw_pthread_getspecificj = alias weak i8* (i32)* @pthread_getspecific ; <i8* (i32)*> [#uses=0]
+@_ZL27__gthrw_pthread_setspecificjPKv = alias weak i32 (i32, i8*)* @pthread_setspecific ; <i32 (i32, i8*)*> [#uses=0]
+@_ZL22__gthrw_pthread_createPmPK16__pthread_attr_sPFPvS3_ES3_ = alias weak i32 (i32*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)* @pthread_create ; <i32 (i32*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)*> [#uses=0]
+@_ZL22__gthrw_pthread_cancelm = alias weak i32 (i32)* @pthread_cancel ; <i32 (i32)*> [#uses=0]
+@_ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_lock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_trylock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_unlock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t = alias weak i32 (%struct.pthread_mutex_t*, %struct.__sched_param*)* @pthread_mutex_init ; <i32 (%struct.pthread_mutex_t*, %struct.__sched_param*)*> [#uses=0]
+@_ZL26__gthrw_pthread_key_createPjPFvPvE = alias weak i32 (i32*, void (i8*)*)* @pthread_key_create ; <i32 (i32*, void (i8*)*)*> [#uses=0]
+@_ZL26__gthrw_pthread_key_deletej = alias weak i32 (i32)* @pthread_key_delete ; <i32 (i32)*> [#uses=0]
+@_ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t = alias weak i32 (%struct.__sched_param*)* @pthread_mutexattr_init ; <i32 (%struct.__sched_param*)*> [#uses=0]
+@_ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = alias weak i32 (%struct.__sched_param*, i32)* @pthread_mutexattr_settype ; <i32 (%struct.__sched_param*, i32)*> [#uses=0]
+@_ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = alias weak i32 (%struct.__sched_param*)* @pthread_mutexattr_destroy ; <i32 (%struct.__sched_param*)*> [#uses=0]
+
+declare fastcc void @_ZNSt10_Select1stISt4pairIKPvS1_EEC1Ev() nounwind readnone
+
+define fastcc void @_ZNSt8_Rb_treeIPvSt4pairIKS0_S0_ESt10_Select1stIS3_ESt4lessIS0_ESaIS3_EE16_M_insert_uniqueERKS3_(%"struct.std::pair<std::_Rb_tree_iterator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,bool>"* noalias nocapture sret %agg.result, %"struct.std::_Rb_tree<void*,std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > >,std::_Select1st<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > >,std::less<void*>,std::allocator<std::pair<void* const, std::vector<ShadowInfo, std::allocator<ShadowInfo> > > > >"* %this, %"struct.std::pair<void* const,void*>"* %__v) nounwind {
+entry:
+ br i1 false, label %bb7, label %bb
+
+bb: ; preds = %bb, %entry
+ br i1 false, label %bb5, label %bb
+
+bb5: ; preds = %bb
+ call fastcc void @_ZNSt10_Select1stISt4pairIKPvS1_EEC1Ev() nounwind
+ br i1 false, label %bb11, label %bb7
+
+bb7: ; preds = %bb5, %entry
+ br label %bb11
+
+bb11: ; preds = %bb7, %bb5
+ call fastcc void @_ZNSt10_Select1stISt4pairIKPvS1_EEC1Ev() nounwind
+ unreachable
+}
+
+declare i32 @pthread_once(i32*, void ()*)
+
+declare i8* @pthread_getspecific(i32)
+
+declare i32 @pthread_setspecific(i32, i8*)
+
+declare i32 @pthread_create(i32*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)
+
+declare i32 @pthread_cancel(i32)
+
+declare i32 @pthread_mutex_lock(%struct.pthread_mutex_t*)
+
+declare i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*)
+
+declare i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*)
+
+declare i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %struct.__sched_param*)
+
+declare i32 @pthread_key_create(i32*, void (i8*)*)
+
+declare i32 @pthread_key_delete(i32)
+
+declare i32 @pthread_mutexattr_init(%struct.__sched_param*)
+
+declare i32 @pthread_mutexattr_settype(%struct.__sched_param*, i32)
+
+declare i32 @pthread_mutexattr_destroy(%struct.__sched_param*)
diff --git a/src/LLVM/test/Transforms/GVN/2009-06-17-InvalidPRE.ll b/src/LLVM/test/Transforms/GVN/2009-06-17-InvalidPRE.ll
new file mode 100644
index 0000000..6ac6072
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-06-17-InvalidPRE.ll
@@ -0,0 +1,72 @@
+; RUN: opt < %s -gvn -enable-load-pre -S | not grep pre1
+; GVN load pre was hoisting the loads at %13 and %16 up to bb4.outer.
+; This is invalid as it bypasses the check for %m.0.ph==null in bb4.
+; ModuleID = 'mbuf.c'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+ %struct.mbuf = type { %struct.mbuf*, %struct.mbuf*, i32, i8*, i16, i16, i32 }
+
+define void @m_adj(%struct.mbuf* %mp, i32 %req_len) nounwind optsize {
+entry:
+ %0 = icmp eq %struct.mbuf* %mp, null ; <i1> [#uses=1]
+ %1 = icmp slt i32 %req_len, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %1, %0 ; <i1> [#uses=1]
+ br i1 %or.cond, label %return, label %bb4.preheader
+
+bb4.preheader: ; preds = %entry
+ br label %bb4.outer
+
+bb2: ; preds = %bb1
+ %2 = sub i32 %len.0, %13 ; <i32> [#uses=1]
+ %3 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 2 ; <i32*> [#uses=1]
+ store i32 0, i32* %3, align 4
+ %4 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 0 ; <%struct.mbuf**> [#uses=1]
+ %5 = load %struct.mbuf** %4, align 4 ; <%struct.mbuf*> [#uses=1]
+ br label %bb4.outer
+
+bb4.outer: ; preds = %bb4.preheader, %bb2
+ %m.0.ph = phi %struct.mbuf* [ %5, %bb2 ], [ %mp, %bb4.preheader ] ; <%struct.mbuf*> [#uses=7]
+ %len.0.ph = phi i32 [ %2, %bb2 ], [ %req_len, %bb4.preheader ] ; <i32> [#uses=1]
+ %6 = icmp ne %struct.mbuf* %m.0.ph, null ; <i1> [#uses=1]
+ %7 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 2 ; <i32*> [#uses=1]
+ %8 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 2 ; <i32*> [#uses=1]
+ %9 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 3 ; <i8**> [#uses=1]
+ %10 = getelementptr %struct.mbuf* %m.0.ph, i32 0, i32 3 ; <i8**> [#uses=1]
+ br label %bb4
+
+bb4: ; preds = %bb4.outer, %bb3
+ %len.0 = phi i32 [ 0, %bb3 ], [ %len.0.ph, %bb4.outer ] ; <i32> [#uses=6]
+ %11 = icmp sgt i32 %len.0, 0 ; <i1> [#uses=1]
+ %12 = and i1 %11, %6 ; <i1> [#uses=1]
+ br i1 %12, label %bb1, label %bb7
+
+bb1: ; preds = %bb4
+ %13 = load i32* %7, align 4 ; <i32> [#uses=3]
+ %14 = icmp sgt i32 %13, %len.0 ; <i1> [#uses=1]
+ br i1 %14, label %bb3, label %bb2
+
+bb3: ; preds = %bb1
+ %15 = sub i32 %13, %len.0 ; <i32> [#uses=1]
+ store i32 %15, i32* %8, align 4
+ %16 = load i8** %9, align 4 ; <i8*> [#uses=1]
+ %17 = getelementptr i8* %16, i32 %len.0 ; <i8*> [#uses=1]
+ store i8* %17, i8** %10, align 4
+ br label %bb4
+
+bb7: ; preds = %bb4
+ %18 = getelementptr %struct.mbuf* %mp, i32 0, i32 5 ; <i16*> [#uses=1]
+ %19 = load i16* %18, align 2 ; <i16> [#uses=1]
+ %20 = zext i16 %19 to i32 ; <i32> [#uses=1]
+ %21 = and i32 %20, 2 ; <i32> [#uses=1]
+ %22 = icmp eq i32 %21, 0 ; <i1> [#uses=1]
+ br i1 %22, label %return, label %bb8
+
+bb8: ; preds = %bb7
+ %23 = sub i32 %req_len, %len.0 ; <i32> [#uses=1]
+ %24 = getelementptr %struct.mbuf* %mp, i32 0, i32 6 ; <i32*> [#uses=1]
+ store i32 %23, i32* %24, align 4
+ ret void
+
+return: ; preds = %bb7, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-07-13-MemDepSortFail.ll b/src/LLVM/test/Transforms/GVN/2009-07-13-MemDepSortFail.ll
new file mode 100644
index 0000000..f079108
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-07-13-MemDepSortFail.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -gvn | llvm-dis
+; PR4256
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %struct.cset = type { i8*, i8, i8, i32, i8* }
+ %struct.lmat = type { %struct.re_guts*, i32, %llvm.dbg.anchor.type*, i8*, i8*, i8*, i8*, i8**, i32, i8*, i8*, i8*, i8*, i8* }
+ %struct.re_guts = type { i32*, %struct.cset*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i32, [1 x i8] }
+
+define i8* @lbackref(%struct.lmat* %m, i8* %start, i8* %stop, i32 %startst, i32 %stopst, i32 %lev, i32 %rec) nounwind {
+entry:
+ br label %bb63
+
+bb: ; preds = %bb63
+ switch i32 0, label %bb62 [
+ i32 268435456, label %bb2
+ i32 805306368, label %bb9
+ i32 -1610612736, label %bb51
+ ]
+
+bb2: ; preds = %bb
+ br label %bb62
+
+bb9: ; preds = %bb
+ %0 = load i8* %sp.1, align 1 ; <i8> [#uses=0]
+ br label %bb62
+
+bb51: ; preds = %bb
+ %1 = load i8* %sp.1, align 1 ; <i8> [#uses=0]
+ ret i8* null
+
+bb62: ; preds = %bb9, %bb2, %bb
+ br label %bb63
+
+bb63: ; preds = %bb84, %bb69, %bb62, %entry
+ %sp.1 = phi i8* [ null, %bb62 ], [ %sp.1.lcssa, %bb84 ], [ %start, %entry ], [ %sp.1.lcssa, %bb69 ] ; <i8*> [#uses=3]
+ br i1 false, label %bb, label %bb65
+
+bb65: ; preds = %bb63
+ %sp.1.lcssa = phi i8* [ %sp.1, %bb63 ] ; <i8*> [#uses=4]
+ br i1 false, label %bb66, label %bb69
+
+bb66: ; preds = %bb65
+ ret i8* null
+
+bb69: ; preds = %bb65
+ switch i32 0, label %bb108.loopexit2.loopexit.loopexit [
+ i32 1342177280, label %bb63
+ i32 1476395008, label %bb84
+ i32 1879048192, label %bb104
+ i32 2013265920, label %bb93
+ ]
+
+bb84: ; preds = %bb69
+ %2 = tail call i8* @lbackref(%struct.lmat* %m, i8* %sp.1.lcssa, i8* %stop, i32 0, i32 %stopst, i32 0, i32 0) nounwind ; <i8*> [#uses=0]
+ br label %bb63
+
+bb93: ; preds = %bb69
+ ret i8* null
+
+bb104: ; preds = %bb69
+ %sp.1.lcssa.lcssa33 = phi i8* [ %sp.1.lcssa, %bb69 ] ; <i8*> [#uses=0]
+ unreachable
+
+bb108.loopexit2.loopexit.loopexit: ; preds = %bb69
+ ret i8* null
+}
diff --git a/src/LLVM/test/Transforms/GVN/2009-11-12-MemDepMallocBitCast.ll b/src/LLVM/test/Transforms/GVN/2009-11-12-MemDepMallocBitCast.ll
new file mode 100644
index 0000000..b433297
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2009-11-12-MemDepMallocBitCast.ll
@@ -0,0 +1,15 @@
+; Test to make sure malloc's bitcast does not block detection of a store
+; to aliased memory; GVN should not optimize away the load in this program.
+; RUN: opt < %s -gvn -S | FileCheck %s
+
+define i64 @test() {
+ %1 = tail call i8* @malloc(i64 mul (i64 4, i64 ptrtoint (i64* getelementptr (i64* null, i64 1) to i64))) ; <i8*> [#uses=2]
+ store i8 42, i8* %1
+ %X = bitcast i8* %1 to i64* ; <i64*> [#uses=1]
+ %Y = load i64* %X ; <i64> [#uses=1]
+ ret i64 %Y
+; CHECK: %Y = load i64* %X
+; CHECK: ret i64 %Y
+}
+
+declare noalias i8* @malloc(i64)
diff --git a/src/LLVM/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll b/src/LLVM/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll
new file mode 100644
index 0000000..d6e1c6b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+; CHECK-NOT: load
+; CHECK-NOT: phi
+
+define i8* @cat(i8* %s1, ...) nounwind {
+entry:
+ br i1 undef, label %bb, label %bb3
+
+bb: ; preds = %entry
+ unreachable
+
+bb3: ; preds = %entry
+ store i8* undef, i8** undef, align 4
+ br i1 undef, label %bb5, label %bb6
+
+bb5: ; preds = %bb3
+ unreachable
+
+bb6: ; preds = %bb3
+ br label %bb12
+
+bb8: ; preds = %bb12
+ br i1 undef, label %bb9, label %bb10
+
+bb9: ; preds = %bb8
+ %0 = load i8** undef, align 4 ; <i8*> [#uses=0]
+ %1 = load i8** undef, align 4 ; <i8*> [#uses=0]
+ br label %bb11
+
+bb10: ; preds = %bb8
+ br label %bb11
+
+bb11: ; preds = %bb10, %bb9
+ br label %bb12
+
+bb12: ; preds = %bb11, %bb6
+ br i1 undef, label %bb8, label %bb13
+
+bb13: ; preds = %bb12
+ ret i8* undef
+}
diff --git a/src/LLVM/test/Transforms/GVN/2010-05-08-OneBit.ll b/src/LLVM/test/Transforms/GVN/2010-05-08-OneBit.ll
new file mode 100644
index 0000000..480ce8b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2010-05-08-OneBit.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -gvn
+; PR7052
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @main(i32 %argc, i8** nocapture %argv) {
+entry:
+ %0 = getelementptr inbounds i8* undef, i64 5 ; <i8*> [#uses=1]
+ %1 = bitcast i8* %0 to i32* ; <i32*> [#uses=1]
+ store i32 undef, i32* %1, align 1
+ br i1 undef, label %k121.i.i, label %l117.i.i
+
+l117.i.i: ; preds = %entry
+ invoke fastcc void @foo()
+ to label %.noexc5 unwind label %landing_pad
+
+.noexc5: ; preds = %l117.i.i
+ unreachable
+
+k121.i.i: ; preds = %entry
+ br i1 undef, label %l129.i.i, label %k133.i.i
+
+l129.i.i: ; preds = %k121.i.i
+ invoke fastcc void @foo()
+ to label %.noexc7 unwind label %landing_pad
+
+.noexc7: ; preds = %l129.i.i
+ unreachable
+
+k133.i.i: ; preds = %k121.i.i
+ %2 = getelementptr i8* undef, i64 5 ; <i8*> [#uses=1]
+ %3 = bitcast i8* %2 to i1* ; <i1*> [#uses=1]
+ %4 = load i1* %3 ; <i1> [#uses=1]
+ br i1 %4, label %k151.i.i, label %l147.i.i
+
+l147.i.i: ; preds = %k133.i.i
+ invoke fastcc void @foo()
+ to label %.noexc10 unwind label %landing_pad
+
+.noexc10: ; preds = %l147.i.i
+ unreachable
+
+k151.i.i: ; preds = %k133.i.i
+ ret i32 0
+
+landing_pad: ; preds = %l147.i.i, %l129.i.i, %l117.i.i
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ switch i32 undef, label %fin [
+ i32 1, label %catch1
+ i32 2, label %catch
+ ]
+
+fin: ; preds = %landing_pad
+ unreachable
+
+catch: ; preds = %landing_pad
+ ret i32 1
+
+catch1: ; preds = %landing_pad
+ ret i32 2
+}
+
+declare fastcc void @foo()
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/GVN/2010-11-13-Simplify.ll b/src/LLVM/test/Transforms/GVN/2010-11-13-Simplify.ll
new file mode 100644
index 0000000..07585a2
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2010-11-13-Simplify.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+declare i32 @foo(i32) readnone
+
+define i1 @bar() {
+; CHECK: @bar
+ %a = call i32 @foo (i32 0) readnone
+ %b = call i32 @foo (i32 0) readnone
+ %c = and i32 %a, %b
+ %x = call i32 @foo (i32 %a) readnone
+ %y = call i32 @foo (i32 %c) readnone
+ %z = icmp eq i32 %x, %y
+ ret i1 %z
+; CHECK: ret i1 true
+}
diff --git a/src/LLVM/test/Transforms/GVN/2011-04-27-phioperands.ll b/src/LLVM/test/Transforms/GVN/2011-04-27-phioperands.ll
new file mode 100644
index 0000000..6e5075d
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2011-04-27-phioperands.ll
@@ -0,0 +1,106 @@
+; RUN: opt %s -gvn -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-f128:128:128-n8:16:32:64"
+
+@nuls = external global [10 x i8]
+
+define fastcc void @p_ere() nounwind {
+entry:
+ br label %"<bb 5>"
+
+"<L18>.i":
+ br i1 undef, label %"<bb 3>.i30.i", label %doemit.exit51.i
+
+"<bb 3>.i30.i":
+ unreachable
+
+doemit.exit51.i:
+ br label %"<bb 53>.i"
+
+"<L19>.i":
+ br i1 undef, label %"<bb 3>.i55.i", label %doemit.exit76.i
+
+"<bb 3>.i55.i":
+ unreachable
+
+doemit.exit76.i:
+ br label %"<bb 53>.i"
+
+"<L98>.i":
+ store i8* getelementptr inbounds ([10 x i8]* @nuls, i64 0, i64 0), i8** undef, align 8
+ br label %"<bb 53>.i"
+
+"<L99>.i":
+ br label %"<bb 53>.i"
+
+"<L24>.i":
+ br i1 undef, label %"<bb 53>.i", label %"<bb 35>.i"
+
+"<bb 35>.i":
+ br label %"<bb 53>.i"
+
+"<L28>.i":
+ br label %"<bb 53>.i"
+
+"<L29>.i":
+ br label %"<bb 53>.i"
+
+"<L39>.i":
+ br label %"<bb 53>.i"
+
+"<bb 53>.i":
+ %wascaret_2.i = phi i32 [ 0, %"<L39>.i" ], [ 0, %"<L29>.i" ], [ 0, %"<L28>.i" ], [ 0, %"<bb 35>.i" ], [ 0, %"<L99>.i" ], [ 0, %"<L98>.i" ], [ 0, %doemit.exit76.i ], [ 1, %doemit.exit51.i ], [ 0, %"<L24>.i" ]
+ %D.5496_84.i = load i8** undef, align 8
+ br i1 undef, label %"<bb 54>.i", label %"<bb 5>"
+
+"<bb 54>.i":
+ br i1 undef, label %"<bb 5>", label %"<bb 58>.i"
+
+"<bb 58>.i":
+ br i1 undef, label %"<bb 64>.i", label %"<bb 59>.i"
+
+"<bb 59>.i":
+ br label %"<bb 64>.i"
+
+"<bb 64>.i":
+ switch i32 undef, label %"<bb 5>" [
+ i32 42, label %"<L54>.i"
+ i32 43, label %"<L55>.i"
+ i32 63, label %"<L56>.i"
+ i32 123, label %"<bb 5>.i258.i"
+ ]
+
+"<L54>.i":
+ br i1 undef, label %"<bb 3>.i105.i", label %doemit.exit127.i
+
+"<bb 3>.i105.i":
+ unreachable
+
+doemit.exit127.i:
+ unreachable
+
+"<L55>.i":
+ br i1 undef, label %"<bb 3>.i157.i", label %"<bb 5>"
+
+"<bb 3>.i157.i":
+ unreachable
+
+"<L56>.i":
+ br label %"<bb 5>"
+
+"<bb 5>.i258.i":
+ unreachable
+
+"<bb 5>":
+ switch i32 undef, label %"<L39>.i" [
+ i32 36, label %"<L19>.i"
+ i32 94, label %"<L18>.i"
+ i32 124, label %"<L98>.i"
+ i32 42, label %"<L99>.i"
+ i32 43, label %"<L99>.i"
+ i32 46, label %"<L24>.i"
+ i32 63, label %"<L99>.i"
+ i32 91, label %"<L28>.i"
+ i32 92, label %"<L29>.i"
+ ]
+}
diff --git a/src/LLVM/test/Transforms/GVN/2011-06-01-NonLocalMemdepMiscompile.ll b/src/LLVM/test/Transforms/GVN/2011-06-01-NonLocalMemdepMiscompile.ll
new file mode 100644
index 0000000..f24e956
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2011-06-01-NonLocalMemdepMiscompile.ll
@@ -0,0 +1,61 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+; This test is checking that (a) this doesn't crash, and (b) we don't
+; conclude the value of %tmp17 is available in bb1.bb15_crit_edge.
+; rdar://9429882
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+define i1 @rb_intern() nounwind ssp {
+; CHECK: @rb_intern
+
+bb:
+ %tmp = alloca i8*, align 8
+ store i8* null, i8** %tmp, align 8
+ store i8 undef, i8* null, align 536870912
+ br label %bb1
+
+bb1:
+ br i1 undef, label %bb3, label %bb15
+
+; CHECK: bb1:
+; CHECK: %tmp16 = phi i8* [ getelementptr (i8* null, i64 undef), %bb10 ], [ null, %bb ]
+
+; CHECK: bb1.bb15_crit_edge:
+; CHECK: %tmp17.pre = load i8* %tmp16, align 1
+
+bb3:
+ call void @isalnum()
+ br i1 undef, label %bb10, label %bb5
+
+bb5:
+ br i1 undef, label %bb10, label %bb6
+
+bb6:
+ %tmp7 = load i8** %tmp, align 8
+ %tmp8 = load i8* %tmp7, align 1
+ %tmp9 = zext i8 %tmp8 to i64
+ br i1 undef, label %bb15, label %bb10
+
+bb10:
+ %tmp11 = load i8** %tmp, align 8
+ %tmp12 = load i8* %tmp11, align 1
+ %tmp13 = zext i8 %tmp12 to i64
+ %tmp14 = getelementptr inbounds i8* null, i64 undef
+ store i8* %tmp14, i8** %tmp, align 8
+ br label %bb1
+
+bb15:
+ %tmp16 = load i8** %tmp, align 8
+ %tmp17 = load i8* %tmp16, align 1
+ %tmp18 = icmp eq i8 %tmp17, 0
+ br label %bb19
+
+; CHECK: bb15:
+; CHECK: %tmp17 = phi i8 [ %tmp17.pre, %bb1.bb15_crit_edge ], [ %tmp8, %bb6 ]
+
+bb19: ; preds = %bb15
+ ret i1 %tmp18
+}
+
+declare void @isalnum() nounwind inlinehint ssp
diff --git a/src/LLVM/test/Transforms/GVN/2011-07-07-MatchIntrinsicExtract.ll b/src/LLVM/test/Transforms/GVN/2011-07-07-MatchIntrinsicExtract.ll
new file mode 100644
index 0000000..18178e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2011-07-07-MatchIntrinsicExtract.ll
@@ -0,0 +1,85 @@
+; RUN: opt < %s -gvn -S | FileCheck %s
+;
+
+%0 = type { i64, i1 }
+
+define i64 @test1(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %uadd = tail call %0 @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
+ %uadd.0 = extractvalue %0 %uadd, 0
+ %add1 = add i64 %a, %b
+ ret i64 %add1
+}
+
+; CHECK: @test1
+; CHECK-NOT: add1
+; CHECK: ret
+
+define i64 @test2(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %usub = tail call %0 @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
+ %usub.0 = extractvalue %0 %usub, 0
+ %sub1 = sub i64 %a, %b
+ ret i64 %sub1
+}
+
+; CHECK: @test2
+; CHECK-NOT: sub1
+; CHECK: ret
+
+define i64 @test3(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %umul = tail call %0 @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
+ %umul.0 = extractvalue %0 %umul, 0
+ %mul1 = mul i64 %a, %b
+ ret i64 %mul1
+}
+
+; CHECK: @test3
+; CHECK-NOT: mul1
+; CHECK: ret
+
+define i64 @test4(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %sadd = tail call %0 @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
+ %sadd.0 = extractvalue %0 %sadd, 0
+ %add1 = add i64 %a, %b
+ ret i64 %add1
+}
+
+; CHECK: @test4
+; CHECK-NOT: add1
+; CHECK: ret
+
+define i64 @test5(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %ssub = tail call %0 @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
+ %ssub.0 = extractvalue %0 %ssub, 0
+ %sub1 = sub i64 %a, %b
+ ret i64 %sub1
+}
+
+; CHECK: @test5
+; CHECK-NOT: sub1
+; CHECK: ret
+
+define i64 @test6(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %smul = tail call %0 @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
+ %smul.0 = extractvalue %0 %smul, 0
+ %mul1 = mul i64 %a, %b
+ ret i64 %mul1
+}
+
+; CHECK: @test6
+; CHECK-NOT: mul1
+; CHECK: ret
+
+declare void @exit(i32) noreturn
+declare %0 @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
+declare %0 @llvm.usub.with.overflow.i64(i64, i64) nounwind readnone
+declare %0 @llvm.umul.with.overflow.i64(i64, i64) nounwind readnone
+declare %0 @llvm.sadd.with.overflow.i64(i64, i64) nounwind readnone
+declare %0 @llvm.ssub.with.overflow.i64(i64, i64) nounwind readnone
+declare %0 @llvm.smul.with.overflow.i64(i64, i64) nounwind readnone
+
diff --git a/src/LLVM/test/Transforms/GVN/2011-09-07-TypeIdFor.ll b/src/LLVM/test/Transforms/GVN/2011-09-07-TypeIdFor.ll
new file mode 100644
index 0000000..314b5bb
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/2011-09-07-TypeIdFor.ll
@@ -0,0 +1,81 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+%struct.__fundamental_type_info_pseudo = type { %struct.__type_info_pseudo }
+%struct.__type_info_pseudo = type { i8*, i8* }
+
+@_ZTIi = external constant %struct.__fundamental_type_info_pseudo
+@_ZTIb = external constant %struct.__fundamental_type_info_pseudo
+
+declare void @_Z4barv()
+
+declare void @_Z7cleanupv()
+
+declare i32 @llvm.eh.typeid.for(i8*) nounwind readonly
+
+declare i8* @__cxa_begin_catch(i8*) nounwind
+
+declare void @__cxa_end_catch()
+
+declare i32 @__gxx_personality_v0(i32, i64, i8*, i8*)
+
+define void @_Z3foov() uwtable {
+entry:
+ invoke void @_Z4barv()
+ to label %return unwind label %lpad
+
+lpad: ; preds = %entry
+ %0 = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ catch %struct.__fundamental_type_info_pseudo* @_ZTIi
+ catch %struct.__fundamental_type_info_pseudo* @_ZTIb
+ catch %struct.__fundamental_type_info_pseudo* @_ZTIi
+ catch %struct.__fundamental_type_info_pseudo* @_ZTIb
+ %exc_ptr2.i = extractvalue { i8*, i32 } %0, 0
+ %filter3.i = extractvalue { i8*, i32 } %0, 1
+ %typeid.i = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%struct.__fundamental_type_info_pseudo* @_ZTIi to i8*))
+; CHECK: call i32 @llvm.eh.typeid.for
+ %1 = icmp eq i32 %filter3.i, %typeid.i
+ br i1 %1, label %ppad, label %next
+
+next: ; preds = %lpad
+ %typeid1.i = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%struct.__fundamental_type_info_pseudo* @_ZTIb to i8*))
+; CHECK: call i32 @llvm.eh.typeid.for
+ %2 = icmp eq i32 %filter3.i, %typeid1.i
+ br i1 %2, label %ppad2, label %next2
+
+ppad: ; preds = %lpad
+ %3 = tail call i8* @__cxa_begin_catch(i8* %exc_ptr2.i) nounwind
+ tail call void @__cxa_end_catch() nounwind
+ br label %return
+
+ppad2: ; preds = %next
+ %D.2073_5.i = tail call i8* @__cxa_begin_catch(i8* %exc_ptr2.i) nounwind
+ tail call void @__cxa_end_catch() nounwind
+ br label %return
+
+next2: ; preds = %next
+ call void @_Z7cleanupv()
+ %typeid = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%struct.__fundamental_type_info_pseudo* @_ZTIi to i8*))
+; CHECK-NOT: call i32 @llvm.eh.typeid.for
+ %4 = icmp eq i32 %filter3.i, %typeid
+ br i1 %4, label %ppad3, label %next3
+
+next3: ; preds = %next2
+ %typeid1 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%struct.__fundamental_type_info_pseudo* @_ZTIb to i8*))
+ %5 = icmp eq i32 %filter3.i, %typeid1
+ br i1 %5, label %ppad4, label %unwind
+
+unwind: ; preds = %next3
+ resume { i8*, i32 } %0
+
+ppad3: ; preds = %next2
+ %6 = tail call i8* @__cxa_begin_catch(i8* %exc_ptr2.i) nounwind
+ tail call void @__cxa_end_catch() nounwind
+ br label %return
+
+ppad4: ; preds = %next3
+ %D.2080_5 = tail call i8* @__cxa_begin_catch(i8* %exc_ptr2.i) nounwind
+ tail call void @__cxa_end_catch() nounwind
+ br label %return
+
+return: ; preds = %ppad4, %ppad3, %ppad2, %ppad, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/atomic.ll b/src/LLVM/test/Transforms/GVN/atomic.ll
new file mode 100644
index 0000000..094e22b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/atomic.ll
@@ -0,0 +1,80 @@
+; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+@x = common global i32 0, align 4
+@y = common global i32 0, align 4
+
+; GVN across unordered store (allowed)
+define i32 @test1() nounwind uwtable ssp {
+; CHECK: test1
+; CHECK: add i32 %x, %x
+entry:
+ %x = load i32* @y
+ store atomic i32 %x, i32* @x unordered, align 4
+ %y = load i32* @y
+ %z = add i32 %x, %y
+ ret i32 %z
+}
+
+; GVN across seq_cst store (allowed in theory; not implemented ATM)
+define i32 @test2() nounwind uwtable ssp {
+; CHECK: test2
+; CHECK: add i32 %x, %y
+entry:
+ %x = load i32* @y
+ store atomic i32 %x, i32* @x seq_cst, align 4
+ %y = load i32* @y
+ %z = add i32 %x, %y
+ ret i32 %z
+}
+
+; GVN across unordered load (allowed)
+define i32 @test3() nounwind uwtable ssp {
+; CHECK: test3
+; CHECK: add i32 %x, %x
+entry:
+ %x = load i32* @y
+ %y = load atomic i32* @x unordered, align 4
+ %z = load i32* @y
+ %a = add i32 %x, %z
+ %b = add i32 %y, %a
+ ret i32 %b
+}
+
+; GVN across acquire load (load after atomic load must not be removed)
+define i32 @test4() nounwind uwtable ssp {
+; CHECK: test4
+; CHECK: load atomic i32* @x
+; CHECK: load i32* @y
+entry:
+ %x = load i32* @y
+ %y = load atomic i32* @x seq_cst, align 4
+ %x2 = load i32* @y
+ %x3 = add i32 %x, %x2
+ %y2 = add i32 %y, %x3
+ ret i32 %y2
+}
+
+; GVN load to unordered load (allowed)
+define i32 @test5() nounwind uwtable ssp {
+; CHECK: test5
+; CHECK: add i32 %x, %x
+entry:
+ %x = load atomic i32* @x unordered, align 4
+ %y = load i32* @x
+ %z = add i32 %x, %y
+ ret i32 %z
+}
+
+; GVN unordered load to load (unordered load must not be removed)
+define i32 @test6() nounwind uwtable ssp {
+; CHECK: test6
+; CHECK: load atomic i32* @x unordered
+entry:
+ %x = load i32* @x
+ %x2 = load atomic i32* @x unordered, align 4
+ %x3 = add i32 %x, %x2
+ ret i32 %x3
+}
diff --git a/src/LLVM/test/Transforms/GVN/basic.ll b/src/LLVM/test/Transforms/GVN/basic.ll
new file mode 100644
index 0000000..1decafa
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/basic.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -gvn -S | not grep {%z2 =}
+
+define i32 @main() {
+block1:
+ %z1 = bitcast i32 0 to i32
+ br label %block2
+block2:
+ %z2 = bitcast i32 0 to i32
+ ret i32 %z2
+}
diff --git a/src/LLVM/test/Transforms/GVN/bitcast-of-call.ll b/src/LLVM/test/Transforms/GVN/bitcast-of-call.ll
new file mode 100644
index 0000000..55b4b6e
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/bitcast-of-call.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -gvn -S | not grep tmp2
+; PR2213
+
+define i32* @f(i8* %x) {
+entry:
+ %tmp = call i8* @m( i32 12 ) ; <i8*> [#uses=2]
+ %tmp1 = bitcast i8* %tmp to i32* ; <i32*> [#uses=0]
+ %tmp2 = bitcast i8* %tmp to i32* ; <i32*> [#uses=0]
+ ret i32* %tmp2
+}
+
+declare i8* @m(i32)
diff --git a/src/LLVM/test/Transforms/GVN/calls-nonlocal.ll b/src/LLVM/test/Transforms/GVN/calls-nonlocal.ll
new file mode 100644
index 0000000..24ef2e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/calls-nonlocal.ll
@@ -0,0 +1,49 @@
+; RUN: opt < %s -basicaa -gvn -S | grep strlen | count 2
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9"
+
+define i32 @test(i32 %g, i8* %P) nounwind {
+entry:
+ %tmp2 = call i32 @strlen( i8* %P ) nounwind readonly ; <i32> [#uses=1]
+ %tmp3 = icmp eq i32 %tmp2, 100 ; <i1> [#uses=1]
+ %tmp34 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp34, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb, label %bb6
+
+bb: ; preds = %entry
+ br label %bb27
+
+bb6: ; preds = %entry
+ %tmp8 = add i32 %g, 42 ; <i32> [#uses=2]
+ %tmp10 = call i32 @strlen( i8* %P ) nounwind readonly ; <i32> [#uses=1]
+ %tmp11 = icmp eq i32 %tmp10, 100 ; <i1> [#uses=1]
+ %tmp1112 = zext i1 %tmp11 to i8 ; <i8> [#uses=1]
+ %toBool13 = icmp ne i8 %tmp1112, 0 ; <i1> [#uses=1]
+ br i1 %toBool13, label %bb14, label %bb16
+
+bb14: ; preds = %bb6
+ br label %bb27
+
+bb16: ; preds = %bb6
+ %tmp18 = mul i32 %tmp8, 2 ; <i32> [#uses=1]
+ %tmp20 = call i32 @strlen( i8* %P ) nounwind readonly ; <i32> [#uses=1]
+ %tmp21 = icmp eq i32 %tmp20, 100 ; <i1> [#uses=1]
+ %tmp2122 = zext i1 %tmp21 to i8 ; <i8> [#uses=1]
+ %toBool23 = icmp ne i8 %tmp2122, 0 ; <i1> [#uses=1]
+ br i1 %toBool23, label %bb24, label %bb26
+
+bb24: ; preds = %bb16
+ br label %bb27
+
+bb26: ; preds = %bb16
+ br label %bb27
+
+bb27: ; preds = %bb26, %bb24, %bb14, %bb
+ %tmp.0 = phi i32 [ 11, %bb26 ], [ %tmp18, %bb24 ], [ %tmp8, %bb14 ], [ %g, %bb ] ; <i32> [#uses=1]
+ br label %return
+
+return: ; preds = %bb27
+ ret i32 %tmp.0
+}
+
+declare i32 @strlen(i8*) nounwind readonly
diff --git a/src/LLVM/test/Transforms/GVN/calls-readonly.ll b/src/LLVM/test/Transforms/GVN/calls-readonly.ll
new file mode 100644
index 0000000..97ec915
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/calls-readonly.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -basicaa -gvn -S | grep {call.*strlen} | count 1
+; Should delete the second call to strlen even though the intervening strchr call exists.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i8* @test(i8* %P, i8* %Q, i32 %x, i32 %y) nounwind readonly {
+entry:
+ %0 = tail call i32 @strlen(i8* %P) ; <i32> [#uses=2]
+ %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
+ br i1 %1, label %bb, label %bb1
+
+bb: ; preds = %entry
+ %2 = sdiv i32 %x, %y ; <i32> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb, %entry
+ %x_addr.0 = phi i32 [ %2, %bb ], [ %x, %entry ] ; <i32> [#uses=1]
+ %3 = tail call i8* @strchr(i8* %Q, i32 97) ; <i8*> [#uses=1]
+ %4 = tail call i32 @strlen(i8* %P) ; <i32> [#uses=1]
+ %5 = add i32 %x_addr.0, %0 ; <i32> [#uses=1]
+ %.sum = sub i32 %5, %4 ; <i32> [#uses=1]
+ %6 = getelementptr i8* %3, i32 %.sum ; <i8*> [#uses=1]
+ ret i8* %6
+}
+
+declare i32 @strlen(i8*) nounwind readonly
+
+declare i8* @strchr(i8*, i32) nounwind readonly
diff --git a/src/LLVM/test/Transforms/GVN/condprop.ll b/src/LLVM/test/Transforms/GVN/condprop.ll
new file mode 100644
index 0000000..0b31b01
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/condprop.ll
@@ -0,0 +1,132 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+@a = external global i32 ; <i32*> [#uses=7]
+
+; CHECK: @test1
+define i32 @test1() nounwind {
+entry:
+ %0 = load i32* @a, align 4
+ %1 = icmp eq i32 %0, 4
+ br i1 %1, label %bb, label %bb1
+
+bb: ; preds = %entry
+ br label %bb8
+
+bb1: ; preds = %entry
+ %2 = load i32* @a, align 4
+ %3 = icmp eq i32 %2, 5
+ br i1 %3, label %bb2, label %bb3
+
+bb2: ; preds = %bb1
+ br label %bb8
+
+bb3: ; preds = %bb1
+ %4 = load i32* @a, align 4
+ %5 = icmp eq i32 %4, 4
+; CHECK: br i1 false, label %bb4, label %bb5
+ br i1 %5, label %bb4, label %bb5
+
+bb4: ; preds = %bb3
+ %6 = load i32* @a, align 4
+ %7 = add i32 %6, 5
+ br label %bb8
+
+bb5: ; preds = %bb3
+ %8 = load i32* @a, align 4
+ %9 = icmp eq i32 %8, 5
+; CHECK: br i1 false, label %bb6, label %bb7
+ br i1 %9, label %bb6, label %bb7
+
+bb6: ; preds = %bb5
+ %10 = load i32* @a, align 4
+ %11 = add i32 %10, 4
+ br label %bb8
+
+bb7: ; preds = %bb5
+ %12 = load i32* @a, align 4
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb6, %bb4, %bb2, %bb
+ %.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ]
+ br label %return
+
+return: ; preds = %bb8
+ ret i32 %.0
+}
+
+declare void @foo(i1)
+
+; CHECK: @test2
+define void @test2(i1 %x, i1 %y) {
+ %z = or i1 %x, %y
+ br i1 %z, label %true, label %false
+true:
+; CHECK: true:
+ %z2 = or i1 %x, %y
+ call void @foo(i1 %z2)
+; CHECK: call void @foo(i1 true)
+ br label %true
+false:
+; CHECK: false:
+ %z3 = or i1 %x, %y
+ call void @foo(i1 %z3)
+; CHECK: call void @foo(i1 false)
+ br label %false
+}
+
+declare void @bar(i32)
+
+; CHECK: @test3
+define void @test3(i32 %x, i32 %y) {
+ %xz = icmp eq i32 %x, 0
+ %yz = icmp eq i32 %y, 0
+ %z = and i1 %xz, %yz
+ br i1 %z, label %both_zero, label %nope
+both_zero:
+ call void @foo(i1 %xz)
+; CHECK: call void @foo(i1 true)
+ call void @foo(i1 %yz)
+; CHECK: call void @foo(i1 true)
+ call void @bar(i32 %x)
+; CHECK: call void @bar(i32 0)
+ call void @bar(i32 %y)
+; CHECK: call void @bar(i32 0)
+ ret void
+nope:
+ call void @foo(i1 %z)
+; CHECK: call void @foo(i1 false)
+ ret void
+}
+
+; CHECK: @test4
+define void @test4(i1 %b, i32 %x) {
+ br i1 %b, label %sw, label %case3
+sw:
+ switch i32 %x, label %default [
+ i32 0, label %case0
+ i32 1, label %case1
+ i32 2, label %case0
+ i32 3, label %case3
+ i32 4, label %default
+ ]
+default:
+; CHECK: default:
+ call void @bar(i32 %x)
+; CHECK: call void @bar(i32 %x)
+ ret void
+case0:
+; CHECK: case0:
+ call void @bar(i32 %x)
+; CHECK: call void @bar(i32 %x)
+ ret void
+case1:
+; CHECK: case1:
+ call void @bar(i32 %x)
+; CHECK: call void @bar(i32 1)
+ ret void
+case3:
+; CHECK: case3:
+ call void @bar(i32 %x)
+; CHECK: call void @bar(i32 %x)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/crash-no-aa.ll b/src/LLVM/test/Transforms/GVN/crash-no-aa.ll
new file mode 100644
index 0000000..dae65dd
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/crash-no-aa.ll
@@ -0,0 +1,16 @@
+; RUN: opt -no-aa -gvn -S %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v1
+28:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-freebsd8.0"
+
+; PR5744
+define i32 @test1({i16, i32} *%P) {
+ %P2 = getelementptr {i16, i32} *%P, i32 0, i32 0
+ store i16 42, i16* %P2
+
+ %P3 = getelementptr {i16, i32} *%P, i32 0, i32 1
+ %V = load i32* %P3
+ ret i32 %V
+}
+
diff --git a/src/LLVM/test/Transforms/GVN/crash.ll b/src/LLVM/test/Transforms/GVN/crash.ll
new file mode 100644
index 0000000..31eae25
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/crash.ll
@@ -0,0 +1,165 @@
+; RUN: opt -gvn %s -disable-output
+
+; PR5631
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0"
+
+define i32* @test1(i8* %name, i32 %namelen, i32* %o, i32 %expected_type) nounwind ssp {
+entry:
+ br i1 undef, label %if.end13, label %while.body.preheader
+
+
+if.end13: ; preds = %if.then6
+ br label %while.body.preheader
+
+while.body.preheader: ; preds = %if.end13, %if.end
+ br label %while.body
+
+while.body: ; preds = %while.body.backedge, %while.body.preheader
+ %o.addr.0 = phi i32* [ undef, %while.body.preheader ], [ %o.addr.0.be, %while.body.backedge ] ; <i32*> [#uses=2]
+ br i1 false, label %return.loopexit, label %lor.lhs.false
+
+lor.lhs.false: ; preds = %while.body
+ %tmp20 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
+ %tmp22 = load i32* %tmp20 ; <i32> [#uses=0]
+ br i1 undef, label %land.lhs.true24, label %if.end31
+
+land.lhs.true24: ; preds = %lor.lhs.false
+ %call28 = call i32* @parse_object(i8* undef) nounwind ; <i32*> [#uses=0]
+ br i1 undef, label %return.loopexit, label %if.end31
+
+if.end31: ; preds = %land.lhs.true24, %lor.lhs.false
+ br i1 undef, label %return.loopexit, label %if.end41
+
+if.end41: ; preds = %if.end31
+ %tmp43 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
+ %tmp45 = load i32* %tmp43 ; <i32> [#uses=0]
+ br i1 undef, label %if.then50, label %if.else
+
+if.then50: ; preds = %if.end41
+ %tmp53 = load i32** undef ; <i32*> [#uses=1]
+ br label %while.body.backedge
+
+if.else: ; preds = %if.end41
+ br i1 undef, label %if.then62, label %if.else67
+
+if.then62: ; preds = %if.else
+ br label %while.body.backedge
+
+while.body.backedge: ; preds = %if.then62, %if.then50
+ %o.addr.0.be = phi i32* [ %tmp53, %if.then50 ], [ undef, %if.then62 ] ; <i32*> [#uses=1]
+ br label %while.body
+
+if.else67: ; preds = %if.else
+ ret i32* null
+
+return.loopexit: ; preds = %if.end31, %land.lhs.true24, %while.body
+ ret i32* undef
+}
+
+declare i32* @parse_object(i8*)
+
+
+
+
+
+
+%struct.attribute_spec = type { i8*, i32, i32, i8, i8, i8 }
+
+@attribute_tables = external global [4 x %struct.attribute_spec*] ; <[4 x %struct.attribute_spec*]*> [#uses=2]
+
+define void @test2() nounwind {
+entry:
+ br label %bb69.i
+
+bb69.i: ; preds = %bb57.i.preheader
+ %tmp4 = getelementptr inbounds [4 x %struct.attribute_spec*]* @attribute_tables, i32 0, i32 undef ; <%struct.attribute_spec**> [#uses=1]
+ %tmp3 = load %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
+ br label %bb65.i
+
+bb65.i: ; preds = %bb65.i.preheader, %bb64.i
+ %storemerge6.i = phi i32 [ 1, %bb64.i ], [ 0, %bb69.i ] ; <i32> [#uses=3]
+ %scevgep14 = getelementptr inbounds %struct.attribute_spec* %tmp3, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=1]
+ %tmp2 = load i8** %scevgep14, align 4 ; <i8*> [#uses=0]
+ %tmp = load %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
+ %scevgep1516 = getelementptr inbounds %struct.attribute_spec* %tmp, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=0]
+ unreachable
+
+bb64.i: ; Unreachable
+ br label %bb65.i
+
+bb66.i: ; Unreachable
+ br label %bb69.i
+}
+
+
+
+; rdar://7438974
+
+@g = external global i64, align 8
+
+define i32* @test3() {
+do.end17.i:
+ %tmp18.i = load i7** undef
+ %tmp1 = bitcast i7* %tmp18.i to i8*
+ br i1 undef, label %do.body36.i, label %if.then21.i
+
+if.then21.i:
+ %tmp2 = bitcast i7* %tmp18.i to i8*
+ ret i32* undef
+
+do.body36.i:
+ %ivar38.i = load i64* @g
+ %tmp3 = bitcast i7* %tmp18.i to i8*
+ %add.ptr39.sum.i = add i64 %ivar38.i, 8
+ %tmp40.i = getelementptr inbounds i8* %tmp3, i64 %add.ptr39.sum.i
+ %tmp4 = bitcast i8* %tmp40.i to i64*
+ %tmp41.i = load i64* %tmp4
+ br i1 undef, label %if.then48.i, label %do.body57.i
+
+if.then48.i:
+ %call54.i = call i32 @foo2()
+ br label %do.body57.i
+
+do.body57.i:
+ %tmp58.i = load i7** undef
+ %ivar59.i = load i64* @g
+ %tmp5 = bitcast i7* %tmp58.i to i8*
+ %add.ptr65.sum.i = add i64 %ivar59.i, 8
+ %tmp66.i = getelementptr inbounds i8* %tmp5, i64 %add.ptr65.sum.i
+ %tmp6 = bitcast i8* %tmp66.i to i64*
+ %tmp67.i = load i64* %tmp6
+ ret i32* undef
+}
+
+declare i32 @foo2()
+
+
+
+define i32 @test4() {
+entry:
+ ret i32 0
+
+dead:
+ %P2 = getelementptr i32 *%P2, i32 52
+ %Q2 = getelementptr i32 *%Q2, i32 52
+ store i32 4, i32* %P2
+ %A = load i32* %Q2
+ br i1 true, label %dead, label %dead2
+
+dead2:
+ ret i32 %A
+}
+
+
+; PR9841
+define fastcc i8 @test5(i8* %P) nounwind {
+entry:
+ %0 = load i8* %P, align 2
+
+ %Q = getelementptr i8* %P, i32 1
+ %1 = load i8* %Q, align 1
+ ret i8 %1
+}
+
diff --git a/src/LLVM/test/Transforms/GVN/dg.exp b/src/LLVM/test/Transforms/GVN/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/GVN/lifetime-simple.ll b/src/LLVM/test/Transforms/GVN/lifetime-simple.ll
new file mode 100644
index 0000000..02f7bcc
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/lifetime-simple.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i8 @test(i8* %P) nounwind {
+; CHECK: lifetime.start
+; CHECK-NOT: load
+; CHECK: lifetime.end
+entry:
+ call void @llvm.lifetime.start(i64 32, i8* %P)
+ %0 = load i8* %P
+ store i8 1, i8* %P
+ call void @llvm.lifetime.end(i64 32, i8* %P)
+ %1 = load i8* %P
+ ret i8 %1
+}
+
+declare void @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
+declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)
diff --git a/src/LLVM/test/Transforms/GVN/load-constant-mem.ll b/src/LLVM/test/Transforms/GVN/load-constant-mem.ll
new file mode 100644
index 0000000..314c806
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/load-constant-mem.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -basicaa -gvn -instcombine -S | grep {ret i32 0}
+; PR4189
+@G = external constant [4 x i32]
+
+define i32 @test(i8* %p, i32 %i) nounwind {
+entry:
+ %P = getelementptr [4 x i32]* @G, i32 0, i32 %i
+ %A = load i32* %P
+ store i8 4, i8* %p
+ %B = load i32* %P
+ %C = sub i32 %A, %B
+ ret i32 %C
+}
diff --git a/src/LLVM/test/Transforms/GVN/load-pre-align.ll b/src/LLVM/test/Transforms/GVN/load-pre-align.ll
new file mode 100644
index 0000000..d8ad59f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/load-pre-align.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -gvn -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"
+
+@p = external global i32
+
+define i32 @test(i32 %n) nounwind {
+; CHECK: @test
+entry:
+ br label %for.cond
+
+; loads aligned greater than the memory should not be moved past conditionals
+; CHECK-NOT: load
+; CHECK: br i1
+
+for.cond:
+ %i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %for.inc ]
+ %cmp = icmp slt i32 %i.0, %n
+ br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
+
+for.cond.for.end_crit_edge:
+; ...but PRE can still move the load out of for.end to here.
+; CHECK: for.cond.for.end_crit_edge:
+; CHECK-NEXT: load
+ br label %for.end
+
+for.body:
+ %tmp3 = load i32* @p, align 8
+ %dec = add i32 %tmp3, -1
+ store i32 %dec, i32* @p
+ %cmp6 = icmp slt i32 %dec, 0
+ br i1 %cmp6, label %for.body.for.end_crit_edge, label %for.inc
+
+for.body.for.end_crit_edge:
+ br label %for.end
+
+for.inc:
+ %indvar.next = add i32 %i.0, 1
+ br label %for.cond
+
+for.end:
+ %tmp9 = load i32* @p, align 8
+ ret i32 %tmp9
+}
diff --git a/src/LLVM/test/Transforms/GVN/load-pre-licm.ll b/src/LLVM/test/Transforms/GVN/load-pre-licm.ll
new file mode 100644
index 0000000..63541ad
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/load-pre-licm.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin11.0.0"
+
+@sortlist = external global [5001 x i32], align 4
+
+define void @Bubble() nounwind noinline {
+; CHECK: entry:
+; CHECK-NEXT: %tmp7.pre = load i32
+entry:
+ br label %while.body5
+
+; CHECK: while.body5:
+; CHECK: %tmp7 = phi i32
+; CHECK-NOT: %tmp7 = load i32
+while.body5:
+ %indvar = phi i32 [ 0, %entry ], [ %tmp6, %if.end ]
+ %tmp5 = add i32 %indvar, 2
+ %arrayidx9 = getelementptr [5001 x i32]* @sortlist, i32 0, i32 %tmp5
+ %tmp6 = add i32 %indvar, 1
+ %arrayidx = getelementptr [5001 x i32]* @sortlist, i32 0, i32 %tmp6
+ %tmp7 = load i32* %arrayidx, align 4
+ %tmp10 = load i32* %arrayidx9, align 4
+ %cmp11 = icmp sgt i32 %tmp7, %tmp10
+ br i1 %cmp11, label %if.then, label %if.end
+
+; CHECK: if.then:
+if.then:
+ store i32 %tmp10, i32* %arrayidx, align 4
+ store i32 %tmp7, i32* %arrayidx9, align 4
+ br label %if.end
+
+if.end:
+ %exitcond = icmp eq i32 %tmp6, 100
+ br i1 %exitcond, label %while.end.loopexit, label %while.body5
+
+while.end.loopexit:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/local-pre.ll b/src/LLVM/test/Transforms/GVN/local-pre.ll
new file mode 100644
index 0000000..5f03984
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/local-pre.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -gvn -enable-pre -S | grep {b.pre}
+
+define i32 @main(i32 %p) {
+block1:
+
+ br i1 true, label %block2, label %block3
+
+block2:
+ %a = add i32 %p, 1
+ br label %block4
+
+block3:
+ br label %block4
+
+block4:
+ %b = add i32 %p, 1
+ ret i32 %b
+}
diff --git a/src/LLVM/test/Transforms/GVN/lpre-call-wrap-2.ll b/src/LLVM/test/Transforms/GVN/lpre-call-wrap-2.ll
new file mode 100644
index 0000000..e39f3ed
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/lpre-call-wrap-2.ll
@@ -0,0 +1,40 @@
+; RUN: opt -S -basicaa -gvn -enable-load-pre %s | FileCheck %s
+;
+; The partially redundant load in bb1 should be hoisted to "bb". This comes
+; from this C code (GCC PR 23455):
+; unsigned outcnt; extern void flush_outbuf(void);
+; void bi_windup(unsigned char *outbuf, unsigned char bi_buf) {
+; outbuf[outcnt] = bi_buf;
+; if (outcnt == 16384)
+; flush_outbuf();
+; outbuf[outcnt] = bi_buf;
+; }
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+@outcnt = common global i32 0 ; <i32*> [#uses=3]
+
+define void @bi_windup(i8* %outbuf, i8 zeroext %bi_buf) nounwind {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %0 = load i32* @outcnt, align 4 ; <i32> [#uses=1]
+ %1 = getelementptr i8* %outbuf, i32 %0 ; <i8*> [#uses=1]
+ store i8 %bi_buf, i8* %1, align 1
+ %2 = load i32* @outcnt, align 4 ; <i32> [#uses=1]
+ %3 = icmp eq i32 %2, 16384 ; <i1> [#uses=1]
+ br i1 %3, label %bb, label %bb1
+
+bb: ; preds = %entry
+ call void @flush_outbuf() nounwind
+ br label %bb1
+
+bb1: ; preds = %bb, %entry
+; CHECK: bb1:
+; CHECK-NEXT: phi
+; CHECK-NEXT: getelementptr
+ %4 = load i32* @outcnt, align 4 ; <i32> [#uses=1]
+ %5 = getelementptr i8* %outbuf, i32 %4 ; <i8*> [#uses=1]
+ store i8 %bi_buf, i8* %5, align 1
+ ret void
+}
+
+declare void @flush_outbuf()
diff --git a/src/LLVM/test/Transforms/GVN/lpre-call-wrap.ll b/src/LLVM/test/Transforms/GVN/lpre-call-wrap.ll
new file mode 100644
index 0000000..4046279
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/lpre-call-wrap.ll
@@ -0,0 +1,55 @@
+; RUN: opt -S -gvn -enable-load-pre %s | FileCheck %s
+;
+; Make sure the load in bb3.backedge is removed and moved into bb1 after the
+; call. This makes the non-call case faster.
+;
+; This test is derived from this C++ code (GCC PR 37810):
+; void g();
+; struct A {
+; int n; int m;
+; A& operator++(void) { ++n; if (n == m) g(); return *this; }
+; A() : n(0), m(0) { }
+; friend bool operator!=(A const& a1, A const& a2) { return a1.n != a2.n; }
+; };
+; void testfunction(A& iter) { A const end; while (iter != end) ++iter; }
+;
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+ %struct.A = type { i32, i32 }
+
+define void @_Z12testfunctionR1A(%struct.A* %iter) {
+entry:
+ %0 = getelementptr %struct.A* %iter, i32 0, i32 0 ; <i32*> [#uses=3]
+ %1 = load i32* %0, align 4 ; <i32> [#uses=2]
+ %2 = icmp eq i32 %1, 0 ; <i1> [#uses=1]
+ br i1 %2, label %return, label %bb.nph
+
+bb.nph: ; preds = %entry
+ %3 = getelementptr %struct.A* %iter, i32 0, i32 1 ; <i32*> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb3.backedge, %bb.nph
+ %.rle = phi i32 [ %1, %bb.nph ], [ %7, %bb3.backedge ] ; <i32> [#uses=1]
+ %4 = add i32 %.rle, 1 ; <i32> [#uses=2]
+ store i32 %4, i32* %0, align 4
+ %5 = load i32* %3, align 4 ; <i32> [#uses=1]
+ %6 = icmp eq i32 %4, %5 ; <i1> [#uses=1]
+ br i1 %6, label %bb1, label %bb3.backedge
+
+bb1: ; preds = %bb
+ tail call void @_Z1gv()
+ br label %bb3.backedge
+
+bb3.backedge: ; preds = %bb, %bb1
+; CHECK: bb3.backedge:
+; CHECK-NEXT: phi
+; CHECK-NEXT: icmp
+ %7 = load i32* %0, align 4 ; <i32> [#uses=2]
+ %8 = icmp eq i32 %7, 0 ; <i1> [#uses=1]
+ br i1 %8, label %return, label %bb
+
+return: ; preds = %bb3.backedge, %entry
+ ret void
+}
+
+declare void @_Z1gv()
diff --git a/src/LLVM/test/Transforms/GVN/non-local-offset.ll b/src/LLVM/test/Transforms/GVN/non-local-offset.ll
new file mode 100644
index 0000000..8eaa999
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/non-local-offset.ll
@@ -0,0 +1,59 @@
+; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+; GVN should ignore the store to p[1] to see that the load from p[0] is
+; fully redundant.
+
+; CHECK: @yes
+; CHECK: if.then:
+; CHECK-NEXT: store i32 0, i32* %q
+; CHECK-NEXT: ret void
+
+define void @yes(i1 %c, i32* %p, i32* %q) nounwind {
+entry:
+ store i32 0, i32* %p
+ %p1 = getelementptr inbounds i32* %p, i64 1
+ store i32 1, i32* %p1
+ br i1 %c, label %if.else, label %if.then
+
+if.then:
+ %t = load i32* %p
+ store i32 %t, i32* %q
+ ret void
+
+if.else:
+ ret void
+}
+
+; GVN should ignore the store to p[1] to see that the first load from p[0] is
+; fully redundant. However, the second load is larger, so it's not a simple
+; redundancy.
+
+; CHECK: @watch_out_for_size_change
+; CHECK: if.then:
+; CHECK-NEXT: store i32 0, i32* %q
+; CHECK-NEXT: ret void
+; CHECK: if.else:
+; CHECK: load i64* %pc
+; CHECK: store i64
+
+define void @watch_out_for_size_change(i1 %c, i32* %p, i32* %q) nounwind {
+entry:
+ store i32 0, i32* %p
+ %p1 = getelementptr inbounds i32* %p, i64 1
+ store i32 1, i32* %p1
+ br i1 %c, label %if.else, label %if.then
+
+if.then:
+ %t = load i32* %p
+ store i32 %t, i32* %q
+ ret void
+
+if.else:
+ %pc = bitcast i32* %p to i64*
+ %qc = bitcast i32* %q to i64*
+ %t64 = load i64* %pc
+ store i64 %t64, i64* %qc
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/nonescaping-malloc.ll b/src/LLVM/test/Transforms/GVN/nonescaping-malloc.ll
new file mode 100644
index 0000000..dba9d81
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/nonescaping-malloc.ll
@@ -0,0 +1,108 @@
+; RUN: opt < %s -basicaa -gvn -stats -disable-output |& grep {Number of loads deleted}
+; rdar://7363102
+
+; GVN should be able to eliminate load %tmp22.i, because it is redundant with
+; load %tmp8.i. This requires being able to prove that %tmp7.i doesn't
+; alias the malloc'd value %tmp.i20.i.i, which it can do since %tmp7.i
+; is derived from %tmp5.i which is computed from a load, and %tmp.i20.i.i
+; is never stored and does not escape.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+
+%"struct.llvm::MallocAllocator" = type <{ i8 }>
+%"struct.llvm::StringMap<void*,llvm::MallocAllocator>" = type { %"struct.llvm::StringMapImpl", %"struct.llvm::MallocAllocator" }
+%"struct.llvm::StringMapEntry<void*>" = type { %"struct.llvm::StringMapEntryBase", i8* }
+%"struct.llvm::StringMapEntryBase" = type { i32 }
+%"struct.llvm::StringMapImpl" = type { %"struct.llvm::StringMapImpl::ItemBucket"*, i32, i32, i32, i32 }
+%"struct.llvm::StringMapImpl::ItemBucket" = type { i32, %"struct.llvm::StringMapEntryBase"* }
+%"struct.llvm::StringRef" = type { i8*, i64 }
+
+define %"struct.llvm::StringMapEntry<void*>"* @_Z3fooRN4llvm9StringMapIPvNS_15MallocAllocatorEEEPKc(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %X, i8* %P) ssp {
+entry:
+ %tmp = alloca %"struct.llvm::StringRef", align 8
+ %tmp.i = getelementptr inbounds %"struct.llvm::StringRef"* %tmp, i64 0, i32 0
+ store i8* %P, i8** %tmp.i, align 8
+ %tmp1.i = call i64 @strlen(i8* %P) nounwind readonly
+ %tmp2.i = getelementptr inbounds %"struct.llvm::StringRef"* %tmp, i64 0, i32 1
+ store i64 %tmp1.i, i64* %tmp2.i, align 8
+ %tmp1 = call %"struct.llvm::StringMapEntry<void*>"* @_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueERKNS_9StringRefE(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %X, %"struct.llvm::StringRef"* %tmp) ssp
+ ret %"struct.llvm::StringMapEntry<void*>"* %tmp1
+}
+
+declare i64 @strlen(i8* nocapture) nounwind readonly
+
+declare noalias i8* @malloc(i64) nounwind
+
+declare i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"*, i64, i64)
+
+define linkonce_odr %"struct.llvm::StringMapEntry<void*>"* @_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueERKNS_9StringRefE(%"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, %"struct.llvm::StringRef"* nocapture %Key) ssp align 2 {
+entry:
+ %elt = bitcast %"struct.llvm::StringRef"* %Key to i64*
+ %val = load i64* %elt
+ %tmp = getelementptr inbounds %"struct.llvm::StringRef"* %Key, i64 0, i32 1
+ %val2 = load i64* %tmp
+ %tmp2.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0
+ %tmp3.i = tail call i32 @_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefE(%"struct.llvm::StringMapImpl"* %tmp2.i, i64 %val, i64 %val2)
+ %tmp4.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0, i32 0
+ %tmp5.i = load %"struct.llvm::StringMapImpl::ItemBucket"** %tmp4.i, align 8
+ %tmp6.i = zext i32 %tmp3.i to i64
+ %tmp7.i = getelementptr inbounds %"struct.llvm::StringMapImpl::ItemBucket"* %tmp5.i, i64 %tmp6.i, i32 1
+ %tmp8.i = load %"struct.llvm::StringMapEntryBase"** %tmp7.i, align 8
+ %tmp9.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp8.i, null
+ %tmp13.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp8.i, inttoptr (i64 -1 to %"struct.llvm::StringMapEntryBase"*)
+ %or.cond.i = or i1 %tmp9.i, %tmp13.i
+ br i1 %or.cond.i, label %bb4.i, label %bb6.i
+
+bb4.i: ; preds = %entry
+ %tmp41.i = inttoptr i64 %val to i8*
+ %tmp4.i35.i = getelementptr inbounds i8* %tmp41.i, i64 %val2
+ %tmp.i.i = ptrtoint i8* %tmp4.i35.i to i64
+ %tmp1.i.i = trunc i64 %tmp.i.i to i32
+ %tmp3.i.i = trunc i64 %val to i32
+ %tmp4.i.i = sub i32 %tmp1.i.i, %tmp3.i.i
+ %tmp5.i.i = add i32 %tmp4.i.i, 17
+ %tmp8.i.i = zext i32 %tmp5.i.i to i64
+ %tmp.i20.i.i = tail call noalias i8* @malloc(i64 %tmp8.i.i) nounwind
+ %tmp10.i.i = bitcast i8* %tmp.i20.i.i to %"struct.llvm::StringMapEntry<void*>"*
+ %tmp12.i.i = icmp eq i8* %tmp.i20.i.i, null
+ br i1 %tmp12.i.i, label %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i, label %bb.i.i
+
+bb.i.i: ; preds = %bb4.i
+ %tmp.i.i.i.i = bitcast i8* %tmp.i20.i.i to i32*
+ store i32 %tmp4.i.i, i32* %tmp.i.i.i.i, align 4
+ %tmp1.i19.i.i = getelementptr inbounds i8* %tmp.i20.i.i, i64 8
+ %0 = bitcast i8* %tmp1.i19.i.i to i8**
+ store i8* null, i8** %0, align 8
+ br label %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
+
+_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i: ; preds = %bb.i.i, %bb4.i
+ %tmp.i18.i.i = getelementptr inbounds i8* %tmp.i20.i.i, i64 16
+ %tmp15.i.i = zext i32 %tmp4.i.i to i64
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp.i18.i.i, i8* %tmp41.i, i64 %tmp15.i.i, i32 1, i1 false)
+ %tmp.i18.sum.i.i = add i64 %tmp15.i.i, 16
+ %tmp17.i.i = getelementptr inbounds i8* %tmp.i20.i.i, i64 %tmp.i18.sum.i.i
+ store i8 0, i8* %tmp17.i.i, align 1
+ %tmp.i.i.i = getelementptr inbounds i8* %tmp.i20.i.i, i64 8
+ %1 = bitcast i8* %tmp.i.i.i to i8**
+ store i8* null, i8** %1, align 8
+ %tmp22.i = load %"struct.llvm::StringMapEntryBase"** %tmp7.i, align 8
+ %tmp24.i = icmp eq %"struct.llvm::StringMapEntryBase"* %tmp22.i, inttoptr (i64 -1 to %"struct.llvm::StringMapEntryBase"*)
+ br i1 %tmp24.i, label %bb9.i, label %_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueIS1_EERNS_14StringMapEntryIS1_EENS_9StringRefET_.exit
+
+bb6.i: ; preds = %entry
+ %tmp16.i = bitcast %"struct.llvm::StringMapEntryBase"* %tmp8.i to %"struct.llvm::StringMapEntry<void*>"*
+ ret %"struct.llvm::StringMapEntry<void*>"* %tmp16.i
+
+bb9.i: ; preds = %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
+ %tmp25.i = getelementptr inbounds %"struct.llvm::StringMap<void*,llvm::MallocAllocator>"* %this, i64 0, i32 0, i32 3
+ %tmp26.i = load i32* %tmp25.i, align 8
+ %tmp27.i = add i32 %tmp26.i, -1
+ store i32 %tmp27.i, i32* %tmp25.i, align 8
+ ret %"struct.llvm::StringMapEntry<void*>"* %tmp10.i.i
+
+_ZN4llvm9StringMapIPvNS_15MallocAllocatorEE16GetOrCreateValueIS1_EERNS_14StringMapEntryIS1_EENS_9StringRefET_.exit: ; preds = %_ZN4llvm14StringMapEntryIPvE6CreateINS_15MallocAllocatorES1_EEPS2_PKcS7_RT_T0_.exit.i
+ ret %"struct.llvm::StringMapEntry<void*>"* %tmp10.i.i
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/GVN/null-aliases-nothing.ll b/src/LLVM/test/Transforms/GVN/null-aliases-nothing.ll
new file mode 100644
index 0000000..9e4ae18
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/null-aliases-nothing.ll
@@ -0,0 +1,20 @@
+; RUN: opt %s -basicaa -gvn -S | FileCheck %s
+
+%t = type { i32 }
+declare void @test1f(i8*)
+
+define void @test1(%t* noalias %stuff ) {
+ %p = getelementptr inbounds %t* %stuff, i32 0, i32 0
+ %before = load i32* %p
+
+ call void @test1f(i8* null)
+
+ %after = load i32* %p ; <--- This should be a dead load
+ %sum = add i32 %before, %after
+
+ store i32 %sum, i32* %p
+ ret void
+; CHECK: load
+; CHECK-NOT: load
+; CHECK: ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/phi-translate-partial-alias.ll b/src/LLVM/test/Transforms/GVN/phi-translate-partial-alias.ll
new file mode 100644
index 0000000..47bec41
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/phi-translate-partial-alias.ll
@@ -0,0 +1,27 @@
+; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-f128:128:128-n8:16:32:64"
+
+; GVN shouldn't PRE the load around the loop backedge because it's
+; not actually redundant around the loop backedge, despite appearances
+; if phi-translation is ignored.
+
+; CHECK: define void @test0(i8* %begin)
+; CHECK: loop:
+; CHECK: %l0 = load i8* %phi
+; CHECK: call void @bar(i8 %l0)
+; CHECK: %l1 = load i8* %phi
+define void @test0(i8* %begin) {
+entry:
+ br label %loop
+
+loop:
+ %phi = phi i8* [ %begin, %entry ], [ %next, %loop ]
+ %l0 = load i8* %phi
+ call void @bar(i8 %l0)
+ %l1 = load i8* %phi
+ %next = getelementptr inbounds i8* %phi, i8 %l1
+ br label %loop
+}
+
+declare void @bar(i8)
diff --git a/src/LLVM/test/Transforms/GVN/phi-translate.ll b/src/LLVM/test/Transforms/GVN/phi-translate.ll
new file mode 100644
index 0000000..fa91d29
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/phi-translate.ll
@@ -0,0 +1,31 @@
+; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+; CHECK: @foo
+; CHECK: entry.end_crit_edge:
+; CHECK: %n.pre = load i32* %q.phi.trans.insert
+; CHECK: then:
+; CHECK: store i32 %z
+; CHECK: end:
+; CHECK: %n = phi i32 [ %n.pre, %entry.end_crit_edge ], [ %z, %then ]
+; CHECK: ret i32 %n
+
+@G = external global [100 x i32]
+define i32 @foo(i32 %x, i32 %z) {
+entry:
+ %tobool = icmp eq i32 %z, 0
+ br i1 %tobool, label %end, label %then
+
+then:
+ %i = sext i32 %x to i64
+ %p = getelementptr [100 x i32]* @G, i64 0, i64 %i
+ store i32 %z, i32* %p
+ br label %end
+
+end:
+ %j = sext i32 %x to i64
+ %q = getelementptr [100 x i32]* @G, i64 0, i64 %j
+ %n = load i32* %q
+ ret i32 %n
+}
diff --git a/src/LLVM/test/Transforms/GVN/pr10820.ll b/src/LLVM/test/Transforms/GVN/pr10820.ll
new file mode 100644
index 0000000..12c1e70
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/pr10820.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+target datalayout =
+"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-f128:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+@g = external global i31
+
+define void @main() nounwind uwtable {
+entry:
+; CHECK: store i32
+ store i32 402662078, i32* bitcast (i31* @g to i32*), align 8
+; CHECK-NOT: load i31
+ %0 = load i31* @g, align 8
+; CHECK: store i31
+ store i31 %0, i31* undef, align 1
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/GVN/pre-basic-add.ll b/src/LLVM/test/Transforms/GVN/pre-basic-add.ll
new file mode 100644
index 0000000..c13099f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/pre-basic-add.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -gvn -enable-pre -S | grep {.pre}
+
+@H = common global i32 0 ; <i32*> [#uses=2]
+@G = common global i32 0 ; <i32*> [#uses=1]
+
+define i32 @test() nounwind {
+entry:
+ %0 = load i32* @H, align 4 ; <i32> [#uses=2]
+ %1 = call i32 (...)* @foo() nounwind ; <i32> [#uses=1]
+ %2 = icmp ne i32 %1, 0 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %bb1
+
+bb: ; preds = %entry
+ %3 = add i32 %0, 42 ; <i32> [#uses=1]
+ store i32 %3, i32* @G, align 4
+ br label %bb1
+
+bb1: ; preds = %bb, %entry
+ %4 = add i32 %0, 42 ; <i32> [#uses=1]
+ store i32 %4, i32* @H, align 4
+ br label %return
+
+return: ; preds = %bb1
+ ret i32 0
+}
+
+declare i32 @foo(...)
diff --git a/src/LLVM/test/Transforms/GVN/pre-load.ll b/src/LLVM/test/Transforms/GVN/pre-load.ll
new file mode 100644
index 0000000..bf4add4
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/pre-load.ll
@@ -0,0 +1,391 @@
+; RUN: opt < %s -basicaa -gvn -enable-load-pre -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+define i32 @test1(i32* %p, i1 %C) {
+; CHECK: @test1
+block1:
+ br i1 %C, label %block2, label %block3
+
+block2:
+ br label %block4
+; CHECK: block2:
+; CHECK-NEXT: load i32* %p
+
+block3:
+ store i32 0, i32* %p
+ br label %block4
+
+block4:
+ %PRE = load i32* %p
+ ret i32 %PRE
+; CHECK: block4:
+; CHECK-NEXT: phi i32
+; CHECK-NEXT: ret i32
+}
+
+; This is a simple phi translation case.
+define i32 @test2(i32* %p, i32* %q, i1 %C) {
+; CHECK: @test2
+block1:
+ br i1 %C, label %block2, label %block3
+
+block2:
+ br label %block4
+; CHECK: block2:
+; CHECK-NEXT: load i32* %q
+
+block3:
+ store i32 0, i32* %p
+ br label %block4
+
+block4:
+ %P2 = phi i32* [%p, %block3], [%q, %block2]
+ %PRE = load i32* %P2
+ ret i32 %PRE
+; CHECK: block4:
+; CHECK-NEXT: phi i32 [
+; CHECK-NOT: load
+; CHECK: ret i32
+}
+
+; This is a PRE case that requires phi translation through a GEP.
+define i32 @test3(i32* %p, i32* %q, i32** %Hack, i1 %C) {
+; CHECK: @test3
+block1:
+ %B = getelementptr i32* %q, i32 1
+ store i32* %B, i32** %Hack
+ br i1 %C, label %block2, label %block3
+
+block2:
+ br label %block4
+; CHECK: block2:
+; CHECK-NEXT: load i32* %B
+
+block3:
+ %A = getelementptr i32* %p, i32 1
+ store i32 0, i32* %A
+ br label %block4
+
+block4:
+ %P2 = phi i32* [%p, %block3], [%q, %block2]
+ %P3 = getelementptr i32* %P2, i32 1
+ %PRE = load i32* %P3
+ ret i32 %PRE
+; CHECK: block4:
+; CHECK-NEXT: phi i32 [
+; CHECK-NOT: load
+; CHECK: ret i32
+}
+
+;; Here the loaded address is available, but the computation is in 'block3'
+;; which does not dominate 'block2'.
+define i32 @test4(i32* %p, i32* %q, i32** %Hack, i1 %C) {
+; CHECK: @test4
+block1:
+ br i1 %C, label %block2, label %block3
+
+block2:
+ br label %block4
+; CHECK: block2:
+; CHECK: load i32*
+; CHECK: br label %block4
+
+block3:
+ %B = getelementptr i32* %q, i32 1
+ store i32* %B, i32** %Hack
+
+ %A = getelementptr i32* %p, i32 1
+ store i32 0, i32* %A
+ br label %block4
+
+block4:
+ %P2 = phi i32* [%p, %block3], [%q, %block2]
+ %P3 = getelementptr i32* %P2, i32 1
+ %PRE = load i32* %P3
+ ret i32 %PRE
+; CHECK: block4:
+; CHECK-NEXT: phi i32 [
+; CHECK-NOT: load
+; CHECK: ret i32
+}
+
+;void test5(int N, double *G) {
+; int j;
+; for (j = 0; j < N - 1; j++)
+; G[j] = G[j] + G[j+1];
+;}
+
+define void @test5(i32 %N, double* nocapture %G) nounwind ssp {
+; CHECK: @test5
+entry:
+ %0 = add i32 %N, -1
+ %1 = icmp sgt i32 %0, 0
+ br i1 %1, label %bb.nph, label %return
+
+bb.nph:
+ %tmp = zext i32 %0 to i64
+ br label %bb
+
+; CHECK: bb.nph:
+; CHECK: load double*
+; CHECK: br label %bb
+
+bb:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
+ %tmp6 = add i64 %indvar, 1
+ %scevgep = getelementptr double* %G, i64 %tmp6
+ %scevgep7 = getelementptr double* %G, i64 %indvar
+ %2 = load double* %scevgep7, align 8
+ %3 = load double* %scevgep, align 8
+ %4 = fadd double %2, %3
+ store double %4, double* %scevgep7, align 8
+ %exitcond = icmp eq i64 %tmp6, %tmp
+ br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+ ret void
+}
+
+;void test6(int N, double *G) {
+; int j;
+; for (j = 0; j < N - 1; j++)
+; G[j+1] = G[j] + G[j+1];
+;}
+
+define void @test6(i32 %N, double* nocapture %G) nounwind ssp {
+; CHECK: @test6
+entry:
+ %0 = add i32 %N, -1
+ %1 = icmp sgt i32 %0, 0
+ br i1 %1, label %bb.nph, label %return
+
+bb.nph:
+ %tmp = zext i32 %0 to i64
+ br label %bb
+
+; CHECK: bb.nph:
+; CHECK: load double*
+; CHECK: br label %bb
+
+bb:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp6, %bb ]
+ %tmp6 = add i64 %indvar, 1
+ %scevgep = getelementptr double* %G, i64 %tmp6
+ %scevgep7 = getelementptr double* %G, i64 %indvar
+ %2 = load double* %scevgep7, align 8
+ %3 = load double* %scevgep, align 8
+ %4 = fadd double %2, %3
+ store double %4, double* %scevgep, align 8
+ %exitcond = icmp eq i64 %tmp6, %tmp
+ br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+ ret void
+}
+
+;void test7(int N, double* G) {
+; long j;
+; G[1] = 1;
+; for (j = 1; j < N - 1; j++)
+; G[j+1] = G[j] + G[j+1];
+;}
+
+; This requires phi translation of the adds.
+define void @test7(i32 %N, double* nocapture %G) nounwind ssp {
+entry:
+ %0 = getelementptr inbounds double* %G, i64 1
+ store double 1.000000e+00, double* %0, align 8
+ %1 = add i32 %N, -1
+ %2 = icmp sgt i32 %1, 1
+ br i1 %2, label %bb.nph, label %return
+
+bb.nph:
+ %tmp = sext i32 %1 to i64
+ %tmp7 = add i64 %tmp, -1
+ br label %bb
+
+bb:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
+ %tmp8 = add i64 %indvar, 2
+ %scevgep = getelementptr double* %G, i64 %tmp8
+ %tmp9 = add i64 %indvar, 1
+ %scevgep10 = getelementptr double* %G, i64 %tmp9
+ %3 = load double* %scevgep10, align 8
+ %4 = load double* %scevgep, align 8
+ %5 = fadd double %3, %4
+ store double %5, double* %scevgep, align 8
+ %exitcond = icmp eq i64 %tmp9, %tmp7
+ br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+ ret void
+}
+
+;; Here the loaded address isn't available in 'block2' at all, requiring a new
+;; GEP to be inserted into it.
+define i32 @test8(i32* %p, i32* %q, i32** %Hack, i1 %C) {
+; CHECK: @test8
+block1:
+ br i1 %C, label %block2, label %block3
+
+block2:
+ br label %block4
+; CHECK: block2:
+; CHECK: load i32*
+; CHECK: br label %block4
+
+block3:
+ %A = getelementptr i32* %p, i32 1
+ store i32 0, i32* %A
+ br label %block4
+
+block4:
+ %P2 = phi i32* [%p, %block3], [%q, %block2]
+ %P3 = getelementptr i32* %P2, i32 1
+ %PRE = load i32* %P3
+ ret i32 %PRE
+; CHECK: block4:
+; CHECK-NEXT: phi i32 [
+; CHECK-NOT: load
+; CHECK: ret i32
+}
+
+;void test9(int N, double* G) {
+; long j;
+; for (j = 1; j < N - 1; j++)
+; G[j+1] = G[j] + G[j+1];
+;}
+
+; This requires phi translation of the adds.
+define void @test9(i32 %N, double* nocapture %G) nounwind ssp {
+entry:
+ add i32 0, 0
+ %1 = add i32 %N, -1
+ %2 = icmp sgt i32 %1, 1
+ br i1 %2, label %bb.nph, label %return
+
+bb.nph:
+ %tmp = sext i32 %1 to i64
+ %tmp7 = add i64 %tmp, -1
+ br label %bb
+
+; CHECK: bb.nph:
+; CHECK: load double*
+; CHECK: br label %bb
+
+bb:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp9, %bb ]
+ %tmp8 = add i64 %indvar, 2
+ %scevgep = getelementptr double* %G, i64 %tmp8
+ %tmp9 = add i64 %indvar, 1
+ %scevgep10 = getelementptr double* %G, i64 %tmp9
+ %3 = load double* %scevgep10, align 8
+ %4 = load double* %scevgep, align 8
+ %5 = fadd double %3, %4
+ store double %5, double* %scevgep, align 8
+ %exitcond = icmp eq i64 %tmp9, %tmp7
+ br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+ ret void
+}
+
+;void test10(int N, double* G) {
+; long j;
+; for (j = 1; j < N - 1; j++)
+; G[j] = G[j] + G[j+1] + G[j-1];
+;}
+
+; PR5501
+define void @test10(i32 %N, double* nocapture %G) nounwind ssp {
+entry:
+ %0 = add i32 %N, -1
+ %1 = icmp sgt i32 %0, 1
+ br i1 %1, label %bb.nph, label %return
+
+bb.nph:
+ %tmp = sext i32 %0 to i64
+ %tmp8 = add i64 %tmp, -1
+ br label %bb
+; CHECK: bb.nph:
+; CHECK: load double*
+; CHECK: load double*
+; CHECK: br label %bb
+
+
+bb:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp11, %bb ]
+ %scevgep = getelementptr double* %G, i64 %indvar
+ %tmp9 = add i64 %indvar, 2
+ %scevgep10 = getelementptr double* %G, i64 %tmp9
+ %tmp11 = add i64 %indvar, 1
+ %scevgep12 = getelementptr double* %G, i64 %tmp11
+ %2 = load double* %scevgep12, align 8
+ %3 = load double* %scevgep10, align 8
+ %4 = fadd double %2, %3
+ %5 = load double* %scevgep, align 8
+ %6 = fadd double %4, %5
+ store double %6, double* %scevgep12, align 8
+ %exitcond = icmp eq i64 %tmp11, %tmp8
+ br i1 %exitcond, label %return, label %bb
+
+; Should only be one load in the loop.
+; CHECK: bb:
+; CHECK: load double*
+; CHECK-NOT: load double*
+; CHECK: br i1 %exitcond
+
+return:
+ ret void
+}
+
+; Test critical edge splitting.
+define i32 @test11(i32* %p, i1 %C, i32 %N) {
+; CHECK: @test11
+block1:
+ br i1 %C, label %block2, label %block3
+
+block2:
+ %cond = icmp sgt i32 %N, 1
+ br i1 %cond, label %block4, label %block5
+; CHECK: load i32* %p
+; CHECK-NEXT: br label %block4
+
+block3:
+ store i32 0, i32* %p
+ br label %block4
+
+block4:
+ %PRE = load i32* %p
+ br label %block5
+
+block5:
+ %ret = phi i32 [ 0, %block2 ], [ %PRE, %block4 ]
+ ret i32 %ret
+; CHECK: block4:
+; CHECK-NEXT: phi i32
+}
diff --git a/src/LLVM/test/Transforms/GVN/pre-single-pred.ll b/src/LLVM/test/Transforms/GVN/pre-single-pred.ll
new file mode 100644
index 0000000..f1f5c71
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/pre-single-pred.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -gvn -enable-load-pre -S | FileCheck %s
+; This testcase assumed we'll PRE the load into %for.cond, but we don't actually
+; verify that doing so is safe. If there didn't _happen_ to be a load in
+; %for.end, we would actually be lengthening the execution on some paths, and
+; we were never actually checking that case. Now we actually do perform some
+; conservative checking to make sure we don't make paths longer, but we don't
+; currently get this case, which we got lucky on previously.
+;
+; Now that that faulty assumption is corrected, test that we DON'T incorrectly
+; hoist the load. Doing the right thing for the wrong reasons is still a bug.
+
+@p = external global i32
+define i32 @f(i32 %n) nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %for.inc ] ; <i32> [#uses=2]
+ %cmp = icmp slt i32 %i.0, %n ; <i1> [#uses=1]
+ br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
+
+for.cond.for.end_crit_edge: ; preds = %for.cond
+ br label %for.end
+
+; CHECK: for.body:
+; CHECK-NEXT: %tmp3 = load i32* @p
+for.body: ; preds = %for.cond
+ %tmp3 = load i32* @p ; <i32> [#uses=1]
+ %dec = add i32 %tmp3, -1 ; <i32> [#uses=2]
+ store i32 %dec, i32* @p
+ %cmp6 = icmp slt i32 %dec, 0 ; <i1> [#uses=1]
+ br i1 %cmp6, label %for.body.for.end_crit_edge, label %for.inc
+
+; CHECK: for.body.for.end_crit_edge:
+for.body.for.end_crit_edge: ; preds = %for.body
+ br label %for.end
+
+for.inc: ; preds = %for.body
+ %indvar.next = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %for.cond
+
+for.end: ; preds = %for.body.for.end_crit_edge, %for.cond.for.end_crit_edge
+ %tmp9 = load i32* @p ; <i32> [#uses=1]
+ ret i32 %tmp9
+}
diff --git a/src/LLVM/test/Transforms/GVN/preserve-tbaa.ll b/src/LLVM/test/Transforms/GVN/preserve-tbaa.ll
new file mode 100644
index 0000000..a936755
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/preserve-tbaa.ll
@@ -0,0 +1,30 @@
+; RUN: opt -tbaa -basicaa -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+; GVN should preserve the TBAA tag on loads when doing PRE.
+
+; CHECK: @test
+; CHECK: %tmp33.pre = load i16* %P, align 2, !tbaa !0
+; CHECK: br label %for.body
+define void @test(i16 *%P, i16* %Q) nounwind {
+entry:
+ br i1 undef, label %bb.nph, label %for.end
+
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %for.body, %bb.nph
+ %tmp33 = load i16* %P, align 2, !tbaa !0
+ store i16 %tmp33, i16* %Q
+
+ store i16 0, i16* %P, align 2, !tbaa !0
+ br i1 false, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
+
+!0 = metadata !{metadata !"short", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
diff --git a/src/LLVM/test/Transforms/GVN/rle-must-alias.ll b/src/LLVM/test/Transforms/GVN/rle-must-alias.ll
new file mode 100644
index 0000000..4797240
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle-must-alias.ll
@@ -0,0 +1,46 @@
+; RUN: opt < %s -basicaa -gvn -S | grep {DEAD = phi i32 }
+
+; GVN should eliminate the fully redundant %9 GEP which
+; allows DEAD to be removed. This is PR3198.
+
+; The %7 and %4 loads combine to make %DEAD unneeded.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+@H = common global [100 x i32] zeroinitializer, align 32 ; <[100 x i32]*> [#uses=3]
+@G = common global i32 0 ; <i32*> [#uses=2]
+
+define i32 @test(i32 %i) nounwind {
+entry:
+ %0 = tail call i32 (...)* @foo() nounwind ; <i32> [#uses=1]
+ %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
+ br i1 %1, label %bb1, label %bb
+
+bb: ; preds = %entry
+ %2 = tail call i32 (...)* @bar() nounwind ; <i32> [#uses=0]
+ %3 = getelementptr [100 x i32]* @H, i32 0, i32 %i ; <i32*> [#uses=1]
+ %4 = load i32* %3, align 4 ; <i32> [#uses=1]
+ store i32 %4, i32* @G, align 4
+ br label %bb3
+
+bb1: ; preds = %entry
+ %5 = tail call i32 (...)* @baz() nounwind ; <i32> [#uses=0]
+ %6 = getelementptr [100 x i32]* @H, i32 0, i32 %i ; <i32*> [#uses=1]
+ %7 = load i32* %6, align 4 ; <i32> [#uses=2]
+ store i32 %7, i32* @G, align 4
+ %8 = icmp eq i32 %7, 0 ; <i1> [#uses=1]
+ br i1 %8, label %bb3, label %bb4
+
+bb3: ; preds = %bb1, %bb
+ %9 = getelementptr [100 x i32]* @H, i32 0, i32 %i ; <i32*> [#uses=1]
+ %DEAD = load i32* %9, align 4 ; <i32> [#uses=1]
+ ret i32 %DEAD
+
+bb4: ; preds = %bb1
+ ret i32 0
+}
+
+declare i32 @foo(...)
+
+declare i32 @bar(...)
+
+declare i32 @baz(...)
diff --git a/src/LLVM/test/Transforms/GVN/rle-no-phi-translate.ll b/src/LLVM/test/Transforms/GVN/rle-no-phi-translate.ll
new file mode 100644
index 0000000..96dbf48
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle-no-phi-translate.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -gvn -S | FileCheck %s
+; XFAIL: *
+; FIXME: This should be promotable, but memdep/gvn don't track values
+; path/edge sensitively enough.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i32 @g(i32* %b, i32* %c) nounwind {
+entry:
+ store i32 1, i32* %b
+ store i32 2, i32* %c
+
+ %t1 = icmp eq i32* %b, null ; <i1> [#uses=1]
+ br i1 %t1, label %bb, label %bb2
+
+bb: ; preds = %entry
+ br label %bb2
+
+bb2: ; preds = %bb1, %bb
+ %c_addr.0 = phi i32* [ %b, %entry ], [ %c, %bb ] ; <i32*> [#uses=1]
+ %cv = load i32* %c_addr.0, align 4 ; <i32> [#uses=1]
+ ret i32 %cv
+; CHECK: bb2:
+; CHECK-NOT: load i32
+; CHECK: ret i32
+}
+
diff --git a/src/LLVM/test/Transforms/GVN/rle-nonlocal.ll b/src/LLVM/test/Transforms/GVN/rle-nonlocal.ll
new file mode 100644
index 0000000..6b74e9a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle-nonlocal.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+define i32 @main(i32** %p) {
+block1:
+ br i1 true, label %block2, label %block3
+
+block2:
+ %a = load i32** %p
+ br label %block4
+
+block3:
+ %b = load i32** %p
+ br label %block4
+
+block4:
+; CHECK-NOT: %existingPHI = phi
+; CHECK: %DEAD = phi
+ %existingPHI = phi i32* [ %a, %block2 ], [ %b, %block3 ]
+ %DEAD = load i32** %p
+ %c = load i32* %DEAD
+ %d = load i32* %existingPHI
+ %e = add i32 %c, %d
+ ret i32 %e
+}
diff --git a/src/LLVM/test/Transforms/GVN/rle-phi-translate.ll b/src/LLVM/test/Transforms/GVN/rle-phi-translate.ll
new file mode 100644
index 0000000..6731f43
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle-phi-translate.ll
@@ -0,0 +1,146 @@
+; RUN: opt < %s -gvn -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i32 @test1(i32* %b, i32* %c) nounwind {
+; CHECK: @test1
+entry:
+ %g = alloca i32
+ %t1 = icmp eq i32* %b, null
+ br i1 %t1, label %bb, label %bb1
+
+bb:
+ %t2 = load i32* %c, align 4
+ %t3 = add i32 %t2, 1
+ store i32 %t3, i32* %g, align 4
+ br label %bb2
+
+bb1: ; preds = %entry
+ %t5 = load i32* %b, align 4
+ %t6 = add i32 %t5, 1
+ store i32 %t6, i32* %g, align 4
+ br label %bb2
+
+bb2: ; preds = %bb1, %bb
+ %c_addr.0 = phi i32* [ %g, %bb1 ], [ %c, %bb ]
+ %b_addr.0 = phi i32* [ %b, %bb1 ], [ %g, %bb ]
+ %cv = load i32* %c_addr.0, align 4
+ %bv = load i32* %b_addr.0, align 4
+; CHECK: %bv = phi i32
+; CHECK: %cv = phi i32
+; CHECK-NOT: load
+; CHECK: ret i32
+ %ret = add i32 %cv, %bv
+ ret i32 %ret
+}
+
+define i8 @test2(i1 %cond, i32* %b, i32* %c) nounwind {
+; CHECK: @test2
+entry:
+ br i1 %cond, label %bb, label %bb1
+
+bb:
+ %b1 = bitcast i32* %b to i8*
+ store i8 4, i8* %b1
+ br label %bb2
+
+bb1:
+ %c1 = bitcast i32* %c to i8*
+ store i8 92, i8* %c1
+ br label %bb2
+
+bb2:
+ %d = phi i32* [ %c, %bb1 ], [ %b, %bb ]
+ %d1 = bitcast i32* %d to i8*
+ %dv = load i8* %d1
+; CHECK: %dv = phi i8 [ 92, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i8 %dv
+ ret i8 %dv
+}
+
+define i32 @test3(i1 %cond, i32* %b, i32* %c) nounwind {
+; CHECK: @test3
+entry:
+ br i1 %cond, label %bb, label %bb1
+
+bb:
+ %b1 = getelementptr i32* %b, i32 17
+ store i32 4, i32* %b1
+ br label %bb2
+
+bb1:
+ %c1 = getelementptr i32* %c, i32 7
+ store i32 82, i32* %c1
+ br label %bb2
+
+bb2:
+ %d = phi i32* [ %c, %bb1 ], [ %b, %bb ]
+ %i = phi i32 [ 7, %bb1 ], [ 17, %bb ]
+ %d1 = getelementptr i32* %d, i32 %i
+ %dv = load i32* %d1
+; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i32 %dv
+ ret i32 %dv
+}
+
+; PR5313
+define i32 @test4(i1 %cond, i32* %b, i32* %c) nounwind {
+; CHECK: @test4
+entry:
+ br i1 %cond, label %bb, label %bb1
+
+bb:
+ store i32 4, i32* %b
+ br label %bb2
+
+bb1:
+ %c1 = getelementptr i32* %c, i32 7
+ store i32 82, i32* %c1
+ br label %bb2
+
+bb2:
+ %d = phi i32* [ %c, %bb1 ], [ %b, %bb ]
+ %i = phi i32 [ 7, %bb1 ], [ 0, %bb ]
+ %d1 = getelementptr i32* %d, i32 %i
+ %dv = load i32* %d1
+; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i32 %dv
+ ret i32 %dv
+}
+
+
+
+; void test5(int N, double* G) {
+; for (long j = 1; j < 1000; j++)
+; G[j] = G[j] + G[j-1];
+; }
+;
+; Should compile into one load in the loop.
+define void @test5(i32 %N, double* nocapture %G) nounwind ssp {
+; CHECK: @test5
+bb.nph:
+ br label %for.body
+
+for.body:
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp, %for.body ]
+ %arrayidx6 = getelementptr double* %G, i64 %indvar
+ %tmp = add i64 %indvar, 1
+ %arrayidx = getelementptr double* %G, i64 %tmp
+ %tmp3 = load double* %arrayidx
+ %tmp7 = load double* %arrayidx6
+ %add = fadd double %tmp3, %tmp7
+ store double %add, double* %arrayidx
+ %exitcond = icmp eq i64 %tmp, 999
+ br i1 %exitcond, label %for.end, label %for.body
+; CHECK: for.body:
+; CHECK: phi double
+; CHECK: load double
+; CHECK-NOT: load double
+; CHECK: br i1
+for.end:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GVN/rle-semidominated.ll b/src/LLVM/test/Transforms/GVN/rle-semidominated.ll
new file mode 100644
index 0000000..c6cd1fd
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle-semidominated.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -basicaa -gvn -S | grep {DEAD = phi i32 }
+
+define i32 @main(i32* %p) {
+block1:
+ %z = load i32* %p
+ br i1 true, label %block2, label %block3
+
+block2:
+ br label %block4
+
+block3:
+ %b = bitcast i32 0 to i32
+ store i32 %b, i32* %p
+ br label %block4
+
+block4:
+ %DEAD = load i32* %p
+ ret i32 %DEAD
+}
diff --git a/src/LLVM/test/Transforms/GVN/rle.ll b/src/LLVM/test/Transforms/GVN/rle.ll
new file mode 100644
index 0000000..2f0d2eb
--- /dev/null
+++ b/src/LLVM/test/Transforms/GVN/rle.ll
@@ -0,0 +1,644 @@
+; RUN: opt < %s -basicaa -gvn -S -die | FileCheck %s
+
+; 32-bit little endian target.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+
+;; Trivial RLE test.
+define i32 @test0(i32 %V, i32* %P) {
+ store i32 %V, i32* %P
+
+ %A = load i32* %P
+ ret i32 %A
+; CHECK: @test0
+; CHECK: ret i32 %V
+}
+
+
+;;===----------------------------------------------------------------------===;;
+;; Tests for crashers
+;;===----------------------------------------------------------------------===;;
+
+;; PR5016
+define i8 @crash0({i32, i32} %A, {i32, i32}* %P) {
+ store {i32, i32} %A, {i32, i32}* %P
+ %X = bitcast {i32, i32}* %P to i8*
+ %Y = load i8* %X
+ ret i8 %Y
+}
+
+
+;;===----------------------------------------------------------------------===;;
+;; Store -> Load and Load -> Load forwarding where src and dst are different
+;; types, but where the base pointer is a must alias.
+;;===----------------------------------------------------------------------===;;
+
+;; i32 -> f32 forwarding.
+define float @coerce_mustalias1(i32 %V, i32* %P) {
+ store i32 %V, i32* %P
+
+ %P2 = bitcast i32* %P to float*
+
+ %A = load float* %P2
+ ret float %A
+; CHECK: @coerce_mustalias1
+; CHECK-NOT: load
+; CHECK: ret float
+}
+
+;; i32* -> float forwarding.
+define float @coerce_mustalias2(i32* %V, i32** %P) {
+ store i32* %V, i32** %P
+
+ %P2 = bitcast i32** %P to float*
+
+ %A = load float* %P2
+ ret float %A
+; CHECK: @coerce_mustalias2
+; CHECK-NOT: load
+; CHECK: ret float
+}
+
+;; float -> i32* forwarding.
+define i32* @coerce_mustalias3(float %V, float* %P) {
+ store float %V, float* %P
+
+ %P2 = bitcast float* %P to i32**
+
+ %A = load i32** %P2
+ ret i32* %A
+; CHECK: @coerce_mustalias3
+; CHECK-NOT: load
+; CHECK: ret i32*
+}
+
+;; i32 -> f32 load forwarding.
+define float @coerce_mustalias4(i32* %P, i1 %cond) {
+ %A = load i32* %P
+
+ %P2 = bitcast i32* %P to float*
+ %B = load float* %P2
+ br i1 %cond, label %T, label %F
+T:
+ ret float %B
+
+F:
+ %X = bitcast i32 %A to float
+ ret float %X
+
+; CHECK: @coerce_mustalias4
+; CHECK: %A = load i32* %P
+; CHECK-NOT: load
+; CHECK: ret float
+; CHECK: F:
+}
+
+;; i32 -> i8 forwarding
+define i8 @coerce_mustalias5(i32 %V, i32* %P) {
+ store i32 %V, i32* %P
+
+ %P2 = bitcast i32* %P to i8*
+
+ %A = load i8* %P2
+ ret i8 %A
+; CHECK: @coerce_mustalias5
+; CHECK-NOT: load
+; CHECK: ret i8
+}
+
+;; i64 -> float forwarding
+define float @coerce_mustalias6(i64 %V, i64* %P) {
+ store i64 %V, i64* %P
+
+ %P2 = bitcast i64* %P to float*
+
+ %A = load float* %P2
+ ret float %A
+; CHECK: @coerce_mustalias6
+; CHECK-NOT: load
+; CHECK: ret float
+}
+
+;; i64 -> i8* (32-bit) forwarding
+define i8* @coerce_mustalias7(i64 %V, i64* %P) {
+ store i64 %V, i64* %P
+
+ %P2 = bitcast i64* %P to i8**
+
+ %A = load i8** %P2
+ ret i8* %A
+; CHECK: @coerce_mustalias7
+; CHECK-NOT: load
+; CHECK: ret i8*
+}
+
+; memset -> i16 forwarding.
+define signext i16 @memset_to_i16_local(i16* %A) nounwind ssp {
+entry:
+ %conv = bitcast i16* %A to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 1, i64 200, i32 1, i1 false)
+ %arrayidx = getelementptr inbounds i16* %A, i64 42
+ %tmp2 = load i16* %arrayidx
+ ret i16 %tmp2
+; CHECK: @memset_to_i16_local
+; CHECK-NOT: load
+; CHECK: ret i16 257
+}
+
+; memset -> float forwarding.
+define float @memset_to_float_local(float* %A, i8 %Val) nounwind ssp {
+entry:
+ %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
+ tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 %Val, i64 400, i32 1, i1 false)
+ %arrayidx = getelementptr inbounds float* %A, i64 42 ; <float*> [#uses=1]
+ %tmp2 = load float* %arrayidx ; <float> [#uses=1]
+ ret float %tmp2
+; CHECK: @memset_to_float_local
+; CHECK-NOT: load
+; CHECK: zext
+; CHECK-NEXT: shl
+; CHECK-NEXT: or
+; CHECK-NEXT: shl
+; CHECK-NEXT: or
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: ret float
+}
+
+;; non-local memset -> i16 load forwarding.
+define i16 @memset_to_i16_nonlocal0(i16* %P, i1 %cond) {
+ %P3 = bitcast i16* %P to i8*
+ br i1 %cond, label %T, label %F
+T:
+ tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 1, i64 400, i32 1, i1 false)
+ br label %Cont
+
+F:
+ tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 2, i64 400, i32 1, i1 false)
+ br label %Cont
+
+Cont:
+ %P2 = getelementptr i16* %P, i32 4
+ %A = load i16* %P2
+ ret i16 %A
+
+; CHECK: @memset_to_i16_nonlocal0
+; CHECK: Cont:
+; CHECK-NEXT: %A = phi i16 [ 514, %F ], [ 257, %T ]
+; CHECK-NOT: load
+; CHECK: ret i16 %A
+}
+
+@GCst = constant {i32, float, i32 } { i32 42, float 14., i32 97 }
+
+; memset -> float forwarding.
+define float @memcpy_to_float_local(float* %A) nounwind ssp {
+entry:
+ %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %conv, i8* bitcast ({i32, float, i32 }* @GCst to i8*), i64 12, i32 1, i1 false)
+ %arrayidx = getelementptr inbounds float* %A, i64 1 ; <float*> [#uses=1]
+ %tmp2 = load float* %arrayidx ; <float> [#uses=1]
+ ret float %tmp2
+; CHECK: @memcpy_to_float_local
+; CHECK-NOT: load
+; CHECK: ret float 1.400000e+01
+}
+
+
+
+;; non-local i32/float -> i8 load forwarding.
+define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
+ %P2 = bitcast i32* %P to float*
+ %P3 = bitcast i32* %P to i8*
+ br i1 %cond, label %T, label %F
+T:
+ store i32 42, i32* %P
+ br label %Cont
+
+F:
+ store float 1.0, float* %P2
+ br label %Cont
+
+Cont:
+ %A = load i8* %P3
+ ret i8 %A
+
+; CHECK: @coerce_mustalias_nonlocal0
+; CHECK: Cont:
+; CHECK: %A = phi i8 [
+; CHECK-NOT: load
+; CHECK: ret i8 %A
+}
+
+
+;; non-local i32/float -> i8 load forwarding. This also tests that the "P3"
+;; bitcast equivalence can be properly phi translated.
+define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
+ %P2 = bitcast i32* %P to float*
+ br i1 %cond, label %T, label %F
+T:
+ store i32 42, i32* %P
+ br label %Cont
+
+F:
+ store float 1.0, float* %P2
+ br label %Cont
+
+Cont:
+ %P3 = bitcast i32* %P to i8*
+ %A = load i8* %P3
+ ret i8 %A
+
+;; FIXME: This is disabled because this caused a miscompile in the llvm-gcc
+;; bootstrap, see r82411
+;
+; HECK: @coerce_mustalias_nonlocal1
+; HECK: Cont:
+; HECK: %A = phi i8 [
+; HECK-NOT: load
+; HECK: ret i8 %A
+}
+
+
+;; non-local i32 -> i8 partial redundancy load forwarding.
+define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
+ %P3 = bitcast i32* %P to i8*
+ br i1 %cond, label %T, label %F
+T:
+ store i32 42, i32* %P
+ br label %Cont
+
+F:
+ br label %Cont
+
+Cont:
+ %A = load i8* %P3
+ ret i8 %A
+
+; CHECK: @coerce_mustalias_pre0
+; CHECK: F:
+; CHECK: load i8* %P3
+; CHECK: Cont:
+; CHECK: %A = phi i8 [
+; CHECK-NOT: load
+; CHECK: ret i8 %A
+}
+
+;;===----------------------------------------------------------------------===;;
+;; Store -> Load and Load -> Load forwarding where src and dst are different
+;; types, and the reload is an offset from the store pointer.
+;;===----------------------------------------------------------------------===;;
+
+;; i32 -> i8 forwarding.
+;; PR4216
+define i8 @coerce_offset0(i32 %V, i32* %P) {
+ store i32 %V, i32* %P
+
+ %P2 = bitcast i32* %P to i8*
+ %P3 = getelementptr i8* %P2, i32 2
+
+ %A = load i8* %P3
+ ret i8 %A
+; CHECK: @coerce_offset0
+; CHECK-NOT: load
+; CHECK: ret i8
+}
+
+;; non-local i32/float -> i8 load forwarding.
+define i8 @coerce_offset_nonlocal0(i32* %P, i1 %cond) {
+ %P2 = bitcast i32* %P to float*
+ %P3 = bitcast i32* %P to i8*
+ %P4 = getelementptr i8* %P3, i32 2
+ br i1 %cond, label %T, label %F
+T:
+ store i32 42, i32* %P
+ br label %Cont
+
+F:
+ store float 1.0, float* %P2
+ br label %Cont
+
+Cont:
+ %A = load i8* %P4
+ ret i8 %A
+
+; CHECK: @coerce_offset_nonlocal0
+; CHECK: Cont:
+; CHECK: %A = phi i8 [
+; CHECK-NOT: load
+; CHECK: ret i8 %A
+}
+
+
+;; non-local i32 -> i8 partial redundancy load forwarding.
+define i8 @coerce_offset_pre0(i32* %P, i1 %cond) {
+ %P3 = bitcast i32* %P to i8*
+ %P4 = getelementptr i8* %P3, i32 2
+ br i1 %cond, label %T, label %F
+T:
+ store i32 42, i32* %P
+ br label %Cont
+
+F:
+ br label %Cont
+
+Cont:
+ %A = load i8* %P4
+ ret i8 %A
+
+; CHECK: @coerce_offset_pre0
+; CHECK: F:
+; CHECK: load i8* %P4
+; CHECK: Cont:
+; CHECK: %A = phi i8 [
+; CHECK-NOT: load
+; CHECK: ret i8 %A
+}
+
+define i32 @chained_load(i32** %p) {
+block1:
+ %A = alloca i32*
+
+ %z = load i32** %p
+ store i32* %z, i32** %A
+ br i1 true, label %block2, label %block3
+
+block2:
+ %a = load i32** %p
+ br label %block4
+
+block3:
+ %b = load i32** %p
+ br label %block4
+
+block4:
+ %c = load i32** %p
+ %d = load i32* %c
+ ret i32 %d
+
+; CHECK: @chained_load
+; CHECK: %z = load i32** %p
+; CHECK-NOT: load
+; CHECK: %d = load i32* %z
+; CHECK-NEXT: ret i32 %d
+}
+
+
+declare i1 @cond() readonly
+declare i1 @cond2() readonly
+
+define i32 @phi_trans2() {
+; CHECK: @phi_trans2
+entry:
+ %P = alloca i32, i32 400
+ br label %F1
+
+F1:
+ %A = phi i32 [1, %entry], [2, %F]
+ %cond2 = call i1 @cond()
+ br i1 %cond2, label %T1, label %TY
+
+T1:
+ %P2 = getelementptr i32* %P, i32 %A
+ %x = load i32* %P2
+ %cond = call i1 @cond2()
+ br i1 %cond, label %TX, label %F
+
+F:
+ %P3 = getelementptr i32* %P, i32 2
+ store i32 17, i32* %P3
+
+ store i32 42, i32* %P2 ; Provides "P[A]".
+ br label %F1
+
+TX:
+ ; This load should not be compiled to 'ret i32 42'. An overly clever
+ ; implementation of GVN would see that we're returning 17 if the loop
+ ; executes once or 42 if it executes more than that, but we'd have to do
+ ; loop restructuring to expose this, and GVN shouldn't do this sort of CFG
+ ; transformation.
+
+; CHECK: TX:
+; CHECK: ret i32 %x
+ ret i32 %x
+TY:
+ ret i32 0
+}
+
+define i32 @phi_trans3(i32* %p) {
+; CHECK: @phi_trans3
+block1:
+ br i1 true, label %block2, label %block3
+
+block2:
+ store i32 87, i32* %p
+ br label %block4
+
+block3:
+ %p2 = getelementptr i32* %p, i32 43
+ store i32 97, i32* %p2
+ br label %block4
+
+block4:
+ %A = phi i32 [-1, %block2], [42, %block3]
+ br i1 true, label %block5, label %exit
+
+; CHECK: block4:
+; CHECK-NEXT: %D = phi i32 [ 87, %block2 ], [ 97, %block3 ]
+; CHECK-NOT: load
+
+block5:
+ %B = add i32 %A, 1
+ br i1 true, label %block6, label %exit
+
+block6:
+ %C = getelementptr i32* %p, i32 %B
+ br i1 true, label %block7, label %exit
+
+block7:
+ %D = load i32* %C
+ ret i32 %D
+
+; CHECK: block7:
+; CHECK-NEXT: ret i32 %D
+
+exit:
+ ret i32 -1
+}
+
+define i8 @phi_trans4(i8* %p) {
+; CHECK: @phi_trans4
+entry:
+ %X3 = getelementptr i8* %p, i32 192
+ store i8 192, i8* %X3
+
+ %X = getelementptr i8* %p, i32 4
+ %Y = load i8* %X
+ br label %loop
+
+loop:
+ %i = phi i32 [4, %entry], [192, %loop]
+ %X2 = getelementptr i8* %p, i32 %i
+ %Y2 = load i8* %X2
+
+; CHECK: loop:
+; CHECK-NEXT: %Y2 = phi i8 [ %Y, %entry ], [ 0, %loop ]
+; CHECK-NOT: load i8
+
+ %cond = call i1 @cond2()
+
+ %Z = bitcast i8 *%X3 to i32*
+ store i32 0, i32* %Z
+ br i1 %cond, label %loop, label %out
+
+out:
+ %R = add i8 %Y, %Y2
+ ret i8 %R
+}
+
+define i8 @phi_trans5(i8* %p) {
+; CHECK: @phi_trans5
+entry:
+
+ %X4 = getelementptr i8* %p, i32 2
+ store i8 19, i8* %X4
+
+ %X = getelementptr i8* %p, i32 4
+ %Y = load i8* %X
+ br label %loop
+
+loop:
+ %i = phi i32 [4, %entry], [3, %cont]
+ %X2 = getelementptr i8* %p, i32 %i
+ %Y2 = load i8* %X2 ; Ensure this load is not being incorrectly replaced.
+ %cond = call i1 @cond2()
+ br i1 %cond, label %cont, label %out
+
+cont:
+ %Z = getelementptr i8* %X2, i32 -1
+ %Z2 = bitcast i8 *%Z to i32*
+ store i32 50462976, i32* %Z2 ;; (1 << 8) | (2 << 16) | (3 << 24)
+
+
+; CHECK: store i32
+; CHECK-NEXT: getelementptr i8* %p, i32 3
+; CHECK-NEXT: load i8*
+ br label %loop
+
+out:
+ %R = add i8 %Y, %Y2
+ ret i8 %R
+}
+
+
+; PR6642
+define i32 @memset_to_load() nounwind readnone {
+entry:
+ %x = alloca [256 x i32], align 4 ; <[256 x i32]*> [#uses=2]
+ %tmp = bitcast [256 x i32]* %x to i8* ; <i8*> [#uses=1]
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 1024, i32 4, i1 false)
+ %arraydecay = getelementptr inbounds [256 x i32]* %x, i32 0, i32 0 ; <i32*>
+ %tmp1 = load i32* %arraydecay ; <i32> [#uses=1]
+ ret i32 %tmp1
+; CHECK: @memset_to_load
+; CHECK: ret i32 0
+}
+
+
+;;===----------------------------------------------------------------------===;;
+;; Load -> Load forwarding in partial alias case.
+;;===----------------------------------------------------------------------===;;
+
+define i32 @load_load_partial_alias(i8* %P) nounwind ssp {
+entry:
+ %0 = bitcast i8* %P to i32*
+ %tmp2 = load i32* %0
+ %add.ptr = getelementptr inbounds i8* %P, i64 1
+ %tmp5 = load i8* %add.ptr
+ %conv = zext i8 %tmp5 to i32
+ %add = add nsw i32 %tmp2, %conv
+ ret i32 %add
+
+; TEMPORARILYDISABLED: @load_load_partial_alias
+; TEMPORARILYDISABLED: load i32*
+; TEMPORARILYDISABLED-NOT: load
+; TEMPORARILYDISABLED: lshr i32 {{.*}}, 8
+; TEMPORARILYDISABLED-NOT: load
+; TEMPORARILYDISABLED: trunc i32 {{.*}} to i8
+; TEMPORARILYDISABLED-NOT: load
+; TEMPORARILYDISABLED: ret i32
+}
+
+
+; Cross block partial alias case.
+define i32 @load_load_partial_alias_cross_block(i8* %P) nounwind ssp {
+entry:
+ %xx = bitcast i8* %P to i32*
+ %x1 = load i32* %xx, align 4
+ %cmp = icmp eq i32 %x1, 127
+ br i1 %cmp, label %land.lhs.true, label %if.end
+
+land.lhs.true: ; preds = %entry
+ %arrayidx4 = getelementptr inbounds i8* %P, i64 1
+ %tmp5 = load i8* %arrayidx4, align 1
+ %conv6 = zext i8 %tmp5 to i32
+ ret i32 %conv6
+
+if.end:
+ ret i32 52
+; TEMPORARILY_DISABLED: @load_load_partial_alias_cross_block
+; TEMPORARILY_DISABLED: land.lhs.true:
+; TEMPORARILY_DISABLED-NOT: load i8
+; TEMPORARILY_DISABLED: ret i32 %conv6
+}
+
+
+;;===----------------------------------------------------------------------===;;
+;; Load Widening
+;;===----------------------------------------------------------------------===;;
+
+%widening1 = type { i32, i8, i8, i8, i8 }
+
+@f = global %widening1 zeroinitializer, align 4
+
+define i32 @test_widening1(i8* %P) nounwind ssp noredzone {
+entry:
+ %tmp = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 1), align 4
+ %conv = zext i8 %tmp to i32
+ %tmp1 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 2), align 1
+ %conv2 = zext i8 %tmp1 to i32
+ %add = add nsw i32 %conv, %conv2
+ ret i32 %add
+; CHECK: @test_widening1
+; CHECK-NOT: load
+; CHECK: load i16*
+; CHECK-NOT: load
+; CHECK-ret i32
+}
+
+define i32 @test_widening2() nounwind ssp noredzone {
+entry:
+ %tmp = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 1), align 4
+ %conv = zext i8 %tmp to i32
+ %tmp1 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 2), align 1
+ %conv2 = zext i8 %tmp1 to i32
+ %add = add nsw i32 %conv, %conv2
+
+ %tmp2 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 3), align 2
+ %conv3 = zext i8 %tmp2 to i32
+ %add2 = add nsw i32 %add, %conv3
+
+ %tmp3 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 4), align 1
+ %conv4 = zext i8 %tmp3 to i32
+ %add3 = add nsw i32 %add2, %conv3
+
+ ret i32 %add3
+; CHECK: @test_widening2
+; CHECK-NOT: load
+; CHECK: load i32*
+; CHECK-NOT: load
+; CHECK-ret i32
+}
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-CastRef.ll b/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-CastRef.ll
new file mode 100644
index 0000000..355311f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-CastRef.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -globaldce
+;
+define internal void @func() {
+ ret void
+}
+
+define void @main() {
+ %X = bitcast void ()* @func to i32* ; <i32*> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-ConstantRef.ll b/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-ConstantRef.ll
new file mode 100644
index 0000000..15b68c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2002-07-17-ConstantRef.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -globaldce
+;
+
+@X = global void ()* @func ; <void ()**> [#uses=0]
+
+; Not dead, can be reachable via X
+define internal void @func() {
+ ret void
+}
+
+define void @main() {
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-FunctionDGE.ll b/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-FunctionDGE.ll
new file mode 100644
index 0000000..c5a21a2
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-FunctionDGE.ll
@@ -0,0 +1,17 @@
+; Make sure that functions are removed successfully if they are referred to by
+; a global that is dead. Make sure any globals they refer to die as well.
+
+; RUN: opt < %s -globaldce -S | not grep foo
+
+;; Unused, kills %foo
+@b = internal global i32 ()* @foo ; <i32 ()**> [#uses=0]
+
+;; Should die when function %foo is killed
+@foo.upgrd.1 = internal global i32 7 ; <i32*> [#uses=1]
+
+ ;; dies when %b dies.
+define internal i32 @foo() {
+ %ret = load i32* @foo.upgrd.1 ; <i32> [#uses=1]
+ ret i32 %ret
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-WorkListTest.ll b/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-WorkListTest.ll
new file mode 100644
index 0000000..a6077d6
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2002-08-17-WorkListTest.ll
@@ -0,0 +1,12 @@
+; This testcase tests that a worklist is being used, and that globals can be
+; removed if they are the subject of a constexpr and ConstantPointerRef
+
+; RUN: opt < %s -globaldce -S | not grep global
+
+@t0 = internal global [4 x i8] c"foo\00" ; <[4 x i8]*> [#uses=1]
+@t1 = internal global [4 x i8] c"bar\00" ; <[4 x i8]*> [#uses=1]
+@s1 = internal global [1 x i8*] [ i8* getelementptr ([4 x i8]* @t0, i32 0, i32 0) ] ; <[1 x i8*]*> [#uses=0]
+@s2 = internal global [1 x i8*] [ i8* getelementptr ([4 x i8]* @t1, i64 0, i64 0) ] ; <[1 x i8*]*> [#uses=0]
+@b = internal global i32* @a ; <i32**> [#uses=0]
+@a = internal global i32 7 ; <i32*> [#uses=1]
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2002-09-12-Redeletion.ll b/src/LLVM/test/Transforms/GlobalDCE/2002-09-12-Redeletion.ll
new file mode 100644
index 0000000..bcff152
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2002-09-12-Redeletion.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -globaldce
+
+;; Should die when function %foo is killed
+@foo.upgrd.1 = internal global i32 7 ; <i32*> [#uses=3]
+@bar = internal global [2 x { i32*, i32 }] [ { i32*, i32 } { i32* @foo.upgrd.1, i32 7 }, { i32*, i32 } { i32* @foo.upgrd.1, i32 1 } ] ; <[2 x { i32*, i32 }]*> [#uses=0]
+
+define internal i32 @foo() {
+ %ret = load i32* @foo.upgrd.1 ; <i32> [#uses=1]
+ ret i32 %ret
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2003-07-01-SelfReference.ll b/src/LLVM/test/Transforms/GlobalDCE/2003-07-01-SelfReference.ll
new file mode 100644
index 0000000..99d590a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2003-07-01-SelfReference.ll
@@ -0,0 +1,11 @@
+; distilled from 255.vortex
+; RUN: opt < %s -globaldce -S | not grep testfunc
+
+declare i1 ()* @getfunc()
+
+define internal i1 @testfunc() {
+ %F = call i1 ()* ()* @getfunc( ) ; <i1 ()*> [#uses=1]
+ %c = icmp eq i1 ()* %F, @testfunc ; <i1> [#uses=1]
+ ret i1 %c
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2003-10-09-PreserveWeakGlobals.ll b/src/LLVM/test/Transforms/GlobalDCE/2003-10-09-PreserveWeakGlobals.ll
new file mode 100644
index 0000000..837949e
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2003-10-09-PreserveWeakGlobals.ll
@@ -0,0 +1,6 @@
+; Weak variables should be preserved by global DCE!
+
+; RUN: opt < %s -globaldce -S | grep @A
+
+
+@A = weak global i32 54
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll b/src/LLVM/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll
new file mode 100644
index 0000000..6658cee
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2009-01-05-DeadAliases.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -globaldce -S | not grep @D
+; RUN: opt < %s -globaldce -S | grep @L | count 3
+
+@A = global i32 0
+@D = alias internal i32* @A
+@L1 = alias i32* @A
+@L2 = alias internal i32* @L1
+@L3 = alias i32* @L2
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll b/src/LLVM/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll
new file mode 100644
index 0000000..68933c6
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll
@@ -0,0 +1,4 @@
+; RUN: opt < %s -globaldce
+
+@A = alias internal void ()* @F
+define internal void @F() { ret void }
diff --git a/src/LLVM/test/Transforms/GlobalDCE/2009-09-03-MDNode.ll b/src/LLVM/test/Transforms/GlobalDCE/2009-09-03-MDNode.ll
new file mode 100644
index 0000000..29864f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/2009-09-03-MDNode.ll
@@ -0,0 +1,264 @@
+; RUN: opt < %s -globaldce | llc -O0 -o /dev/null
+
+%struct..0__pthread_mutex_s = type { i32, i32, i32, i32, i32, i32, %struct.__pthread_list_t }
+%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>" = type { i32 }
+%struct.__pthread_list_t = type { %struct.__pthread_list_t*, %struct.__pthread_list_t* }
+%struct.pthread_attr_t = type { i64, [48 x i8] }
+%struct.pthread_mutex_t = type { %struct..0__pthread_mutex_s }
+
+@_ZL20__gthrw_pthread_oncePiPFvvE = alias weak i32 (i32*, void ()*)* @pthread_once ; <i32 (i32*, void ()*)*> [#uses=0]
+@_ZL27__gthrw_pthread_getspecificj = alias weak i8* (i32)* @pthread_getspecific ; <i8* (i32)*> [#uses=0]
+@_ZL27__gthrw_pthread_setspecificjPKv = alias weak i32 (i32, i8*)* @pthread_setspecific ; <i32 (i32, i8*)*> [#uses=0]
+@_ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_ = alias weak i32 (i64*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)* @pthread_create ; <i32 (i64*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)*> [#uses=0]
+@_ZL22__gthrw_pthread_cancelm = alias weak i32 (i64)* @pthread_cancel ; <i32 (i64)*> [#uses=0]
+@_ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_lock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_trylock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t = alias weak i32 (%struct.pthread_mutex_t*)* @pthread_mutex_unlock ; <i32 (%struct.pthread_mutex_t*)*> [#uses=0]
+@_ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t = alias weak i32 (%struct.pthread_mutex_t*, %"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)* @pthread_mutex_init ; <i32 (%struct.pthread_mutex_t*, %"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)*> [#uses=0]
+@_ZL26__gthrw_pthread_key_createPjPFvPvE = alias weak i32 (i32*, void (i8*)*)* @pthread_key_create ; <i32 (i32*, void (i8*)*)*> [#uses=0]
+@_ZL26__gthrw_pthread_key_deletej = alias weak i32 (i32)* @pthread_key_delete ; <i32 (i32)*> [#uses=0]
+@_ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t = alias weak i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)* @pthread_mutexattr_init ; <i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)*> [#uses=0]
+@_ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = alias weak i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*, i32)* @pthread_mutexattr_settype ; <i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*, i32)*> [#uses=0]
+@_ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = alias weak i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)* @pthread_mutexattr_destroy ; <i32 (%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)*> [#uses=0]
+
+define weak void @_ZN9__gnu_cxx26__aux_require_boolean_exprIbEEvRKT_(i8* %__t) {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !0)
+ tail call void @llvm.dbg.stoppoint(i32 240, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !0)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_19_ConvertibleConceptIjjEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !8)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !8)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !11)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !11)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPKcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !12)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !12)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !13)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !13)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPKwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !14)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !14)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIPwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !15)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !15)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIPcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !16)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !16)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIiEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !17)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !17)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIlEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !18)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !18)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIxEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !19)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !19)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIjEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !20)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !20)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_22_OutputIteratorConceptISt19ostreambuf_iteratorIcSt11char_traitsIcEEcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !21)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !21)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_22_OutputIteratorConceptISt19ostreambuf_iteratorIwSt11char_traitsIwEEwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !22)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !22)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !23)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !23)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPKcEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !24)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !24)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPKcSsEEEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !25)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !25)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPcSsEEEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !26)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !26)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPKwSbIwSt11char_traitsIwESaIwEEEEEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !27)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !27)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPwSbIwSt11char_traitsIwESaIwEEEEEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !28)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !28)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !29)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !29)
+ ret void
+}
+
+define weak void @_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPKwEEEEvv() {
+entry:
+ tail call void @llvm.dbg.func.start(metadata !30)
+ tail call void @llvm.dbg.stoppoint(i32 63, i32 0, metadata !2)
+ tail call void @llvm.dbg.region.end(metadata !30)
+ ret void
+}
+
+declare void @llvm.dbg.func.start(metadata) nounwind readnone
+
+declare void @llvm.dbg.stoppoint(i32, i32, metadata) nounwind readnone
+
+declare void @llvm.dbg.region.end(metadata) nounwind readnone
+
+declare extern_weak i32 @pthread_once(i32*, void ()*)
+
+declare extern_weak i8* @pthread_getspecific(i32)
+
+declare extern_weak i32 @pthread_setspecific(i32, i8*)
+
+declare extern_weak i32 @pthread_create(i64*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)
+
+declare extern_weak i32 @pthread_cancel(i64)
+
+declare extern_weak i32 @pthread_mutex_lock(%struct.pthread_mutex_t*)
+
+declare extern_weak i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*)
+
+declare extern_weak i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*)
+
+declare extern_weak i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)
+
+declare extern_weak i32 @pthread_key_create(i32*, void (i8*)*)
+
+declare extern_weak i32 @pthread_key_delete(i32)
+
+declare extern_weak i32 @pthread_mutexattr_init(%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)
+
+declare extern_weak i32 @pthread_mutexattr_settype(%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*, i32)
+
+declare extern_weak i32 @pthread_mutexattr_destroy(%"struct.__gnu_cxx::_ConvertibleConcept<unsigned int,unsigned int>"*)
+
+!0 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__aux_require_boolean_expr<bool>", metadata !"__aux_require_boolean_expr<bool>", metadata !"_ZN9__gnu_cxx26__aux_require_boolean_exprIbEEvRKT_", metadata !2, i32 239, metadata !3, i1 false, i1 true}
+!1 = metadata !{i32 458769, i32 0, i32 4, metadata !"concept-inst.cc", metadata !"/home/buildbot/buildslave/llvm-x86_64-linux-selfhost/llvm-gcc.obj/x86_64-unknown-linux-gnu/libstdc++-v3/src/../../../../llvm-gcc.src/libstdc++-v3/src", metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build)", i1 true, i1 true, metadata !"", i32 0}
+!2 = metadata !{i32 458769, i32 0, i32 4, metadata !"boost_concept_check.h", metadata !"/home/buildbot/buildslave/llvm-x86_64-linux-selfhost/llvm-gcc.obj/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits", metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build)", i1 false, i1 true, metadata !"", i32 0}
+!3 = metadata !{i32 458773, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0}
+!4 = metadata !{null, metadata !5}
+!5 = metadata !{i32 458768, metadata !1, metadata !"", metadata !1, i32 0, i64 64, i64 64, i64 0, i32 0, metadata !6}
+!6 = metadata !{i32 458790, metadata !1, metadata !"", metadata !1, i32 0, i64 8, i64 8, i64 0, i32 0, metadata !7}
+!7 = metadata !{i32 458788, metadata !1, metadata !"bool", metadata !1, i32 0, i64 8, i64 8, i64 0, i32 0, i32 2}
+!8 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_ConvertibleConcept<unsigned int, unsigned int> >", metadata !"__function_requires<__gnu_cxx::_ConvertibleConcept<unsigned int, unsigned int> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_19_ConvertibleConceptIjjEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!9 = metadata !{i32 458773, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !10, i32 0}
+!10 = metadata !{null}
+!11 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<char*> >", metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<char*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!12 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<const char*> >", metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<const char*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPKcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!13 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<wchar_t*> >", metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<wchar_t*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!14 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<const wchar_t*> >", metadata !"__function_requires<__gnu_cxx::_InputIteratorConcept<const wchar_t*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_21_InputIteratorConceptIPKwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!15 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<wchar_t*> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<wchar_t*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIPwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!16 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<char*> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<char*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIPcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!17 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<int> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<int> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIiEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!18 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<long int> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<long int> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIlEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!19 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<long long int> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<long long int> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIxEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!20 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<unsigned int> >", metadata !"__function_requires<__gnu_cxx::_LessThanComparableConcept<unsigned int> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_26_LessThanComparableConceptIjEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!21 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_OutputIteratorConcept<std::ostreambuf_iterator<char, std::char_traits<char> >, char> >", metadata !"__function_requires<__gnu_cxx::_OutputIteratorConcept<std::ostreambuf_iterator<char, std::char_traits<char> >, char> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_22_OutputIteratorConceptISt19ostreambuf_iteratorIcSt11char_traitsIcEEcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!22 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_OutputIteratorConcept<std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, wchar_t> >", metadata !"__function_requires<__gnu_cxx::_OutputIteratorConcept<std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, wchar_t> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_22_OutputIteratorConceptISt19ostreambuf_iteratorIwSt11char_traitsIwEEwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!23 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<char*> >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<char*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!24 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<const char*> >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<const char*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPKcEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!25 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPKcSsEEEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!26 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPcSsEEEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!27 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<const wchar_t*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<const wchar_t*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPKwSbIwSt11char_traitsIwESaIwEEEEEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!28 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<wchar_t*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<__gnu_cxx::__normal_iterator<wchar_t*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptINS_17__normal_iteratorIPwSbIwSt11char_traitsIwESaIwEEEEEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!29 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<wchar_t*> >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<wchar_t*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
+!30 = metadata !{i32 458798, i32 0, metadata !1, metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<const wchar_t*> >", metadata !"__function_requires<__gnu_cxx::_RandomAccessIteratorConcept<const wchar_t*> >", metadata !"_ZN9__gnu_cxx19__function_requiresINS_28_RandomAccessIteratorConceptIPKwEEEEvv", metadata !2, i32 61, metadata !9, i1 false, i1 true}
diff --git a/src/LLVM/test/Transforms/GlobalDCE/basicvariabletest.ll b/src/LLVM/test/Transforms/GlobalDCE/basicvariabletest.ll
new file mode 100644
index 0000000..cfa481b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/basicvariabletest.ll
@@ -0,0 +1,5 @@
+; RUN: opt < %s -globaldce -S | not grep global
+
+@X = external global i32
+@Y = internal global i32 7
+
diff --git a/src/LLVM/test/Transforms/GlobalDCE/dg.exp b/src/LLVM/test/Transforms/GlobalDCE/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/GlobalDCE/externally_available.ll b/src/LLVM/test/Transforms/GlobalDCE/externally_available.ll
new file mode 100644
index 0000000..cc88cb1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalDCE/externally_available.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -globaldce -S | not grep test_
+
+; test_function should not be emitted to the .s file.
+define available_externally i32 @test_function() {
+ ret i32 4
+}
+
+; test_global should not be emitted to the .s file.
+@test_global = available_externally global i32 4
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2004-10-10-CastStoreOnce.ll b/src/LLVM/test/Transforms/GlobalOpt/2004-10-10-CastStoreOnce.ll
new file mode 100644
index 0000000..9072826
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2004-10-10-CastStoreOnce.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -globalopt
+
+@V = global float 1.200000e+01 ; <float*> [#uses=1]
+@G = internal global i32* null ; <i32**> [#uses=2]
+
+define i32 @user() {
+ %P = load i32** @G ; <i32*> [#uses=1]
+ %Q = load i32* %P ; <i32> [#uses=1]
+ ret i32 %Q
+}
+
+define void @setter() {
+ %Vi = bitcast float* @V to i32* ; <i32*> [#uses=1]
+ store i32* %Vi, i32** @G
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2005-06-15-LocalizeConstExprCrash.ll b/src/LLVM/test/Transforms/GlobalOpt/2005-06-15-LocalizeConstExprCrash.ll
new file mode 100644
index 0000000..788ddf5
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2005-06-15-LocalizeConstExprCrash.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -globalopt -disable-output
+; PR579
+
+@g_40507551 = internal global i16 31038 ; <i16*> [#uses=1]
+
+define void @main() {
+ %tmp.4.i.1 = load i8* getelementptr (i8* bitcast (i16* @g_40507551 to i8*), i32 1) ; <i8> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2005-09-27-Crash.ll b/src/LLVM/test/Transforms/GlobalOpt/2005-09-27-Crash.ll
new file mode 100644
index 0000000..896b6c7
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2005-09-27-Crash.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -globalopt -disable-output
+ %RPyString = type { i32, %arraytype.Char }
+ %arraytype.Char = type { i32, [0 x i8] }
+ %arraytype.Signed = type { i32, [0 x i32] }
+ %functiontype.1 = type { %RPyString* (i32) *}
+ %structtype.test = type { i32, %arraytype.Signed }
+@structinstance.test = internal global { i32, { i32, [2 x i32] } } { i32 41, { i32, [2 x i32] } { i32 2, [2 x i32] [ i32 100, i32 101 ] } } ; <{ i32, { i32, [2 x i32] } }*> [#uses=1]
+
+define fastcc void @pypy_array_constant() {
+block0:
+ %tmp.9 = getelementptr %structtype.test* bitcast ({ i32, { i32, [2 x i32] } }* @structinstance.test to %structtype.test*), i32 0, i32 0 ; <i32*> [#uses=0]
+ ret void
+}
+
+define fastcc void @new.varsizestruct.rpy_string() {
+ unreachable
+}
+
+define void @__entrypoint__pypy_array_constant() {
+ call fastcc void @pypy_array_constant( )
+ ret void
+}
+
+define void @__entrypoint__raised_LLVMException() {
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2006-07-07-InlineAsmCrash.ll b/src/LLVM/test/Transforms/GlobalOpt/2006-07-07-InlineAsmCrash.ll
new file mode 100644
index 0000000..f65775d
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2006-07-07-InlineAsmCrash.ll
@@ -0,0 +1,135 @@
+; RUN: opt < %s -globalopt -disable-output
+; PR820
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct..0FileDescriptor = type { i32 }
+ %"struct.FlagDescription<int32>" = type { i8*, i32*, i1, i1, i32, i8* }
+ %"struct.FlagRegisterer<bool>" = type { i8 }
+ %struct.MutexLock = type { %struct..0FileDescriptor* }
+ %"struct.std::DisabledRangeMap" = type { %"struct.std::_Rb_tree<const char*,std::pair<const char* const, FlagDescription<bool> >,std::_Select1st<std::pair<const char* const, FlagDescription<bool> > >,StringCmp,std::allocator<std::pair<const char* const, FlagDescription<bool> > > >" }
+ %"struct.std::_Rb_tree<const char*,std::pair<const char* const, FlagDescription<bool> >,std::_Select1st<std::pair<const char* const, FlagDescription<bool> > >,StringCmp,std::allocator<std::pair<const char* const, FlagDescription<bool> > > >" = type { %"struct.std::_Rb_tree<const char*,std::pair<const char* const, FlagDescription<bool> >,std::_Select1st<std::pair<const char* const, FlagDescription<bool> > >,StringCmp,std::allocator<std::pair<const char* const, FlagDescription<bool> > > >::_Rb_tree_impl<StringCmp,false>" }
+ %"struct.std::_Rb_tree<const char*,std::pair<const char* const, FlagDescription<bool> >,std::_Select1st<std::pair<const char* const, FlagDescription<bool> > >,StringCmp,std::allocator<std::pair<const char* const, FlagDescription<bool> > > >::_Rb_tree_impl<StringCmp,false>" = type { %"struct.FlagRegisterer<bool>", %"struct.std::_Rb_tree_node_base", i32 }
+ %"struct.std::_Rb_tree_const_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" = type { %"struct.std::_Rb_tree_node_base"* }
+ %"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* }
+ %"struct.std::_Vector_base<int,std::allocator<int> >" = type { %"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl" }
+ %"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl" = type { i32*, i32*, i32* }
+ %"struct.std::vector<int,std::allocator<int> >" = type { %"struct.std::_Vector_base<int,std::allocator<int> >" }
+@registry_lock = external global %struct..0FileDescriptor ; <%struct..0FileDescriptor*> [#uses=0]
+@_ZN61FLAG__foo_int32_44FLAGS_E = external global %"struct.FlagRegisterer<bool>" ; <%"struct.FlagRegisterer<bool>"*> [#uses=0]
+@llvm.global_ctors = appending global [20 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_10FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN60FLAG__foo_bool_19FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZNK5Bzh4Enum13is_contiguousEv }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_21FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN7ScannerC2Ev }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z11StripStringPSsPKcc }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZNK9__gnu_cxx4hashI11StringPieceEclERKS1_ }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN8Hasher325ResetEj }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z25ACLRv }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int64_25FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_7FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_18FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_25FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_eventbuf }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN61FLAG__foo_int32_26FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN62FLAG__foo_string_16FLAGS_E }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__ZN17InitializerC2EPKcS1_PFvvE }, { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__checker_bcad_variable } ] ; <[20 x { i32, void ()* }]*> [#uses=0]
+
+declare void @_GLOBAL__I__ZN62FLAG__foo_string_10FLAGS_E()
+
+declare void @_GLOBAL__I__ZN60FLAG__foo_bool_19FLAGS_E()
+
+declare void @_GLOBAL__I__ZNK5Bzh4Enum13is_contiguousEv()
+
+declare void @_GLOBAL__I__ZN62FLAG__foo_string_17FLAGS_E()
+
+declare void @_GLOBAL__I__ZN61FLAG__foo_int32_21FLAGS_E()
+
+define void @_ZN14FlagRegistererIiEC1EPKcRK15FlagDescriptionIiE() {
+entry:
+ call void @_Z12RegisterFlagIiEvPKcRK15FlagDescriptionIT_E( )
+ ret void
+}
+
+define void @_Z12RegisterFlagIiEvPKcRK15FlagDescriptionIT_E() {
+entry:
+ call void @_ZN9MutexLockC1EP5Mutex( )
+ ret void
+}
+
+declare void @_GLOBAL__I__ZN7ScannerC2Ev()
+
+declare void @_GLOBAL__I__Z11StripStringPSsPKcc()
+
+define void @_ZNSt6vectorIiSaIiEEC1ERKS0_() {
+entry:
+ unreachable
+}
+
+declare void @_GLOBAL__I__ZNK9__gnu_cxx4hashI11StringPieceEclERKS1_()
+
+declare void @_GLOBAL__I__ZN8Hasher325ResetEj()
+
+declare void @_GLOBAL__I__Z25ACLRv()
+
+define void @_ZN9MutexLockC1EP5Mutex() {
+entry:
+ call void @_ZN5Mutex4LockEv( )
+ ret void
+}
+
+define void @_ZN5Mutex4LockEv() {
+entry:
+ call void @_Z22Acquire_CASPViii( )
+ ret void
+}
+
+define void @_ZNSt3mapIPKc15FlagDescriptionIiE9StringCmpSaISt4pairIKS1_S3_EEE3endEv(%"struct.std::_Rb_tree_const_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >"* sret %agg.result) {
+entry:
+ unreachable
+}
+
+declare void @_GLOBAL__I__ZN61FLAG__foo_int64_25FLAGS_E()
+
+define void @_Z14CASPViii() {
+entry:
+ %tmp3 = call i32 asm sideeffect "lock; cmpxchg $1,$2", "={ax},q,m,0,~{dirflag},~{fpsr},~{flags},~{memory}"( i32 0, i32* null, i32 0 ) ; <i32> [#uses=0]
+ unreachable
+}
+
+declare void @_GLOBAL__I__ZN61FLAG__foo_int32_7FLAGS_E()
+
+declare void @_GLOBAL__I__ZN62FLAG__foo_string_18FLAGS_E()
+
+define void @_Z22Acquire_CASPViii() {
+entry:
+ call void @_Z14CASPViii( )
+ unreachable
+}
+
+declare void @_GLOBAL__I__ZN61FLAG__foo_int32_25FLAGS_E()
+
+declare void @_GLOBAL__I_eventbuf()
+
+define void @_GLOBAL__I__ZN61FLAG__foo_int32_26FLAGS_E() {
+entry:
+ call void @_Z41__static_initialization_and_destruction_0ii1662( i32 1, i32 65535 )
+ ret void
+}
+
+define void @_Z41__static_initialization_and_destruction_0ii1662(i32 %__initialize_p, i32 %__priority) {
+entry:
+ %__initialize_p_addr = alloca i32 ; <i32*> [#uses=2]
+ %__priority_addr = alloca i32 ; <i32*> [#uses=2]
+ store i32 %__initialize_p, i32* %__initialize_p_addr
+ store i32 %__priority, i32* %__priority_addr
+ %tmp = load i32* %__priority_addr ; <i32> [#uses=1]
+ %tmp.upgrd.1 = icmp eq i32 %tmp, 65535 ; <i1> [#uses=1]
+ br i1 %tmp.upgrd.1, label %cond_true, label %cond_next14
+
+cond_true: ; preds = %entry
+ %tmp8 = load i32* %__initialize_p_addr ; <i32> [#uses=1]
+ %tmp9 = icmp eq i32 %tmp8, 1 ; <i1> [#uses=1]
+ br i1 %tmp9, label %cond_true10, label %cond_next14
+
+cond_true10: ; preds = %cond_true
+ call void @_ZN14FlagRegistererIiEC1EPKcRK15FlagDescriptionIiE( )
+ ret void
+
+cond_next14: ; preds = %cond_true, %entry
+ ret void
+}
+
+declare void @_GLOBAL__I__ZN62FLAG__foo_string_16FLAGS_E()
+
+define void @_ZN9__gnu_cxx13new_allocatorIPNS_15_Hashtable_nodeIjEEEC2Ev() {
+entry:
+ unreachable
+}
+
+declare void @_GLOBAL__I__ZN17InitializerC2EPKcS1_PFvvE()
+
+declare void @_GLOBAL__I__checker_bcad_variable()
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2006-11-01-ShrinkGlobalPhiCrash.ll b/src/LLVM/test/Transforms/GlobalOpt/2006-11-01-ShrinkGlobalPhiCrash.ll
new file mode 100644
index 0000000..f1bcc36
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2006-11-01-ShrinkGlobalPhiCrash.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -globalopt -disable-output
+
+ %struct._list = type { i32*, %struct._list* }
+ %struct._play = type { i32, i32*, %struct._list*, %struct._play* }
+@nrow = internal global i32 0 ; <i32*> [#uses=2]
+
+define void @make_play() {
+entry:
+ br label %cond_true16.i
+
+cond_true16.i: ; preds = %cond_true16.i, %entry
+ %low.0.in.i.0 = phi i32* [ @nrow, %entry ], [ null, %cond_true16.i ] ; <i32*> [#uses=1]
+ %low.0.i = load i32* %low.0.in.i.0 ; <i32> [#uses=0]
+ br label %cond_true16.i
+}
+
+define void @make_wanted() {
+entry:
+ unreachable
+}
+
+define void @get_good_move() {
+entry:
+ ret void
+}
+
+define void @main() {
+entry:
+ store i32 8, i32* @nrow
+ tail call void @make_play( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2007-04-05-Crash.ll b/src/LLVM/test/Transforms/GlobalOpt/2007-04-05-Crash.ll
new file mode 100644
index 0000000..5387819
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2007-04-05-Crash.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -globalopt -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32"
+target triple = "thumb-apple-darwin8"
+@replacementUnichar = internal global i16 -3 ; <i16*> [#uses=2]
+@"L_OBJC_IMAGE_INFO" = internal global [2 x i32] zeroinitializer ; <[2 x i32]*> [#uses=1]
+@llvm.used = appending global [1 x i8*] [ i8* bitcast ([2 x i32]* @"L_OBJC_IMAGE_INFO" to i8*) ] ; <[1 x i8*]*> [#uses=0]
+
+define zeroext i16 @__NSCharToUnicharCFWrapper(i8 zeroext %ch) {
+entry:
+ %iftmp.0.0.in.in = select i1 false, i16* @replacementUnichar, i16* null ; <i16*> [#uses=1]
+ %iftmp.0.0.in = load i16* %iftmp.0.0.in.in ; <i16> [#uses=1]
+ ret i16 %iftmp.0.0.in
+}
+
+define void @__NSASCIICharToUnichar() {
+entry:
+ ret void
+}
+
+define void @_NSDefaultCStringEncoding() {
+entry:
+ call void @__NSSetCStringCharToUnichar( )
+ br i1 false, label %cond_true6, label %cond_next8
+
+cond_true6: ; preds = %entry
+ store i16 -2, i16* @replacementUnichar
+ ret void
+
+cond_next8: ; preds = %entry
+ ret void
+}
+
+declare void @__NSSetCStringCharToUnichar()
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2007-05-13-Crash.ll b/src/LLVM/test/Transforms/GlobalOpt/2007-05-13-Crash.ll
new file mode 100644
index 0000000..bffef3e
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2007-05-13-Crash.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -globalopt -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-apple-darwin8"
+ %struct.SFLMutableListItem = type { i16 }
+ %struct.__CFDictionary = type opaque
+ %struct.__CFString = type opaque
+ %struct.__builtin_CFString = type { i32*, i32, i8*, i32 }
+@_ZZ19SFLGetVisibilityKeyvE19_kSFLLVisibilityKey = internal global %struct.__CFString* null ; <%struct.__CFString**> [#uses=2]
+@_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey = internal global %struct.__CFString* null ; <%struct.__CFString**> [#uses=7]
+internal constant %struct.__builtin_CFString {
+ i32* getelementptr ([0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0),
+ i32 1992,
+ i8* getelementptr ([14 x i8]* @.str, i32 0, i32 0),
+ i32 13 }, section "__DATA,__cfstring" ; <%struct.__builtin_CFString*>:0 [#uses=1]
+@__CFConstantStringClassReference = external global [0 x i32] ; <[0 x i32]*> [#uses=1]
+@.str = internal constant [14 x i8] c"AlwaysVisible\00" ; <[14 x i8]*> [#uses=1]
+@_ZZ21SFLGetNeverVisibleKeyvE21_kSFLLNeverVisibleKey = internal global %struct.__CFString* null ; <%struct.__CFString**> [#uses=2]
+
+define %struct.__CFString* @_Z19SFLGetVisibilityKeyv() {
+entry:
+ %tmp1 = load %struct.__CFString** @_ZZ19SFLGetVisibilityKeyvE19_kSFLLVisibilityKey ; <%struct.__CFString*> [#uses=1]
+ ret %struct.__CFString* %tmp1
+}
+
+define %struct.__CFString* @_Z22SFLGetAlwaysVisibleKeyv() {
+entry:
+ %tmp1 = load %struct.__CFString** @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey ; <%struct.__CFString*> [#uses=1]
+ %tmp2 = icmp eq %struct.__CFString* %tmp1, null ; <i1> [#uses=1]
+ br i1 %tmp2, label %cond_true, label %cond_next
+
+cond_true: ; preds = %entry
+ store %struct.__CFString* bitcast (%struct.__builtin_CFString* @0 to %struct.__CFString*), %struct.__CFString** @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey
+ br label %cond_next
+
+cond_next: ; preds = %entry, %cond_true
+ %tmp4 = load %struct.__CFString** @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey ; <%struct.__CFString*> [#uses=1]
+ ret %struct.__CFString* %tmp4
+}
+
+define %struct.__CFString* @_Z21SFLGetNeverVisibleKeyv() {
+entry:
+ %tmp1 = load %struct.__CFString** @_ZZ21SFLGetNeverVisibleKeyvE21_kSFLLNeverVisibleKey ; <%struct.__CFString*> [#uses=1]
+ ret %struct.__CFString* %tmp1
+}
+
+define %struct.__CFDictionary* @_ZN18SFLMutableListItem18GetPrefsDictionaryEv(%struct.SFLMutableListItem* %this) {
+entry:
+ %tmp4 = getelementptr %struct.SFLMutableListItem* %this, i32 0, i32 0 ; <i16*> [#uses=1]
+ %tmp5 = load i16* %tmp4 ; <i16> [#uses=1]
+ %tmp6 = icmp eq i16 %tmp5, 0 ; <i1> [#uses=1]
+ br i1 %tmp6, label %cond_next22, label %cond_true
+
+cond_true: ; preds = %entry
+ %tmp9 = load %struct.__CFString** @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey ; <%struct.__CFString*> [#uses=1]
+ %tmp10 = icmp eq %struct.__CFString* %tmp9, null ; <i1> [#uses=1]
+ br i1 %tmp10, label %cond_true13, label %cond_next22
+
+cond_true13: ; preds = %cond_true
+ store %struct.__CFString* bitcast (%struct.__builtin_CFString* @0 to %struct.__CFString*), %struct.__CFString** @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey
+ br label %cond_next22
+
+cond_next22: ; preds = %entry, %cond_true13, %cond_true
+ %iftmp.1.0.in = phi %struct.__CFString** [ @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey, %cond_true ], [ @_ZZ22SFLGetAlwaysVisibleKeyvE22_kSFLLAlwaysVisibleKey, %cond_true13 ], [ @_ZZ21SFLGetNeverVisibleKeyvE21_kSFLLNeverVisibleKey, %entry ] ; <%struct.__CFString**> [#uses=1]
+ %iftmp.1.0 = load %struct.__CFString** %iftmp.1.0.in ; <%struct.__CFString*> [#uses=1]
+ %tmp24 = load %struct.__CFString** @_ZZ19SFLGetVisibilityKeyvE19_kSFLLVisibilityKey ; <%struct.__CFString*> [#uses=1]
+ %tmp2728 = bitcast %struct.__CFString* %tmp24 to i8* ; <i8*> [#uses=1]
+ %tmp2930 = bitcast %struct.__CFString* %iftmp.1.0 to i8* ; <i8*> [#uses=1]
+ call void @_Z20CFDictionaryAddValuePKvS0_( i8* %tmp2728, i8* %tmp2930 )
+ ret %struct.__CFDictionary* undef
+}
+
+declare void @_Z20CFDictionaryAddValuePKvS0_(i8*, i8*)
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2007-06-04-PackedStruct.ll b/src/LLVM/test/Transforms/GlobalOpt/2007-06-04-PackedStruct.ll
new file mode 100644
index 0000000..f3dc3c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2007-06-04-PackedStruct.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -globalopt -disable-output
+; PR1491
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+ %"struct.__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<const int, int> > >" = type <{ i8 }>
+ %"struct.std::_Rb_tree<int,std::pair<const int, int>,std::_Select1st<std::pair<const int, int> >,std::less<int>,std::allocator<std::pair<const int, int> > >" = type { %"struct.std::_Rb_tree<int,std::pair<const int, int>,std::_Select1st<std::pair<const int, int> >,std::less<int>,std::allocator<std::pair<const int, int> > >::_Rb_tree_impl<std::less<int>,false>" }
+ %"struct.std::_Rb_tree<int,std::pair<const int, int>,std::_Select1st<std::pair<const int, int> >,std::less<int>,std::allocator<std::pair<const int, int> > >::_Rb_tree_impl<std::less<int>,false>" = type { %"struct.__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<const int, int> > >", %"struct.std::_Rb_tree_node_base", i32 }
+ %"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* }
+ %"struct.std::map<int,int,std::less<int>,std::allocator<std::pair<const int, int> > >" = type { %"struct.std::_Rb_tree<int,std::pair<const int, int>,std::_Select1st<std::pair<const int, int> >,std::less<int>,std::allocator<std::pair<const int, int> > >" }
+@someMap = global %"struct.std::map<int,int,std::less<int>,std::allocator<std::pair<const int, int> > >" zeroinitializer ; <%"struct.std::map<int,int,std::less<int>,std::allocator<std::pair<const int, int> > >"*> [#uses=1]
+@llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_someMap } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
+@llvm.global_dtors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__D_someMap } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
+
+define void @_GLOBAL__I_someMap() {
+entry:
+ call void @_Z41__static_initialization_and_destruction_0ii( i32 1, i32 65535 )
+ ret void
+}
+
+declare void @_GLOBAL__D_someMap()
+
+define void @_Z41__static_initialization_and_destruction_0ii(i32 %__initialize_p, i32 %__priority) {
+entry:
+ %tmp1 = icmp eq i32 %__priority, 65535 ; <i1> [#uses=1]
+ %tmp4 = icmp eq i32 %__initialize_p, 1 ; <i1> [#uses=1]
+ %tmp7 = and i1 %tmp1, %tmp4 ; <i1> [#uses=1]
+ br i1 %tmp7, label %cond_true, label %cond_next
+
+cond_true: ; preds = %entry
+ store i8 0, i8* getelementptr (%"struct.std::map<int,int,std::less<int>,std::allocator<std::pair<const int, int> > >"* @someMap, i32 0, i32 0, i32 0, i32 0, i32 0)
+ ret void
+
+cond_next: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2007-11-09-GEP-GEP-Crash.ll b/src/LLVM/test/Transforms/GlobalOpt/2007-11-09-GEP-GEP-Crash.ll
new file mode 100644
index 0000000..442cb92
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2007-11-09-GEP-GEP-Crash.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalopt -disable-output
+target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f128:64:128"
+target triple = "powerpc-apple-darwin8"
+ %struct.empty0 = type { }
+ %struct.es = type { %struct.empty0 }
+ %struct.es1 = type { %struct.empty0 }
+@aaui1 = internal global [6 x [2 x i32]] [ [2 x i32] [ i32 1, i32 1 ], [2 x i32] [ i32 1, i32 1 ], [2 x i32] [ i32 1, i32 1 ], [2 x i32] [ i32 1, i32 1 ], [2 x i32] [ i32 1, i32 1 ], [2 x i32] [ i32 1, i32 1 ] ] ; <[6 x [2 x i32]]*> [#uses=1]
+@aaui0 = internal global [0 x [2 x i32]] zeroinitializer ; <[0 x [2 x i32]]*> [#uses=1]
+
+define i8 @func() {
+entry:
+ %tmp10 = getelementptr [2 x i32]* getelementptr ([6 x [2 x i32]]* @aaui1, i32 0, i32 0), i32 5, i32 1 ; <i32*> [#uses=1]
+ %tmp11 = load i32* %tmp10, align 4 ; <i32> [#uses=1]
+ %tmp12 = call i32 (...)* @func3( i32* null, i32 0, i32 %tmp11 ) ; <i32> [#uses=0]
+ ret i8 undef
+}
+
+declare i32 @func3(...)
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-01-03-Crash.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-01-03-Crash.ll
new file mode 100644
index 0000000..4105ab1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-01-03-Crash.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -globalopt | llvm-dis
+; PR1896
+
+@indirect1 = internal global void (i32)* null ; <void (i32)**> [#uses=2]
+
+declare void @indirectmarked(i32)
+
+define i32 @main() {
+entry:
+ br i1 false, label %cond_next20.i, label %cond_true.i9
+
+cond_true.i9: ; preds = %entry
+ ret i32 0
+
+cond_next20.i: ; preds = %entry
+ store void (i32)* @indirectmarked, void (i32)** @indirect1, align 4
+ br i1 false, label %cond_next21.i.i23.i, label %stack_restore
+
+stack_restore: ; preds = %cond_next20.i
+ ret i32 0
+
+cond_next21.i.i23.i: ; preds = %cond_next20.i
+ %tmp6.i4.i = load i32* bitcast (void (i32)** @indirect1 to i32*), align 4 ; <i32> [#uses=0]
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-01-13-OutOfRangeSROA.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-01-13-OutOfRangeSROA.ll
new file mode 100644
index 0000000..82abc8f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-01-13-OutOfRangeSROA.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -globalopt -S | grep {16 x .31 x double.. zeroinitializer}
+
+; The 'X' indices could be larger than 31. Do not SROA the outer indices of this array.
+@mm = internal global [16 x [31 x double]] zeroinitializer, align 32
+
+define void @test(i32 %X) {
+ %P = getelementptr [16 x [31 x double]]* @mm, i32 0, i32 0, i32 %X
+ store double 1.0, double* %P
+ ret void
+}
+
+define double @get(i32 %X) {
+ %P = getelementptr [16 x [31 x double]]* @mm, i32 0, i32 0, i32 %X
+ %V = load double* %P
+ ret double %V
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-01-29-VolatileGlobal.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-01-29-VolatileGlobal.ll
new file mode 100644
index 0000000..a6803ab
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-01-29-VolatileGlobal.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -globalopt -S | grep {load volatile}
+@t0.1441 = internal global double 0x3FD5555555555555, align 8 ; <double*> [#uses=1]
+
+define double @foo() nounwind {
+entry:
+ %tmp1 = volatile load double* @t0.1441, align 8 ; <double> [#uses=2]
+ %tmp4 = fmul double %tmp1, %tmp1 ; <double> [#uses=1]
+ ret double %tmp4
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-02-16-NestAttr.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-02-16-NestAttr.ll
new file mode 100644
index 0000000..0e70c49
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-02-16-NestAttr.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -globalopt -S | grep { nest } | count 1
+ %struct.FRAME.nest = type { i32, i32 (i32)* }
+ %struct.__builtin_trampoline = type { [10 x i8] }
+@.str = internal constant [7 x i8] c"%d %d\0A\00" ; <[7 x i8]*> [#uses=1]
+
+define i32 @process(i32 (i32)* %func) nounwind {
+entry:
+ %tmp2 = tail call i32 %func( i32 1 ) nounwind ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define internal fastcc i32 @g.1478(%struct.FRAME.nest* nest %CHAIN.1, i32 %m) nounwind {
+entry:
+ %tmp3 = getelementptr %struct.FRAME.nest* %CHAIN.1, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp4 = load i32* %tmp3, align 4 ; <i32> [#uses=1]
+ %tmp7 = icmp eq i32 %tmp4, %m ; <i1> [#uses=1]
+ %tmp78 = zext i1 %tmp7 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp78
+}
+
+define internal i32 @f.1481(%struct.FRAME.nest* nest %CHAIN.2, i32 %m) nounwind {
+entry:
+ %tmp4 = tail call fastcc i32 @g.1478( %struct.FRAME.nest* nest %CHAIN.2, i32 %m ) nounwind ; <i32> [#uses=1]
+ %tmp6 = getelementptr %struct.FRAME.nest* %CHAIN.2, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp7 = load i32* %tmp6, align 4 ; <i32> [#uses=1]
+ %tmp9 = icmp eq i32 %tmp4, %tmp7 ; <i1> [#uses=1]
+ %tmp910 = zext i1 %tmp9 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp910
+}
+
+define i32 @nest(i32 %n) nounwind {
+entry:
+ %TRAMP.316 = alloca [10 x i8] ; <[10 x i8]*> [#uses=1]
+ %FRAME.0 = alloca %struct.FRAME.nest ; <%struct.FRAME.nest*> [#uses=3]
+ %TRAMP.316.sub = getelementptr [10 x i8]* %TRAMP.316, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp3 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %n, i32* %tmp3, align 8
+ %FRAME.06 = bitcast %struct.FRAME.nest* %FRAME.0 to i8* ; <i8*> [#uses=1]
+ %tramp = call i8* @llvm.init.trampoline( i8* %TRAMP.316.sub, i8* bitcast (i32 (%struct.FRAME.nest*, i32)* @f.1481 to i8*), i8* %FRAME.06 ) ; <i8*> [#uses=1]
+ %tmp7 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
+ %tmp89 = bitcast i8* %tramp to i32 (i32)* ; <i32 (i32)*> [#uses=2]
+ store i32 (i32)* %tmp89, i32 (i32)** %tmp7, align 4
+ %tmp13 = call i32 @process( i32 (i32)* %tmp89 ) nounwind ; <i32> [#uses=1]
+ ret i32 %tmp13
+}
+
+declare i8* @llvm.init.trampoline(i8*, i8*, i8*) nounwind
+
+define i32 @main() nounwind {
+entry:
+ %tmp = tail call i32 @nest( i32 2 ) nounwind ; <i32> [#uses=1]
+ %tmp1 = tail call i32 @nest( i32 1 ) nounwind ; <i32> [#uses=1]
+ %tmp3 = tail call i32 (i8*, ...)* @printf( i8* noalias getelementptr ([7 x i8]* @.str, i32 0, i32 0), i32 %tmp1, i32 %tmp ) nounwind ; <i32> [#uses=0]
+ ret i32 undef
+}
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-04-26-SROA-Global-Align.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-04-26-SROA-Global-Align.ll
new file mode 100644
index 0000000..5b06fea
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-04-26-SROA-Global-Align.ll
@@ -0,0 +1,32 @@
+; Verify that when @G is SROA'd that the new globals have correct
+; alignments. Elements 0 and 2 must be 16-byte aligned, and element
+; 1 must be at least 8 byte aligned (but could be more).
+
+; RUN: opt < %s -globalopt -S | grep {@G.0 = internal unnamed_addr global .*align 16}
+; RUN: opt < %s -globalopt -S | grep {@G.1 = internal unnamed_addr global .*align 8}
+; RUN: opt < %s -globalopt -S | grep {@G.2 = internal unnamed_addr global .*align 16}
+; rdar://5891920
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin8"
+
+%T = type { double, double, double }
+
+@G = internal global %T zeroinitializer, align 16
+
+
+define void @test() {
+ store double 1.0, double* getelementptr (%T* @G, i32 0, i32 0), align 16
+ store double 2.0, double* getelementptr (%T* @G, i32 0, i32 1), align 8
+ store double 3.0, double* getelementptr (%T* @G, i32 0, i32 2), align 16
+ ret void
+}
+
+define double @test2() {
+ %V1 = load double* getelementptr (%T* @G, i32 0, i32 0), align 16
+ %V2 = load double* getelementptr (%T* @G, i32 0, i32 1), align 8
+ %V3 = load double* getelementptr (%T* @G, i32 0, i32 2), align 16
+ %R = fadd double %V1, %V2
+ %R2 = fadd double %R, %V3
+ ret double %R2
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-07-17-addrspace.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-07-17-addrspace.ll
new file mode 100644
index 0000000..390e77a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-07-17-addrspace.ll
@@ -0,0 +1,28 @@
+; This test lets globalopt split the global struct and array into different
+; values. This used to crash, because globalopt forgot to put the new var in the
+; same address space as the old one.
+
+; RUN: opt < %s -globalopt -S > %t
+; Check that the new global values still have their address space
+; RUN: cat %t | grep addrspace.*global
+
+@struct = internal addrspace(1) global { i32, i32 } zeroinitializer
+@array = internal addrspace(1) global [ 2 x i32 ] zeroinitializer
+
+define i32 @foo() {
+ %A = load i32 addrspace(1) * getelementptr ({ i32, i32 } addrspace(1) * @struct, i32 0, i32 0)
+ %B = load i32 addrspace(1) * getelementptr ([ 2 x i32 ] addrspace(1) * @array, i32 0, i32 0)
+ ; Use the loaded values, so they won't get removed completely
+ %R = add i32 %A, %B
+ ret i32 %R
+}
+
+; We put stores in a different function, so that the global variables won't get
+; optimized away completely.
+define void @bar(i32 %R) {
+ store i32 %R, i32 addrspace(1) * getelementptr ([ 2 x i32 ] addrspace(1) * @array, i32 0, i32 0)
+ store i32 %R, i32 addrspace(1) * getelementptr ({ i32, i32 } addrspace(1) * @struct, i32 0, i32 0)
+ ret void
+}
+
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash-2.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash-2.ll
new file mode 100644
index 0000000..b74e4fc
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash-2.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -globalopt | llvm-dis
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
+
+define void @bar(i32 %Size) nounwind noinline {
+entry:
+ %malloccall = tail call i8* @malloc(i32 trunc (i64 mul (i64 ptrtoint (i32* getelementptr (i32* null, i32 1) to i64), i64 2000000) to i32))
+ %tmp = bitcast i8* %malloccall to [1000000 x %struct.foo]*
+ %.sub = getelementptr [1000000 x %struct.foo]* %tmp, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i32)
+
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %tmpLD1 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %tmp = phi %struct.foo* [ %tmpLD1, %bb1.thread ], [ %tmpLD1, %bb1 ] ; <%struct.foo*> [#uses=1]
+ %0 = getelementptr %struct.foo* %tmp, i32 1 ; <%struct.foo*> [#uses=0]
+ br label %bb1
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash.ll b/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash.ll
new file mode 100644
index 0000000..613cb7b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2008-12-16-HeapSRACrash.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -globalopt | llvm-dis
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
+
+define void @bar(i32 %Size) nounwind noinline {
+entry:
+ %malloccall = tail call i8* @malloc(i32 trunc (i64 mul (i64 ptrtoint (i32* getelementptr (i32* null, i32 1) to i64), i64 2000000) to i32))
+ %tmp = bitcast i8* %malloccall to [1000000 x %struct.foo]*
+ %.sub = getelementptr [1000000 x %struct.foo]* %tmp, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i32)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %tmpLD1 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=3]
+ store %struct.foo* %tmpLD1, %struct.foo** null
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %tmp = phi %struct.foo* [ %tmpLD1, %bb1.thread ], [ %tmpLD1, %bb1 ] ; <%struct.foo*> [#uses=0]
+ br i1 false, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-01-13-phi-user.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-01-13-phi-user.ll
new file mode 100644
index 0000000..c4b6e52
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-01-13-phi-user.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -globalopt -S | grep {phi.*@head}
+; PR3321
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.node = type { %struct.node*, i32 }
+@head = internal global %struct.node* null ; <%struct.node**> [#uses=2]
+@node = internal global %struct.node { %struct.node* null, i32 42 }, align 16 ; <%struct.node*> [#uses=1]
+
+define i32 @f() nounwind {
+entry:
+ store %struct.node* @node, %struct.node** @head, align 8
+ br label %bb1
+
+bb: ; preds = %bb1
+ %0 = getelementptr %struct.node* %t.0, i64 0, i32 1 ; <i32*> [#uses=1]
+ %1 = load i32* %0, align 4 ; <i32> [#uses=1]
+ %2 = getelementptr %struct.node* %t.0, i64 0, i32 0 ; <%struct.node**> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb, %entry
+ %value.0 = phi i32 [ undef, %entry ], [ %1, %bb ] ; <i32> [#uses=1]
+ %t.0.in = phi %struct.node** [ @head, %entry ], [ %2, %bb ] ; <%struct.node**> [#uses=1]
+ %t.0 = load %struct.node** %t.0.in ; <%struct.node*> [#uses=3]
+ %3 = icmp eq %struct.node* %t.0, null ; <i1> [#uses=1]
+ br i1 %3, label %bb2, label %bb
+
+bb2: ; preds = %bb1
+ ret i32 %value.0
+}
+
+define i32 @main() nounwind {
+entry:
+ %0 = call i32 @f() nounwind ; <i32> [#uses=1]
+ ret i32 %0
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll
new file mode 100644
index 0000000..a1b69ef
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-BitcastAlias.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -globalopt
+
+@g = external global i32
+
+@a = alias bitcast (i32* @g to i8*)
+
+define void @f() {
+ %tmp = load i8* @a
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
new file mode 100644
index 0000000..a5be2b1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+define internal void @f() {
+; CHECK-NOT: @f
+; CHECK: define void @a
+ ret void
+}
+
+@a = alias void ()* @f
+
+define void @g() {
+ call void()* @a()
+ ret void
+}
+
+@b = alias internal void ()* @g
+; CHECK-NOT: @b
+
+define void @h() {
+ call void()* @b()
+; CHECK: call void @g
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-03-05-dbg.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-03-05-dbg.ll
new file mode 100644
index 0000000..3154856
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-03-05-dbg.ll
@@ -0,0 +1,76 @@
+; RUN: opt < %s -globalopt -stats -disable-output |& grep "1 globalopt - Number of global vars shrunk to booleans"
+
+@Stop = internal global i32 0 ; <i32*> [#uses=3]
+
+define i32 @foo(i32 %i) nounwind ssp {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.value(metadata !{i32 %i}, i64 0, metadata !3)
+ %0 = icmp eq i32 %i, 1, !dbg !7 ; <i1> [#uses=1]
+ br i1 %0, label %bb, label %bb1, !dbg !7
+
+bb: ; preds = %entry
+ store i32 0, i32* @Stop, align 4, !dbg !9
+ %1 = mul nsw i32 %i, 42, !dbg !10 ; <i32> [#uses=1]
+ call void @llvm.dbg.value(metadata !{i32 %1}, i64 0, metadata !3), !dbg !10
+ br label %bb2, !dbg !10
+
+bb1: ; preds = %entry
+ store i32 1, i32* @Stop, align 4, !dbg !11
+ br label %bb2, !dbg !11
+
+bb2: ; preds = %bb1, %bb
+ %i_addr.0 = phi i32 [ %1, %bb ], [ %i, %bb1 ] ; <i32> [#uses=1]
+ br label %return, !dbg !12
+
+return: ; preds = %bb2
+ ret i32 %i_addr.0, !dbg !12
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+define i32 @bar() nounwind ssp {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %0 = load i32* @Stop, align 4, !dbg !13 ; <i32> [#uses=1]
+ %1 = icmp eq i32 %0, 1, !dbg !13 ; <i1> [#uses=1]
+ br i1 %1, label %bb, label %bb1, !dbg !13
+
+bb: ; preds = %entry
+ br label %bb2, !dbg !18
+
+bb1: ; preds = %entry
+ br label %bb2, !dbg !19
+
+bb2: ; preds = %bb1, %bb
+ %.0 = phi i32 [ 0, %bb ], [ 1, %bb1 ] ; <i32> [#uses=1]
+ br label %return, !dbg !19
+
+return: ; preds = %bb2
+ ret i32 %.0, !dbg !19
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.gv = !{!0}
+
+!0 = metadata !{i32 458804, i32 0, metadata !1, metadata !"Stop", metadata !"Stop", metadata !"", metadata !1, i32 2, metadata !2, i1 true, i1 true, i32* @Stop} ; [ DW_TAG_variable ]
+!1 = metadata !{i32 458769, i32 0, i32 1, metadata !"g.c", metadata !"/tmp", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!2 = metadata !{i32 458788, metadata !1, metadata !"int", metadata !1, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!3 = metadata !{i32 459009, metadata !4, metadata !"i", metadata !1, i32 4, metadata !2} ; [ DW_TAG_arg_variable ]
+!4 = metadata !{i32 458798, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"foo", metadata !1, i32 4, metadata !5, i1 false, i1 true, i32 0, i32 0, null, i1 false} ; [ DW_TAG_subprogram ]
+!5 = metadata !{i32 458773, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !6, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!6 = metadata !{metadata !2, metadata !2}
+!7 = metadata !{i32 5, i32 0, metadata !8, null}
+!8 = metadata !{i32 458763, metadata !4, i32 0, i32 0} ; [ DW_TAG_lexical_block ]
+!9 = metadata !{i32 6, i32 0, metadata !8, null}
+!10 = metadata !{i32 7, i32 0, metadata !8, null}
+!11 = metadata !{i32 9, i32 0, metadata !8, null}
+!12 = metadata !{i32 11, i32 0, metadata !8, null}
+!13 = metadata !{i32 14, i32 0, metadata !14, null}
+!14 = metadata !{i32 458763, metadata !15, i32 0, i32 0} ; [ DW_TAG_lexical_block ]
+!15 = metadata !{i32 458798, i32 0, metadata !1, metadata !"bar", metadata !"bar", metadata !"bar", metadata !1, i32 13, metadata !16, i1 false, i1 true, i32 0, i32 0, null, i1 false} ; [ DW_TAG_subprogram ]
+!16 = metadata !{i32 458773, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !17, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!17 = metadata !{metadata !2}
+!18 = metadata !{i32 15, i32 0, metadata !14, null}
+!19 = metadata !{i32 16, i32 0, metadata !14, null}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll
new file mode 100644
index 0000000..62f75e1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -globalopt -S | grep internal | count 2
+
+global i32 0
+define i32* @1() {
+ ret i32* @0
+}
+define i32* @f() {
+entry:
+ call i32* @1()
+ ret i32* %0
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll
new file mode 100644
index 0000000..d645ce4
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-03-07-PromotePtrToBool.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -globalopt -S | grep {@X = internal unnamed_addr global i32}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+@X = internal global i32* null ; <i32**> [#uses=2]
+@Y = internal global i32 0 ; <i32*> [#uses=1]
+
+define void @foo() nounwind {
+entry:
+ store i32* @Y, i32** @X, align 4
+ ret void
+}
+
+define i32* @get() nounwind {
+entry:
+ %0 = load i32** @X, align 4 ; <i32*> [#uses=1]
+ ret i32* %0
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll
new file mode 100644
index 0000000..d3c3ff5
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-06-01-RecursivePHI.ll
@@ -0,0 +1,122 @@
+; RUN: opt < %s -globalopt
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.s_annealing_sched = type { i32, float, float, float, float }
+ %struct.s_bb = type { i32, i32, i32, i32 }
+ %struct.s_net = type { i8*, i32, i32*, float, float }
+ %struct.s_placer_opts = type { i32, float, i32, i32, i8*, i32, i32 }
+@net = internal global %struct.s_net* null ; <%struct.s_net**> [#uses=4]
+
+define fastcc void @alloc_and_load_placement_structs(i32 %place_cost_type, i32 %num_regions, float %place_cost_exp, float*** nocapture %old_region_occ_x, float*** nocapture %old_region_occ_y) nounwind ssp {
+entry:
+ br i1 undef, label %bb.i, label %my_malloc.exit
+
+bb.i: ; preds = %entry
+ unreachable
+
+my_malloc.exit: ; preds = %entry
+ br i1 undef, label %bb.i81, label %my_malloc.exit83
+
+bb.i81: ; preds = %my_malloc.exit
+ unreachable
+
+my_malloc.exit83: ; preds = %my_malloc.exit
+ br i1 undef, label %bb.i.i57, label %my_calloc.exit.i
+
+bb.i.i57: ; preds = %my_malloc.exit83
+ unreachable
+
+my_calloc.exit.i: ; preds = %my_malloc.exit83
+ br i1 undef, label %bb.i4.i, label %my_calloc.exit5.i
+
+bb.i4.i: ; preds = %my_calloc.exit.i
+ unreachable
+
+my_calloc.exit5.i: ; preds = %my_calloc.exit.i
+ %.pre.i58 = load %struct.s_net** @net, align 4 ; <%struct.s_net*> [#uses=1]
+ br label %bb17.i78
+
+bb1.i61: ; preds = %bb4.preheader.i, %bb1.i61
+ br i1 undef, label %bb1.i61, label %bb5.i62
+
+bb5.i62: ; preds = %bb1.i61
+ br i1 undef, label %bb6.i64, label %bb15.preheader.i
+
+bb15.preheader.i: ; preds = %bb4.preheader.i, %bb5.i62
+ br label %bb16.i77
+
+bb6.i64: ; preds = %bb5.i62
+ br i1 undef, label %bb7.i65, label %bb8.i67
+
+bb7.i65: ; preds = %bb6.i64
+ unreachable
+
+bb8.i67: ; preds = %bb6.i64
+ br i1 undef, label %bb.i1.i68, label %my_malloc.exit.i70
+
+bb.i1.i68: ; preds = %bb8.i67
+ unreachable
+
+my_malloc.exit.i70: ; preds = %bb8.i67
+ %0 = load %struct.s_net** @net, align 4 ; <%struct.s_net*> [#uses=1]
+ br i1 undef, label %bb9.i71, label %bb16.i77
+
+bb9.i71: ; preds = %bb9.i71, %my_malloc.exit.i70
+ %1 = load %struct.s_net** @net, align 4 ; <%struct.s_net*> [#uses=1]
+ br i1 undef, label %bb9.i71, label %bb16.i77
+
+bb16.i77: ; preds = %bb9.i71, %my_malloc.exit.i70, %bb15.preheader.i
+ %.pre41.i.rle244 = phi %struct.s_net* [ %.pre41.i, %bb15.preheader.i ], [ %0, %my_malloc.exit.i70 ], [ %1, %bb9.i71 ] ; <%struct.s_net*> [#uses=1]
+ br label %bb17.i78
+
+bb17.i78: ; preds = %bb16.i77, %my_calloc.exit5.i
+ %.pre41.i = phi %struct.s_net* [ %.pre41.i.rle244, %bb16.i77 ], [ %.pre.i58, %my_calloc.exit5.i ] ; <%struct.s_net*> [#uses=1]
+ br i1 undef, label %bb4.preheader.i, label %alloc_and_load_unique_pin_list.exit
+
+bb4.preheader.i: ; preds = %bb17.i78
+ br i1 undef, label %bb1.i61, label %bb15.preheader.i
+
+alloc_and_load_unique_pin_list.exit: ; preds = %bb17.i78
+ ret void
+}
+
+define void @read_net(i8* %net_file) nounwind ssp {
+entry:
+ br i1 undef, label %bb3.us.us.i, label %bb6.preheader
+
+bb6.preheader: ; preds = %entry
+ br i1 undef, label %bb7, label %bb
+
+bb3.us.us.i: ; preds = %entry
+ unreachable
+
+bb: ; preds = %bb6.preheader
+ br i1 undef, label %bb.i34, label %bb1.i38
+
+bb.i34: ; preds = %bb
+ unreachable
+
+bb1.i38: ; preds = %bb
+ %mallocsize = mul i64 28, undef ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+ %0 = bitcast i8* %malloccall to %struct.s_net* ; <%struct.s_net*> [#uses=1]
+ br i1 undef, label %bb.i1.i39, label %my_malloc.exit2.i
+
+bb.i1.i39: ; preds = %bb1.i38
+ unreachable
+
+my_malloc.exit2.i: ; preds = %bb1.i38
+ store %struct.s_net* %0, %struct.s_net** @net, align 4
+ br i1 undef, label %bb.i7.i40, label %my_malloc.exit8.i
+
+bb.i7.i40: ; preds = %my_malloc.exit2.i
+ unreachable
+
+my_malloc.exit8.i: ; preds = %my_malloc.exit2.i
+ unreachable
+
+bb7: ; preds = %bb6.preheader
+ unreachable
+}
+
+declare noalias i8* @malloc(i64)
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-BrokenPerformHeapAllocSRoA.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-BrokenPerformHeapAllocSRoA.ll
new file mode 100644
index 0000000..54e8f90
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-BrokenPerformHeapAllocSRoA.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+
+%struct.hashheader = type { i16, i16, i16, i16, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, [5 x i8], [13 x i8], i8, i8, i8, [228 x i16], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [228 x i8], [128 x i8], [100 x [11 x i8]], [100 x i32], [100 x i32], i16 }
+%struct.strchartype = type { i8*, i8*, i8* }
+
+@hashheader = internal global %struct.hashheader zeroinitializer, align 32 ; <%struct.hashheader*> [#uses=1]
+@chartypes = internal global %struct.strchartype* null ; <%struct.strchartype**> [#uses=1]
+; CHECK-NOT: @hashheader
+; CHECK-NOT: @chartypes
+
+; based on linit in office-ispell
+define void @test() nounwind ssp {
+ %1 = load i32* getelementptr inbounds (%struct.hashheader* @hashheader, i64 0, i32 13), align 8 ; <i32> [#uses=1]
+ %2 = sext i32 %1 to i64 ; <i64> [#uses=1]
+ %3 = mul i64 %2, ptrtoint (%struct.strchartype* getelementptr (%struct.strchartype* null, i64 1) to i64) ; <i64> [#uses=1]
+ %4 = tail call i8* @malloc(i64 %3) ; <i8*> [#uses=1]
+; CHECK: call i8* @malloc(i64
+ %5 = bitcast i8* %4 to %struct.strchartype* ; <%struct.strchartype*> [#uses=1]
+ store %struct.strchartype* %5, %struct.strchartype** @chartypes, align 8
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-MallocSingleStoreToGlobalVar.ll b/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-MallocSingleStoreToGlobalVar.ll
new file mode 100644
index 0000000..b73f62b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2009-11-16-MallocSingleStoreToGlobalVar.ll
@@ -0,0 +1,30 @@
+; Test ensures that non-optimizable array mallocs are not optimized; specifically
+; GlobalOpt was treating a non-optimizable array malloc as a non-array malloc
+; and optimizing the global object that the malloc was stored to as a single
+; element global. The global object @TOP in this test should not be optimized.
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+
+@TOP = internal global i64* null ; <i64**> [#uses=2]
+; CHECK: @TOP = internal unnamed_addr global i64* null
+@channelColumns = internal global i64 0 ; <i64*> [#uses=2]
+
+; Derived from @DescribeChannel() in yacr2
+define void @test() nounwind ssp {
+ store i64 2335, i64* @channelColumns, align 8
+ %1 = load i64* @channelColumns, align 8 ; <i64> [#uses=1]
+ %2 = shl i64 %1, 3 ; <i64> [#uses=1]
+ %3 = add i64 %2, 8 ; <i64> [#uses=1]
+ %4 = call noalias i8* @malloc(i64 %3) nounwind ; <i8*> [#uses=1]
+; CHECK: call noalias i8* @malloc
+ %5 = bitcast i8* %4 to i64* ; <i64*> [#uses=1]
+ store i64* %5, i64** @TOP, align 8
+ %6 = load i64** @TOP, align 8 ; <i64*> [#uses=1]
+ %7 = getelementptr inbounds i64* %6, i64 13 ; <i64*> [#uses=1]
+ store i64 0, i64* %7, align 8
+ ret void
+}
+
+declare noalias i8* @malloc(i64) nounwind
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2010-02-25-MallocPromote.ll b/src/LLVM/test/Transforms/GlobalOpt/2010-02-25-MallocPromote.ll
new file mode 100644
index 0000000..27352fa
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2010-02-25-MallocPromote.ll
@@ -0,0 +1,18 @@
+; PR6422
+; RUN: opt -globalopt -S %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@fixLRBT = internal global i32* null ; <i32**> [#uses=2]
+
+declare noalias i8* @malloc(i32)
+
+define i32 @parser() nounwind {
+bb918:
+ %malloccall.i10 = call i8* @malloc(i32 16) nounwind ; <i8*> [#uses=1]
+ %0 = bitcast i8* %malloccall.i10 to i32* ; <i32*> [#uses=1]
+ store i32* %0, i32** @fixLRBT, align 8
+ %1 = load i32** @fixLRBT, align 8 ; <i32*> [#uses=0]
+ %A = load i32* %1
+ ret i32 %A
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2010-02-26-MallocSROA.ll b/src/LLVM/test/Transforms/GlobalOpt/2010-02-26-MallocSROA.ll
new file mode 100644
index 0000000..6f1996a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2010-02-26-MallocSROA.ll
@@ -0,0 +1,27 @@
+; RUN: opt -globalopt -S %s
+; PR6435
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.xyz = type { double, i32 }
+
+@Y = internal global %struct.xyz* null ; <%struct.xyz**> [#uses=2]
+@numf2s = external global i32 ; <i32*> [#uses=1]
+
+define fastcc void @init_net() nounwind {
+entry:
+ %0 = load i32* @numf2s, align 4 ; <i32> [#uses=1]
+ %mallocsize2 = shl i32 %0, 4 ; <i32> [#uses=1]
+ %malloccall3 = tail call i8* @malloc(i32 %mallocsize2) nounwind ; <i8*> [#uses=1]
+ %1 = bitcast i8* %malloccall3 to %struct.xyz* ; <%struct.xyz*> [#uses=1]
+ store %struct.xyz* %1, %struct.xyz** @Y, align 8
+ ret void
+}
+
+define fastcc void @load_train(i8* %trainfile, i32 %mode, i32 %objects) nounwind {
+entry:
+ %0 = load %struct.xyz** @Y, align 8 ; <%struct.xyz*> [#uses=0]
+ ret void
+}
+
+declare noalias i8* @malloc(i32)
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2010-10-19-WeakOdr.ll b/src/LLVM/test/Transforms/GlobalOpt/2010-10-19-WeakOdr.ll
new file mode 100644
index 0000000..ad5b440
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2010-10-19-WeakOdr.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+; PR8389: Globals with weak_odr linkage type must not be modified
+
+; CHECK: weak_odr global i32 0
+
+@SomeVar = weak_odr global i32 0
+
+@llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR } ]
+
+define internal void @CTOR() {
+ store i32 23, i32* @SomeVar
+ ret void
+}
+
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll b/src/LLVM/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll
new file mode 100644
index 0000000..321a487
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/2011-04-09-EmptyGlobalCtors.ll
@@ -0,0 +1,5 @@
+; RUN: opt < %s -globalopt -disable-output
+
+%0 = type { i32, void ()* }
+@llvm.global_ctors = appending global [0 x %0] zeroinitializer
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/alias-resolve.ll b/src/LLVM/test/Transforms/GlobalOpt/alias-resolve.ll
new file mode 100644
index 0000000..8451179
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/alias-resolve.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalopt -S > %t
+; RUN: cat %t | grep foo1 | count 1
+; RUN: cat %t | grep foo2 | count 4
+; RUN: cat %t | grep bar1 | count 1
+; RUN: cat %t | grep bar2 | count 4
+
+@foo1 = alias void ()* @foo2
+@foo2 = alias weak void()* @bar1
+@bar1 = alias void ()* @bar2
+
+declare void @bar2()
+
+define void @baz() {
+entry:
+ call void @foo1()
+ call void @foo2()
+ call void @bar1()
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/basictest.ll b/src/LLVM/test/Transforms/GlobalOpt/basictest.ll
new file mode 100644
index 0000000..c687603
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/basictest.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -globalopt -S | not grep global
+
+@X = internal global i32 4 ; <i32*> [#uses=1]
+
+define i32 @foo() {
+ %V = load i32* @X ; <i32> [#uses=1]
+ ret i32 %V
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/constantexpr-dangle.ll b/src/LLVM/test/Transforms/GlobalOpt/constantexpr-dangle.ll
new file mode 100644
index 0000000..e312840
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/constantexpr-dangle.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -globalopt -S | \
+; RUN: grep {internal fastcc float @foo}
+
+define internal float @foo() {
+ ret float 0.000000e+00
+}
+
+define float @bar() {
+ %tmp1 = call float (...)* bitcast (float ()* @foo to float (...)*)( )
+ %tmp2 = fmul float %tmp1, 1.000000e+01 ; <float> [#uses=1]
+ ret float %tmp2
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/constantfold-initializers.ll b/src/LLVM/test/Transforms/GlobalOpt/constantfold-initializers.ll
new file mode 100644
index 0000000..834bd00
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/constantfold-initializers.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -S -globalopt | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+@.str91250 = global [3 x i8] zeroinitializer
+
+; CHECK: @A = global i1 false
+@A = global i1 icmp ne (i64 sub nsw (i64 ptrtoint (i8* getelementptr inbounds ([3 x i8]* @.str91250, i64 0, i64 1) to i64), i64 ptrtoint ([3 x i8]* @.str91250 to i64)), i64 1)
diff --git a/src/LLVM/test/Transforms/GlobalOpt/crash.ll b/src/LLVM/test/Transforms/GlobalOpt/crash.ll
new file mode 100644
index 0000000..366a874
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/crash.ll
@@ -0,0 +1,80 @@
+; RUN: opt -globalopt -disable-output %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.8"
+
+%0 = type { i32, void ()* }
+%struct.btSimdScalar = type { %"union.btSimdScalar::$_14" }
+%"union.btSimdScalar::$_14" = type { <4 x float> }
+
+@_ZL6vTwist = global %struct.btSimdScalar zeroinitializer ; <%struct.btSimdScalar*> [#uses=1]
+@llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I__ZN21btConeTwistConstraintC2Ev }] ; <[12 x %0]*> [#uses=0]
+
+define internal void @_GLOBAL__I__ZN21btConeTwistConstraintC2Ev() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" {
+entry:
+ store float 1.0, float* getelementptr inbounds (%struct.btSimdScalar* @_ZL6vTwist, i32 0, i32 0, i32 0, i32 3), align 4
+ ret void
+}
+
+
+; PR6760
+%T = type { [5 x i32] }
+
+@switch_inf = internal global %T* null
+
+define void @test(i8* %arch_file, i32 %route_type) {
+entry:
+ %A = sext i32 1 to i64
+ %B = mul i64 %A, 20
+ %C = call noalias i8* @malloc(i64 %B) nounwind
+ %D = bitcast i8* %C to %T*
+ store %T* %D, %T** @switch_inf, align 8
+ unreachable
+
+bb.nph.i:
+ %scevgep.i539 = getelementptr i8* %C, i64 4
+ unreachable
+
+xx:
+ %E = load %T** @switch_inf, align 8
+ unreachable
+}
+
+declare noalias i8* @malloc(i64) nounwind
+
+
+; PR8063
+@permute_bitrev.bitrev = internal global i32* null, align 8
+define void @permute_bitrev() nounwind {
+entry:
+ %tmp = load i32** @permute_bitrev.bitrev, align 8
+ %conv = sext i32 0 to i64
+ %mul = mul i64 %conv, 4
+ %call = call i8* @malloc(i64 %mul)
+ %0 = bitcast i8* %call to i32*
+ store i32* %0, i32** @permute_bitrev.bitrev, align 8
+ ret void
+}
+
+
+
+
+@data8 = internal global [8000 x i8] zeroinitializer, align 16
+define void @memset_with_strange_user() ssp {
+ call void @llvm.memset.p0i8.i64(i8* getelementptr inbounds ([8000 x i8]* @data8, i64 0, i64 0), i8 undef, i64 ptrtoint (i8* getelementptr ([8000 x i8]* @data8, i64 1, i64 sub (i64 0, i64 ptrtoint ([8000 x i8]* @data8 to i64))) to i64), i32 16, i1 false)
+ ret void
+}
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+
+
+; PR9856
+@g_52 = internal global i32** null, align 8
+@g_90 = external global i32*, align 8
+
+define void @icmp_user_of_stored_once() nounwind ssp {
+entry:
+ %tmp4 = load i32*** @g_52, align 8
+ store i32** @g_90, i32*** @g_52
+ %cmp17 = icmp ne i32*** undef, @g_52
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-constexpr.ll b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-constexpr.ll
new file mode 100644
index 0000000..204f979
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-constexpr.ll
@@ -0,0 +1,23 @@
+; RUN: opt -globalopt %s -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+%0 = type { i32, void ()* }
+%struct.foo = type { i32* }
+
+@G = global i32 0, align 4
+@H = global i32 0, align 4
+@X = global %struct.foo zeroinitializer, align 8
+@llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @init }]
+
+; PR8710 - GlobalOpt shouldn't change the global's initializer to have this
+; arbitrary constant expression, the code generator can't handle it.
+define internal void @init() {
+entry:
+ %tmp = getelementptr inbounds %struct.foo* @X, i32 0, i32 0
+ store i32* inttoptr (i64 sdiv (i64 ptrtoint (i32* @G to i64), i64 ptrtoint (i32* @H to i64)) to i32*), i32** %tmp, align 8
+ ret void
+}
+
+; CHECK: @init
+; CHECK: store i32*
diff --git a/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-inbounds.ll b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-inbounds.ll
new file mode 100644
index 0000000..9b11985
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt-inbounds.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+; Don't get fooled by the inbounds keyword; it doesn't change
+; the computed address.
+
+; CHECK: @H = global i32 2
+; CHECK: @I = global i32 2
+
+@llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR } ]
+@addr = external global i32
+@G = internal global [6 x [5 x i32]] zeroinitializer
+@H = global i32 80
+@I = global i32 90
+
+define internal void @CTOR() {
+ store i32 1, i32* getelementptr ([6 x [5 x i32]]* @G, i64 0, i64 0, i64 0)
+ store i32 2, i32* getelementptr inbounds ([6 x [5 x i32]]* @G, i64 0, i64 0, i64 0)
+ %t = load i32* getelementptr ([6 x [5 x i32]]* @G, i64 0, i64 0, i64 0)
+ store i32 %t, i32* @H
+ %s = load i32* getelementptr inbounds ([6 x [5 x i32]]* @G, i64 0, i64 0, i64 0)
+ store i32 %s, i32* @I
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt.ll b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt.ll
new file mode 100644
index 0000000..17ff6a5
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/ctor-list-opt.ll
@@ -0,0 +1,100 @@
+; RUN: opt < %s -globalopt -S | not grep CTOR
+@llvm.global_ctors = appending global [11 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @CTOR1 }, { i32, void ()* } { i32 65535, void ()* @CTOR1 }, { i32, void ()* } { i32 65535, void ()* @CTOR2 }, { i32, void ()* } { i32 65535, void ()* @CTOR3 }, { i32, void ()* } { i32 65535, void ()* @CTOR4 }, { i32, void ()* } { i32 65535, void ()* @CTOR5 }, { i32, void ()* } { i32 65535, void ()* @CTOR6 }, { i32, void ()* } { i32 65535, void ()* @CTOR7 }, { i32, void ()* } { i32 65535, void ()* @CTOR8 }, { i32, void ()* } { i32 65535, void ()* @CTOR9 }, { i32, void ()* } { i32 2147483647, void ()* null } ] ; <[10 x { i32, void ()* }]*> [#uses=0]
+@G = global i32 0 ; <i32*> [#uses=1]
+@G2 = global i32 0 ; <i32*> [#uses=1]
+@G3 = global i32 -123 ; <i32*> [#uses=2]
+@X = global { i32, [2 x i32] } { i32 0, [2 x i32] [ i32 17, i32 21 ] } ; <{ i32, [2 x i32] }*> [#uses=2]
+@Y = global i32 -1 ; <i32*> [#uses=2]
+@Z = global i32 123 ; <i32*> [#uses=1]
+@D = global double 0.000000e+00 ; <double*> [#uses=1]
+@CTORGV = internal global i1 false ; <i1*> [#uses=2]
+
+define internal void @CTOR1() {
+ ret void
+}
+
+define internal void @CTOR2() {
+ %A = add i32 1, 23 ; <i32> [#uses=1]
+ store i32 %A, i32* @G
+ store i1 true, i1* @CTORGV
+ ret void
+}
+
+define internal void @CTOR3() {
+ %X = or i1 true, false ; <i1> [#uses=1]
+ br label %Cont
+
+Cont: ; preds = %0
+ br i1 %X, label %S, label %T
+
+S: ; preds = %Cont
+ store i32 24, i32* @G2
+ ret void
+
+T: ; preds = %Cont
+ ret void
+}
+
+define internal void @CTOR4() {
+ %X = load i32* @G3 ; <i32> [#uses=1]
+ %Y = add i32 %X, 123 ; <i32> [#uses=1]
+ store i32 %Y, i32* @G3
+ ret void
+}
+
+define internal void @CTOR5() {
+ %X.2p = getelementptr inbounds { i32, [2 x i32] }* @X, i32 0, i32 1, i32 0 ; <i32*> [#uses=2]
+ %X.2 = load i32* %X.2p ; <i32> [#uses=1]
+ %X.1p = getelementptr inbounds { i32, [2 x i32] }* @X, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %X.2, i32* %X.1p
+ store i32 42, i32* %X.2p
+ ret void
+}
+
+define internal void @CTOR6() {
+ %A = alloca i32 ; <i32*> [#uses=2]
+ %y = load i32* @Y ; <i32> [#uses=1]
+ store i32 %y, i32* %A
+ %Av = load i32* %A ; <i32> [#uses=1]
+ %Av1 = add i32 %Av, 1 ; <i32> [#uses=1]
+ store i32 %Av1, i32* @Y
+ ret void
+}
+
+define internal void @CTOR7() {
+ call void @setto( i32* @Z, i32 0 )
+ ret void
+}
+
+define void @setto(i32* %P, i32 %V) {
+ store i32 %V, i32* %P
+ ret void
+}
+
+declare double @cos(double)
+
+define internal void @CTOR8() {
+ %X = call double @cos( double 0.000000e+00 ) ; <double> [#uses=1]
+ store double %X, double* @D
+ ret void
+}
+
+define i1 @accessor() {
+ %V = load i1* @CTORGV ; <i1> [#uses=1]
+ ret i1 %V
+}
+
+%struct.A = type { i32 }
+%struct.B = type { i32 (...)**, i8*, [4 x i8] }
+@GV1 = global %struct.B zeroinitializer, align 8
+@GV2 = constant [3 x i8*] [i8* inttoptr (i64 16 to i8*), i8* null, i8* bitcast ({ i8*, i8*, i32, i32, i8*, i64 }* null to i8*)]
+; CHECK-NOT: CTOR9
+define internal void @CTOR9() {
+entry:
+ %0 = bitcast %struct.B* @GV1 to i8*
+ %1 = getelementptr inbounds i8* %0, i64 16
+ %2 = bitcast i8* %1 to %struct.A*
+ %3 = bitcast %struct.B* @GV1 to i8***
+ store i8** getelementptr inbounds ([3 x i8*]* @GV2, i64 1, i64 0), i8*** %3
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/cxx-dtor.ll b/src/LLVM/test/Transforms/GlobalOpt/cxx-dtor.ll
new file mode 100644
index 0000000..2263562
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/cxx-dtor.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+%0 = type { i32, void ()* }
+%struct.A = type { i8 }
+
+@a = global %struct.A zeroinitializer, align 1
+@__dso_handle = external global i8*
+@llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }]
+
+; CHECK-NOT: call i32 @__cxa_atexit
+
+define internal void @__cxx_global_var_init() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" {
+ %1 = call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
+ ret void
+}
+
+define linkonce_odr void @_ZN1AD1Ev(%struct.A* %this) nounwind align 2 {
+ call void @_ZN1AD2Ev(%struct.A* %this)
+ ret void
+}
+
+declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
+
+define linkonce_odr void @_ZN1AD2Ev(%struct.A* %this) nounwind align 2 {
+ ret void
+}
+
+define internal void @_GLOBAL__I_a() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" {
+ call void @__cxx_global_var_init()
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/deadglobal-2.ll b/src/LLVM/test/Transforms/GlobalOpt/deadglobal-2.ll
new file mode 100644
index 0000000..4f81819
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/deadglobal-2.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -globalopt -S | not grep internal
+
+; This is a harder case to delete as the GEP has a variable index.
+
+@G = internal global [4 x i32] zeroinitializer
+
+define void @foo(i32 %X) {
+ %Ptr = getelementptr [4 x i32]* @G, i32 0, i32 %X
+ store i32 1, i32* %Ptr
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/deadglobal.ll b/src/LLVM/test/Transforms/GlobalOpt/deadglobal.ll
new file mode 100644
index 0000000..3be4fed
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/deadglobal.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -globalopt -S | not grep internal
+
+@G = internal global i32 123 ; <i32*> [#uses=1]
+
+define void @foo() {
+ store i32 1, i32* @G
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/dg.exp b/src/LLVM/test/Transforms/GlobalOpt/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/GlobalOpt/globalsra-partial.ll b/src/LLVM/test/Transforms/GlobalOpt/globalsra-partial.ll
new file mode 100644
index 0000000..c7a3c10
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/globalsra-partial.ll
@@ -0,0 +1,24 @@
+; In this case, the global can only be broken up by one level.
+
+; RUN: opt < %s -globalopt -S | not grep 12345
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@G = internal global { i32, [4 x float] } zeroinitializer ; <{ i32, [4 x float] }*> [#uses=3]
+
+define void @onlystore() {
+ store i32 12345, i32* getelementptr ({ i32, [4 x float] }* @G, i32 0, i32 0)
+ ret void
+}
+
+define void @storeinit(i32 %i) {
+ %Ptr = getelementptr { i32, [4 x float] }* @G, i32 0, i32 1, i32 %i ; <float*> [#uses=1]
+ store float 1.000000e+00, float* %Ptr
+ ret void
+}
+
+define float @readval(i32 %i) {
+ %Ptr = getelementptr { i32, [4 x float] }* @G, i32 0, i32 1, i32 %i ; <float*> [#uses=1]
+ %V = load float* %Ptr ; <float> [#uses=1]
+ ret float %V
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/globalsra-unknown-index.ll b/src/LLVM/test/Transforms/GlobalOpt/globalsra-unknown-index.ll
new file mode 100644
index 0000000..1e0db6a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/globalsra-unknown-index.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -globalopt -S > %t
+; RUN: grep {@Y = internal unnamed_addr global \\\[3 x \[%\]struct.X\\\] zeroinitializer} %t
+; RUN: grep load %t | count 6
+; RUN: grep {add i32 \[%\]a, \[%\]b} %t | count 3
+
+; globalopt should not sra the global, because it can't see the index.
+
+%struct.X = type { [3 x i32], [3 x i32] }
+
+@Y = internal global [3 x %struct.X] zeroinitializer
+
+@addr = external global i8
+
+define void @frob() {
+ store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 ptrtoint (i8* @addr to i64)), align 4
+ ret void
+}
+define i32 @borf(i64 %i, i64 %j) {
+ %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0
+ %a = load i32* %p
+ %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 0
+ %b = load i32* %q
+ %c = add i32 %a, %b
+ ret i32 %c
+}
+define i32 @borg(i64 %i, i64 %j) {
+ %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 1
+ %a = load i32* %p
+ %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 1
+ %b = load i32* %q
+ %c = add i32 %a, %b
+ ret i32 %c
+}
+define i32 @borh(i64 %i, i64 %j) {
+ %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 2
+ %a = load i32* %p
+ %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 2
+ %b = load i32* %q
+ %c = add i32 %a, %b
+ ret i32 %c
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/globalsra.ll b/src/LLVM/test/Transforms/GlobalOpt/globalsra.ll
new file mode 100644
index 0000000..0c5c0f1
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/globalsra.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -globalopt -S | not grep global
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@G = internal global { i32, float, { double } } {
+ i32 1,
+ float 1.000000e+00,
+ { double } { double 1.727000e+01 } } ; <{ i32, float, { double } }*> [#uses=3]
+
+define void @onlystore() {
+ store i32 123, i32* getelementptr ({ i32, float, { double } }* @G, i32 0, i32 0)
+ ret void
+}
+
+define float @storeinit() {
+ store float 1.000000e+00, float* getelementptr ({ i32, float, { double } }* @G, i32 0, i32 1)
+ %X = load float* getelementptr ({ i32, float, { double } }* @G, i32 0, i32 1) ; <float> [#uses=1]
+ ret float %X
+}
+
+define double @constantize() {
+ %X = load double* getelementptr ({ i32, float, { double } }* @G, i32 0, i32 2, i32 0) ; <double> [#uses=1]
+ ret double %X
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/heap-sra-1.ll b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-1.ll
new file mode 100644
index 0000000..9d5148f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-1.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null
+; CHECK: @X.f0
+; CHECK: @X.f1
+
+define void @bar(i64 %Size) nounwind noinline {
+entry:
+ %mallocsize = mul i64 %Size, 8 ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+ %.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %0 = load %struct.foo** @X, align 4
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ]
+ %sum.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %3, %bb1 ]
+ %1 = getelementptr %struct.foo* %0, i32 %i.0.reg2mem.0, i32 0
+ %2 = load i32* %1, align 4
+ %3 = add i32 %2, %sum.0.reg2mem.0
+ %indvar.next = add i32 %i.0.reg2mem.0, 1
+ %exitcond = icmp eq i32 %indvar.next, 1200
+ br i1 %exitcond, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 %3
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/heap-sra-2.ll b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-2.ll
new file mode 100644
index 0000000..fa8c362
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-2.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
+; CHECK: @X.f0
+; CHECK: @X.f1
+
+define void @bar(i32 %Size) nounwind noinline {
+entry:
+ %malloccall = tail call i8* @malloc(i64 8000000) ; <i8*> [#uses=1]
+ %0 = bitcast i8* %malloccall to [1000000 x %struct.foo]* ; <[1000000 x %struct.foo]*> [#uses=1]
+ %.sub = getelementptr [1000000 x %struct.foo]* %0, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %0 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2]
+ %sum.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %3, %bb1 ] ; <i32> [#uses=1]
+ %1 = getelementptr %struct.foo* %0, i32 %i.0.reg2mem.0, i32 0 ; <i32*> [#uses=1]
+ %2 = load i32* %1, align 4 ; <i32> [#uses=1]
+ %3 = add i32 %2, %sum.0.reg2mem.0 ; <i32> [#uses=2]
+ %indvar.next = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, 1200 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 %3
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/heap-sra-3.ll b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-3.ll
new file mode 100644
index 0000000..e7a877c
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-3.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null
+; CHECK: @X.f0
+; CHECK: @X.f1
+
+define void @bar(i64 %Size) nounwind noinline {
+entry:
+ %mallocsize = mul i64 8, %Size ; <i64> [#uses=1]
+; CHECK: mul i64 %Size, 4
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+ %.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %0 = load %struct.foo** @X, align 4
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ]
+ %sum.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %3, %bb1 ]
+ %1 = getelementptr %struct.foo* %0, i32 %i.0.reg2mem.0, i32 0
+ %2 = load i32* %1, align 4
+ %3 = add i32 %2, %sum.0.reg2mem.0
+ %indvar.next = add i32 %i.0.reg2mem.0, 1
+ %exitcond = icmp eq i32 %indvar.next, 1200
+ br i1 %exitcond, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 %3
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/heap-sra-4.ll b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-4.ll
new file mode 100644
index 0000000..d5a5828
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-4.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null
+; CHECK: @X.f0
+; CHECK: @X.f1
+
+define void @bar(i64 %Size) nounwind noinline {
+entry:
+ %mallocsize = shl i64 %Size, 3 ; <i64> [#uses=1]
+ %malloccall = tail call i8* @malloc(i64 %mallocsize) ; <i8*> [#uses=1]
+; CHECK: mul i64 %Size, 4
+ %.sub = bitcast i8* %malloccall to %struct.foo* ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %0 = load %struct.foo** @X, align 4
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ]
+ %sum.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %3, %bb1 ]
+ %1 = getelementptr %struct.foo* %0, i32 %i.0.reg2mem.0, i32 0
+ %2 = load i32* %1, align 4
+ %3 = add i32 %2, %sum.0.reg2mem.0
+ %indvar.next = add i32 %i.0.reg2mem.0, 1
+ %exitcond = icmp eq i32 %indvar.next, 1200
+ br i1 %exitcond, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 %3
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/heap-sra-phi.ll b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-phi.ll
new file mode 100644
index 0000000..6188e5a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/heap-sra-phi.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -globalopt -S | grep {tmp.f1 = phi i32. }
+; RUN: opt < %s -globalopt -S | grep {tmp.f0 = phi i32. }
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+ %struct.foo = type { i32, i32 }
+@X = internal global %struct.foo* null ; <%struct.foo**> [#uses=2]
+
+define void @bar(i32 %Size) nounwind noinline {
+entry:
+ %malloccall = tail call i8* @malloc(i64 8000000) ; <i8*> [#uses=1]
+ %tmp = bitcast i8* %malloccall to [1000000 x %struct.foo]* ; <[1000000 x %struct.foo]*> [#uses=1]
+ %.sub = getelementptr [1000000 x %struct.foo]* %tmp, i32 0, i32 0 ; <%struct.foo*> [#uses=1]
+ store %struct.foo* %.sub, %struct.foo** @X, align 4
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @baz() nounwind readonly noinline {
+bb1.thread:
+ %tmpLD1 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %tmp = phi %struct.foo* [%tmpLD1, %bb1.thread ], [ %tmpLD2, %bb1 ] ; <i32> [#uses=2]
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2]
+ %sum.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %tmp3, %bb1 ] ; <i32> [#uses=1]
+ %tmp1 = getelementptr %struct.foo* %tmp, i32 %i.0.reg2mem.0, i32 0 ; <i32*> [#uses=1]
+ %tmp2 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ %tmp6 = add i32 %tmp2, %sum.0.reg2mem.0 ; <i32> [#uses=2]
+ %tmp4 = getelementptr %struct.foo* %tmp, i32 %i.0.reg2mem.0, i32 1 ; <i32*> [#uses=1]
+ %tmp5 = load i32 * %tmp4
+ %tmp3 = add i32 %tmp5, %tmp6
+ %indvar.next = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=2]
+
+ %tmpLD2 = load %struct.foo** @X, align 4 ; <%struct.foo*> [#uses=1]
+
+ %exitcond = icmp eq i32 %indvar.next, 1200 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb2, label %bb1
+
+bb2: ; preds = %bb1
+ ret i32 %tmp3
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/integer-bool.ll b/src/LLVM/test/Transforms/GlobalOpt/integer-bool.ll
new file mode 100644
index 0000000..f41f126
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/integer-bool.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -globalopt -instcombine | \
+; RUN: llvm-dis | grep {ret i1 true}
+
+;; check that global opt turns integers that only hold 0 or 1 into bools.
+
+@G = internal global i32 0 ; <i32*> [#uses=3]
+
+define void @set1() {
+ store i32 0, i32* @G
+ ret void
+}
+
+define void @set2() {
+ store i32 1, i32* @G
+ ret void
+}
+
+define i1 @get() {
+ %A = load i32* @G ; <i32> [#uses=1]
+ %C = icmp slt i32 %A, 2 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/iterate.ll b/src/LLVM/test/Transforms/GlobalOpt/iterate.ll
new file mode 100644
index 0000000..8f2ac0a
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/iterate.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -globalopt -S | not grep %G
+
+@G = internal global i32 0 ; <i32*> [#uses=1]
+@H = internal global { i32* } { i32* @G } ; <{ i32* }*> [#uses=1]
+
+define i32 @loadg() {
+ %G = load i32** getelementptr ({ i32* }* @H, i32 0, i32 0) ; <i32*> [#uses=1]
+ %GV = load i32* %G ; <i32> [#uses=1]
+ ret i32 %GV
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/load-store-global.ll b/src/LLVM/test/Transforms/GlobalOpt/load-store-global.ll
new file mode 100644
index 0000000..d73c36e
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/load-store-global.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -globalopt -S | not grep G
+
+@G = internal global i32 17 ; <i32*> [#uses=3]
+
+define void @foo() {
+ %V = load i32* @G ; <i32> [#uses=1]
+ store i32 %V, i32* @G
+ ret void
+}
+
+define i32 @bar() {
+ %X = load i32* @G ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-1.ll b/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-1.ll
new file mode 100644
index 0000000..369de02
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-1.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@G = internal global i32* null ; <i32**> [#uses=3]
+; CHECK-NOT: global
+
+define void @init() {
+ %malloccall = tail call i8* @malloc(i64 4) ; <i8*> [#uses=1]
+ %P = bitcast i8* %malloccall to i32* ; <i32*> [#uses=1]
+ store i32* %P, i32** @G
+ %GV = load i32** @G ; <i32*> [#uses=1]
+ store i32 0, i32* %GV
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
+
+define i32 @get() {
+ %GV = load i32** @G ; <i32*> [#uses=1]
+ %V = load i32* %GV ; <i32> [#uses=1]
+ ret i32 %V
+; CHECK: ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-2.ll b/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-2.ll
new file mode 100644
index 0000000..e5aad8f
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/malloc-promote-2.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@G = internal global i32* null
+
+define void @t() {
+; CHECK: @t()
+; CHECK-NOT: call i8* @malloc
+; CHECK-NEXT: ret void
+ %malloccall = tail call i8* @malloc(i64 mul (i64 100, i64 4))
+ %P = bitcast i8* %malloccall to i32*
+ store i32* %P, i32** @G
+ %GV = load i32** @G
+ %GVe = getelementptr i32* %GV, i32 40
+ store i32 20, i32* %GVe
+ ret void
+}
+
+declare noalias i8* @malloc(i64)
diff --git a/src/LLVM/test/Transforms/GlobalOpt/memcpy.ll b/src/LLVM/test/Transforms/GlobalOpt/memcpy.ll
new file mode 100644
index 0000000..5e87638
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/memcpy.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -globalopt -S | \
+; RUN: grep {G1 = internal unnamed_addr constant}
+
+@G1 = internal global [58 x i8] c"asdlfkajsdlfkajsd;lfkajds;lfkjasd;flkajsd;lkfja;sdlkfjasd\00" ; <[58 x i8]*> [#uses=1]
+
+define void @foo() {
+ %Blah = alloca [58 x i8]
+ %tmp.0 = getelementptr [58 x i8]* %Blah, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp.0, i8* getelementptr inbounds ([58 x i8]* @G1, i32 0, i32 0), i32 58, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/GlobalOpt/memset-null.ll b/src/LLVM/test/Transforms/GlobalOpt/memset-null.ll
new file mode 100644
index 0000000..0153402
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/memset-null.ll
@@ -0,0 +1,29 @@
+; RUN: opt -globalopt %s -S -o - | FileCheck %s
+; PR10047
+
+%0 = type { i32, void ()* }
+%struct.A = type { [100 x i32] }
+
+; CHECK: @a
+@a = global %struct.A zeroinitializer, align 4
+@llvm.global_ctors = appending global [2 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }, %0 { i32 65535, void ()* @_GLOBAL__I_b }]
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+
+; CHECK-NOT: GLOBAL__I_a
+define internal void @_GLOBAL__I_a() nounwind {
+entry:
+ tail call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.A* @a to i8*), i8 0, i64 400, i32 4, i1 false) nounwind
+ ret void
+}
+
+%struct.X = type { i8 }
+@y = global i8* null, align 8
+@x = global %struct.X zeroinitializer, align 1
+
+define internal void @_GLOBAL__I_b() nounwind {
+entry:
+ %tmp.i.i.i = load i8** @y, align 8
+ tail call void @llvm.memset.p0i8.i64(i8* %tmp.i.i.i, i8 0, i64 10, i32 1, i1 false) nounwind
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/memset.ll b/src/LLVM/test/Transforms/GlobalOpt/memset.ll
new file mode 100644
index 0000000..5276f8c
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/memset.ll
@@ -0,0 +1,18 @@
+; both globals are write only, delete them.
+
+; RUN: opt < %s -globalopt -S | not grep internal
+
+@G0 = internal global [58 x i8] c"asdlfkajsdlfkajsd;lfkajds;lfkjasd;flkajsd;lkfja;sdlkfjasd\00" ; <[58 x i8]*> [#uses=1]
+@G1 = internal global [4 x i32] [ i32 1, i32 2, i32 3, i32 4 ] ; <[4 x i32]*> [#uses=1]
+
+define void @foo() {
+ %Blah = alloca [58 x i8]
+ %tmp3 = bitcast [58 x i8]* %Blah to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast ([4 x i32]* @G1 to i8*), i8* %tmp3, i32 16, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([58 x i8]* @G0, i32 0, i32 0), i8 17, i32 58, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/GlobalOpt/metadata.ll b/src/LLVM/test/Transforms/GlobalOpt/metadata.ll
new file mode 100644
index 0000000..730e2b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/metadata.ll
@@ -0,0 +1,26 @@
+; RUN: opt -S -globalopt < %s | FileCheck %s
+
+; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop
+; to null. Function local metadata that references @G from a different function
+; to that containing %G should likewise drop to null.
+@G = internal global i8** null
+
+define i32 @main(i32 %argc, i8** %argv) {
+; CHECK: @main
+; CHECK: %G = alloca
+ store i8** %argv, i8*** @G
+ ret i32 0
+}
+
+define void @foo(i32 %x) {
+ call void @llvm.foo(metadata !{i8*** @G, i32 %x})
+; CHECK: call void @llvm.foo(metadata !{null, i32 %x})
+ ret void
+}
+
+declare void @llvm.foo(metadata) nounwind readnone
+
+!named = !{!0}
+
+!0 = metadata !{i8*** @G}
+; CHECK: !0 = metadata !{null}
diff --git a/src/LLVM/test/Transforms/GlobalOpt/phi-select.ll b/src/LLVM/test/Transforms/GlobalOpt/phi-select.ll
new file mode 100644
index 0000000..ced4653
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/phi-select.ll
@@ -0,0 +1,31 @@
+; Test that PHI nodes and select instructions do not necessarily make stuff
+; non-constant.
+
+; RUN: opt < %s -globalopt -S | not grep global
+
+@X = internal global i32 4 ; <i32*> [#uses=2]
+@Y = internal global i32 5 ; <i32*> [#uses=2]
+
+define i32 @test1(i1 %C) {
+ %P = select i1 %C, i32* @X, i32* @Y ; <i32*> [#uses=1]
+ %V = load i32* %P ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define i32 @test2(i1 %C) {
+; <label>:0
+ br i1 %C, label %T, label %Cont
+
+T: ; preds = %0
+ br label %Cont
+
+Cont: ; preds = %T, %0
+ %P = phi i32* [ @X, %0 ], [ @Y, %T ] ; <i32*> [#uses=1]
+ %V = load i32* %P ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+
+
+
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/storepointer-compare.ll b/src/LLVM/test/Transforms/GlobalOpt/storepointer-compare.ll
new file mode 100644
index 0000000..9dfa756
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/storepointer-compare.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -globalopt -S | \
+; RUN: grep {call void @Actual}
+
+; Check that a comparison does not prevent an indirect call from being made
+; direct. The global will still remain, but indirect call elim is still good.
+
+@G = internal global void ()* null ; <void ()**> [#uses=2]
+
+define internal void @Actual() {
+ ret void
+}
+
+define void @init() {
+ store void ()* @Actual, void ()** @G
+ ret void
+}
+
+define void @doit() {
+ %FP = load void ()** @G ; <void ()*> [#uses=2]
+ %CC = icmp eq void ()* %FP, null ; <i1> [#uses=1]
+ br i1 %CC, label %isNull, label %DoCall
+
+DoCall: ; preds = %0
+ call void %FP( )
+ ret void
+
+isNull: ; preds = %0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/storepointer.ll b/src/LLVM/test/Transforms/GlobalOpt/storepointer.ll
new file mode 100644
index 0000000..a7d46d3
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/storepointer.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalopt -S | not grep global
+
+@G = internal global void ()* null ; <void ()**> [#uses=2]
+
+define internal void @Actual() {
+ ret void
+}
+
+define void @init() {
+ store void ()* @Actual, void ()** @G
+ ret void
+}
+
+define void @doit() {
+ %FP = load void ()** @G ; <void ()*> [#uses=1]
+ call void %FP( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/trivialstore.ll b/src/LLVM/test/Transforms/GlobalOpt/trivialstore.ll
new file mode 100644
index 0000000..94042a5
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/trivialstore.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalopt -S | not grep G
+
+@G = internal global i32 17 ; <i32*> [#uses=3]
+
+define void @foo() {
+ store i32 17, i32* @G
+ ret void
+}
+
+define i32 @bar() {
+ %X = load i32* @G ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+define internal void @dead() {
+ store i32 123, i32* @G
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/undef-init.ll b/src/LLVM/test/Transforms/GlobalOpt/undef-init.ll
new file mode 100644
index 0000000..4186fa9
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/undef-init.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -globalopt -S | not grep store
+
+@llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I__Z3foov } ] ; <[1 x { i32, void ()* }]*> [#uses=0]
+@X.0 = internal global i32 undef ; <i32*> [#uses=2]
+
+define i32 @_Z3foov() {
+entry:
+ %tmp.1 = load i32* @X.0 ; <i32> [#uses=1]
+ ret i32 %tmp.1
+}
+
+define internal void @_GLOBAL__I__Z3foov() {
+entry:
+ store i32 1, i32* @X.0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/GlobalOpt/unnamed-addr.ll b/src/LLVM/test/Transforms/GlobalOpt/unnamed-addr.ll
new file mode 100644
index 0000000..be02821
--- /dev/null
+++ b/src/LLVM/test/Transforms/GlobalOpt/unnamed-addr.ll
@@ -0,0 +1,54 @@
+; RUN: opt %s -globalopt -S | FileCheck %s
+
+@a = internal global i32 0, align 4
+@b = internal global i32 0, align 4
+@c = internal global i32 0, align 4
+@d = internal constant [4 x i8] c"foo\00", align 1
+
+; CHECK: @a = internal global i32 0, align 4
+; CHECK: @b = internal global i32 0, align 4
+; CHECK: @c = internal unnamed_addr global i32 0, align 4
+; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
+
+define i1 @bah(i64 %i) nounwind readonly optsize ssp {
+entry:
+ %arrayidx4 = getelementptr inbounds [4 x i8]* @d, i64 0, i64 %i
+ %tmp5 = load i8* %arrayidx4, align 1
+ %cmp = icmp eq i8 %tmp5, 42
+ ret i1 %cmp
+}
+
+define void @baz(i32 %x) {
+entry:
+ store i32 %x, i32* @a, align 4
+ store i32 %x, i32* @b, align 4
+ store i32 %x, i32* @c, align 4
+ ret void
+}
+
+define i32 @foo(i32* %x) nounwind readnone optsize ssp {
+entry:
+ %cmp = icmp eq i32* %x, @a
+ %conv = zext i1 %cmp to i32
+ ret i32 %conv
+}
+
+define i32 @bar() {
+entry:
+ switch i64 ptrtoint (i32* @b to i64), label %sw.epilog [
+ i64 1, label %return
+ i64 0, label %return
+ ]
+
+sw.epilog:
+ ret i32 0
+
+return:
+ ret i32 1
+}
+
+define i32 @zed() {
+entry:
+ %tmp1 = load i32* @c, align 4
+ ret i32 %tmp1
+}
diff --git a/src/LLVM/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll b/src/LLVM/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll
new file mode 100644
index 0000000..6640336
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -ipconstprop -S | grep {ret i32 %r}
+; Should not propagate the result of a weak function.
+; PR2411
+
+define weak i32 @foo() nounwind {
+entry:
+ ret i32 1
+}
+
+define i32 @main() nounwind {
+entry:
+ %r = call i32 @foo( ) nounwind
+ ret i32 %r
+}
+
diff --git a/src/LLVM/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll b/src/LLVM/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll
new file mode 100644
index 0000000..bd174a8
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll
@@ -0,0 +1,40 @@
+; RUN: llvm-as <%s | opt -ipsccp | llvm-dis | FileCheck %s
+; Don't constant-propagate byval pointers, since they are not pointers!
+; PR5038
+%struct.MYstr = type { i8, i32 }
+@mystr = internal global %struct.MYstr zeroinitializer ; <%struct.MYstr*> [#uses=3]
+define internal void @vfu1(%struct.MYstr* byval align 4 %u) nounwind {
+entry:
+ %0 = getelementptr %struct.MYstr* %u, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 99, i32* %0, align 4
+; CHECK: %struct.MYstr* %u
+ %1 = getelementptr %struct.MYstr* %u, i32 0, i32 0 ; <i8*> [#uses=1]
+ store i8 97, i8* %1, align 4
+; CHECK: %struct.MYstr* %u
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal i32 @vfu2(%struct.MYstr* byval align 4 %u) nounwind readonly {
+entry:
+ %0 = getelementptr %struct.MYstr* %u, i32 0, i32 1 ; <i32*> [#uses=1]
+ %1 = load i32* %0
+; CHECK: load i32* getelementptr inbounds (%struct.MYstr* @mystr, i32 0, i32 1)
+ %2 = getelementptr %struct.MYstr* %u, i32 0, i32 0 ; <i8*> [#uses=1]
+ %3 = load i8* %2
+; CHECK: load i8* getelementptr inbounds (%struct.MYstr* @mystr, i32 0, i32 0)
+ %4 = zext i8 %3 to i32
+ %5 = add i32 %4, %1
+ ret i32 %5
+}
+
+define i32 @unions() nounwind {
+entry:
+ call void @vfu1(%struct.MYstr* byval align 4 @mystr) nounwind
+ %result = call i32 @vfu2(%struct.MYstr* byval align 4 @mystr) nounwind
+
+ ret i32 %result
+}
+
diff --git a/src/LLVM/test/Transforms/IPConstantProp/dangling-block-address.ll b/src/LLVM/test/Transforms/IPConstantProp/dangling-block-address.ll
new file mode 100644
index 0000000..0489dfa
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/dangling-block-address.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -internalize -ipsccp -S | FileCheck %s
+; PR5569
+
+; IPSCCP should prove that the blocks are dead and delete them, and
+; properly handle the dangling blockaddress constants.
+
+; CHECK: @bar.l = internal constant [2 x i8*] [i8* inttoptr (i32 1 to i8*), i8* inttoptr (i32 1 to i8*)]
+
+@code = global [5 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1], align 4 ; <[5 x i32]*> [#uses=0]
+@bar.l = internal constant [2 x i8*] [i8* blockaddress(@bar, %lab0), i8* blockaddress(@bar, %end)] ; <[2 x i8*]*> [#uses=1]
+
+define void @foo(i32 %x) nounwind readnone {
+entry:
+ %b = alloca i32, align 4 ; <i32*> [#uses=1]
+ volatile store i32 -1, i32* %b
+ ret void
+}
+
+define void @bar(i32* nocapture %pc) nounwind readonly {
+entry:
+ br label %indirectgoto
+
+lab0: ; preds = %indirectgoto
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br label %indirectgoto
+
+end: ; preds = %indirectgoto
+ ret void
+
+indirectgoto: ; preds = %lab0, %entry
+ %indvar = phi i32 [ %indvar.next, %lab0 ], [ 0, %entry ] ; <i32> [#uses=2]
+ %pc.addr.0 = getelementptr i32* %pc, i32 %indvar ; <i32*> [#uses=1]
+ %tmp1.pn = load i32* %pc.addr.0 ; <i32> [#uses=1]
+ %indirect.goto.dest.in = getelementptr inbounds [2 x i8*]* @bar.l, i32 0, i32 %tmp1.pn ; <i8**> [#uses=1]
+ %indirect.goto.dest = load i8** %indirect.goto.dest.in ; <i8*> [#uses=1]
+ indirectbr i8* %indirect.goto.dest, [label %lab0, label %end]
+}
+
+define i32 @main() nounwind readnone {
+entry:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/IPConstantProp/deadarg.ll b/src/LLVM/test/Transforms/IPConstantProp/deadarg.ll
new file mode 100644
index 0000000..8f037af
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/deadarg.ll
@@ -0,0 +1,6 @@
+; RUN: opt < %s -ipconstprop -disable-output
+define internal void @foo(i32 %X) {
+ call void @foo( i32 %X )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IPConstantProp/dg.exp b/src/LLVM/test/Transforms/IPConstantProp/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/IPConstantProp/global.ll b/src/LLVM/test/Transforms/IPConstantProp/global.ll
new file mode 100644
index 0000000..6715293
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/global.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -S -ipsccp | FileCheck %s
+
+@_ZL6test1g = internal global i32 42, align 4
+
+define void @_Z7test1f1v() nounwind {
+entry:
+ %tmp = load i32* @_ZL6test1g, align 4
+ %cmp = icmp eq i32 %tmp, 0
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ store i32 0, i32* @_ZL6test1g, align 4
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ ret void
+}
+
+; CHECK: @_Z7test1f2v()
+; CHECK: entry:
+; CHECK-NEXT: ret i32 42
+define i32 @_Z7test1f2v() nounwind {
+entry:
+ %tmp = load i32* @_ZL6test1g, align 4
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/IPConstantProp/recursion.ll b/src/LLVM/test/Transforms/IPConstantProp/recursion.ll
new file mode 100644
index 0000000..8f44ed1
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/recursion.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -ipconstprop -deadargelim -S | not grep %X
+define internal i32 @foo(i32 %X) {
+ %Y = call i32 @foo( i32 %X ) ; <i32> [#uses=1]
+ %Z = add i32 %Y, 1 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define void @bar() {
+ call i32 @foo( i32 17 ) ; <i32>:1 [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IPConstantProp/return-argument.ll b/src/LLVM/test/Transforms/IPConstantProp/return-argument.ll
new file mode 100644
index 0000000..f4b7018
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/return-argument.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -ipconstprop -S > %t
+; RUN: cat %t | grep {store i32 %Z, i32\\* %Q}
+; RUN: cat %t | grep {add i32 1, 3}
+
+;; This function returns its second argument on all return statements
+define internal i32* @incdec(i1 %C, i32* %V) {
+ %X = load i32* %V
+ br i1 %C, label %T, label %F
+
+T: ; preds = %0
+ %X1 = add i32 %X, 1
+ store i32 %X1, i32* %V
+ ret i32* %V
+
+F: ; preds = %0
+ %X2 = sub i32 %X, 1
+ store i32 %X2, i32* %V
+ ret i32* %V
+}
+
+;; This function returns its first argument as a part of a multiple return
+;; value
+define internal { i32, i32 } @foo(i32 %A, i32 %B) {
+ %X = add i32 %A, %B
+ %Y = insertvalue { i32, i32 } undef, i32 %A, 0
+ %Z = insertvalue { i32, i32 } %Y, i32 %X, 1
+ ret { i32, i32 } %Z
+}
+
+define void @caller(i1 %C) {
+ %Q = alloca i32
+ ;; Call incdec to see if %W is properly replaced by %Q
+ %W = call i32* @incdec(i1 %C, i32* %Q ) ; <i32> [#uses=1]
+ ;; Call @foo twice, to prevent the arguments from propagating into the
+ ;; function (so we can check the returned argument is properly
+ ;; propagated per-caller).
+ %S1 = call { i32, i32 } @foo(i32 1, i32 2)
+ %X1 = extractvalue { i32, i32 } %S1, 0
+ %S2 = invoke { i32, i32 } @foo(i32 3, i32 4) to label %OK unwind label %LPAD
+
+OK:
+ %X2 = extractvalue { i32, i32 } %S2, 0
+ ;; Do some stuff with the returned values which we can grep for
+ %Z = add i32 %X1, %X2
+ store i32 %Z, i32* %W
+ br label %RET
+
+LPAD:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ br label %RET
+
+RET:
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/IPConstantProp/return-constant.ll b/src/LLVM/test/Transforms/IPConstantProp/return-constant.ll
new file mode 100644
index 0000000..b97bc2d
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/return-constant.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -ipconstprop -instcombine | \
+; RUN: llvm-dis | grep {ret i1 true} | count 2
+define internal i32 @foo(i1 %C) {
+ br i1 %C, label %T, label %F
+
+T: ; preds = %0
+ ret i32 52
+
+F: ; preds = %0
+ ret i32 52
+}
+
+define i1 @caller(i1 %C) {
+ %X = call i32 @foo( i1 %C ) ; <i32> [#uses=1]
+ %Y = icmp ne i32 %X, 0 ; <i1> [#uses=1]
+ ret i1 %Y
+}
+
+define i1 @invokecaller(i1 %C) {
+ %X = invoke i32 @foo( i1 %C ) to label %OK unwind label %FAIL ; <i32> [#uses=1]
+OK:
+ %Y = icmp ne i32 %X, 0 ; <i1> [#uses=1]
+ ret i1 %Y
+FAIL:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i1 false
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/IPConstantProp/return-constants.ll b/src/LLVM/test/Transforms/IPConstantProp/return-constants.ll
new file mode 100644
index 0000000..2cd99fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/return-constants.ll
@@ -0,0 +1,46 @@
+; RUN: opt < %s -ipconstprop -S > %t
+;; Check that the 21 constants got propagated properly
+; RUN: cat %t | grep {%M = add i32 21, 21}
+;; Check that the second return values didn't get propagated
+; RUN: cat %t | grep {%N = add i32 %B, %D}
+
+%0 = type { i32, i32 }
+
+define internal %0 @foo(i1 %Q) {
+ br i1 %Q, label %T, label %F
+
+T: ; preds = %0
+ %mrv = insertvalue %0 undef, i32 21, 0
+ %mrv1 = insertvalue %0 %mrv, i32 22, 1
+ ret %0 %mrv1
+
+F: ; preds = %0
+ %mrv2 = insertvalue %0 undef, i32 21, 0
+ %mrv3 = insertvalue %0 %mrv2, i32 23, 1
+ ret %0 %mrv3
+}
+
+define internal %0 @bar(i1 %Q) {
+ %A = insertvalue %0 undef, i32 21, 0
+ br i1 %Q, label %T, label %F
+
+T: ; preds = %0
+ %B = insertvalue %0 %A, i32 22, 1
+ ret %0 %B
+
+F: ; preds = %0
+ %C = insertvalue %0 %A, i32 23, 1
+ ret %0 %C
+}
+
+define %0 @caller(i1 %Q) {
+ %X = call %0 @foo(i1 %Q)
+ %A = extractvalue %0 %X, 0
+ %B = extractvalue %0 %X, 1
+ %Y = call %0 @bar(i1 %Q)
+ %C = extractvalue %0 %Y, 0
+ %D = extractvalue %0 %Y, 1
+ %M = add i32 %A, %C
+ %N = add i32 %B, %D
+ ret %0 %X
+}
diff --git a/src/LLVM/test/Transforms/IPConstantProp/user-with-multiple-uses.ll b/src/LLVM/test/Transforms/IPConstantProp/user-with-multiple-uses.ll
new file mode 100644
index 0000000..402ea41
--- /dev/null
+++ b/src/LLVM/test/Transforms/IPConstantProp/user-with-multiple-uses.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -S -ipsccp | FileCheck %s
+; PR5596
+
+; IPSCCP should propagate the 0 argument, eliminate the switch, and propagate
+; the result.
+
+; CHECK: define i32 @main() noreturn nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %call2 = tail call i32 @wwrite(i64 0) nounwind
+; CHECK-NEXT: ret i32 123
+
+define i32 @main() noreturn nounwind {
+entry:
+ %call2 = tail call i32 @wwrite(i64 0) nounwind
+ ret i32 %call2
+}
+
+define internal i32 @wwrite(i64 %i) nounwind readnone {
+entry:
+ switch i64 %i, label %sw.default [
+ i64 3, label %return
+ i64 10, label %return
+ ]
+
+sw.default:
+ ret i32 123
+
+return:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2002-09-09-PointerIndVar.ll b/src/LLVM/test/Transforms/IndVarSimplify/2002-09-09-PointerIndVar.ll
new file mode 100644
index 0000000..757ebaf
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2002-09-09-PointerIndVar.ll
@@ -0,0 +1,17 @@
+; Induction variable pass is doing bad things with pointer induction vars,
+; trying to do arithmetic on them directly.
+;
+; RUN: opt < %s -indvars
+;
+define void @test(i32 %A, i32 %S, i8* %S.upgrd.1) {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %PIV = phi i8* [ %S.upgrd.1, %0 ], [ %PIVNext.upgrd.3, %Loop ] ; <i8*> [#uses=1]
+ %PIV.upgrd.2 = ptrtoint i8* %PIV to i64 ; <i64> [#uses=1]
+ %PIVNext = add i64 %PIV.upgrd.2, 8 ; <i64> [#uses=1]
+ %PIVNext.upgrd.3 = inttoptr i64 %PIVNext to i8* ; <i8*> [#uses=1]
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2003-04-16-ExprAnalysis.ll b/src/LLVM/test/Transforms/IndVarSimplify/2003-04-16-ExprAnalysis.ll
new file mode 100644
index 0000000..642fc5e
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2003-04-16-ExprAnalysis.ll
@@ -0,0 +1,17 @@
+; This is a test case for the expression analysis code, not really indvars.
+; It was assuming any constant of int type was a ConstantInteger.
+;
+; RUN: opt < %s -indvars
+
+@X = global i32 7 ; <i32*> [#uses=1]
+
+define void @test(i32 %A) {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %IV = phi i32 [ %A, %0 ], [ %IVNext, %Loop ] ; <i32> [#uses=1]
+ %IVNext = add i32 %IV, ptrtoint (i32* @X to i32) ; <i32> [#uses=1]
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2003-09-23-NotAtTop.ll b/src/LLVM/test/Transforms/IndVarSimplify/2003-09-23-NotAtTop.ll
new file mode 100644
index 0000000..13121bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2003-09-23-NotAtTop.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -indvars %s | FileCheck %s
+
+; The indvar simplification code should ensure that the first PHI in the block
+; is the canonical one!
+
+define i32 @test() {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+; CHECK: Loop:
+; CHECK-NEXT: Canonical
+ %NonIndvar = phi i32 [ 200, %0 ], [ %NonIndvarNext, %Loop ] ; <i32> [#uses=1]
+ %Canonical = phi i32 [ 0, %0 ], [ %CanonicalNext, %Loop ] ; <i32> [#uses=2]
+ store i32 %Canonical, i32* null
+ %NonIndvarNext = sdiv i32 %NonIndvar, 2 ; <i32> [#uses=1]
+ %CanonicalNext = add i32 %Canonical, 1 ; <i32> [#uses=1]
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2003-12-10-RemoveInstrCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2003-12-10-RemoveInstrCrash.ll
new file mode 100644
index 0000000..4fc148f
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2003-12-10-RemoveInstrCrash.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @test() {
+entry:
+ %inc.2 = add i32 1, 1 ; <i32> [#uses=1]
+ br i1 false, label %no_exit, label %loopexit
+
+no_exit: ; preds = %no_exit, %entry
+ %j.0.pn = phi i32 [ %inc.3, %no_exit ], [ %inc.2, %entry ] ; <i32> [#uses=1]
+ %k.0.pn = phi i32 [ %inc.4, %no_exit ], [ 1, %entry ] ; <i32> [#uses=1]
+ %inc.3 = add i32 %j.0.pn, 1 ; <i32> [#uses=1]
+ %inc.4 = add i32 %k.0.pn, 1 ; <i32> [#uses=1]
+ br i1 undef, label %no_exit, label %loopexit
+
+loopexit: ; preds = %no_exit, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2003-12-15-Crash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2003-12-15-Crash.ll
new file mode 100644
index 0000000..9340c06
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2003-12-15-Crash.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -indvars -disable-output
+define void @_ZN17CoinFactorization7cleanupEv() {
+entry:
+ br i1 false, label %loopexit.14, label %cond_continue.3
+
+cond_continue.3: ; preds = %entry
+ ret void
+
+loopexit.14: ; preds = %entry
+ %tmp.738 = sub i32 0, 0 ; <i32> [#uses=1]
+ br i1 undef, label %no_exit.15.preheader, label %loopexit.15
+
+no_exit.15.preheader: ; preds = %loopexit.14
+ br label %no_exit.15
+
+no_exit.15: ; preds = %no_exit.15, %no_exit.15.preheader
+ %highC.0 = phi i32 [ %tmp.738, %no_exit.15.preheader ], [ %dec.0, %no_exit.15 ] ; <i32> [#uses=1]
+ %dec.0 = add i32 %highC.0, -1 ; <i32> [#uses=1]
+ br i1 undef, label %no_exit.15, label %loopexit.15
+
+loopexit.15: ; preds = %no_exit.15, %loopexit.14
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2004-03-10-PHIInsertionBug.ll b/src/LLVM/test/Transforms/IndVarSimplify/2004-03-10-PHIInsertionBug.ll
new file mode 100644
index 0000000..4e85c26
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2004-03-10-PHIInsertionBug.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @test() {
+ br label %endif.0.i
+
+endif.0.i: ; preds = %0
+ br i1 false, label %then.3.i, label %endif.3.i
+
+then.3.i: ; preds = %endif.0.i
+ br label %endif.3.i
+
+endif.3.i: ; preds = %then.3.i, %endif.0.i
+ %inxm.0.i = phi i32 [ 8, %then.3.i ], [ 0, %endif.0.i ] ; <i32> [#uses=1]
+ %doinner.1.i = phi i32 [ 0, %then.3.i ], [ 0, %endif.0.i ] ; <i32> [#uses=0]
+ br label %loopentry.2.i
+
+loopentry.2.i: ; preds = %no_exit.2.i, %endif.3.i
+ %inxk.0.i = phi i32 [ %tmp.210.i, %no_exit.2.i ], [ 0, %endif.3.i ] ; <i32> [#uses=1]
+ br label %no_exit.2.i
+
+no_exit.2.i: ; preds = %loopentry.2.i
+ %tmp.210.i = sub i32 %inxk.0.i, %inxm.0.i ; <i32> [#uses=2]
+ %tmp.213.i = add i32 %tmp.210.i, 0 ; <i32> [#uses=0]
+ br label %loopentry.2.i
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2004-04-05-InvokeCastCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2004-04-05-InvokeCastCrash.ll
new file mode 100644
index 0000000..c8057f9
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2004-04-05-InvokeCastCrash.ll
@@ -0,0 +1,291 @@
+; RUN: opt < %s -indvars -disable-output
+; ModuleID = '2004-04-05-InvokeCastCrash.ll'
+ %struct.__false_type = type { i8 }
+ %"struct.__gnu_cxx::_Hashtable_node<const llvm::Constant*>" = type { %"struct.__gnu_cxx::_Hashtable_node<const llvm::Constant*>"*, %"struct.llvm::Constant"* }
+ %"struct.__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >" = type { %"struct.__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >"*, %"struct.std::pair<const llvm::Value* const,int>" }
+ %"struct.__gnu_cxx::hash_map<const llvm::Value*,int,__gnu_cxx::hash<const llvm::Value*>,std::equal_to<const llvm::Value*>,std::allocator<int> >" = type { %"struct.__gnu_cxx::hashtable<std::pair<const llvm::Value* const, int>,const llvm::Value*,__gnu_cxx::hash<const llvm::Value*>,std::_Select1st<std::pair<const llvm::Value* const, int> >,std::equal_to<const llvm::Value*>,std::allocator<int> >" }
+ %"struct.__gnu_cxx::hash_set<const llvm::Constant*,__gnu_cxx::hash<const llvm::Constant*>,std::equal_to<const llvm::Constant*>,std::allocator<const llvm::Constant*> >" = type { %"struct.__gnu_cxx::hashtable<const llvm::Constant*,const llvm::Constant*,__gnu_cxx::hash<const llvm::Constant*>,std::_Identity<const llvm::Constant*>,std::equal_to<const llvm::Constant*>,std::allocator<const llvm::Constant*> >" }
+ %"struct.__gnu_cxx::hashtable<const llvm::Constant*,const llvm::Constant*,__gnu_cxx::hash<const llvm::Constant*>,std::_Identity<const llvm::Constant*>,std::equal_to<const llvm::Constant*>,std::allocator<const llvm::Constant*> >" = type { %struct.__false_type, %struct.__false_type, %struct.__false_type, %struct.__false_type, %"struct.std::vector<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*> >", i32 }
+ %"struct.__gnu_cxx::hashtable<std::pair<const llvm::Value* const, int>,const llvm::Value*,__gnu_cxx::hash<const llvm::Value*>,std::_Select1st<std::pair<const llvm::Value* const, int> >,std::equal_to<const llvm::Value*>,std::allocator<int> >" = type { %struct.__false_type, %struct.__false_type, %struct.__false_type, %struct.__false_type, %"struct.std::vector<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int> >", i32 }
+ %"struct.llvm::AbstractTypeUser" = type { i32 (...)** }
+ %"struct.llvm::Annotable" = type { i32 (...)**, %"struct.llvm::Annotation"* }
+ %"struct.llvm::Annotation" = type { i32 (...)**, %"struct.llvm::AnnotationID", %"struct.llvm::Annotation"* }
+ %"struct.llvm::AnnotationID" = type { i32 }
+ %"struct.llvm::Argument" = type { %"struct.llvm::Value", %"struct.llvm::Function"*, %"struct.llvm::Argument"*, %"struct.llvm::Argument"* }
+ %"struct.llvm::BasicBlock" = type { %"struct.llvm::Value", %"struct.llvm::iplist<llvm::Instruction,llvm::ilist_traits<llvm::Instruction> >", %"struct.llvm::BasicBlock"*, %"struct.llvm::BasicBlock"* }
+ %"struct.llvm::Constant" = type opaque
+ %"struct.llvm::DerivedType" = type { %"struct.llvm::Type", %"struct.llvm::AbstractTypeUser", %"struct.std::vector<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*> >" }
+ %"struct.llvm::Function" = type { %"struct.llvm::GlobalValue", %"struct.llvm::Annotable", %"struct.llvm::iplist<llvm::BasicBlock,llvm::ilist_traits<llvm::BasicBlock> >", %"struct.llvm::iplist<llvm::Argument,llvm::ilist_traits<llvm::Argument> >", %"struct.llvm::SymbolTable"*, %"struct.llvm::Function"*, %"struct.llvm::Function"* }
+ %"struct.llvm::FunctionPass" = type { %"struct.llvm::Pass" }
+ %"struct.llvm::FunctionType" = type { %"struct.llvm::DerivedType", i1 }
+ %"struct.llvm::GlobalValue" = type { %"struct.llvm::User", i32, %"struct.llvm::Module"* }
+ %"struct.llvm::Instruction" = type { %"struct.llvm::User", %"struct.llvm::Annotable", %"struct.llvm::BasicBlock"*, %"struct.llvm::Instruction"*, %"struct.llvm::Instruction"*, i32 }
+ %"struct.llvm::IntrinsicLowering" = type opaque
+ %"struct.llvm::MachineBasicBlock" = type { %"struct.llvm::ilist<llvm::MachineInstr>", %"struct.llvm::MachineBasicBlock"*, %"struct.llvm::MachineBasicBlock"*, %"struct.llvm::BasicBlock"* }
+ %"struct.llvm::MachineConstantPool" = type opaque
+ %"struct.llvm::MachineFrameInfo" = type opaque
+ %"struct.llvm::MachineFunction" = type { %"struct.llvm::Annotation", %"struct.llvm::Function"*, %"struct.llvm::TargetMachine"*, %"struct.llvm::iplist<llvm::MachineBasicBlock,llvm::ilist_traits<llvm::MachineBasicBlock> >", %"struct.llvm::SSARegMap"*, %"struct.llvm::MachineFunctionInfo"*, %"struct.llvm::MachineFrameInfo"*, %"struct.llvm::MachineConstantPool"* }
+ %"struct.llvm::MachineFunctionInfo" = type { %"struct.__gnu_cxx::hash_set<const llvm::Constant*,__gnu_cxx::hash<const llvm::Constant*>,std::equal_to<const llvm::Constant*>,std::allocator<const llvm::Constant*> >", %"struct.__gnu_cxx::hash_map<const llvm::Value*,int,__gnu_cxx::hash<const llvm::Value*>,std::equal_to<const llvm::Value*>,std::allocator<int> >", i32, i32, i32, i32, i32, i32, i32, i1, i1, i1, %"struct.llvm::MachineFunction"* }
+ %"struct.llvm::MachineFunctionPass" = type { %"struct.llvm::FunctionPass" }
+ %"struct.llvm::MachineInstr" = type { i16, i8, %"struct.std::vector<llvm::MachineOperand,std::allocator<llvm::MachineOperand> >", %"struct.llvm::MachineInstr"*, %"struct.llvm::MachineInstr"*, %"struct.llvm::MachineBasicBlock"* }
+ %"struct.llvm::MachineInstrBuilder" = type { %"struct.llvm::MachineInstr"* }
+ %"struct.llvm::MachineOperand" = type { %"union.llvm::MachineOperand::._65", i32, i32 }
+ %"struct.llvm::Module" = type opaque
+ %"struct.llvm::PATypeHandle" = type { %"struct.llvm::Type"*, %"struct.llvm::AbstractTypeUser"* }
+ %"struct.llvm::PATypeHolder" = type { %"struct.llvm::Type"* }
+ %"struct.llvm::Pass" = type { i32 (...)**, %"struct.llvm::AbstractTypeUser"*, %"struct.llvm::PassInfo"*, %"struct.std::vector<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> > >" }
+ %"struct.llvm::PassInfo" = type { i8*, i8*, %"struct.std::type_info"*, i8, %"struct.std::vector<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*> >", %"struct.llvm::Pass"* ()*, %"struct.llvm::Pass"* (%"struct.llvm::TargetMachine"*)* }
+ %"struct.llvm::SSARegMap" = type opaque
+ %"struct.llvm::SymbolTable" = type opaque
+ %"struct.llvm::SymbolTableListTraits<llvm::Argument,llvm::Function,llvm::Function,llvm::ilist_traits<llvm::Argument> >" = type { %"struct.llvm::Function"*, %"struct.llvm::Function"* }
+ %"struct.llvm::SymbolTableListTraits<llvm::Instruction,llvm::BasicBlock,llvm::Function,llvm::ilist_traits<llvm::Instruction> >" = type { %"struct.llvm::Function"*, %"struct.llvm::BasicBlock"* }
+ %"struct.llvm::TargetData" = type { %"struct.llvm::FunctionPass", i1, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %"struct.llvm::TargetFrameInfo" = type { i32 (...)**, i32, i32, i32 }
+ %"struct.llvm::TargetInstrDescriptor" = type { i8*, i32, i32, i32, i1, i32, i32, i32, i32, i32, i32*, i32* }
+ %"struct.llvm::TargetInstrInfo" = type { i32 (...)**, %"struct.llvm::TargetInstrDescriptor"*, i32, i32 }
+ %"struct.llvm::TargetMachine" = type { i32 (...)**, %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >", %"struct.llvm::TargetData", %"struct.llvm::IntrinsicLowering"* }
+ %"struct.llvm::TargetRegClassInfo" = type { i32 (...)**, i32, i32, i32 }
+ %"struct.llvm::TargetRegInfo" = type { i32 (...)**, %"struct.std::vector<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*> >", %"struct.llvm::TargetMachine"* }
+ %"struct.llvm::Type" = type { %"struct.llvm::Value", i32, i32, i1, i32, %"struct.llvm::Type"*, %"struct.std::vector<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle> >" }
+ %"struct.llvm::Use" = type { %"struct.llvm::Value"*, %"struct.llvm::User"*, %"struct.llvm::Use"*, %"struct.llvm::Use"* }
+ %"struct.llvm::User" = type { %"struct.llvm::Value", %"struct.std::vector<llvm::Use,std::allocator<llvm::Use> >" }
+ %"struct.llvm::Value" = type { i32 (...)**, %"struct.llvm::iplist<llvm::Use,llvm::ilist_traits<llvm::Use> >", %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >", %"struct.llvm::PATypeHolder", i32 }
+ %"struct.llvm::_GLOBAL__N_::InsertPrologEpilogCode" = type { %"struct.llvm::MachineFunctionPass" }
+ %"struct.llvm::ilist<llvm::MachineInstr>" = type { %"struct.llvm::iplist<llvm::MachineInstr,llvm::ilist_traits<llvm::MachineInstr> >" }
+ %"struct.llvm::ilist_iterator<const llvm::MachineBasicBlock>" = type { %"struct.llvm::MachineBasicBlock"* }
+ %"struct.llvm::ilist_traits<llvm::Argument>" = type { %"struct.llvm::SymbolTableListTraits<llvm::Argument,llvm::Function,llvm::Function,llvm::ilist_traits<llvm::Argument> >" }
+ %"struct.llvm::ilist_traits<llvm::Instruction>" = type { %"struct.llvm::SymbolTableListTraits<llvm::Instruction,llvm::BasicBlock,llvm::Function,llvm::ilist_traits<llvm::Instruction> >" }
+ %"struct.llvm::iplist<llvm::Argument,llvm::ilist_traits<llvm::Argument> >" = type { %"struct.llvm::ilist_traits<llvm::Argument>", %"struct.llvm::Argument"*, %"struct.llvm::Argument"* }
+ %"struct.llvm::iplist<llvm::BasicBlock,llvm::ilist_traits<llvm::BasicBlock> >" = type { %"struct.llvm::ilist_traits<llvm::Argument>", %"struct.llvm::BasicBlock"*, %"struct.llvm::BasicBlock"* }
+ %"struct.llvm::iplist<llvm::Instruction,llvm::ilist_traits<llvm::Instruction> >" = type { %"struct.llvm::ilist_traits<llvm::Instruction>", %"struct.llvm::Instruction"*, %"struct.llvm::Instruction"* }
+ %"struct.llvm::iplist<llvm::MachineBasicBlock,llvm::ilist_traits<llvm::MachineBasicBlock> >" = type { %"struct.llvm::MachineBasicBlock"*, %"struct.llvm::MachineBasicBlock"* }
+ %"struct.llvm::iplist<llvm::MachineInstr,llvm::ilist_traits<llvm::MachineInstr> >" = type { %"struct.llvm::ilist_iterator<const llvm::MachineBasicBlock>", %"struct.llvm::MachineInstr"*, %"struct.llvm::MachineInstr"* }
+ %"struct.llvm::iplist<llvm::Use,llvm::ilist_traits<llvm::Use> >" = type { %"struct.llvm::Use"*, %"struct.llvm::Use"* }
+ %"struct.std::_Vector_alloc_base<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*>, true>" = type { %"struct.__gnu_cxx::_Hashtable_node<const llvm::Constant*>"**, %"struct.__gnu_cxx::_Hashtable_node<const llvm::Constant*>"**, %"struct.__gnu_cxx::_Hashtable_node<const llvm::Constant*>"** }
+ %"struct.std::_Vector_alloc_base<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int>, true>" = type { %"struct.__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >"**, %"struct.__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >"**, %"struct.__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >"** }
+ %"struct.std::_Vector_alloc_base<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*>, true>" = type { %"struct.llvm::PassInfo"**, %"struct.llvm::PassInfo"**, %"struct.llvm::PassInfo"** }
+ %"struct.std::_Vector_alloc_base<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*>, true>" = type { %"struct.llvm::TargetFrameInfo"**, %"struct.llvm::TargetFrameInfo"**, %"struct.llvm::TargetFrameInfo"** }
+ %"struct.std::_Vector_alloc_base<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*>, true>" = type { %"struct.llvm::AbstractTypeUser"**, %"struct.llvm::AbstractTypeUser"**, %"struct.llvm::AbstractTypeUser"** }
+ %"struct.std::_Vector_alloc_base<llvm::MachineInstr*,std::allocator<llvm::MachineInstr*>, true>" = type { %"struct.llvm::MachineInstr"**, %"struct.llvm::MachineInstr"**, %"struct.llvm::MachineInstr"** }
+ %"struct.std::_Vector_alloc_base<llvm::MachineOperand,std::allocator<llvm::MachineOperand>, true>" = type { %"struct.llvm::MachineOperand"*, %"struct.llvm::MachineOperand"*, %"struct.llvm::MachineOperand"* }
+ %"struct.std::_Vector_alloc_base<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle>, true>" = type { %"struct.llvm::PATypeHandle"*, %"struct.llvm::PATypeHandle"*, %"struct.llvm::PATypeHandle"* }
+ %"struct.std::_Vector_alloc_base<llvm::Use,std::allocator<llvm::Use>, true>" = type { %"struct.llvm::Use"*, %"struct.llvm::Use"*, %"struct.llvm::Use"* }
+ %"struct.std::_Vector_alloc_base<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> >, true>" = type { %"struct.std::pair<const llvm::PassInfo*,llvm::Pass*>"*, %"struct.std::pair<const llvm::PassInfo*,llvm::Pass*>"*, %"struct.std::pair<const llvm::PassInfo*,llvm::Pass*>"* }
+ %"struct.std::_Vector_base<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*> >" = type { %"struct.std::_Vector_alloc_base<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*>, true>" }
+ %"struct.std::_Vector_base<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int> >" = type { %"struct.std::_Vector_alloc_base<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int>, true>" }
+ %"struct.std::_Vector_base<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*> >" = type { %"struct.std::_Vector_alloc_base<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*>, true>" }
+ %"struct.std::_Vector_base<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*> >" = type { %"struct.std::_Vector_alloc_base<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*>, true>" }
+ %"struct.std::_Vector_base<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*> >" = type { %"struct.std::_Vector_alloc_base<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*>, true>" }
+ %"struct.std::_Vector_base<llvm::MachineInstr*,std::allocator<llvm::MachineInstr*> >" = type { %"struct.std::_Vector_alloc_base<llvm::MachineInstr*,std::allocator<llvm::MachineInstr*>, true>" }
+ %"struct.std::_Vector_base<llvm::MachineOperand,std::allocator<llvm::MachineOperand> >" = type { %"struct.std::_Vector_alloc_base<llvm::MachineOperand,std::allocator<llvm::MachineOperand>, true>" }
+ %"struct.std::_Vector_base<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle> >" = type { %"struct.std::_Vector_alloc_base<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle>, true>" }
+ %"struct.std::_Vector_base<llvm::Use,std::allocator<llvm::Use> >" = type { %"struct.std::_Vector_alloc_base<llvm::Use,std::allocator<llvm::Use>, true>" }
+ %"struct.std::_Vector_base<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> > >" = type { %"struct.std::_Vector_alloc_base<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> >, true>" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" = type { %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Alloc_hider" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Alloc_hider" = type { i8* }
+ %"struct.std::pair<const llvm::PassInfo*,llvm::Pass*>" = type { %"struct.llvm::PassInfo"*, %"struct.llvm::Pass"* }
+ %"struct.std::pair<const llvm::Value* const,int>" = type { %"struct.llvm::Value"*, i32 }
+ %"struct.std::type_info" = type { i32 (...)**, i8* }
+ %"struct.std::vector<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*> >" = type { %"struct.std::_Vector_base<__gnu_cxx::_Hashtable_node<const llvm::Constant*>*,std::allocator<const llvm::Constant*> >" }
+ %"struct.std::vector<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int> >" = type { %"struct.std::_Vector_base<__gnu_cxx::_Hashtable_node<std::pair<const llvm::Value* const, int> >*,std::allocator<int> >" }
+ %"struct.std::vector<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*> >" = type { %"struct.std::_Vector_base<const llvm::PassInfo*,std::allocator<const llvm::PassInfo*> >" }
+ %"struct.std::vector<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*> >" = type { %"struct.std::_Vector_base<const llvm::TargetRegClassInfo*,std::allocator<const llvm::TargetRegClassInfo*> >" }
+ %"struct.std::vector<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*> >" = type { %"struct.std::_Vector_base<llvm::AbstractTypeUser*,std::allocator<llvm::AbstractTypeUser*> >" }
+ %"struct.std::vector<llvm::MachineInstr*,std::allocator<llvm::MachineInstr*> >" = type { %"struct.std::_Vector_base<llvm::MachineInstr*,std::allocator<llvm::MachineInstr*> >" }
+ %"struct.std::vector<llvm::MachineOperand,std::allocator<llvm::MachineOperand> >" = type { %"struct.std::_Vector_base<llvm::MachineOperand,std::allocator<llvm::MachineOperand> >" }
+ %"struct.std::vector<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle> >" = type { %"struct.std::_Vector_base<llvm::PATypeHandle,std::allocator<llvm::PATypeHandle> >" }
+ %"struct.std::vector<llvm::Use,std::allocator<llvm::Use> >" = type { %"struct.std::_Vector_base<llvm::Use,std::allocator<llvm::Use> >" }
+ %"struct.std::vector<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> > >" = type { %"struct.std::_Vector_base<std::pair<const llvm::PassInfo*, llvm::Pass*>,std::allocator<std::pair<const llvm::PassInfo*, llvm::Pass*> > >" }
+ %"union.llvm::MachineOperand::._65" = type { %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >"* }
+
+declare void @_Znwj()
+
+declare void @_ZN4llvm12MachineInstrC1Esjbb()
+
+declare void @_ZNSt6vectorIPN4llvm12MachineInstrESaIS2_EE9push_backERKS2_()
+
+declare void @_ZNK4llvm8Function15getFunctionTypeEv()
+
+declare void @_ZNK4llvm19MachineInstrBuilder7addMRegEiNS_14MachineOperand7UseTypeE()
+
+declare void @_ZNK4llvm19MachineInstrBuilder7addSImmEi()
+
+declare i32 @__gxx_personality_v0(...)
+
+define void @_ZN4llvm11_GLOBAL__N_22InsertPrologEpilogCode20runOnMachineFunctionERNS_15MachineFunctionE(%"struct.llvm::MachineFunction"* %F) {
+entry:
+ %tmp.8.i = invoke %"struct.llvm::TargetFrameInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.0.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetFrameInfo"*> [#uses=0]
+
+invoke_catch.0.i: ; preds = %invoke_cont.49.i, %invoke_cont.48.i, %invoke_cont.47.i, %invoke_cont.i53.i, %no_exit.i, %invoke_cont.44.i, %invoke_cont.43.i, %invoke_cont.42.i, %invoke_cont.41.i, %invoke_cont.40.i, %invoke_cont.39.i, %invoke_cont.38.i, %invoke_cont.37.i, %then.2.i, %invoke_cont.35.i, %invoke_cont.34.i, %then.1.i, %endif.0.i, %invoke_cont.9.i, %invoke_cont.8.i, %invoke_cont.7.i, %invoke_cont.i.i, %then.0.i, %invoke_cont.4.i, %invoke_cont.3.i, %invoke_cont.2.i, %invoke_cont.1.i, %endif.0.i.i, %tmp.7.i.noexc.i, %invoke_cont.0.i, %entry
+ %exn0.i = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+
+invoke_cont.0.i: ; preds = %entry
+ %tmp.7.i1.i = invoke %"struct.llvm::TargetFrameInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %tmp.7.i.noexc.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetFrameInfo"*> [#uses=2]
+
+tmp.7.i.noexc.i: ; preds = %invoke_cont.0.i
+ %tmp.17.i2.i = invoke i32 null( %"struct.llvm::TargetFrameInfo"* %tmp.7.i1.i )
+ to label %endif.0.i.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+endif.0.i.i: ; preds = %tmp.7.i.noexc.i
+ %tmp.38.i4.i = invoke i32 null( %"struct.llvm::TargetFrameInfo"* %tmp.7.i1.i )
+ to label %tmp.38.i.noexc.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+tmp.38.i.noexc.i: ; preds = %endif.0.i.i
+ br i1 false, label %invoke_cont.1.i, label %then.1.i.i
+
+then.1.i.i: ; preds = %tmp.38.i.noexc.i
+ ret void
+
+invoke_cont.1.i: ; preds = %tmp.38.i.noexc.i
+ %tmp.21.i = invoke %"struct.llvm::TargetRegInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.2.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetRegInfo"*> [#uses=1]
+
+invoke_cont.2.i: ; preds = %invoke_cont.1.i
+ %tmp.28.i = invoke i32 null( %"struct.llvm::TargetRegInfo"* %tmp.21.i )
+ to label %invoke_cont.3.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+invoke_cont.3.i: ; preds = %invoke_cont.2.i
+ %tmp.36.i = invoke %"struct.llvm::TargetInstrInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.4.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetInstrInfo"*> [#uses=1]
+
+invoke_cont.4.i: ; preds = %invoke_cont.3.i
+ %tmp.43.i = invoke i1 null( %"struct.llvm::TargetInstrInfo"* %tmp.36.i, i16 383, i64 0 )
+ to label %invoke_cont.5.i unwind label %invoke_catch.0.i ; <i1> [#uses=1]
+
+invoke_cont.5.i: ; preds = %invoke_cont.4.i
+ br i1 %tmp.43.i, label %then.0.i, label %else.i
+
+then.0.i: ; preds = %invoke_cont.5.i
+ invoke void @_Znwj( )
+ to label %tmp.0.i.noexc.i unwind label %invoke_catch.0.i
+
+tmp.0.i.noexc.i: ; preds = %then.0.i
+ invoke void @_ZN4llvm12MachineInstrC1Esjbb( )
+ to label %invoke_cont.i.i unwind label %cond_true.i.i
+
+cond_true.i.i: ; preds = %tmp.0.i.noexc.i
+ %exn.i.i = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+
+invoke_cont.i.i: ; preds = %tmp.0.i.noexc.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addMRegEiNS_14MachineOperand7UseTypeE( )
+ to label %invoke_cont.7.i unwind label %invoke_catch.0.i
+
+invoke_cont.7.i: ; preds = %invoke_cont.i.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addSImmEi( )
+ to label %invoke_cont.8.i unwind label %invoke_catch.0.i
+
+invoke_cont.8.i: ; preds = %invoke_cont.7.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addMRegEiNS_14MachineOperand7UseTypeE( )
+ to label %invoke_cont.9.i unwind label %invoke_catch.0.i
+
+invoke_cont.9.i: ; preds = %invoke_cont.8.i
+ invoke void @_ZNSt6vectorIPN4llvm12MachineInstrESaIS2_EE9push_backERKS2_( )
+ to label %endif.0.i unwind label %invoke_catch.0.i
+
+else.i: ; preds = %invoke_cont.5.i
+ ret void
+
+endif.0.i: ; preds = %invoke_cont.9.i
+ invoke void @_ZNK4llvm8Function15getFunctionTypeEv( )
+ to label %invoke_cont.33.i unwind label %invoke_catch.0.i
+
+invoke_cont.33.i: ; preds = %endif.0.i
+ br i1 false, label %then.1.i, label %endif.1.i
+
+then.1.i: ; preds = %invoke_cont.33.i
+ invoke void @_ZNK4llvm8Function15getFunctionTypeEv( )
+ to label %invoke_cont.34.i unwind label %invoke_catch.0.i
+
+invoke_cont.34.i: ; preds = %then.1.i
+ %tmp.121.i = invoke %"struct.llvm::TargetRegInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.35.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetRegInfo"*> [#uses=1]
+
+invoke_cont.35.i: ; preds = %invoke_cont.34.i
+ %tmp.128.i = invoke i32 null( %"struct.llvm::TargetRegInfo"* %tmp.121.i )
+ to label %invoke_cont.36.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+invoke_cont.36.i: ; preds = %invoke_cont.35.i
+ br i1 false, label %then.2.i, label %endif.1.i
+
+then.2.i: ; preds = %invoke_cont.36.i
+ %tmp.140.i = invoke %"struct.llvm::TargetRegInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.37.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetRegInfo"*> [#uses=0]
+
+invoke_cont.37.i: ; preds = %then.2.i
+ %tmp.148.i = invoke %"struct.llvm::TargetRegInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.38.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetRegInfo"*> [#uses=1]
+
+invoke_cont.38.i: ; preds = %invoke_cont.37.i
+ %tmp.155.i = invoke i32 null( %"struct.llvm::TargetRegInfo"* %tmp.148.i, %"struct.llvm::Type"* null, i1 false )
+ to label %invoke_cont.39.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+invoke_cont.39.i: ; preds = %invoke_cont.38.i
+ %tmp.163.i = invoke %"struct.llvm::TargetFrameInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.40.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetFrameInfo"*> [#uses=1]
+
+invoke_cont.40.i: ; preds = %invoke_cont.39.i
+ %tmp.170.i = invoke i32 null( %"struct.llvm::TargetFrameInfo"* %tmp.163.i )
+ to label %invoke_cont.41.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+invoke_cont.41.i: ; preds = %invoke_cont.40.i
+ %tmp.177.i = invoke %"struct.llvm::TargetFrameInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.42.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetFrameInfo"*> [#uses=1]
+
+invoke_cont.42.i: ; preds = %invoke_cont.41.i
+ %tmp.184.i = invoke i32 null( %"struct.llvm::TargetFrameInfo"* %tmp.177.i )
+ to label %invoke_cont.43.i unwind label %invoke_catch.0.i ; <i32> [#uses=1]
+
+invoke_cont.43.i: ; preds = %invoke_cont.42.i
+ %tmp.191.i = invoke %"struct.llvm::TargetFrameInfo"* null( %"struct.llvm::TargetMachine"* null )
+ to label %invoke_cont.44.i unwind label %invoke_catch.0.i ; <%"struct.llvm::TargetFrameInfo"*> [#uses=1]
+
+invoke_cont.44.i: ; preds = %invoke_cont.43.i
+ %tmp.198.i = invoke i32 null( %"struct.llvm::TargetFrameInfo"* %tmp.191.i, %"struct.llvm::MachineFunction"* %F, i1* null )
+ to label %invoke_cont.45.i unwind label %invoke_catch.0.i ; <i32> [#uses=0]
+
+invoke_cont.45.i: ; preds = %invoke_cont.44.i
+ br i1 false, label %no_exit.i, label %endif.1.i
+
+no_exit.i: ; preds = %invoke_cont.50.i, %invoke_cont.45.i
+ %nextArgOffset.0.i.1 = phi i32 [ %tmp.221.i, %invoke_cont.50.i ], [ 0, %invoke_cont.45.i ] ; <i32> [#uses=1]
+ invoke void @_Znwj( )
+ to label %tmp.0.i.noexc55.i unwind label %invoke_catch.0.i
+
+tmp.0.i.noexc55.i: ; preds = %no_exit.i
+ invoke void @_ZN4llvm12MachineInstrC1Esjbb( )
+ to label %invoke_cont.i53.i unwind label %cond_true.i52.i
+
+cond_true.i52.i: ; preds = %tmp.0.i.noexc55.i
+ %exn.i52.i = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+
+invoke_cont.i53.i: ; preds = %tmp.0.i.noexc55.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addMRegEiNS_14MachineOperand7UseTypeE( )
+ to label %invoke_cont.47.i unwind label %invoke_catch.0.i
+
+invoke_cont.47.i: ; preds = %invoke_cont.i53.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addMRegEiNS_14MachineOperand7UseTypeE( )
+ to label %invoke_cont.48.i unwind label %invoke_catch.0.i
+
+invoke_cont.48.i: ; preds = %invoke_cont.47.i
+ invoke void @_ZNK4llvm19MachineInstrBuilder7addSImmEi( )
+ to label %invoke_cont.49.i unwind label %invoke_catch.0.i
+
+invoke_cont.49.i: ; preds = %invoke_cont.48.i
+ invoke void @_ZNSt6vectorIPN4llvm12MachineInstrESaIS2_EE9push_backERKS2_( )
+ to label %invoke_cont.50.i unwind label %invoke_catch.0.i
+
+invoke_cont.50.i: ; preds = %invoke_cont.49.i
+ %tmp.221.i = add i32 %nextArgOffset.0.i.1, %tmp.184.i ; <i32> [#uses=1]
+ br i1 false, label %no_exit.i, label %endif.1.i
+
+endif.1.i: ; preds = %invoke_cont.50.i, %invoke_cont.45.i, %invoke_cont.36.i, %invoke_cont.33.i
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2004-04-07-ScalarEvolutionCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2004-04-07-ScalarEvolutionCrash.ll
new file mode 100644
index 0000000..b060fab
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2004-04-07-ScalarEvolutionCrash.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @.outPlank_21() {
+entry:
+ br i1 false, label %loopexit.0, label %no_exit.0
+
+no_exit.0: ; preds = %entry
+ ret void
+
+loopexit.0: ; preds = %entry
+ br i1 false, label %no_exit.1, label %loopexit.1
+
+no_exit.1: ; preds = %loopexit.2, %loopexit.0
+ %i.0.0 = phi i32 [ %inc, %loopexit.2 ], [ 0, %loopexit.0 ] ; <i32> [#uses=1]
+ br i1 false, label %loopexit.2, label %no_exit.2
+
+no_exit.2: ; preds = %no_exit.1
+ ret void
+
+loopexit.2: ; preds = %no_exit.1
+ %inc = add i32 %i.0.0, 1 ; <i32> [#uses=1]
+ br i1 false, label %no_exit.1, label %loopexit.1
+
+loopexit.1: ; preds = %loopexit.2, %loopexit.0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2005-02-11-InvokeCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-11-InvokeCrash.ll
new file mode 100644
index 0000000..e8e15b3
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-11-InvokeCrash.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @_ZN5ArrayISt7complexIdEEC2ERK10dim_vector() {
+entry:
+ %tmp.7 = invoke i32 @_ZN5ArrayISt7complexIdEE8get_sizeERK10dim_vector( )
+ to label %invoke_cont.0 unwind label %cond_true.1 ; <i32> [#uses=2]
+
+invoke_cont.0: ; preds = %entry
+ %tmp.4.i = bitcast i32 %tmp.7 to i32 ; <i32> [#uses=0]
+ %tmp.14.0.i5 = add i32 %tmp.7, -1 ; <i32> [#uses=1]
+ br label %no_exit.i
+
+no_exit.i: ; preds = %no_exit.i, %invoke_cont.0
+ %tmp.14.0.i.0 = phi i32 [ %tmp.14.0.i, %no_exit.i ], [ %tmp.14.0.i5, %invoke_cont.0 ] ; <i32> [#uses=1]
+ %tmp.14.0.i = add i32 %tmp.14.0.i.0, -1 ; <i32> [#uses=1]
+ br label %no_exit.i
+
+cond_true.1: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %exn
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare i32 @_ZN5ArrayISt7complexIdEE8get_sizeERK10dim_vector()
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2005-02-17-TruncateExprCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-17-TruncateExprCrash.ll
new file mode 100644
index 0000000..28961e1
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-17-TruncateExprCrash.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -indvars -disable-output
+
+declare void @q_atomic_increment()
+
+declare void @_Z9qt_assertPKcS0_i()
+
+define void @_ZN13QMetaResourceC1EPKh() {
+entry:
+ invoke void @_Z9qt_assertPKcS0_i( )
+ to label %endif.1 unwind label %then.i.i551
+
+then.i.i551: ; preds = %entry
+ %exn551 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+
+endif.1: ; preds = %entry
+ br i1 false, label %then.2, label %then.i.i
+
+then.2: ; preds = %endif.1
+ invoke void @q_atomic_increment( )
+ to label %loopentry.0 unwind label %invoke_catch.6
+
+invoke_catch.6: ; preds = %then.2
+ %exn6 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+
+loopentry.0: ; preds = %then.2
+ br i1 false, label %shortcirc_next.i, label %endif.3
+
+endif.3: ; preds = %loopentry.0
+ ret void
+
+shortcirc_next.i: ; preds = %loopentry.0
+ br i1 false, label %_ZNK7QString2atEi.exit, label %then.i
+
+then.i: ; preds = %shortcirc_next.i
+ ret void
+
+_ZNK7QString2atEi.exit: ; preds = %shortcirc_next.i
+ br i1 false, label %endif.4, label %then.4
+
+then.4: ; preds = %_ZNK7QString2atEi.exit
+ ret void
+
+endif.4: ; preds = %_ZNK7QString2atEi.exit
+ %tmp.115 = load i8* null ; <i8> [#uses=1]
+ br i1 false, label %loopexit.1, label %no_exit.0
+
+no_exit.0: ; preds = %no_exit.0, %endif.4
+ %bytes_in_len.4.5 = phi i8 [ %dec, %no_exit.0 ], [ %tmp.115, %endif.4 ] ; <i8> [#uses=1]
+ %off.5.5.in = phi i32 [ %off.5.5, %no_exit.0 ], [ 0, %endif.4 ] ; <i32> [#uses=1]
+ %off.5.5 = add i32 %off.5.5.in, 1 ; <i32> [#uses=2]
+ %dec = add i8 %bytes_in_len.4.5, -1 ; <i8> [#uses=2]
+ %tmp.123631 = icmp eq i8 %dec, 0 ; <i1> [#uses=1]
+ br i1 %tmp.123631, label %loopexit.1, label %no_exit.0
+
+loopexit.1: ; preds = %no_exit.0, %endif.4
+ %off.5.in.6 = phi i32 [ 0, %endif.4 ], [ %off.5.5, %no_exit.0 ] ; <i32> [#uses=0]
+ ret void
+
+then.i.i: ; preds = %endif.1
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2005-02-26-ExitValueCompute.ll b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-26-ExitValueCompute.ll
new file mode 100644
index 0000000..fd3803c
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2005-02-26-ExitValueCompute.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -indvars -S | \
+; RUN: grep {ret i32 152}
+
+define i32 @main() {
+entry:
+ br label %no_exit
+
+no_exit: ; preds = %no_exit, %entry
+ %i.1.0 = phi i32 [ 0, %entry ], [ %inc, %no_exit ] ; <i32> [#uses=2]
+ %tmp.4 = icmp sgt i32 %i.1.0, 50 ; <i1> [#uses=1]
+ %tmp.7 = select i1 %tmp.4, i32 100, i32 0 ; <i32> [#uses=1]
+ %i.0 = add i32 %i.1.0, 1 ; <i32> [#uses=1]
+ %inc = add i32 %i.0, %tmp.7 ; <i32> [#uses=3]
+ %tmp.1 = icmp slt i32 %inc, 100 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %no_exit, label %loopexit
+
+loopexit: ; preds = %no_exit
+ ret i32 %inc
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2005-06-15-InstMoveCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2005-06-15-InstMoveCrash.ll
new file mode 100644
index 0000000..d33af3a
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2005-06-15-InstMoveCrash.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @main() {
+entry:
+ br label %no_exit.1.outer
+
+no_exit.1.outer: ; preds = %endif.0, %entry
+ %l_14237116.1.0.ph = phi i8 [ -46, %entry ], [ 0, %endif.0 ] ; <i8> [#uses=1]
+ %i.0.0.0.ph = phi i32 [ 0, %entry ], [ %inc.1, %endif.0 ] ; <i32> [#uses=1]
+ br label %no_exit.1
+
+no_exit.1: ; preds = %_Z13func_47880058cc.exit, %no_exit.1.outer
+ br i1 false, label %_Z13func_47880058cc.exit, label %then.i
+
+then.i: ; preds = %no_exit.1
+ br label %_Z13func_47880058cc.exit
+
+_Z13func_47880058cc.exit: ; preds = %then.i, %no_exit.1
+ br i1 false, label %then.0, label %no_exit.1
+
+then.0: ; preds = %_Z13func_47880058cc.exit
+ %tmp.6 = bitcast i8 %l_14237116.1.0.ph to i8 ; <i8> [#uses=1]
+ br i1 false, label %endif.0, label %then.1
+
+then.1: ; preds = %then.0
+ br label %endif.0
+
+endif.0: ; preds = %then.1, %then.0
+ %inc.1 = add i32 %i.0.0.0.ph, 1 ; <i32> [#uses=2]
+ %tmp.2 = icmp sgt i32 %inc.1, 99 ; <i1> [#uses=1]
+ br i1 %tmp.2, label %loopexit.0, label %no_exit.1.outer
+
+loopexit.0: ; preds = %endif.0
+ %tmp.28 = zext i8 %tmp.6 to i32 ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2005-11-18-Crash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2005-11-18-Crash.ll
new file mode 100644
index 0000000..c80f7b4
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2005-11-18-Crash.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -indvars -disable-output
+
+@fixtab = external global [29 x [29 x [2 x i32]]] ; <[29 x [29 x [2 x i32]]]*> [#uses=1]
+
+define void @init_optabs() {
+entry:
+ br label %no_exit.0
+
+no_exit.0: ; preds = %no_exit.0, %entry
+ %p.0.0 = phi i32* [ getelementptr ([29 x [29 x [2 x i32]]]* @fixtab, i32 0, i32 0, i32 0, i32 0), %entry ], [ %inc.0, %no_exit.0 ] ; <i32*> [#uses=1]
+ %inc.0 = getelementptr i32* %p.0.0, i32 1 ; <i32*> [#uses=1]
+ br i1 undef, label %no_exit.0, label %no_exit.1
+
+no_exit.1: ; preds = %no_exit.0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2006-03-31-NegativeStride.ll b/src/LLVM/test/Transforms/IndVarSimplify/2006-03-31-NegativeStride.ll
new file mode 100644
index 0000000..0e9c138
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2006-03-31-NegativeStride.ll
@@ -0,0 +1,22 @@
+; PR726
+; RUN: opt < %s -indvars -S | \
+; RUN: grep {ret i32 27}
+
+; Make sure to compute the right exit value based on negative strides.
+
+define i32 @test() {
+entry:
+ br label %cond_true
+
+cond_true: ; preds = %cond_true, %entry
+ %a.0.0 = phi i32 [ 10, %entry ], [ %tmp4, %cond_true ] ; <i32> [#uses=2]
+ %b.0.0 = phi i32 [ 0, %entry ], [ %tmp2, %cond_true ] ; <i32> [#uses=1]
+ %tmp2 = add i32 %b.0.0, %a.0.0 ; <i32> [#uses=2]
+ %tmp4 = add i32 %a.0.0, -1 ; <i32> [#uses=2]
+ %tmp = icmp sgt i32 %tmp4, 7 ; <i1> [#uses=1]
+ br i1 %tmp, label %cond_true, label %bb7
+
+bb7: ; preds = %cond_true
+ ret i32 %tmp2
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2006-06-16-Indvar-LCSSA-Crash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2006-06-16-Indvar-LCSSA-Crash.ll
new file mode 100644
index 0000000..f56200b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2006-06-16-Indvar-LCSSA-Crash.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -indvars -disable-output
+
+define void @get_block() {
+endif.0:
+ br label %no_exit.30
+
+no_exit.30: ; preds = %no_exit.30, %endif.0
+ %x.12.0 = phi i32 [ %inc.28, %no_exit.30 ], [ -2, %endif.0 ] ; <i32> [#uses=1]
+ %tmp.583 = load i16* null ; <i16> [#uses=1]
+ %tmp.584 = zext i16 %tmp.583 to i32 ; <i32> [#uses=1]
+ %tmp.588 = load i32* null ; <i32> [#uses=1]
+ %tmp.589 = mul i32 %tmp.584, %tmp.588 ; <i32> [#uses=1]
+ %tmp.591 = add i32 %tmp.589, 0 ; <i32> [#uses=1]
+ %inc.28 = add i32 %x.12.0, 1 ; <i32> [#uses=2]
+ %tmp.565 = icmp sgt i32 %inc.28, 3 ; <i1> [#uses=1]
+ br i1 %tmp.565, label %loopexit.30, label %no_exit.30
+
+loopexit.30: ; preds = %no_exit.30
+ %tmp.591.lcssa = phi i32 [ %tmp.591, %no_exit.30 ] ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2006-09-20-LFTR-Crash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2006-09-20-LFTR-Crash.ll
new file mode 100644
index 0000000..600e710
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2006-09-20-LFTR-Crash.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -indvars -disable-output
+; ModuleID = '2006-09-20-LFTR-Crash.ll'
+ %struct.p7prior_s = type { i32, i32, [200 x float], [200 x [7 x float]], i32, [200 x float], [200 x [20 x float]], i32, [200 x float], [200 x [20 x float]] }
+
+define void @P7DefaultPrior() {
+entry:
+ switch i32 0, label %UnifiedReturnBlock [
+ i32 2, label %bb160
+ i32 3, label %bb
+ ]
+
+bb: ; preds = %entry
+ br i1 false, label %cond_true.i, label %sre_malloc.exit
+
+cond_true.i: ; preds = %bb
+ unreachable
+
+sre_malloc.exit: ; preds = %bb
+ br label %cond_true
+
+cond_true: ; preds = %cond_true66, %cond_true, %sre_malloc.exit
+ %tmp59 = phi i32 [ 1, %sre_malloc.exit ], [ %phitmp, %cond_true66 ], [ %tmp59, %cond_true ] ; <i32> [#uses=2]
+ %indvar245.0.ph = phi i32 [ 0, %sre_malloc.exit ], [ %indvar.next246, %cond_true66 ], [ %indvar245.0.ph, %cond_true ] ; <i32> [#uses=2]
+ br i1 false, label %bb57, label %cond_true
+
+bb57: ; preds = %cond_true
+ %tmp65 = icmp sgt i32 0, %tmp59 ; <i1> [#uses=1]
+ %indvar.next246 = add i32 %indvar245.0.ph, 1 ; <i32> [#uses=2]
+ br i1 %tmp65, label %cond_true66, label %bb69
+
+cond_true66: ; preds = %bb57
+ %q.1.0 = bitcast i32 %indvar.next246 to i32 ; <i32> [#uses=1]
+ %phitmp = add i32 %q.1.0, 1 ; <i32> [#uses=1]
+ br label %cond_true
+
+bb69: ; preds = %bb57
+ ret void
+
+bb160: ; preds = %entry
+ ret void
+
+UnifiedReturnBlock: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2006-12-10-BitCast.ll b/src/LLVM/test/Transforms/IndVarSimplify/2006-12-10-BitCast.ll
new file mode 100644
index 0000000..bcf9693
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2006-12-10-BitCast.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -indvars -disable-output
+target datalayout = "e-p:32:32"
+target triple = "i686-apple-darwin8"
+ %struct.vorbis_dsp_state = type { i32, %struct.vorbis_info*, float**, float**, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i8* }
+ %struct.vorbis_info = type { i32, i32, i32, i32, i32, i32, i32, i8* }
+
+define void @_ve_envelope_search() {
+entry:
+ br i1 false, label %cond_true27, label %bb137
+
+cond_true27: ; preds = %entry
+ br i1 false, label %cond_true52, label %bb80
+
+cond_true52: ; preds = %cond_true27
+ %tmp152.i = bitcast float 0.000000e+00 to i32 ; <i32> [#uses=1]
+ br label %cond_next182.i
+
+cond_next182.i: ; preds = %cond_next182.i, %cond_true52
+ %decay.i.0 = phi i32 [ %tmp195.i.upgrd.1, %cond_next182.i ], [ %tmp152.i, %cond_true52 ] ; <i32> [#uses=1]
+ %tmp194.i53 = bitcast i32 %decay.i.0 to float ; <float> [#uses=1]
+ %tmp195.i = fsub float %tmp194.i53, 8.000000e+00 ; <float> [#uses=1]
+ %tmp195.i.upgrd.1 = bitcast float %tmp195.i to i32 ; <i32> [#uses=1]
+ br i1 undef, label %cond_next182.i, label %bb418.i.preheader
+
+bb418.i.preheader: ; preds = %cond_next182.i
+ ret void
+
+bb80: ; preds = %cond_true27
+ ret void
+
+bb137: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2007-01-06-TripCount.ll b/src/LLVM/test/Transforms/IndVarSimplify/2007-01-06-TripCount.ll
new file mode 100644
index 0000000..5998d03
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2007-01-06-TripCount.ll
@@ -0,0 +1,38 @@
+; PR1015
+; RUN: opt < %s -indvars -S | not grep {ret i32 0}
+
+target datalayout = "e-p:32:32"
+target triple = "i686-apple-darwin8"
+@foo = internal constant [5 x i8] c"\00abc\00" ; <[5 x i8]*> [#uses=1]
+@str = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+
+define i32 @test(i32 %J) {
+entry:
+ br label %bb2
+
+bb: ; preds = %cond_next, %cond_true
+ %tmp1 = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %tmp1, %bb ] ; <i32> [#uses=4]
+ %tmp = icmp eq i32 %i.0, 0 ; <i1> [#uses=1]
+ br i1 %tmp, label %cond_true, label %cond_next
+
+cond_true: ; preds = %bb2
+ br label %bb
+
+cond_next: ; preds = %bb2
+ %tmp2 = getelementptr [5 x i8]* @foo, i32 0, i32 %i.0 ; <i8*> [#uses=1]
+ %tmp3 = load i8* %tmp2 ; <i8> [#uses=1]
+ %tmp5 = icmp eq i8 %tmp3, 0 ; <i1> [#uses=1]
+ br i1 %tmp5, label %bb6, label %bb
+
+bb6: ; preds = %cond_next
+ br label %return
+
+return: ; preds = %bb6
+ ret i32 %i.0
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll b/src/LLVM/test/Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll
new file mode 100644
index 0000000..ae8bdc0
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll
@@ -0,0 +1,117 @@
+; RUN: opt < %s -indvars -disable-output
+; PR1487
+
+ %struct.AVClass = type { i8*, i8* (i8*)*, %struct.AVOption* }
+ %struct.AVCodec = type { i8*, i32, i32, i32, i32 (%struct.AVCodecContext*)*, i32 (%struct.AVCodecContext*, i8*, i32, i8*)*, i32 (%struct.AVCodecContext*)*, i32 (%struct.AVCodecContext*, i8*, i32*, i8*, i32)*, i32, %struct.AVCodec*, void (%struct.AVCodecContext*)*, %struct.AVCodecTag*, i32* }
+ %struct.AVCodecContext = type { %struct.AVClass*, i32, i32, i32, i32, i32, i8*, i32, %struct.AVCodecTag, i32, i32, i32, i32, i32, void (%struct.AVCodecContext*, %struct.AVFrame*, i32*, i32, i32, i32)*, i32, i32, i32, i32, i32, i32, i32, float, float, i32, i32, i32, i32, float, i32, i32, i32, %struct.AVCodec*, i8*, i32, i32, void (%struct.AVCodecContext*, i8*, i32, i32)*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, [32 x i8], i32, i32, i32, i32, i32, i32, i32, float, i32, i32 (%struct.AVCodecContext*, %struct.AVFrame*)*, void (%struct.AVCodecContext*, %struct.AVFrame*)*, i32, i32, i32, i32, i8*, i8*, float, float, i32, %struct.RcOverride*, i32, i8*, i32, i32, i32, float, float, float, float, i32, float, float, float, float, float, i32, i32, i32, i32*, i32, i32, i32, i32, %struct.AVCodecTag, %struct.AVFrame*, i32, i32, [4 x i64], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 (%struct.AVCodecContext*, i32*)*, i32, i32, i32, i32, i32, i32, i8*, i32, i32, i32, i32, i32, i32, i16*, i16*, i32, i32, i32, i32, %struct.AVPaletteControl*, i32, i32 (%struct.AVCodecContext*, %struct.AVFrame*)*, i32, i32, i32, i32, i32, i32, i32, i32 (%struct.AVCodecContext*, i32 (%struct.AVCodecContext*, i8*)*, i8**, i32*, i32)*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, i32, i32, i32, i32, i32, i32, i32, i32, float, i32, i32, i32, i32, i32, i32, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64 }
+ %struct.AVCodecTag = type { i32, i32 }
+ %struct.AVFrame = type { [4 x i8*], [4 x i32], [4 x i8*], i32, i32, i64, i32, i32, i32, i32, i32, i8*, i32, i8*, [2 x [2 x i16]*], i32*, i8, i8*, [4 x i64], i32, i32, i32, i32, i32, %struct.AVPanScan*, i32, i32, i16*, [2 x i8*] }
+ %struct.AVOption = type { i8*, i8*, i32, i32, double, double, double, i32, i8* }
+ %struct.AVPaletteControl = type { i32, [256 x i32] }
+ %struct.AVPanScan = type { i32, i32, i32, [3 x [2 x i16]] }
+ %struct.RcOverride = type { i32, i32, i32, float }
+
+define i32 @smc_decode_frame(%struct.AVCodecContext* %avctx, i8* %data, i32* %data_size, i8* %buf, i32 %buf_size) {
+entry:
+ br i1 false, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ ret i32 -1
+
+cond_next: ; preds = %entry
+ br i1 false, label %bb.outer5.split.split.split.us, label %cond_true194.split
+
+bb.outer5.split.split.split.us: ; preds = %cond_next
+ br i1 false, label %cond_next188.us503.us, label %bb.us481
+
+bb275.us493.us: ; preds = %cond_next188.us503.us, %cond_next188.us503.us
+ ret i32 0
+
+cond_next188.us503.us: ; preds = %bb.outer5.split.split.split.us
+ switch i32 0, label %bb1401 [
+ i32 0, label %cond_next202.bb215_crit_edge.split
+ i32 16, label %bb215
+ i32 32, label %bb275.us493.us
+ i32 48, label %bb275.us493.us
+ i32 64, label %cond_next202.bb417_crit_edge.split
+ i32 80, label %bb417
+ i32 96, label %cond_next202.bb615_crit_edge.split
+ i32 112, label %bb615
+ i32 128, label %cond_next202.bb716_crit_edge.split
+ i32 144, label %bb716
+ i32 160, label %cond_next202.bb882_crit_edge.split
+ i32 176, label %bb882
+ i32 192, label %cond_next202.bb1062_crit_edge.split
+ i32 208, label %bb1062
+ i32 224, label %bb1326.us.outer.outer
+ ]
+
+bb.us481: ; preds = %bb.outer5.split.split.split.us
+ ret i32 0
+
+cond_true194.split: ; preds = %cond_next
+ ret i32 %buf_size
+
+cond_next202.bb1062_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+cond_next202.bb882_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+cond_next202.bb716_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+cond_next202.bb615_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+cond_next202.bb417_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+cond_next202.bb215_crit_edge.split: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb215: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb417: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb615: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb716: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb882: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb1062: ; preds = %cond_next188.us503.us
+ ret i32 0
+
+bb1326.us: ; preds = %bb1326.us.outer.outer, %bb1347.loopexit.us, %bb1326.us
+ %pixel_y.162036.us.ph = phi i32 [ %tmp1352.us, %bb1347.loopexit.us ], [ 0, %bb1326.us.outer.outer ], [ %pixel_y.162036.us.ph, %bb1326.us ] ; <i32> [#uses=2]
+ %stream_ptr.142038.us.ph = phi i32 [ %tmp1339.us, %bb1347.loopexit.us ], [ %stream_ptr.142038.us.ph.ph, %bb1326.us.outer.outer ], [ %stream_ptr.142038.us.ph, %bb1326.us ] ; <i32> [#uses=2]
+ %pixel_x.232031.us = phi i32 [ %tmp1341.us, %bb1326.us ], [ 0, %bb1326.us.outer.outer ], [ 0, %bb1347.loopexit.us ] ; <i32> [#uses=3]
+ %block_ptr.222030.us = add i32 0, %pixel_x.232031.us ; <i32> [#uses=1]
+ %stream_ptr.132032.us = add i32 %pixel_x.232031.us, %stream_ptr.142038.us.ph ; <i32> [#uses=1]
+ %tmp1341.us = add i32 %pixel_x.232031.us, 1 ; <i32> [#uses=2]
+ %tmp1344.us = icmp slt i32 %tmp1341.us, 4 ; <i1> [#uses=1]
+ br i1 %tmp1344.us, label %bb1326.us, label %bb1347.loopexit.us
+
+bb1347.loopexit.us: ; preds = %bb1326.us
+ %tmp1339.us = add i32 %stream_ptr.132032.us, 1 ; <i32> [#uses=2]
+ %tmp1337.us = add i32 %block_ptr.222030.us, 1 ; <i32> [#uses=0]
+ %tmp1352.us = add i32 %pixel_y.162036.us.ph, 1 ; <i32> [#uses=2]
+ %tmp1355.us = icmp slt i32 %tmp1352.us, 4 ; <i1> [#uses=1]
+ br i1 %tmp1355.us, label %bb1326.us, label %bb1358
+
+bb1358: ; preds = %bb1347.loopexit.us
+ br label %bb1326.us.outer.outer
+
+bb1326.us.outer.outer: ; preds = %bb1358, %cond_next188.us503.us
+ %stream_ptr.142038.us.ph.ph = phi i32 [ %tmp1339.us, %bb1358 ], [ 0, %cond_next188.us503.us ] ; <i32> [#uses=1]
+ br label %bb1326.us
+
+bb1401: ; preds = %cond_next188.us503.us
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2007-11-23-BitcastCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2007-11-23-BitcastCrash.ll
new file mode 100644
index 0000000..cad4eb1
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2007-11-23-BitcastCrash.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -indvars -disable-output
+; PR1814
+target datalayout = "e-p:32:32-f64:32:64-i64:32:64-f80:32:32"
+
+define void @FuncAt1938470480(i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i64, i64, i1, i1, i1, i1, i1, i1) {
+EntryBlock:
+ br label %asmBlockAt738ab7f3
+
+asmBlockAt738ab9b0: ; preds = %asmBlockAt738ab7f3
+ %.lcssa6 = phi i64 [ %23, %asmBlockAt738ab7f3 ] ; <i64> [#uses=0]
+ ret void
+
+asmBlockAt738ab7f3: ; preds = %asmBlockAt738ab7f3, %EntryBlock
+ %ebp95 = phi i32 [ 128, %EntryBlock ], [ %24, %asmBlockAt738ab7f3 ] ; <i32> [#uses=2]
+ sub <4 x i16> zeroinitializer, zeroinitializer ; <<4 x i16>>:22 [#uses=1]
+ bitcast <4 x i16> %22 to i64 ; <i64>:23 [#uses=1]
+ add i32 %ebp95, -64 ; <i32>:24 [#uses=1]
+ icmp ult i32 %ebp95, 64 ; <i1>:25 [#uses=1]
+ br i1 %25, label %asmBlockAt738ab9b0, label %asmBlockAt738ab7f3
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2008-06-15-SCEVExpanderBug.ll b/src/LLVM/test/Transforms/IndVarSimplify/2008-06-15-SCEVExpanderBug.ll
new file mode 100644
index 0000000..77235d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2008-06-15-SCEVExpanderBug.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -indvars -disable-output
+; PR2434
+
+define fastcc void @regcppop() nounwind {
+entry:
+ %tmp61 = add i32 0, -5 ; <i32> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %PL_savestack_ix.tmp.0 = phi i32 [ %tmp61, %entry ], [ %tmp127, %bb ] ; <i32> [#uses=2]
+ %indvar10 = phi i32 [ 0, %entry ], [ %indvar.next11, %bb ] ; <i32> [#uses=2]
+ %tmp13 = mul i32 %indvar10, -4 ; <i32> [#uses=0]
+ %tmp111 = add i32 %PL_savestack_ix.tmp.0, -3 ; <i32> [#uses=0]
+ %tmp127 = add i32 %PL_savestack_ix.tmp.0, -4 ; <i32> [#uses=1]
+ %indvar.next11 = add i32 %indvar10, 1 ; <i32> [#uses=1]
+ br label %bb
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll b/src/LLVM/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll
new file mode 100644
index 0000000..a004831
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll
@@ -0,0 +1,58 @@
+; RUN: opt < %s -indvars -S | grep sext | count 1
+; ModuleID = '<stdin>'
+
+ %struct.App1Marker = type <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }>
+ %struct.ComponentInstanceRecord = type <{ [1 x i32] }>
+ %struct.DCPredictors = type { [5 x i16] }
+ %struct.DecodeTable = type { i16, i16, i16, i16, i8**, i8** }
+ %struct.ICMDataProcRecord = type <{ i16 (i8**, i32, i32)*, i32 }>
+ %struct.JPEGBitStream = type { i8*, i32, i32, i32, i32, i32, %struct.App1Marker*, i8*, i32, i16, i16, i32 }
+ %struct.JPEGGlobals = type { [2048 x i8], %struct.JPEGBitStream, i8*, i32, i32, %struct.ComponentInstanceRecord*, %struct.ComponentInstanceRecord*, i32, %struct.OpaqueQTMLMutex*, %struct.Rect, i32, i32, %struct.SharedGlobals, %struct.DCPredictors, i8, i8, void (i8*, i16**, i32, %struct.YUVGeneralParams*)*, %struct.YUVGeneralParams, i16, i16, i32, [5 x i16*], [5 x %struct.DecodeTable*], [5 x %struct.DecodeTable*], [5 x i8], [5 x i8], [4 x [65 x i16]], [4 x %struct.DecodeTable], [4 x %struct.DecodeTable], [4 x i8*], [4 x i8*], i16, i16, i32, i8**, i8**, i8**, i8**, i8**, i8**, i8**, i8**, i8**, i8**, [18 x i8], [18 x i8], [18 x i8], [18 x i8], i32, i32, i8**, i8**, i8, i8, i8, i8, i16, i16, %struct.App1Marker*, i8, i8, i8, i8, i32**, i8*, i16*, i8*, i16*, i8, [3 x i8], i32, [3 x i32], [3 x i32], [3 x i32], [3 x i32], [3 x i32], [3 x i16*], [3 x i16*], [3 x i8**], [3 x %struct.DecodeTable*], [3 x %struct.DecodeTable*], [3 x i32], i32, [3 x i16*], i32, i32, i32, [3 x i32], i8, i8, i8, i8, %struct.ICMDataProcRecord*, i32, i32, i8**, i8**, i8**, i8**, i32, i32, i8*, i32, i32, i16*, i16*, i8*, i32, i32, i32, i32, i32, i32, i32, [16 x <2 x i64>], [1280 x i8], i8 }
+ %struct.OpaqueQTMLMutex = type opaque
+ %struct.Rect = type { i16, i16, i16, i16 }
+ %struct.SharedDGlobals = type { %struct.DecodeTable, %struct.DecodeTable, %struct.DecodeTable, %struct.DecodeTable }
+ %struct.SharedEGlobals = type { i8**, i8**, i8**, i8** }
+ %struct.SharedGlobals = type { %struct.SharedEGlobals*, %struct.SharedDGlobals* }
+ %struct.YUVGeneralParams = type { i16*, i8*, i8*, i8*, i8*, i8*, void (i8*, i16**, i32, %struct.YUVGeneralParams*)*, i16, i16, i16, [6 x i8], void (i8*, i16**, i32, %struct.YUVGeneralParams*)*, i16, i16 }
+@llvm.used = appending global [1 x i8*] [ i8* bitcast (i16 (%struct.JPEGGlobals*)* @ExtractBufferedBlocksIgnored to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
+
+define signext i16 @ExtractBufferedBlocksIgnored(%struct.JPEGGlobals* %globp) nounwind {
+entry:
+ %tmp4311 = getelementptr %struct.JPEGGlobals* %globp, i32 0, i32 70 ; <i32*> [#uses=1]
+ %tmp4412 = load i32* %tmp4311, align 16 ; <i32> [#uses=2]
+ %tmp4613 = icmp sgt i32 %tmp4412, 0 ; <i1> [#uses=1]
+ br i1 %tmp4613, label %bb, label %bb49
+
+bb: ; preds = %bb28, %entry
+ %component.09 = phi i16 [ 0, %entry ], [ %tmp37, %bb28 ] ; <i16> [#uses=2]
+ %tmp12 = sext i16 %component.09 to i32 ; <i32> [#uses=2]
+ %tmp6 = getelementptr %struct.JPEGGlobals* %globp, i32 0, i32 77, i32 %tmp12 ; <i16**> [#uses=2]
+ %tmp7 = load i16** %tmp6, align 4 ; <i16*> [#uses=2]
+ %tmp235 = getelementptr %struct.JPEGGlobals* %globp, i32 0, i32 71, i32 %tmp12 ; <i32*> [#uses=1]
+ %tmp246 = load i32* %tmp235, align 4 ; <i32> [#uses=2]
+ %tmp267 = icmp sgt i32 %tmp246, 0 ; <i1> [#uses=1]
+ br i1 %tmp267, label %bb8, label %bb28
+
+bb8: ; preds = %bb8, %bb
+ %indvar = phi i32 [ 0, %bb ], [ %indvar.next2, %bb8 ] ; <i32> [#uses=3]
+ %theDCTBufferIter.01.rec = shl i32 %indvar, 6 ; <i32> [#uses=1]
+ %tmp10.rec = add i32 %theDCTBufferIter.01.rec, 64 ; <i32> [#uses=1]
+ %tmp10 = getelementptr i16* %tmp7, i32 %tmp10.rec ; <i16*> [#uses=1]
+ %i.02 = trunc i32 %indvar to i16 ; <i16> [#uses=1]
+ %tmp13 = add i16 %i.02, 1 ; <i16> [#uses=1]
+ %phitmp = sext i16 %tmp13 to i32 ; <i32> [#uses=1]
+ %tmp26 = icmp slt i32 %phitmp, %tmp246 ; <i1> [#uses=1]
+ %indvar.next2 = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br i1 %tmp26, label %bb8, label %bb28
+
+bb28: ; preds = %bb8, %bb
+ %theDCTBufferIter.0.lcssa = phi i16* [ %tmp7, %bb ], [ %tmp10, %bb8 ] ; <i16*> [#uses=1]
+ store i16* %theDCTBufferIter.0.lcssa, i16** %tmp6, align 4
+ %tmp37 = add i16 %component.09, 1 ; <i16> [#uses=2]
+ %phitmp15 = sext i16 %tmp37 to i32 ; <i32> [#uses=1]
+ %tmp46 = icmp slt i32 %phitmp15, 42 ; <i1> [#uses=1]
+ br i1 %tmp46, label %bb, label %bb49
+
+bb49: ; preds = %bb28, %entry
+ ret i16 0
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2008-10-03-CouldNotCompute.ll b/src/LLVM/test/Transforms/IndVarSimplify/2008-10-03-CouldNotCompute.ll
new file mode 100644
index 0000000..23e7884
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2008-10-03-CouldNotCompute.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -indvars
+; PR2857
+
+@foo = external global i32 ; <i32*> [#uses=1]
+
+define void @test(i32 %n, i32 %arg) {
+entry:
+ br i1 false, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ %0 = load i32* @foo, align 4 ; <i32> [#uses=1]
+ %1 = sext i32 %0 to i64 ; <i64> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %.in = phi i32 [ %2, %bb ], [ %n, %bb.nph ] ; <i32> [#uses=1]
+ %val.02 = phi i64 [ %5, %bb ], [ 0, %bb.nph ] ; <i64> [#uses=2]
+ %result.01 = phi i64 [ %4, %bb ], [ 0, %bb.nph ] ; <i64> [#uses=1]
+ %2 = add i32 %.in, -1 ; <i32> [#uses=2]
+ %3 = mul i64 %1, %val.02 ; <i64> [#uses=1]
+ %4 = add i64 %3, %result.01 ; <i64> [#uses=2]
+ %5 = add i64 %val.02, 1 ; <i64> [#uses=1]
+ %6 = icmp sgt i32 %2, 0 ; <i1> [#uses=1]
+ br i1 %6, label %bb, label %bb3.bb4_crit_edge
+
+bb3.bb4_crit_edge: ; preds = %bb
+ %.lcssa = phi i64 [ %4, %bb ] ; <i64> [#uses=0]
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2008-11-25-APFloatAssert.ll b/src/LLVM/test/Transforms/IndVarSimplify/2008-11-25-APFloatAssert.ll
new file mode 100644
index 0000000..39b97af
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2008-11-25-APFloatAssert.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -indvars
+
+define void @t() nounwind {
+entry:
+ br label %bb23.i91
+
+bb23.i91: ; preds = %bb23.i91, %entry
+ %result.0.i89 = phi ppc_fp128 [ 0xM00000000000000000000000000000000, %entry ], [ %0, %bb23.i91 ] ; <ppc_fp128> [#uses=2]
+ %0 = fmul ppc_fp128 %result.0.i89, %result.0.i89 ; <ppc_fp128> [#uses=1]
+ br label %bb23.i91
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2009-04-14-shorten_iv_vars.ll b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-14-shorten_iv_vars.ll
new file mode 100644
index 0000000..dd400be
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-14-shorten_iv_vars.ll
@@ -0,0 +1,114 @@
+; RUN: opt < %s -indvars -S | not grep {sext}
+; ModuleID = '<stdin>'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+target triple = "x86_64-apple-darwin9.6"
+@a = external global i32* ; <i32**> [#uses=3]
+@b = external global i32* ; <i32**> [#uses=3]
+@c = external global i32* ; <i32**> [#uses=3]
+@d = external global i32* ; <i32**> [#uses=3]
+@e = external global i32* ; <i32**> [#uses=3]
+@f = external global i32* ; <i32**> [#uses=3]
+
+define void @foo() nounwind {
+bb1.thread:
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %84, %bb1 ] ; <i32> [#uses=19]
+ %0 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %1 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %2 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %3 = getelementptr i32* %1, i64 %2 ; <i32*> [#uses=1]
+ %4 = load i32* %3, align 1 ; <i32> [#uses=1]
+ %5 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %6 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %7 = getelementptr i32* %5, i64 %6 ; <i32*> [#uses=1]
+ %8 = load i32* %7, align 1 ; <i32> [#uses=1]
+ %9 = add i32 %8, %4 ; <i32> [#uses=1]
+ %10 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %11 = getelementptr i32* %0, i64 %10 ; <i32*> [#uses=1]
+ store i32 %9, i32* %11, align 1
+ %12 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %13 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %14 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %15 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %16 = sext i32 %15 to i64 ; <i64> [#uses=1]
+ %17 = getelementptr i32* %14, i64 %16 ; <i32*> [#uses=1]
+ %18 = load i32* %17, align 1 ; <i32> [#uses=1]
+ %19 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %20 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %21 = sext i32 %20 to i64 ; <i64> [#uses=1]
+ %22 = getelementptr i32* %19, i64 %21 ; <i32*> [#uses=1]
+ %23 = load i32* %22, align 1 ; <i32> [#uses=1]
+ %24 = add i32 %23, %18 ; <i32> [#uses=1]
+ %25 = sext i32 %13 to i64 ; <i64> [#uses=1]
+ %26 = getelementptr i32* %12, i64 %25 ; <i32*> [#uses=1]
+ store i32 %24, i32* %26, align 1
+ %27 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %28 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %29 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %30 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %31 = sext i32 %30 to i64 ; <i64> [#uses=1]
+ %32 = getelementptr i32* %29, i64 %31 ; <i32*> [#uses=1]
+ %33 = load i32* %32, align 1 ; <i32> [#uses=1]
+ %34 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %35 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %36 = sext i32 %35 to i64 ; <i64> [#uses=1]
+ %37 = getelementptr i32* %34, i64 %36 ; <i32*> [#uses=1]
+ %38 = load i32* %37, align 1 ; <i32> [#uses=1]
+ %39 = add i32 %38, %33 ; <i32> [#uses=1]
+ %40 = sext i32 %28 to i64 ; <i64> [#uses=1]
+ %41 = getelementptr i32* %27, i64 %40 ; <i32*> [#uses=1]
+ store i32 %39, i32* %41, align 1
+ %42 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %43 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %44 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %45 = getelementptr i32* %43, i64 %44 ; <i32*> [#uses=1]
+ %46 = load i32* %45, align 1 ; <i32> [#uses=1]
+ %47 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %48 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %49 = getelementptr i32* %47, i64 %48 ; <i32*> [#uses=1]
+ %50 = load i32* %49, align 1 ; <i32> [#uses=1]
+ %51 = add i32 %50, %46 ; <i32> [#uses=1]
+ %52 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %53 = getelementptr i32* %42, i64 %52 ; <i32*> [#uses=1]
+ store i32 %51, i32* %53, align 1
+ %54 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %55 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %56 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %57 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %58 = sext i32 %57 to i64 ; <i64> [#uses=1]
+ %59 = getelementptr i32* %56, i64 %58 ; <i32*> [#uses=1]
+ %60 = load i32* %59, align 1 ; <i32> [#uses=1]
+ %61 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %62 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %63 = sext i32 %62 to i64 ; <i64> [#uses=1]
+ %64 = getelementptr i32* %61, i64 %63 ; <i32*> [#uses=1]
+ %65 = load i32* %64, align 1 ; <i32> [#uses=1]
+ %66 = add i32 %65, %60 ; <i32> [#uses=1]
+ %67 = sext i32 %55 to i64 ; <i64> [#uses=1]
+ %68 = getelementptr i32* %54, i64 %67 ; <i32*> [#uses=1]
+ store i32 %66, i32* %68, align 1
+ %69 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %70 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %71 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %72 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %73 = sext i32 %72 to i64 ; <i64> [#uses=1]
+ %74 = getelementptr i32* %71, i64 %73 ; <i32*> [#uses=1]
+ %75 = load i32* %74, align 1 ; <i32> [#uses=1]
+ %76 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %77 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %78 = sext i32 %77 to i64 ; <i64> [#uses=1]
+ %79 = getelementptr i32* %76, i64 %78 ; <i32*> [#uses=1]
+ %80 = load i32* %79, align 1 ; <i32> [#uses=1]
+ %81 = add i32 %80, %75 ; <i32> [#uses=1]
+ %82 = sext i32 %70 to i64 ; <i64> [#uses=1]
+ %83 = getelementptr i32* %69, i64 %82 ; <i32*> [#uses=1]
+ store i32 %81, i32* %83, align 1
+ %84 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %85 = icmp sgt i32 %84, 23646 ; <i1> [#uses=1]
+ br i1 %85, label %return, label %bb1
+
+return: ; preds = %bb1
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2009-04-15-shorten-iv-vars-2.ll b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-15-shorten-iv-vars-2.ll
new file mode 100644
index 0000000..55e8a50
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-15-shorten-iv-vars-2.ll
@@ -0,0 +1,160 @@
+; RUN: opt < %s -indvars -instcombine -S | not grep {\[sz\]ext}
+; ModuleID = '<stdin>'
+;extern int *a, *b, *c, *d, *e, *f; /* 64 bit */
+;extern int K[256];
+;void foo () {
+; int i;
+; for (i=0; i<23647; i++) {
+; a[(i&15)] = b[i&15]+c[i&15];
+; a[(i+1)&15] = b[(i+1)&15]+c[(i+1)&15];
+; a[(i+2)&15] = b[(i+2)&15]+c[(i+2)&15];
+; d[i&15] = e[i&15]+f[i&15] +K[i];
+; d[(i+1)&15] = e[(i+1)&15]+f[(i+1)&15]+K[i+1];
+; d[(i+2)&15] = e[(i+2)&15]+f[(i+2)&15]+K[i+2];
+; }
+;}
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+target triple = "x86_64-apple-darwin9.6"
+@a = external global i32* ; <i32**> [#uses=3]
+@b = external global i32* ; <i32**> [#uses=3]
+@c = external global i32* ; <i32**> [#uses=3]
+@d = external global i32* ; <i32**> [#uses=3]
+@e = external global i32* ; <i32**> [#uses=3]
+@f = external global i32* ; <i32**> [#uses=3]
+@K = external global [256 x i32] ; <[256 x i32]*> [#uses=3]
+
+define void @foo() nounwind {
+bb1.thread:
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb1.thread
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb1.thread ], [ %116, %bb1 ] ; <i32> [#uses=22]
+ %0 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %1 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %2 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %3 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %4 = zext i32 %3 to i64 ; <i64> [#uses=1]
+ %5 = getelementptr i32* %2, i64 %4 ; <i32*> [#uses=1]
+ %6 = load i32* %5, align 1 ; <i32> [#uses=1]
+ %7 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %8 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %9 = zext i32 %8 to i64 ; <i64> [#uses=1]
+ %10 = getelementptr i32* %7, i64 %9 ; <i32*> [#uses=1]
+ %11 = load i32* %10, align 1 ; <i32> [#uses=1]
+ %12 = add i32 %11, %6 ; <i32> [#uses=1]
+ %13 = zext i32 %1 to i64 ; <i64> [#uses=1]
+ %14 = getelementptr i32* %0, i64 %13 ; <i32*> [#uses=1]
+ store i32 %12, i32* %14, align 1
+ %15 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %16 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %17 = and i32 %16, 15 ; <i32> [#uses=1]
+ %18 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %19 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %20 = and i32 %19, 15 ; <i32> [#uses=1]
+ %21 = zext i32 %20 to i64 ; <i64> [#uses=1]
+ %22 = getelementptr i32* %18, i64 %21 ; <i32*> [#uses=1]
+ %23 = load i32* %22, align 1 ; <i32> [#uses=1]
+ %24 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %25 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %26 = and i32 %25, 15 ; <i32> [#uses=1]
+ %27 = zext i32 %26 to i64 ; <i64> [#uses=1]
+ %28 = getelementptr i32* %24, i64 %27 ; <i32*> [#uses=1]
+ %29 = load i32* %28, align 1 ; <i32> [#uses=1]
+ %30 = add i32 %29, %23 ; <i32> [#uses=1]
+ %31 = zext i32 %17 to i64 ; <i64> [#uses=1]
+ %32 = getelementptr i32* %15, i64 %31 ; <i32*> [#uses=1]
+ store i32 %30, i32* %32, align 1
+ %33 = load i32** @a, align 8 ; <i32*> [#uses=1]
+ %34 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %35 = and i32 %34, 15 ; <i32> [#uses=1]
+ %36 = load i32** @b, align 8 ; <i32*> [#uses=1]
+ %37 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %38 = and i32 %37, 15 ; <i32> [#uses=1]
+ %39 = zext i32 %38 to i64 ; <i64> [#uses=1]
+ %40 = getelementptr i32* %36, i64 %39 ; <i32*> [#uses=1]
+ %41 = load i32* %40, align 1 ; <i32> [#uses=1]
+ %42 = load i32** @c, align 8 ; <i32*> [#uses=1]
+ %43 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %44 = and i32 %43, 15 ; <i32> [#uses=1]
+ %45 = zext i32 %44 to i64 ; <i64> [#uses=1]
+ %46 = getelementptr i32* %42, i64 %45 ; <i32*> [#uses=1]
+ %47 = load i32* %46, align 1 ; <i32> [#uses=1]
+ %48 = add i32 %47, %41 ; <i32> [#uses=1]
+ %49 = zext i32 %35 to i64 ; <i64> [#uses=1]
+ %50 = getelementptr i32* %33, i64 %49 ; <i32*> [#uses=1]
+ store i32 %48, i32* %50, align 1
+ %51 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %52 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %53 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %54 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %55 = zext i32 %54 to i64 ; <i64> [#uses=1]
+ %56 = getelementptr i32* %53, i64 %55 ; <i32*> [#uses=1]
+ %57 = load i32* %56, align 1 ; <i32> [#uses=1]
+ %58 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %59 = and i32 %i.0.reg2mem.0, 15 ; <i32> [#uses=1]
+ %60 = zext i32 %59 to i64 ; <i64> [#uses=1]
+ %61 = getelementptr i32* %58, i64 %60 ; <i32*> [#uses=1]
+ %62 = load i32* %61, align 1 ; <i32> [#uses=1]
+ %63 = sext i32 %i.0.reg2mem.0 to i64 ; <i64> [#uses=1]
+ %64 = getelementptr [256 x i32]* @K, i64 0, i64 %63 ; <i32*> [#uses=1]
+ %65 = load i32* %64, align 4 ; <i32> [#uses=1]
+ %66 = add i32 %62, %57 ; <i32> [#uses=1]
+ %67 = add i32 %66, %65 ; <i32> [#uses=1]
+ %68 = zext i32 %52 to i64 ; <i64> [#uses=1]
+ %69 = getelementptr i32* %51, i64 %68 ; <i32*> [#uses=1]
+ store i32 %67, i32* %69, align 1
+ %70 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %71 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %72 = and i32 %71, 15 ; <i32> [#uses=1]
+ %73 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %74 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %75 = and i32 %74, 15 ; <i32> [#uses=1]
+ %76 = zext i32 %75 to i64 ; <i64> [#uses=1]
+ %77 = getelementptr i32* %73, i64 %76 ; <i32*> [#uses=1]
+ %78 = load i32* %77, align 1 ; <i32> [#uses=1]
+ %79 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %80 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %81 = and i32 %80, 15 ; <i32> [#uses=1]
+ %82 = zext i32 %81 to i64 ; <i64> [#uses=1]
+ %83 = getelementptr i32* %79, i64 %82 ; <i32*> [#uses=1]
+ %84 = load i32* %83, align 1 ; <i32> [#uses=1]
+ %85 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=1]
+ %86 = sext i32 %85 to i64 ; <i64> [#uses=1]
+ %87 = getelementptr [256 x i32]* @K, i64 0, i64 %86 ; <i32*> [#uses=1]
+ %88 = load i32* %87, align 4 ; <i32> [#uses=1]
+ %89 = add i32 %84, %78 ; <i32> [#uses=1]
+ %90 = add i32 %89, %88 ; <i32> [#uses=1]
+ %91 = zext i32 %72 to i64 ; <i64> [#uses=1]
+ %92 = getelementptr i32* %70, i64 %91 ; <i32*> [#uses=1]
+ store i32 %90, i32* %92, align 1
+ %93 = load i32** @d, align 8 ; <i32*> [#uses=1]
+ %94 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %95 = and i32 %94, 15 ; <i32> [#uses=1]
+ %96 = load i32** @e, align 8 ; <i32*> [#uses=1]
+ %97 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %98 = and i32 %97, 15 ; <i32> [#uses=1]
+ %99 = zext i32 %98 to i64 ; <i64> [#uses=1]
+ %100 = getelementptr i32* %96, i64 %99 ; <i32*> [#uses=1]
+ %101 = load i32* %100, align 1 ; <i32> [#uses=1]
+ %102 = load i32** @f, align 8 ; <i32*> [#uses=1]
+ %103 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %104 = and i32 %103, 15 ; <i32> [#uses=1]
+ %105 = zext i32 %104 to i64 ; <i64> [#uses=1]
+ %106 = getelementptr i32* %102, i64 %105 ; <i32*> [#uses=1]
+ %107 = load i32* %106, align 1 ; <i32> [#uses=1]
+ %108 = add i32 %i.0.reg2mem.0, 2 ; <i32> [#uses=1]
+ %109 = sext i32 %108 to i64 ; <i64> [#uses=1]
+ %110 = getelementptr [256 x i32]* @K, i64 0, i64 %109 ; <i32*> [#uses=1]
+ %111 = load i32* %110, align 4 ; <i32> [#uses=1]
+ %112 = add i32 %107, %101 ; <i32> [#uses=1]
+ %113 = add i32 %112, %111 ; <i32> [#uses=1]
+ %114 = zext i32 %95 to i64 ; <i64> [#uses=1]
+ %115 = getelementptr i32* %93, i64 %114 ; <i32*> [#uses=1]
+ store i32 %113, i32* %115, align 1
+ %116 = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %117 = icmp sgt i32 %116, 23646 ; <i1> [#uses=1]
+ br i1 %117, label %return, label %bb1
+
+return: ; preds = %bb1
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2009-04-22-IndvarCrash.ll b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-22-IndvarCrash.ll
new file mode 100644
index 0000000..24074bf
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-22-IndvarCrash.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -indvars
+; rdar://6817574
+
+define i32 @t1() nounwind ssp {
+entry:
+ br label %bb32
+
+bb32: ; preds = %bb32, %entry
+ %mbPartIdx.0.reg2mem.0 = phi i8 [ %2, %bb32 ], [ 0, %entry ] ; <i8> [#uses=3]
+ %0 = and i8 %mbPartIdx.0.reg2mem.0, 1 ; <i8> [#uses=0]
+ %1 = zext i8 %mbPartIdx.0.reg2mem.0 to i64 ; <i64> [#uses=0]
+ %2 = add i8 %mbPartIdx.0.reg2mem.0, 1 ; <i8> [#uses=2]
+ %3 = icmp ugt i8 %2, 3 ; <i1> [#uses=1]
+ br i1 %3, label %bb41, label %bb32
+
+bb41: ; preds = %bb32
+ ret i32 0
+}
+
+define i32 @t2() nounwind ssp {
+entry:
+ br label %bb116
+
+bb116: ; preds = %bb116, %entry
+ %mbPartIdx.1.reg2mem.0 = phi i8 [ %3, %bb116 ], [ 0, %entry ] ; <i8> [#uses=3]
+ %0 = and i8 %mbPartIdx.1.reg2mem.0, 1 ; <i8> [#uses=1]
+ %1 = zext i8 %mbPartIdx.1.reg2mem.0 to i64 ; <i64> [#uses=0]
+ %2 = zext i8 %0 to i32 ; <i32> [#uses=0]
+ %3 = add i8 %mbPartIdx.1.reg2mem.0, 1 ; <i8> [#uses=2]
+ %4 = icmp ugt i8 %3, 3 ; <i1> [#uses=1]
+ br i1 %4, label %bb131, label %bb116
+
+bb131: ; preds = %bb116
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2009-04-27-Floating.ll b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-27-Floating.ll
new file mode 100644
index 0000000..47164d8
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2009-04-27-Floating.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; PR4086
+declare void @foo()
+
+define void @test() {
+entry:
+ br label %loop_body
+
+loop_body:
+ %i = phi float [ %nexti, %loop_body ], [ 0.0, %entry ]
+ tail call void @foo()
+ %nexti = fadd float %i, 1.0
+ ; CHECK: icmp ne i32 %{{[a-zA-Z$._0-9]+}}, 2
+ %less = fcmp olt float %nexti, 2.0
+ br i1 %less, label %loop_body, label %done
+
+done:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2009-05-24-useafterfree.ll b/src/LLVM/test/Transforms/IndVarSimplify/2009-05-24-useafterfree.ll
new file mode 100644
index 0000000..d211e3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2009-05-24-useafterfree.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -indvars
+; PR4258
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define void @0(i32*, i32*, i32, i32) nounwind {
+ br i1 false, label %bb.nph1.preheader, label %.outer._crit_edge
+
+bb.nph1.preheader: ; preds = %4
+ %smax = select i1 false, i32 -1, i32 0 ; <i32> [#uses=1]
+ %tmp12 = sub i32 0, %smax ; <i32> [#uses=1]
+ br label %bb.nph1
+
+bb.nph1: ; preds = %.outer, %bb.nph1.preheader
+ br i1 undef, label %bb.nph3.preheader, label %.outer
+
+bb.nph3.preheader: ; preds = %bb.nph1
+ br label %bb.nph3
+
+bb.nph3: ; preds = %bb.nph3, %bb.nph3.preheader
+ %indvar7 = phi i32 [ %indvar.next8, %bb.nph3 ], [ 0, %bb.nph3.preheader ] ; <i32> [#uses=3]
+ %tmp9 = mul i32 %indvar7, -1 ; <i32> [#uses=1]
+ %tmp13 = add i32 %tmp9, %tmp12 ; <i32> [#uses=1]
+ %tmp14 = add i32 %tmp13, -2 ; <i32> [#uses=1]
+ %5 = icmp sgt i32 %tmp14, 0 ; <i1> [#uses=1]
+ %indvar.next8 = add i32 %indvar7, 1 ; <i32> [#uses=1]
+ br i1 %5, label %bb.nph3, label %.outer.loopexit
+
+.outer.loopexit: ; preds = %bb.nph3
+ %indvar7.lcssa = phi i32 [ %indvar7, %bb.nph3 ] ; <i32> [#uses=0]
+ br label %.outer
+
+.outer: ; preds = %.outer.loopexit, %bb.nph1
+ br i1 undef, label %bb.nph1, label %.outer._crit_edge.loopexit
+
+.outer._crit_edge.loopexit: ; preds = %.outer
+ br label %.outer._crit_edge
+
+.outer._crit_edge: ; preds = %.outer._crit_edge.loopexit, %4
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll
new file mode 100644
index 0000000..77354f7
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+; Test WidenIV::GetExtendedOperandRecurrence.
+; add219 should be extended to i64 because it is nsw, even though its
+; sext cannot be hoisted outside the loop.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+define void @test() nounwind {
+entry:
+ br i1 undef, label %for.body11, label %for.end285
+
+for.body11: ; preds = %entry
+ %shl = shl i32 1, 1
+ %shl132 = shl i32 %shl, 1
+ br label %for.body153
+
+for.body153: ; preds = %for.body153, %for.body11
+ br i1 undef, label %for.body170, label %for.body153
+
+; CHECK: add nsw i64 %indvars.iv, 1
+for.body170: ; preds = %for.body170, %for.body153
+ %i2.19 = phi i32 [ %add249, %for.body170 ], [ undef, %for.body153 ]
+ %add219 = add nsw i32 %i2.19, 1
+ %idxprom220 = sext i32 %add219 to i64
+ %add249 = add nsw i32 %i2.19, %shl132
+ br label %for.body170
+
+for.end285: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2011-09-19-vectoriv.ll b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-19-vectoriv.ll
new file mode 100644
index 0000000..6a01012
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-19-vectoriv.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; PR10946: Vector IVs are not SCEVable.
+; CHECK-NOT: phi
+define void @test() nounwind {
+allocas:
+ br i1 undef, label %cif_done, label %for_loop398
+
+cif_done: ; preds = %allocas
+ ret void
+
+for_loop398: ; preds = %for_loop398, %allocas
+ %storemerge35 = phi <4 x i32> [ %storemerge, %for_loop398 ], [ undef, %allocas ]
+ %bincmp431 = icmp sge <4 x i32> %storemerge35, <i32 5, i32 5, i32 5, i32 5>
+ %storemerge = bitcast <4 x float> undef to <4 x i32>
+ br label %for_loop398
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/2011-09-27-hoistsext.ll b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-27-hoistsext.ll
new file mode 100644
index 0000000..0737489
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/2011-09-27-hoistsext.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; Test indvars' ability to hoist new sext created by WidenIV.
+; From ffbench.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+define internal double @fourn(double* %data, i32 %x, i32 %y, i32 %n) nounwind {
+; CHECK: entry:
+; CHECK: sext
+; CHECK: sext
+entry:
+ br label %for.body
+
+; CHECK: for.body:
+; CHECK-NOT: sext
+; CHECK: br
+for.body:
+ %i2.115 = phi i32 [ 0, %entry ], [ %add249, %for.body ]
+ %add174 = add nsw i32 %i2.115, %x
+ %idxprom177 = sext i32 %add174 to i64
+ %arrayidx179 = getelementptr inbounds double* %data, i64 %idxprom177
+ %tmp180 = load double* %arrayidx179, align 8
+ %add249 = add nsw i32 %i2.115, %y
+ %cmp168 = icmp sgt i32 %add249, %n
+ br i1 %cmp168, label %exit, label %for.body
+
+exit:
+ ret double %tmp180
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/ada-loops.ll b/src/LLVM/test/Transforms/IndVarSimplify/ada-loops.ll
new file mode 100644
index 0000000..154de6f
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/ada-loops.ll
@@ -0,0 +1,93 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+;
+; PR1301
+
+; Do a bunch of analysis and prove that the loops can use an i32 trip
+; count without casting.
+;
+; Note that all four functions should actually be converted to
+; memset. However, this test case validates indvars behavior. We
+; don't check that phis are "folded together" because that is a job
+; for loop strength reduction. But indvars must remove sext, zext, and add i8.
+;
+; CHECK-NOT: {{sext|zext|add i8}}
+
+; ModuleID = 'ada.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32"
+target triple = "i686-pc-linux-gnu"
+
+define void @kinds__sbytezero([256 x i32]* nocapture %a) nounwind {
+bb.thread:
+ %tmp46 = getelementptr [256 x i32]* %a, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp46
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ -128, %bb.thread ], [ %tmp8, %bb ] ; <i8> [#uses=1]
+ %tmp8 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=3]
+ %tmp1 = sext i8 %tmp8 to i32 ; <i32> [#uses=1]
+ %tmp3 = add i32 %tmp1, 128 ; <i32> [#uses=1]
+ %tmp4 = getelementptr [256 x i32]* %a, i32 0, i32 %tmp3 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp4
+ %0 = icmp eq i8 %tmp8, 127 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
+
+define void @kinds__ubytezero([256 x i32]* nocapture %a) nounwind {
+bb.thread:
+ %tmp35 = getelementptr [256 x i32]* %a, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp35
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ 0, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=1]
+ %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=3]
+ %tmp1 = zext i8 %tmp7 to i32 ; <i32> [#uses=1]
+ %tmp3 = getelementptr [256 x i32]* %a, i32 0, i32 %tmp1 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp3
+ %0 = icmp eq i8 %tmp7, -1 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
+
+define void @kinds__srangezero([21 x i32]* nocapture %a) nounwind {
+bb.thread:
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ -10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2]
+ %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp12, 10 ; <i32> [#uses=1]
+ %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp5
+ %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2]
+ %0 = icmp sgt i8 %tmp7, 10 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
+
+define void @kinds__urangezero([21 x i32]* nocapture %a) nounwind {
+bb.thread:
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ 10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2]
+ %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp12, -10 ; <i32> [#uses=1]
+ %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp5
+ %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2]
+ %0 = icmp sgt i8 %tmp7, 30 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/addrec-gep.ll b/src/LLVM/test/Transforms/IndVarSimplify/addrec-gep.ll
new file mode 100644
index 0000000..b62d093
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/addrec-gep.ll
@@ -0,0 +1,78 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK: getelementptr
+; CHECK: mul {{.*}}, 37
+; CHECK: add {{.*}}, 5203
+; CHECK-NOT: cast
+
+; This test tests several things. The load and store should use the
+; same address instead of having it computed twice, and SCEVExpander should
+; be able to reconstruct the full getelementptr, despite it having a few
+; obstacles set in its way.
+
+target datalayout = "e-p:64:64:64-n32:64"
+
+define void @foo(i64 %n, i64 %m, i64 %o, i64 %q, double* nocapture %p) nounwind {
+entry:
+ %tmp = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
+ br i1 %tmp, label %bb.nph3, label %return
+
+bb.nph: ; preds = %bb2.preheader
+ %tmp1 = mul i64 %tmp16, %i.02 ; <i64> [#uses=1]
+ %tmp2 = mul i64 %tmp19, %i.02 ; <i64> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb2, %bb.nph
+ %j.01 = phi i64 [ %tmp9, %bb2 ], [ 0, %bb.nph ] ; <i64> [#uses=3]
+ %tmp3 = add i64 %j.01, %tmp1 ; <i64> [#uses=1]
+ %tmp4 = add i64 %j.01, %tmp2 ; <i64> [#uses=1]
+ %z0 = add i64 %tmp3, 5203
+ %tmp5 = getelementptr double* %p, i64 %z0 ; <double*> [#uses=1]
+ %tmp6 = load double* %tmp5, align 8 ; <double> [#uses=1]
+ %tmp7 = fdiv double %tmp6, 2.100000e+00 ; <double> [#uses=1]
+ %z1 = add i64 %tmp4, 5203
+ %tmp8 = getelementptr double* %p, i64 %z1 ; <double*> [#uses=1]
+ store double %tmp7, double* %tmp8, align 8
+ %tmp9 = add i64 %j.01, 1 ; <i64> [#uses=2]
+ br label %bb2
+
+bb2: ; preds = %bb1
+ %tmp10 = icmp slt i64 %tmp9, %m ; <i1> [#uses=1]
+ br i1 %tmp10, label %bb1, label %bb2.bb3_crit_edge
+
+bb2.bb3_crit_edge: ; preds = %bb2
+ br label %bb3
+
+bb3: ; preds = %bb2.preheader, %bb2.bb3_crit_edge
+ %tmp11 = add i64 %i.02, 1 ; <i64> [#uses=2]
+ br label %bb4
+
+bb4: ; preds = %bb3
+ %tmp12 = icmp slt i64 %tmp11, %n ; <i1> [#uses=1]
+ br i1 %tmp12, label %bb2.preheader, label %bb4.return_crit_edge
+
+bb4.return_crit_edge: ; preds = %bb4
+ br label %bb4.return_crit_edge.split
+
+bb4.return_crit_edge.split: ; preds = %bb.nph3, %bb4.return_crit_edge
+ br label %return
+
+bb.nph3: ; preds = %entry
+ %tmp13 = icmp sgt i64 %m, 0 ; <i1> [#uses=1]
+ %tmp14 = mul i64 %n, 37 ; <i64> [#uses=1]
+ %tmp15 = mul i64 %tmp14, %o ; <i64> [#uses=1]
+ %tmp16 = mul i64 %tmp15, %q ; <i64> [#uses=1]
+ %tmp17 = mul i64 %n, 37 ; <i64> [#uses=1]
+ %tmp18 = mul i64 %tmp17, %o ; <i64> [#uses=1]
+ %tmp19 = mul i64 %tmp18, %q ; <i64> [#uses=1]
+ br i1 %tmp13, label %bb.nph3.split, label %bb4.return_crit_edge.split
+
+bb.nph3.split: ; preds = %bb.nph3
+ br label %bb2.preheader
+
+bb2.preheader: ; preds = %bb.nph3.split, %bb4
+ %i.02 = phi i64 [ %tmp11, %bb4 ], [ 0, %bb.nph3.split ] ; <i64> [#uses=3]
+ br i1 true, label %bb.nph, label %bb3
+
+return: ; preds = %bb4.return_crit_edge.split, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/ashr-tripcount.ll b/src/LLVM/test/Transforms/IndVarSimplify/ashr-tripcount.ll
new file mode 100644
index 0000000..b47c8ad
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/ashr-tripcount.ll
@@ -0,0 +1,107 @@
+; RUN: opt < %s -indvars -S > %t
+; RUN: grep sext %t | count 1
+
+; Indvars should be able to eliminate all of the sign extensions
+; inside the loop.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+@pow_2_tab = external constant [0 x float] ; <[0 x float]*> [#uses=1]
+@pow_2_025_tab = external constant [0 x float] ; <[0 x float]*> [#uses=1]
+@i_pow_2_tab = external constant [0 x float] ; <[0 x float]*> [#uses=1]
+@i_pow_2_025_tab = external constant [0 x float] ; <[0 x float]*> [#uses=1]
+
+define void @foo(i32 %gain, i32 %noOfLines, i32* %quaSpectrum, float* %iquaSpectrum, float* %pow4_3_tab_ptr) nounwind {
+entry:
+ %t0 = icmp slt i32 %gain, 0 ; <i1> [#uses=1]
+ br i1 %t0, label %bb1, label %bb2
+
+bb1: ; preds = %entry
+ %t1 = sub i32 0, %gain ; <i32> [#uses=1]
+ %t2 = sub i32 0, %gain ; <i32> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb1, %entry
+ %pow_2_tab.pn = phi [0 x float]* [ @i_pow_2_tab, %bb1 ], [ @pow_2_tab, %entry ] ; <[0 x float]*> [#uses=1]
+ %.pn3.in.in = phi i32 [ %t1, %bb1 ], [ %gain, %entry ] ; <i32> [#uses=1]
+ %pow_2_025_tab.pn = phi [0 x float]* [ @i_pow_2_025_tab, %bb1 ], [ @pow_2_025_tab, %entry ] ; <[0 x float]*> [#uses=1]
+ %.pn2.in.in = phi i32 [ %t2, %bb1 ], [ %gain, %entry ] ; <i32> [#uses=1]
+ %.pn3.in = ashr i32 %.pn3.in.in, 2 ; <i32> [#uses=1]
+ %.pn2.in = and i32 %.pn2.in.in, 3 ; <i32> [#uses=1]
+ %.pn3 = sext i32 %.pn3.in to i64 ; <i64> [#uses=1]
+ %.pn2 = zext i32 %.pn2.in to i64 ; <i64> [#uses=1]
+ %.pn.in = getelementptr [0 x float]* %pow_2_tab.pn, i64 0, i64 %.pn3 ; <float*> [#uses=1]
+ %.pn1.in = getelementptr [0 x float]* %pow_2_025_tab.pn, i64 0, i64 %.pn2 ; <float*> [#uses=1]
+ %.pn = load float* %.pn.in ; <float> [#uses=1]
+ %.pn1 = load float* %.pn1.in ; <float> [#uses=1]
+ %invQuantizer.0 = fmul float %.pn, %.pn1 ; <float> [#uses=4]
+ %t3 = ashr i32 %noOfLines, 2 ; <i32> [#uses=1]
+ %t4 = icmp sgt i32 %t3, 0 ; <i1> [#uses=1]
+ br i1 %t4, label %bb.nph, label %return
+
+bb.nph: ; preds = %bb2
+ %t5 = ashr i32 %noOfLines, 2 ; <i32> [#uses=1]
+ br label %bb3
+
+bb3: ; preds = %bb4, %bb.nph
+ %i.05 = phi i32 [ %t49, %bb4 ], [ 0, %bb.nph ] ; <i32> [#uses=9]
+ %k.04 = phi i32 [ %t48, %bb4 ], [ 0, %bb.nph ] ; <i32> [#uses=1]
+ %t6 = sext i32 %i.05 to i64 ; <i64> [#uses=1]
+ %t7 = getelementptr i32* %quaSpectrum, i64 %t6 ; <i32*> [#uses=1]
+ %t8 = load i32* %t7, align 4 ; <i32> [#uses=1]
+ %t9 = zext i32 %t8 to i64 ; <i64> [#uses=1]
+ %t10 = getelementptr float* %pow4_3_tab_ptr, i64 %t9 ; <float*> [#uses=1]
+ %t11 = load float* %t10, align 4 ; <float> [#uses=1]
+ %t12 = or i32 %i.05, 1 ; <i32> [#uses=1]
+ %t13 = sext i32 %t12 to i64 ; <i64> [#uses=1]
+ %t14 = getelementptr i32* %quaSpectrum, i64 %t13 ; <i32*> [#uses=1]
+ %t15 = load i32* %t14, align 4 ; <i32> [#uses=1]
+ %t16 = zext i32 %t15 to i64 ; <i64> [#uses=1]
+ %t17 = getelementptr float* %pow4_3_tab_ptr, i64 %t16 ; <float*> [#uses=1]
+ %t18 = load float* %t17, align 4 ; <float> [#uses=1]
+ %t19 = or i32 %i.05, 2 ; <i32> [#uses=1]
+ %t20 = sext i32 %t19 to i64 ; <i64> [#uses=1]
+ %t21 = getelementptr i32* %quaSpectrum, i64 %t20 ; <i32*> [#uses=1]
+ %t22 = load i32* %t21, align 4 ; <i32> [#uses=1]
+ %t23 = zext i32 %t22 to i64 ; <i64> [#uses=1]
+ %t24 = getelementptr float* %pow4_3_tab_ptr, i64 %t23 ; <float*> [#uses=1]
+ %t25 = load float* %t24, align 4 ; <float> [#uses=1]
+ %t26 = or i32 %i.05, 3 ; <i32> [#uses=1]
+ %t27 = sext i32 %t26 to i64 ; <i64> [#uses=1]
+ %t28 = getelementptr i32* %quaSpectrum, i64 %t27 ; <i32*> [#uses=1]
+ %t29 = load i32* %t28, align 4 ; <i32> [#uses=1]
+ %t30 = zext i32 %t29 to i64 ; <i64> [#uses=1]
+ %t31 = getelementptr float* %pow4_3_tab_ptr, i64 %t30 ; <float*> [#uses=1]
+ %t32 = load float* %t31, align 4 ; <float> [#uses=1]
+ %t33 = fmul float %t11, %invQuantizer.0 ; <float> [#uses=1]
+ %t34 = sext i32 %i.05 to i64 ; <i64> [#uses=1]
+ %t35 = getelementptr float* %iquaSpectrum, i64 %t34 ; <float*> [#uses=1]
+ store float %t33, float* %t35, align 4
+ %t36 = or i32 %i.05, 1 ; <i32> [#uses=1]
+ %t37 = fmul float %t18, %invQuantizer.0 ; <float> [#uses=1]
+ %t38 = sext i32 %t36 to i64 ; <i64> [#uses=1]
+ %t39 = getelementptr float* %iquaSpectrum, i64 %t38 ; <float*> [#uses=1]
+ store float %t37, float* %t39, align 4
+ %t40 = or i32 %i.05, 2 ; <i32> [#uses=1]
+ %t41 = fmul float %t25, %invQuantizer.0 ; <float> [#uses=1]
+ %t42 = sext i32 %t40 to i64 ; <i64> [#uses=1]
+ %t43 = getelementptr float* %iquaSpectrum, i64 %t42 ; <float*> [#uses=1]
+ store float %t41, float* %t43, align 4
+ %t44 = or i32 %i.05, 3 ; <i32> [#uses=1]
+ %t45 = fmul float %t32, %invQuantizer.0 ; <float> [#uses=1]
+ %t46 = sext i32 %t44 to i64 ; <i64> [#uses=1]
+ %t47 = getelementptr float* %iquaSpectrum, i64 %t46 ; <float*> [#uses=1]
+ store float %t45, float* %t47, align 4
+ %t48 = add i32 %k.04, 1 ; <i32> [#uses=2]
+ %t49 = add i32 %i.05, 4 ; <i32> [#uses=1]
+ br label %bb4
+
+bb4: ; preds = %bb3
+ %t50 = icmp sgt i32 %t5, %t48 ; <i1> [#uses=1]
+ br i1 %t50, label %bb3, label %bb4.return_crit_edge
+
+bb4.return_crit_edge: ; preds = %bb4
+ br label %return
+
+return: ; preds = %bb4.return_crit_edge, %bb2
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/avoid-i0.ll b/src/LLVM/test/Transforms/IndVarSimplify/avoid-i0.ll
new file mode 100644
index 0000000..59661fa
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/avoid-i0.ll
@@ -0,0 +1,126 @@
+; RUN: opt < %s -indvars
+; PR4052
+; PR4054
+
+; Don't treat an and with 0 as a mask (trunc+zext).
+
+define i32 @int80(i8 signext %p_71) nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb6, %entry
+ %p_71_addr.0 = phi i8 [ %p_71, %entry ], [ %0, %bb6 ] ; <i8> [#uses=0]
+ br i1 undef, label %bb4, label %bb1
+
+bb1: ; preds = %bb
+ ret i32 0
+
+bb4: ; preds = %bb4, %bb
+ br i1 undef, label %bb6, label %bb4
+
+bb6: ; preds = %bb4
+ %0 = and i8 0, 0 ; <i8> [#uses=1]
+ br label %bb
+}
+
+@x = common global i32 0 ; <i32*> [#uses=1]
+
+define signext i8 @safe_sub_func_int32_t_s_s(i32 %_si1, i8 signext %_si2) nounwind {
+entry:
+ %_si1_addr = alloca i32 ; <i32*> [#uses=3]
+ %_si2_addr = alloca i8 ; <i8*> [#uses=3]
+ %retval = alloca i32 ; <i32*> [#uses=2]
+ %0 = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %_si1, i32* %_si1_addr
+ store i8 %_si2, i8* %_si2_addr
+ %1 = load i8* %_si2_addr, align 1 ; <i8> [#uses=1]
+ %2 = sext i8 %1 to i32 ; <i32> [#uses=1]
+ %3 = load i32* %_si1_addr, align 4 ; <i32> [#uses=1]
+ %4 = xor i32 %2, %3 ; <i32> [#uses=1]
+ %5 = load i8* %_si2_addr, align 1 ; <i8> [#uses=1]
+ %6 = sext i8 %5 to i32 ; <i32> [#uses=1]
+ %7 = sub i32 7, %6 ; <i32> [#uses=1]
+ %8 = load i32* %_si1_addr, align 4 ; <i32> [#uses=1]
+ %9 = shl i32 %8, %7 ; <i32> [#uses=1]
+ %10 = and i32 %4, %9 ; <i32> [#uses=1]
+ %11 = icmp slt i32 %10, 0 ; <i1> [#uses=1]
+ %12 = zext i1 %11 to i32 ; <i32> [#uses=1]
+ store i32 %12, i32* %0, align 4
+ %13 = load i32* %0, align 4 ; <i32> [#uses=1]
+ store i32 %13, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; <i32> [#uses=1]
+ %retval12 = trunc i32 %retval1 to i8 ; <i8> [#uses=1]
+ ret i8 %retval12
+}
+
+define i32 @safe_sub_func_uint64_t_u_u(i32 %_ui1, i32 %_ui2) nounwind {
+entry:
+ %_ui1_addr = alloca i32 ; <i32*> [#uses=2]
+ %_ui2_addr = alloca i32 ; <i32*> [#uses=1]
+ %retval = alloca i32 ; <i32*> [#uses=2]
+ %0 = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %_ui1, i32* %_ui1_addr
+ store i32 %_ui2, i32* %_ui2_addr
+ %1 = load i32* %_ui1_addr, align 4 ; <i32> [#uses=1]
+ %2 = sub i32 %1, 1 ; <i32> [#uses=1]
+ store i32 %2, i32* %0, align 4
+ %3 = load i32* %0, align 4 ; <i32> [#uses=1]
+ store i32 %3, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval1
+}
+
+define void @int87(i8 signext %p_48, i8 signext %p_49) nounwind {
+entry:
+ %p_48_addr = alloca i8 ; <i8*> [#uses=1]
+ %p_49_addr = alloca i8 ; <i8*> [#uses=1]
+ %l_52 = alloca i32 ; <i32*> [#uses=7]
+ %vol.0 = alloca i32 ; <i32*> [#uses=1]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i8 %p_48, i8* %p_48_addr
+ store i8 %p_49, i8* %p_49_addr
+ br label %bb4
+
+bb: ; preds = %bb4
+ %0 = volatile load i32* @x, align 4 ; <i32> [#uses=1]
+ store i32 %0, i32* %vol.0, align 4
+ store i32 0, i32* %l_52, align 4
+ br label %bb2
+
+bb1: ; preds = %bb2
+ %1 = load i32* %l_52, align 4 ; <i32> [#uses=1]
+ %2 = call i32 @safe_sub_func_uint64_t_u_u(i32 %1, i32 1) nounwind ; <i32> [#uses=1]
+ store i32 %2, i32* %l_52, align 4
+ br label %bb2
+
+bb2: ; preds = %bb1, %bb
+ %3 = load i32* %l_52, align 4 ; <i32> [#uses=1]
+ %4 = icmp eq i32 %3, 0 ; <i1> [#uses=1]
+ br i1 %4, label %bb1, label %bb3
+
+bb3: ; preds = %bb2
+ %5 = load i32* %l_52, align 4 ; <i32> [#uses=1]
+ %6 = call signext i8 @safe_sub_func_int32_t_s_s(i32 %5, i8 signext 1) nounwind ; <i8> [#uses=1]
+ %7 = sext i8 %6 to i32 ; <i32> [#uses=1]
+ store i32 %7, i32* %l_52, align 4
+ br label %bb4
+
+bb4: ; preds = %bb3, %entry
+ %8 = load i32* %l_52, align 4 ; <i32> [#uses=1]
+ %9 = icmp ne i32 %8, 0 ; <i1> [#uses=1]
+ br i1 %9, label %bb, label %bb5
+
+bb5: ; preds = %bb4
+ br label %return
+
+return: ; preds = %bb5
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/casted-argument.ll b/src/LLVM/test/Transforms/IndVarSimplify/casted-argument.ll
new file mode 100644
index 0000000..a5e002b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/casted-argument.ll
@@ -0,0 +1,50 @@
+; RUN: opt < %s -indvars -disable-output
+; PR4009
+; PR4038
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define void @safe_bcopy(i8* %to) nounwind {
+entry:
+ %cmp11 = icmp ult i8* %to, null ; <i1> [#uses=1]
+ br i1 %cmp11, label %loop, label %return
+
+return: ; preds = %entry
+ ret void
+
+loop: ; preds = %loop, %if.else
+ %pn = phi i8* [ %ge, %loop ], [ null, %entry ] ; <i8*> [#uses=1]
+ %cp = ptrtoint i8* %to to i32 ; <i32> [#uses=1]
+ %su = sub i32 0, %cp ; <i32> [#uses=1]
+ %ge = getelementptr i8* %pn, i32 %su ; <i8*> [#uses=2]
+ tail call void @bcopy(i8* %ge) nounwind
+ br label %loop
+}
+
+define void @safe_bcopy_4038(i8* %from, i8* %to, i32 %size) nounwind {
+entry:
+ br i1 false, label %if.else, label %if.then12
+
+if.then12: ; preds = %entry
+ ret void
+
+if.else: ; preds = %entry
+ %sub.ptr.rhs.cast40 = ptrtoint i8* %from to i32 ; <i32> [#uses=1]
+ br label %if.end54
+
+if.end54: ; preds = %if.end54, %if.else
+ %sub.ptr4912.pn = phi i8* [ %sub.ptr4912, %if.end54 ], [ null, %if.else ] ; <i8*> [#uses=1]
+ %sub.ptr7 = phi i8* [ %sub.ptr, %if.end54 ], [ null, %if.else ] ; <i8*> [#uses=2]
+ %sub.ptr.rhs.cast46.pn = ptrtoint i8* %from to i32 ; <i32> [#uses=1]
+ %sub.ptr.lhs.cast45.pn = ptrtoint i8* %to to i32 ; <i32> [#uses=1]
+ %sub.ptr.sub47.pn = sub i32 %sub.ptr.rhs.cast46.pn, %sub.ptr.lhs.cast45.pn ; <i32> [#uses=1]
+ %sub.ptr4912 = getelementptr i8* %sub.ptr4912.pn, i32 %sub.ptr.sub47.pn ; <i8*> [#uses=2]
+ tail call void @bcopy_4038(i8* %sub.ptr4912, i8* %sub.ptr7, i32 0) nounwind
+ %sub.ptr = getelementptr i8* %sub.ptr7, i32 %sub.ptr.rhs.cast40 ; <i8*> [#uses=1]
+ br label %if.end54
+}
+
+declare void @bcopy(i8* nocapture) nounwind
+
+declare void @bcopy_4038(i8*, i8*, i32) nounwind
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/complex-scev.ll b/src/LLVM/test/Transforms/IndVarSimplify/complex-scev.ll
new file mode 100644
index 0000000..f6fc7f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/complex-scev.ll
@@ -0,0 +1,31 @@
+; The i induction variable looks like a wrap-around, but it really is just
+; a simple affine IV. Make sure that indvars eliminates it.
+
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK: phi
+; CHECK-NOT: phi
+
+define void @foo() {
+entry:
+ br label %bb6
+
+bb6: ; preds = %cond_true, %entry
+ %j.0 = phi i32 [ 1, %entry ], [ %tmp5, %cond_true ] ; <i32> [#uses=3]
+ %i.0 = phi i32 [ 0, %entry ], [ %j.0, %cond_true ] ; <i32> [#uses=1]
+ %tmp7 = call i32 (...)* @foo2( ) ; <i32> [#uses=1]
+ %tmp = icmp ne i32 %tmp7, 0 ; <i1> [#uses=1]
+ br i1 %tmp, label %cond_true, label %return
+
+cond_true: ; preds = %bb6
+ %tmp2 = call i32 (...)* @bar( i32 %i.0, i32 %j.0 ) ; <i32> [#uses=0]
+ %tmp5 = add i32 %j.0, 1 ; <i32> [#uses=1]
+ br label %bb6
+
+return: ; preds = %bb6
+ ret void
+}
+
+declare i32 @bar(...)
+
+declare i32 @foo2(...)
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/crash.ll b/src/LLVM/test/Transforms/IndVarSimplify/crash.ll
new file mode 100644
index 0000000..3335be7
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/crash.ll
@@ -0,0 +1,89 @@
+; RUN: opt -indvars %s -disable-output
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+declare i32 @putchar(i8) nounwind
+
+define void @t2(i1* %P) nounwind {
+; <label>:0
+ br label %1
+
+; <label>:1 ; preds = %1, %0
+ %2 = phi double [ 9.000000e+00, %0 ], [ %4, %1 ] ; <double> [#uses=1]
+ %3 = tail call i32 @putchar(i8 72) ; <i32> [#uses=0]
+ %4 = fadd double %2, -1.000000e+00 ; <double> [#uses=2]
+ %5 = fcmp ult double %4, 0.000000e+00 ; <i1> [#uses=1]
+ store i1 %5, i1* %P
+ br i1 %5, label %6, label %1
+
+; <label>:6 ; preds = %1
+ ret void
+}
+
+; PR7562
+define void @fannkuch() nounwind {
+entry: ; preds = %entry
+ br label %bb12
+
+bb12: ; preds = %bb29, %entry
+ %i.1 = phi i32 [ undef, %entry ], [ %i.0, %bb29 ] ; <i32> [#uses=2]
+ %r.1 = phi i32 [ undef, %entry ], [ %r.0, %bb29 ] ; <i32> [#uses=2]
+ br i1 undef, label %bb13, label %bb24
+
+bb13: ; preds = %bb12
+ br label %bb24
+
+bb24: ; preds = %bb30, %bb13, %bb12
+ %i.2 = phi i32 [ %i.1, %bb13 ], [ %i.0, %bb30 ], [ %i.1, %bb12 ] ; <i32> [#uses=1]
+ %r.0 = phi i32 [ %r.1, %bb13 ], [ %2, %bb30 ], [ %r.1, %bb12 ] ; <i32> [#uses=3]
+ br label %bb28
+
+bb27: ; preds = %bb28
+ %0 = add nsw i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb28
+
+bb28: ; preds = %bb27, %bb26
+ %i.0 = phi i32 [ %i.2, %bb24 ], [ %0, %bb27 ] ; <i32> [#uses=4]
+ %1 = icmp slt i32 %i.0, %r.0 ; <i1> [#uses=1]
+ br i1 %1, label %bb27, label %bb29
+
+bb29: ; preds = %bb28
+ br i1 undef, label %bb12, label %bb30
+
+bb30: ; preds = %bb29
+ %2 = add nsw i32 %r.0, 1 ; <i32> [#uses=1]
+ br label %bb24
+}
+
+; PR10770
+
+declare void @__go_panic() noreturn
+
+declare void @__go_undefer()
+
+declare i32 @__gccgo_personality_v0(i32, i64, i8*, i8*)
+
+define void @main.main() uwtable {
+entry:
+ invoke void @__go_panic() noreturn
+ to label %0 unwind label %"5.i"
+
+; <label>:0 ; preds = %entry
+ unreachable
+
+"3.i": ; preds = %"7.i", %"5.i"
+ invoke void @__go_undefer()
+ to label %main.f.exit unwind label %"7.i"
+
+"5.i": ; preds = %entry
+ %1 = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gccgo_personality_v0
+ catch i8* null
+ br label %"3.i"
+
+"7.i": ; preds = %"3.i"
+ %2 = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gccgo_personality_v0
+ catch i8* null
+ br label %"3.i"
+
+main.f.exit: ; preds = %"3.i"
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/dangling-use.ll b/src/LLVM/test/Transforms/IndVarSimplify/dangling-use.ll
new file mode 100644
index 0000000..51c3120
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/dangling-use.ll
@@ -0,0 +1,41 @@
+; RUN: opt -indvars -disable-output < %s
+
+target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i8:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f128:64:128-n32"
+target triple = "powerpc-apple-darwin11"
+
+define void @vec_inverse_5_7_vert_loop_copyseparate(i8* %x, i32 %n, i32 %rowbytes) nounwind {
+entry:
+ %tmp1 = sdiv i32 %n, 3 ; <i32> [#uses=1]
+ %tmp2 = sdiv i32 %rowbytes, 5 ; <i32> [#uses=2]
+ br label %bb49
+
+bb49: ; preds = %bb48, %entry
+ %x_addr.0 = phi i8* [ %x, %entry ], [ %tmp481, %bb48 ] ; <i8*> [#uses=2]
+ br label %bb10
+
+bb10: ; preds = %bb49
+ %tmp326 = mul nsw i32 %tmp1, %tmp2 ; <i32> [#uses=1]
+ %tmp351 = getelementptr inbounds i8* %x_addr.0, i32 %tmp326 ; <i8*> [#uses=1]
+ br i1 false, label %bb.nph, label %bb48
+
+bb.nph: ; preds = %bb10
+ br label %bb23
+
+bb23: ; preds = %bb28, %bb.nph
+ %pOriginHi.01 = phi i8* [ %tmp351, %bb.nph ], [ %pOriginHi.0, %bb28 ] ; <i8*> [#uses=2]
+ %tmp378 = bitcast i8* %pOriginHi.01 to i8* ; <i8*> [#uses=1]
+ store i8* %tmp378, i8** null
+ %tmp385 = getelementptr inbounds i8* %pOriginHi.01, i32 %tmp2 ; <i8*> [#uses=1]
+ br label %bb28
+
+bb28: ; preds = %bb23
+ %pOriginHi.0 = phi i8* [ %tmp385, %bb23 ] ; <i8*> [#uses=1]
+ br i1 false, label %bb23, label %bb28.bb48_crit_edge
+
+bb28.bb48_crit_edge: ; preds = %bb28
+ br label %bb48
+
+bb48: ; preds = %bb28.bb48_crit_edge, %bb10
+ %tmp481 = getelementptr inbounds i8* %x_addr.0, i32 1 ; <i8*> [#uses=1]
+ br label %bb49
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/dg.exp b/src/LLVM/test/Transforms/IndVarSimplify/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/divide-pointer.ll b/src/LLVM/test/Transforms/IndVarSimplify/divide-pointer.ll
new file mode 100644
index 0000000..16608ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/divide-pointer.ll
@@ -0,0 +1,95 @@
+; RUN: opt < %s -indvars
+; PR4271
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+ %struct.xyz = type <{ i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, [8 x i8], i64, i64, i32, i32, [4 x i32], i32, i32, i32, i32, i32, i32, [76 x i32], i32, [2 x %struct.uvw] }>
+ %struct.uvw = type <{ i64, i64 }>
+
+define i32 @foo(%struct.xyz* %header, i8* %p2, i8* %p3, i8* nocapture %p4) nounwind {
+entry:
+ br label %while.body.i
+
+while.body.i: ; preds = %while.body.i, %entry
+ br i1 undef, label %while.body.i, label %bcopy_internal.exit
+
+bcopy_internal.exit: ; preds = %while.body.i
+ %conv135 = ptrtoint %struct.xyz* %header to i32 ; <i32> [#uses=1]
+ %shr136 = lshr i32 %conv135, 12 ; <i32> [#uses=1]
+ br label %for.body
+
+for.body: ; preds = %for.body, %bcopy_internal.exit
+ %ppnum.052 = phi i32 [ %inc, %for.body ], [ %shr136, %bcopy_internal.exit ] ; <i32> [#uses=1]
+ %inc = add i32 %ppnum.052, 1 ; <i32> [#uses=2]
+ %cmp = icmp ugt i32 %inc, undef ; <i1> [#uses=1]
+ br i1 %cmp, label %if.then199, label %for.body
+
+if.then199: ; preds = %if.then199, %for.body
+ br label %if.then199
+}
+
+define i32 @same_thing_but_signed(%struct.xyz* %header, i8* %p2, i8* %p3, i8* nocapture %p4) nounwind {
+entry:
+ br label %while.body.i
+
+while.body.i: ; preds = %while.body.i, %entry
+ br i1 undef, label %while.body.i, label %bcopy_internal.exit
+
+bcopy_internal.exit: ; preds = %while.body.i
+ %conv135 = ptrtoint %struct.xyz* %header to i32 ; <i32> [#uses=1]
+ %shr136 = ashr i32 %conv135, 12 ; <i32> [#uses=1]
+ br label %for.body
+
+for.body: ; preds = %for.body, %bcopy_internal.exit
+ %ppnum.052 = phi i32 [ %inc, %for.body ], [ %shr136, %bcopy_internal.exit ] ; <i32> [#uses=1]
+ %inc = add i32 %ppnum.052, 1 ; <i32> [#uses=2]
+ %cmp = icmp ugt i32 %inc, undef ; <i1> [#uses=1]
+ br i1 %cmp, label %if.then199, label %for.body
+
+if.then199: ; preds = %if.then199, %for.body
+ br label %if.then199
+}
+
+define i32 @same_thing_but_multiplied(%struct.xyz* %header, i8* %p2, i8* %p3, i8* nocapture %p4) nounwind {
+entry:
+ br label %while.body.i
+
+while.body.i: ; preds = %while.body.i, %entry
+ br i1 undef, label %while.body.i, label %bcopy_internal.exit
+
+bcopy_internal.exit: ; preds = %while.body.i
+ %conv135 = ptrtoint %struct.xyz* %header to i32 ; <i32> [#uses=1]
+ %shr136 = shl i32 %conv135, 12 ; <i32> [#uses=1]
+ br label %for.body
+
+for.body: ; preds = %for.body, %bcopy_internal.exit
+ %ppnum.052 = phi i32 [ %inc, %for.body ], [ %shr136, %bcopy_internal.exit ] ; <i32> [#uses=1]
+ %inc = add i32 %ppnum.052, 1 ; <i32> [#uses=2]
+ %cmp = icmp ugt i32 %inc, undef ; <i1> [#uses=1]
+ br i1 %cmp, label %if.then199, label %for.body
+
+if.then199: ; preds = %if.then199, %for.body
+ br label %if.then199
+}
+
+define i32 @same_thing_but_xored(%struct.xyz* %header, i8* %p2, i8* %p3, i8* nocapture %p4) nounwind {
+entry:
+ br label %while.body.i
+
+while.body.i: ; preds = %while.body.i, %entry
+ br i1 undef, label %while.body.i, label %bcopy_internal.exit
+
+bcopy_internal.exit: ; preds = %while.body.i
+ %conv135 = ptrtoint %struct.xyz* %header to i32 ; <i32> [#uses=1]
+ %shr136 = xor i32 %conv135, 12 ; <i32> [#uses=1]
+ br label %for.body
+
+for.body: ; preds = %for.body, %bcopy_internal.exit
+ %ppnum.052 = phi i32 [ %inc, %for.body ], [ %shr136, %bcopy_internal.exit ] ; <i32> [#uses=1]
+ %inc = add i32 %ppnum.052, 1 ; <i32> [#uses=2]
+ %cmp = icmp ugt i32 %inc, undef ; <i1> [#uses=1]
+ br i1 %cmp, label %if.then199, label %for.body
+
+if.then199: ; preds = %if.then199, %for.body
+ br label %if.then199
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/elim-extend.ll b/src/LLVM/test/Transforms/IndVarSimplify/elim-extend.ll
new file mode 100644
index 0000000..43c162f
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/elim-extend.ll
@@ -0,0 +1,153 @@
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+; IV with constant start, preinc and postinc sign extends, with and without NSW.
+; IV rewrite only removes one sext. WidenIVs removes all three.
+define void @postincConstIV(i8* %base, i32 %limit) nounwind {
+entry:
+ br label %loop
+; CHECK: loop:
+; CHECK-NOT: sext
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ %postiv, %loop ], [ 0, %entry ]
+ %ivnsw = phi i32 [ %postivnsw, %loop ], [ 0, %entry ]
+ %preofs = sext i32 %iv to i64
+ %preadr = getelementptr i8* %base, i64 %preofs
+ store i8 0, i8* %preadr
+ %postiv = add i32 %iv, 1
+ %postofs = sext i32 %postiv to i64
+ %postadr = getelementptr i8* %base, i64 %postofs
+ store i8 0, i8* %postadr
+ %postivnsw = add nsw i32 %ivnsw, 1
+ %postofsnsw = sext i32 %postivnsw to i64
+ %postadrnsw = getelementptr i8* %base, i64 %postofsnsw
+ store i8 0, i8* %postadrnsw
+ %cond = icmp sgt i32 %limit, %iv
+ br i1 %cond, label %loop, label %exit
+exit:
+ br label %return
+return:
+ ret void
+}
+
+; IV with nonconstant start, preinc and postinc sign extends,
+; with and without NSW.
+; As with postincConstIV, WidenIVs removes all three sexts.
+define void @postincVarIV(i8* %base, i32 %init, i32 %limit) nounwind {
+entry:
+ %precond = icmp sgt i32 %limit, %init
+ br i1 %precond, label %loop, label %return
+; CHECK: loop:
+; CHECK-NOT: sext
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ %postiv, %loop ], [ %init, %entry ]
+ %ivnsw = phi i32 [ %postivnsw, %loop ], [ %init, %entry ]
+ %preofs = sext i32 %iv to i64
+ %preadr = getelementptr i8* %base, i64 %preofs
+ store i8 0, i8* %preadr
+ %postiv = add i32 %iv, 1
+ %postofs = sext i32 %postiv to i64
+ %postadr = getelementptr i8* %base, i64 %postofs
+ store i8 0, i8* %postadr
+ %postivnsw = add nsw i32 %ivnsw, 1
+ %postofsnsw = sext i32 %postivnsw to i64
+ %postadrnsw = getelementptr i8* %base, i64 %postofsnsw
+ store i8 0, i8* %postadrnsw
+ %cond = icmp sgt i32 %limit, %postiv
+ br i1 %cond, label %loop, label %exit
+exit:
+ br label %return
+return:
+ ret void
+}
+
+; Test sign extend elimination in the inner and outer loop.
+; %outercount is straightforward to widen, besides being in an outer loop.
+; %innercount is currently blocked by lcssa, so is not widened.
+; %inneriv can be widened only after proving it has no signed-overflow
+; based on the loop test.
+define void @nestedIV(i8* %address, i32 %limit) nounwind {
+entry:
+ %limitdec = add i32 %limit, -1
+ br label %outerloop
+
+; CHECK: outerloop:
+;
+; Eliminate %ofs1 after widening outercount.
+; CHECK-NOT: sext
+; CHECK: getelementptr
+;
+; IV rewriting hoists a gep into this block. We don't like that.
+; CHECK-NOT: getelementptr
+outerloop:
+ %outercount = phi i32 [ %outerpostcount, %outermerge ], [ 0, %entry ]
+ %innercount = phi i32 [ %innercount.merge, %outermerge ], [ 0, %entry ]
+
+ %outercountdec = add i32 %outercount, -1
+ %ofs1 = sext i32 %outercountdec to i64
+ %adr1 = getelementptr i8* %address, i64 %ofs1
+ store i8 0, i8* %adr1
+
+ br label %innerpreheader
+
+innerpreheader:
+ %innerprecmp = icmp sgt i32 %limitdec, %innercount
+ br i1 %innerprecmp, label %innerloop, label %outermerge
+
+; CHECK: innerloop:
+;
+; Eliminate %ofs2 after widening inneriv.
+; Eliminate %ofs3 after normalizing sext(innerpostiv)
+; CHECK-NOT: sext
+; CHECK: getelementptr
+;
+; FIXME: We should check that indvars does not increase the number of
+; IVs in this loop. sext elimination plus LFTR currently results in 2 final
+; IVs. Waiting to remove LFTR.
+innerloop:
+ %inneriv = phi i32 [ %innerpostiv, %innerloop ], [ %innercount, %innerpreheader ]
+ %innerpostiv = add i32 %inneriv, 1
+
+ %ofs2 = sext i32 %inneriv to i64
+ %adr2 = getelementptr i8* %address, i64 %ofs2
+ store i8 0, i8* %adr2
+
+ %ofs3 = sext i32 %innerpostiv to i64
+ %adr3 = getelementptr i8* %address, i64 %ofs3
+ store i8 0, i8* %adr3
+
+ %innercmp = icmp sgt i32 %limitdec, %innerpostiv
+ br i1 %innercmp, label %innerloop, label %innerexit
+
+innerexit:
+ %innercount.lcssa = phi i32 [ %innerpostiv, %innerloop ]
+ br label %outermerge
+
+; CHECK: outermerge:
+;
+; Eliminate %ofs4 after widening outercount
+; CHECK-NOT: sext
+; CHECK: getelementptr
+;
+; TODO: Eliminate %ofs5 after removing lcssa
+outermerge:
+ %innercount.merge = phi i32 [ %innercount.lcssa, %innerexit ], [ %innercount, %innerpreheader ]
+
+ %ofs4 = sext i32 %outercount to i64
+ %adr4 = getelementptr i8* %address, i64 %ofs4
+ store i8 0, i8* %adr4
+
+ %ofs5 = sext i32 %innercount.merge to i64
+ %adr5 = getelementptr i8* %address, i64 %ofs5
+ store i8 0, i8* %adr5
+
+ %outerpostcount = add i32 %outercount, 1
+ %tmp47 = icmp slt i32 %outerpostcount, %limit
+ br i1 %tmp47, label %outerloop, label %return
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/eliminate-comparison.ll b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-comparison.ll
new file mode 100644
index 0000000..953bbdf
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-comparison.ll
@@ -0,0 +1,108 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+@X = external global [0 x double]
+
+; Indvars should be able to simplify simple comparisons involving
+; induction variables.
+
+; CHECK: @foo
+; CHECK: %cond = and i1 %tobool.not, true
+
+define void @foo(i64 %n, i32* nocapture %p) nounwind {
+entry:
+ %cmp9 = icmp sgt i64 %n, 0
+ br i1 %cmp9, label %pre, label %return
+
+pre:
+ %t3 = load i32* %p
+ %tobool.not = icmp ne i32 %t3, 0
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %pre ], [ %inc, %for.inc ]
+ %cmp6 = icmp slt i64 %i, %n
+ %cond = and i1 %tobool.not, %cmp6
+ br i1 %cond, label %if.then, label %for.inc
+
+if.then:
+ %arrayidx = getelementptr [0 x double]* @X, i64 0, i64 %i
+ store double 3.200000e+00, double* %arrayidx
+ br label %for.inc
+
+for.inc:
+ %inc = add nsw i64 %i, 1
+ %exitcond = icmp sge i64 %inc, %n
+ br i1 %exitcond, label %return, label %loop
+
+return:
+ ret void
+}
+
+; Don't eliminate an icmp that's contributing to the loop exit test though.
+
+; CHECK: @_ZNK4llvm5APInt3ultERKS0_
+; CHECK: %tmp99 = icmp sgt i32 %i, -1
+
+define i32 @_ZNK4llvm5APInt3ultERKS0_(i32 %tmp2.i1, i64** %tmp65, i64** %tmp73, i64** %tmp82, i64** %tmp90) {
+entry:
+ br label %bb18
+
+bb13:
+ %tmp66 = load i64** %tmp65, align 4
+ %tmp68 = getelementptr inbounds i64* %tmp66, i32 %i
+ %tmp69 = load i64* %tmp68, align 4
+ %tmp74 = load i64** %tmp73, align 4
+ %tmp76 = getelementptr inbounds i64* %tmp74, i32 %i
+ %tmp77 = load i64* %tmp76, align 4
+ %tmp78 = icmp ugt i64 %tmp69, %tmp77
+ br i1 %tmp78, label %bb20.loopexit, label %bb15
+
+bb15:
+ %tmp83 = load i64** %tmp82, align 4
+ %tmp85 = getelementptr inbounds i64* %tmp83, i32 %i
+ %tmp86 = load i64* %tmp85, align 4
+ %tmp91 = load i64** %tmp90, align 4
+ %tmp93 = getelementptr inbounds i64* %tmp91, i32 %i
+ %tmp94 = load i64* %tmp93, align 4
+ %tmp95 = icmp ult i64 %tmp86, %tmp94
+ br i1 %tmp95, label %bb20.loopexit, label %bb17
+
+bb17:
+ %tmp97 = add nsw i32 %i, -1
+ br label %bb18
+
+bb18:
+ %i = phi i32 [ %tmp2.i1, %entry ], [ %tmp97, %bb17 ]
+ %tmp99 = icmp sgt i32 %i, -1
+ br i1 %tmp99, label %bb13, label %bb20.loopexit
+
+bb20.loopexit:
+ %tmp.0.ph = phi i32 [ 0, %bb18 ], [ 1, %bb15 ], [ 0, %bb13 ]
+ ret i32 %tmp.0.ph
+}
+
+; Indvars should eliminate the icmp here.
+
+; CHECK: @func_10
+; CHECK-NOT: icmp
+; CHECK: ret void
+
+define void @func_10() nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i32 [ %i.next, %loop ], [ 0, %entry ]
+ %t0 = icmp slt i32 %i, 0
+ %t1 = zext i1 %t0 to i32
+ %t2 = add i32 %t1, %i
+ %u3 = zext i32 %t2 to i64
+ store i64 %u3, i64* null
+ %i.next = add i32 %i, 1
+ br i1 undef, label %loop, label %return
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/eliminate-max.ll b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-max.ll
new file mode 100644
index 0000000..c25bd0e
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-max.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -S -indvars | grep {= icmp} | count 3
+; PR4914.ll
+
+; Indvars should be able to do range analysis and eliminate icmps.
+; There are two here which cannot be eliminated.
+; There's one that icmp which can be eliminated and which indvars currently
+; cannot eliminate, because it requires analyzing more than just the
+; range of the induction variable.
+
+@0 = private constant [4 x i8] c"%d\0A\00", align 1 ; <[4 x i8]*> [#uses=1]
+
+define i32 @main() nounwind {
+bb:
+ br label %bb1
+
+bb1: ; preds = %bb14, %bb
+ %t = phi i32 [ 0, %bb ], [ %t19, %bb14 ] ; <i32> [#uses=5]
+ %t2 = phi i32 [ 0, %bb ], [ %t18, %bb14 ] ; <i32> [#uses=1]
+ %t3 = icmp slt i32 %t, 0 ; <i1> [#uses=1]
+ br i1 %t3, label %bb7, label %bb4
+
+bb4: ; preds = %bb1
+ %t5 = icmp sgt i32 %t, 255 ; <i1> [#uses=1]
+ %t6 = select i1 %t5, i32 255, i32 %t ; <i32> [#uses=1]
+ br label %bb7
+
+bb7: ; preds = %bb4, %bb1
+ %t8 = phi i32 [ %t6, %bb4 ], [ 0, %bb1 ] ; <i32> [#uses=1]
+ %t9 = sub i32 0, %t ; <i32> [#uses=3]
+ %t10 = icmp slt i32 %t9, 0 ; <i1> [#uses=1]
+ br i1 %t10, label %bb14, label %bb11
+
+bb11: ; preds = %bb7
+ %t12 = icmp sgt i32 %t9, 255 ; <i1> [#uses=1]
+ %t13 = select i1 %t12, i32 255, i32 %t9 ; <i32> [#uses=1]
+ br label %bb14
+
+bb14: ; preds = %bb11, %bb7
+ %t15 = phi i32 [ %t13, %bb11 ], [ 0, %bb7 ] ; <i32> [#uses=1]
+ %t16 = add nsw i32 %t2, 255 ; <i32> [#uses=1]
+ %t17 = add nsw i32 %t16, %t8 ; <i32> [#uses=1]
+ %t18 = add nsw i32 %t17, %t15 ; <i32> [#uses=2]
+ %t19 = add nsw i32 %t, 1 ; <i32> [#uses=2]
+ %t20 = icmp slt i32 %t19, 1000000000 ; <i1> [#uses=1]
+ br i1 %t20, label %bb1, label %bb21
+
+bb21: ; preds = %bb14
+ %t22 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([4 x i8]* @0, i32 0, i32 0), i32 %t18) nounwind
+ ret i32 0
+}
+
+declare i32 @printf(i8* noalias nocapture, ...) nounwind
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/eliminate-rem.ll b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-rem.ll
new file mode 100644
index 0000000..f756389
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/eliminate-rem.ll
@@ -0,0 +1,121 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+; Indvars should be able to eliminate this srem.
+; CHECK: @simple
+; CHECK-NOT: rem
+; CHECK: ret
+
+define void @simple(i64 %arg, double* %arg3) nounwind {
+bb:
+ %t = icmp slt i64 0, %arg ; <i1> [#uses=1]
+ br i1 %t, label %bb4, label %bb12
+
+bb4: ; preds = %bb
+ br label %bb5
+
+bb5: ; preds = %bb4, %bb5
+ %t6 = phi i64 [ %t9, %bb5 ], [ 0, %bb4 ] ; <i64> [#uses=2]
+ %t7 = srem i64 %t6, %arg ; <i64> [#uses=1]
+ %t8 = getelementptr inbounds double* %arg3, i64 %t7 ; <double*> [#uses=1]
+ store double 0.000000e+00, double* %t8
+ %t9 = add nsw i64 %t6, 1 ; <i64> [#uses=2]
+ %t10 = icmp slt i64 %t9, %arg ; <i1> [#uses=1]
+ br i1 %t10, label %bb5, label %bb11
+
+bb11: ; preds = %bb5
+ br label %bb12
+
+bb12: ; preds = %bb11, %bb
+ ret void
+}
+
+; Indvars should be able to eliminate the (i+1)%n.
+; CHECK: @f
+; CHECK-NOT: rem
+; CHECK: rem
+; CHECK-NOT: rem
+; CHECK: ret
+
+define i32 @f(i64* %arg, i64 %arg1, i64 %arg2, i64 %arg3) nounwind {
+bb:
+ %t = icmp sgt i64 %arg1, 0 ; <i1> [#uses=1]
+ br i1 %t, label %bb4, label %bb54
+
+bb4: ; preds = %bb
+ br label %bb5
+
+bb5: ; preds = %bb49, %bb4
+ %t6 = phi i64 [ %t51, %bb49 ], [ 0, %bb4 ] ; <i64> [#uses=4]
+ %t7 = phi i32 [ %t50, %bb49 ], [ 0, %bb4 ] ; <i32> [#uses=2]
+ %t8 = add nsw i64 %t6, %arg1 ; <i64> [#uses=1]
+ %t9 = add nsw i64 %t8, -2 ; <i64> [#uses=1]
+ %t10 = srem i64 %t9, %arg1 ; <i64> [#uses=1]
+ %t11 = add nsw i64 %t10, 1 ; <i64> [#uses=1]
+ %t12 = add nsw i64 %t6, 1 ; <i64> [#uses=1]
+ %t13 = srem i64 %t12, %arg1 ; <i64> [#uses=1]
+ %t14 = icmp sgt i64 %arg1, 0 ; <i1> [#uses=1]
+ br i1 %t14, label %bb15, label %bb49
+
+bb15: ; preds = %bb5
+ br label %bb16
+
+bb16: ; preds = %bb44, %bb15
+ %t17 = phi i64 [ %t46, %bb44 ], [ 0, %bb15 ] ; <i64> [#uses=1]
+ %t18 = phi i32 [ %t45, %bb44 ], [ %t7, %bb15 ] ; <i32> [#uses=2]
+ %t19 = icmp sgt i64 %arg1, 0 ; <i1> [#uses=1]
+ br i1 %t19, label %bb20, label %bb44
+
+bb20: ; preds = %bb16
+ br label %bb21
+
+bb21: ; preds = %bb21, %bb20
+ %t22 = phi i64 [ %t41, %bb21 ], [ 0, %bb20 ] ; <i64> [#uses=4]
+ %t23 = phi i32 [ %t40, %bb21 ], [ %t18, %bb20 ] ; <i32> [#uses=1]
+ %t24 = mul i64 %t6, %arg1 ; <i64> [#uses=1]
+ %t25 = mul i64 %t13, %arg1 ; <i64> [#uses=1]
+ %t26 = add nsw i64 %t24, %t22 ; <i64> [#uses=1]
+ %t27 = mul i64 %t11, %arg1 ; <i64> [#uses=1]
+ %t28 = add nsw i64 %t25, %t22 ; <i64> [#uses=1]
+ %t29 = getelementptr inbounds i64* %arg, i64 %t26 ; <i64*> [#uses=1]
+ %t30 = add nsw i64 %t27, %t22 ; <i64> [#uses=1]
+ %t31 = getelementptr inbounds i64* %arg, i64 %t28 ; <i64*> [#uses=1]
+ %t32 = zext i32 %t23 to i64 ; <i64> [#uses=1]
+ %t33 = load i64* %t29 ; <i64> [#uses=1]
+ %t34 = getelementptr inbounds i64* %arg, i64 %t30 ; <i64*> [#uses=1]
+ %t35 = load i64* %t31 ; <i64> [#uses=1]
+ %t36 = add nsw i64 %t32, %t33 ; <i64> [#uses=1]
+ %t37 = add nsw i64 %t36, %t35 ; <i64> [#uses=1]
+ %t38 = load i64* %t34 ; <i64> [#uses=1]
+ %t39 = add nsw i64 %t37, %t38 ; <i64> [#uses=1]
+ %t40 = trunc i64 %t39 to i32 ; <i32> [#uses=2]
+ %t41 = add nsw i64 %t22, 1 ; <i64> [#uses=2]
+ %t42 = icmp slt i64 %t41, %arg1 ; <i1> [#uses=1]
+ br i1 %t42, label %bb21, label %bb43
+
+bb43: ; preds = %bb21
+ br label %bb44
+
+bb44: ; preds = %bb43, %bb16
+ %t45 = phi i32 [ %t18, %bb16 ], [ %t40, %bb43 ] ; <i32> [#uses=2]
+ %t46 = add nsw i64 %t17, 1 ; <i64> [#uses=2]
+ %t47 = icmp slt i64 %t46, %arg1 ; <i1> [#uses=1]
+ br i1 %t47, label %bb16, label %bb48
+
+bb48: ; preds = %bb44
+ br label %bb49
+
+bb49: ; preds = %bb48, %bb5
+ %t50 = phi i32 [ %t7, %bb5 ], [ %t45, %bb48 ] ; <i32> [#uses=2]
+ %t51 = add nsw i64 %t6, 1 ; <i64> [#uses=2]
+ %t52 = icmp slt i64 %t51, %arg1 ; <i1> [#uses=1]
+ br i1 %t52, label %bb5, label %bb53
+
+bb53: ; preds = %bb49
+ br label %bb54
+
+bb54: ; preds = %bb53, %bb
+ %t55 = phi i32 [ 0, %bb ], [ %t50, %bb53 ] ; <i32> [#uses=1]
+ ret i32 %t55
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/exit_value_tests.ll b/src/LLVM/test/Transforms/IndVarSimplify/exit_value_tests.ll
new file mode 100644
index 0000000..7403b1c
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/exit_value_tests.ll
@@ -0,0 +1,114 @@
+; Test that we can evaluate the exit values of various expression types. Since
+; these loops all have predictable exit values we can replace the use outside
+; of the loop with a closed-form computation, making the loop dead.
+;
+; RUN: opt < %s -indvars -loop-deletion -simplifycfg | \
+; RUN: llvm-dis | not grep br
+
+define i32 @polynomial_constant() {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; <i32> [#uses=3]
+ %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; <i32> [#uses=1]
+ %A2 = add i32 %A1, 1 ; <i32> [#uses=1]
+ %B2 = add i32 %B1, %A1 ; <i32> [#uses=2]
+ %C = icmp eq i32 %A1, 1000 ; <i1> [#uses=1]
+ br i1 %C, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ ret i32 %B2
+}
+
+define i32 @NSquare(i32 %N) {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; <i32> [#uses=4]
+ %X2 = add i32 %X, 1 ; <i32> [#uses=1]
+ %c = icmp eq i32 %X, %N ; <i1> [#uses=1]
+ br i1 %c, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ %Y = mul i32 %X, %X ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
+define i32 @NSquareOver2(i32 %N) {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %X = phi i32 [ 0, %0 ], [ %X2, %Loop ] ; <i32> [#uses=3]
+ %Y = phi i32 [ 15, %0 ], [ %Y2, %Loop ] ; <i32> [#uses=1]
+ %Y2 = add i32 %Y, %X ; <i32> [#uses=2]
+ %X2 = add i32 %X, 1 ; <i32> [#uses=1]
+ %c = icmp eq i32 %X, %N ; <i1> [#uses=1]
+ br i1 %c, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ ret i32 %Y2
+}
+
+define i32 @strength_reduced() {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; <i32> [#uses=3]
+ %B1 = phi i32 [ 0, %0 ], [ %B2, %Loop ] ; <i32> [#uses=1]
+ %A2 = add i32 %A1, 1 ; <i32> [#uses=1]
+ %B2 = add i32 %B1, %A1 ; <i32> [#uses=2]
+ %C = icmp eq i32 %A1, 1000 ; <i1> [#uses=1]
+ br i1 %C, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ ret i32 %B2
+}
+
+define i32 @chrec_equals() {
+entry:
+ br label %no_exit
+
+no_exit: ; preds = %no_exit, %entry
+ %i0 = phi i32 [ 0, %entry ], [ %i1, %no_exit ] ; <i32> [#uses=3]
+ %ISq = mul i32 %i0, %i0 ; <i32> [#uses=1]
+ %i1 = add i32 %i0, 1 ; <i32> [#uses=2]
+ %tmp.1 = icmp ne i32 %ISq, 10000 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %no_exit, label %loopexit
+
+loopexit: ; preds = %no_exit
+ ret i32 %i1
+}
+
+define i16 @cast_chrec_test() {
+; <label>:0
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %A1 = phi i32 [ 0, %0 ], [ %A2, %Loop ] ; <i32> [#uses=2]
+ %B1 = trunc i32 %A1 to i16 ; <i16> [#uses=2]
+ %A2 = add i32 %A1, 1 ; <i32> [#uses=1]
+ %C = icmp eq i16 %B1, 1000 ; <i1> [#uses=1]
+ br i1 %C, label %Out, label %Loop
+
+Out: ; preds = %Loop
+ ret i16 %B1
+}
+
+define i32 @linear_div_fold() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 4, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 8 ; <i32> [#uses=1]
+ %RV = udiv i32 %i, 2 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 68 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %RV
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/floating-point-iv.ll b/src/LLVM/test/Transforms/IndVarSimplify/floating-point-iv.ll
new file mode 100644
index 0000000..266eebd
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/floating-point-iv.ll
@@ -0,0 +1,92 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+define void @test1() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %x.0.reg2mem.0 = phi double [ 0.000000e+00, %entry ], [ %1, %bb ] ; <double> [#uses=2]
+ %0 = tail call i32 @foo(double %x.0.reg2mem.0) nounwind ; <i32> [#uses=0]
+ %1 = fadd double %x.0.reg2mem.0, 1.000000e+00 ; <double> [#uses=2]
+ %2 = fcmp olt double %1, 1.000000e+04 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %return
+
+return: ; preds = %bb
+ ret void
+; CHECK: @test1
+; CHECK: icmp
+}
+
+declare i32 @foo(double)
+
+define void @test2() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %x.0.reg2mem.0 = phi double [ -10.000000e+00, %entry ], [ %1, %bb ] ; <double> [#uses=2]
+ %0 = tail call i32 @foo(double %x.0.reg2mem.0) nounwind ; <i32> [#uses=0]
+ %1 = fadd double %x.0.reg2mem.0, 2.000000e+00 ; <double> [#uses=2]
+ %2 = fcmp olt double %1, -1.000000e+00 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %return
+
+return: ; preds = %bb
+ ret void
+; CHECK: @test2
+; CHECK: icmp
+}
+
+
+define void @test3() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %x.0.reg2mem.0 = phi double [ 0.000000e+00, %entry ], [ %1, %bb ]
+ %0 = tail call i32 @foo(double %x.0.reg2mem.0) nounwind
+ %1 = fadd double %x.0.reg2mem.0, 1.000000e+00
+ %2 = fcmp olt double %1, -1.000000e+00
+ br i1 %2, label %bb, label %return
+
+return:
+ ret void
+; CHECK: @test3
+; CHECK: fcmp
+}
+
+define void @test4() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %x.0.reg2mem.0 = phi double [ 40.000000e+00, %entry ], [ %1, %bb ] ; <double> [#uses=2]
+ %0 = tail call i32 @foo(double %x.0.reg2mem.0) nounwind ; <i32> [#uses=0]
+ %1 = fadd double %x.0.reg2mem.0, -1.000000e+00 ; <double> [#uses=2]
+ %2 = fcmp olt double %1, 1.000000e+00 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %return
+
+return:
+ ret void
+; CHECK: @test4
+; CHECK-NOT: cmp
+; CHECK: br i1 false
+}
+
+; PR6761
+define void @test5() nounwind {
+; <label>:0
+ br label %1
+
+; <label>:1 ; preds = %1, %0
+ %2 = phi double [ 9.000000e+00, %0 ], [ %4, %1 ] ; <double> [#uses=1]
+ %3 = tail call i32 @foo(double 0.0) ; <i32> [#uses=0]
+ %4 = fadd double %2, -1.000000e+00 ; <double> [#uses=2]
+ %5 = fcmp ult double %4, 0.000000e+00 ; <i1> [#uses=1]
+ br i1 %5, label %exit, label %1
+
+exit:
+ ret void
+
+; CHECK: @test5
+; CHECK: icmp slt i32 {{.*}}, 0
+; CHECK-NEXT: br i1
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/gep-with-mul-base.ll b/src/LLVM/test/Transforms/IndVarSimplify/gep-with-mul-base.ll
new file mode 100644
index 0000000..7e1e2a3
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/gep-with-mul-base.ll
@@ -0,0 +1,68 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK: define void @foo
+; CHECK: mul
+; CHECK: mul
+; CHECK: mul
+; CHECK: add
+; CHECK: sub
+; CHECK: define void @bar
+; CHECK: mul
+; CHECK: mul
+; CHECK: mul
+; CHECK: add
+; CHECK: sub
+
+define void @foo(i64 %n, i64 %m, i64 %o, double* nocapture %p) nounwind {
+entry:
+ %tmp = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
+ br i1 %tmp, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ %tmp1 = mul i64 %n, 37 ; <i64> [#uses=1]
+ %tmp2 = mul i64 %tmp1, %m ; <i64> [#uses=1]
+ %tmp3 = mul i64 %tmp2, %o ; <i64> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %i.01 = phi i64 [ %tmp3, %bb.nph ], [ %tmp13, %bb ] ; <i64> [#uses=3]
+ %tmp9 = getelementptr double* %p, i64 %i.01 ; <double*> [#uses=1]
+ %tmp10 = load double* %tmp9, align 8 ; <double> [#uses=1]
+ %tmp11 = fdiv double %tmp10, 2.100000e+00 ; <double> [#uses=1]
+ store double %tmp11, double* %tmp9, align 8
+ %tmp13 = add i64 %i.01, 1 ; <i64> [#uses=2]
+ %tmp14 = icmp slt i64 %tmp13, %n ; <i1> [#uses=1]
+ br i1 %tmp14, label %bb, label %return.loopexit
+
+return.loopexit: ; preds = %bb
+ br label %return
+
+return: ; preds = %return.loopexit, %entry
+ ret void
+}
+define void @bar(i64 %n, i64 %m, i64 %o, i64 %q, double* nocapture %p) nounwind {
+entry:
+ %tmp = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
+ br i1 %tmp, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ %tmp1 = mul i64 %n, %q ; <i64> [#uses=1]
+ %tmp2 = mul i64 %tmp1, %m ; <i64> [#uses=1]
+ %tmp3 = mul i64 %tmp2, %o ; <i64> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %i.01 = phi i64 [ %tmp3, %bb.nph ], [ %tmp13, %bb ] ; <i64> [#uses=3]
+ %tmp9 = getelementptr double* %p, i64 %i.01 ; <double*> [#uses=1]
+ %tmp10 = load double* %tmp9, align 8 ; <double> [#uses=1]
+ %tmp11 = fdiv double %tmp10, 2.100000e+00 ; <double> [#uses=1]
+ store double %tmp11, double* %tmp9, align 8
+ %tmp13 = add i64 %i.01, 1 ; <i64> [#uses=2]
+ %tmp14 = icmp slt i64 %tmp13, %n ; <i1> [#uses=1]
+ br i1 %tmp14, label %bb, label %return.loopexit
+
+return.loopexit: ; preds = %bb
+ br label %return
+
+return: ; preds = %return.loopexit, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/indirectbr.ll b/src/LLVM/test/Transforms/IndVarSimplify/indirectbr.ll
new file mode 100644
index 0000000..a208ded
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/indirectbr.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -indvars -S -disable-output
+
+; PR5758
+define zeroext i1 @foo() nounwind {
+entry:
+ indirectbr i8* undef, [label %"202", label %"133"]
+
+"132": ; preds = %"133"
+ %0 = add i32 %1, 1 ; <i32> [#uses=1]
+ br label %"133"
+
+"133": ; preds = %"132", %entry
+ %1 = phi i32 [ %0, %"132" ], [ 0, %entry ] ; <i32> [#uses=2]
+ %2 = icmp eq i32 %1, 4 ; <i1> [#uses=1]
+ br i1 %2, label %"134", label %"132"
+
+"134": ; preds = %"133"
+ ret i1 true
+
+"202": ; preds = %entry
+ ret i1 false
+}
+
+; PR7333
+define void @__atomvec_module__put_vrml_bonds() nounwind {
+bb7.preheader: ; preds = %entry
+ indirectbr i8* undef, [label %bb14, label %bb16]
+
+bb14: ; preds = %bb14, %bb7.preheader
+ br label %bb16
+
+bb16: ; preds = %bb16, %bb14, %bb7.preheader
+ %S.31.0 = phi i64 [ %3, %bb16 ], [ 1, %bb7.preheader ], [ 1, %bb14 ] ; <i64> [#uses=2]
+ %0 = add nsw i64 %S.31.0, -1 ; <i64> [#uses=1]
+ %1 = getelementptr inbounds [3 x double]* undef, i64 0, i64 %0 ; <double*> [#uses=1]
+ %2 = load double* %1, align 8 ; <double> [#uses=0]
+ %3 = add nsw i64 %S.31.0, 1 ; <i64> [#uses=1]
+ br label %bb16
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/interesting-invoke-use.ll b/src/LLVM/test/Transforms/IndVarSimplify/interesting-invoke-use.ll
new file mode 100644
index 0000000..69bea6e
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/interesting-invoke-use.ll
@@ -0,0 +1,61 @@
+; RUN: opt < %s -indvars
+
+; An invoke has a result value which is used in an "Interesting"
+; expression inside the loop. IndVars should be able to rewrite
+; the expression in the correct place.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %struct.string___XUB = type { i32, i32 }
+ %struct.string___XUP = type { [0 x i8]*, %struct.string___XUB* }
+@.str7 = external constant [24 x i8] ; <[24 x i8]*> [#uses=1]
+@C.17.316 = external constant %struct.string___XUB ; <%struct.string___XUB*> [#uses=1]
+
+define void @_ada_c35503g() {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ br i1 false, label %bb65.loopexit, label %bb
+
+bb65.loopexit: ; preds = %bb
+ br label %bb123
+
+bb123: ; preds = %bb178, %bb65.loopexit
+ %i.0 = phi i32 [ %3, %bb178 ], [ 0, %bb65.loopexit ] ; <i32> [#uses=3]
+ %0 = invoke i32 @report__ident_int(i32 1)
+ to label %invcont127 unwind label %lpad266 ; <i32> [#uses=1]
+
+invcont127: ; preds = %bb123
+ %1 = sub i32 %i.0, %0 ; <i32> [#uses=1]
+ %2 = icmp eq i32 0, %1 ; <i1> [#uses=1]
+ br i1 %2, label %bb178, label %bb128
+
+bb128: ; preds = %invcont127
+ invoke void @system__img_int__image_integer(%struct.string___XUP* noalias sret null, i32 %i.0)
+ to label %invcont129 unwind label %lpad266
+
+invcont129: ; preds = %bb128
+ invoke void @system__string_ops__str_concat(%struct.string___XUP* noalias sret null, [0 x i8]* bitcast ([24 x i8]* @.str7 to [0 x i8]*), %struct.string___XUB* @C.17.316, [0 x i8]* null, %struct.string___XUB* null)
+ to label %invcont138 unwind label %lpad266
+
+invcont138: ; preds = %invcont129
+ unreachable
+
+bb178: ; preds = %invcont127
+ %3 = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb123
+
+lpad266: ; preds = %invcont129, %bb128, %bb123
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @system__img_int__image_integer(%struct.string___XUP* noalias sret, i32)
+
+declare void @system__string_ops__str_concat(%struct.string___XUP* noalias sret, [0 x i8]*, %struct.string___XUB*, [0 x i8]*, %struct.string___XUB*)
+
+declare i32 @report__ident_int(i32)
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/iterationCount_zext_or_trunc.ll b/src/LLVM/test/Transforms/IndVarSimplify/iterationCount_zext_or_trunc.ll
new file mode 100644
index 0000000..02145d1
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/iterationCount_zext_or_trunc.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -indvars -disable-output
+
+; ModuleID = 'testcase.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+
+define i32 @testcase(i5 zeroext %k) {
+entry:
+ br label %bb2
+
+bb: ; preds = %bb2
+ %tmp1 = add i32 %tmp2, %result ; <i32> [#uses=1]
+ %indvar_next1 = add i5 %k_0, 1 ; <i5> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb, %entry
+ %k_0 = phi i5 [ 0, %entry ], [ %indvar_next1, %bb ] ; <i5> [#uses=2]
+ %result = phi i32 [ 0, %entry ], [ %tmp1, %bb ] ; <i32> [#uses=2]
+ %tmp2 = zext i5 %k_0 to i32 ; <i32> [#uses=1]
+ %exitcond = icmp eq i32 %tmp2, 16 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb3, label %bb
+
+bb3: ; preds = %bb2
+ ret i32 %result
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/iv-fold.ll b/src/LLVM/test/Transforms/IndVarSimplify/iv-fold.ll
new file mode 100644
index 0000000..2e19118
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/iv-fold.ll
@@ -0,0 +1,56 @@
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+
+; Indvars should be able to fold IV increments into shr when low bits are zero.
+;
+; CHECK: @foldIncShr
+; CHECK: shr.1 = lshr i32 %0, 5
+define i32 @foldIncShr(i32* %bitmap, i32 %bit_addr, i32 %nbits) nounwind {
+entry:
+ br label %while.body
+
+while.body:
+ %0 = phi i32 [ 0, %entry ], [ %inc.2, %while.body ]
+ %shr = lshr i32 %0, 5
+ %arrayidx = getelementptr inbounds i32* %bitmap, i32 %shr
+ %tmp6 = load i32* %arrayidx, align 4
+ %inc.1 = add i32 %0, 1
+ %shr.1 = lshr i32 %inc.1, 5
+ %arrayidx.1 = getelementptr inbounds i32* %bitmap, i32 %shr.1
+ %tmp6.1 = load i32* %arrayidx.1, align 4
+ %inc.2 = add i32 %inc.1, 1
+ %exitcond.3 = icmp eq i32 %inc.2, 128
+ br i1 %exitcond.3, label %while.end, label %while.body
+
+while.end:
+ %r = add i32 %tmp6, %tmp6.1
+ ret i32 %r
+}
+
+; Invdars should not fold an increment into shr unless 2^shiftBits is
+; a multiple of the recurrence step.
+;
+; CHECK: @noFoldIncShr
+; CHECK: shr.1 = lshr i32 %inc.1, 5
+define i32 @noFoldIncShr(i32* %bitmap, i32 %bit_addr, i32 %nbits) nounwind {
+entry:
+ br label %while.body
+
+while.body:
+ %0 = phi i32 [ 0, %entry ], [ %inc.3, %while.body ]
+ %shr = lshr i32 %0, 5
+ %arrayidx = getelementptr inbounds i32* %bitmap, i32 %shr
+ %tmp6 = load i32* %arrayidx, align 4
+ %inc.1 = add i32 %0, 1
+ %shr.1 = lshr i32 %inc.1, 5
+ %arrayidx.1 = getelementptr inbounds i32* %bitmap, i32 %shr.1
+ %tmp6.1 = load i32* %arrayidx.1, align 4
+ %inc.3 = add i32 %inc.1, 2
+ %exitcond.3 = icmp eq i32 %inc.3, 96
+ br i1 %exitcond.3, label %while.end, label %while.body
+
+while.end:
+ %r = add i32 %tmp6, %tmp6.1
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/iv-sext.ll b/src/LLVM/test/Transforms/IndVarSimplify/iv-sext.ll
new file mode 100644
index 0000000..04df0f9
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/iv-sext.ll
@@ -0,0 +1,149 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+
+; Indvars should be able to promote the hiPart induction variable in the
+; inner loop to i64.
+; TODO: it should promote hiPart to i64 in the outer loop too.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+
+define void @t(float* %pTmp1, float* %peakWeight, float* %nrgReducePeakrate, i32 %bandEdgeIndex, float %tmp1) nounwind {
+entry:
+ %tmp = load float* %peakWeight, align 4 ; <float> [#uses=1]
+ %tmp2 = icmp sgt i32 %bandEdgeIndex, 0 ; <i1> [#uses=1]
+ br i1 %tmp2, label %bb.nph22, label %return
+
+bb.nph22: ; preds = %entry
+ %tmp3 = add i32 %bandEdgeIndex, -1 ; <i32> [#uses=2]
+ br label %bb
+
+; CHECK: bb:
+; CHECK: phi i64
+; CHECK-NOT: phi i64
+bb: ; preds = %bb8, %bb.nph22
+ %distERBhi.121 = phi float [ %distERBhi.2.lcssa, %bb8 ], [ 0.000000e+00, %bb.nph22 ] ; <float> [#uses=2]
+ %distERBlo.120 = phi float [ %distERBlo.0.lcssa, %bb8 ], [ 0.000000e+00, %bb.nph22 ] ; <float> [#uses=2]
+ %hiPart.119 = phi i32 [ %hiPart.0.lcssa, %bb8 ], [ 0, %bb.nph22 ] ; <i32> [#uses=3]
+ %loPart.118 = phi i32 [ %loPart.0.lcssa, %bb8 ], [ 0, %bb.nph22 ] ; <i32> [#uses=2]
+ %peakCount.117 = phi float [ %peakCount.2.lcssa, %bb8 ], [ %tmp, %bb.nph22 ] ; <float> [#uses=2]
+ %part.016 = phi i32 [ %tmp46, %bb8 ], [ 0, %bb.nph22 ] ; <i32> [#uses=5]
+ %tmp4 = icmp sgt i32 %part.016, 0 ; <i1> [#uses=1]
+ br i1 %tmp4, label %bb1, label %bb3.preheader
+
+; CHECK: bb1:
+bb1: ; preds = %bb
+ %tmp5 = add i32 %part.016, -1 ; <i32> [#uses=1]
+ %tmp6 = sext i32 %tmp5 to i64 ; <i64> [#uses=1]
+ %tmp7 = getelementptr float* %pTmp1, i64 %tmp6 ; <float*> [#uses=1]
+ %tmp8 = load float* %tmp7, align 4 ; <float> [#uses=1]
+ %tmp9 = fadd float %tmp8, %distERBlo.120 ; <float> [#uses=1]
+ %tmp10 = add i32 %part.016, -1 ; <i32> [#uses=1]
+ %tmp11 = sext i32 %tmp10 to i64 ; <i64> [#uses=1]
+ %tmp12 = getelementptr float* %pTmp1, i64 %tmp11 ; <float*> [#uses=1]
+ %tmp13 = load float* %tmp12, align 4 ; <float> [#uses=1]
+ %tmp14 = fsub float %distERBhi.121, %tmp13 ; <float> [#uses=1]
+ br label %bb3.preheader
+
+bb3.preheader: ; preds = %bb1, %bb
+ %distERBlo.0.ph = phi float [ %distERBlo.120, %bb ], [ %tmp9, %bb1 ] ; <float> [#uses=3]
+ %distERBhi.0.ph = phi float [ %distERBhi.121, %bb ], [ %tmp14, %bb1 ] ; <float> [#uses=3]
+ %tmp15 = fcmp ogt float %distERBlo.0.ph, 2.500000e+00 ; <i1> [#uses=1]
+ br i1 %tmp15, label %bb.nph, label %bb5.preheader
+
+bb.nph: ; preds = %bb3.preheader
+ br label %bb2
+
+bb2: ; preds = %bb3, %bb.nph
+ %distERBlo.03 = phi float [ %tmp19, %bb3 ], [ %distERBlo.0.ph, %bb.nph ] ; <float> [#uses=1]
+ %loPart.02 = phi i32 [ %tmp24, %bb3 ], [ %loPart.118, %bb.nph ] ; <i32> [#uses=3]
+ %peakCount.01 = phi float [ %tmp23, %bb3 ], [ %peakCount.117, %bb.nph ] ; <float> [#uses=1]
+ %tmp16 = sext i32 %loPart.02 to i64 ; <i64> [#uses=1]
+ %tmp17 = getelementptr float* %pTmp1, i64 %tmp16 ; <float*> [#uses=1]
+ %tmp18 = load float* %tmp17, align 4 ; <float> [#uses=1]
+ %tmp19 = fsub float %distERBlo.03, %tmp18 ; <float> [#uses=3]
+ %tmp20 = sext i32 %loPart.02 to i64 ; <i64> [#uses=1]
+ %tmp21 = getelementptr float* %peakWeight, i64 %tmp20 ; <float*> [#uses=1]
+ %tmp22 = load float* %tmp21, align 4 ; <float> [#uses=1]
+ %tmp23 = fsub float %peakCount.01, %tmp22 ; <float> [#uses=2]
+ %tmp24 = add i32 %loPart.02, 1 ; <i32> [#uses=2]
+ br label %bb3
+
+bb3: ; preds = %bb2
+ %tmp25 = fcmp ogt float %tmp19, 2.500000e+00 ; <i1> [#uses=1]
+ br i1 %tmp25, label %bb2, label %bb3.bb5.preheader_crit_edge
+
+bb3.bb5.preheader_crit_edge: ; preds = %bb3
+ %tmp24.lcssa = phi i32 [ %tmp24, %bb3 ] ; <i32> [#uses=1]
+ %tmp23.lcssa = phi float [ %tmp23, %bb3 ] ; <float> [#uses=1]
+ %tmp19.lcssa = phi float [ %tmp19, %bb3 ] ; <float> [#uses=1]
+ br label %bb5.preheader
+
+bb5.preheader: ; preds = %bb3.bb5.preheader_crit_edge, %bb3.preheader
+ %distERBlo.0.lcssa = phi float [ %tmp19.lcssa, %bb3.bb5.preheader_crit_edge ], [ %distERBlo.0.ph, %bb3.preheader ] ; <float> [#uses=2]
+ %loPart.0.lcssa = phi i32 [ %tmp24.lcssa, %bb3.bb5.preheader_crit_edge ], [ %loPart.118, %bb3.preheader ] ; <i32> [#uses=1]
+ %peakCount.0.lcssa = phi float [ %tmp23.lcssa, %bb3.bb5.preheader_crit_edge ], [ %peakCount.117, %bb3.preheader ] ; <float> [#uses=2]
+ %.not10 = fcmp olt float %distERBhi.0.ph, 2.500000e+00 ; <i1> [#uses=1]
+ %tmp26 = icmp sgt i32 %tmp3, %hiPart.119 ; <i1> [#uses=1]
+ %or.cond11 = and i1 %tmp26, %.not10 ; <i1> [#uses=1]
+ br i1 %or.cond11, label %bb.nph12, label %bb7
+
+bb.nph12: ; preds = %bb5.preheader
+ br label %bb4
+; CHECK: bb4:
+; CHECK: phi i64
+; CHECK-NOT: phi i64
+; CHECK-NOT: sext
+bb4: ; preds = %bb5, %bb.nph12
+ %distERBhi.29 = phi float [ %tmp30, %bb5 ], [ %distERBhi.0.ph, %bb.nph12 ] ; <float> [#uses=1]
+ %hiPart.08 = phi i32 [ %tmp31, %bb5 ], [ %hiPart.119, %bb.nph12 ] ; <i32> [#uses=2]
+ %peakCount.27 = phi float [ %tmp35, %bb5 ], [ %peakCount.0.lcssa, %bb.nph12 ] ; <float> [#uses=1]
+ %tmp27 = sext i32 %hiPart.08 to i64 ; <i64> [#uses=1]
+ %tmp28 = getelementptr float* %pTmp1, i64 %tmp27 ; <float*> [#uses=1]
+ %tmp29 = load float* %tmp28, align 4 ; <float> [#uses=1]
+ %tmp30 = fadd float %tmp29, %distERBhi.29 ; <float> [#uses=3]
+ %tmp31 = add i32 %hiPart.08, 1 ; <i32> [#uses=4]
+ %tmp32 = sext i32 %tmp31 to i64 ; <i64> [#uses=1]
+ %tmp33 = getelementptr float* %peakWeight, i64 %tmp32 ; <float*> [#uses=1]
+ %tmp34 = load float* %tmp33, align 4 ; <float> [#uses=1]
+ %tmp35 = fadd float %tmp34, %peakCount.27 ; <float> [#uses=2]
+ br label %bb5
+
+; CHECK: bb5:
+bb5: ; preds = %bb4
+ %.not = fcmp olt float %tmp30, 2.500000e+00 ; <i1> [#uses=1]
+ %tmp36 = icmp sgt i32 %tmp3, %tmp31 ; <i1> [#uses=1]
+ %or.cond = and i1 %tmp36, %.not ; <i1> [#uses=1]
+ br i1 %or.cond, label %bb4, label %bb5.bb7_crit_edge
+
+bb5.bb7_crit_edge: ; preds = %bb5
+ %tmp35.lcssa = phi float [ %tmp35, %bb5 ] ; <float> [#uses=1]
+ %tmp31.lcssa = phi i32 [ %tmp31, %bb5 ] ; <i32> [#uses=1]
+ %tmp30.lcssa = phi float [ %tmp30, %bb5 ] ; <float> [#uses=1]
+ br label %bb7
+
+bb7: ; preds = %bb5.bb7_crit_edge, %bb5.preheader
+ %distERBhi.2.lcssa = phi float [ %tmp30.lcssa, %bb5.bb7_crit_edge ], [ %distERBhi.0.ph, %bb5.preheader ] ; <float> [#uses=2]
+ %hiPart.0.lcssa = phi i32 [ %tmp31.lcssa, %bb5.bb7_crit_edge ], [ %hiPart.119, %bb5.preheader ] ; <i32> [#uses=1]
+ %peakCount.2.lcssa = phi float [ %tmp35.lcssa, %bb5.bb7_crit_edge ], [ %peakCount.0.lcssa, %bb5.preheader ] ; <float> [#uses=2]
+ %tmp37 = fadd float %distERBlo.0.lcssa, %distERBhi.2.lcssa ; <float> [#uses=1]
+ %tmp38 = fdiv float %peakCount.2.lcssa, %tmp37 ; <float> [#uses=1]
+ %tmp39 = fmul float %tmp38, %tmp1 ; <float> [#uses=2]
+ %tmp40 = fmul float %tmp39, %tmp39 ; <float> [#uses=2]
+ %tmp41 = fmul float %tmp40, %tmp40 ; <float> [#uses=1]
+ %tmp42 = fadd float %tmp41, 1.000000e+00 ; <float> [#uses=1]
+ %tmp43 = fdiv float 1.000000e+00, %tmp42 ; <float> [#uses=1]
+ %tmp44 = sext i32 %part.016 to i64 ; <i64> [#uses=1]
+ %tmp45 = getelementptr float* %nrgReducePeakrate, i64 %tmp44 ; <float*> [#uses=1]
+ store float %tmp43, float* %tmp45, align 4
+ %tmp46 = add i32 %part.016, 1 ; <i32> [#uses=2]
+ br label %bb8
+
+bb8: ; preds = %bb7
+ %tmp47 = icmp slt i32 %tmp46, %bandEdgeIndex ; <i1> [#uses=1]
+ br i1 %tmp47, label %bb, label %bb8.return_crit_edge
+
+bb8.return_crit_edge: ; preds = %bb8
+ br label %return
+
+return: ; preds = %bb8.return_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/iv-zext.ll b/src/LLVM/test/Transforms/IndVarSimplify/iv-zext.ll
new file mode 100644
index 0000000..646e6c0
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/iv-zext.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+; CHECK-NOT: and
+; CHECK-NOT: zext
+
+target datalayout = "-p:64:64:64-n32:64"
+
+define void @foo(double* %d, i64 %n) nounwind {
+entry:
+ br label %loop
+
+loop:
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %loop ]
+ %indvar.i8 = and i64 %indvar, 255
+ %t0 = getelementptr double* %d, i64 %indvar.i8
+ %t1 = load double* %t0
+ %t2 = fmul double %t1, 0.1
+ store double %t2, double* %t0
+ %indvar.i24 = and i64 %indvar, 16777215
+ %t3 = getelementptr double* %d, i64 %indvar.i24
+ %t4 = load double* %t3
+ %t5 = fmul double %t4, 2.3
+ store double %t5, double* %t3
+ %t6 = getelementptr double* %d, i64 %indvar
+ %t7 = load double* %t6
+ %t8 = fmul double %t7, 4.5
+ store double %t8, double* %t6
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 10
+ br i1 %exitcond, label %return, label %loop
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/lftr-other-uses.ll b/src/LLVM/test/Transforms/IndVarSimplify/lftr-other-uses.ll
new file mode 100644
index 0000000..09ec237
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/lftr-other-uses.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -indvars -disable-output
+
+; Don't RAUW the loop's original comparison instruction if it has
+; other uses which aren't dominated by the new comparison instruction.
+
+ %struct.DecRefPicMarking_s = type { i32, i32, i32, i32, i32, %struct.DecRefPicMarking_s* }
+ %struct.datapartition = type { %typedef.Bitstream*, %typedef.DecodingEnvironment, i32 (%struct.syntaxelement*, %struct.img_par*, %struct.inp_par*, %struct.datapartition*)* }
+ %struct.img_par = type { i32, i32, i32, i32, i32*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x [16 x i16]], [6 x [32 x i32]], [16 x [16 x i32]], [4 x [12 x [4 x [4 x i32]]]], [16 x i32], i32**, i32*, i32***, i32**, i32, i32, i32, i32, %typedef.Slice*, %struct.macroblock*, i32, i32, i32, i32, i32, i32, i32**, %struct.DecRefPicMarking_s*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32***, i32***, i32****, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.timeb, %struct.timeb, i32, i32, i32, i32, i32, i32, i32, i32 }
+ %struct.inp_par = type { [100 x i8], [100 x i8], [100 x i8], i32, i32, i32, i32, i32, i32, i32 }
+ %struct.macroblock = type { i32, i32, i32, %struct.macroblock*, %struct.macroblock*, i32, [2 x [4 x [4 x [2 x i32]]]], i32, i64, i64, i32, i32, [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
+ %struct.syntaxelement = type { i32, i32, i32, i32, i32, i32, i32, i32, void (i32, i32, i32*, i32*)*, void (%struct.syntaxelement*, %struct.inp_par*, %struct.img_par*, %typedef.DecodingEnvironment*)* }
+ %struct.timeb = type { i32, i16, i16, i16 }
+ %typedef.BiContextType = type { i16, i8 }
+ %typedef.Bitstream = type { i32, i32, i32, i32, i8*, i32 }
+ %typedef.DecodingEnvironment = type { i32, i32, i32, i32, i32, i8*, i32* }
+ %typedef.MotionInfoContexts = type { [4 x [11 x %typedef.BiContextType]], [2 x [9 x %typedef.BiContextType]], [2 x [10 x %typedef.BiContextType]], [2 x [6 x %typedef.BiContextType]], [4 x %typedef.BiContextType], [4 x %typedef.BiContextType], [3 x %typedef.BiContextType] }
+ %typedef.Slice = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.datapartition*, %typedef.MotionInfoContexts*, %typedef.TextureInfoContexts*, i32, i32*, i32*, i32*, i32, i32*, i32*, i32*, i32 (%struct.img_par*, %struct.inp_par*)*, i32, i32, i32, i32 }
+ %typedef.TextureInfoContexts = type { [2 x %typedef.BiContextType], [4 x %typedef.BiContextType], [3 x [4 x %typedef.BiContextType]], [10 x [4 x %typedef.BiContextType]], [10 x [15 x %typedef.BiContextType]], [10 x [15 x %typedef.BiContextType]], [10 x [5 x %typedef.BiContextType]], [10 x [5 x %typedef.BiContextType]], [10 x [15 x %typedef.BiContextType]], [10 x [15 x %typedef.BiContextType]] }
+
+define void @readCBP_CABAC(%struct.syntaxelement* %se, %struct.inp_par* %inp, %struct.img_par* %img.1, %typedef.DecodingEnvironment* %dep_dp) {
+entry:
+ br label %loopentry.0
+
+loopentry.0: ; preds = %loopentry.1, %entry
+ %mb_y.0 = phi i32 [ 0, %entry ], [ %tmp.152, %loopentry.1 ] ; <i32> [#uses=2]
+ %tmp.14 = icmp sle i32 %mb_y.0, 3 ; <i1> [#uses=2]
+ %tmp.15 = zext i1 %tmp.14 to i32 ; <i32> [#uses=0]
+ br i1 %tmp.14, label %loopentry.1, label %loopexit.0
+
+loopentry.1: ; preds = %loopentry.0
+ %tmp.152 = add i32 %mb_y.0, 2 ; <i32> [#uses=1]
+ br label %loopentry.0
+
+loopexit.0: ; preds = %loopentry.0
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/lftr-promote.ll b/src/LLVM/test/Transforms/IndVarSimplify/lftr-promote.ll
new file mode 100644
index 0000000..c4ecc84
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/lftr-promote.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -indvars -S | grep add | count 1
+
+; Indvars should be able to compute the exit value of this loop
+; without any additional arithmetic. The only add needed should
+; be the canonical IV increment.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+define void @foo(double* %p, i32 %n) nounwind {
+entry:
+ %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ br label %bb2
+
+bb2: ; preds = %bb3, %bb.nph
+ %i.01 = phi i32 [ %7, %bb3 ], [ 0, %bb.nph ] ; <i32> [#uses=3]
+ %1 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
+ %2 = getelementptr double* %p, i64 %1 ; <double*> [#uses=1]
+ %3 = load double* %2, align 8 ; <double> [#uses=1]
+ %4 = fmul double %3, 1.100000e+00 ; <double> [#uses=1]
+ %5 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
+ %6 = getelementptr double* %p, i64 %5 ; <double*> [#uses=1]
+ store double %4, double* %6, align 8
+ %7 = add i32 %i.01, 1 ; <i32> [#uses=2]
+ br label %bb3
+
+bb3: ; preds = %bb2
+ %8 = icmp slt i32 %7, %n ; <i1> [#uses=1]
+ br i1 %8, label %bb2, label %bb3.return_crit_edge
+
+bb3.return_crit_edge: ; preds = %bb3
+ br label %return
+
+return: ; preds = %bb3.return_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/lftr-reuse.ll b/src/LLVM/test/Transforms/IndVarSimplify/lftr-reuse.ll
new file mode 100644
index 0000000..490eee9
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/lftr-reuse.ll
@@ -0,0 +1,230 @@
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+;
+; Make sure that indvars can perform LFTR without a canonical IV.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+; Perform LFTR using the original pointer-type IV.
+
+; for(char* p = base; p < base + n; ++p) {
+; *p = p-base;
+; }
+define void @ptriv(i8* %base, i32 %n) nounwind {
+entry:
+ %idx.ext = sext i32 %n to i64
+ %add.ptr = getelementptr inbounds i8* %base, i64 %idx.ext
+ %cmp1 = icmp ult i8* %base, %add.ptr
+ br i1 %cmp1, label %for.body, label %for.end
+
+; CHECK: for.body:
+; CHECK: phi i8*
+; CHECK-NOT: phi
+; CHECK-NOT: add
+; CHECK: icmp ne i8*
+; CHECK: br i1
+for.body:
+ %p.02 = phi i8* [ %base, %entry ], [ %incdec.ptr, %for.body ]
+ ; cruft to make the IV useful
+ %sub.ptr.lhs.cast = ptrtoint i8* %p.02 to i64
+ %sub.ptr.rhs.cast = ptrtoint i8* %base to i64
+ %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
+ %conv = trunc i64 %sub.ptr.sub to i8
+ store i8 %conv, i8* %p.02
+ %incdec.ptr = getelementptr inbounds i8* %p.02, i32 1
+ %cmp = icmp ult i8* %incdec.ptr, %add.ptr
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
+
+; It would be nice if SCEV and any loop analysis could assume that
+; preheaders exist. Unfortunately it is not always the case. This test
+; checks that SCEVExpander can handle an outer loop that has not yet
+; been simplified. As a result, the inner loop's exit test will not be
+; rewritten.
+define void @expandOuterRecurrence(i32 %arg) nounwind {
+entry:
+ %sub1 = sub nsw i32 %arg, 1
+ %cmp1 = icmp slt i32 0, %sub1
+ br i1 %cmp1, label %outer, label %exit
+
+outer:
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.inc ]
+ %sub2 = sub nsw i32 %arg, %i
+ %sub3 = sub nsw i32 %sub2, 1
+ %cmp2 = icmp slt i32 0, %sub3
+ br i1 %cmp2, label %inner.ph, label %outer.inc
+
+inner.ph:
+ br label %inner
+
+; CHECK: inner:
+; CHECK: icmp slt
+; CHECK: br i1
+inner:
+ %j = phi i32 [ 0, %inner.ph ], [ %j.inc, %inner ]
+ %j.inc = add nsw i32 %j, 1
+ %cmp3 = icmp slt i32 %j.inc, %sub3
+ br i1 %cmp3, label %inner, label %outer.inc
+
+; CHECK: outer.inc:
+; CHECK: icmp ne
+; CHECK: br i1
+outer.inc:
+ %i.inc = add nsw i32 %i, 1
+ %cmp4 = icmp slt i32 %i.inc, %sub1
+ br i1 %cmp4, label %outer, label %exit
+
+exit:
+ ret void
+}
+
+; Force SCEVExpander to look for an existing well-formed phi.
+; Perform LFTR without generating extra preheader code.
+define void @guardedloop([0 x double]* %matrix, [0 x double]* %vector,
+ i32 %irow, i32 %ilead) nounwind {
+; CHECK: entry:
+; CHECK-NOT: zext
+; CHECK-NOT: add
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK: phi i64
+; CHECK-NOT: phi
+; CHECK: icmp ne
+; CHECK: br i1
+entry:
+ %cmp = icmp slt i32 1, %irow
+ br i1 %cmp, label %loop, label %return
+
+loop:
+ %rowidx = phi i32 [ 0, %entry ], [ %row.inc, %loop ]
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %loop ]
+ %diagidx = add nsw i32 %rowidx, %i
+ %diagidxw = sext i32 %diagidx to i64
+ %matrixp = getelementptr inbounds [0 x double]* %matrix, i32 0, i64 %diagidxw
+ %v1 = load double* %matrixp
+ %iw = sext i32 %i to i64
+ %vectorp = getelementptr inbounds [0 x double]* %vector, i32 0, i64 %iw
+ %v2 = load double* %vectorp
+ %row.inc = add nsw i32 %rowidx, %ilead
+ %i.inc = add nsw i32 %i, 1
+ %cmp196 = icmp slt i32 %i.inc, %irow
+ br i1 %cmp196, label %loop, label %return
+
+return:
+ ret void
+}
+
+; Avoid generating extra code to materialize a trip count. Skip LFTR.
+define void @unguardedloop([0 x double]* %matrix, [0 x double]* %vector,
+ i32 %irow, i32 %ilead) nounwind {
+entry:
+ br label %loop
+
+; CHECK: entry:
+; CHECK-NOT: zext
+; CHECK-NOT: add
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK: phi i64
+; CHECK-NOT: phi
+; CHECK: icmp slt
+; CHECK: br i1
+loop:
+ %rowidx = phi i32 [ 0, %entry ], [ %row.inc, %loop ]
+ %i = phi i32 [ 0, %entry ], [ %i.inc, %loop ]
+ %diagidx = add nsw i32 %rowidx, %i
+ %diagidxw = sext i32 %diagidx to i64
+ %matrixp = getelementptr inbounds [0 x double]* %matrix, i32 0, i64 %diagidxw
+ %v1 = load double* %matrixp
+ %iw = sext i32 %i to i64
+ %vectorp = getelementptr inbounds [0 x double]* %vector, i32 0, i64 %iw
+ %v2 = load double* %vectorp
+ %row.inc = add nsw i32 %rowidx, %ilead
+ %i.inc = add nsw i32 %i, 1
+ %cmp196 = icmp slt i32 %i.inc, %irow
+ br i1 %cmp196, label %loop, label %return
+
+return:
+ ret void
+}
+
+; Remove %i which is only used by the exit test.
+; Verify that SCEV can still compute a backedge count from the sign
+; extended %n, used for pointer comparison by LFTR.
+define void @geplftr(i8* %base, i32 %x, i32 %y, i32 %n) nounwind {
+entry:
+ %x.ext = sext i32 %x to i64
+ %add.ptr = getelementptr inbounds i8* %base, i64 %x.ext
+ %y.ext = sext i32 %y to i64
+ %add.ptr10 = getelementptr inbounds i8* %add.ptr, i64 %y.ext
+ %lim = add i32 %x, %n
+ %cmp.ph = icmp ult i32 %x, %lim
+ br i1 %cmp.ph, label %loop, label %exit
+
+; CHECK: loop:
+; CHECK: phi i8*
+; CHECK-NOT: phi
+; CHECK: getelementptr
+; CHECK: store
+; CHECK: icmp ne i8*
+; CHECK: br i1
+loop:
+ %i = phi i32 [ %x, %entry ], [ %inc, %loop ]
+ %aptr = phi i8* [ %add.ptr10, %entry ], [ %incdec.ptr, %loop ]
+ %incdec.ptr = getelementptr inbounds i8* %aptr, i32 1
+ store i8 3, i8* %aptr
+ %inc = add i32 %i, 1
+ %cmp = icmp ult i32 %inc, %lim
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+; Exercise backedge taken count verification with a never-taken loop.
+define void @nevertaken() nounwind uwtable ssp {
+entry:
+ br label %loop
+
+; CHECK: loop:
+; CHECK-NOT: phi
+; CHECK-NOT: add
+; CHECK-NOT: icmp
+; CHECK: exit:
+loop:
+ %i = phi i32 [ 0, %entry ], [ %inc, %loop ]
+ %inc = add nsw i32 %i, 1
+ %cmp = icmp sle i32 %inc, 0
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+; Test LFTR on an IV whose recurrence start is a non-unit pointer type.
+define void @aryptriv([256 x i8]* %base, i32 %n) nounwind {
+entry:
+ %ivstart = getelementptr inbounds [256 x i8]* %base, i32 0, i32 0
+ %ivend = getelementptr inbounds [256 x i8]* %base, i32 0, i32 %n
+ %cmp.ph = icmp ult i8* %ivstart, %ivend
+ br i1 %cmp.ph, label %loop, label %exit
+
+; CHECK: loop:
+; CHECK: phi i8*
+; CHECK-NOT: phi
+; CHECK: getelementptr
+; CHECK: store
+; CHECK: icmp ne i8*
+; CHECK: br i1
+loop:
+ %aptr = phi i8* [ %ivstart, %entry ], [ %incdec.ptr, %loop ]
+ %incdec.ptr = getelementptr inbounds i8* %aptr, i32 1
+ store i8 3, i8* %aptr
+ %cmp = icmp ult i8* %incdec.ptr, %ivend
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/lftr_simple.ll b/src/LLVM/test/Transforms/IndVarSimplify/lftr_simple.ll
new file mode 100644
index 0000000..3e13734
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/lftr_simple.ll
@@ -0,0 +1,22 @@
+; LFTR should eliminate the need for the computation of i*i completely. It
+; is only used to compute the exit value.
+; RUN: opt < %s -indvars -dce -S | not grep mul
+
+@A = external global i32 ; <i32*> [#uses=1]
+
+define i32 @quadratic_setlt() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 7, %entry ], [ %i.next, %loop ] ; <i32> [#uses=5]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ store i32 %i, i32* @A
+ %i2 = mul i32 %i, %i ; <i32> [#uses=1]
+ %c = icmp slt i32 %i2, 1000 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate10.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate10.ll
new file mode 100644
index 0000000..269478a
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate10.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -indvars -S \
+; RUN: | grep {%b.1 = phi i32 \\\[ 2, %bb \\\], \\\[ 1, %bb2 \\\]}
+
+; This loop has multiple exits, and the value of %b1 depends on which
+; exit is taken. Indvars should correctly compute the exit values.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-pc-linux-gnu"
+ %struct..0anon = type <{ i8, [3 x i8] }>
+
+define i32 @main() nounwind {
+entry:
+ br label %bb2
+
+bb2: ; preds = %bb, %entry
+ %sdata.0 = phi i32 [ 1, %entry ], [ %ins10, %bb ] ; <i32> [#uses=2]
+ %b.0 = phi i32 [ 0, %entry ], [ %t0, %bb ] ; <i32> [#uses=2]
+ %tmp6 = trunc i32 %sdata.0 to i8 ; <i8> [#uses=2]
+ %t2 = and i8 %tmp6, 1 ; <i8> [#uses=1]
+ %t3 = icmp eq i8 %t2, 0 ; <i1> [#uses=1]
+ %t4 = xor i8 %tmp6, 1 ; <i8> [#uses=1]
+ %tmp8 = zext i8 %t4 to i32 ; <i32> [#uses=1]
+ %mask9 = and i32 %sdata.0, -256 ; <i32> [#uses=1]
+ %ins10 = or i32 %tmp8, %mask9 ; <i32> [#uses=1]
+ br i1 %t3, label %bb3, label %bb
+
+bb: ; preds = %bb2
+ %t0 = add i32 %b.0, 1 ; <i32> [#uses=3]
+ %t1 = icmp sgt i32 %t0, 100 ; <i1> [#uses=1]
+ br i1 %t1, label %bb3, label %bb2
+
+bb3: ; preds = %bb, %bb2
+ %b.1 = phi i32 [ %t0, %bb ], [ %b.0, %bb2 ] ; <i32> [#uses=1]
+ %t5 = icmp eq i32 %b.1, 1 ; <i1> [#uses=1]
+ br i1 %t5, label %bb5, label %bb4
+
+bb4: ; preds = %bb3
+ tail call void @abort() noreturn nounwind
+ unreachable
+
+bb5: ; preds = %bb3
+ ret i32 0
+}
+
+declare void @llvm.memset.i64(i8* nocapture, i8, i64, i32) nounwind
+
+declare void @abort() noreturn nounwind
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate11.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate11.ll
new file mode 100644
index 0000000..40b785e
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate11.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -domfrontier -indvars -loop-deletion
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+define void @slap_sl_mem_create() nounwind {
+entry:
+ br label %bb15
+
+bb15: ; preds = %bb15, %entry
+ %order_end.0 = phi i32 [ 0, %entry ], [ %tmp, %bb15 ] ; <i32> [#uses=1]
+ %tmp = add i32 %order_end.0, 1 ; <i32> [#uses=2]
+ br i1 undef, label %bb17, label %bb15
+
+bb17: ; preds = %bb17, %bb15
+ %order_start.0 = phi i32 [ %tmp1, %bb17 ], [ 0, %bb15 ] ; <i32> [#uses=2]
+ %tmp1 = add i32 %order_start.0, 1 ; <i32> [#uses=2]
+ %tmp2 = icmp eq i32 undef, 0 ; <i1> [#uses=1]
+ br i1 %tmp2, label %bb18, label %bb17
+
+bb18: ; preds = %bb17
+ %tmp3 = sub i32 %tmp, %tmp1 ; <i32> [#uses=0]
+ br label %bb59
+
+bb51: ; preds = %bb59
+ %tmp4 = add i32 %order_start.0, 2 ; <i32> [#uses=1]
+ %tmp5 = add i32 %tmp4, undef ; <i32> [#uses=1]
+ %tmp6 = lshr i32 undef, %tmp5 ; <i32> [#uses=1]
+ %tmp7 = icmp eq i32 %tmp6, 0 ; <i1> [#uses=1]
+ br i1 %tmp7, label %bb52, label %bb59
+
+bb59: ; preds = %bb51, %bb18
+ br label %bb51
+
+bb52: ; preds = %bb51
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate7.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate7.ll
new file mode 100644
index 0000000..b9c0b12
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate7.ll
@@ -0,0 +1,61 @@
+; RUN: opt < %s -indvars
+; PR4436
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define i8* @string_expandtabs(i32 %n, i8* %m) nounwind {
+entry:
+ br i1 undef, label %bb33, label %bb1
+
+bb1: ; preds = %entry
+ br i1 undef, label %overflow1, label %bb15
+
+bb15: ; preds = %bb1
+ br i1 undef, label %bb33, label %bb17
+
+bb17: ; preds = %bb15
+ br label %bb30
+
+bb19: ; preds = %bb30
+ br i1 undef, label %bb20, label %bb29
+
+bb20: ; preds = %bb19
+ %0 = load i32* undef, align 4 ; <i32> [#uses=1]
+ %1 = sub i32 %0, %n ; <i32> [#uses=1]
+ br label %bb23
+
+bb21: ; preds = %bb23
+ %2 = icmp ult i8* %q.0, %m ; <i1> [#uses=1]
+ br i1 %2, label %bb22, label %overflow2
+
+bb22: ; preds = %bb21
+ %3 = getelementptr i8* %q.0, i32 1 ; <i8*> [#uses=1]
+ br label %bb23
+
+bb23: ; preds = %bb22, %bb20
+ %i.2 = phi i32 [ %1, %bb20 ], [ %4, %bb22 ] ; <i32> [#uses=1]
+ %q.0 = phi i8* [ undef, %bb20 ], [ %3, %bb22 ] ; <i8*> [#uses=3]
+ %4 = add i32 %i.2, -1 ; <i32> [#uses=2]
+ %5 = icmp eq i32 %4, -1 ; <i1> [#uses=1]
+ br i1 %5, label %bb29, label %bb21
+
+bb29: ; preds = %bb23, %bb19
+ %q.1 = phi i8* [ undef, %bb19 ], [ %q.0, %bb23 ] ; <i8*> [#uses=0]
+ br label %bb30
+
+bb30: ; preds = %bb29, %bb17
+ br i1 undef, label %bb19, label %bb33
+
+overflow2: ; preds = %bb21
+ br i1 undef, label %bb32, label %overflow1
+
+bb32: ; preds = %overflow2
+ br label %overflow1
+
+overflow1: ; preds = %bb32, %overflow2, %bb1
+ ret i8* null
+
+bb33: ; preds = %bb30, %bb15, %entry
+ ret i8* undef
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate8.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate8.ll
new file mode 100644
index 0000000..2a9d205
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate8.ll
@@ -0,0 +1,63 @@
+; RUN: opt < %s -indvars -S | not grep select
+
+; This loop has backedge-taken-count zero. Indvars shouldn't expand any
+; instructions to compute a trip count.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define i8* @string_expandtabs() nounwind {
+entry:
+ br i1 undef, label %bb33, label %bb1
+
+bb1: ; preds = %entry
+ br i1 undef, label %overflow1, label %bb15
+
+bb15: ; preds = %bb1
+ br i1 undef, label %bb33, label %bb17
+
+bb17: ; preds = %bb15
+ br label %bb30
+
+bb19: ; preds = %bb30
+ br i1 undef, label %bb20, label %bb29
+
+bb20: ; preds = %bb19
+ %0 = load i32* undef, align 4 ; <i32> [#uses=1]
+ %1 = sub i32 %0, undef ; <i32> [#uses=1]
+ br label %bb23
+
+bb21: ; preds = %bb23
+ %2 = icmp ult i8* %q.0, undef ; <i1> [#uses=1]
+ br i1 %2, label %bb22, label %overflow2
+
+bb22: ; preds = %bb21
+ %3 = getelementptr i8* %q.0, i32 1 ; <i8*> [#uses=1]
+ br label %bb23
+
+bb23: ; preds = %bb22, %bb20
+ %i.2 = phi i32 [ %1, %bb20 ], [ %4, %bb22 ] ; <i32> [#uses=1]
+ %q.0 = phi i8* [ undef, %bb20 ], [ %3, %bb22 ] ; <i8*> [#uses=3]
+ %4 = add i32 %i.2, -1 ; <i32> [#uses=2]
+ %5 = icmp eq i32 %4, -1 ; <i1> [#uses=1]
+ br i1 %5, label %bb29, label %bb21
+
+bb29: ; preds = %bb23, %bb19
+ %q.1 = phi i8* [ undef, %bb19 ], [ %q.0, %bb23 ] ; <i8*> [#uses=0]
+ br label %bb30
+
+bb30: ; preds = %bb29, %bb17
+ br i1 undef, label %bb19, label %bb33
+
+overflow2: ; preds = %bb21
+ br i1 undef, label %bb32, label %overflow1
+
+bb32: ; preds = %overflow2
+ br label %overflow1
+
+overflow1: ; preds = %bb32, %overflow2, %bb1
+ ret i8* null
+
+bb33: ; preds = %bb30, %bb15, %entry
+ ret i8* undef
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate9.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate9.ll
new file mode 100644
index 0000000..8184a73
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate9.ll
@@ -0,0 +1,78 @@
+; RUN: opt < %s -indvars -S > %t
+; RUN: grep {\[%\]tmp7 = icmp eq i8 -28, -28} %t
+; RUN: grep {\[%\]tmp8 = icmp eq i8 63, 63} %t
+; PR4477
+
+; Indvars should compute the exit values in loop.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %struct.cc70a02__complex_integers__complex_type = type { i8, i8 }
+@.str = internal constant [13 x i8] c"fc70a00.adb\00\00", align 1 ; <[13 x i8]*> [#uses=1]
+
+define void @_ada_cc70a02() {
+entry:
+ br label %bb1.i
+
+bb1.i: ; preds = %bb2.i, %entry
+ %indvar.i = phi i32 [ 0, %entry ], [ %indvar.next.i, %bb2.i ] ; <i32> [#uses=2]
+ %result.0.i = phi i16 [ 0, %entry ], [ %ins36.i, %bb2.i ] ; <i16> [#uses=2]
+ %tmp38.i = trunc i16 %result.0.i to i8 ; <i8> [#uses=2]
+ %tmp = add i8 %tmp38.i, 96 ; <i8> [#uses=1]
+ %tmp1 = icmp ugt i8 %tmp, -56 ; <i1> [#uses=1]
+ br i1 %tmp1, label %bb.i.i, label %bb1.i.i
+
+bb.i.i: ; preds = %bb1.i
+ tail call void @__gnat_rcheck_12(i8* getelementptr ([13 x i8]* @.str, i32 0, i32 0), i32 24) noreturn
+ unreachable
+
+bb1.i.i: ; preds = %bb1.i
+ %tmp41.i = lshr i16 %result.0.i, 8 ; <i16> [#uses=1]
+ %tmp42.i = trunc i16 %tmp41.i to i8 ; <i8> [#uses=2]
+ %tmp2 = add i8 %tmp42.i, 109 ; <i8> [#uses=1]
+ %tmp3 = icmp ugt i8 %tmp2, -56 ; <i1> [#uses=1]
+ br i1 %tmp3, label %bb2.i.i, label %cc70a02__complex_integers__Oadd.153.exit.i
+
+bb2.i.i: ; preds = %bb1.i.i
+ tail call void @__gnat_rcheck_12(i8* getelementptr ([13 x i8]* @.str, i32 0, i32 0), i32 24) noreturn
+ unreachable
+
+cc70a02__complex_integers__Oadd.153.exit.i: ; preds = %bb1.i.i
+ %tmp4 = add i8 %tmp38.i, -4 ; <i8> [#uses=2]
+ %tmp5 = add i8 %tmp42.i, 9 ; <i8> [#uses=2]
+ %tmp25.i = zext i8 %tmp4 to i16 ; <i16> [#uses=1]
+ %tmp33.i = zext i8 %tmp5 to i16 ; <i16> [#uses=1]
+ %tmp34.i = shl i16 %tmp33.i, 8 ; <i16> [#uses=1]
+ %ins36.i = or i16 %tmp34.i, %tmp25.i ; <i16> [#uses=1]
+ %tmp6 = icmp eq i32 %indvar.i, 6 ; <i1> [#uses=1]
+ br i1 %tmp6, label %cc70a02__complex_multiplication.170.exit, label %bb2.i
+
+bb2.i: ; preds = %cc70a02__complex_integers__Oadd.153.exit.i
+ %indvar.next.i = add i32 %indvar.i, 1 ; <i32> [#uses=1]
+ br label %bb1.i
+
+cc70a02__complex_multiplication.170.exit: ; preds = %cc70a02__complex_integers__Oadd.153.exit.i
+ %tmp7 = icmp eq i8 %tmp4, -28 ; <i1> [#uses=1]
+ %tmp8 = icmp eq i8 %tmp5, 63 ; <i1> [#uses=1]
+ %or.cond = and i1 %tmp8, %tmp7 ; <i1> [#uses=1]
+ br i1 %or.cond, label %return, label %bb1
+
+bb1: ; preds = %cc70a02__complex_multiplication.170.exit
+ tail call void @exit(i32 1)
+ ret void
+
+return: ; preds = %cc70a02__complex_multiplication.170.exit
+ ret void
+}
+
+declare fastcc void @cc70a02__complex_integers__complex.164(%struct.cc70a02__complex_integers__complex_type* noalias nocapture sret, i8 signext, i8 signext) nounwind
+
+declare fastcc void @cc70a02__complex_integers__Osubtract.149(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4)
+
+declare fastcc void @cc70a02__complex_integers__Oadd.153(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4, %struct.cc70a02__complex_integers__complex_type* byval align 4)
+
+declare fastcc void @cc70a02__complex_multiplication.170(%struct.cc70a02__complex_integers__complex_type* noalias sret, %struct.cc70a02__complex_integers__complex_type* byval align 4)
+
+declare void @__gnat_rcheck_12(i8*, i32) noreturn
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_1.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_1.ll
new file mode 100644
index 0000000..b0c7ffd
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_1.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -indvars -loop-deletion -simplifycfg -S | not grep br
+;
+; Testcase distilled from 256.bzip2
+
+define i32 @main() {
+entry:
+ br label %loopentry
+
+loopentry: ; preds = %loopentry, %entry
+ %indvar1 = phi i32 [ 0, %entry ], [ %indvar.next2, %loopentry ] ; <i32> [#uses=1]
+ %h.0 = phi i32 [ %tmp.2, %loopentry ], [ 4, %entry ] ; <i32> [#uses=1]
+ %tmp.1 = mul i32 %h.0, 3 ; <i32> [#uses=1]
+ %tmp.2 = add i32 %tmp.1, 1 ; <i32> [#uses=2]
+ %indvar.next2 = add i32 %indvar1, 1 ; <i32> [#uses=2]
+ %exitcond3 = icmp ne i32 %indvar.next2, 4 ; <i1> [#uses=1]
+ br i1 %exitcond3, label %loopentry, label %loopexit
+
+loopexit: ; preds = %loopentry
+ ret i32 %tmp.2
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_2.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_2.ll
new file mode 100644
index 0000000..72db51a
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_2.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -indvars -loop-deletion -simplifycfg | opt \
+; RUN: -analyze -loops | not grep "^Loop Containing"
+; PR1179
+
+define i32 @ltst(i32 %x) {
+entry:
+ icmp sgt i32 %x, 0 ; <i1>:0 [#uses=1]
+ br i1 %0, label %bb.preheader, label %bb8
+
+bb.preheader: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb, %bb.preheader
+ %i.01.0 = phi i32 [ %tmp4, %bb ], [ 0, %bb.preheader ] ; <i32> [#uses=1]
+ %j.03.0 = phi i32 [ %tmp2, %bb ], [ 0, %bb.preheader ] ; <i32> [#uses=1]
+ %tmp4 = add i32 %i.01.0, 1 ; <i32> [#uses=2]
+ %tmp2 = add i32 %j.03.0, 1 ; <i32> [#uses=2]
+ icmp slt i32 %tmp4, %x ; <i1>:1 [#uses=1]
+ br i1 %1, label %bb, label %bb8.loopexit
+
+bb8.loopexit: ; preds = %bb
+ br label %bb8
+
+bb8: ; preds = %bb8.loopexit, %entry
+ %j.03.1 = phi i32 [ 0, %entry ], [ %tmp2, %bb8.loopexit ] ; <i32> [#uses=1]
+ ret i32 %j.03.1
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_3.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_3.ll
new file mode 100644
index 0000000..78b2e98
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_3.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -indvars -S | grep {ret i32 600000}
+; PR1179
+
+define i32 @foo() {
+entry:
+ br label %bb5
+
+bb5: ; preds = %bb5, %entry
+ %i.01.0 = phi i32 [ 0, %entry ], [ %tmp2, %bb5 ] ; <i32> [#uses=1]
+ %x.03.0 = phi i32 [ 0, %entry ], [ %tmp4, %bb5 ] ; <i32> [#uses=1]
+ %tmp2 = add i32 %i.01.0, 3 ; <i32> [#uses=2]
+ %tmp4 = add i32 %x.03.0, 1 ; <i32> [#uses=2]
+ icmp slt i32 %tmp4, 200000 ; <i1>:0 [#uses=1]
+ br i1 %0, label %bb5, label %bb7
+
+bb7: ; preds = %bb5
+ ret i32 %tmp2
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_4.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_4.ll
new file mode 100644
index 0000000..a667b01
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_4.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -indvars -S | grep {ret i32 9900}
+; PR1179
+
+define i32 @test4() {
+entry:
+ br label %bb7
+
+bb7: ; preds = %bb7, %entry
+ %v.01.0 = phi i32 [ 0, %entry ], [ %tmp4, %bb7 ] ; <i32> [#uses=1]
+ %i.03.0 = phi i32 [ 0, %entry ], [ %tmp6, %bb7 ] ; <i32> [#uses=2]
+ %tmp2 = shl i32 %i.03.0, 1 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp2, %v.01.0 ; <i32> [#uses=2]
+ %tmp6 = add i32 %i.03.0, 1 ; <i32> [#uses=2]
+ icmp slt i32 %tmp6, 100 ; <i1>:0 [#uses=1]
+ br i1 %0, label %bb7, label %bb9
+
+bb9: ; preds = %bb7
+ ret i32 %tmp4
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_5.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_5.ll
new file mode 100644
index 0000000..80b961a
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_5.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -indvars -S | grep {120, %bb2.bb3_crit_edge}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+
+; Indvars should be able to compute an exit value for %tmp1.
+
+define i32 @testcase(i5 zeroext %k) nounwind readnone {
+entry:
+ br i1 false, label %bb3, label %bb.nph
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb2, %bb.nph
+ %result2 = phi i32 [ %tmp1, %bb2 ], [ 0, %bb.nph ] ; <i32> [#uses=1]
+ %k_01 = phi i5 [ %indvar_next1, %bb2 ], [ 0, %bb.nph ] ; <i5> [#uses=2]
+ %tmp2 = zext i5 %k_01 to i32 ; <i32> [#uses=1]
+ %tmp1 = add i32 %tmp2, %result2 ; <i32> [#uses=2]
+ %indvar_next1 = add i5 %k_01, 1 ; <i5> [#uses=2]
+ br label %bb2
+
+bb2: ; preds = %bb
+ %phitmp = icmp eq i5 %indvar_next1, -16 ; <i1> [#uses=1]
+ br i1 %phitmp, label %bb2.bb3_crit_edge, label %bb
+
+bb2.bb3_crit_edge: ; preds = %bb2
+ br label %bb3
+
+bb3: ; preds = %bb2.bb3_crit_edge, %entry
+ %result.lcssa = phi i32 [ %tmp1, %bb2.bb3_crit_edge ], [ 0, %entry ] ; <i32> [#uses=1]
+ ret i32 %result.lcssa
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_6.ll b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_6.ll
new file mode 100644
index 0000000..da38de5
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/loop_evaluate_6.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -indvars -loop-deletion -S | grep phi | count 1
+; XFAIL: *
+
+; Indvars can't evaluate this loop, because ScalarEvolution can't compute
+; an exact trip count, because it doesn't know if dividing by the stride will
+; have a remainder. It could be done with more aggressive VRP though.
+
+define i32 @test(i32 %x_offs) nounwind readnone {
+entry:
+ %0 = icmp sgt i32 %x_offs, 4 ; <i1> [#uses=1]
+ br i1 %0, label %bb.nph, label %bb2
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb1, %bb.nph
+ %x_offs_addr.01 = phi i32 [ %1, %bb1 ], [ %x_offs, %bb.nph ] ; <i32> [#uses=1]
+ %1 = add i32 %x_offs_addr.01, -4 ; <i32> [#uses=3]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %2 = icmp sgt i32 %1, 4 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %bb1.bb2_crit_edge
+
+bb1.bb2_crit_edge: ; preds = %bb1
+ br label %bb2
+
+bb2: ; preds = %bb1.bb2_crit_edge, %entry
+ %x_offs_addr.0.lcssa = phi i32 [ %1, %bb1.bb2_crit_edge ], [ %x_offs, %entry ] ; <i32> [#uses=1]
+ ret i32 %x_offs_addr.0.lcssa
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/masked-iv.ll b/src/LLVM/test/Transforms/IndVarSimplify/masked-iv.ll
new file mode 100644
index 0000000..f1f5af9
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/masked-iv.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -indvars -S > %t
+; RUN: not grep trunc %t
+; RUN: grep and %t | count 1
+
+; Indvars should do the IV arithmetic in the canonical IV type (i64),
+; and only use one truncation.
+
+define void @foo(i64* %A, i64* %B, i64 %n, i64 %a, i64 %s) nounwind {
+entry:
+ %t0 = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
+ br i1 %t0, label %bb.preheader, label %return
+
+bb.preheader: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb, %bb.preheader
+ %i.01 = phi i64 [ %t6, %bb ], [ %a, %bb.preheader ] ; <i64> [#uses=3]
+ %t1 = and i64 %i.01, 255 ; <i64> [#uses=1]
+ %t2 = getelementptr i64* %A, i64 %t1 ; <i64*> [#uses=1]
+ store i64 %i.01, i64* %t2, align 8
+ %t6 = add i64 %i.01, %s ; <i64> [#uses=1]
+ br label %bb
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/no-iv-rewrite.ll b/src/LLVM/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
new file mode 100644
index 0000000..9c2abd0
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
@@ -0,0 +1,392 @@
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+;
+; Make sure that indvars isn't inserting canonical IVs.
+; This is kinda hard to do until linear function test replacement is removed.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+define i32 @sum(i32* %arr, i32 %n) nounwind {
+entry:
+ %precond = icmp slt i32 0, %n
+ br i1 %precond, label %ph, label %return
+
+ph:
+ br label %loop
+
+; CHECK: loop:
+;
+; We should only have 2 IVs.
+; CHECK: phi
+; CHECK: phi
+; CHECK-NOT: phi
+;
+; sext should be eliminated while preserving gep inboundsness.
+; CHECK-NOT: sext
+; CHECK: getelementptr inbounds
+; CHECK: exit:
+loop:
+ %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
+ %s.01 = phi i32 [ 0, %ph ], [ %sinc, %loop ]
+ %ofs = sext i32 %i.02 to i64
+ %adr = getelementptr inbounds i32* %arr, i64 %ofs
+ %val = load i32* %adr
+ %sinc = add nsw i32 %s.01, %val
+ %iinc = add nsw i32 %i.02, 1
+ %cond = icmp slt i32 %iinc, %n
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ %s.lcssa = phi i32 [ %sinc, %loop ]
+ br label %return
+
+return:
+ %s.0.lcssa = phi i32 [ %s.lcssa, %exit ], [ 0, %entry ]
+ ret i32 %s.0.lcssa
+}
+
+define i64 @suml(i32* %arr, i32 %n) nounwind {
+entry:
+ %precond = icmp slt i32 0, %n
+ br i1 %precond, label %ph, label %return
+
+ph:
+ br label %loop
+
+; CHECK: loop:
+;
+; We should only have 2 IVs.
+; CHECK: phi
+; CHECK: phi
+; CHECK-NOT: phi
+;
+; %ofs sext should be eliminated while preserving gep inboundsness.
+; CHECK-NOT: sext
+; CHECK: getelementptr inbounds
+; %vall sext should obviously not be eliminated
+; CHECK: sext
+; CHECK: exit:
+loop:
+ %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
+ %s.01 = phi i64 [ 0, %ph ], [ %sinc, %loop ]
+ %ofs = sext i32 %i.02 to i64
+ %adr = getelementptr inbounds i32* %arr, i64 %ofs
+ %val = load i32* %adr
+ %vall = sext i32 %val to i64
+ %sinc = add nsw i64 %s.01, %vall
+ %iinc = add nsw i32 %i.02, 1
+ %cond = icmp slt i32 %iinc, %n
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ %s.lcssa = phi i64 [ %sinc, %loop ]
+ br label %return
+
+return:
+ %s.0.lcssa = phi i64 [ %s.lcssa, %exit ], [ 0, %entry ]
+ ret i64 %s.0.lcssa
+}
+
+define void @outofbounds(i32* %first, i32* %last, i32 %idx) nounwind {
+ %precond = icmp ne i32* %first, %last
+ br i1 %precond, label %ph, label %return
+
+; CHECK: ph:
+; It's not indvars' job to perform LICM on %ofs
+; CHECK-NOT: sext
+ph:
+ br label %loop
+
+; CHECK: loop:
+;
+; Preserve exactly one pointer type IV.
+; CHECK: phi i32*
+; CHECK-NOT: phi
+;
+; Don't create any extra adds.
+; CHECK-NOT: add
+;
+; Preserve gep inboundsness, and don't factor it.
+; CHECK: getelementptr inbounds i32* %ptriv, i32 1
+; CHECK-NOT: add
+; CHECK: exit:
+loop:
+ %ptriv = phi i32* [ %first, %ph ], [ %ptrpost, %loop ]
+ %ofs = sext i32 %idx to i64
+ %adr = getelementptr inbounds i32* %ptriv, i64 %ofs
+ store i32 3, i32* %adr
+ %ptrpost = getelementptr inbounds i32* %ptriv, i32 1
+ %cond = icmp ne i32* %ptrpost, %last
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ br label %return
+
+return:
+ ret void
+}
+
+%structI = type { i32 }
+
+define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %structI* %base)
+nounwind
+{
+entry:
+ br label %loop
+
+; CHECK: loop:
+;
+; Preserve casts
+; CHECK: phi i32
+; CHECK: bitcast
+; CHECK: getelementptr
+; CHECK: exit:
+loop:
+ %iv = phi i32 [%start, %entry], [%next, %loop]
+ %p = phi %structI* [%base, %entry], [%pinc, %loop]
+ %adr = getelementptr %structI* %p, i32 0, i32 0
+ store i32 3, i32* %adr
+ %pp = bitcast %structI* %p to i32*
+ store i32 4, i32* %pp
+ %pinc = getelementptr %structI* %p, i32 1
+ %next = add i32 %iv, 1
+ %cond = icmp ne i32 %next, %limit
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define void @maxvisitor(i32 %limit, i32* %base) nounwind {
+entry:
+ br label %loop
+
+; Test inserting a truncate at a phi use.
+;
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK: trunc
+; CHECK: exit:
+loop:
+ %idx = phi i32 [ 0, %entry ], [ %idx.next, %loop.inc ]
+ %max = phi i32 [ 0, %entry ], [ %max.next, %loop.inc ]
+ %idxprom = sext i32 %idx to i64
+ %adr = getelementptr inbounds i32* %base, i64 %idxprom
+ %val = load i32* %adr
+ %cmp19 = icmp sgt i32 %val, %max
+ br i1 %cmp19, label %if.then, label %if.else
+
+if.then:
+ br label %loop.inc
+
+if.else:
+ br label %loop.inc
+
+loop.inc:
+ %max.next = phi i32 [ %idx, %if.then ], [ %max, %if.else ]
+ %idx.next = add nsw i32 %idx, 1
+ %cmp = icmp slt i32 %idx.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define void @identityphi(i32 %limit) nounwind {
+entry:
+ br label %loop
+
+; Test an edge case of removing an identity phi that directly feeds
+; back to the loop iv.
+;
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK-NOT: phi
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
+ br i1 undef, label %if.then, label %control
+
+if.then:
+ br label %control
+
+control:
+ %iv.next = phi i32 [ %iv, %loop ], [ undef, %if.then ]
+ %cmp = icmp slt i32 %iv.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define i64 @cloneOr(i32 %limit, i64* %base) nounwind {
+entry:
+ ; ensure that the loop can't overflow
+ %halfLim = ashr i32 %limit, 2
+ br label %loop
+
+; Test cloning an or, which is not an OverflowBinaryOperator.
+;
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK-NOT: sext
+; CHECK: or i64
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+ %t1 = sext i32 %iv to i64
+ %adr = getelementptr i64* %base, i64 %t1
+ %val = load i64* %adr
+ %t2 = or i32 %iv, 1
+ %t3 = sext i32 %t2 to i64
+ %iv.next = add i32 %iv, 2
+ %cmp = icmp slt i32 %iv.next, %halfLim
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %result = and i64 %val, %t3
+ ret i64 %result
+}
+
+; The i induction variable looks like a wrap-around, but it really is just
+; a simple affine IV. Make sure that indvars simplifies through.
+define i32 @indirectRecurrence() nounwind {
+entry:
+ br label %loop
+
+; ReplaceLoopExitValue should fold the return value to constant 9.
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK: ret i32 9
+loop:
+ %j.0 = phi i32 [ 1, %entry ], [ %j.next, %cond_true ]
+ %i.0 = phi i32 [ 0, %entry ], [ %j.0, %cond_true ]
+ %tmp = icmp ne i32 %j.0, 10
+ br i1 %tmp, label %cond_true, label %return
+
+cond_true:
+ %j.next = add i32 %j.0, 1
+ br label %loop
+
+return:
+ ret i32 %i.0
+}
+
+; Eliminate the congruent phis j, k, and l.
+; Eliminate the redundant IV increments k.next and l.next.
+; Two phis should remain, one starting at %init, and one at %init1.
+; Two increments should remain, one by %step and one by %step1.
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK: phi i32
+; CHECK-NOT: phi
+; CHECK: add i32
+; CHECK: add i32
+; CHECK: add i32
+; CHECK-NOT: add
+; CHECK: return:
+;
+; Five live-outs should remain.
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK-NOT: phi
+; CHECK: ret
+define i32 @isomorphic(i32 %init, i32 %step, i32 %lim) nounwind {
+entry:
+ %step1 = add i32 %step, 1
+ %init1 = add i32 %init, %step1
+ %l.0 = sub i32 %init1, %step1
+ br label %loop
+
+loop:
+ %ii = phi i32 [ %init1, %entry ], [ %ii.next, %loop ]
+ %i = phi i32 [ %init, %entry ], [ %ii, %loop ]
+ %j = phi i32 [ %init, %entry ], [ %j.next, %loop ]
+ %k = phi i32 [ %init1, %entry ], [ %k.next, %loop ]
+ %l = phi i32 [ %l.0, %entry ], [ %l.next, %loop ]
+ %ii.next = add i32 %ii, %step1
+ %j.next = add i32 %j, %step1
+ %k.next = add i32 %k, %step1
+ %l.step = add i32 %l, %step
+ %l.next = add i32 %l.step, 1
+ %cmp = icmp ne i32 %ii.next, %lim
+ br i1 %cmp, label %loop, label %return
+
+return:
+ %sum1 = add i32 %i, %j.next
+ %sum2 = add i32 %sum1, %k.next
+ %sum3 = add i32 %sum1, %l.step
+ %sum4 = add i32 %sum1, %l.next
+ ret i32 %sum4
+}
+
+; Test a GEP IV that is derived from another GEP IV by a nop gep that
+; lowers the type without changing the expression.
+%structIF = type { i32, float }
+
+define void @congruentgepiv(%structIF* %base) nounwind uwtable ssp {
+entry:
+ %first = getelementptr inbounds %structIF* %base, i64 0, i32 0
+ br label %loop
+
+; CHECK: loop:
+; CHECK: phi %structIF*
+; CHECK: phi i32*
+; CHECK: getelementptr inbounds
+; CHECK: getelementptr inbounds
+; CHECK: exit:
+loop:
+ %ptr.iv = phi %structIF* [ %ptr.inc, %latch ], [ %base, %entry ]
+ %next = phi i32* [ %next.inc, %latch ], [ %first, %entry ]
+ store i32 4, i32* %next
+ br i1 undef, label %latch, label %exit
+
+latch: ; preds = %for.inc50.i
+ %ptr.inc = getelementptr inbounds %structIF* %ptr.iv, i64 1
+ %next.inc = getelementptr inbounds %structIF* %ptr.inc, i64 0, i32 0
+ br label %loop
+
+exit:
+ ret void
+}
+
+; Test a widened IV that is used by a phi on different paths within the loop.
+;
+; CHECK: for.body:
+; CHECK: phi i64
+; CHECK: trunc i64
+; CHECK: if.then:
+; CHECK: for.inc:
+; CHECK: phi i32
+; CHECK: for.end:
+define void @phiUsesTrunc() nounwind {
+entry:
+ br i1 undef, label %for.body, label %for.end
+
+for.body:
+ %iv = phi i32 [ %inc, %for.inc ], [ 1, %entry ]
+ br i1 undef, label %if.then, label %if.else
+
+if.then:
+ br i1 undef, label %if.then33, label %for.inc
+
+if.then33:
+ br label %for.inc
+
+if.else:
+ br i1 undef, label %if.then97, label %for.inc
+
+if.then97:
+ %idxprom100 = sext i32 %iv to i64
+ br label %for.inc
+
+for.inc:
+ %kmin.1 = phi i32 [ %iv, %if.then33 ], [ 0, %if.then ], [ %iv, %if.then97 ], [ 0, %if.else ]
+ %inc = add nsw i32 %iv, 1
+ br i1 undef, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/phi-uses-value-multiple-times.ll b/src/LLVM/test/Transforms/IndVarSimplify/phi-uses-value-multiple-times.ll
new file mode 100644
index 0000000..52c9e5c
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/phi-uses-value-multiple-times.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -indvars -disable-output -stats -info-output-file - | FileCheck %s
+; Check that IndVarSimplify is not creating unnecessary canonical IVs
+; that will never be used.
+; CHECK-NOT: indvars
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+@ue = external global i64
+
+define i32 @foo() nounwind {
+entry:
+ br label %bb38.i
+
+bb14.i27:
+ %t0 = load i64* @ue, align 8
+ %t1 = sub i64 %t0, %i.0.i35
+ %t2 = add i64 %t1, 1
+ br i1 undef, label %bb15.i28, label %bb19.i31
+
+bb15.i28:
+ br label %bb19.i31
+
+bb19.i31:
+ %y.0.i = phi i64 [ %t2, %bb15.i28 ], [ %t2, %bb14.i27 ]
+ br label %bb35.i
+
+bb35.i:
+ br i1 undef, label %bb37.i, label %bb14.i27
+
+bb37.i:
+ %t3 = add i64 %i.0.i35, 1
+ br label %bb38.i
+
+bb38.i:
+ %i.0.i35 = phi i64 [ 1, %entry ], [ %t3, %bb37.i ]
+ br label %bb35.i
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/polynomial-expand.ll b/src/LLVM/test/Transforms/IndVarSimplify/polynomial-expand.ll
new file mode 100644
index 0000000..2087f6a
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/polynomial-expand.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -indvars -disable-output
+; PR5073
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @ctpmv_(float* noalias nocapture %tmp4, i32 %tmp21) nounwind {
+bb20: ; preds = %bb19
+ br label %bb24
+
+bb24: ; preds = %bb40, %bb23
+ %tmp25 = phi i32 [ %tmp43, %bb40 ], [ %tmp21, %bb20 ] ; <i32> [#uses=4]
+ %tmp26 = phi i32 [ %tmp41, %bb40 ], [ undef, %bb20 ] ; <i32> [#uses=2]
+ %tmp27 = add nsw i32 %tmp26, -1 ; <i32> [#uses=1]
+ %tmp28 = add nsw i32 %tmp25, -1 ; <i32> [#uses=2]
+ %tmp29 = icmp sgt i32 %tmp28, 0 ; <i1> [#uses=1]
+ br i1 %tmp29, label %bb30, label %bb40
+
+bb30: ; preds = %bb30, %bb24
+ %tmp31 = phi i32 [ %tmp39, %bb30 ], [ %tmp28, %bb24 ] ; <i32> [#uses=2]
+ %tmp32 = phi i32 [ %tmp37, %bb30 ], [ %tmp27, %bb24 ] ; <i32> [#uses=2]
+ %tmp33 = sext i32 %tmp32 to i64 ; <i64> [#uses=1]
+ %tmp35 = getelementptr float* %tmp4, i64 %tmp33 ; <%0*> [#uses=1]
+ %tmp36 = load float* %tmp35, align 4 ; <%0> [#uses=0]
+ %tmp37 = add nsw i32 %tmp32, -1 ; <i32> [#uses=1]
+ %tmp39 = add nsw i32 %tmp31, -1 ; <i32> [#uses=1]
+ %tmp38 = icmp eq i32 %tmp31, 1 ; <i1> [#uses=1]
+ br i1 %tmp38, label %bb40, label %bb30
+
+bb40: ; preds = %bb30, %bb24
+ %tmp41 = sub i32 %tmp26, %tmp25 ; <i32> [#uses=1]
+ %tmp43 = add nsw i32 %tmp25, -1 ; <i32> [#uses=1]
+ %tmp42 = icmp eq i32 %tmp25, 1 ; <i1> [#uses=1]
+ br i1 %tmp42, label %bb46, label %bb24
+
+bb46: ; preds = %bb40, %bb23, %bb19
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-loop-variant.ll b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-loop-variant.ll
new file mode 100644
index 0000000..251d34e
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-loop-variant.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK-NOT: {{inttoptr|ptrtoint}}
+; CHECK: scevgep
+; CHECK-NOT: {{inttoptr|ptrtoint}}
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n32:64"
+
+; Indvars shouldn't need inttoptr/ptrtoint to expand an address here.
+
+define void @foo(i8* %p) nounwind {
+entry:
+ br i1 true, label %bb.nph, label %for.end
+
+for.cond:
+ %phitmp = icmp slt i64 %inc, 20
+ br i1 %phitmp, label %for.body, label %for.cond.for.end_crit_edge
+
+for.cond.for.end_crit_edge:
+ br label %for.end
+
+bb.nph:
+ br label %for.body
+
+for.body:
+ %storemerge1 = phi i64 [ %inc, %for.cond ], [ 0, %bb.nph ]
+ %call = tail call i64 @bar() nounwind
+ %call2 = tail call i64 @car() nounwind
+ %conv = trunc i64 %call2 to i8
+ %conv3 = sext i8 %conv to i64
+ %add = add nsw i64 %call, %storemerge1
+ %add4 = add nsw i64 %add, %conv3
+ %arrayidx = getelementptr inbounds i8* %p, i64 %add4
+ store i8 0, i8* %arrayidx
+ %inc = add nsw i64 %storemerge1, 1
+ br label %for.cond
+
+for.end:
+ ret void
+}
+
+declare i64 @bar()
+
+declare i64 @car()
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-nested.ll b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-nested.ll
new file mode 100644
index 0000000..cdcaaa0
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-nested.ll
@@ -0,0 +1,76 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; No explicit integer multiplications!
+; No i8* arithmetic or pointer casting anywhere!
+; CHECK-NOT: = {{= mul|i8\*|bitcast|inttoptr|ptrtoint}}
+; Exactly one getelementptr for each load+store.
+; Each getelementptr using %struct.Q* %s as a base and not i8*.
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK: getelementptr %struct.Q* %s,
+; CHECK-NOT: = {{= mul|i8\*|bitcast|inttoptr|ptrtoint}}
+
+; FIXME: This test should pass with or without TargetData. Until opt
+; supports running tests without targetdata, just hardware this in.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+
+%struct.Q = type { [10 x %struct.N] }
+%struct.N = type { %struct.S }
+%struct.S = type { [100 x double], [100 x double] }
+
+define void @foo(%struct.Q* %s, i64 %n) nounwind {
+entry:
+ br label %bb1
+
+bb1:
+ %i = phi i64 [ 2, %entry ], [ %i.next, %bb ]
+ %j = phi i64 [ 0, %entry ], [ %j.next, %bb ]
+ %t5 = icmp slt i64 %i, %n
+ br i1 %t5, label %bb, label %return
+
+bb:
+ %t0 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 0, i64 %i
+ %t1 = load double* %t0, align 8
+ %t2 = fmul double %t1, 3.200000e+00
+ %t3 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 0, i64 %i
+ store double %t2, double* %t3, align 8
+
+ %s0 = getelementptr inbounds %struct.Q* %s, i64 13, i32 0, i64 7, i32 0, i32 1, i64 %i
+ %s1 = load double* %s0, align 8
+ %s2 = fmul double %s1, 3.200000e+00
+ %s3 = getelementptr inbounds %struct.Q* %s, i64 13, i32 0, i64 7, i32 0, i32 1, i64 %i
+ store double %s2, double* %s3, align 8
+
+ %u0 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 7, i32 0, i32 1, i64 %j
+ %u1 = load double* %u0, align 8
+ %u2 = fmul double %u1, 3.200000e+00
+ %u3 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 7, i32 0, i32 1, i64 %j
+ store double %u2, double* %u3, align 8
+
+ %v0 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 1, i64 %i
+ %v1 = load double* %v0, align 8
+ %v2 = fmul double %v1, 3.200000e+00
+ %v3 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 1, i64 %i
+ store double %v2, double* %v3, align 8
+
+ %w0 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 0, i64 %j
+ %w1 = load double* %w0, align 8
+ %w2 = fmul double %w1, 3.200000e+00
+ %w3 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 0, i32 0, i32 0, i64 %j
+ store double %w2, double* %w3, align 8
+
+ %x0 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 3, i32 0, i32 0, i64 %i
+ %x1 = load double* %x0, align 8
+ %x2 = fmul double %x1, 3.200000e+00
+ %x3 = getelementptr inbounds %struct.Q* %s, i64 0, i32 0, i64 3, i32 0, i32 0, i64 %i
+ store double %x2, double* %x3, align 8
+
+ %i.next = add i64 %i, 1
+ %j.next = add i64 %j, 1
+ br label %bb1
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-remainder.ll b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-remainder.ll
new file mode 100644
index 0000000..2f3100f
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep-remainder.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK: %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 2, i64 %0, i64 1
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n32:64"
+
+; Indvars shouldn't expand this to
+; %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 0, i64 %tmp, i64 19
+; or something. That's valid, but more obscure.
+
+define void @foo([3 x [3 x double]]* noalias %p) nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
+ %ip = add i64 %i, 1
+ %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 2, i64 %ip, i64 1
+ volatile store double 0.0, double* %p.2.ip.1
+ %i.next = add i64 %i, 1
+ br label %loop
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep.ll b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep.ll
new file mode 100644
index 0000000..fec8a28
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/preserve-gep.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -indvars -S -enable-iv-rewrite | FileCheck %s
+; CHECK-NOT: {{ptrtoint|inttoptr}}
+; CHECK: getelementptr
+; CHECK-NOT: {{ptrtoint|inttoptr|getelementptr}}
+
+; Indvars shouldn't leave getelementptrs expanded out as
+; inttoptr+ptrtoint in its output in common cases.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.Foo = type { i32, i32, [10 x i32], i32 }
+
+define void @me(%struct.Foo* nocapture %Bar) nounwind {
+entry:
+ br i1 false, label %return, label %bb.nph
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb1, %bb.nph
+ %i.01 = phi i64 [ %4, %bb1 ], [ 0, %bb.nph ] ; <i64> [#uses=3]
+ %0 = getelementptr %struct.Foo* %Bar, i64 %i.01, i32 2, i64 3 ; <i32*> [#uses=1]
+ %1 = load i32* %0, align 4 ; <i32> [#uses=1]
+ %2 = mul i32 %1, 113 ; <i32> [#uses=1]
+ %3 = getelementptr %struct.Foo* %Bar, i64 %i.01, i32 2, i64 3 ; <i32*> [#uses=1]
+ store i32 %2, i32* %3, align 4
+ %4 = add i64 %i.01, 1 ; <i64> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %phitmp = icmp sgt i64 %4, 19999 ; <i1> [#uses=1]
+ br i1 %phitmp, label %bb1.return_crit_edge, label %bb
+
+bb1.return_crit_edge: ; preds = %bb1
+ br label %return
+
+return: ; preds = %bb1.return_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll b/src/LLVM/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
new file mode 100644
index 0000000..22e2092
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
+
+; Indvars should insert a 64-bit induction variable to eliminate the
+; sext for the addressing, however it shouldn't eliminate the sext
+; on the other phi, since that value undergoes signed wrapping.
+
+define void @foo(i32* nocapture %d, i32 %n) nounwind {
+entry:
+ %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+; CHECK: bb:
+; CHECK: phi i64
+; CHECK: sext i8
+; CHECK-NOT: sext
+bb: ; preds = %bb1, %bb.nph
+ %i.02 = phi i32 [ %5, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=2]
+ %p.01 = phi i8 [ %4, %bb1 ], [ -1, %bb.nph ] ; <i8> [#uses=2]
+ %1 = sext i8 %p.01 to i32 ; <i32> [#uses=1]
+ %2 = sext i32 %i.02 to i64 ; <i64> [#uses=1]
+ %3 = getelementptr i32* %d, i64 %2 ; <i32*> [#uses=1]
+ store i32 %1, i32* %3, align 4
+ %4 = add i8 %p.01, 1 ; <i8> [#uses=1]
+ %5 = add i32 %i.02, 1 ; <i32> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %6 = icmp slt i32 %5, %n ; <i1> [#uses=1]
+ br i1 %6, label %bb, label %bb1.return_crit_edge
+
+bb1.return_crit_edge: ; preds = %bb1
+ br label %return
+
+return: ; preds = %bb1.return_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll b/src/LLVM/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll
new file mode 100644
index 0000000..a007ca6
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll
@@ -0,0 +1,99 @@
+; RUN: opt < %s -indvars -S > %t
+; RUN: not grep sext %t
+
+define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly {
+entry:
+ %t0 = icmp sgt i32 %count, 0 ; <i1> [#uses=1]
+ br i1 %t0, label %bb.nph, label %bb2
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb1, %bb.nph
+ %result.02 = phi i64 [ %t5, %bb1 ], [ 0, %bb.nph ] ; <i64> [#uses=1]
+ %n.01 = phi i32 [ %t6, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=2]
+ %t1 = sext i32 %n.01 to i64 ; <i64> [#uses=1]
+ %t2 = getelementptr i64* %first, i64 %t1 ; <i64*> [#uses=1]
+ %t3 = load i64* %t2, align 8 ; <i64> [#uses=1]
+ %t4 = lshr i64 %t3, 4 ; <i64> [#uses=1]
+ %t5 = add i64 %t4, %result.02 ; <i64> [#uses=2]
+ %t6 = add i32 %n.01, 1 ; <i32> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %t7 = icmp slt i32 %t6, %count ; <i1> [#uses=1]
+ br i1 %t7, label %bb, label %bb1.bb2_crit_edge
+
+bb1.bb2_crit_edge: ; preds = %bb1
+ %.lcssa = phi i64 [ %t5, %bb1 ] ; <i64> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb1.bb2_crit_edge, %entry
+ %result.0.lcssa = phi i64 [ %.lcssa, %bb1.bb2_crit_edge ], [ 0, %entry ] ; <i64> [#uses=1]
+ ret i64 %result.0.lcssa
+}
+
+define void @foo(i16 signext %N, i32* nocapture %P) nounwind {
+entry:
+ %t0 = icmp sgt i16 %N, 0 ; <i1> [#uses=1]
+ br i1 %t0, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb1, %bb.nph
+ %i.01 = phi i16 [ %t3, %bb1 ], [ 0, %bb.nph ] ; <i16> [#uses=2]
+ %t1 = sext i16 %i.01 to i64 ; <i64> [#uses=1]
+ %t2 = getelementptr i32* %P, i64 %t1 ; <i32*> [#uses=1]
+ store i32 123, i32* %t2, align 4
+ %t3 = add i16 %i.01, 1 ; <i16> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %t4 = icmp slt i16 %t3, %N ; <i1> [#uses=1]
+ br i1 %t4, label %bb, label %bb1.return_crit_edge
+
+bb1.return_crit_edge: ; preds = %bb1
+ br label %return
+
+return: ; preds = %bb1.return_crit_edge, %entry
+ ret void
+}
+
+; Test cases from PR1301:
+
+define void @kinds__srangezero([21 x i32]* nocapture %a) nounwind {
+bb.thread:
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ -10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2]
+ %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp12, 10 ; <i32> [#uses=1]
+ %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp5
+ %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2]
+ %0 = icmp sgt i8 %tmp7, 10 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
+
+define void @kinds__urangezero([21 x i32]* nocapture %a) nounwind {
+bb.thread:
+ br label %bb
+
+bb: ; preds = %bb, %bb.thread
+ %i.0.reg2mem.0 = phi i8 [ 10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2]
+ %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp12, -10 ; <i32> [#uses=1]
+ %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp5
+ %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2]
+ %0 = icmp sgt i8 %tmp7, 30 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/shrunk-constant.ll b/src/LLVM/test/Transforms/IndVarSimplify/shrunk-constant.ll
new file mode 100644
index 0000000..271f8ed
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/shrunk-constant.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -scalar-evolution -analyze \
+; RUN: | grep {\\--> (zext i4 {-7,+,-8}<%loop> to i32)}
+
+define fastcc void @foo() nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i32 [ 0, %entry ], [ %t2, %loop ]
+ %t0 = add i32 %i, 9
+ %t1 = and i32 %t0, 9
+ store i32 %t1, i32* null
+ %t2 = add i32 %i, 8
+ br label %loop
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/signed-trip-count.ll b/src/LLVM/test/Transforms/IndVarSimplify/signed-trip-count.ll
new file mode 100644
index 0000000..1a5e64d
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/signed-trip-count.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -indvars -S > %t
+; RUN: not grep sext %t
+; RUN: grep phi %t | count 1
+
+define void @foo(i64* nocapture %x, i32 %n) nounwind {
+entry:
+ %tmp102 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
+ br i1 %tmp102, label %bb.nph, label %return
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb7, %bb.nph
+ %i.01 = phi i32 [ %tmp6, %bb7 ], [ 0, %bb.nph ] ; <i32> [#uses=3]
+ %tmp1 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
+ %tmp4 = getelementptr i64* %x, i32 %i.01 ; <i64*> [#uses=1]
+ store i64 %tmp1, i64* %tmp4, align 8
+ %tmp6 = add i32 %i.01, 1 ; <i32> [#uses=2]
+ br label %bb7
+
+bb7: ; preds = %bb
+ %tmp10 = icmp slt i32 %tmp6, %n ; <i1> [#uses=1]
+ br i1 %tmp10, label %bb, label %bb7.return_crit_edge
+
+bb7.return_crit_edge: ; preds = %bb7
+ br label %return
+
+return: ; preds = %bb7.return_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/single-element-range.ll b/src/LLVM/test/Transforms/IndVarSimplify/single-element-range.ll
new file mode 100644
index 0000000..4b035ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/single-element-range.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -indvars
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:64"
+target triple = "armv6-apple-darwin10"
+
+define void @sqlite3_free_table(i8** %azResult) nounwind {
+entry:
+ br i1 undef, label %return, label %bb
+
+bb: ; preds = %entry
+ %0 = load i8** undef, align 4 ; <i8*> [#uses=2]
+ %1 = ptrtoint i8* %0 to i32 ; <i32> [#uses=1]
+ %2 = icmp sgt i8* %0, inttoptr (i32 1 to i8*) ; <i1> [#uses=1]
+ br i1 %2, label %bb1, label %bb5
+
+bb1: ; preds = %bb1, %bb
+ %i.01 = phi i32 [ %3, %bb1 ], [ 1, %bb ] ; <i32> [#uses=1]
+ %3 = add i32 %i.01, 1 ; <i32> [#uses=2]
+ %4 = icmp slt i32 %3, %1 ; <i1> [#uses=1]
+ br i1 %4, label %bb1, label %bb5
+
+bb5: ; preds = %bb1, %bb
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/sink-alloca.ll b/src/LLVM/test/Transforms/IndVarSimplify/sink-alloca.ll
new file mode 100644
index 0000000..3a6c683
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/sink-alloca.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+; PR4775
+
+; Indvars shouldn't sink the alloca out of the entry block, even though
+; it's not used until after the loop.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @main to i8*)],
+section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
+
+define i32 @main() nounwind {
+; CHECK: entry:
+; CHECK-NEXT: %result.i = alloca i32, align 4
+entry:
+ %result.i = alloca i32, align 4 ; <i32*> [#uses=2]
+ br label %while.cond
+
+while.cond: ; preds = %while.cond, %entry
+ %call = call i32 @bar() nounwind ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %call, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %while.end, label %while.cond
+
+while.end: ; preds = %while.cond
+ volatile store i32 0, i32* %result.i
+ %tmp.i = volatile load i32* %result.i ; <i32> [#uses=0]
+ ret i32 0
+}
+
+declare i32 @bar()
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/sink-trapping.ll b/src/LLVM/test/Transforms/IndVarSimplify/sink-trapping.ll
new file mode 100644
index 0000000..a18000c
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/sink-trapping.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -indvars -S | FileCheck %s --check-prefix=CHECK
+
+declare i1 @b()
+
+define i32 @a(i32 %x) nounwind {
+for.body.preheader:
+ %y = sdiv i32 10, %x
+ br label %for.body
+
+for.body:
+ %cmp = call i1 @b()
+ br i1 %cmp, label %for.body, label %for.end.loopexit
+
+for.end.loopexit:
+ ret i32 %y
+}
+; CHECK: for.end.loopexit:
+; CHECK: sdiv
+; CHECK: ret
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/tripcount_compute.ll b/src/LLVM/test/Transforms/IndVarSimplify/tripcount_compute.ll
new file mode 100644
index 0000000..0d1de29
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/tripcount_compute.ll
@@ -0,0 +1,162 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+
+; These tests ensure that we can compute the trip count of various forms of
+; loops. If the trip count of the loop is computable, then we will know what
+; the exit value of the loop will be for some value, allowing us to substitute
+; it directly into users outside of the loop, making the loop dead.
+
+; CHECK: @linear_setne
+; CHECK: ret i32 100
+
+define i32 @linear_setne() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+; CHECK: @linear_setne_2
+; CHECK: ret i32 100
+
+define i32 @linear_setne_2() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 2 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+; CHECK: @linear_setne_overflow
+; CHECK: ret i32 0
+
+define i32 @linear_setne_overflow() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 1024, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 1024 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 0 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+; CHECK: @linear_setlt
+; CHECK: ret i32 100
+
+define i32 @linear_setlt() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ %c = icmp slt i32 %i, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+; CHECK: @quadratic_setlt
+; CHECK: ret i32 34
+
+define i32 @quadratic_setlt() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 7, %entry ], [ %i.next, %loop ] ; <i32> [#uses=4]
+ %i.next = add i32 %i, 3 ; <i32> [#uses=1]
+ %i2 = mul i32 %i, %i ; <i32> [#uses=1]
+ %c = icmp slt i32 %i2, 1000 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+; CHECK: @chained
+; CHECK: ret i32 200
+
+define i32 @chained() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ br label %loop2
+
+loop2: ; preds = %loop2, %loopexit
+ %j = phi i32 [ %i, %loopexit ], [ %j.next, %loop2 ] ; <i32> [#uses=3]
+ %j.next = add i32 %j, 1 ; <i32> [#uses=1]
+ %c2 = icmp ne i32 %j, 200 ; <i1> [#uses=1]
+ br i1 %c2, label %loop2, label %loopexit2
+
+loopexit2: ; preds = %loop2
+ ret i32 %j
+}
+
+; CHECK: @chained4
+; CHECK: ret i32 400
+
+define i32 @chained4() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i.next, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ br label %loop2
+
+loop2: ; preds = %loop2, %loopexit
+ %j = phi i32 [ %i.next, %loopexit ], [ %j.next, %loop2 ] ; <i32> [#uses=3]
+ %j.next = add i32 %j, 1 ; <i32> [#uses=1]
+ %c2 = icmp ne i32 %j.next, 200 ; <i1> [#uses=1]
+ br i1 %c2, label %loop2, label %loopexit2
+
+loopexit2: ; preds = %loop
+ br label %loop8
+
+loop8: ; preds = %loop2, %loopexit
+ %k = phi i32 [ %j.next, %loopexit2 ], [ %k.next, %loop8 ] ; <i32> [#uses=3]
+ %k.next = add i32 %k, 1 ; <i32> [#uses=1]
+ %c8 = icmp ne i32 %k.next, 300 ; <i1> [#uses=1]
+ br i1 %c8, label %loop8, label %loopexit8
+
+loopexit8: ; preds = %loop2
+ br label %loop9
+
+loop9: ; preds = %loop2, %loopexit
+ %l = phi i32 [ %k.next, %loopexit8 ], [ %l.next, %loop9 ] ; <i32> [#uses=3]
+ %l.next = add i32 %l, 1 ; <i32> [#uses=1]
+ %c9 = icmp ne i32 %l.next, 400 ; <i1> [#uses=1]
+ br i1 %c9, label %loop9, label %loopexit9
+
+loopexit9: ; preds = %loop2
+ ret i32 %l.next
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/tripcount_infinite.ll b/src/LLVM/test/Transforms/IndVarSimplify/tripcount_infinite.ll
new file mode 100644
index 0000000..64aa12b
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/tripcount_infinite.ll
@@ -0,0 +1,38 @@
+; These tests have an infinite trip count. We obviously shouldn't remove the
+; loops! :)
+;
+; RUN: opt < %s -indvars -adce -simplifycfg -S | grep icmp | wc -l > %t2
+; RUN: llvm-as < %s | llvm-dis | grep icmp | wc -l > %t1
+; RUN: diff %t1 %t2
+
+;; test for (i = 1; i != 100; i += 2)
+define i32 @infinite_linear() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 1, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
+ %i.next = add i32 %i, 2 ; <i32> [#uses=1]
+ %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
+;; test for (i = 1; i*i != 63; ++i)
+define i32 @infinite_quadratic() {
+entry:
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ %i = phi i32 [ 1, %entry ], [ %i.next, %loop ] ; <i32> [#uses=4]
+ %isquare = mul i32 %i, %i ; <i32> [#uses=1]
+ %i.next = add i32 %i, 1 ; <i32> [#uses=1]
+ %c = icmp ne i32 %isquare, 63 ; <i1> [#uses=1]
+ br i1 %c, label %loop, label %loopexit
+
+loopexit: ; preds = %loop
+ ret i32 %i
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/udiv.ll b/src/LLVM/test/Transforms/IndVarSimplify/udiv.ll
new file mode 100644
index 0000000..8260093
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/udiv.ll
@@ -0,0 +1,162 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+@main.flags = internal global [8193 x i8] zeroinitializer, align 1 ; <[8193 x i8]*> [#uses=5]
+@.str = private constant [11 x i8] c"Count: %d\0A\00" ; <[11 x i8]*> [#uses=1]
+
+; Indvars shouldn't emit a udiv here, because there's no udiv in the
+; original code. This comes from SingleSource/Benchmarks/Shootout/sieve.c.
+
+; CHECK: @main
+; CHECK-NOT: div
+
+define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
+entry:
+ %cmp = icmp eq i32 %argc, 2 ; <i1> [#uses=1]
+ br i1 %cmp, label %cond.true, label %while.cond.preheader
+
+cond.true: ; preds = %entry
+ %arrayidx = getelementptr inbounds i8** %argv, i64 1 ; <i8**> [#uses=1]
+ %tmp2 = load i8** %arrayidx ; <i8*> [#uses=1]
+ %call = tail call i32 @atoi(i8* %tmp2) nounwind readonly ; <i32> [#uses=1]
+ br label %while.cond.preheader
+
+while.cond.preheader: ; preds = %entry, %cond.true
+ %NUM.0.ph = phi i32 [ %call, %cond.true ], [ 170000, %entry ] ; <i32> [#uses=2]
+ %tobool18 = icmp eq i32 %NUM.0.ph, 0 ; <i1> [#uses=1]
+ br i1 %tobool18, label %while.end, label %bb.nph30
+
+while.cond.loopexit: ; preds = %for.cond12.while.cond.loopexit_crit_edge, %for.cond12.loopexit
+ %count.2.lcssa = phi i32 [ %count.1.lcssa, %for.cond12.while.cond.loopexit_crit_edge ], [ 0, %for.cond12.loopexit ] ; <i32> [#uses=1]
+ br label %while.cond
+
+while.cond: ; preds = %while.cond.loopexit
+ %tobool = icmp eq i32 %dec19, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %while.cond.while.end_crit_edge, label %for.cond.preheader
+
+while.cond.while.end_crit_edge: ; preds = %while.cond
+ %count.2.lcssa.lcssa = phi i32 [ %count.2.lcssa, %while.cond ] ; <i32> [#uses=1]
+ br label %while.end
+
+bb.nph30: ; preds = %while.cond.preheader
+ br label %for.cond.preheader
+
+for.cond.preheader: ; preds = %bb.nph30, %while.cond
+ %dec19.in = phi i32 [ %NUM.0.ph, %bb.nph30 ], [ %dec19, %while.cond ] ; <i32> [#uses=1]
+ %dec19 = add i32 %dec19.in, -1 ; <i32> [#uses=2]
+ br i1 true, label %bb.nph, label %for.cond12.loopexit
+
+for.cond: ; preds = %for.body
+ %cmp8 = icmp slt i64 %inc, 8193 ; <i1> [#uses=1]
+ br i1 %cmp8, label %for.body, label %for.cond.for.cond12.loopexit_crit_edge
+
+for.cond.for.cond12.loopexit_crit_edge: ; preds = %for.cond
+ br label %for.cond12.loopexit
+
+bb.nph: ; preds = %for.cond.preheader
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.cond
+ %i.02 = phi i64 [ 2, %bb.nph ], [ %inc, %for.cond ] ; <i64> [#uses=2]
+ %arrayidx10 = getelementptr inbounds [8193 x i8]* @main.flags, i64 0, i64 %i.02 ; <i8*> [#uses=1]
+ store i8 1, i8* %arrayidx10
+ %inc = add nsw i64 %i.02, 1 ; <i64> [#uses=2]
+ br label %for.cond
+
+for.cond12.loopexit: ; preds = %for.cond.for.cond12.loopexit_crit_edge, %for.cond.preheader
+ br i1 true, label %bb.nph16, label %while.cond.loopexit
+
+for.cond12: ; preds = %for.inc35
+ %cmp14 = icmp slt i64 %inc37, 8193 ; <i1> [#uses=1]
+ br i1 %cmp14, label %for.body15, label %for.cond12.while.cond.loopexit_crit_edge
+
+for.cond12.while.cond.loopexit_crit_edge: ; preds = %for.cond12
+ %count.1.lcssa = phi i32 [ %count.1, %for.cond12 ] ; <i32> [#uses=1]
+ br label %while.cond.loopexit
+
+bb.nph16: ; preds = %for.cond12.loopexit
+ br label %for.body15
+
+for.body15: ; preds = %bb.nph16, %for.cond12
+ %count.212 = phi i32 [ 0, %bb.nph16 ], [ %count.1, %for.cond12 ] ; <i32> [#uses=2]
+ %i.17 = phi i64 [ 2, %bb.nph16 ], [ %inc37, %for.cond12 ] ; <i64> [#uses=4]
+ %arrayidx17 = getelementptr inbounds [8193 x i8]* @main.flags, i64 0, i64 %i.17 ; <i8*> [#uses=1]
+ %tmp18 = load i8* %arrayidx17 ; <i8> [#uses=1]
+ %tobool19 = icmp eq i8 %tmp18, 0 ; <i1> [#uses=1]
+ br i1 %tobool19, label %for.inc35, label %if.then
+
+if.then: ; preds = %for.body15
+ %add = shl i64 %i.17, 1 ; <i64> [#uses=2]
+ %cmp243 = icmp slt i64 %add, 8193 ; <i1> [#uses=1]
+ br i1 %cmp243, label %bb.nph5, label %for.end32
+
+for.cond22: ; preds = %for.body25
+ %cmp24 = icmp slt i64 %add31, 8193 ; <i1> [#uses=1]
+ br i1 %cmp24, label %for.body25, label %for.cond22.for.end32_crit_edge
+
+for.cond22.for.end32_crit_edge: ; preds = %for.cond22
+ br label %for.end32
+
+bb.nph5: ; preds = %if.then
+ br label %for.body25
+
+for.body25: ; preds = %bb.nph5, %for.cond22
+ %k.04 = phi i64 [ %add, %bb.nph5 ], [ %add31, %for.cond22 ] ; <i64> [#uses=2]
+ %arrayidx27 = getelementptr inbounds [8193 x i8]* @main.flags, i64 0, i64 %k.04 ; <i8*> [#uses=1]
+ store i8 0, i8* %arrayidx27
+ %add31 = add nsw i64 %k.04, %i.17 ; <i64> [#uses=2]
+ br label %for.cond22
+
+for.end32: ; preds = %for.cond22.for.end32_crit_edge, %if.then
+ %inc34 = add nsw i32 %count.212, 1 ; <i32> [#uses=1]
+ br label %for.inc35
+
+for.inc35: ; preds = %for.body15, %for.end32
+ %count.1 = phi i32 [ %inc34, %for.end32 ], [ %count.212, %for.body15 ] ; <i32> [#uses=2]
+ %inc37 = add nsw i64 %i.17, 1 ; <i64> [#uses=2]
+ br label %for.cond12
+
+while.end: ; preds = %while.cond.while.end_crit_edge, %while.cond.preheader
+ %count.0.lcssa = phi i32 [ %count.2.lcssa.lcssa, %while.cond.while.end_crit_edge ], [ 0, %while.cond.preheader ] ; <i32> [#uses=1]
+ %call40 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([11 x i8]* @.str, i64 0, i64 0), i32 %count.0.lcssa) nounwind ; <i32> [#uses=0]
+ ret i32 0
+}
+
+declare i32 @atoi(i8* nocapture) nounwind readonly
+
+declare i32 @printf(i8* nocapture, ...) nounwind
+
+; IndVars shouldn't be afraid to emit a udiv here, since there's a udiv in
+; the original code.
+
+; CHECK: @foo
+; CHECK: for.body.preheader:
+; CHECK-NEXT: udiv
+
+define void @foo(double* %p, i64 %n) nounwind {
+entry:
+ %div0 = udiv i64 %n, 7 ; <i64> [#uses=1]
+ %div1 = add i64 %div0, 1
+ %cmp2 = icmp ult i64 0, %div1 ; <i1> [#uses=1]
+ br i1 %cmp2, label %for.body.preheader, label %for.end
+
+for.body.preheader: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %for.body.preheader, %for.body
+ %i.03 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] ; <i64> [#uses=2]
+ %arrayidx = getelementptr inbounds double* %p, i64 %i.03 ; <double*> [#uses=1]
+ store double 0.000000e+00, double* %arrayidx
+ %inc = add i64 %i.03, 1 ; <i64> [#uses=2]
+ %divx = udiv i64 %n, 7 ; <i64> [#uses=1]
+ %div = add i64 %divx, 1
+ %cmp = icmp ult i64 %inc, %div ; <i1> [#uses=1]
+ br i1 %cmp, label %for.body, label %for.end.loopexit
+
+for.end.loopexit: ; preds = %for.body
+ br label %for.end
+
+for.end: ; preds = %for.end.loopexit, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/uglygep.ll b/src/LLVM/test/Transforms/IndVarSimplify/uglygep.ll
new file mode 100644
index 0000000..0014b683
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/uglygep.ll
@@ -0,0 +1,40 @@
+; RUN: opt -indvars -S < %s | not grep uglygep
+; rdar://8197217
+
+; Indvars should be able to emit a clean GEP here, not an uglygep.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0"
+
+@numf2s = external global i32 ; <i32*> [#uses=1]
+@numf1s = external global i32 ; <i32*> [#uses=1]
+@tds = external global double** ; <double***> [#uses=1]
+
+define void @init_td(i32 %tmp7) nounwind {
+entry:
+ br label %bb4
+
+bb4: ; preds = %bb3, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %tmp9, %bb3 ] ; <i32> [#uses=3]
+ br label %bb
+
+bb: ; preds = %bb4
+ br label %bb2
+
+bb2: ; preds = %bb1, %bb
+ %j.0 = phi i32 [ 0, %bb ], [ %tmp6, %bb1 ] ; <i32> [#uses=3]
+ %tmp8 = icmp slt i32 %j.0, %tmp7 ; <i1> [#uses=1]
+ br i1 %tmp8, label %bb1, label %bb3
+
+bb1: ; preds = %bb2
+ %tmp = load double*** @tds, align 8 ; <double**> [#uses=1]
+ %tmp1 = sext i32 %i.0 to i64 ; <i64> [#uses=1]
+ %tmp2 = getelementptr inbounds double** %tmp, i64 %tmp1 ; <double**> [#uses=1]
+ %tmp3 = load double** %tmp2, align 1 ; <double*> [#uses=1]
+ %tmp6 = add nsw i32 %j.0, 1 ; <i32> [#uses=1]
+ br label %bb2
+
+bb3: ; preds = %bb2
+ %tmp9 = add nsw i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb4
+}
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll b/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll
new file mode 100644
index 0000000..3e53aa4
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -indvars -instcombine -S | FileCheck %s
+; RUN: opt < %s -indvars -enable-iv-rewrite=false -instcombine -S | FileCheck %s
+;
+; Test that -indvars can reduce variable stride IVs. If it can reduce variable
+; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
+; cycles, allowing the tmp.21 subtraction to be eliminated.
+
+define void @vnum_test8(i32* %data) {
+entry:
+ %tmp.1 = getelementptr i32* %data, i32 3 ; <i32*> [#uses=1]
+ %tmp.2 = load i32* %tmp.1 ; <i32> [#uses=2]
+ %tmp.4 = getelementptr i32* %data, i32 4 ; <i32*> [#uses=1]
+ %tmp.5 = load i32* %tmp.4 ; <i32> [#uses=2]
+ %tmp.8 = getelementptr i32* %data, i32 2 ; <i32*> [#uses=1]
+ %tmp.9 = load i32* %tmp.8 ; <i32> [#uses=3]
+ %tmp.125 = icmp sgt i32 %tmp.2, 0 ; <i1> [#uses=1]
+ br i1 %tmp.125, label %no_exit.preheader, label %return
+
+no_exit.preheader: ; preds = %entry
+ %tmp.16 = getelementptr i32* %data, i32 %tmp.9 ; <i32*> [#uses=1]
+ br label %no_exit
+
+; CHECK: store i32 0
+no_exit: ; preds = %no_exit, %no_exit.preheader
+ %iv.ui = phi i32 [ 0, %no_exit.preheader ], [ %iv..inc.ui, %no_exit ] ; <i32> [#uses=1]
+ %iv. = phi i32 [ %tmp.5, %no_exit.preheader ], [ %iv..inc, %no_exit ] ; <i32> [#uses=2]
+ %m.0.0 = phi i32 [ %tmp.5, %no_exit.preheader ], [ %tmp.24, %no_exit ] ; <i32> [#uses=2]
+ store i32 2, i32* %tmp.16
+ %tmp.21 = sub i32 %m.0.0, %iv. ; <i32> [#uses=1]
+ store i32 %tmp.21, i32* %data
+ %tmp.24 = add i32 %m.0.0, %tmp.9 ; <i32> [#uses=1]
+ %iv..inc = add i32 %tmp.9, %iv. ; <i32> [#uses=1]
+ %iv..inc.ui = add i32 %iv.ui, 1 ; <i32> [#uses=2]
+ %iv..inc1 = bitcast i32 %iv..inc.ui to i32 ; <i32> [#uses=1]
+ %tmp.12 = icmp slt i32 %iv..inc1, %tmp.2 ; <i1> [#uses=1]
+ br i1 %tmp.12, label %no_exit, label %return.loopexit
+
+return.loopexit: ; preds = %no_exit
+ br label %return
+
+return: ; preds = %return.loopexit, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-1.ll b/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-1.ll
new file mode 100644
index 0000000..98cfa34
--- /dev/null
+++ b/src/LLVM/test/Transforms/IndVarSimplify/variable-stride-ivs-1.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -indvars
+; PR4315
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "x86_64-undermydesk-freebsd8.0"
+ %struct.mbuf = type <{ %struct.mbuf*, i8*, i32, i8, i8, i8, i8 }>
+
+define i32 @crash(%struct.mbuf* %m) nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %if.end, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ] ; <i32> [#uses=3]
+ %chksum.0 = phi i8 [ 0, %entry ], [ %conv3, %if.end ] ; <i8> [#uses=3]
+ %cmp = icmp slt i32 %i.0, 1 ; <i1> [#uses=1]
+ br i1 %cmp, label %for.body, label %do.body
+
+for.body: ; preds = %for.cond
+ br i1 undef, label %if.end, label %do.body
+
+if.end: ; preds = %for.body
+ %i.02 = trunc i32 %i.0 to i8 ; <i8> [#uses=1]
+ %conv3 = add i8 %chksum.0, %i.02 ; <i8> [#uses=1]
+ %inc = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %for.cond
+
+do.body: ; preds = %do.cond, %for.body, %for.cond
+ %chksum.2 = phi i8 [ undef, %do.cond ], [ %chksum.0, %for.body ], [ %chksum.0, %for.cond ] ; <i8> [#uses=1]
+ br i1 undef, label %do.cond, label %bb.nph
+
+bb.nph: ; preds = %do.body
+ br label %while.body
+
+while.body: ; preds = %while.body, %bb.nph
+ %chksum.13 = phi i8 [ undef, %while.body ], [ %chksum.2, %bb.nph ] ; <i8> [#uses=0]
+ br i1 undef, label %do.cond, label %while.body
+
+do.cond: ; preds = %while.body, %do.body
+ br i1 false, label %do.end, label %do.body
+
+do.end: ; preds = %do.cond
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/Inline/2003-09-14-InlineValue.ll b/src/LLVM/test/Transforms/Inline/2003-09-14-InlineValue.ll
new file mode 100644
index 0000000..bd67920
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2003-09-14-InlineValue.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -inline -disable-output
+
+declare i32 @External()
+
+define internal i32 @Callee() {
+ %I = call i32 @External( ) ; <i32> [#uses=2]
+ %J = add i32 %I, %I ; <i32> [#uses=1]
+ ret i32 %J
+}
+
+define i32 @Caller() {
+ %V = invoke i32 @Callee( )
+ to label %Ok unwind label %Bad ; <i32> [#uses=1]
+
+Ok: ; preds = %0
+ ret i32 %V
+
+Bad: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 0
+}
+
+declare i32 @__gxx_personality_v0(...)
+
diff --git a/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll
new file mode 100644
index 0000000..5796786
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -inline -disable-output
+
+define i32 @main() {
+entry:
+ invoke void @__main( )
+ to label %LongJmpBlkPre unwind label %LongJmpBlkPre
+
+LongJmpBlkPre: ; preds = %entry, %entry
+ %i.3 = phi i32 [ 0, %entry ], [ 0, %entry ] ; <i32> [#uses=0]
+ ret i32 0
+}
+
+define void @__main() {
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll
new file mode 100644
index 0000000..c512b91
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -inline -disable-output
+
+define i32 @main() {
+entry:
+ invoke void @__main( )
+ to label %Call2Invoke unwind label %LongJmpBlkPre
+
+Call2Invoke: ; preds = %entry
+ br label %exit
+
+LongJmpBlkPre: ; preds = %Call2Invoke, %entry
+ %i.3 = phi i32 [ 0, %entry ], [ 0, %Call2Invoke ] ; <i32> [#uses=0]
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ br label %exit
+
+exit:
+ ret i32 0
+}
+
+define void @__main() {
+ call void @__llvm_getGlobalCtors( )
+ call void @__llvm_getGlobalDtors( )
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @__llvm_getGlobalCtors()
+
+declare void @__llvm_getGlobalDtors()
+
diff --git a/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInNormalInvokeDest.ll b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInNormalInvokeDest.ll
new file mode 100644
index 0000000..48b253e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2003-09-22-PHINodesInNormalInvokeDest.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -inline -disable-output
+
+define i32 @main() {
+entry:
+ invoke void @__main( )
+ to label %else unwind label %RethrowExcept
+
+else: ; preds = %LJDecisionBB, %entry
+ %i.2 = phi i32 [ 36, %entry ], [ %i.2, %LJDecisionBB ] ; <i32> [#uses=1]
+ br label %LJDecisionBB
+
+LJDecisionBB: ; preds = %else
+ br label %else
+
+RethrowExcept: ; preds = %entry
+ ret i32 0
+}
+
+define void @__main() {
+ ret void
+}
+
+
diff --git a/src/LLVM/test/Transforms/Inline/2003-10-13-AllocaDominanceProblem.ll b/src/LLVM/test/Transforms/Inline/2003-10-13-AllocaDominanceProblem.ll
new file mode 100644
index 0000000..bc4ad41
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2003-10-13-AllocaDominanceProblem.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -inline -disable-output
+
+define i32 @reload() {
+reloadentry:
+ br label %A
+
+A: ; preds = %reloadentry
+ call void @callee( )
+ ret i32 0
+}
+
+define internal void @callee() {
+entry:
+ %X = alloca i8, i32 0 ; <i8*> [#uses=0]
+ %Y = bitcast i32 0 to i32 ; <i32> [#uses=1]
+ %Z = alloca i8, i32 %Y ; <i8*> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2004-04-15-InlineDeletesCall.ll b/src/LLVM/test/Transforms/Inline/2004-04-15-InlineDeletesCall.ll
new file mode 100644
index 0000000..9216c72
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2004-04-15-InlineDeletesCall.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -inline -disable-output
+
+; Inlining the first call caused the inliner function to delete the second
+; call. Then the inliner tries to inline the second call, which no longer
+; exists.
+
+define internal void @Callee1() {
+ unreachable
+}
+
+define void @Callee2() {
+ ret void
+}
+
+define void @caller() {
+ call void @Callee1( )
+ call void @Callee2( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2004-04-20-InlineLinkOnce.ll b/src/LLVM/test/Transforms/Inline/2004-04-20-InlineLinkOnce.ll
new file mode 100644
index 0000000..42e12b5
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2004-04-20-InlineLinkOnce.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -inline -prune-eh -disable-output
+
+define linkonce void @caller() {
+ call void @callee( )
+ ret void
+}
+
+define linkonce void @callee() {
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2004-10-17-InlineFunctionWithoutReturn.ll b/src/LLVM/test/Transforms/Inline/2004-10-17-InlineFunctionWithoutReturn.ll
new file mode 100644
index 0000000..6bb141a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2004-10-17-InlineFunctionWithoutReturn.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -inline -disable-output
+
+define i32 @test() {
+ unreachable
+}
+
+define i32 @caller() {
+ %X = call i32 @test( ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2006-01-14-CallGraphUpdate.ll b/src/LLVM/test/Transforms/Inline/2006-01-14-CallGraphUpdate.ll
new file mode 100644
index 0000000..78cc16a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2006-01-14-CallGraphUpdate.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -inline -prune-eh -disable-output
+
+ %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>" = type { %"struct.std::locale::facet" }
+ %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >" = type { i32 (...)**, i32*, i32*, i32*, i32*, i32*, i32*, %"struct.std::locale" }
+ %"struct.std::ios_base" = type { i32 (...)**, i32, i32, i32, i32, i32, %"struct.std::ios_base::_Callback_list"*, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, %"struct.std::ios_base::_Words"*, %"struct.std::locale" }
+ %"struct.std::ios_base::_Callback_list" = type { %"struct.std::ios_base::_Callback_list"*, void (i32, %"struct.std::ios_base"*, i32)*, i32, i32 }
+ %"struct.std::ios_base::_Words" = type { i8*, i32 }
+ %"struct.std::locale" = type { %"struct.std::locale::_Impl"* }
+ %"struct.std::locale::_Impl" = type { i32, %"struct.std::locale::facet"**, i32, %"struct.std::locale::facet"**, i8** }
+ %"struct.std::locale::facet" = type { i32 (...)**, i32 }
+ %"struct.std::ostreambuf_iterator<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >"*, i32 }
+
+define void @_ZNKSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE6do_putES3_RSt8ios_basewl(%"struct.std::ostreambuf_iterator<wchar_t,std::char_traits<wchar_t> >"* %agg.result, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"* %this, %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >"* %__s.0__, i32 %__s.1__, %"struct.std::ios_base"* %__io, i32 %__fill, i32 %__v) {
+entry:
+ tail call fastcc void @_ZNKSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE13_M_insert_intIlEES3_S3_RSt8ios_basewT_( )
+ ret void
+}
+
+define fastcc void @_ZNKSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE13_M_insert_intIlEES3_S3_RSt8ios_basewT_() {
+entry:
+ %tmp.38 = shl i32 0, 3 ; <i32> [#uses=1]
+ %tmp.39 = alloca i8, i32 %tmp.38 ; <i8*> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2006-07-12-InlinePruneCGUpdate.ll b/src/LLVM/test/Transforms/Inline/2006-07-12-InlinePruneCGUpdate.ll
new file mode 100644
index 0000000..15869cf
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2006-07-12-InlinePruneCGUpdate.ll
@@ -0,0 +1,840 @@
+; RUN: opt < %s -inline -prune-eh -disable-output
+; PR827
+@_ZTV8CRjii = internal global [1 x i32 (...)*] [ i32 (...)* @_ZN8CRjii12NlFeeEPN5Jr7sE ] ; <[1 x i32 (...)*]*> [#uses=0]
+
+define internal i32 @_ZN8CRjii12NlFeeEPN5Jr7sE(...) {
+entry:
+ br i1 false, label %cond_true, label %cond_false179
+
+cond_true: ; preds = %entry
+ br label %bb9
+
+bb: ; preds = %cond_true14
+ br label %bb9
+
+bb9: ; preds = %bb, %cond_true
+ br i1 false, label %cond_true14, label %cond_false
+
+cond_true14: ; preds = %bb9
+ br label %bb
+
+cond_false: ; preds = %bb9
+ br label %bb15
+
+cond_next: ; No predecessors!
+ br label %bb15
+
+bb15: ; preds = %cond_next, %cond_false
+ br label %bb24
+
+bb17: ; preds = %cond_true29
+ br label %bb24
+
+bb24: ; preds = %bb17, %bb15
+ br i1 false, label %cond_true29, label %cond_false30
+
+cond_true29: ; preds = %bb24
+ br label %bb17
+
+cond_false30: ; preds = %bb24
+ br label %bb32
+
+cond_next31: ; No predecessors!
+ br label %bb32
+
+bb32: ; preds = %cond_next31, %cond_false30
+ br label %bb41
+
+bb34: ; preds = %cond_true46
+ br label %bb41
+
+bb41: ; preds = %bb34, %bb32
+ br i1 false, label %cond_true46, label %cond_false47
+
+cond_true46: ; preds = %bb41
+ br label %bb34
+
+cond_false47: ; preds = %bb41
+ br label %bb49
+
+cond_next48: ; No predecessors!
+ br label %bb49
+
+bb49: ; preds = %cond_next48, %cond_false47
+ br label %bb58
+
+bb51: ; preds = %cond_true63
+ br label %bb58
+
+bb58: ; preds = %bb51, %bb49
+ br i1 false, label %cond_true63, label %cond_false64
+
+cond_true63: ; preds = %bb58
+ br label %bb51
+
+cond_false64: ; preds = %bb58
+ br label %bb66
+
+cond_next65: ; No predecessors!
+ br label %bb66
+
+bb66: ; preds = %cond_next65, %cond_false64
+ br label %bb76
+
+bb68: ; preds = %cond_true81
+ br label %bb76
+
+bb76: ; preds = %bb68, %bb66
+ br i1 false, label %cond_true81, label %cond_false82
+
+cond_true81: ; preds = %bb76
+ br label %bb68
+
+cond_false82: ; preds = %bb76
+ br label %bb84
+
+cond_next83: ; No predecessors!
+ br label %bb84
+
+bb84: ; preds = %cond_next83, %cond_false82
+ br label %bb94
+
+bb86: ; preds = %cond_true99
+ br label %bb94
+
+bb94: ; preds = %bb86, %bb84
+ br i1 false, label %cond_true99, label %cond_false100
+
+cond_true99: ; preds = %bb94
+ br label %bb86
+
+cond_false100: ; preds = %bb94
+ br label %bb102
+
+cond_next101: ; No predecessors!
+ br label %bb102
+
+bb102: ; preds = %cond_next101, %cond_false100
+ br label %bb112
+
+bb104: ; preds = %cond_true117
+ br label %bb112
+
+bb112: ; preds = %bb104, %bb102
+ br i1 false, label %cond_true117, label %cond_false118
+
+cond_true117: ; preds = %bb112
+ br label %bb104
+
+cond_false118: ; preds = %bb112
+ br label %bb120
+
+cond_next119: ; No predecessors!
+ br label %bb120
+
+bb120: ; preds = %cond_next119, %cond_false118
+ br label %bb130
+
+bb122: ; preds = %cond_true135
+ br label %bb130
+
+bb130: ; preds = %bb122, %bb120
+ br i1 false, label %cond_true135, label %cond_false136
+
+cond_true135: ; preds = %bb130
+ br label %bb122
+
+cond_false136: ; preds = %bb130
+ br label %bb138
+
+cond_next137: ; No predecessors!
+ br label %bb138
+
+bb138: ; preds = %cond_next137, %cond_false136
+ br label %bb148
+
+bb140: ; preds = %cond_true153
+ call fastcc void @_Zjrf1( )
+ br label %bb148
+
+bb148: ; preds = %bb140, %bb138
+ br i1 false, label %cond_true153, label %cond_false154
+
+cond_true153: ; preds = %bb148
+ br label %bb140
+
+cond_false154: ; preds = %bb148
+ br label %bb156
+
+cond_next155: ; No predecessors!
+ br label %bb156
+
+bb156: ; preds = %cond_next155, %cond_false154
+ br label %bb166
+
+bb158: ; preds = %cond_true171
+ br label %bb166
+
+bb166: ; preds = %bb158, %bb156
+ br i1 false, label %cond_true171, label %cond_false172
+
+cond_true171: ; preds = %bb166
+ br label %bb158
+
+cond_false172: ; preds = %bb166
+ br label %bb174
+
+cond_next173: ; No predecessors!
+ br label %bb174
+
+bb174: ; preds = %cond_next173, %cond_false172
+ br label %cleanup
+
+cleanup: ; preds = %bb174
+ br label %finally
+
+finally: ; preds = %cleanup
+ br label %cond_next180
+
+cond_false179: ; preds = %entry
+ br label %cond_next180
+
+cond_next180: ; preds = %cond_false179, %finally
+ br label %return
+
+return: ; preds = %cond_next180
+ ret i32 0
+}
+
+define internal fastcc void @_Zjrf2() {
+entry:
+ br label %bb3
+
+bb: ; preds = %cond_true
+ br label %bb3
+
+bb3: ; preds = %bb, %entry
+ %tmp5 = load i8** null ; <i8*> [#uses=1]
+ %tmp = icmp ne i8* null, %tmp5 ; <i1> [#uses=1]
+ br i1 %tmp, label %cond_true, label %cond_false
+
+cond_true: ; preds = %bb3
+ br label %bb
+
+cond_false: ; preds = %bb3
+ br label %bb6
+
+cond_next: ; No predecessors!
+ br label %bb6
+
+bb6: ; preds = %cond_next, %cond_false
+ br label %return
+
+return: ; preds = %bb6
+ ret void
+}
+
+define internal fastcc void @_Zjrf3() {
+entry:
+ call fastcc void @_Zjrf2( )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal fastcc void @_Zjrf4() {
+entry:
+ br label %bb6
+
+bb: ; preds = %cond_true
+ br label %bb6
+
+bb6: ; preds = %bb, %entry
+ br i1 false, label %cond_true, label %cond_false
+
+cond_true: ; preds = %bb6
+ br label %bb
+
+cond_false: ; preds = %bb6
+ br label %bb8
+
+cond_next: ; No predecessors!
+ br label %bb8
+
+bb8: ; preds = %cond_next, %cond_false
+ br i1 false, label %cond_true9, label %cond_false12
+
+cond_true9: ; preds = %bb8
+ call fastcc void @_Zjrf3( )
+ br label %cond_next13
+
+cond_false12: ; preds = %bb8
+ br label %cond_next13
+
+cond_next13: ; preds = %cond_false12, %cond_true9
+ br label %return
+
+return: ; preds = %cond_next13
+ ret void
+}
+
+define internal fastcc void @_Zjrf5() {
+entry:
+ call fastcc void @_Zjrf4( )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal fastcc void @_Zjrf6() {
+entry:
+ call fastcc void @_Zjrf5( )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal fastcc void @_Zjrf7() {
+entry:
+ br label %cleanup
+
+cleanup: ; preds = %entry
+ br label %finally
+
+finally: ; preds = %cleanup
+ call fastcc void @_Zjrf6( )
+ br label %cleanup9
+
+cleanup9: ; preds = %finally
+ br label %finally8
+
+finally8: ; preds = %cleanup9
+ br label %cleanup11
+
+cleanup11: ; preds = %finally8
+ br label %finally10
+
+finally10: ; preds = %cleanup11
+ br label %finally23
+
+finally23: ; preds = %finally10
+ br label %return
+
+return: ; preds = %finally23
+ ret void
+}
+
+define internal fastcc void @_Zjrf11() {
+entry:
+ br label %bb7
+
+bb: ; preds = %cond_true
+ br label %bb7
+
+bb7: ; preds = %bb, %entry
+ br i1 false, label %cond_true, label %cond_false
+
+cond_true: ; preds = %bb7
+ br label %bb
+
+cond_false: ; preds = %bb7
+ br label %bb9
+
+cond_next: ; No predecessors!
+ br label %bb9
+
+bb9: ; preds = %cond_next, %cond_false
+ br label %return
+ ; No predecessors!
+ br i1 false, label %cond_true12, label %cond_false15
+
+cond_true12: ; preds = %0
+ call fastcc void @_Zjrf3( )
+ br label %cond_next16
+
+cond_false15: ; preds = %0
+ br label %cond_next16
+
+cond_next16: ; preds = %cond_false15, %cond_true12
+ br label %return
+
+return: ; preds = %cond_next16, %bb9
+ ret void
+}
+
+define internal fastcc void @_Zjrf9() {
+entry:
+ call fastcc void @_Zjrf11( )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal fastcc void @_Zjrf10() {
+entry:
+ call fastcc void @_Zjrf9( )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define internal fastcc void @_Zjrf8() {
+entry:
+ br i1 false, label %cond_true, label %cond_false201
+
+cond_true: ; preds = %entry
+ br i1 false, label %cond_true36, label %cond_false
+
+cond_true36: ; preds = %cond_true
+ br label %cleanup
+
+cleanup: ; preds = %cond_true36
+ br label %finally
+
+finally: ; preds = %cleanup
+ br label %cond_next189
+
+cond_false: ; preds = %cond_true
+ br i1 false, label %cond_true99, label %cond_false137
+
+cond_true99: ; preds = %cond_false
+ br label %cleanup136
+
+cleanup136: ; preds = %cond_true99
+ br label %finally135
+
+finally135: ; preds = %cleanup136
+ br label %cond_next
+
+cond_false137: ; preds = %cond_false
+ call fastcc void @_Zjrf10( )
+ br label %cleanup188
+
+cleanup188: ; preds = %cond_false137
+ br label %finally187
+
+finally187: ; preds = %cleanup188
+ br label %cond_next
+
+cond_next: ; preds = %finally187, %finally135
+ br label %cond_next189
+
+cond_next189: ; preds = %cond_next, %finally
+ br label %cond_next202
+
+cond_false201: ; preds = %entry
+ br label %cond_next202
+
+cond_next202: ; preds = %cond_false201, %cond_next189
+ br label %return
+
+return: ; preds = %cond_next202
+ ret void
+}
+
+define internal fastcc void @_Zjrf1() {
+entry:
+ br label %bb492
+
+bb: ; preds = %cond_true499
+ br label %cleanup
+
+cleanup: ; preds = %bb
+ br label %finally
+
+finally: ; preds = %cleanup
+ br label %cleanup11
+
+cleanup11: ; preds = %finally
+ br label %finally10
+
+finally10: ; preds = %cleanup11
+ br i1 false, label %cond_true, label %cond_false286
+
+cond_true: ; preds = %finally10
+ br label %cleanup26
+
+cleanup26: ; preds = %cond_true
+ br label %finally25
+
+finally25: ; preds = %cleanup26
+ br label %bb30
+
+bb27: ; preds = %cond_true37
+ br label %bb30
+
+bb30: ; preds = %bb27, %finally25
+ br i1 false, label %cond_true37, label %cond_false
+
+cond_true37: ; preds = %bb30
+ br label %bb27
+
+cond_false: ; preds = %bb30
+ br label %bb38
+
+cond_next: ; No predecessors!
+ br label %bb38
+
+bb38: ; preds = %cond_next, %cond_false
+ br label %bb148
+
+bb40: ; preds = %cond_true156
+ br label %bb139
+
+bb41: ; preds = %cond_true142
+ call fastcc void @_Zjrf7( )
+ br label %bb105
+
+bb44: ; preds = %cond_true112
+ br label %bb74
+
+bb66: ; preds = %cond_true80
+ br label %bb74
+
+bb74: ; preds = %bb66, %bb44
+ br i1 false, label %cond_true80, label %cond_false81
+
+cond_true80: ; preds = %bb74
+ br label %bb66
+
+cond_false81: ; preds = %bb74
+ br label %bb83
+
+cond_next82: ; No predecessors!
+ br label %bb83
+
+bb83: ; preds = %cond_next82, %cond_false81
+ br label %cleanup97
+
+cleanup97: ; preds = %bb83
+ br label %finally96
+
+finally96: ; preds = %cleanup97
+ br label %cleanup99
+
+cleanup99: ; preds = %finally96
+ br label %finally98
+
+finally98: ; preds = %cleanup99
+ br label %bb105
+
+bb105: ; preds = %finally98, %bb41
+ br i1 false, label %cond_true112, label %cond_false113
+
+cond_true112: ; preds = %bb105
+ br label %bb44
+
+cond_false113: ; preds = %bb105
+ br label %bb115
+
+cond_next114: ; No predecessors!
+ br label %bb115
+
+bb115: ; preds = %cond_next114, %cond_false113
+ br i1 false, label %cond_true119, label %cond_false123
+
+cond_true119: ; preds = %bb115
+ call fastcc void @_Zjrf8( )
+ br label %cond_next124
+
+cond_false123: ; preds = %bb115
+ br label %cond_next124
+
+cond_next124: ; preds = %cond_false123, %cond_true119
+ br i1 false, label %cond_true131, label %cond_false132
+
+cond_true131: ; preds = %cond_next124
+ br label %cleanup135
+
+cond_false132: ; preds = %cond_next124
+ br label %cond_next133
+
+cond_next133: ; preds = %cond_false132
+ br label %cleanup136
+
+cleanup135: ; preds = %cond_true131
+ br label %done
+
+cleanup136: ; preds = %cond_next133
+ br label %finally134
+
+finally134: ; preds = %cleanup136
+ br label %bb139
+
+bb139: ; preds = %finally134, %bb40
+ br i1 false, label %cond_true142, label %cond_false143
+
+cond_true142: ; preds = %bb139
+ br label %bb41
+
+cond_false143: ; preds = %bb139
+ br label %bb145
+
+cond_next144: ; No predecessors!
+ br label %bb145
+
+bb145: ; preds = %cond_next144, %cond_false143
+ br label %bb148
+
+bb148: ; preds = %bb145, %bb38
+ br i1 false, label %cond_true156, label %cond_false157
+
+cond_true156: ; preds = %bb148
+ br label %bb40
+
+cond_false157: ; preds = %bb148
+ br label %bb159
+
+cond_next158: ; No predecessors!
+ br label %bb159
+
+bb159: ; preds = %cond_next158, %cond_false157
+ br label %done
+
+done: ; preds = %bb159, %cleanup135
+ br label %bb214
+
+bb185: ; preds = %cond_true218
+ br i1 false, label %cond_true193, label %cond_false206
+
+cond_true193: ; preds = %bb185
+ br label %cond_next211
+
+cond_false206: ; preds = %bb185
+ br label %cond_next211
+
+cond_next211: ; preds = %cond_false206, %cond_true193
+ br label %bb214
+
+bb214: ; preds = %cond_next211, %done
+ br i1 false, label %cond_true218, label %cond_false219
+
+cond_true218: ; preds = %bb214
+ br label %bb185
+
+cond_false219: ; preds = %bb214
+ br label %bb221
+
+cond_next220: ; No predecessors!
+ br label %bb221
+
+bb221: ; preds = %cond_next220, %cond_false219
+ br i1 false, label %cond_true236, label %cond_false245
+
+cond_true236: ; preds = %bb221
+ br label %cond_next249
+
+cond_false245: ; preds = %bb221
+ br label %cond_next249
+
+cond_next249: ; preds = %cond_false245, %cond_true236
+ br i1 false, label %cond_true272, label %cond_false277
+
+cond_true272: ; preds = %cond_next249
+ br label %cond_next278
+
+cond_false277: ; preds = %cond_next249
+ br label %cond_next278
+
+cond_next278: ; preds = %cond_false277, %cond_true272
+ br label %cleanup285
+
+cleanup285: ; preds = %cond_next278
+ br label %finally284
+
+finally284: ; preds = %cleanup285
+ br label %cond_next287
+
+cond_false286: ; preds = %finally10
+ br label %cond_next287
+
+cond_next287: ; preds = %cond_false286, %finally284
+ br i1 false, label %cond_true317, label %cond_false319
+
+cond_true317: ; preds = %cond_next287
+ br label %cond_next321
+
+cond_false319: ; preds = %cond_next287
+ br label %cond_next321
+
+cond_next321: ; preds = %cond_false319, %cond_true317
+ br label %bb348
+
+bb335: ; preds = %cond_true355
+ br label %bb348
+
+bb348: ; preds = %bb335, %cond_next321
+ br i1 false, label %cond_true355, label %cond_false356
+
+cond_true355: ; preds = %bb348
+ br label %bb335
+
+cond_false356: ; preds = %bb348
+ br label %bb358
+
+cond_next357: ; No predecessors!
+ br label %bb358
+
+bb358: ; preds = %cond_next357, %cond_false356
+ br i1 false, label %cond_true363, label %cond_false364
+
+cond_true363: ; preds = %bb358
+ br label %bb388
+
+cond_false364: ; preds = %bb358
+ br label %cond_next365
+
+cond_next365: ; preds = %cond_false364
+ br i1 false, label %cond_true370, label %cond_false371
+
+cond_true370: ; preds = %cond_next365
+ br label %bb388
+
+cond_false371: ; preds = %cond_next365
+ br label %cond_next372
+
+cond_next372: ; preds = %cond_false371
+ br i1 false, label %cond_true385, label %cond_false386
+
+cond_true385: ; preds = %cond_next372
+ br label %bb388
+
+cond_false386: ; preds = %cond_next372
+ br label %cond_next387
+
+cond_next387: ; preds = %cond_false386
+ br label %bb389
+
+bb388: ; preds = %cond_true385, %cond_true370, %cond_true363
+ br label %bb389
+
+bb389: ; preds = %bb388, %cond_next387
+ br i1 false, label %cond_true392, label %cond_false443
+
+cond_true392: ; preds = %bb389
+ br label %bb419
+
+bb402: ; preds = %cond_true425
+ br i1 false, label %cond_true406, label %cond_false412
+
+cond_true406: ; preds = %bb402
+ br label %cond_next416
+
+cond_false412: ; preds = %bb402
+ br label %cond_next416
+
+cond_next416: ; preds = %cond_false412, %cond_true406
+ br label %bb419
+
+bb419: ; preds = %cond_next416, %cond_true392
+ br i1 false, label %cond_true425, label %cond_false426
+
+cond_true425: ; preds = %bb419
+ br label %bb402
+
+cond_false426: ; preds = %bb419
+ br label %bb428
+
+cond_next427: ; No predecessors!
+ br label %bb428
+
+bb428: ; preds = %cond_next427, %cond_false426
+ br label %cond_next478
+
+cond_false443: ; preds = %bb389
+ br label %bb460
+
+bb450: ; preds = %cond_true466
+ br label %bb460
+
+bb460: ; preds = %bb450, %cond_false443
+ br i1 false, label %cond_true466, label %cond_false467
+
+cond_true466: ; preds = %bb460
+ br label %bb450
+
+cond_false467: ; preds = %bb460
+ br label %bb469
+
+cond_next468: ; No predecessors!
+ br label %bb469
+
+bb469: ; preds = %cond_next468, %cond_false467
+ br label %cond_next478
+
+cond_next478: ; preds = %bb469, %bb428
+ br label %cleanup485
+
+cleanup485: ; preds = %cond_next478
+ br label %finally484
+
+finally484: ; preds = %cleanup485
+ br label %cleanup487
+
+cleanup487: ; preds = %finally484
+ br label %finally486
+
+finally486: ; preds = %cleanup487
+ br label %cleanup489
+
+cleanup489: ; preds = %finally486
+ br label %finally488
+
+finally488: ; preds = %cleanup489
+ br label %bb492
+
+bb492: ; preds = %finally488, %entry
+ br i1 false, label %cond_true499, label %cond_false500
+
+cond_true499: ; preds = %bb492
+ br label %bb
+
+cond_false500: ; preds = %bb492
+ br label %bb502
+
+cond_next501: ; No predecessors!
+ br label %bb502
+
+bb502: ; preds = %cond_next501, %cond_false500
+ br label %return
+
+return: ; preds = %bb502
+ ret void
+}
+
+define internal fastcc void @_ZSt26__unguarded_insertion_sortIN9__gnu_cxx17__normal_iteratorIPSsSt6vectorISsSaISsEEEEEvT_S7_() {
+entry:
+ br label %bb12
+
+bb: ; preds = %cond_true
+ br label %cleanup
+
+cleanup: ; preds = %bb
+ br label %finally
+
+finally: ; preds = %cleanup
+ br label %bb12
+
+bb12: ; preds = %finally, %entry
+ br i1 false, label %cond_true, label %cond_false
+
+cond_true: ; preds = %bb12
+ br label %bb
+
+cond_false: ; preds = %bb12
+ br label %bb14
+
+cond_next: ; No predecessors!
+ br label %bb14
+
+bb14: ; preds = %cond_next, %cond_false
+ br label %return
+
+return: ; preds = %bb14
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate-2.ll b/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate-2.ll
new file mode 100644
index 0000000..a74eb65
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate-2.ll
@@ -0,0 +1,253 @@
+; RUN: opt < %s -inline -prune-eh -disable-output
+; PR993
+target datalayout = "e-p:32:32"
+target triple = "i386-unknown-openbsd3.9"
+deplibs = [ "stdc++", "c", "crtend" ]
+ %"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" = type { i8* }
+ %"struct.__gnu_cxx::char_producer<char>" = type { i32 (...)** }
+ %struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, i8*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+ %struct.__sbuf = type { i8*, i32 }
+ %"struct.std::__basic_file<char>" = type { %struct.__sFILE*, i1 }
+ %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>" = type { %"struct.std::locale::facet" }
+ %"struct.std::bad_alloc" = type { %"struct.__gnu_cxx::char_producer<char>" }
+ %"struct.std::basic_filebuf<char,std::char_traits<char> >" = type { %"struct.std::basic_streambuf<char,std::char_traits<char> >", i32, %"struct.std::__basic_file<char>", i32, %union.__mbstate_t, %union.__mbstate_t, i8*, i32, i1, i1, i1, i1, i8, i8*, i8*, i1, %"struct.std::codecvt<char,char,__mbstate_t>"*, i8*, i32, i8*, i8* }
+ %"struct.std::basic_ios<char,std::char_traits<char> >" = type { %"struct.std::ios_base", %"struct.std::basic_ostream<char,std::char_traits<char> >"*, i8, i1, %"struct.std::basic_streambuf<char,std::char_traits<char> >"*, %"struct.std::ctype<char>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"* }
+ %"struct.std::basic_iostream<char,std::char_traits<char> >" = type { %"struct.std::locale::facet", %"struct.__gnu_cxx::char_producer<char>", %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_ofstream<char,std::char_traits<char> >" = type { %"struct.__gnu_cxx::char_producer<char>", %"struct.std::basic_filebuf<char,std::char_traits<char> >", %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_ostream<char,std::char_traits<char> >" = type { i32 (...)**, %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_streambuf<char,std::char_traits<char> >" = type { i32 (...)**, i8*, i8*, i8*, i8*, i8*, i8*, %"struct.std::locale" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" = type { %"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep" = type { %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" = type { i32, i32, i32 }
+ %"struct.std::codecvt<char,char,__mbstate_t>" = type { %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>", i32* }
+ %"struct.std::ctype<char>" = type { %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>", i32*, i1, i32*, i32*, i32* }
+ %"struct.std::domain_error" = type { %"struct.std::logic_error" }
+ %"struct.std::ios_base" = type { i32 (...)**, i32, i32, i32, i32, i32, %"struct.std::ios_base::_Callback_list"*, %struct.__sbuf, [8 x %struct.__sbuf], i32, %struct.__sbuf*, %"struct.std::locale" }
+ %"struct.std::ios_base::_Callback_list" = type { %"struct.std::ios_base::_Callback_list"*, void (i32, %"struct.std::ios_base"*, i32)*, i32, i32 }
+ %"struct.std::ios_base::_Words" = type { i8*, i32 }
+ %"struct.std::locale" = type { %"struct.std::locale::_Impl"* }
+ %"struct.std::locale::_Impl" = type { i32, %"struct.std::locale::facet"**, i32, %"struct.std::locale::facet"**, i8** }
+ %"struct.std::locale::facet" = type { i32 (...)**, i32 }
+ %"struct.std::logic_error" = type { %"struct.__gnu_cxx::char_producer<char>", %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" }
+ %union.__mbstate_t = type { i64, [120 x i8] }
+@.str_1 = external global [17 x i8] ; <[17 x i8]*> [#uses=0]
+@.str_9 = external global [24 x i8] ; <[24 x i8]*> [#uses=0]
+
+define void @main() {
+entry:
+ call fastcc void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode( )
+ ret void
+}
+
+define fastcc void @_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode() {
+entry:
+ %tmp.6 = icmp eq %"struct.std::basic_filebuf<char,std::char_traits<char> >"* null, null ; <i1> [#uses=1]
+ br i1 %tmp.6, label %then, label %UnifiedReturnBlock
+
+then: ; preds = %entry
+ tail call fastcc void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate( )
+ ret void
+
+UnifiedReturnBlock: ; preds = %entry
+ ret void
+}
+
+define fastcc void @_ZN10__cxxabiv111__terminateEPFvvE() {
+entry:
+ unreachable
+}
+
+define void @_ZNSdD0Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZThn8_NSdD1Ev() {
+entry:
+ ret void
+}
+
+define void @_ZNSt13basic_filebufIcSt11char_traitsIcEED0Ev() {
+entry:
+ ret void
+}
+
+define void @_ZNSt13basic_filebufIcSt11char_traitsIcEE9pbackfailEi() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSoD2Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt9basic_iosIcSt11char_traitsIcEED2Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate() {
+entry:
+ tail call fastcc void @_ZSt19__throw_ios_failurePKc( )
+ ret void
+}
+
+declare fastcc void @_ZNSaIcED1Ev()
+
+define fastcc void @_ZNSsC1EPKcRKSaIcE() {
+entry:
+ tail call fastcc void @_ZNSs16_S_construct_auxIPKcEEPcT_S3_RKSaIcE12__false_type( )
+ unreachable
+}
+
+define fastcc void @_ZSt14__convert_to_vIyEvPKcRT_RSt12_Ios_IostateRKPii() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEEC1Ej() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZSt19__throw_ios_failurePKc() {
+entry:
+ call fastcc void @_ZNSsC1EPKcRKSaIcE( )
+ unreachable
+}
+
+define void @_GLOBAL__D__ZSt23lexicographical_compareIPKaS1_EbT_S2_T0_S3_() {
+entry:
+ ret void
+}
+
+define void @_ZNSt9bad_allocD1Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZSt19__throw_logic_errorPKc() {
+entry:
+ invoke fastcc void @_ZNSt11logic_errorC1ERKSs( )
+ to label %try_exit.0 unwind label %try_catch.0
+
+try_catch.0: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ resume { i8*, i32 } %exn
+
+try_exit.0: ; preds = %entry
+ unreachable
+}
+
+define fastcc void @_ZNSt11logic_errorC1ERKSs() {
+entry:
+ call fastcc void @_ZNSsC1ERKSs( )
+ ret void
+}
+
+define void @_ZNSt12domain_errorD1Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZSt20__throw_length_errorPKc() {
+entry:
+ call fastcc void @_ZNSt12length_errorC1ERKSs( )
+ unreachable
+}
+
+define fastcc void @_ZNSt12length_errorC1ERKSs() {
+entry:
+ invoke fastcc void @_ZNSsC1ERKSs( )
+ to label %_ZNSt11logic_errorC2ERKSs.exit unwind label %invoke_catch.i
+
+invoke_catch.i: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ resume { i8*, i32 } %exn
+
+_ZNSt11logic_errorC2ERKSs.exit: ; preds = %entry
+ ret void
+}
+
+define fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE() {
+entry:
+ call fastcc void @_ZSt20__throw_length_errorPKc( )
+ unreachable
+}
+
+define fastcc void @_ZNSs12_S_constructIN9__gnu_cxx17__normal_iteratorIPcSsEEEES2_T_S4_RKSaIcESt20forward_iterator_tag() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSs16_S_construct_auxIPKcEEPcT_S3_RKSaIcE12__false_type() {
+entry:
+ br i1 false, label %then.1.i, label %endif.1.i
+
+then.1.i: ; preds = %entry
+ call fastcc void @_ZSt19__throw_logic_errorPKc( )
+ br label %endif.1.i
+
+endif.1.i: ; preds = %then.1.i, %entry
+ call fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE( )
+ unreachable
+}
+
+define fastcc void @_ZNSsC1ERKSs() {
+entry:
+ call fastcc void @_ZNSs4_Rep7_M_grabERKSaIcES2_( )
+ invoke fastcc void @_ZNSaIcEC1ERKS_( )
+ to label %invoke_cont.1 unwind label %invoke_catch.1
+
+invoke_catch.1: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ call fastcc void @_ZNSaIcED1Ev( )
+ resume { i8*, i32 } %exn
+
+invoke_cont.1: ; preds = %entry
+ call fastcc void @_ZNSaIcEC2ERKS_( )
+ ret void
+}
+
+define fastcc void @_ZNSaIcEC1ERKS_() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSs7replaceEN9__gnu_cxx17__normal_iteratorIPcSsEES2_jc() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSs4_Rep7_M_grabERKSaIcES2_() {
+entry:
+ br i1 false, label %else.i, label %cond_true
+
+cond_true: ; preds = %entry
+ ret void
+
+else.i: ; preds = %entry
+ tail call fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE( )
+ unreachable
+}
+
+define fastcc void @_ZNSaIcEC2ERKS_() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZN9__gnu_cxx12__pool_allocILb1ELi0EE8allocateEj() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZN9__gnu_cxx12__pool_allocILb1ELi0EE9_S_refillEj() {
+entry:
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate.ll b/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate.ll
new file mode 100644
index 0000000..139632a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2006-11-09-InlineCGUpdate.ll
@@ -0,0 +1,344 @@
+; RUN: opt < %s -inline -prune-eh -disable-output
+; PR992
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+deplibs = [ "stdc++", "c", "crtend" ]
+ %struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i32, [52 x i8] }
+ %struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
+ %"struct.__cxxabiv1::__array_type_info" = type { %"struct.std::type_info" }
+ %"struct.__cxxabiv1::__si_class_type_info" = type { %"struct.__cxxabiv1::__array_type_info", %"struct.__cxxabiv1::__array_type_info"* }
+ %"struct.__gnu_cxx::_Rope_rep_alloc_base<char,std::allocator<char>, true>" = type { i32 }
+ %"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" = type { i8* }
+ %"struct.__gnu_cxx::__normal_iterator<const wchar_t*,std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >" = type { i32* }
+ %"struct.__gnu_cxx::char_producer<char>" = type { i32 (...)** }
+ %"struct.__gnu_cxx::stdio_sync_filebuf<char,std::char_traits<char> >" = type { %"struct.std::basic_streambuf<char,std::char_traits<char> >", %struct._IO_FILE*, i32 }
+ %"struct.__gnu_cxx::stdio_sync_filebuf<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >", %struct._IO_FILE*, i32 }
+ %struct.__locale_struct = type { [13 x %struct.locale_data*], i16*, i32*, i32*, [13 x i8*] }
+ %struct.__mbstate_t = type { i32, %"struct.__gnu_cxx::_Rope_rep_alloc_base<char,std::allocator<char>, true>" }
+ %struct.locale_data = type opaque
+ %"struct.std::__basic_file<char>" = type { %struct._IO_FILE*, i1 }
+ %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>" = type { %"struct.std::locale::facet" }
+ %"struct.std::basic_filebuf<char,std::char_traits<char> >" = type { %"struct.std::basic_streambuf<char,std::char_traits<char> >", i32, %"struct.std::__basic_file<char>", i32, %struct.__mbstate_t, %struct.__mbstate_t, i8*, i32, i1, i1, i1, i1, i8, i8*, i8*, i1, %"struct.std::codecvt<char,char,__mbstate_t>"*, i8*, i32, i8*, i8* }
+ %"struct.std::basic_filebuf<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >", i32, %"struct.std::__basic_file<char>", i32, %struct.__mbstate_t, %struct.__mbstate_t, i32*, i32, i1, i1, i1, i1, i32, i32*, i32*, i1, %"struct.std::codecvt<char,char,__mbstate_t>"*, i8*, i32, i8*, i8* }
+ %"struct.std::basic_fstream<char,std::char_traits<char> >" = type { { %"struct.std::locale::facet", %"struct.__gnu_cxx::char_producer<char>" }, %"struct.std::basic_filebuf<char,std::char_traits<char> >", %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_fstream<wchar_t,std::char_traits<wchar_t> >" = type { { %"struct.std::locale::facet", %"struct.__gnu_cxx::char_producer<char>" }, %"struct.std::basic_filebuf<wchar_t,std::char_traits<wchar_t> >", %"struct.std::basic_ios<wchar_t,std::char_traits<wchar_t> >" }
+ %"struct.std::basic_ios<char,std::char_traits<char> >" = type { %"struct.std::ios_base", %"struct.std::basic_ostream<char,std::char_traits<char> >"*, i8, i1, %"struct.std::basic_streambuf<char,std::char_traits<char> >"*, %"struct.std::ctype<char>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"* }
+ %"struct.std::basic_ios<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::ios_base", %"struct.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >"*, i32, i1, %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >"*, %"struct.std::codecvt<char,char,__mbstate_t>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"*, %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>"* }
+ %"struct.std::basic_iostream<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::locale::facet", %"struct.__gnu_cxx::char_producer<char>", %"struct.std::basic_ios<wchar_t,std::char_traits<wchar_t> >" }
+ %"struct.std::basic_ostream<char,std::char_traits<char> >" = type { i32 (...)**, %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_ostream<wchar_t,std::char_traits<wchar_t> >" = type { i32 (...)**, %"struct.std::basic_ios<wchar_t,std::char_traits<wchar_t> >" }
+ %"struct.std::basic_streambuf<char,std::char_traits<char> >" = type { i32 (...)**, i8*, i8*, i8*, i8*, i8*, i8*, %"struct.std::locale" }
+ %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >" = type { i32 (...)**, i32*, i32*, i32*, i32*, i32*, i32*, %"struct.std::locale" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" = type { %"struct.__gnu_cxx::__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep" = type { %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" }
+ %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Rep_base" = type { i32, i32, i32 }
+ %"struct.std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >" = type { %"struct.__gnu_cxx::__normal_iterator<const wchar_t*,std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >" }
+ %"struct.std::codecvt<char,char,__mbstate_t>" = type { %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>", %struct.__locale_struct* }
+ %"struct.std::collate<char>" = type { %"struct.std::locale::facet", %struct.__locale_struct* }
+ %"struct.std::collate_byname<char>" = type { %"struct.std::collate<char>" }
+ %"struct.std::ctype<char>" = type { %"struct.std::__codecvt_abstract_base<char,char,__mbstate_t>", %struct.__locale_struct*, i1, i32*, i32*, i16* }
+ %"struct.std::ctype_byname<char>" = type { %"struct.std::ctype<char>" }
+ %"struct.std::domain_error" = type { %"struct.std::logic_error" }
+ %"struct.std::ios_base" = type { i32 (...)**, i32, i32, i32, i32, i32, %"struct.std::ios_base::_Callback_list"*, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, %"struct.std::ios_base::_Words"*, %"struct.std::locale" }
+ %"struct.std::ios_base::_Callback_list" = type { %"struct.std::ios_base::_Callback_list"*, void (i32, %"struct.std::ios_base"*, i32)*, i32, i32 }
+ %"struct.std::ios_base::_Words" = type { i8*, i32 }
+ %"struct.std::istreambuf_iterator<char,std::char_traits<char> >" = type { %"struct.std::basic_streambuf<char,std::char_traits<char> >"*, i32 }
+ %"struct.std::istreambuf_iterator<wchar_t,std::char_traits<wchar_t> >" = type { %"struct.std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >"*, i32 }
+ %"struct.std::locale" = type { %"struct.std::locale::_Impl"* }
+ %"struct.std::locale::_Impl" = type { i32, %"struct.std::locale::facet"**, i32, %"struct.std::locale::facet"**, i8** }
+ %"struct.std::locale::facet" = type { i32 (...)**, i32 }
+ %"struct.std::logic_error" = type { %"struct.__gnu_cxx::char_producer<char>", %"struct.std::basic_string<char,std::char_traits<char>,std::allocator<char> >" }
+ %"struct.std::type_info" = type { i32 (...)**, i8* }
+@.str_11 = external global [42 x i8] ; <[42 x i8]*> [#uses=0]
+@.str_9 = external global [24 x i8] ; <[24 x i8]*> [#uses=0]
+@.str_1 = external global [17 x i8] ; <[17 x i8]*> [#uses=0]
+
+define void @main() {
+entry:
+ tail call fastcc void @_ZNSolsEi( )
+ ret void
+}
+
+define fastcc void @_ZNSolsEi() {
+entry:
+ %tmp.22 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.22, label %else, label %then
+
+then: ; preds = %entry
+ ret void
+
+else: ; preds = %entry
+ tail call fastcc void @_ZNSolsEl( )
+ ret void
+}
+
+define void @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate() {
+entry:
+ tail call fastcc void @_ZSt19__throw_ios_failurePKc( )
+ ret void
+}
+
+define fastcc void @_ZNSo3putEc() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSolsEl() {
+entry:
+ %tmp.21.i = icmp eq %"struct.std::basic_ostream<char,std::char_traits<char> >"* null, null ; <i1> [#uses=1]
+ br i1 %tmp.21.i, label %endif.0.i, label %shortcirc_next.i
+
+shortcirc_next.i: ; preds = %entry
+ ret void
+
+endif.0.i: ; preds = %entry
+ call fastcc void @_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate( )
+ ret void
+}
+
+define fastcc void @_ZSt19__throw_ios_failurePKc() {
+entry:
+ call fastcc void @_ZNSsC1EPKcRKSaIcE( )
+ ret void
+}
+
+define fastcc void @_ZNSt8ios_baseD2Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZN9__gnu_cxx18stdio_sync_filebufIwSt11char_traitsIwEE5uflowEv() {
+entry:
+ unreachable
+}
+
+define void @_ZN9__gnu_cxx18stdio_sync_filebufIcSt11char_traitsIcEED1Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZNSt15basic_streambufIcSt11char_traitsIcEE6setbufEPci() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZSt9use_facetISt5ctypeIcEERKT_RKSt6locale() {
+entry:
+ ret void
+}
+
+declare fastcc void @_ZNSaIcED1Ev()
+
+define fastcc void @_ZSt19__throw_logic_errorPKc() {
+entry:
+ call fastcc void @_ZNSt11logic_errorC1ERKSs( )
+ ret void
+}
+
+define fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE() {
+entry:
+ br i1 false, label %then.0, label %endif.0
+
+then.0: ; preds = %entry
+ call fastcc void @_ZSt20__throw_length_errorPKc( )
+ ret void
+
+endif.0: ; preds = %entry
+ ret void
+}
+
+define fastcc void @_ZSt20__throw_length_errorPKc() {
+entry:
+ call fastcc void @_ZNSt12length_errorC1ERKSs( )
+ ret void
+}
+
+define fastcc void @_ZNSs16_S_construct_auxIPKcEEPcT_S3_RKSaIcE12__false_type() {
+entry:
+ br i1 false, label %then.1.i, label %endif.1.i
+
+then.1.i: ; preds = %entry
+ call fastcc void @_ZSt19__throw_logic_errorPKc( )
+ ret void
+
+endif.1.i: ; preds = %entry
+ call fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE( )
+ unreachable
+}
+
+define fastcc void @_ZNSsC1ERKSs() {
+entry:
+ call fastcc void @_ZNSs4_Rep7_M_grabERKSaIcES2_( )
+ invoke fastcc void @_ZNSaIcEC1ERKS_( )
+ to label %invoke_cont.1 unwind label %invoke_catch.1
+
+invoke_catch.1: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ call fastcc void @_ZNSaIcED1Ev( )
+ resume { i8*, i32 } %exn
+
+invoke_cont.1: ; preds = %entry
+ call fastcc void @_ZNSaIcEC2ERKS_( )
+ ret void
+}
+
+define fastcc void @_ZNSs7reserveEj() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSaIcEC1ERKS_() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSs4_Rep7_M_grabERKSaIcES2_() {
+entry:
+ br i1 false, label %else.i, label %cond_true
+
+cond_true: ; preds = %entry
+ ret void
+
+else.i: ; preds = %entry
+ tail call fastcc void @_ZNSs4_Rep9_S_createEjRKSaIcE( )
+ ret void
+}
+
+define fastcc void @_ZNSsC1EPKcRKSaIcE() {
+entry:
+ tail call fastcc void @_ZNSs16_S_construct_auxIPKcEEPcT_S3_RKSaIcE12__false_type( )
+ unreachable
+}
+
+define fastcc void @_ZNSaIcEC2ERKS_() {
+entry:
+ ret void
+}
+
+define void @_ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEED1Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZNSt14collate_bynameIcED1Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZNKSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE6do_getES3_S3_RSt8ios_baseRSt12_Ios_IostateRy() {
+entry:
+ ret void
+}
+
+define void @_ZNSt23__codecvt_abstract_baseIcc11__mbstate_tED1Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZNSt12ctype_bynameIcED0Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt8messagesIwEC1Ej() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZSt14__convert_to_vIlEvPKcRT_RSt12_Ios_IostateRKP15__locale_structi() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSt8time_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEEC1Ej() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEEC1Ej() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNKSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE16_M_extract_floatES3_S3_RSt8ios_baseRSt12_Ios_IostateRSs() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSbIwSt11char_traitsIwESaIwEE4swapERS2_() {
+entry:
+ ret void
+}
+
+define void @_ZNSt14basic_iostreamIwSt11char_traitsIwEED0Ev() {
+entry:
+ unreachable
+}
+
+define void @_ZNSt15basic_streambufIcSt11char_traitsIcEE9showmanycEv() {
+entry:
+ ret void
+}
+
+define void @_ZNSt9exceptionD0Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt11logic_errorC1ERKSs() {
+entry:
+ call fastcc void @_ZNSsC1ERKSs( )
+ ret void
+}
+
+define fastcc void @_ZNSt11logic_errorD2Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt12length_errorC1ERKSs() {
+entry:
+ invoke fastcc void @_ZNSsC1ERKSs( )
+ to label %_ZNSt11logic_errorC2ERKSs.exit unwind label %invoke_catch.i
+
+invoke_catch.i: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ resume { i8*, i32 } %exn
+
+_ZNSt11logic_errorC2ERKSs.exit: ; preds = %entry
+ ret void
+}
+
+define void @_ZNK10__cxxabiv120__si_class_type_info20__do_find_public_srcEiPKvPKNS_17__class_type_infoES2_() {
+entry:
+ ret void
+}
+
+define fastcc void @_ZNSbIwSt11char_traitsIwESaIwEE16_S_construct_auxIPKwEEPwT_S7_RKS1_12__false_type() {
+entry:
+ ret void
+}
+
+define void @_ZTv0_n12_NSt13basic_fstreamIwSt11char_traitsIwEED1Ev() {
+entry:
+ ret void
+}
+
+define void @_ZNSt13basic_fstreamIcSt11char_traitsIcEED1Ev() {
+entry:
+ unreachable
+}
+
+define fastcc void @_ZNSt5ctypeIcEC1EPKtbj() {
+entry:
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/2007-04-15-InlineEH.ll b/src/LLVM/test/Transforms/Inline/2007-04-15-InlineEH.ll
new file mode 100644
index 0000000..01ff746
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2007-04-15-InlineEH.ll
@@ -0,0 +1,53 @@
+; RUN: opt < %s -inline -S | not grep {invoke void asm}
+; PR1335
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+ %struct.gnat__strings__string_access = type { i8*, %struct.string___XUB* }
+ %struct.string___XUB = type { i32, i32 }
+
+define void @bc__support__high_resolution_time__clock() {
+entry:
+ call void asm "rdtsc\0A\09movl %eax, $0\0A\09movl %edx, $1", "=*imr,=*imr,~{dirflag},~{fpsr},~{flags},~{dx},~{ax}"( i32* null, i32* null ) nounwind
+ unreachable
+}
+
+define fastcc void @bc__support__high_resolution_time__initialize_clock_rate() {
+entry:
+ invoke void @gnat__os_lib__getenv( %struct.gnat__strings__string_access* null )
+ to label %invcont unwind label %cleanup144
+
+invcont: ; preds = %entry
+ invoke void @ada__calendar__delays__delay_for( )
+ to label %invcont64 unwind label %cleanup144
+
+invcont64: ; preds = %invcont
+ invoke void @ada__calendar__clock( )
+ to label %invcont65 unwind label %cleanup144
+
+invcont65: ; preds = %invcont64
+ invoke void @bc__support__high_resolution_time__clock( )
+ to label %invcont67 unwind label %cleanup144
+
+invcont67: ; preds = %invcont65
+ ret void
+
+cleanup144: ; preds = %invcont65, %invcont64, %invcont, %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %exn
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @gnat__os_lib__getenv(%struct.gnat__strings__string_access*)
+
+declare void @ada__calendar__delays__delay_for()
+
+declare void @ada__calendar__clock()
+
+define void @bc__support__high_resolution_time___elabb() {
+entry:
+ call fastcc void @bc__support__high_resolution_time__initialize_clock_rate( )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/2007-06-06-NoInline.ll b/src/LLVM/test/Transforms/Inline/2007-06-06-NoInline.ll
new file mode 100644
index 0000000..bbfd7e0
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2007-06-06-NoInline.ll
@@ -0,0 +1,46 @@
+; RUN: opt < %s -inline -S | grep "define internal i32 @bar"
+@llvm.noinline = appending global [1 x i8*] [ i8* bitcast (i32 (i32, i32)* @bar to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
+
+define internal i32 @bar(i32 %x, i32 %y) {
+entry:
+ %x_addr = alloca i32 ; <i32*> [#uses=2]
+ %y_addr = alloca i32 ; <i32*> [#uses=2]
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %x, i32* %x_addr
+ store i32 %y, i32* %y_addr
+ %tmp1 = load i32* %x_addr ; <i32> [#uses=1]
+ %tmp2 = load i32* %y_addr ; <i32> [#uses=1]
+ %tmp3 = add i32 %tmp1, %tmp2 ; <i32> [#uses=1]
+ store i32 %tmp3, i32* %tmp
+ %tmp4 = load i32* %tmp ; <i32> [#uses=1]
+ store i32 %tmp4, i32* %retval
+ br label %return
+
+return: ; preds = %entry
+ %retval5 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval5
+}
+
+define i32 @foo(i32 %a, i32 %b) {
+entry:
+ %a_addr = alloca i32 ; <i32*> [#uses=2]
+ %b_addr = alloca i32 ; <i32*> [#uses=2]
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %a, i32* %a_addr
+ store i32 %b, i32* %b_addr
+ %tmp1 = load i32* %b_addr ; <i32> [#uses=1]
+ %tmp2 = load i32* %a_addr ; <i32> [#uses=1]
+ %tmp3 = call i32 @bar( i32 %tmp1, i32 %tmp2 ) ; <i32> [#uses=1]
+ store i32 %tmp3, i32* %tmp
+ %tmp4 = load i32* %tmp ; <i32> [#uses=1]
+ store i32 %tmp4, i32* %retval
+ br label %return
+
+return: ; preds = %entry
+ %retval5 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval5
+}
diff --git a/src/LLVM/test/Transforms/Inline/2007-06-25-WeakInline.ll b/src/LLVM/test/Transforms/Inline/2007-06-25-WeakInline.ll
new file mode 100644
index 0000000..6a451d4
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2007-06-25-WeakInline.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -inline -S | grep call
+
+; 'bar' can be overridden at link-time, don't inline it.
+
+define void @foo() {
+entry:
+ tail call void @bar( ) ; <i32> [#uses=0]
+ ret void
+}
+
+define weak void @bar() {
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2007-12-19-InlineNoUnwind.ll b/src/LLVM/test/Transforms/Inline/2007-12-19-InlineNoUnwind.ll
new file mode 100644
index 0000000..a5cfc3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2007-12-19-InlineNoUnwind.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -inline -S | grep nounwind
+; RUN: opt < %s -inline -S | grep unreachable
+
+declare i1 @extern()
+
+define internal i32 @test() {
+entry:
+ %n = call i1 @extern( )
+ br i1 %n, label %r, label %u
+r:
+ ret i32 0
+u:
+ unreachable
+}
+
+define i32 @caller() {
+ %X = call i32 @test( ) nounwind
+ ret i32 %X
+}
diff --git a/src/LLVM/test/Transforms/Inline/2008-09-02-AlwaysInline.ll b/src/LLVM/test/Transforms/Inline/2008-09-02-AlwaysInline.ll
new file mode 100644
index 0000000..39095c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2008-09-02-AlwaysInline.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -inline-threshold=0 -inline -S | not grep call
+
+define i32 @fn2() alwaysinline {
+ ret i32 1
+}
+
+define i32 @fn3() {
+ %r = call i32 @fn2()
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/Inline/2008-09-02-NoInline.ll b/src/LLVM/test/Transforms/Inline/2008-09-02-NoInline.ll
new file mode 100644
index 0000000..33c8949
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2008-09-02-NoInline.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -inline -S | grep call | count 1
+
+define i32 @fn2() noinline {
+ ret i32 1
+}
+
+define i32 @fn3() {
+ %r = call i32 @fn2()
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/Inline/2008-10-30-AlwaysInline.ll b/src/LLVM/test/Transforms/Inline/2008-10-30-AlwaysInline.ll
new file mode 100644
index 0000000..11e5012
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2008-10-30-AlwaysInline.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -always-inline -S | not grep call
+
+; Ensure that threshold doesn't disrupt always inline.
+; RUN: opt < %s -inline-threshold=-2000000001 -always-inline -S | not grep call
+
+
+define internal i32 @if0() alwaysinline {
+ ret i32 1
+}
+
+define i32 @f0() {
+ %r = call i32 @if0()
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/Inline/2008-11-04-AlwaysInline.ll b/src/LLVM/test/Transforms/Inline/2008-11-04-AlwaysInline.ll
new file mode 100644
index 0000000..bc9787b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2008-11-04-AlwaysInline.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -always-inline -S | grep {@foo}
+; Ensure that foo is not removed by always inliner
+; PR 2945
+
+define internal i32 @foo() nounwind {
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/Inline/2009-01-08-NoInlineDynamicAlloca.ll b/src/LLVM/test/Transforms/Inline/2009-01-08-NoInlineDynamicAlloca.ll
new file mode 100644
index 0000000..db2a799
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2009-01-08-NoInlineDynamicAlloca.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -inline -S | grep call
+; Do not inline calls to variable-sized alloca.
+
+@q = common global i8* null ; <i8**> [#uses=1]
+
+define i8* @a(i32 %i) nounwind {
+entry:
+ %i_addr = alloca i32 ; <i32*> [#uses=2]
+ %retval = alloca i8* ; <i8**> [#uses=1]
+ %p = alloca i8* ; <i8**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %i, i32* %i_addr
+ %0 = load i32* %i_addr, align 4 ; <i32> [#uses=1]
+ %1 = alloca i8, i32 %0 ; <i8*> [#uses=1]
+ store i8* %1, i8** %p, align 4
+ %2 = load i8** %p, align 4 ; <i8*> [#uses=1]
+ store i8* %2, i8** @q, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i8** %retval ; <i8*> [#uses=1]
+ ret i8* %retval1
+}
+
+define void @b(i32 %i) nounwind {
+entry:
+ %i_addr = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %i, i32* %i_addr
+ %0 = load i32* %i_addr, align 4 ; <i32> [#uses=1]
+ %1 = call i8* @a(i32 %0) nounwind ; <i8*> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/2009-01-13-RecursiveInlineCrash.ll b/src/LLVM/test/Transforms/Inline/2009-01-13-RecursiveInlineCrash.ll
new file mode 100644
index 0000000..7d8d16b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2009-01-13-RecursiveInlineCrash.ll
@@ -0,0 +1,293 @@
+; RUN: opt < %s -inline -argpromotion -disable-output
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+ %struct.quad_struct = type { i32, i32, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct* }
+@NumNodes = external global i32 ; <i32*> [#uses=0]
+@"\01LC" = external constant [43 x i8] ; <[43 x i8]*> [#uses=0]
+@"\01LC1" = external constant [19 x i8] ; <[19 x i8]*> [#uses=0]
+@"\01LC2" = external constant [17 x i8] ; <[17 x i8]*> [#uses=0]
+
+declare i32 @dealwithargs(i32, i8** nocapture) nounwind
+
+declare i32 @atoi(i8*)
+
+define internal fastcc i32 @adj(i32 %d, i32 %ct) nounwind readnone {
+entry:
+ switch i32 %d, label %return [
+ i32 0, label %bb
+ i32 1, label %bb10
+ i32 2, label %bb5
+ i32 3, label %bb15
+ ]
+
+bb: ; preds = %entry
+ switch i32 %ct, label %bb3 [
+ i32 1, label %return
+ i32 0, label %return
+ ]
+
+bb3: ; preds = %bb
+ ret i32 0
+
+bb5: ; preds = %entry
+ switch i32 %ct, label %bb8 [
+ i32 3, label %return
+ i32 2, label %return
+ ]
+
+bb8: ; preds = %bb5
+ ret i32 0
+
+bb10: ; preds = %entry
+ switch i32 %ct, label %bb13 [
+ i32 1, label %return
+ i32 3, label %return
+ ]
+
+bb13: ; preds = %bb10
+ ret i32 0
+
+bb15: ; preds = %entry
+ switch i32 %ct, label %bb18 [
+ i32 2, label %return
+ i32 0, label %return
+ ]
+
+bb18: ; preds = %bb15
+ ret i32 0
+
+return: ; preds = %bb15, %bb15, %bb10, %bb10, %bb5, %bb5, %bb, %bb, %entry
+ ret i32 1
+}
+
+declare fastcc i32 @reflect(i32, i32) nounwind readnone
+
+declare i32 @CountTree(%struct.quad_struct* nocapture) nounwind readonly
+
+define internal fastcc %struct.quad_struct* @child(%struct.quad_struct* nocapture %tree, i32 %ct) nounwind readonly {
+entry:
+ switch i32 %ct, label %bb5 [
+ i32 0, label %bb1
+ i32 1, label %bb
+ i32 2, label %bb3
+ i32 3, label %bb2
+ ]
+
+bb: ; preds = %entry
+ %0 = getelementptr %struct.quad_struct* %tree, i32 0, i32 3 ; <%struct.quad_struct**> [#uses=1]
+ %1 = load %struct.quad_struct** %0, align 4 ; <%struct.quad_struct*> [#uses=1]
+ ret %struct.quad_struct* %1
+
+bb1: ; preds = %entry
+ %2 = getelementptr %struct.quad_struct* %tree, i32 0, i32 2 ; <%struct.quad_struct**> [#uses=1]
+ %3 = load %struct.quad_struct** %2, align 4 ; <%struct.quad_struct*> [#uses=1]
+ ret %struct.quad_struct* %3
+
+bb2: ; preds = %entry
+ %4 = getelementptr %struct.quad_struct* %tree, i32 0, i32 5 ; <%struct.quad_struct**> [#uses=1]
+ %5 = load %struct.quad_struct** %4, align 4 ; <%struct.quad_struct*> [#uses=1]
+ ret %struct.quad_struct* %5
+
+bb3: ; preds = %entry
+ %6 = getelementptr %struct.quad_struct* %tree, i32 0, i32 4 ; <%struct.quad_struct**> [#uses=1]
+ %7 = load %struct.quad_struct** %6, align 4 ; <%struct.quad_struct*> [#uses=1]
+ ret %struct.quad_struct* %7
+
+bb5: ; preds = %entry
+ ret %struct.quad_struct* null
+}
+
+define internal fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* nocapture %tree, i32 %d) nounwind readonly {
+entry:
+ %0 = getelementptr %struct.quad_struct* %tree, i32 0, i32 6 ; <%struct.quad_struct**> [#uses=1]
+ %1 = load %struct.quad_struct** %0, align 4 ; <%struct.quad_struct*> [#uses=4]
+ %2 = getelementptr %struct.quad_struct* %tree, i32 0, i32 1 ; <i32*> [#uses=1]
+ %3 = load i32* %2, align 4 ; <i32> [#uses=2]
+ %4 = icmp eq %struct.quad_struct* %1, null ; <i1> [#uses=1]
+ br i1 %4, label %bb3, label %bb
+
+bb: ; preds = %entry
+ %5 = call fastcc i32 @adj(i32 %d, i32 %3) nounwind ; <i32> [#uses=1]
+ %6 = icmp eq i32 %5, 0 ; <i1> [#uses=1]
+ br i1 %6, label %bb3, label %bb1
+
+bb1: ; preds = %bb
+ %7 = call fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* %1, i32 %d) nounwind ; <%struct.quad_struct*> [#uses=1]
+ br label %bb3
+
+bb3: ; preds = %bb1, %bb, %entry
+ %q.0 = phi %struct.quad_struct* [ %7, %bb1 ], [ %1, %bb ], [ %1, %entry ] ; <%struct.quad_struct*> [#uses=4]
+ %8 = icmp eq %struct.quad_struct* %q.0, null ; <i1> [#uses=1]
+ br i1 %8, label %bb7, label %bb4
+
+bb4: ; preds = %bb3
+ %9 = getelementptr %struct.quad_struct* %q.0, i32 0, i32 0 ; <i32*> [#uses=1]
+ %10 = load i32* %9, align 4 ; <i32> [#uses=1]
+ %11 = icmp eq i32 %10, 2 ; <i1> [#uses=1]
+ br i1 %11, label %bb5, label %bb7
+
+bb5: ; preds = %bb4
+ %12 = call fastcc i32 @reflect(i32 %d, i32 %3) nounwind ; <i32> [#uses=1]
+ %13 = call fastcc %struct.quad_struct* @child(%struct.quad_struct* %q.0, i32 %12) nounwind ; <%struct.quad_struct*> [#uses=1]
+ ret %struct.quad_struct* %13
+
+bb7: ; preds = %bb4, %bb3
+ ret %struct.quad_struct* %q.0
+}
+
+declare fastcc i32 @sum_adjacent(%struct.quad_struct* nocapture, i32, i32, i32) nounwind readonly
+
+define i32 @perimeter(%struct.quad_struct* nocapture %tree, i32 %size) nounwind readonly {
+entry:
+ %0 = getelementptr %struct.quad_struct* %tree, i32 0, i32 0 ; <i32*> [#uses=1]
+ %1 = load i32* %0, align 4 ; <i32> [#uses=1]
+ %2 = icmp eq i32 %1, 2 ; <i1> [#uses=1]
+ br i1 %2, label %bb, label %bb2
+
+bb: ; preds = %entry
+ %3 = getelementptr %struct.quad_struct* %tree, i32 0, i32 4 ; <%struct.quad_struct**> [#uses=1]
+ %4 = load %struct.quad_struct** %3, align 4 ; <%struct.quad_struct*> [#uses=1]
+ %5 = sdiv i32 %size, 2 ; <i32> [#uses=1]
+ %6 = call i32 @perimeter(%struct.quad_struct* %4, i32 %5) nounwind ; <i32> [#uses=1]
+ %7 = getelementptr %struct.quad_struct* %tree, i32 0, i32 5 ; <%struct.quad_struct**> [#uses=1]
+ %8 = load %struct.quad_struct** %7, align 4 ; <%struct.quad_struct*> [#uses=1]
+ %9 = sdiv i32 %size, 2 ; <i32> [#uses=1]
+ %10 = call i32 @perimeter(%struct.quad_struct* %8, i32 %9) nounwind ; <i32> [#uses=1]
+ %11 = add i32 %10, %6 ; <i32> [#uses=1]
+ %12 = getelementptr %struct.quad_struct* %tree, i32 0, i32 3 ; <%struct.quad_struct**> [#uses=1]
+ %13 = load %struct.quad_struct** %12, align 4 ; <%struct.quad_struct*> [#uses=1]
+ %14 = sdiv i32 %size, 2 ; <i32> [#uses=1]
+ %15 = call i32 @perimeter(%struct.quad_struct* %13, i32 %14) nounwind ; <i32> [#uses=1]
+ %16 = add i32 %15, %11 ; <i32> [#uses=1]
+ %17 = getelementptr %struct.quad_struct* %tree, i32 0, i32 2 ; <%struct.quad_struct**> [#uses=1]
+ %18 = load %struct.quad_struct** %17, align 4 ; <%struct.quad_struct*> [#uses=1]
+ %19 = sdiv i32 %size, 2 ; <i32> [#uses=1]
+ %20 = call i32 @perimeter(%struct.quad_struct* %18, i32 %19) nounwind ; <i32> [#uses=1]
+ %21 = add i32 %20, %16 ; <i32> [#uses=1]
+ ret i32 %21
+
+bb2: ; preds = %entry
+ %22 = getelementptr %struct.quad_struct* %tree, i32 0, i32 0 ; <i32*> [#uses=1]
+ %23 = load i32* %22, align 4 ; <i32> [#uses=1]
+ %24 = icmp eq i32 %23, 0 ; <i1> [#uses=1]
+ br i1 %24, label %bb3, label %bb23
+
+bb3: ; preds = %bb2
+ %25 = call fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* %tree, i32 0) nounwind ; <%struct.quad_struct*> [#uses=4]
+ %26 = icmp eq %struct.quad_struct* %25, null ; <i1> [#uses=1]
+ br i1 %26, label %bb8, label %bb4
+
+bb4: ; preds = %bb3
+ %27 = getelementptr %struct.quad_struct* %25, i32 0, i32 0 ; <i32*> [#uses=1]
+ %28 = load i32* %27, align 4 ; <i32> [#uses=1]
+ %29 = icmp eq i32 %28, 1 ; <i1> [#uses=1]
+ br i1 %29, label %bb8, label %bb6
+
+bb6: ; preds = %bb4
+ %30 = getelementptr %struct.quad_struct* %25, i32 0, i32 0 ; <i32*> [#uses=1]
+ %31 = load i32* %30, align 4 ; <i32> [#uses=1]
+ %32 = icmp eq i32 %31, 2 ; <i1> [#uses=1]
+ br i1 %32, label %bb7, label %bb8
+
+bb7: ; preds = %bb6
+ %33 = call fastcc i32 @sum_adjacent(%struct.quad_struct* %25, i32 3, i32 2, i32 %size) nounwind ; <i32> [#uses=1]
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb6, %bb4, %bb3
+ %retval1.1 = phi i32 [ 0, %bb6 ], [ %33, %bb7 ], [ %size, %bb4 ], [ %size, %bb3 ] ; <i32> [#uses=3]
+ %34 = call fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* %tree, i32 1) nounwind ; <%struct.quad_struct*> [#uses=4]
+ %35 = icmp eq %struct.quad_struct* %34, null ; <i1> [#uses=1]
+ br i1 %35, label %bb10, label %bb9
+
+bb9: ; preds = %bb8
+ %36 = getelementptr %struct.quad_struct* %34, i32 0, i32 0 ; <i32*> [#uses=1]
+ %37 = load i32* %36, align 4 ; <i32> [#uses=1]
+ %38 = icmp eq i32 %37, 1 ; <i1> [#uses=1]
+ br i1 %38, label %bb10, label %bb11
+
+bb10: ; preds = %bb9, %bb8
+ %39 = add i32 %retval1.1, %size ; <i32> [#uses=1]
+ br label %bb13
+
+bb11: ; preds = %bb9
+ %40 = getelementptr %struct.quad_struct* %34, i32 0, i32 0 ; <i32*> [#uses=1]
+ %41 = load i32* %40, align 4 ; <i32> [#uses=1]
+ %42 = icmp eq i32 %41, 2 ; <i1> [#uses=1]
+ br i1 %42, label %bb12, label %bb13
+
+bb12: ; preds = %bb11
+ %43 = call fastcc i32 @sum_adjacent(%struct.quad_struct* %34, i32 2, i32 0, i32 %size) nounwind ; <i32> [#uses=1]
+ %44 = add i32 %43, %retval1.1 ; <i32> [#uses=1]
+ br label %bb13
+
+bb13: ; preds = %bb12, %bb11, %bb10
+ %retval1.2 = phi i32 [ %retval1.1, %bb11 ], [ %44, %bb12 ], [ %39, %bb10 ] ; <i32> [#uses=3]
+ %45 = call fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* %tree, i32 2) nounwind ; <%struct.quad_struct*> [#uses=4]
+ %46 = icmp eq %struct.quad_struct* %45, null ; <i1> [#uses=1]
+ br i1 %46, label %bb15, label %bb14
+
+bb14: ; preds = %bb13
+ %47 = getelementptr %struct.quad_struct* %45, i32 0, i32 0 ; <i32*> [#uses=1]
+ %48 = load i32* %47, align 4 ; <i32> [#uses=1]
+ %49 = icmp eq i32 %48, 1 ; <i1> [#uses=1]
+ br i1 %49, label %bb15, label %bb16
+
+bb15: ; preds = %bb14, %bb13
+ %50 = add i32 %retval1.2, %size ; <i32> [#uses=1]
+ br label %bb18
+
+bb16: ; preds = %bb14
+ %51 = getelementptr %struct.quad_struct* %45, i32 0, i32 0 ; <i32*> [#uses=1]
+ %52 = load i32* %51, align 4 ; <i32> [#uses=1]
+ %53 = icmp eq i32 %52, 2 ; <i1> [#uses=1]
+ br i1 %53, label %bb17, label %bb18
+
+bb17: ; preds = %bb16
+ %54 = call fastcc i32 @sum_adjacent(%struct.quad_struct* %45, i32 0, i32 1, i32 %size) nounwind ; <i32> [#uses=1]
+ %55 = add i32 %54, %retval1.2 ; <i32> [#uses=1]
+ br label %bb18
+
+bb18: ; preds = %bb17, %bb16, %bb15
+ %retval1.3 = phi i32 [ %retval1.2, %bb16 ], [ %55, %bb17 ], [ %50, %bb15 ] ; <i32> [#uses=3]
+ %56 = call fastcc %struct.quad_struct* @gtequal_adj_neighbor(%struct.quad_struct* %tree, i32 3) nounwind ; <%struct.quad_struct*> [#uses=4]
+ %57 = icmp eq %struct.quad_struct* %56, null ; <i1> [#uses=1]
+ br i1 %57, label %bb20, label %bb19
+
+bb19: ; preds = %bb18
+ %58 = getelementptr %struct.quad_struct* %56, i32 0, i32 0 ; <i32*> [#uses=1]
+ %59 = load i32* %58, align 4 ; <i32> [#uses=1]
+ %60 = icmp eq i32 %59, 1 ; <i1> [#uses=1]
+ br i1 %60, label %bb20, label %bb21
+
+bb20: ; preds = %bb19, %bb18
+ %61 = add i32 %retval1.3, %size ; <i32> [#uses=1]
+ ret i32 %61
+
+bb21: ; preds = %bb19
+ %62 = getelementptr %struct.quad_struct* %56, i32 0, i32 0 ; <i32*> [#uses=1]
+ %63 = load i32* %62, align 4 ; <i32> [#uses=1]
+ %64 = icmp eq i32 %63, 2 ; <i1> [#uses=1]
+ br i1 %64, label %bb22, label %bb23
+
+bb22: ; preds = %bb21
+ %65 = call fastcc i32 @sum_adjacent(%struct.quad_struct* %56, i32 1, i32 3, i32 %size) nounwind ; <i32> [#uses=1]
+ %66 = add i32 %65, %retval1.3 ; <i32> [#uses=1]
+ ret i32 %66
+
+bb23: ; preds = %bb21, %bb2
+ %retval1.0 = phi i32 [ 0, %bb2 ], [ %retval1.3, %bb21 ] ; <i32> [#uses=1]
+ ret i32 %retval1.0
+}
+
+declare i32 @main(i32, i8** nocapture) noreturn nounwind
+
+declare i32 @printf(i8*, ...) nounwind
+
+declare void @exit(i32) noreturn nounwind
+
+declare fastcc i32 @CheckOutside(i32, i32) nounwind readnone
+
+declare fastcc i32 @CheckIntersect(i32, i32, i32) nounwind readnone
+
+declare %struct.quad_struct* @MakeTree(i32, i32, i32, i32, i32, %struct.quad_struct*, i32, i32) nounwind
diff --git a/src/LLVM/test/Transforms/Inline/2009-05-07-CallUsingSelfCrash.ll b/src/LLVM/test/Transforms/Inline/2009-05-07-CallUsingSelfCrash.ll
new file mode 100644
index 0000000..c8629ea
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2009-05-07-CallUsingSelfCrash.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -inline -disable-output
+; PR4123
+ %struct.S0 = type <{ i32 }>
+ %struct.S1 = type <{ i8, i8, i8, i8, %struct.S0 }>
+ %struct.S2 = type <{ %struct.S1, i32 }>
+
+define void @func_113(%struct.S1* noalias nocapture sret %agg.result, i8 signext %p_114) noreturn nounwind {
+entry:
+ unreachable
+
+for.inc: ; preds = %for.inc
+ %call48 = call fastcc signext i8 @safe_sub_func_uint8_t_u_u(i8 signext %call48) ; <i8> [#uses=1]
+ br label %for.inc
+}
+
+define fastcc signext i8 @safe_sub_func_uint8_t_u_u(i8 signext %_ui1) nounwind readnone {
+entry:
+ ret i8 %_ui1
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/2010-05-12-ValueMap.ll b/src/LLVM/test/Transforms/Inline/2010-05-12-ValueMap.ll
new file mode 100644
index 0000000..f9cc13f
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2010-05-12-ValueMap.ll
@@ -0,0 +1,28 @@
+; RUN: opt %s -inline -mergefunc -disable-output
+
+; This tests for a bug where the inliner kept the functions in a ValueMap after
+; it had completed and a ModulePass started to run. LLVM would crash deleting
+; a function that was still a key in the ValueMap.
+
+define internal fastcc void @list_Cdr1918() nounwind inlinehint {
+ unreachable
+}
+
+define internal fastcc void @list_PairSecond1927() nounwind inlinehint {
+ call fastcc void @list_Cdr1918() nounwind inlinehint
+ unreachable
+}
+
+define internal fastcc void @list_Cdr3164() nounwind inlinehint {
+ unreachable
+}
+
+define internal fastcc void @list_Nconc3167() nounwind inlinehint {
+ call fastcc void @list_Cdr3164() nounwind inlinehint
+ unreachable
+}
+
+define void @term_Equal() nounwind {
+ call fastcc void @list_Cdr3164() nounwind inlinehint
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/Inline/2010-05-31-ByvalTailcall.ll b/src/LLVM/test/Transforms/Inline/2010-05-31-ByvalTailcall.ll
new file mode 100644
index 0000000..1ce74e6
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/2010-05-31-ByvalTailcall.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -tailcallelim -inline -instcombine -dse -S | FileCheck %s
+; PR7272
+
+; When inlining through a byval call site, the inliner creates allocas which may
+; be used by inlined calls, so any inlined calls need to have their 'tail' flags
+; cleared. If not then you can get nastiness like with this testcase, where the
+; (inlined) call to 'ext' in 'foo' was being passed an uninitialized value.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+declare void @ext(i32*)
+
+define void @bar(i32* byval %x) {
+ call void @ext(i32* %x)
+ ret void
+}
+
+define void @foo(i32* %x) {
+; CHECK: define void @foo
+; CHECK: store i32 %1, i32* %x
+ call void @bar(i32* byval %x)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/PR4909.ll b/src/LLVM/test/Transforms/Inline/PR4909.ll
new file mode 100644
index 0000000..24545f9
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/PR4909.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -partial-inliner -disable-output
+
+define i32 @f() {
+entry:
+ br label %return
+
+return: ; preds = %entry
+ ret i32 undef
+}
+
+define i32 @g() {
+entry:
+ %0 = call i32 @f()
+ ret i32 %0
+}
diff --git a/src/LLVM/test/Transforms/Inline/alloca-in-scc.ll b/src/LLVM/test/Transforms/Inline/alloca-in-scc.ll
new file mode 100644
index 0000000..d539255
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/alloca-in-scc.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -inline | llvm-dis
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+define i32 @main(i32 %argc, i8** %argv) nounwind ssp {
+entry:
+ call fastcc void @c() nounwind
+ unreachable
+}
+
+define internal fastcc void @a() nounwind ssp {
+entry:
+ %al = alloca [3 x i32], align 4
+ %0 = getelementptr inbounds [3 x i32]* %al, i32 0, i32 2
+
+ call fastcc void @c() nounwind
+ unreachable
+}
+
+define internal fastcc void @b() nounwind ssp {
+entry:
+ tail call fastcc void @a() nounwind ssp
+ unreachable
+}
+
+define internal fastcc void @c() nounwind ssp {
+entry:
+ call fastcc void @b() nounwind
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/Inline/alloca_test.ll b/src/LLVM/test/Transforms/Inline/alloca_test.ll
new file mode 100644
index 0000000..a0bb19d
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/alloca_test.ll
@@ -0,0 +1,23 @@
+; This test ensures that alloca instructions in the entry block for an inlined
+; function are moved to the top of the function they are inlined into.
+;
+; RUN: opt -S -inline %s | FileCheck %s
+
+define i32 @func(i32 %i) {
+ %X = alloca i32 ; <i32*> [#uses=1]
+ store i32 %i, i32* %X
+ ret i32 %i
+}
+
+declare void @bar()
+
+define i32 @main(i32 %argc) {
+Entry:
+; CHECK: Entry
+; CHECK-NEXT: alloca
+ call void @bar( )
+ %X = call i32 @func( i32 7 ) ; <i32> [#uses=1]
+ %Y = add i32 %X, %argc ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/always_inline_dyn_alloca.ll b/src/LLVM/test/Transforms/Inline/always_inline_dyn_alloca.ll
new file mode 100644
index 0000000..25cfc49
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/always_inline_dyn_alloca.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -inline -S | not grep callee
+; rdar://6655932
+
+; If callee is marked alwaysinline, inline it! Even if callee has dynamic
+; alloca and caller does not,
+
+define internal void @callee(i32 %N) alwaysinline {
+ %P = alloca i32, i32 %N
+ ret void
+}
+
+define void @foo(i32 %N) {
+ call void @callee( i32 %N )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/array_merge.ll b/src/LLVM/test/Transforms/Inline/array_merge.ll
new file mode 100644
index 0000000..b2eafeb
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/array_merge.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+; rdar://7173846
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+define internal void @foo() nounwind ssp {
+entry:
+ %A = alloca [100 x i32]
+ %B = alloca [100 x i32]
+ call void @bar([100 x i32]* %A, [100 x i32]* %B) nounwind
+ ret void
+}
+
+declare void @bar([100 x i32]*, [100 x i32]*)
+
+define void @test() nounwind ssp {
+entry:
+; CHECK: @test()
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %A.i = alloca
+; CHECK-NEXT: %B.i = alloca
+; CHECK-NOT: alloca
+ call void @foo() nounwind
+ call void @foo() nounwind
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/basictest.ll b/src/LLVM/test/Transforms/Inline/basictest.ll
new file mode 100644
index 0000000..ed0a235
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/basictest.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -inline -scalarrepl -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+define i32 @test1f(i32 %i) {
+ ret i32 %i
+}
+
+define i32 @test1(i32 %W) {
+ %X = call i32 @test1f(i32 7)
+ %Y = add i32 %X, %W
+ ret i32 %Y
+; CHECK: @test1(
+; CHECK-NEXT: %Y = add i32 7, %W
+; CHECK-NEXT: ret i32 %Y
+}
+
+
+
+; rdar://7339069
+
+%T = type { i32, i32 }
+
+; CHECK-NOT: @test2f
+define internal %T* @test2f(i1 %cond, %T* %P) {
+ br i1 %cond, label %T, label %F
+
+T:
+ %A = getelementptr %T* %P, i32 0, i32 0
+ store i32 42, i32* %A
+ ret %T* %P
+
+F:
+ ret %T* %P
+}
+
+define i32 @test2(i1 %cond) {
+ %A = alloca %T
+
+ %B = call %T* @test2f(i1 %cond, %T* %A)
+ %C = getelementptr %T* %B, i32 0, i32 0
+ %D = load i32* %C
+ ret i32 %D
+
+; CHECK: @test2(
+; CHECK-NOT: = alloca
+; CHECK: ret i32
+}
diff --git a/src/LLVM/test/Transforms/Inline/byval.ll b/src/LLVM/test/Transforms/Inline/byval.ll
new file mode 100644
index 0000000..e601faf
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/byval.ll
@@ -0,0 +1,106 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+
+; Inlining a byval struct should cause an explicit copy into an alloca.
+
+ %struct.ss = type { i32, i64 }
+@.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1]
+
+define internal void @f(%struct.ss* byval %b) nounwind {
+entry:
+ %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
+ %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
+ store i32 %tmp2, i32* %tmp, align 4
+ ret void
+}
+
+declare i32 @printf(i8*, ...) nounwind
+
+define i32 @test1() nounwind {
+entry:
+ %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
+ %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp1, align 8
+ %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
+ store i64 2, i64* %tmp4, align 4
+ call void @f( %struct.ss* byval %S ) nounwind
+ ret i32 0
+; CHECK: @test1()
+; CHECK: %S1 = alloca %struct.ss
+; CHECK: %S = alloca %struct.ss
+; CHECK: call void @llvm.memcpy
+; CHECK: ret i32 0
+}
+
+; Inlining a byval struct should NOT cause an explicit copy
+; into an alloca if the function is readonly
+
+define internal i32 @f2(%struct.ss* byval %b) nounwind readonly {
+entry:
+ %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2]
+ %tmp1 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @test2() nounwind {
+entry:
+ %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
+ %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp1, align 8
+ %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1]
+ store i64 2, i64* %tmp4, align 4
+ %X = call i32 @f2( %struct.ss* byval %S ) nounwind
+ ret i32 %X
+; CHECK: @test2()
+; CHECK: %S = alloca %struct.ss
+; CHECK-NOT: call void @llvm.memcpy
+; CHECK: ret i32
+}
+
+
+; Inlining a byval with an explicit alignment needs to use *at least* that
+; alignment on the generated alloca.
+; PR8769
+declare void @g3(%struct.ss* %p)
+
+define internal void @f3(%struct.ss* byval align 64 %b) nounwind {
+ call void @g3(%struct.ss* %b) ;; Could make alignment assumptions!
+ ret void
+}
+
+define void @test3() nounwind {
+entry:
+ %S = alloca %struct.ss, align 1 ;; May not be aligned.
+ call void @f3( %struct.ss* byval align 64 %S) nounwind
+ ret void
+; CHECK: @test3()
+; CHECK: %S1 = alloca %struct.ss, align 64
+; CHECK: %S = alloca %struct.ss
+; CHECK: call void @llvm.memcpy
+; CHECK: call void @g3(%struct.ss* %S1)
+; CHECK: ret void
+}
+
+
+; Inlining a byval struct should NOT cause an explicit copy
+; into an alloca if the function is readonly, but should increase an alloca's
+; alignment to satisfy an explicit alignment request.
+
+define internal i32 @f4(%struct.ss* byval align 64 %b) nounwind readonly {
+ call void @g3(%struct.ss* %b)
+ ret i32 4
+}
+
+define i32 @test4() nounwind {
+entry:
+ %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4]
+ %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind
+ ret i32 %X
+; CHECK: @test4()
+; CHECK: %S = alloca %struct.ss, align 64
+; CHECK-NOT: call void @llvm.memcpy
+; CHECK: call void @g3
+; CHECK: ret i32 4
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/callgraph-update.ll b/src/LLVM/test/Transforms/Inline/callgraph-update.ll
new file mode 100644
index 0000000..b96fbc3
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/callgraph-update.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -inline -loop-rotate -verify-dom-info -verify-loop-info -disable-output
+; PR3601
+declare void @solve()
+
+define internal fastcc void @read() {
+ br label %bb4
+
+bb3:
+ br label %bb4
+
+bb4:
+ call void @solve()
+ br i1 false, label %bb5, label %bb3
+
+bb5:
+ unreachable
+}
+
+define internal fastcc void @parse() {
+ call fastcc void @read()
+ ret void
+}
+
+define void @main() {
+ invoke fastcc void @parse()
+ to label %invcont unwind label %lpad
+
+invcont:
+ unreachable
+
+lpad:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/casts.ll b/src/LLVM/test/Transforms/Inline/casts.ll
new file mode 100644
index 0000000..484cb3a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/casts.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -inline -S | grep {ret i32 1}
+; ModuleID = 'short.opt.bc'
+
+define i32 @testBool(i1 %X) {
+ %tmp = zext i1 %X to i32 ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+define i32 @testByte(i8 %X) {
+ %tmp = icmp ne i8 %X, 0 ; <i1> [#uses=1]
+ %tmp.i = zext i1 %tmp to i32 ; <i32> [#uses=1]
+ ret i32 %tmp.i
+}
+
+define i32 @main() {
+ %rslt = call i32 @testByte( i8 123 ) ; <i32> [#uses=1]
+ ret i32 %rslt
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/cfg_preserve_test.ll b/src/LLVM/test/Transforms/Inline/cfg_preserve_test.ll
new file mode 100644
index 0000000..09b85d7
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/cfg_preserve_test.ll
@@ -0,0 +1,16 @@
+; This test ensures that inlining an "empty" function does not destroy the CFG
+;
+; RUN: opt < %s -inline -S | not grep br
+
+define i32 @func(i32 %i) {
+ ret i32 %i
+}
+
+declare void @bar()
+
+define i32 @main(i32 %argc) {
+Entry:
+ %X = call i32 @func( i32 7 ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/crash.ll b/src/LLVM/test/Transforms/Inline/crash.ll
new file mode 100644
index 0000000..e2cd49c
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/crash.ll
@@ -0,0 +1,127 @@
+; RUN: opt < %s -inline -argpromotion -instcombine -disable-output
+
+; This test was failing because the inliner would inline @list_DeleteElement
+; into @list_DeleteDuplicates and then into @inf_GetBackwardPartnerLits,
+; turning the indirect call into a direct one. This allowed instcombine to see
+; the bitcast and eliminate it, deleting the original call and introducing
+; another one. This crashed the inliner because the new call was not in the
+; callgraph.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+
+
+define void @list_DeleteElement(i32 (i8*, i8*)* nocapture %Test) nounwind ssp {
+entry:
+ %0 = call i32 %Test(i8* null, i8* undef) nounwind
+ ret void
+}
+
+
+define void @list_DeleteDuplicates(i32 (i8*, i8*)* nocapture %Test) nounwind ssp {
+foo:
+ call void @list_DeleteElement(i32 (i8*, i8*)* %Test) nounwind ssp
+ call fastcc void @list_Rplacd1284() nounwind ssp
+ unreachable
+
+}
+
+define internal i32 @inf_LiteralsHaveSameSubtermAndAreFromSameClause(i32* nocapture %L1, i32* nocapture %L2) nounwind readonly ssp {
+entry:
+ unreachable
+}
+
+
+define internal fastcc void @inf_GetBackwardPartnerLits(i32* nocapture %Flags) nounwind ssp {
+test:
+ call void @list_DeleteDuplicates(i32 (i8*, i8*)* bitcast (i32 (i32*, i32*)* @inf_LiteralsHaveSameSubtermAndAreFromSameClause to i32 (i8*, i8*)*)) nounwind
+ ret void
+}
+
+
+define void @inf_BackwardEmptySortPlusPlus() nounwind ssp {
+entry:
+ call fastcc void @inf_GetBackwardPartnerLits(i32* null) nounwind ssp
+ unreachable
+}
+
+define void @inf_BackwardWeakening() nounwind ssp {
+entry:
+ call fastcc void @inf_GetBackwardPartnerLits(i32* null) nounwind ssp
+ unreachable
+}
+
+declare fastcc void @list_Rplacd1284() nounwind ssp
+
+
+
+
+;============================
+; PR5208
+
+define void @AAA() {
+entry:
+ %A = alloca i8, i32 undef, align 1
+ invoke fastcc void @XXX()
+ to label %invcont98 unwind label %lpad156
+
+invcont98:
+ unreachable
+
+lpad156:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare fastcc void @YYY()
+
+define internal fastcc void @XXX() {
+entry:
+ %B = alloca i8, i32 undef, align 1
+ invoke fastcc void @YYY()
+ to label %bb260 unwind label %lpad
+
+bb260:
+ ret void
+
+lpad:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %exn
+}
+
+
+
+;; This exposed a crash handling devirtualized calls.
+define void @f1(void ()* %f) ssp {
+entry:
+ call void %f()
+ ret void
+}
+
+define void @f4(i32 %size) ssp {
+entry:
+ invoke void @f1(void ()* @f3)
+ to label %invcont3 unwind label %lpad18
+
+invcont3: ; preds = %bb1
+ ret void
+
+lpad18: ; preds = %invcont3, %bb1
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+define void @f3() ssp {
+entry:
+ unreachable
+}
+
+declare void @f5() ssp
+
+
+
diff --git a/src/LLVM/test/Transforms/Inline/crash2.ll b/src/LLVM/test/Transforms/Inline/crash2.ll
new file mode 100644
index 0000000..cb1f44d
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/crash2.ll
@@ -0,0 +1,29 @@
+; RUN: opt -inline -scalarrepl -max-cg-scc-iterations=1 %s -disable-output
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.3"
+
+declare i8* @f1(i8*) ssp align 2
+
+define linkonce_odr void @f2(i8* %t) inlinehint ssp {
+entry:
+ unreachable
+}
+
+define linkonce_odr void @f3(void (i8*)* %__f) ssp {
+entry:
+ %__f_addr = alloca void (i8*)*, align 8
+ store void (i8*)* %__f, void (i8*)** %__f_addr
+
+ %0 = load void (i8*)** %__f_addr, align 8
+ call void %0(i8* undef)
+ call i8* @f1(i8* undef) ssp
+ unreachable
+}
+
+define linkonce_odr void @f4(i8* %this) ssp align 2 {
+entry:
+ %0 = alloca i32
+ call void @f3(void (i8*)* @f2) ssp
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/delete-call.ll b/src/LLVM/test/Transforms/Inline/delete-call.ll
new file mode 100644
index 0000000..3505608
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/delete-call.ll
@@ -0,0 +1,22 @@
+; RUN: opt %s -S -inline -functionattrs -stats |& grep {Number of call sites deleted, not inlined}
+; RUN: opt %s -S -inline -stats |& grep {Number of functions inlined}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.8"
+
+define internal i32 @test(i32 %x, i32 %y, i32 %z) nounwind {
+entry:
+ %0 = add nsw i32 %y, %z ; <i32> [#uses=1]
+ %1 = mul i32 %0, %x ; <i32> [#uses=1]
+ %2 = mul i32 %y, %z ; <i32> [#uses=1]
+ %3 = add nsw i32 %1, %2 ; <i32> [#uses=1]
+ ret i32 %3
+}
+
+define i32 @test2() nounwind {
+entry:
+ %0 = call i32 @test(i32 1, i32 2, i32 4) nounwind ; <i32> [#uses=1]
+ ret i32 14
+}
+
+
diff --git a/src/LLVM/test/Transforms/Inline/devirtualize-2.ll b/src/LLVM/test/Transforms/Inline/devirtualize-2.ll
new file mode 100644
index 0000000..02ff767
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/devirtualize-2.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+; PR4834
+
+define i32 @test1() {
+ %funcall1_ = call fastcc i32 ()* ()* @f1()
+ %executecommandptr1_ = call i32 %funcall1_()
+ ret i32 %executecommandptr1_
+}
+
+define internal fastcc i32 ()* @f1() nounwind readnone {
+ ret i32 ()* @f2
+}
+
+define internal i32 @f2() nounwind readnone {
+ ret i32 1
+}
+
+; CHECK: @test1()
+; CHECK-NEXT: ret i32 1
+
+
+
+
+
+declare i8* @f1a(i8*) ssp align 2
+
+define internal i32 @f2a(i8* %t) inlinehint ssp {
+entry:
+ ret i32 41
+}
+
+define internal i32 @f3a(i32 (i8*)* %__f) ssp {
+entry:
+ %A = call i32 %__f(i8* undef)
+ ret i32 %A
+}
+
+define i32 @test2(i8* %this) ssp align 2 {
+ %X = call i32 @f3a(i32 (i8*)* @f2a) ssp
+ ret i32 %X
+}
+
+; CHECK: @test2
+; CHECK-NEXT: ret i32 41
diff --git a/src/LLVM/test/Transforms/Inline/devirtualize-3.ll b/src/LLVM/test/Transforms/Inline/devirtualize-3.ll
new file mode 100644
index 0000000..c32be4e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/devirtualize-3.ll
@@ -0,0 +1,79 @@
+; RUN: opt -basicaa -inline -S -scalarrepl -gvn -instcombine %s | FileCheck %s
+; PR5009
+
+; CHECK: define i32 @main()
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @exit(i32 38)
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+%struct.cont_t = type { void (i8*, i32)*, i8* }
+%struct.foo_sf_t = type { %struct.cont_t*, i32 }
+
+define i32 @main() nounwind ssp {
+entry:
+ %cont = alloca %struct.cont_t, align 8 ; <%struct.cont_t*> [#uses=4]
+ %tmp = getelementptr inbounds %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
+ %tmp1 = getelementptr inbounds %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=2]
+ store void (i8*, i32)* bitcast (void (%struct.cont_t*, i32)* @quit to void (i8*, i32)*), void (i8*, i32)** %tmp1
+ %tmp2 = load void (i8*, i32)** %tmp1 ; <void (i8*, i32)*> [#uses=1]
+ store void (i8*, i32)* %tmp2, void (i8*, i32)** %tmp
+ %tmp3 = getelementptr inbounds %struct.cont_t* %cont, i32 0, i32 1 ; <i8**> [#uses=1]
+ store i8* null, i8** %tmp3
+ call void @foo(%struct.cont_t* %cont)
+ ret i32 0
+}
+
+define internal void @quit(%struct.cont_t* %cont, i32 %rcode) nounwind ssp {
+entry:
+ call void @exit(i32 %rcode) noreturn
+ unreachable
+}
+
+define internal void @foo(%struct.cont_t* %c) nounwind ssp {
+entry:
+ %sf = alloca %struct.foo_sf_t, align 8 ; <%struct.foo_sf_t*> [#uses=3]
+ %next = alloca %struct.cont_t, align 8 ; <%struct.cont_t*> [#uses=3]
+ %tmp = getelementptr inbounds %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
+ store %struct.cont_t* %c, %struct.cont_t** %tmp
+ %tmp2 = getelementptr inbounds %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 2, i32* %tmp2
+ %tmp4 = getelementptr inbounds %struct.cont_t* %next, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
+ store void (i8*, i32)* bitcast (void (%struct.foo_sf_t*, i32)* @foo2 to void (i8*, i32)*), void (i8*, i32)** %tmp4
+ %tmp5 = getelementptr inbounds %struct.cont_t* %next, i32 0, i32 1 ; <i8**> [#uses=1]
+ %conv = bitcast %struct.foo_sf_t* %sf to i8* ; <i8*> [#uses=1]
+ store i8* %conv, i8** %tmp5
+ call void @bar(%struct.cont_t* %next, i32 14)
+ ret void
+}
+
+define internal void @foo2(%struct.foo_sf_t* %sf, i32 %y) nounwind ssp {
+entry:
+ %tmp1 = getelementptr inbounds %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
+ %tmp2 = load %struct.cont_t** %tmp1 ; <%struct.cont_t*> [#uses=1]
+ %tmp3 = getelementptr inbounds %struct.cont_t* %tmp2, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
+ %tmp4 = load void (i8*, i32)** %tmp3 ; <void (i8*, i32)*> [#uses=1]
+ %tmp6 = getelementptr inbounds %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
+ %tmp7 = load %struct.cont_t** %tmp6 ; <%struct.cont_t*> [#uses=1]
+ %conv = bitcast %struct.cont_t* %tmp7 to i8* ; <i8*> [#uses=1]
+ %tmp9 = getelementptr inbounds %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp10 = load i32* %tmp9 ; <i32> [#uses=1]
+ %mul = mul i32 %tmp10, %y ; <i32> [#uses=1]
+ call void %tmp4(i8* %conv, i32 %mul)
+ ret void
+}
+
+define internal void @bar(%struct.cont_t* %c, i32 %y) nounwind ssp {
+entry:
+ %tmp1 = getelementptr inbounds %struct.cont_t* %c, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
+ %tmp2 = load void (i8*, i32)** %tmp1 ; <void (i8*, i32)*> [#uses=1]
+ %tmp4 = getelementptr inbounds %struct.cont_t* %c, i32 0, i32 1 ; <i8**> [#uses=1]
+ %tmp5 = load i8** %tmp4 ; <i8*> [#uses=1]
+ %add = add nsw i32 %y, 5 ; <i32> [#uses=1]
+ call void %tmp2(i8* %tmp5, i32 %add)
+ ret void
+}
+
+declare void @exit(i32) noreturn
+
diff --git a/src/LLVM/test/Transforms/Inline/devirtualize.ll b/src/LLVM/test/Transforms/Inline/devirtualize.ll
new file mode 100644
index 0000000..51ea4ba
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/devirtualize.ll
@@ -0,0 +1,182 @@
+; RUN: opt -S -basicaa -inline -scalarrepl -instcombine -simplifycfg -instcombine -gvn -globaldce %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+
+; Simple devirt testcase, requires iteration between inliner and GVN.
+; rdar://6295824
+define i32 @foo(i32 ()** noalias %p, i64* noalias %q) nounwind ssp {
+entry:
+ store i32 ()* @bar, i32 ()** %p
+ store i64 0, i64* %q
+ %tmp3 = load i32 ()** %p ; <i32 ()*> [#uses=1]
+ %call = call i32 %tmp3() ; <i32> [#uses=1]
+ %X = add i32 %call, 4
+ ret i32 %X
+
+; CHECK: @foo
+; CHECK-NEXT: entry:
+; CHECK-NEXT: store
+; CHECK-NEXT: store
+; CHECK-NEXT: ret i32 11
+}
+
+define internal i32 @bar() nounwind ssp {
+entry:
+ ret i32 7
+}
+
+
+;; More complex devirt case, from PR6724
+; CHECK: @_Z1gv()
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i32 7
+
+%0 = type { i8*, i8* }
+%1 = type { i8*, i8*, i32, i32, i8*, i64, i8*, i64 }
+%2 = type { i8*, i8*, i8* }
+%struct.A = type { i8** }
+%struct.B = type { i8** }
+%struct.C = type { [16 x i8] }
+%struct.D = type { [16 x i8] }
+
+@_ZTV1D = linkonce_odr constant [6 x i8*] [i8* null, i8* bitcast (%2* @_ZTI1D to i8*), i8* bitcast (i32 (%struct.C*)* @_ZN1D1fEv to i8*), i8* inttoptr (i64 -8 to i8*), i8* bitcast (%2* @_ZTI1D to i8*), i8* bitcast (i32 (%struct.C*)* @_ZThn8_N1D1fEv to i8*)] ; <[6 x i8*]*> [#uses=2]
+@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8* ; <i8**> [#uses=1]
+@_ZTS1D = linkonce_odr constant [3 x i8] c"1D\00" ; <[3 x i8]*> [#uses=1]
+@_ZTVN10__cxxabiv121__vmi_class_type_infoE = external global i8* ; <i8**> [#uses=1]
+@_ZTS1C = linkonce_odr constant [3 x i8] c"1C\00" ; <[3 x i8]*> [#uses=1]
+@_ZTVN10__cxxabiv117__class_type_infoE = external global i8* ; <i8**> [#uses=1]
+@_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00" ; <[3 x i8]*> [#uses=1]
+@_ZTI1A = linkonce_odr constant %0 { i8* bitcast (i8** getelementptr inbounds (i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8]* @_ZTS1A, i32 0, i32 0) } ; <%0*> [#uses=1]
+@_ZTS1B = linkonce_odr constant [3 x i8] c"1B\00" ; <[3 x i8]*> [#uses=1]
+@_ZTI1B = linkonce_odr constant %0 { i8* bitcast (i8** getelementptr inbounds (i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8]* @_ZTS1B, i32 0, i32 0) } ; <%0*> [#uses=1]
+@_ZTI1C = linkonce_odr constant %1 { i8* bitcast (i8** getelementptr inbounds (i8** @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8]* @_ZTS1C, i32 0, i32 0), i32 0, i32 2, i8* bitcast (%0* @_ZTI1A to i8*), i64 2, i8* bitcast (%0* @_ZTI1B to i8*), i64 2050 } ; <%1*> [#uses=1]
+@_ZTI1D = linkonce_odr constant %2 { i8* bitcast (i8** getelementptr inbounds (i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8]* @_ZTS1D, i32 0, i32 0), i8* bitcast (%1* @_ZTI1C to i8*) } ; <%2*> [#uses=1]
+@_ZTV1C = linkonce_odr constant [6 x i8*] [i8* null, i8* bitcast (%1* @_ZTI1C to i8*), i8* bitcast (i32 (%struct.C*)* @_ZN1C1fEv to i8*), i8* inttoptr (i64 -8 to i8*), i8* bitcast (%1* @_ZTI1C to i8*), i8* bitcast (i32 (%struct.C*)* @_ZThn8_N1C1fEv to i8*)] ; <[6 x i8*]*> [#uses=2]
+@_ZTV1B = linkonce_odr constant [3 x i8*] [i8* null, i8* bitcast (%0* @_ZTI1B to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1B1fEv to i8*)] ; <[3 x i8*]*> [#uses=1]
+@_ZTV1A = linkonce_odr constant [3 x i8*] [i8* null, i8* bitcast (%0* @_ZTI1A to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A1fEv to i8*)] ; <[3 x i8*]*> [#uses=1]
+
+define i32 @_Z1gv() ssp {
+entry:
+ %d = alloca %struct.C, align 8 ; <%struct.C*> [#uses=2]
+ call void @_ZN1DC1Ev(%struct.C* %d)
+ %call = call i32 @_Z1fP1D(%struct.C* %d) ; <i32> [#uses=1]
+ %X = add i32 %call, 3
+ ret i32 %X
+}
+
+define linkonce_odr void @_ZN1DC1Ev(%struct.C* %this) inlinehint ssp align 2 {
+entry:
+ call void @_ZN1DC2Ev(%struct.C* %this)
+ ret void
+}
+
+define internal i32 @_Z1fP1D(%struct.C* %d) ssp {
+entry:
+ %0 = icmp eq %struct.C* %d, null ; <i1> [#uses=1]
+ br i1 %0, label %cast.end, label %cast.notnull
+
+cast.notnull: ; preds = %entry
+ %1 = bitcast %struct.C* %d to i8* ; <i8*> [#uses=1]
+ %add.ptr = getelementptr i8* %1, i64 8 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %add.ptr to %struct.A* ; <%struct.A*> [#uses=1]
+ br label %cast.end
+
+cast.end: ; preds = %entry, %cast.notnull
+ %3 = phi %struct.A* [ %2, %cast.notnull ], [ null, %entry ] ; <%struct.A*> [#uses=2]
+ %4 = bitcast %struct.A* %3 to i32 (%struct.A*)*** ; <i32 (%struct.A*)***> [#uses=1]
+ %5 = load i32 (%struct.A*)*** %4 ; <i32 (%struct.A*)**> [#uses=1]
+ %vfn = getelementptr inbounds i32 (%struct.A*)** %5, i64 0 ; <i32 (%struct.A*)**> [#uses=1]
+ %6 = load i32 (%struct.A*)** %vfn ; <i32 (%struct.A*)*> [#uses=1]
+ %call = call i32 %6(%struct.A* %3) ; <i32> [#uses=1]
+ ret i32 %call
+}
+
+define linkonce_odr i32 @_ZN1D1fEv(%struct.C* %this) ssp align 2 {
+entry:
+ ret i32 4
+}
+
+define linkonce_odr i32 @_ZThn8_N1D1fEv(%struct.C* %this) {
+entry:
+ %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %1 = getelementptr inbounds i8* %0, i64 -8 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %1 to %struct.C* ; <%struct.C*> [#uses=1]
+ %call = call i32 @_ZN1D1fEv(%struct.C* %2) ; <i32> [#uses=1]
+ ret i32 %call
+}
+
+define linkonce_odr void @_ZN1DC2Ev(%struct.C* %this) inlinehint ssp align 2 {
+entry:
+ call void @_ZN1CC2Ev(%struct.C* %this)
+ %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %1 = getelementptr inbounds i8* %0, i64 0 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([6 x i8*]* @_ZTV1D, i64 0, i64 2), i8*** %2
+ %3 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %4 = getelementptr inbounds i8* %3, i64 8 ; <i8*> [#uses=1]
+ %5 = bitcast i8* %4 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([6 x i8*]* @_ZTV1D, i64 0, i64 5), i8*** %5
+ ret void
+}
+
+define linkonce_odr void @_ZN1CC2Ev(%struct.C* %this) inlinehint ssp align 2 {
+entry:
+ %0 = bitcast %struct.C* %this to %struct.A* ; <%struct.A*> [#uses=1]
+ call void @_ZN1AC2Ev(%struct.A* %0)
+ %1 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %2 = getelementptr inbounds i8* %1, i64 8 ; <i8*> [#uses=1]
+ %3 = bitcast i8* %2 to %struct.A* ; <%struct.A*> [#uses=1]
+ call void @_ZN1BC2Ev(%struct.A* %3)
+ %4 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %5 = getelementptr inbounds i8* %4, i64 0 ; <i8*> [#uses=1]
+ %6 = bitcast i8* %5 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([6 x i8*]* @_ZTV1C, i64 0, i64 2), i8*** %6
+ %7 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %8 = getelementptr inbounds i8* %7, i64 8 ; <i8*> [#uses=1]
+ %9 = bitcast i8* %8 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([6 x i8*]* @_ZTV1C, i64 0, i64 5), i8*** %9
+ ret void
+}
+
+define linkonce_odr i32 @_ZN1C1fEv(%struct.C* %this) ssp align 2 {
+entry:
+ ret i32 3
+}
+
+define linkonce_odr i32 @_ZThn8_N1C1fEv(%struct.C* %this) {
+entry:
+ %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1]
+ %1 = getelementptr inbounds i8* %0, i64 -8 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %1 to %struct.C* ; <%struct.C*> [#uses=1]
+ %call = call i32 @_ZN1C1fEv(%struct.C* %2) ; <i32> [#uses=1]
+ ret i32 %call
+}
+
+define linkonce_odr void @_ZN1AC2Ev(%struct.A* %this) inlinehint ssp align 2 {
+entry:
+ %0 = bitcast %struct.A* %this to i8* ; <i8*> [#uses=1]
+ %1 = getelementptr inbounds i8* %0, i64 0 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1A, i64 0, i64 2), i8*** %2
+ ret void
+}
+
+define linkonce_odr void @_ZN1BC2Ev(%struct.A* %this) inlinehint ssp align 2 {
+entry:
+ %0 = bitcast %struct.A* %this to i8* ; <i8*> [#uses=1]
+ %1 = getelementptr inbounds i8* %0, i64 0 ; <i8*> [#uses=1]
+ %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1]
+ store i8** getelementptr inbounds ([3 x i8*]* @_ZTV1B, i64 0, i64 2), i8*** %2
+ ret void
+}
+
+define linkonce_odr i32 @_ZN1B1fEv(%struct.A* %this) ssp align 2 {
+entry:
+ ret i32 2
+}
+
+define linkonce_odr i32 @_ZN1A1fEv(%struct.A* %this) ssp align 2 {
+entry:
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/Inline/dg.exp b/src/LLVM/test/Transforms/Inline/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/Inline/dynamic_alloca_test.ll b/src/LLVM/test/Transforms/Inline/dynamic_alloca_test.ll
new file mode 100644
index 0000000..171f126
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/dynamic_alloca_test.ll
@@ -0,0 +1,35 @@
+; Test that functions with dynamic allocas get inlined in a case where
+; naively inlining it would result in a miscompilation.
+; Functions with dynamic allocas can only be inlined into functions that
+; already have dynamic allocas.
+
+; RUN: opt < %s -inline -S | \
+; RUN: grep llvm.stacksave
+; RUN: opt < %s -inline -S | not grep callee
+
+
+declare void @ext(i32*)
+
+define internal void @callee(i32 %N) {
+ %P = alloca i32, i32 %N ; <i32*> [#uses=1]
+ call void @ext( i32* %P )
+ ret void
+}
+
+define void @foo(i32 %N) {
+; <label>:0
+ %P = alloca i32, i32 %N ; <i32*> [#uses=1]
+ call void @ext( i32* %P )
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %count = phi i32 [ 0, %0 ], [ %next, %Loop ] ; <i32> [#uses=2]
+ %next = add i32 %count, 1 ; <i32> [#uses=1]
+ call void @callee( i32 %N )
+ %cond = icmp eq i32 %count, 100000 ; <i1> [#uses=1]
+ br i1 %cond, label %out, label %Loop
+
+out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/externally_available.ll b/src/LLVM/test/Transforms/Inline/externally_available.ll
new file mode 100644
index 0000000..08b5638
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/externally_available.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -inline -constprop -S > %t
+; RUN: not grep test_function %t
+; RUN: grep {ret i32 5} %t
+
+
+; test_function should not be emitted to the .s file.
+define available_externally i32 @test_function() {
+ ret i32 4
+}
+
+
+define i32 @result() {
+ %A = call i32 @test_function()
+ %B = add i32 %A, 1
+ ret i32 %B
+}
diff --git a/src/LLVM/test/Transforms/Inline/gvn-inline-iteration.ll b/src/LLVM/test/Transforms/Inline/gvn-inline-iteration.ll
new file mode 100644
index 0000000..e502fd5
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/gvn-inline-iteration.ll
@@ -0,0 +1,23 @@
+; RUN: opt -basicaa -inline -gvn %s -S -max-cg-scc-iterations=1 | FileCheck %s
+; rdar://6295824 and PR6724
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define i32 @foo(i32 ()** noalias nocapture %p, i64* noalias nocapture %q) nounwind ssp {
+entry:
+ store i32 ()* @bar, i32 ()** %p
+ store i64 0, i64* %q
+ %tmp3 = load i32 ()** %p ; <i32 ()*> [#uses=1]
+ %call = tail call i32 %tmp3() nounwind ; <i32> [#uses=1]
+ ret i32 %call
+}
+; CHECK: @foo
+; CHECK: ret i32 7
+; CHECK: @bar
+; CHECK: ret i32 7
+
+define internal i32 @bar() nounwind readnone ssp {
+entry:
+ ret i32 7
+}
diff --git a/src/LLVM/test/Transforms/Inline/inline-invoke-tail.ll b/src/LLVM/test/Transforms/Inline/inline-invoke-tail.ll
new file mode 100644
index 0000000..462c29a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline-invoke-tail.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -inline -S | not grep {tail call void @llvm.memcpy.i32}
+; PR3550
+
+define internal void @foo(i32* %p, i32* %q) {
+ %pp = bitcast i32* %p to i8*
+ %qq = bitcast i32* %q to i8*
+ tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %pp, i8* %qq, i32 4, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.i32(i8* nocapture, i8* nocapture, i32, i32) nounwind
+
+define i32 @main() {
+ %a = alloca i32 ; <i32*> [#uses=3]
+ %b = alloca i32 ; <i32*> [#uses=2]
+ store i32 1, i32* %a, align 4
+ store i32 0, i32* %b, align 4
+ invoke void @foo(i32* %a, i32* %b)
+ to label %invcont unwind label %lpad
+
+invcont:
+ %retval = load i32* %a, align 4
+ ret i32 %retval
+
+lpad:
+ %eh_ptr = call i8* @llvm.eh.exception()
+ %eh_select = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %eh_ptr, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null)
+ unreachable
+}
+
+declare i8* @llvm.eh.exception() nounwind readonly
+
+declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/Inline/inline-tail.ll b/src/LLVM/test/Transforms/Inline/inline-tail.ll
new file mode 100644
index 0000000..05020a6
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline-tail.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -inline -S | not grep tail
+
+declare void @bar(i32*)
+
+define internal void @foo(i32* %P) {
+ tail call void @bar( i32* %P )
+ ret void
+}
+
+define void @caller() {
+ %A = alloca i32 ; <i32*> [#uses=1]
+ call void @foo( i32* %A )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/inline_cleanup.ll b/src/LLVM/test/Transforms/Inline/inline_cleanup.ll
new file mode 100644
index 0000000..1829110
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline_cleanup.ll
@@ -0,0 +1,63 @@
+; Test that the inliner doesn't leave around dead allocas, and that it folds
+; uncond branches away after it is done specializing.
+
+; RUN: opt < %s -inline -S | \
+; RUN: not grep {alloca.*uses=0}
+; RUN: opt < %s -inline -S | \
+; RUN: not grep {br label}
+@A = weak global i32 0 ; <i32*> [#uses=1]
+@B = weak global i32 0 ; <i32*> [#uses=1]
+@C = weak global i32 0 ; <i32*> [#uses=1]
+
+define internal fastcc void @foo(i32 %X) {
+entry:
+ %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
+ %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
+ %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
+ br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ store i32 1, i32* @A
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %entry
+ %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
+ %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
+ br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
+
+cond_true5: ; preds = %cond_next
+ store i32 1, i32* @B
+ br label %cond_next7
+
+cond_next7: ; preds = %cond_true5, %cond_next
+ %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
+ %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
+ br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
+
+cond_true11: ; preds = %cond_next7
+ store i32 1, i32* @C
+ br label %cond_next13
+
+cond_next13: ; preds = %cond_true11, %cond_next7
+ %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
+ %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
+ br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
+
+cond_true17: ; preds = %cond_next13
+ call void @ext( i32* %ALL )
+ ret void
+
+UnifiedReturnBlock: ; preds = %cond_next13
+ ret void
+}
+
+declare void @ext(i32*)
+
+define void @test() {
+entry:
+ tail call fastcc void @foo( i32 1 )
+ tail call fastcc void @foo( i32 2 )
+ tail call fastcc void @foo( i32 3 )
+ tail call fastcc void @foo( i32 8 )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/inline_constprop.ll b/src/LLVM/test/Transforms/Inline/inline_constprop.ll
new file mode 100644
index 0000000..de0a476
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline_constprop.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -inline -S | not grep callee
+; RUN: opt < %s -inline -S | not grep div
+
+
+define internal i32 @callee(i32 %A, i32 %B) {
+ %C = sdiv i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test() {
+ %X = call i32 @callee( i32 10, i32 3 ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/inline_dce.ll b/src/LLVM/test/Transforms/Inline/inline_dce.ll
new file mode 100644
index 0000000..d6fd736
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline_dce.ll
@@ -0,0 +1,25 @@
+; This checks to ensure that the inline pass deletes functions if they get
+; inlined into all of their callers.
+
+; RUN: opt < %s -inline -S | \
+; RUN: not grep @reallysmall
+
+define internal i32 @reallysmall(i32 %A) {
+ ret i32 %A
+}
+
+define void @caller1() {
+ call i32 @reallysmall( i32 5 ) ; <i32>:1 [#uses=0]
+ ret void
+}
+
+define void @caller2(i32 %A) {
+ call i32 @reallysmall( i32 %A ) ; <i32>:1 [#uses=0]
+ ret void
+}
+
+define i32 @caller3(i32 %A) {
+ %B = call i32 @reallysmall( i32 %A ) ; <i32> [#uses=1]
+ ret i32 %B
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/inline_invoke.ll b/src/LLVM/test/Transforms/Inline/inline_invoke.ll
new file mode 100644
index 0000000..9f5f670
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline_invoke.ll
@@ -0,0 +1,342 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+
+; Test that the inliner correctly handles inlining into invoke sites
+; by appending selectors and forwarding _Unwind_Resume directly to the
+; enclosing landing pad.
+
+;; Test 0 - basic functionality.
+
+%struct.A = type { i8 }
+
+@_ZTIi = external constant i8*
+
+declare void @_ZN1AC1Ev(%struct.A*)
+
+declare void @_ZN1AD1Ev(%struct.A*)
+
+declare void @use(i32) nounwind
+
+declare void @opaque()
+
+declare i32 @llvm.eh.typeid.for(i8*) nounwind
+
+declare i32 @__gxx_personality_v0(...)
+
+declare i8* @__cxa_begin_catch(i8*)
+
+declare void @__cxa_end_catch()
+
+declare void @_ZSt9terminatev()
+
+define internal void @test0_in() alwaysinline uwtable ssp {
+entry:
+ %a = alloca %struct.A, align 1
+ %b = alloca %struct.A, align 1
+ call void @_ZN1AC1Ev(%struct.A* %a)
+ invoke void @_ZN1AC1Ev(%struct.A* %b)
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont:
+ invoke void @_ZN1AD1Ev(%struct.A* %b)
+ to label %invoke.cont1 unwind label %lpad
+
+invoke.cont1:
+ call void @_ZN1AD1Ev(%struct.A* %a)
+ ret void
+
+lpad:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ invoke void @_ZN1AD1Ev(%struct.A* %a)
+ to label %invoke.cont2 unwind label %terminate.lpad
+
+invoke.cont2:
+ resume { i8*, i32 } %exn
+
+terminate.lpad:
+ %exn1 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ call void @_ZSt9terminatev() noreturn nounwind
+ unreachable
+}
+
+define void @test0_out() uwtable ssp {
+entry:
+ invoke void @test0_in()
+ to label %ret unwind label %lpad
+
+ret:
+ ret void
+
+lpad: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ %eh.exc = extractvalue { i8*, i32 } %exn, 0
+ %eh.selector = extractvalue { i8*, i32 } %exn, 1
+ %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
+ %1 = icmp eq i32 %eh.selector, %0
+ br i1 %1, label %catch, label %eh.resume
+
+catch:
+ %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
+ call void @__cxa_end_catch() nounwind
+ br label %ret
+
+eh.resume:
+ resume { i8*, i32 } %exn
+}
+
+; CHECK: define void @test0_out()
+; CHECK: [[A:%.*]] = alloca %struct.A,
+; CHECK: [[B:%.*]] = alloca %struct.A,
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
+; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
+; CHECK-NEXT: to label %[[LBL:[^\s]+]] unwind
+; CHECK: [[LBL]]:
+; CHECK-NEXT: br label %[[LPAD:[^\s]+]]
+; CHECK: ret void
+; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: br label %[[LPAD]]
+; CHECK: [[LPAD]]:
+; CHECK-NEXT: phi { i8*, i32 } [
+; CHECK-NEXT: extractvalue { i8*, i32 }
+; CHECK-NEXT: extractvalue { i8*, i32 }
+; CHECK-NEXT: call i32 @llvm.eh.typeid.for(
+
+
+;; Test 1 - Correctly handle phis in outer landing pads.
+
+define void @test1_out() uwtable ssp {
+entry:
+ invoke void @test0_in()
+ to label %cont unwind label %lpad
+
+cont:
+ invoke void @test0_in()
+ to label %ret unwind label %lpad
+
+ret:
+ ret void
+
+lpad:
+ %x = phi i32 [ 0, %entry ], [ 1, %cont ]
+ %y = phi i32 [ 1, %entry ], [ 4, %cont ]
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ %eh.exc = extractvalue { i8*, i32 } %exn, 0
+ %eh.selector = extractvalue { i8*, i32 } %exn, 1
+ %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
+ %1 = icmp eq i32 %eh.selector, %0
+ br i1 %1, label %catch, label %eh.resume
+
+catch:
+ %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
+ call void @use(i32 %x)
+ call void @use(i32 %y)
+ call void @__cxa_end_catch() nounwind
+ br label %ret
+
+eh.resume:
+ resume { i8*, i32 } %exn
+}
+
+; CHECK: define void @test1_out()
+; CHECK: [[A2:%.*]] = alloca %struct.A,
+; CHECK: [[B2:%.*]] = alloca %struct.A,
+; CHECK: [[A1:%.*]] = alloca %struct.A,
+; CHECK: [[B1:%.*]] = alloca %struct.A,
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A1]])
+; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B1]])
+; CHECK-NEXT: unwind label %[[LPAD1:[^\s]+]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B1]])
+; CHECK-NEXT: unwind label %[[LPAD1]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
+; CHECK-NEXT: unwind label %[[LPAD]]
+
+; Inner landing pad from first inlining.
+; CHECK: [[LPAD1]]:
+; CHECK-NEXT: [[LPADVAL1:%.*]] = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
+; CHECK-NEXT: to label %[[RESUME1:[^\s]+]] unwind
+; CHECK: [[RESUME1]]:
+; CHECK-NEXT: br label %[[LPAD_JOIN1:[^\s]+]]
+
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A2]])
+; CHECK-NEXT: unwind label %[[LPAD]]
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B2]])
+; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B2]])
+; CHECK-NEXT: unwind label %[[LPAD2]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
+; CHECK-NEXT: unwind label %[[LPAD]]
+
+; Inner landing pad from second inlining.
+; CHECK: [[LPAD2]]:
+; CHECK-NEXT: [[LPADVAL2:%.*]] = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
+; CHECK-NEXT: to label %[[RESUME2:[^\s]+]] unwind
+; CHECK: [[RESUME2]]:
+; CHECK-NEXT: br label %[[LPAD_JOIN2:[^\s]+]]
+
+; CHECK: ret void
+
+; CHECK: [[LPAD]]:
+; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, %entry ], [ 0, {{%.*}} ], [ 1, %cont ], [ 1, {{%.*}} ]
+; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 1, %entry ], [ 1, {{%.*}} ], [ 4, %cont ], [ 4, {{%.*}} ]
+; CHECK-NEXT: [[LPADVAL:%.*]] = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: br label %[[LPAD_JOIN2]]
+
+; CHECK: [[LPAD_JOIN2]]:
+; CHECK-NEXT: [[XJ2:%.*]] = phi i32 [ [[X]], %[[LPAD]] ], [ 1, %[[RESUME2]] ]
+; CHECK-NEXT: [[YJ2:%.*]] = phi i32 [ [[Y]], %[[LPAD]] ], [ 4, %[[RESUME2]] ]
+; CHECK-NEXT: [[EXNJ2:%.*]] = phi { i8*, i32 } [ [[LPADVAL]], %[[LPAD]] ], [ [[LPADVAL2]], %[[RESUME2]] ]
+; CHECK-NEXT: br label %[[LPAD_JOIN1]]
+
+; CHECK: [[LPAD_JOIN1]]:
+; CHECK-NEXT: [[XJ1:%.*]] = phi i32 [ [[XJ2]], %[[LPAD_JOIN2]] ], [ 0, %[[RESUME1]] ]
+; CHECK-NEXT: [[YJ1:%.*]] = phi i32 [ [[YJ2]], %[[LPAD_JOIN2]] ], [ 1, %[[RESUME1]] ]
+; CHECK-NEXT: [[EXNJ1:%.*]] = phi { i8*, i32 } [ [[EXNJ2]], %[[LPAD_JOIN2]] ], [ [[LPADVAL1]], %[[RESUME1]] ]
+; CHECK-NEXT: extractvalue { i8*, i32 } [[EXNJ1]], 0
+; CHECK-NEXT: [[SELJ1:%.*]] = extractvalue { i8*, i32 } [[EXNJ1]], 1
+; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.eh.typeid.for(
+; CHECK-NEXT: icmp eq i32 [[SELJ1]], [[T]]
+
+; CHECK: call void @use(i32 [[XJ1]])
+; CHECK: call void @use(i32 [[YJ1]])
+
+; CHECK: resume { i8*, i32 }
+
+
+;; Test 2 - Don't make invalid IR for inlines into landing pads without eh.exception calls
+define void @test2_out() uwtable ssp {
+entry:
+ invoke void @test0_in()
+ to label %ret unwind label %lpad
+
+ret:
+ ret void
+
+lpad:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @_ZSt9terminatev()
+ unreachable
+}
+
+; CHECK: define void @test2_out()
+; CHECK: [[A:%.*]] = alloca %struct.A,
+; CHECK: [[B:%.*]] = alloca %struct.A,
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
+; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
+; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
+; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
+; CHECK-NEXT: unwind label %[[LPAD2]]
+; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
+; CHECK-NEXT: unwind label %[[LPAD]]
+
+
+;; Test 3 - Deal correctly with split unwind edges.
+define void @test3_out() uwtable ssp {
+entry:
+ invoke void @test0_in()
+ to label %ret unwind label %lpad
+
+ret:
+ ret void
+
+lpad:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ br label %lpad.cont
+
+lpad.cont:
+ call void @_ZSt9terminatev()
+ unreachable
+}
+
+; CHECK: define void @test3_out()
+; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: invoke void @_ZN1AD1Ev(
+; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
+; CHECK: [[L]]:
+; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: phi { i8*, i32 }
+; CHECK-NEXT: br label %lpad.cont
+; CHECK: lpad.cont:
+; CHECK-NEXT: call void @_ZSt9terminatev()
+
+
+;; Test 4 - Split unwind edges with a dominance problem
+define void @test4_out() uwtable ssp {
+entry:
+ invoke void @test0_in()
+ to label %cont unwind label %lpad.crit
+
+cont:
+ invoke void @opaque()
+ to label %ret unwind label %lpad
+
+ret:
+ ret void
+
+lpad.crit:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ call void @opaque() nounwind
+ br label %terminate
+
+lpad:
+ %exn2 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ br label %terminate
+
+terminate:
+ %phi = phi i32 [ 0, %lpad.crit ], [ 1, %lpad ]
+ call void @use(i32 %phi)
+ call void @_ZSt9terminatev()
+ unreachable
+}
+
+; CHECK: define void @test4_out()
+; CHECK: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: invoke void @_ZN1AD1Ev(
+; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
+; CHECK: [[L]]:
+; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
+; CHECK: invoke void @opaque()
+; CHECK-NEXT: unwind label %lpad
+; CHECK: lpad.crit:
+; CHECK-NEXT: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: phi { i8*, i32 }
+; CHECK-NEXT: call void @opaque() nounwind
+; CHECK-NEXT: br label %[[FIX:[^\s]+]]
+; CHECK: lpad:
+; CHECK-NEXT: landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
+; CHECK-NEXT: br label %[[FIX]]
+; CHECK: [[FIX]]:
+; CHECK-NEXT: [[T1:%.*]] = phi i32 [ 0, %[[JOIN]] ], [ 1, %lpad ]
+; CHECK-NEXT: call void @use(i32 [[T1]])
+; CHECK-NEXT: call void @_ZSt9terminatev()
diff --git a/src/LLVM/test/Transforms/Inline/inline_prune.ll b/src/LLVM/test/Transforms/Inline/inline_prune.ll
new file mode 100644
index 0000000..f2908d7
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/inline_prune.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -inline -S | \
+; RUN: not grep {callee\[12\](}
+; RUN: opt < %s -inline -S | not grep mul
+
+define internal i32 @callee1(i32 %A, i32 %B) {
+ %cond = icmp eq i32 %A, 123 ; <i1> [#uses=1]
+ br i1 %cond, label %T, label %F
+
+T: ; preds = %0
+ %C = mul i32 %B, %B ; <i32> [#uses=1]
+ ret i32 %C
+
+F: ; preds = %0
+ ret i32 0
+}
+
+define internal i32 @callee2(i32 %A, i32 %B) {
+ switch i32 %A, label %T [
+ i32 10, label %F
+ i32 1234, label %G
+ ]
+ ; No predecessors!
+ %cond = icmp eq i32 %A, 123 ; <i1> [#uses=1]
+ br i1 %cond, label %T, label %F
+
+T: ; preds = %1, %0
+ %C = mul i32 %B, %B ; <i32> [#uses=1]
+ ret i32 %C
+
+F: ; preds = %1, %0
+ ret i32 0
+
+G: ; preds = %0
+ %D = mul i32 %B, %B ; <i32> [#uses=1]
+ %E = mul i32 %D, %B ; <i32> [#uses=1]
+ ret i32 %E
+}
+
+define i32 @test(i32 %A) {
+ %X = call i32 @callee1( i32 10, i32 %A ) ; <i32> [#uses=1]
+ %Y = call i32 @callee2( i32 10, i32 %A ) ; <i32> [#uses=1]
+ %Z = add i32 %X, %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/Inline/invoke_test-1.ll b/src/LLVM/test/Transforms/Inline/invoke_test-1.ll
new file mode 100644
index 0000000..5e32e9e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/invoke_test-1.ll
@@ -0,0 +1,28 @@
+; Test that we can inline a simple function, turning the calls in it into invoke
+; instructions
+
+; RUN: opt < %s -inline -S | \
+; RUN: not grep {call\[^e\]}
+
+declare void @might_throw()
+
+define internal void @callee() {
+ call void @might_throw( )
+ ret void
+}
+
+; caller returns true if might_throw throws an exception...
+define i32 @caller() {
+ invoke void @callee( )
+ to label %cont unwind label %exc
+
+cont: ; preds = %0
+ ret i32 0
+
+exc: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 1
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/invoke_test-2.ll b/src/LLVM/test/Transforms/Inline/invoke_test-2.ll
new file mode 100644
index 0000000..f13c3f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/invoke_test-2.ll
@@ -0,0 +1,36 @@
+; Test that if an invoked function is inlined, and if that function cannot
+; throw, that the dead handler is now unreachable.
+
+; RUN: opt < %s -inline -simplifycfg -S | \
+; RUN: not grep UnreachableExceptionHandler
+
+declare void @might_throw()
+
+define internal i32 @callee() {
+ invoke void @might_throw( )
+ to label %cont unwind label %exc
+
+cont: ; preds = %0
+ ret i32 0
+
+exc: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 1
+}
+
+; caller returns true if might_throw throws an exception... callee cannot throw.
+define i32 @caller() {
+ %X = invoke i32 @callee( )
+ to label %cont unwind label %UnreachableExceptionHandler ; <i32> [#uses=1]
+
+cont: ; preds = %0
+ ret i32 %X
+
+UnreachableExceptionHandler: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 -1
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/invoke_test-3.ll b/src/LLVM/test/Transforms/Inline/invoke_test-3.ll
new file mode 100644
index 0000000..741dff2
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/invoke_test-3.ll
@@ -0,0 +1,38 @@
+; Test that any rethrown exceptions in an inlined function are automatically
+; turned into branches to the invoke destination.
+
+; RUN: opt < %s -inline -S | not grep unwind$
+
+declare void @might_throw()
+
+define internal i32 @callee() {
+ invoke void @might_throw( )
+ to label %cont unwind label %exc
+
+cont: ; preds = %0
+ ret i32 0
+
+exc: ; preds = %0a
+ ; This just rethrows the exception!
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %exn
+}
+
+; caller returns true if might_throw throws an exception... which gets
+; propagated by callee.
+define i32 @caller() {
+ %X = invoke i32 @callee( )
+ to label %cont unwind label %Handler ; <i32> [#uses=1]
+
+cont: ; preds = %0
+ ret i32 %X
+
+Handler: ; preds = %0
+; This consumes an exception thrown by might_throw
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 1
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/Inline/lifetime.ll b/src/LLVM/test/Transforms/Inline/lifetime.ll
new file mode 100644
index 0000000..a95c836
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/lifetime.ll
@@ -0,0 +1,78 @@
+; RUN: opt -inline %s -S -o - | FileCheck %s
+
+declare void @llvm.lifetime.start(i64, i8*)
+declare void @llvm.lifetime.end(i64, i8*)
+
+define void @helper_both_markers() {
+ %a = alloca i8
+ call void @llvm.lifetime.start(i64 1, i8* %a)
+ call void @llvm.lifetime.end(i64 1, i8* %a)
+ ret void
+}
+
+define void @test_both_markers() {
+; CHECK: @test_both_markers
+; CHECK: llvm.lifetime.start(i64 1
+; CHECK-NEXT: llvm.lifetime.end(i64 1
+ call void @helper_both_markers()
+; CHECK-NEXT: llvm.lifetime.start(i64 1
+; CHECK-NEXT: llvm.lifetime.end(i64 1
+ call void @helper_both_markers()
+; CHECK-NEXT: ret void
+ ret void
+}
+
+;; Without this, the inliner will simplify out @test_no_marker before adding
+;; any lifetime markers.
+declare void @use(i8* %a)
+
+define void @helper_no_markers() {
+ %a = alloca i8
+ call void @use(i8* %a)
+ ret void
+}
+
+;; We can't use CHECK-NEXT because there's an extra call void @use in between.
+;; Instead, we use CHECK-NOT to verify that there are no other lifetime calls.
+define void @test_no_marker() {
+; CHECK: @test_no_marker
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.start(i64 -1
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.end(i64 -1
+ call void @helper_no_markers()
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.start(i64 -1
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.end(i64 -1
+ call void @helper_no_markers()
+; CHECK-NOT: lifetime
+; CHECK: ret void
+ ret void
+}
+
+define void @helper_two_casts() {
+ %a = alloca i32
+ %b = bitcast i32* %a to i8*
+ call void @llvm.lifetime.start(i64 4, i8* %b)
+ %c = bitcast i32* %a to i8*
+ call void @llvm.lifetime.end(i64 4, i8* %c)
+ ret void
+}
+
+define void @test_two_casts() {
+; CHECK: @test_two_casts
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.start(i64 4
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.end(i64 4
+ call void @helper_two_casts()
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.start(i64 4
+; CHECK-NOT: lifetime
+; CHECK: llvm.lifetime.end(i64 4
+ call void @helper_two_casts()
+; CHECK-NOT: lifetime
+; CHECK: ret void
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/nested-inline.ll b/src/LLVM/test/Transforms/Inline/nested-inline.ll
new file mode 100644
index 0000000..1292667
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/nested-inline.ll
@@ -0,0 +1,111 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+; Test that bar and bar2 are both inlined throughout and removed.
+@A = weak global i32 0 ; <i32*> [#uses=1]
+@B = weak global i32 0 ; <i32*> [#uses=1]
+@C = weak global i32 0 ; <i32*> [#uses=1]
+
+define fastcc void @foo(i32 %X) {
+entry:
+; CHECK: @foo
+ %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
+ %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
+ %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
+ br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ store i32 1, i32* @A
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %entry
+ %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
+ %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
+ br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
+
+cond_true5: ; preds = %cond_next
+ store i32 1, i32* @B
+ br label %cond_next7
+
+cond_next7: ; preds = %cond_true5, %cond_next
+ %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
+ %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
+ br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
+
+cond_true11: ; preds = %cond_next7
+ store i32 1, i32* @C
+ br label %cond_next13
+
+cond_next13: ; preds = %cond_true11, %cond_next7
+ %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
+ %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
+ br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
+
+cond_true17: ; preds = %cond_next13
+ call void @ext( i32* %ALL )
+ ret void
+
+UnifiedReturnBlock: ; preds = %cond_next13
+ ret void
+}
+
+; CHECK-NOT: @bar
+define internal fastcc void @bar(i32 %X) {
+entry:
+ %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
+ %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
+ %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
+ br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ store i32 1, i32* @A
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %entry
+ %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
+ %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
+ br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
+
+cond_true5: ; preds = %cond_next
+ store i32 1, i32* @B
+ br label %cond_next7
+
+cond_next7: ; preds = %cond_true5, %cond_next
+ %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
+ %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
+ br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
+
+cond_true11: ; preds = %cond_next7
+ store i32 1, i32* @C
+ br label %cond_next13
+
+cond_next13: ; preds = %cond_true11, %cond_next7
+ %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
+ %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
+ br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
+
+cond_true17: ; preds = %cond_next13
+ call void @foo( i32 %X )
+ ret void
+
+UnifiedReturnBlock: ; preds = %cond_next13
+ ret void
+}
+
+define internal fastcc void @bar2(i32 %X) {
+entry:
+ call void @foo( i32 %X )
+ ret void
+}
+
+declare void @ext(i32*)
+
+define void @test(i32 %X) {
+entry:
+; CHECK: test
+; CHECK-NOT: @bar
+ tail call fastcc void @bar( i32 %X )
+ tail call fastcc void @bar( i32 %X )
+ tail call fastcc void @bar2( i32 %X )
+ tail call fastcc void @bar2( i32 %X )
+ ret void
+; CHECK: ret
+}
diff --git a/src/LLVM/test/Transforms/Inline/noinline-recursive-fn.ll b/src/LLVM/test/Transforms/Inline/noinline-recursive-fn.ll
new file mode 100644
index 0000000..1d5ebbb
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/noinline-recursive-fn.ll
@@ -0,0 +1,73 @@
+; The inliner should never inline recursive functions into other functions.
+; This effectively is just peeling off the first iteration of a loop, and the
+; inliner heuristics are not set up for this.
+
+; RUN: opt -inline %s -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.3"
+
+@g = common global i32 0 ; <i32*> [#uses=1]
+
+define internal void @foo(i32 %x) nounwind ssp {
+entry:
+ %0 = icmp slt i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+bb: ; preds = %entry
+ %1 = sub nsw i32 %x, 1 ; <i32> [#uses=1]
+ call void @foo(i32 %1) nounwind ssp
+ volatile store i32 1, i32* @g, align 4
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
+
+
+;; CHECK: @bonk
+;; CHECK: call void @foo(i32 42)
+define void @bonk() nounwind ssp {
+entry:
+ call void @foo(i32 42) nounwind ssp
+ ret void
+}
+
+
+
+;; Here is an indirect case that should not be infinitely inlined.
+
+define internal void @f1(i32 %x, i8* %Foo, i8* %Bar) nounwind ssp {
+entry:
+ %0 = bitcast i8* %Bar to void (i32, i8*, i8*)*
+ %1 = sub nsw i32 %x, 1
+ call void %0(i32 %1, i8* %Foo, i8* %Bar) nounwind
+ volatile store i32 42, i32* @g, align 4
+ ret void
+}
+
+define internal void @f2(i32 %x, i8* %Foo, i8* %Bar) nounwind ssp {
+entry:
+ %0 = icmp slt i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %0, label %return, label %bb
+
+bb: ; preds = %entry
+ %1 = bitcast i8* %Foo to void (i32, i8*, i8*)* ; <void (i32, i8*, i8*)*> [#uses=1]
+ call void %1(i32 %x, i8* %Foo, i8* %Bar) nounwind
+ volatile store i32 13, i32* @g, align 4
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
+
+
+; CHECK: @top_level
+; CHECK: call void @f2(i32 122
+; Here we inline one instance of the cycle, but we don't want to completely
+; unroll it.
+define void @top_level() nounwind ssp {
+entry:
+ call void @f2(i32 123, i8* bitcast (void (i32, i8*, i8*)* @f1 to i8*), i8* bitcast (void (i32, i8*, i8*)* @f2 to i8*)) nounwind ssp
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Inline/noinline.ll b/src/LLVM/test/Transforms/Inline/noinline.ll
new file mode 100644
index 0000000..dc3f6e0
--- /dev/null
+++ b/src/LLVM/test/Transforms/Inline/noinline.ll
@@ -0,0 +1,18 @@
+; RUN: opt %s -inline -S | FileCheck %s
+; PR6682
+declare void @foo() nounwind
+
+define void @bar() nounwind {
+entry:
+ tail call void @foo() nounwind
+ ret void
+}
+
+define void @bazz() nounwind {
+entry:
+ tail call void @bar() nounwind noinline
+ ret void
+}
+
+; CHECK: define void @bazz()
+; CHECK: call void @bar()
diff --git a/src/LLVM/test/Transforms/InstCombine/2002-03-11-InstCombineHang.ll b/src/LLVM/test/Transforms/InstCombine/2002-03-11-InstCombineHang.ll
new file mode 100644
index 0000000..dad5798
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2002-03-11-InstCombineHang.ll
@@ -0,0 +1,9 @@
+; This testcase causes instcombine to hang.
+;
+; RUN: opt < %s -instcombine
+
+define void @test(i32 %X) {
+ %reg117 = add i32 %X, 0 ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2002-05-14-SubFailure.ll b/src/LLVM/test/Transforms/InstCombine/2002-05-14-SubFailure.ll
new file mode 100644
index 0000000..642d206
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2002-05-14-SubFailure.ll
@@ -0,0 +1,10 @@
+; Instcombine was missing a test that caused it to make illegal transformations
+; sometimes. In this case, it transforms the sub into an add:
+; RUN: opt < %s -instcombine -S | grep sub
+;
+define i32 @test(i32 %i, i32 %j) {
+ %A = mul i32 %i, %j
+ %B = sub i32 2, %A
+ ret i32 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2002-08-02-CastTest.ll b/src/LLVM/test/Transforms/InstCombine/2002-08-02-CastTest.ll
new file mode 100644
index 0000000..5add123
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2002-08-02-CastTest.ll
@@ -0,0 +1,11 @@
+; This testcase is incorrectly getting completely eliminated. There should be
+; SOME instruction named %c here, even if it's a bitwise and.
+;
+; RUN: opt < %s -instcombine -S | grep %c
+;
+define i64 @test3(i64 %A) {
+ %c1 = trunc i64 %A to i8 ; <i8> [#uses=1]
+ %c2 = zext i8 %c1 to i64 ; <i64> [#uses=1]
+ ret i64 %c2
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2002-12-05-MissedConstProp.ll b/src/LLVM/test/Transforms/InstCombine/2002-12-05-MissedConstProp.ll
new file mode 100644
index 0000000..394cdca
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2002-12-05-MissedConstProp.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | not grep add
+
+define i32 @test(i32 %A) {
+ %A.neg = sub i32 0, %A ; <i32> [#uses=1]
+ %.neg = sub i32 0, 1 ; <i32> [#uses=1]
+ %X = add i32 %.neg, 1 ; <i32> [#uses=1]
+ %Y.neg.ra = add i32 %A, %X ; <i32> [#uses=1]
+ %r = add i32 %A.neg, %Y.neg.ra ; <i32> [#uses=1]
+ ret i32 %r
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-05-26-CastMiscompile.ll b/src/LLVM/test/Transforms/InstCombine/2003-05-26-CastMiscompile.ll
new file mode 100644
index 0000000..709ebfc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-05-26-CastMiscompile.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep 4294967295
+
+define i64 @test(i64 %Val) {
+ %tmp.3 = trunc i64 %Val to i32 ; <i32> [#uses=1]
+ %tmp.8 = zext i32 %tmp.3 to i64 ; <i64> [#uses=1]
+ ret i64 %tmp.8
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-05-27-ConstExprCrash.ll b/src/LLVM/test/Transforms/InstCombine/2003-05-27-ConstExprCrash.ll
new file mode 100644
index 0000000..c3da050
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-05-27-ConstExprCrash.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+
+@X = global i32 5 ; <i32*> [#uses=1]
+
+define i64 @test() {
+ %C = add i64 1, 2 ; <i64> [#uses=1]
+ %V = add i64 ptrtoint (i32* @X to i64), %C ; <i64> [#uses=1]
+ ret i64 %V
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-06-05-BranchInvertInfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2003-06-05-BranchInvertInfLoop.ll
new file mode 100644
index 0000000..ebcc75f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-06-05-BranchInvertInfLoop.ll
@@ -0,0 +1,16 @@
+; This testcase causes an infinite loop in the instruction combiner,
+; because it things that the constant value is a not expression... and
+; constantly inverts the branch back and forth.
+;
+; RUN: opt < %s -instcombine -disable-output
+
+define i8 @test19(i1 %c) {
+ br i1 true, label %True, label %False
+
+True: ; preds = %0
+ ret i8 1
+
+False: ; preds = %0
+ ret i8 3
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-07-21-ExternalConstant.ll b/src/LLVM/test/Transforms/InstCombine/2003-07-21-ExternalConstant.ll
new file mode 100644
index 0000000..eff5f4c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-07-21-ExternalConstant.ll
@@ -0,0 +1,44 @@
+;
+; Test: ExternalConstant
+;
+; Description:
+; This regression test helps check whether the instruction combining
+; optimization pass correctly handles global variables which are marked
+; as external and constant.
+;
+; If a problem occurs, we should die on an assert(). Otherwise, we
+; should pass through the optimizer without failure.
+;
+; Extra code:
+; RUN: opt < %s -instcombine
+; END.
+
+target datalayout = "e-p:32:32"
+@silly = external constant i32 ; <i32*> [#uses=1]
+
+declare void @bzero(i8*, i32)
+
+declare void @bcopy(i8*, i8*, i32)
+
+declare i32 @bcmp(i8*, i8*, i32)
+
+declare i32 @fputs(i8*, i8*)
+
+declare i32 @fputs_unlocked(i8*, i8*)
+
+define i32 @function(i32 %a.1) {
+entry:
+ %a.0 = alloca i32 ; <i32*> [#uses=2]
+ %result = alloca i32 ; <i32*> [#uses=2]
+ store i32 %a.1, i32* %a.0
+ %tmp.0 = load i32* %a.0 ; <i32> [#uses=1]
+ %tmp.1 = load i32* @silly ; <i32> [#uses=1]
+ %tmp.2 = add i32 %tmp.0, %tmp.1 ; <i32> [#uses=1]
+ store i32 %tmp.2, i32* %result
+ br label %return
+
+return: ; preds = %entry
+ %tmp.3 = load i32* %result ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-08-12-AllocaNonNull.ll b/src/LLVM/test/Transforms/InstCombine/2003-08-12-AllocaNonNull.ll
new file mode 100644
index 0000000..d3db282
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-08-12-AllocaNonNull.ll
@@ -0,0 +1,20 @@
+; This testcase can be simplified by "realizing" that alloca can never return
+; null.
+; RUN: opt < %s -instcombine -simplifycfg -S | not grep br
+
+declare i32 @bitmap_clear(...)
+
+define i32 @oof() {
+entry:
+ %live_head = alloca i32 ; <i32*> [#uses=2]
+ %tmp.1 = icmp ne i32* %live_head, null ; <i1> [#uses=1]
+ br i1 %tmp.1, label %then, label %UnifiedExitNode
+
+then: ; preds = %entry
+ %tmp.4 = call i32 (...)* @bitmap_clear( i32* %live_head ) ; <i32> [#uses=0]
+ br label %UnifiedExitNode
+
+UnifiedExitNode: ; preds = %then, %entry
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-09-09-VolatileLoadElim.ll b/src/LLVM/test/Transforms/InstCombine/2003-09-09-VolatileLoadElim.ll
new file mode 100644
index 0000000..60dee1f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-09-09-VolatileLoadElim.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep load
+
+define void @test(i32* %P) {
+ ; Dead but not deletable!
+ %X = volatile load i32* %P ; <i32> [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-10-29-CallSiteResolve.ll b/src/LLVM/test/Transforms/InstCombine/2003-10-29-CallSiteResolve.ll
new file mode 100644
index 0000000..09d1421
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-10-29-CallSiteResolve.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -disable-output
+
+declare i32* @bar()
+
+define float* @foo() {
+ %tmp.11 = invoke float* bitcast (i32* ()* @bar to float* ()*)( )
+ to label %invoke_cont unwind label %X ; <float*> [#uses=1]
+
+invoke_cont: ; preds = %0
+ ret float* %tmp.11
+
+X: ; preds = %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret float* null
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2003-11-03-VarargsCallBug.ll b/src/LLVM/test/Transforms/InstCombine/2003-11-03-VarargsCallBug.ll
new file mode 100644
index 0000000..fa2dee6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2003-11-03-VarargsCallBug.ll
@@ -0,0 +1,13 @@
+; The cast in this testcase is not eliminable on a 32-bit target!
+; RUN: opt < %s -instcombine -S | grep inttoptr
+
+target datalayout = "e-p:32:32"
+
+declare void @foo(...)
+
+define void @test(i64 %X) {
+ %Y = inttoptr i64 %X to i32* ; <i32*> [#uses=1]
+ call void (...)* @foo( i32* %Y )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-01-13-InstCombineInvokePHI.ll b/src/LLVM/test/Transforms/InstCombine/2004-01-13-InstCombineInvokePHI.ll
new file mode 100644
index 0000000..bb2d379
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-01-13-InstCombineInvokePHI.ll
@@ -0,0 +1,31 @@
+; Test for a problem afflicting several C++ programs in the testsuite. The
+; instcombine pass is trying to get rid of the cast in the invoke instruction,
+; inserting a cast of the return value after the PHI instruction, but which is
+; used by the PHI instruction. This is bad: because of the semantics of the
+; invoke instruction, we really cannot perform this transformation at all at
+; least without splitting the critical edge.
+;
+; RUN: opt < %s -instcombine -disable-output
+
+declare i8* @test()
+
+define i32 @foo() {
+entry:
+ br i1 true, label %cont, label %call
+
+call: ; preds = %entry
+ %P = invoke i32* bitcast (i8* ()* @test to i32* ()*)( )
+ to label %cont unwind label %N ; <i32*> [#uses=1]
+
+cont: ; preds = %call, %entry
+ %P2 = phi i32* [ %P, %call ], [ null, %entry ] ; <i32*> [#uses=1]
+ %V = load i32* %P2 ; <i32> [#uses=1]
+ ret i32 %V
+
+N: ; preds = %call
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i32 0
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-02-23-ShiftShiftOverflow.ll b/src/LLVM/test/Transforms/InstCombine/2004-02-23-ShiftShiftOverflow.ll
new file mode 100644
index 0000000..64d9660
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-02-23-ShiftShiftOverflow.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | not grep 34
+
+define i32 @test(i32 %X) {
+ ; Do not fold into shr X, 34, as this uses undefined behavior!
+ %Y = ashr i32 %X, 17 ; <i32> [#uses=1]
+ %Z = ashr i32 %Y, 17 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test2(i32 %X) {
+ ; Do not fold into shl X, 34, as this uses undefined behavior!
+ %Y = shl i32 %X, 17 ; <i32> [#uses=1]
+ %Z = shl i32 %Y, 17 ; <i32> [#uses=1]
+ ret i32 %Z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-03-13-InstCombineInfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2004-03-13-InstCombineInfLoop.ll
new file mode 100644
index 0000000..1ceab8e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-03-13-InstCombineInfLoop.ll
@@ -0,0 +1,13 @@
+; This testcase caused the combiner to go into an infinite loop, moving the
+; cast back and forth, changing the seteq to operate on int vs uint and back.
+
+; RUN: opt < %s -instcombine -disable-output
+
+define i1 @test(i32 %A, i32 %B) {
+ %C = sub i32 0, %A ; <i32> [#uses=1]
+ %Cc = bitcast i32 %C to i32 ; <i32> [#uses=1]
+ %D = sub i32 0, %B ; <i32> [#uses=1]
+ %E = icmp eq i32 %Cc, %D ; <i1> [#uses=1]
+ ret i1 %E
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll b/src/LLVM/test/Transforms/InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll
new file mode 100644
index 0000000..30d2e47
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define i32 @test() {
+ ret i32 0
+
+Loop: ; preds = %Loop
+ %X = add i32 %X, 1 ; <i32> [#uses=1]
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-05-07-UnsizedCastLoad.ll b/src/LLVM/test/Transforms/InstCombine/2004-05-07-UnsizedCastLoad.ll
new file mode 100644
index 0000000..df56d07
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-05-07-UnsizedCastLoad.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+
+%Ty = type opaque
+
+define i32 @test(%Ty* %X) {
+ %Y = bitcast %Ty* %X to i32* ; <i32*> [#uses=1]
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-07-27-ConstantExprMul.ll b/src/LLVM/test/Transforms/InstCombine/2004-07-27-ConstantExprMul.ll
new file mode 100644
index 0000000..ee19cbc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-07-27-ConstantExprMul.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -disable-output
+
+@p = weak global i32 0 ; <i32*> [#uses=1]
+
+define i32 @test(i32 %x) {
+ %y = mul i32 %x, ptrtoint (i32* @p to i32) ; <i32> [#uses=1]
+ ret i32 %y
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-08-09-RemInfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2004-08-09-RemInfLoop.ll
new file mode 100644
index 0000000..da55d85
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-08-09-RemInfLoop.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine
+
+; This testcase should not send the instcombiner into an infinite loop!
+
+define i32 @test(i32 %X) {
+ %Y = srem i32 %X, 0 ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-08-10-BoolSetCC.ll b/src/LLVM/test/Transforms/InstCombine/2004-08-10-BoolSetCC.ll
new file mode 100644
index 0000000..20b681c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-08-10-BoolSetCC.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {ret i1 false}
+
+define i1 @test(i1 %V) {
+ %Y = icmp ult i1 %V, false ; <i1> [#uses=1]
+ ret i1 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine.ll b/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine.ll
new file mode 100644
index 0000000..30a3f4e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -mem2reg -S | \
+; RUN: not grep {i32 1}
+
+; When propagating the load through the select, make sure that the load is
+; inserted where the original load was, not where the select is. Not doing
+; so could produce incorrect results!
+
+define i32 @test(i1 %C) {
+ %X = alloca i32 ; <i32*> [#uses=3]
+ %X2 = alloca i32 ; <i32*> [#uses=2]
+ store i32 1, i32* %X
+ store i32 2, i32* %X2
+ %Y = select i1 %C, i32* %X, i32* %X2 ; <i32*> [#uses=1]
+ store i32 3, i32* %X
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine2.ll b/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine2.ll
new file mode 100644
index 0000000..8b70d74
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-09-20-BadLoadCombine2.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine -mem2reg -simplifycfg | \
+; RUN: llvm-dis | grep -v store | not grep {i32 1}
+
+; Test to make sure that instcombine does not accidentally propagate the load
+; into the PHI, which would break the program.
+
+define i32 @test(i1 %C) {
+entry:
+ %X = alloca i32 ; <i32*> [#uses=3]
+ %X2 = alloca i32 ; <i32*> [#uses=2]
+ store i32 1, i32* %X
+ store i32 2, i32* %X2
+ br i1 %C, label %cond_true.i, label %cond_continue.i
+
+cond_true.i: ; preds = %entry
+ br label %cond_continue.i
+
+cond_continue.i: ; preds = %cond_true.i, %entry
+ %mem_tmp.i.0 = phi i32* [ %X, %cond_true.i ], [ %X2, %entry ] ; <i32*> [#uses=1]
+ store i32 3, i32* %X
+ %tmp.3 = load i32* %mem_tmp.i.0 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.ll b/src/LLVM/test/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.ll
new file mode 100644
index 0000000..f8861a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep -- -65536
+
+define i1 @test(i32 %tmp.124) {
+ %tmp.125 = shl i32 %tmp.124, 8 ; <i32> [#uses=1]
+ %tmp.126.mask = and i32 %tmp.125, -16777216 ; <i32> [#uses=1]
+ %tmp.128 = icmp eq i32 %tmp.126.mask, 167772160 ; <i1> [#uses=1]
+ ret i1 %tmp.128
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-11-22-Missed-and-fold.ll b/src/LLVM/test/Transforms/InstCombine/2004-11-22-Missed-and-fold.ll
new file mode 100644
index 0000000..b851b98
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-11-22-Missed-and-fold.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | not grep and
+
+define i8 @test21(i8 %A) {
+ ;; sign extend
+ %C = ashr i8 %A, 7 ; <i8> [#uses=1]
+ ;; chop off sign
+ %D = and i8 %C, 1 ; <i8> [#uses=1]
+ ret i8 %D
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-11-27-SetCCForCastLargerAndConstant.ll b/src/LLVM/test/Transforms/InstCombine/2004-11-27-SetCCForCastLargerAndConstant.ll
new file mode 100644
index 0000000..dfd8c6d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-11-27-SetCCForCastLargerAndConstant.ll
@@ -0,0 +1,192 @@
+; This test case tests the InstructionCombining optimization that
+; reduces things like:
+; %Y = sext i8 %X to i32
+; %C = icmp ult i32 %Y, 1024
+; to
+; %C = i1 true
+; It includes test cases for different constant values, signedness of the
+; cast operands, and types of setCC operators. In all cases, the cast should
+; be eliminated. In many cases the setCC is also eliminated based on the
+; constant value and the range of the casted value.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; END.
+define i1 @lt_signed_to_large_unsigned(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C1 = icmp sgt i8 %SB, -1
+; CHECK: ret i1 %C1
+}
+
+define i1 @lt_signed_to_large_signed(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @lt_signed_to_large_negative(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, -1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @lt_signed_to_small_unsigned(i8 %SB) {
+ %Y = sext i8 %SB to i32
+ %C = icmp ult i32 %Y, 17
+ ret i1 %C
+; CHECK: %C = icmp ult i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @lt_signed_to_small_signed(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, 17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp slt i8 %SB, 17
+; CHECK: ret i1 %C
+}
+define i1 @lt_signed_to_small_negative(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp slt i8 %SB, -17
+; CHECK: ret i1 %C
+}
+
+define i1 @lt_unsigned_to_large_unsigned(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @lt_unsigned_to_large_signed(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @lt_unsigned_to_large_negative(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, -1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @lt_unsigned_to_small_unsigned(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ult i32 %Y, 17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp ult i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @lt_unsigned_to_small_signed(i8 %SB) {
+ %Y = zext i8 %SB to i32
+ %C = icmp slt i32 %Y, 17
+ ret i1 %C
+; CHECK: %C = icmp ult i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @lt_unsigned_to_small_negative(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @gt_signed_to_large_unsigned(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp slt i8 %SB, 0
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_signed_to_large_signed(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @gt_signed_to_large_negative(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @gt_signed_to_small_unsigned(i8 %SB) {
+ %Y = sext i8 %SB to i32
+ %C = icmp ugt i32 %Y, 17
+ ret i1 %C
+; CHECK: %C = icmp ugt i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_signed_to_small_signed(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, 17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp sgt i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_signed_to_small_negative(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp sgt i8 %SB, -17
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_unsigned_to_large_unsigned(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @gt_unsigned_to_large_signed(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @gt_unsigned_to_large_negative(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @gt_unsigned_to_small_unsigned(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp ugt i32 %Y, 17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp ugt i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_unsigned_to_small_signed(i8 %SB) {
+ %Y = zext i8 %SB to i32
+ %C = icmp sgt i32 %Y, 17
+ ret i1 %C
+; CHECK: %C = icmp ugt i8 %SB, 17
+; CHECK: ret i1 %C
+}
+
+define i1 @gt_unsigned_to_small_negative(i8 %SB) {
+ %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2004-12-08-RemInfiniteLoop.ll b/src/LLVM/test/Transforms/InstCombine/2004-12-08-RemInfiniteLoop.ll
new file mode 100644
index 0000000..a5d4e03
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2004-12-08-RemInfiniteLoop.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine
+
+define i32 @test(i32 %X) {
+ %Y = srem i32 %X, undef ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-03-04-ShiftOverflow.ll b/src/LLVM/test/Transforms/InstCombine/2005-03-04-ShiftOverflow.ll
new file mode 100644
index 0000000..1842566
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-03-04-ShiftOverflow.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep {ret i1 false}
+
+define i1 @test(i64 %tmp.169) {
+ %tmp.1710 = lshr i64 %tmp.169, 1 ; <i64> [#uses=1]
+ %tmp.1912 = icmp ugt i64 %tmp.1710, 0 ; <i1> [#uses=1]
+ ret i1 %tmp.1912
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-04-07-UDivSelectCrash.ll b/src/LLVM/test/Transforms/InstCombine/2005-04-07-UDivSelectCrash.ll
new file mode 100644
index 0000000..d709f19
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-04-07-UDivSelectCrash.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define i32 @test(i1 %C, i32 %tmp.15) {
+ %tmp.16 = select i1 %C, i32 8, i32 1 ; <i32> [#uses=1]
+ %tmp.18 = udiv i32 %tmp.15, %tmp.16 ; <i32> [#uses=1]
+ ret i32 %tmp.18
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-06-15-DivSelectCrash.ll b/src/LLVM/test/Transforms/InstCombine/2005-06-15-DivSelectCrash.ll
new file mode 100644
index 0000000..1cb10a2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-06-15-DivSelectCrash.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define i32 @_Z13func_31585107li(i32 %l_39521025, i32 %l_59244666) {
+ %shortcirc_val = select i1 false, i32 1, i32 0 ; <i32> [#uses=1]
+ %tmp.8 = udiv i32 0, %shortcirc_val ; <i32> [#uses=1]
+ %tmp.9 = icmp eq i32 %tmp.8, 0 ; <i1> [#uses=1]
+ %retval = select i1 %tmp.9, i32 %l_59244666, i32 -1621308501 ; <i32> [#uses=1]
+ ret i32 %retval
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-06-15-ShiftSetCCCrash.ll b/src/LLVM/test/Transforms/InstCombine/2005-06-15-ShiftSetCCCrash.ll
new file mode 100644
index 0000000..bfdc0c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-06-15-ShiftSetCCCrash.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR577
+
+define i1 @test() {
+ %tmp.3 = shl i32 0, 41 ; <i32> [#uses=1]
+ %tmp.4 = icmp ne i32 %tmp.3, 0 ; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-06-16-RangeCrash.ll b/src/LLVM/test/Transforms/InstCombine/2005-06-16-RangeCrash.ll
new file mode 100644
index 0000000..2ce7aaa
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-06-16-RangeCrash.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR585
+
+define i1 @test() {
+ %tmp.26 = sdiv i32 0, -2147483648 ; <i32> [#uses=1]
+ %tmp.27 = icmp eq i32 %tmp.26, 0 ; <i1> [#uses=1]
+ ret i1 %tmp.27
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-06-16-SetCCOrSetCCMiscompile.ll b/src/LLVM/test/Transforms/InstCombine/2005-06-16-SetCCOrSetCCMiscompile.ll
new file mode 100644
index 0000000..6d91094
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-06-16-SetCCOrSetCCMiscompile.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {ret i1 true}
+; PR586
+
+@g_07918478 = external global i32 ; <i32*> [#uses=1]
+
+define i1 @test() {
+ %tmp.0 = load i32* @g_07918478 ; <i32> [#uses=2]
+ %tmp.1 = icmp ne i32 %tmp.0, 0 ; <i1> [#uses=1]
+ %tmp.4 = icmp ult i32 %tmp.0, 4111 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp.1, %tmp.4 ; <i1> [#uses=1]
+ ret i1 %bothcond
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2005-07-07-DeadPHILoop.ll b/src/LLVM/test/Transforms/InstCombine/2005-07-07-DeadPHILoop.ll
new file mode 100644
index 0000000..d404b10
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2005-07-07-DeadPHILoop.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -disable-output
+
+; This example caused instcombine to spin into an infinite loop.
+
+define void @test(i32* %P) {
+ ret void
+
+Dead: ; preds = %Dead
+ %X = phi i32 [ %Y, %Dead ] ; <i32> [#uses=1]
+ %Y = sdiv i32 %X, 10 ; <i32> [#uses=2]
+ store i32 %Y, i32* %P
+ br label %Dead
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-02-13-DemandedMiscompile.ll b/src/LLVM/test/Transforms/InstCombine/2006-02-13-DemandedMiscompile.ll
new file mode 100644
index 0000000..8c61efe
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-02-13-DemandedMiscompile.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep undef
+
+define i32 @test(i8 %A) {
+ %B = sext i8 %A to i32 ; <i32> [#uses=1]
+ %C = ashr i32 %B, 8 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-02-28-Crash.ll b/src/LLVM/test/Transforms/InstCombine/2006-02-28-Crash.ll
new file mode 100644
index 0000000..4857880
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-02-28-Crash.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define i32 @test() {
+ %tmp203 = icmp eq i32 1, 2 ; <i1> [#uses=1]
+ %tmp203.upgrd.1 = zext i1 %tmp203 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp203.upgrd.1
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-03-30-ExtractElement.ll b/src/LLVM/test/Transforms/InstCombine/2006-03-30-ExtractElement.ll
new file mode 100644
index 0000000..5decc21
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-03-30-ExtractElement.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define float @test(<4 x float> %V) {
+ %V2 = insertelement <4 x float> %V, float 1.000000e+00, i32 3 ; <<4 x float>> [#uses=1]
+ %R = extractelement <4 x float> %V2, i32 2 ; <float> [#uses=1]
+ ret float %R
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-04-28-ShiftShiftLongLong.ll b/src/LLVM/test/Transforms/InstCombine/2006-04-28-ShiftShiftLongLong.ll
new file mode 100644
index 0000000..28075c0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-04-28-ShiftShiftLongLong.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; This cannot be turned into a sign extending cast!
+
+define i64 @test(i64 %X) {
+ %Y = shl i64 %X, 16 ; <i64> [#uses=1]
+; CHECK: %Y = shl i64 %X, 16
+ %Z = ashr i64 %Y, 16 ; <i64> [#uses=1]
+; CHECK: %Z = ashr exact i64 %Y, 16
+ ret i64 %Z
+; CHECK: ret i64 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-05-04-DemandedBitCrash.ll b/src/LLVM/test/Transforms/InstCombine/2006-05-04-DemandedBitCrash.ll
new file mode 100644
index 0000000..b328b7b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-05-04-DemandedBitCrash.ll
@@ -0,0 +1,51 @@
+; RUN: opt < %s -instcombine -disable-output
+; END.
+
+define void @test() {
+bb38.i:
+ %varspec.0.i1014 = bitcast i64 123814269237067777 to i64 ; <i64> [#uses=1]
+ %locspec.0.i1015 = bitcast i32 1 to i32 ; <i32> [#uses=2]
+ %tmp51391.i1018 = lshr i64 %varspec.0.i1014, 16 ; <i64> [#uses=1]
+ %tmp51392.i1019 = trunc i64 %tmp51391.i1018 to i32 ; <i32> [#uses=2]
+ %tmp51392.mask.i1020 = lshr i32 %tmp51392.i1019, 29 ; <i32> [#uses=1]
+ %tmp7.i1021 = and i32 %tmp51392.mask.i1020, 1 ; <i32> [#uses=2]
+ %tmp18.i1026 = lshr i32 %tmp51392.i1019, 31 ; <i32> [#uses=2]
+ %tmp18.i1027 = trunc i32 %tmp18.i1026 to i8 ; <i8> [#uses=1]
+ br i1 false, label %cond_false1148.i1653, label %bb377.i1259
+
+bb377.i1259: ; preds = %bb38.i
+ br i1 false, label %cond_true541.i1317, label %cond_false1148.i1653
+
+cond_true541.i1317: ; preds = %bb377.i1259
+ %tmp545.i1318 = lshr i32 %locspec.0.i1015, 10 ; <i32> [#uses=1]
+ %tmp550.i1319 = lshr i32 %locspec.0.i1015, 4 ; <i32> [#uses=1]
+ %tmp550551.i1320 = and i32 %tmp550.i1319, 63 ; <i32> [#uses=1]
+ %tmp553.i1321 = icmp ult i32 %tmp550551.i1320, 4 ; <i1> [#uses=1]
+ %tmp558.i1322 = icmp eq i32 %tmp7.i1021, 0 ; <i1> [#uses=1]
+ %bothcond.i1326 = or i1 %tmp553.i1321, false ; <i1> [#uses=1]
+ %bothcond1.i1327 = or i1 %bothcond.i1326, false ; <i1> [#uses=1]
+ %bothcond2.not.i1328 = or i1 %bothcond1.i1327, false ; <i1> [#uses=1]
+ %bothcond3.i1329 = or i1 %bothcond2.not.i1328, %tmp558.i1322 ; <i1> [#uses=0]
+ br i1 false, label %cond_true583.i1333, label %cond_next592.i1337
+
+cond_true583.i1333: ; preds = %cond_true541.i1317
+ br i1 false, label %cond_true586.i1335, label %cond_next592.i1337
+
+cond_true586.i1335: ; preds = %cond_true583.i1333
+ br label %cond_true.i
+
+cond_next592.i1337: ; preds = %cond_true583.i1333, %cond_true541.i1317
+ %mask_z.0.i1339 = phi i32 [ %tmp18.i1026, %cond_true541.i1317 ], [ 0, %cond_true583.i1333 ] ; <i32> [#uses=0]
+ %tmp594.i1340 = and i32 %tmp545.i1318, 15 ; <i32> [#uses=0]
+ br label %cond_true.i
+
+cond_false1148.i1653: ; preds = %bb377.i1259, %bb38.i
+ %tmp1150.i1654 = icmp eq i32 %tmp7.i1021, 0 ; <i1> [#uses=1]
+ %tmp1160.i1656 = icmp eq i8 %tmp18.i1027, 0 ; <i1> [#uses=1]
+ %bothcond8.i1658 = or i1 %tmp1150.i1654, %tmp1160.i1656 ; <i1> [#uses=1]
+ %bothcond9.i1659 = or i1 %bothcond8.i1658, false ; <i1> [#uses=0]
+ br label %cond_true.i
+
+cond_true.i: ; preds = %cond_false1148.i1653, %cond_next592.i1337, %cond_true586.i1335
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-09-15-CastToBool.ll b/src/LLVM/test/Transforms/InstCombine/2006-09-15-CastToBool.ll
new file mode 100644
index 0000000..128bdc4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-09-15-CastToBool.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep and
+; PR913
+
+define i32 @test(i32* %tmp1) {
+ %tmp.i = load i32* %tmp1 ; <i32> [#uses=1]
+ %tmp = bitcast i32 %tmp.i to i32 ; <i32> [#uses=1]
+ %tmp2.ui = lshr i32 %tmp, 5 ; <i32> [#uses=1]
+ %tmp2 = bitcast i32 %tmp2.ui to i32 ; <i32> [#uses=1]
+ %tmp3 = and i32 %tmp2, 1 ; <i32> [#uses=1]
+ %tmp3.upgrd.1 = icmp ne i32 %tmp3, 0 ; <i1> [#uses=1]
+ %tmp34 = zext i1 %tmp3.upgrd.1 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp34
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll b/src/LLVM/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll
new file mode 100644
index 0000000..252786e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll
@@ -0,0 +1,10 @@
+; The optimizer should be able to remove cast operation here.
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep sext.*i32
+
+define i1 @eq_signed_to_small_unsigned(i8 %SB) {
+ %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
+ %C = icmp eq i32 %Y, 17 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-10-20-mask.ll b/src/LLVM/test/Transforms/InstCombine/2006-10-20-mask.ll
new file mode 100644
index 0000000..2cdcfc7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-10-20-mask.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep and
+
+define i64 @foo(i64 %tmp, i64 %tmp2) {
+ %tmp.upgrd.1 = trunc i64 %tmp to i32 ; <i32> [#uses=1]
+ %tmp2.upgrd.2 = trunc i64 %tmp2 to i32 ; <i32> [#uses=1]
+ %tmp3 = and i32 %tmp.upgrd.1, %tmp2.upgrd.2 ; <i32> [#uses=1]
+ %tmp4 = zext i32 %tmp3 to i64 ; <i64> [#uses=1]
+ ret i64 %tmp4
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-10-26-VectorReassoc.ll b/src/LLVM/test/Transforms/InstCombine/2006-10-26-VectorReassoc.ll
new file mode 100644
index 0000000..1541191
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-10-26-VectorReassoc.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep mul | count 2
+
+define <4 x float> @test(<4 x float> %V) {
+ %Y = fmul <4 x float> %V, < float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 > ; <<4 x float>> [#uses=1]
+ %Z = fmul <4 x float> %Y, < float 1.000000e+00, float 2.000000e+05, float -3.000000e+00, float 4.000000e+00 > ; <<4 x float>> [#uses=1]
+ ret <4 x float> %Z
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-11-10-ashr-miscompile.ll b/src/LLVM/test/Transforms/InstCombine/2006-11-10-ashr-miscompile.ll
new file mode 100644
index 0000000..cc512d0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-11-10-ashr-miscompile.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep lshr
+; Verify this is not turned into -1.
+
+define i32 @test(i8 %amt) {
+ %shift.upgrd.1 = zext i8 %amt to i32 ; <i32> [#uses=1]
+ %B = lshr i32 -1, %shift.upgrd.1 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-01-BadFPVectorXform.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-01-BadFPVectorXform.ll
new file mode 100644
index 0000000..1d3cf2d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-01-BadFPVectorXform.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep sub
+; RUN: opt < %s -instcombine -S | grep add
+
+define <4 x float> @test(<4 x float> %tmp26, <4 x float> %tmp53) {
+ ; (X+Y)-Y != X for fp vectors.
+ %tmp64 = fadd <4 x float> %tmp26, %tmp53 ; <<4 x float>> [#uses=1]
+ %tmp75 = fsub <4 x float> %tmp64, %tmp53 ; <<4 x float>> [#uses=1]
+ ret <4 x float> %tmp75
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-05-fp-to-int-ext.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-05-fp-to-int-ext.ll
new file mode 100644
index 0000000..682d99d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-05-fp-to-int-ext.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | grep zext
+
+; Never merge these two conversions, even though it's possible: this is
+; significantly more expensive than the two conversions on some targets
+; and it causes libgcc to be compile __fixunsdfdi into a recursive
+; function.
+define i64 @test(double %D) {
+ %A = fptoui double %D to i32 ; <i32> [#uses=1]
+ %B = zext i32 %A to i64 ; <i64> [#uses=1]
+ ret i64 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-08-Phi-ICmp-Op-Fold.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-08-Phi-ICmp-Op-Fold.ll
new file mode 100644
index 0000000..43e9822
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-08-Phi-ICmp-Op-Fold.ll
@@ -0,0 +1,51 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {icmp sgt}
+; END.
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.point = type { i32, i32 }
+
+define i32 @visible(i32 %direction, i64 %p1.0, i64 %p2.0, i64 %p3.0) {
+entry:
+ %p1_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %p2_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %p3_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp = bitcast %struct.point* %p1_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp.upgrd.1 = getelementptr { i64 }* %tmp, i64 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p1.0, i64* %tmp.upgrd.1
+ %tmp1 = bitcast %struct.point* %p2_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp2 = getelementptr { i64 }* %tmp1, i64 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p2.0, i64* %tmp2
+ %tmp3 = bitcast %struct.point* %p3_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp4 = getelementptr { i64 }* %tmp3, i64 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p3.0, i64* %tmp4
+ %tmp.upgrd.2 = icmp eq i32 %direction, 0 ; <i1> [#uses=1]
+ %tmp5 = bitcast %struct.point* %p1_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp6 = getelementptr { i64 }* %tmp5, i64 0, i32 0 ; <i64*> [#uses=1]
+ %tmp.upgrd.3 = load i64* %tmp6 ; <i64> [#uses=1]
+ %tmp7 = bitcast %struct.point* %p2_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp8 = getelementptr { i64 }* %tmp7, i64 0, i32 0 ; <i64*> [#uses=1]
+ %tmp9 = load i64* %tmp8 ; <i64> [#uses=1]
+ %tmp10 = bitcast %struct.point* %p3_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp11 = getelementptr { i64 }* %tmp10, i64 0, i32 0 ; <i64*> [#uses=1]
+ %tmp12 = load i64* %tmp11 ; <i64> [#uses=1]
+ %tmp13 = call i32 @determinant( i64 %tmp.upgrd.3, i64 %tmp9, i64 %tmp12 ) ; <i32> [#uses=2]
+ br i1 %tmp.upgrd.2, label %cond_true, label %cond_false
+
+cond_true: ; preds = %entry
+ %tmp14 = icmp slt i32 %tmp13, 0 ; <i1> [#uses=1]
+ %tmp14.upgrd.4 = zext i1 %tmp14 to i32 ; <i32> [#uses=1]
+ br label %return
+
+cond_false: ; preds = %entry
+ %tmp26 = icmp sgt i32 %tmp13, 0 ; <i1> [#uses=1]
+ %tmp26.upgrd.5 = zext i1 %tmp26 to i32 ; <i32> [#uses=1]
+ br label %return
+
+return: ; preds = %cond_false, %cond_true
+ %retval.0 = phi i32 [ %tmp14.upgrd.4, %cond_true ], [ %tmp26.upgrd.5, %cond_false ] ; <i32> [#uses=1]
+ ret i32 %retval.0
+}
+
+declare i32 @determinant(i64, i64, i64)
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-08-Select-ICmp.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-08-Select-ICmp.ll
new file mode 100644
index 0000000..507bcbc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-08-Select-ICmp.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -instcombine -S | grep select
+; END.
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.point = type { i32, i32 }
+
+define i32 @visible(i32 %direction, i64 %p1.0, i64 %p2.0, i64 %p3.0) {
+entry:
+ %p1_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %p2_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %p3_addr = alloca %struct.point ; <%struct.point*> [#uses=2]
+ %tmp = bitcast %struct.point* %p1_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp.upgrd.1 = getelementptr { i64 }* %tmp, i32 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p1.0, i64* %tmp.upgrd.1
+ %tmp1 = bitcast %struct.point* %p2_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp2 = getelementptr { i64 }* %tmp1, i32 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p2.0, i64* %tmp2
+ %tmp3 = bitcast %struct.point* %p3_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp4 = getelementptr { i64 }* %tmp3, i32 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %p3.0, i64* %tmp4
+ %tmp.upgrd.2 = icmp eq i32 %direction, 0 ; <i1> [#uses=1]
+ %tmp5 = bitcast %struct.point* %p1_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp6 = getelementptr { i64 }* %tmp5, i32 0, i32 0 ; <i64*> [#uses=1]
+ %tmp.upgrd.3 = load i64* %tmp6 ; <i64> [#uses=1]
+ %tmp7 = bitcast %struct.point* %p2_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp8 = getelementptr { i64 }* %tmp7, i32 0, i32 0 ; <i64*> [#uses=1]
+ %tmp9 = load i64* %tmp8 ; <i64> [#uses=1]
+ %tmp10 = bitcast %struct.point* %p3_addr to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp11 = getelementptr { i64 }* %tmp10, i32 0, i32 0 ; <i64*> [#uses=1]
+ %tmp12 = load i64* %tmp11 ; <i64> [#uses=1]
+ %tmp13 = call i32 @determinant( i64 %tmp.upgrd.3, i64 %tmp9, i64 %tmp12 ) ; <i32> [#uses=2]
+ %tmp14 = icmp slt i32 %tmp13, 0 ; <i1> [#uses=1]
+ %tmp26 = icmp sgt i32 %tmp13, 0 ; <i1> [#uses=1]
+ %retval.0.in = select i1 %tmp.upgrd.2, i1 %tmp14, i1 %tmp26 ; <i1> [#uses=1]
+ %retval.0 = zext i1 %retval.0.in to i32 ; <i32> [#uses=1]
+ ret i32 %retval.0
+}
+
+declare i32 @determinant(i64, i64, i64)
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-15-Range-Test.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-15-Range-Test.ll
new file mode 100644
index 0000000..b6b810a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-15-Range-Test.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep icmp | count 1
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {icmp ugt} | count 1
+; END.
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+@r = external global [17 x i32] ; <[17 x i32]*> [#uses=1]
+
+define i1 @print_pgm_cond_true(i32 %tmp12.reload, i32* %tmp16.out) {
+newFuncRoot:
+ br label %cond_true
+
+bb27.exitStub: ; preds = %cond_true
+ store i32 %tmp16, i32* %tmp16.out
+ ret i1 true
+
+cond_next23.exitStub: ; preds = %cond_true
+ store i32 %tmp16, i32* %tmp16.out
+ ret i1 false
+
+cond_true: ; preds = %newFuncRoot
+ %tmp15 = getelementptr [17 x i32]* @r, i32 0, i32 %tmp12.reload ; <i32*> [#uses=1]
+ %tmp16 = load i32* %tmp15 ; <i32> [#uses=4]
+ %tmp18 = icmp slt i32 %tmp16, -31 ; <i1> [#uses=1]
+ %tmp21 = icmp sgt i32 %tmp16, 31 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp18, %tmp21 ; <i1> [#uses=1]
+ br i1 %bothcond, label %bb27.exitStub, label %cond_next23.exitStub
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2006-12-23-Select-Cmp-Cmp.ll b/src/LLVM/test/Transforms/InstCombine/2006-12-23-Select-Cmp-Cmp.ll
new file mode 100644
index 0000000..6c3a06f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2006-12-23-Select-Cmp-Cmp.ll
@@ -0,0 +1,30 @@
+; For PR1065. This causes an assertion in instcombine if a select with two cmp
+; operands is encountered.
+; RUN: opt < %s -instcombine -disable-output
+; END.
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.internal_state = type { i32 }
+ %struct.mng_data = type { i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, i32, i8, i32, i32, i32, i32, i16, i16, i16, i8, i8, double, double, double, i8, i8, i8, i8, i32, i32, i32, i32, i32, i8, i32, i32, i8*, i8* (i32)*, void (i8*, i32)*, void (i8*, i8*, i32)*, i8 (%struct.mng_data*)*, i8 (%struct.mng_data*)*, i8 (%struct.mng_data*, i8*, i32, i32*)*, i8 (%struct.mng_data*, i8*, i32, i32*)*, i8 (%struct.mng_data*, i32, i8, i32, i32, i32, i32, i8*)*, i8 (%struct.mng_data*, i32, i32, i8*)*, i8 (%struct.mng_data*, i32, i32)*, i8 (%struct.mng_data*, i8, i8*, i8*, i8*, i8*)*, i8 (%struct.mng_data*)*, i8 (%struct.mng_data*, i8*)*, i8 (%struct.mng_data*, i8*)*, i8 (%struct.mng_data*, i32, i32)*, i8 (%struct.mng_data*, i32, i32, i8*)*, i8 (%struct.mng_data*, i8, i8, i32, i32)*, i8* (%struct.mng_data*, i32)*, i8* (%struct.mng_data*, i32)*, i8* (%struct.mng_data*, i32)*, i8 (%struct.mng_data*, i32, i32, i32, i32)*, i32 (%struct.mng_data*)*, i8 (%struct.mng_data*, i32)*, i8 (%struct.mng_data*, i32)*, i8 (%struct.mng_data*, i32, i32, i32, i32, i32, i32, i32, i32)*, i8 (%struct.mng_data*, i8)*, i8 (%struct.mng_data*, i32, i8*)*, i8 (%struct.mng_data*, i32, i8, i8*)*, i8, i32, i32, i8*, i8*, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, i8, i8, i8, i8, i32, i8, i8, i8, i32, i8*, i32, i8*, i32, i8, i8, i8, i32, i8*, i8*, i32, i32, i8*, i8*, %struct.mng_pushdata*, %struct.mng_pushdata*, %struct.mng_pushdata*, %struct.mng_pushdata*, i8, i8, i32, i32, i8*, i8, i8, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, i8*, i32, i32, i32, i8, i8, i32, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i8*, i8*, i8*, i32, i8*, i8*, i8*, i8*, i8*, %struct.mng_savedata*, i32, i32, i32, i32, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8*, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i8*, [256 x i8], double, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, i16, i8, i8, i8, i8, i8, i32, i32, i8, i32, i32, i32, i32, i16, i16, i16, i8, i16, i8, i32, i32, i32, i32, i8, i32, i32, i8, i32, i32, i32, i32, i8, i32, i32, i8, i32, i32, i32, i32, i32, i8, i32, i8, i16, i16, i16, i16, i32, [256 x %struct.mng_palette8e], i32, [256 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i8*, i16, i16, i16, i8*, i8, i8, i32, i32, i32, i32, i8, void ()*, void ()*, void ()*, void ()*, void ()*, void ()*, i8*, i8, i8, i8, i32, i8*, i8*, i16, i16, i16, i16, i32, i32, i8*, %struct.z_stream, i32, i32, i32, i32, i32, i32, i8, i8, [256 x i32], i8 }
+ %struct.mng_palette8e = type { i8, i8, i8 }
+ %struct.mng_pushdata = type { i8*, i8*, i32, i8, i8*, i32 }
+ %struct.mng_savedata = type { i8, i8, i8, i8, i8, i8, i8, i16, i16, i16, i8, i16, i8, i8, i32, i32, i8, i32, i32, i32, i32, i32, [256 x %struct.mng_palette8e], i32, [256 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32, i8*, i16, i16, i16 }
+ %struct.z_stream = type { i8*, i32, i32, i8*, i32, i32, i8*, %struct.internal_state*, i8* (i8*, i32, i32)*, void (i8*, i8*)*, i8*, i32, i32, i32 }
+
+define void @mng_write_basi() {
+entry:
+ %tmp = load i8* null ; <i8> [#uses=1]
+ %tmp.upgrd.1 = icmp ugt i8 %tmp, 8 ; <i1> [#uses=1]
+ %tmp.upgrd.2 = load i16* null ; <i16> [#uses=2]
+ %tmp3 = icmp eq i16 %tmp.upgrd.2, 255 ; <i1> [#uses=1]
+ %tmp7 = icmp eq i16 %tmp.upgrd.2, -1 ; <i1> [#uses=1]
+ %bOpaque.0.in = select i1 %tmp.upgrd.1, i1 %tmp7, i1 %tmp3 ; <i1> [#uses=1]
+ br i1 %bOpaque.0.in, label %cond_next90, label %bb95
+
+cond_next90: ; preds = %entry
+ ret void
+
+bb95: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-01-13-ExtCompareMiscompile.ll b/src/LLVM/test/Transforms/InstCombine/2007-01-13-ExtCompareMiscompile.ll
new file mode 100644
index 0000000..fd00319
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-01-13-ExtCompareMiscompile.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {icmp ugt}
+; PR1107
+; PR1940
+
+define i1 @test(i8 %A, i8 %B) {
+ %a = zext i8 %A to i32
+ %b = zext i8 %B to i32
+ %c = icmp sgt i32 %a, %b
+ ret i1 %c
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-01-14-FcmpSelf.ll b/src/LLVM/test/Transforms/InstCombine/2007-01-14-FcmpSelf.ll
new file mode 100644
index 0000000..c02955f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-01-14-FcmpSelf.ll
@@ -0,0 +1,6 @@
+; RUN: opt < %s -instcombine -S | grep {fcmp uno.*0.0}
+; PR1111
+define i1 @test(double %X) {
+ %tmp = fcmp une double %X, %X
+ ret i1 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-01-18-VectorInfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2007-01-18-VectorInfLoop.ll
new file mode 100644
index 0000000..c0852f1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-01-18-VectorInfLoop.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define <4 x i32> @test(<4 x i32> %A) {
+ %B = xor <4 x i32> %A, < i32 -1, i32 -1, i32 -1, i32 -1 >
+ %C = and <4 x i32> %B, < i32 -1, i32 -1, i32 -1, i32 -1 >
+ ret <4 x i32> %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-01-27-AndICmp.ll b/src/LLVM/test/Transforms/InstCombine/2007-01-27-AndICmp.ll
new file mode 100644
index 0000000..e6c3768
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-01-27-AndICmp.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep {ugt.*, 1}
+
+define i1 @test(i32 %tmp1030) {
+ %tmp1037 = icmp ne i32 %tmp1030, 40 ; <i1> [#uses=1]
+ %tmp1039 = icmp ne i32 %tmp1030, 41 ; <i1> [#uses=1]
+ %tmp1042 = and i1 %tmp1037, %tmp1039 ; <i1> [#uses=1]
+ ret i1 %tmp1042
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-02-01-LoadSinkAlloca.ll b/src/LLVM/test/Transforms/InstCombine/2007-02-01-LoadSinkAlloca.ll
new file mode 100644
index 0000000..4c5ceb7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-02-01-LoadSinkAlloca.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -instcombine -mem2reg -S | grep {%A = alloca}
+; RUN: opt < %s -instcombine -mem2reg -S | \
+; RUN: not grep {%B = alloca}
+; END.
+
+; Ensure that instcombine doesn't sink the loads in entry/cond_true into
+; cond_next. Doing so prevents mem2reg from promoting the B alloca.
+
+define i32 @test2(i32 %C) {
+entry:
+ %A = alloca i32
+ %B = alloca i32
+ %tmp = call i32 (...)* @bar( i32* %A ) ; <i32> [#uses=0]
+ %T = load i32* %A ; <i32> [#uses=1]
+ %tmp2 = icmp eq i32 %C, 0 ; <i1> [#uses=1]
+ br i1 %tmp2, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ store i32 123, i32* %B
+ call i32 @test2( i32 123 ) ; <i32>:0 [#uses=0]
+ %T1 = load i32* %B ; <i32> [#uses=1]
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %entry
+ %tmp1.0 = phi i32 [ %T1, %cond_true ], [ %T, %entry ] ; <i32> [#uses=1]
+ %tmp7 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp8 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp9 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp10 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp11 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp12 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp13 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp14 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp15 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp16 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp17 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp18 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp19 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ %tmp20 = call i32 (...)* @baq( ) ; <i32> [#uses=0]
+ ret i32 %tmp1.0
+}
+
+declare i32 @bar(...)
+
+declare i32 @baq(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-02-07-PointerCast.ll b/src/LLVM/test/Transforms/InstCombine/2007-02-07-PointerCast.ll
new file mode 100644
index 0000000..e6ccc22
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-02-07-PointerCast.ll
@@ -0,0 +1,22 @@
+;RUN: opt < %s -instcombine -S | grep zext
+
+; Make sure the uint isn't removed. Instcombine in llvm 1.9 was dropping the
+; uint cast which was causing a sign extend. This only affected code with
+; pointers in the high half of memory, so it wasn't noticed much
+; compile a kernel though...
+
+target datalayout = "e-p:32:32"
+@str = internal constant [6 x i8] c"%llx\0A\00" ; <[6 x i8]*> [#uses=1]
+
+declare i32 @printf(i8*, ...)
+
+define i32 @main(i32 %x, i8** %a) {
+entry:
+ %tmp = getelementptr [6 x i8]* @str, i32 0, i64 0 ; <i8*> [#uses=1]
+ %tmp1 = load i8** %a ; <i8*> [#uses=1]
+ %tmp2 = ptrtoint i8* %tmp1 to i32 ; <i32> [#uses=1]
+ %tmp3 = zext i32 %tmp2 to i64 ; <i64> [#uses=1]
+ %tmp.upgrd.1 = call i32 (i8*, ...)* @printf( i8* %tmp, i64 %tmp3 ) ; <i32> [#uses=0]
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-02-23-PhiFoldInfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2007-02-23-PhiFoldInfLoop.ll
new file mode 100644
index 0000000..b06a851
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-02-23-PhiFoldInfLoop.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -instcombine -S | grep ret
+; PR1217
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.termbox = type { %struct.termbox*, i32, i32, i32, i32, i32 }
+
+
+define void @ggenorien() {
+entry:
+ %tmp68 = icmp eq %struct.termbox* null, null ; <i1> [#uses=1]
+ br i1 %tmp68, label %cond_next448, label %bb80
+
+bb80: ; preds = %entry
+ ret void
+
+cond_next448: ; preds = %entry
+ br i1 false, label %bb756, label %bb595
+
+bb595: ; preds = %cond_next448
+ br label %bb609
+
+bb609: ; preds = %bb756, %bb595
+ %termnum.6240.0 = phi i32 [ 2, %bb595 ], [ %termnum.6, %bb756 ] ; <i32> [#uses=1]
+ %tmp755 = add i32 %termnum.6240.0, 1 ; <i32> [#uses=1]
+ br label %bb756
+
+bb756: ; preds = %bb609, %cond_next448
+ %termnum.6 = phi i32 [ %tmp755, %bb609 ], [ 2, %cond_next448 ] ; <i32> [#uses=1]
+ br label %bb609
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-13-CompareMerge.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-13-CompareMerge.ll
new file mode 100644
index 0000000..7f87161
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-13-CompareMerge.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {icmp sle}
+; PR1244
+
+define i1 @test(i32 %c.3.i, i32 %d.292.2.i) {
+ %tmp266.i = icmp slt i32 %c.3.i, %d.292.2.i
+ %tmp276.i = icmp eq i32 %c.3.i, %d.292.2.i
+ %sel_tmp80 = or i1 %tmp266.i, %tmp276.i
+ ret i1 %sel_tmp80
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-19-BadTruncChangePR1261.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-19-BadTruncChangePR1261.ll
new file mode 100644
index 0000000..75f5d76
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-19-BadTruncChangePR1261.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep zext
+; PR1261.
+
+define i16 @test(i31 %zzz) {
+ %A = sext i31 %zzz to i32
+ %B = add i32 %A, 16384
+ %C = lshr i32 %B, 15
+ %D = trunc i32 %C to i16
+ ret i16 %D
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-21-SignedRangeTest.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-21-SignedRangeTest.ll
new file mode 100644
index 0000000..d0ac22d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-21-SignedRangeTest.ll
@@ -0,0 +1,7 @@
+; For PR1248
+; RUN: opt < %s -instcombine -S | grep {ugt i32 .*, 11}
+define i1 @test(i32 %tmp6) {
+ %tmp7 = sdiv i32 %tmp6, 12 ; <i32> [#uses=1]
+ icmp ne i32 %tmp7, -6 ; <i1>:1 [#uses=1]
+ ret i1 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-25-BadShiftMask.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-25-BadShiftMask.ll
new file mode 100644
index 0000000..addcf8a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-25-BadShiftMask.ll
@@ -0,0 +1,29 @@
+; PR1271
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {icmp eq i32 .tmp.*, 2146435072}
+%struct..0anon = type { i32, i32 }
+%struct..1anon = type { double }
+
+define i32 @main() {
+entry:
+ %u = alloca %struct..1anon, align 8 ; <%struct..1anon*> [#uses=4]
+ %tmp1 = getelementptr %struct..1anon* %u, i32 0, i32 0 ; <double*> [#uses=1]
+ store double 0x7FF0000000000000, double* %tmp1
+ %tmp3 = getelementptr %struct..1anon* %u, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp34 = bitcast double* %tmp3 to %struct..0anon* ; <%struct..0anon*> [#uses=1]
+ %tmp5 = getelementptr %struct..0anon* %tmp34, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp6 = load i32* %tmp5 ; <i32> [#uses=1]
+ %tmp7 = shl i32 %tmp6, 1 ; <i32> [#uses=1]
+ %tmp8 = lshr i32 %tmp7, 21 ; <i32> [#uses=1]
+ %tmp89 = trunc i32 %tmp8 to i16 ; <i16> [#uses=1]
+ icmp ne i16 %tmp89, 2047 ; <i1>:0 [#uses=1]
+ zext i1 %0 to i8 ; <i8>:1 [#uses=1]
+ icmp ne i8 %1, 0 ; <i1>:2 [#uses=1]
+ br i1 %2, label %cond_true, label %cond_false
+
+cond_true: ; preds = %entry
+ ret i32 0
+
+cond_false: ; preds = %entry
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-25-DoubleShift.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-25-DoubleShift.ll
new file mode 100644
index 0000000..ac38dfe
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-25-DoubleShift.ll
@@ -0,0 +1,9 @@
+; PR1271
+; RUN: opt < %s -instcombine -S | grep and
+define i1 @test(i32 %tmp13) {
+entry:
+ %tmp14 = shl i32 %tmp13, 12 ; <i32> [#uses=1]
+ %tmp15 = lshr i32 %tmp14, 12 ; <i32> [#uses=1]
+ %res = icmp ne i32 %tmp15, 0 ; <i1>:3 [#uses=1]
+ ret i1 %res
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-03-26-BadShiftMask.ll b/src/LLVM/test/Transforms/InstCombine/2007-03-26-BadShiftMask.ll
new file mode 100644
index 0000000..c3032d9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-03-26-BadShiftMask.ll
@@ -0,0 +1,35 @@
+; PR1271
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {ashr exact i32 %.mp137, 2}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+
+
+define i1 @test(i32* %tmp141, i32* %tmp145,
+ i32 %b8, i32 %iftmp.430.0, i32* %tmp134.out, i32* %tmp137.out)
+{
+newFuncRoot:
+ %tmp133 = and i32 %b8, 1 ; <i32> [#uses=1]
+ %tmp134 = shl i32 %tmp133, 3 ; <i32> [#uses=3]
+ %tmp136 = ashr i32 %b8, 1 ; <i32> [#uses=1]
+ %tmp137 = shl i32 %tmp136, 3 ; <i32> [#uses=3]
+ %tmp139 = ashr i32 %tmp134, 2 ; <i32> [#uses=1]
+ store i32 %tmp139, i32* %tmp141
+ %tmp143 = ashr i32 %tmp137, 2 ; <i32> [#uses=1]
+ store i32 %tmp143, i32* %tmp145
+ icmp eq i32 %iftmp.430.0, 0 ; <i1>:0 [#uses=1]
+ zext i1 %0 to i8 ; <i8>:1 [#uses=1]
+ icmp ne i8 %1, 0 ; <i1>:2 [#uses=1]
+ br i1 %2, label %cond_true147.exitStub, label %cond_false252.exitStub
+
+cond_true147.exitStub: ; preds = %newFuncRoot
+ store i32 %tmp134, i32* %tmp134.out
+ store i32 %tmp137, i32* %tmp137.out
+ ret i1 true
+
+cond_false252.exitStub: ; preds = %newFuncRoot
+ store i32 %tmp134, i32* %tmp134.out
+ store i32 %tmp137, i32* %tmp137.out
+ ret i1 false
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll b/src/LLVM/test/Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll
new file mode 100644
index 0000000..335d707
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR1304
+
+define i64 @bork(<1 x i64> %vec) {
+ %tmp = extractelement <1 x i64> %vec, i32 0
+ ret i64 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-05-10-icmp-or.ll b/src/LLVM/test/Transforms/InstCombine/2007-05-10-icmp-or.ll
new file mode 100644
index 0000000..54b60f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-05-10-icmp-or.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -disable-output
+define i1 @test(i32 %tmp9) {
+ %tmp20 = icmp ugt i32 %tmp9, 255 ; <i1> [#uses=1]
+ %tmp11.not = icmp sgt i32 %tmp9, 255 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp20, %tmp11.not ; <i1> [#uses=1]
+ ret i1 %bothcond
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-05-14-Crash.ll b/src/LLVM/test/Transforms/InstCombine/2007-05-14-Crash.ll
new file mode 100644
index 0000000..86b747c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-05-14-Crash.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -disable-output
+
+target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "powerpc-apple-darwin8.8.0"
+
+%struct.abc = type { i32, [32 x i8] }
+%struct.def = type { i8**, %struct.abc }
+ %struct.anon = type <{ }>
+
+define i8* @foo(%struct.anon* %deviceRef, %struct.abc* %pCap) {
+entry:
+ %tmp1 = bitcast %struct.anon* %deviceRef to %struct.def*
+ %tmp3 = getelementptr %struct.def* %tmp1, i32 0, i32 1
+ %tmp35 = bitcast %struct.abc* %tmp3 to i8*
+ ret i8* %tmp35
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-05-18-CastFoldBug.ll b/src/LLVM/test/Transforms/InstCombine/2007-05-18-CastFoldBug.ll
new file mode 100644
index 0000000..c6f6cc9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-05-18-CastFoldBug.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {call.*sret}
+; Make sure instcombine doesn't drop the sret attribute.
+
+define void @blah(i16* %tmp10) {
+entry:
+ call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend_stret to void (i16*)*)( i16* sret %tmp10 )
+ ret void
+}
+
+declare i8* @objc_msgSend_stret(i8*, i8*, ...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-06-06-AshrSignBit.ll b/src/LLVM/test/Transforms/InstCombine/2007-06-06-AshrSignBit.ll
new file mode 100644
index 0000000..f9bf725
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-06-06-AshrSignBit.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -S | grep {ashr}
+; PR1499
+
+define void @av_cmp_q_cond_true(i32* %retval, i32* %tmp9, i64* %tmp10) {
+newFuncRoot:
+ br label %cond_true
+
+return.exitStub: ; preds = %cond_true
+ ret void
+
+cond_true: ; preds = %newFuncRoot
+ %tmp30 = load i64* %tmp10 ; <i64> [#uses=1]
+ %.cast = zext i32 63 to i64 ; <i64> [#uses=1]
+ %tmp31 = ashr i64 %tmp30, %.cast ; <i64> [#uses=1]
+ %tmp3132 = trunc i64 %tmp31 to i32 ; <i32> [#uses=1]
+ %tmp33 = or i32 %tmp3132, 1 ; <i32> [#uses=1]
+ store i32 %tmp33, i32* %tmp9
+ %tmp34 = load i32* %tmp9 ; <i32> [#uses=1]
+ store i32 %tmp34, i32* %retval
+ br label %return.exitStub
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-06-21-DivCompareMiscomp.ll b/src/LLVM/test/Transforms/InstCombine/2007-06-21-DivCompareMiscomp.ll
new file mode 100644
index 0000000..7a30e6a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-06-21-DivCompareMiscomp.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 true}
+; rdar://5278853
+
+define i1 @test(i32 %tmp468) {
+ %tmp470 = udiv i32 %tmp468, 4 ; <i32> [#uses=2]
+ %tmp475 = icmp ult i32 %tmp470, 1073741824 ; <i1> [#uses=1]
+ ret i1 %tmp475
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-08-02-InfiniteLoop.ll b/src/LLVM/test/Transforms/InstCombine/2007-08-02-InfiniteLoop.ll
new file mode 100644
index 0000000..3f76187
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-08-02-InfiniteLoop.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR1594
+
+define i64 @test(i16 %tmp510, i16 %tmp512) {
+ %W = sext i16 %tmp510 to i32 ; <i32> [#uses=1]
+ %X = sext i16 %tmp512 to i32 ; <i32> [#uses=1]
+ %Y = add i32 %W, %X ; <i32> [#uses=1]
+ %Z = sext i32 %Y to i64 ; <i64> [#uses=1]
+ ret i64 %Z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-09-10-AliasConstFold.ll b/src/LLVM/test/Transforms/InstCombine/2007-09-10-AliasConstFold.ll
new file mode 100644
index 0000000..c27fe0a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-09-10-AliasConstFold.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | grep icmp
+; PR1646
+
+@__gthrw_pthread_cancel = alias weak i32 (i32)* @pthread_cancel ; <i32 (i32)*> [#uses=1]
+@__gthread_active_ptr.5335 = internal constant i8* bitcast (i32 (i32)* @__gthrw_pthread_cancel to i8*) ; <i8**> [#uses=1]
+declare extern_weak i32 @pthread_cancel(i32)
+
+define i1 @__gthread_active_p() {
+entry:
+ %tmp1 = load i8** @__gthread_active_ptr.5335, align 4 ; <i8*> [#uses=1]
+ %tmp2 = icmp ne i8* %tmp1, null ; <i1> [#uses=1]
+ ret i1 %tmp2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-09-11-Trampoline.ll b/src/LLVM/test/Transforms/InstCombine/2007-09-11-Trampoline.ll
new file mode 100644
index 0000000..6190aa9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-09-11-Trampoline.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -instcombine -S | grep {call i32 @f}
+
+ %struct.FRAME.nest = type { i32, i32 (i32)* }
+ %struct.__builtin_trampoline = type { [10 x i8] }
+
+declare i8* @llvm.init.trampoline(i8*, i8*, i8*)
+
+declare i32 @f(%struct.FRAME.nest* nest , i32 )
+
+define i32 @nest(i32 %n) {
+entry:
+ %FRAME.0 = alloca %struct.FRAME.nest, align 8 ; <%struct.FRAME.nest*> [#uses=3]
+ %TRAMP.216 = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
+ %TRAMP.216.sub = getelementptr [10 x i8]* %TRAMP.216, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp3 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %n, i32* %tmp3, align 8
+ %FRAME.06 = bitcast %struct.FRAME.nest* %FRAME.0 to i8* ; <i8*> [#uses=1]
+ %tramp = call i8* @llvm.init.trampoline( i8* %TRAMP.216.sub, i8* bitcast (i32 (%struct.FRAME.nest* , i32)* @f to i8*), i8* %FRAME.06 ) ; <i8*> [#uses=1]
+ %tmp7 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 1 ; <i32 (i32)**> [#uses=1]
+ %tmp89 = bitcast i8* %tramp to i32 (i32)* ; <i32 (i32)*> [#uses=2]
+ store i32 (i32)* %tmp89, i32 (i32)** %tmp7, align 8
+ %tmp2.i = call i32 %tmp89( i32 1 ) ; <i32> [#uses=1]
+ ret i32 %tmp2.i
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-09-17-AliasConstFold2.ll b/src/LLVM/test/Transforms/InstCombine/2007-09-17-AliasConstFold2.ll
new file mode 100644
index 0000000..23ee12b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-09-17-AliasConstFold2.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep icmp
+; PR1678
+
+@A = alias weak void ()* @B ; <void ()*> [#uses=1]
+
+declare extern_weak void @B()
+
+define i32 @active() {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp1 = icmp ne void ()* @A, null ; <i1> [#uses=1]
+ %tmp12 = zext i1 %tmp1 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp12
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-10-10-EliminateMemCpy.ll b/src/LLVM/test/Transforms/InstCombine/2007-10-10-EliminateMemCpy.ll
new file mode 100644
index 0000000..fe935f9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-10-10-EliminateMemCpy.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | not grep call
+; RUN: opt < %s -std-compile-opts -S | not grep xyz
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@.str = internal constant [4 x i8] c"xyz\00" ; <[4 x i8]*> [#uses=1]
+
+define void @foo(i8* %P) {
+entry:
+ %P_addr = alloca i8*
+ store i8* %P, i8** %P_addr
+ %tmp = load i8** %P_addr, align 4
+ %tmp1 = getelementptr [4 x i8]* @.str, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp, i8* %tmp1, i32 4, i32 1, i1 false)
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-10-12-Crash.ll b/src/LLVM/test/Transforms/InstCombine/2007-10-12-Crash.ll
new file mode 100644
index 0000000..b3d9f02
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-10-12-Crash.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -instcombine -disable-output
+
+ %struct.Ray = type { %struct.Vec, %struct.Vec }
+ %struct.Scene = type { i32 (...)** }
+ %struct.Vec = type { double, double, double }
+
+declare double @_Z9ray_traceRK3VecRK3RayRK5Scene(%struct.Vec*, %struct.Ray*, %struct.Scene*)
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %tmp3 = alloca %struct.Ray, align 4 ; <%struct.Ray*> [#uses=2]
+ %tmp97 = icmp slt i32 0, 512 ; <i1> [#uses=1]
+ br i1 %tmp97, label %bb71, label %bb108
+
+bb29: ; preds = %bb62
+ %tmp322 = bitcast %struct.Ray* %tmp3 to %struct.Vec* ; <%struct.Vec*> [#uses=1]
+ %tmp322.0 = getelementptr %struct.Vec* %tmp322, i32 0, i32 0 ; <double*> [#uses=1]
+ store double 0.000000e+00, double* %tmp322.0
+ %tmp57 = call double @_Z9ray_traceRK3VecRK3RayRK5Scene( %struct.Vec* null, %struct.Ray* %tmp3, %struct.Scene* null ) ; <double> [#uses=0]
+ br label %bb62
+
+bb62: ; preds = %bb71, %bb29
+ %tmp65 = icmp slt i32 0, 4 ; <i1> [#uses=1]
+ br i1 %tmp65, label %bb29, label %bb68
+
+bb68: ; preds = %bb62
+ ret i32 0
+
+bb71: ; preds = %entry
+ %tmp74 = icmp slt i32 0, 4 ; <i1> [#uses=1]
+ br i1 %tmp74, label %bb62, label %bb77
+
+bb77: ; preds = %bb71
+ ret i32 0
+
+bb108: ; preds = %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-10-28-stacksave.ll b/src/LLVM/test/Transforms/InstCombine/2007-10-28-stacksave.ll
new file mode 100644
index 0000000..76bceb6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-10-28-stacksave.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -instcombine -S | grep {call.*stacksave}
+; PR1745
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+@p = weak global i8* null ; <i8**> [#uses=1]
+
+define i32 @main() {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ br label %lab
+
+lab: ; preds = %cleanup31, %entry
+ %n.0 = phi i32 [ 0, %entry ], [ %tmp25, %cleanup31 ] ; <i32> [#uses=2]
+ %tmp2 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=2]
+ %tmp4 = srem i32 %n.0, 47 ; <i32> [#uses=1]
+ %tmp5 = add i32 %tmp4, 1 ; <i32> [#uses=5]
+ %tmp7 = sub i32 %tmp5, 1 ; <i32> [#uses=0]
+ %tmp89 = zext i32 %tmp5 to i64 ; <i64> [#uses=1]
+ %tmp10 = mul i64 %tmp89, 32 ; <i64> [#uses=0]
+ %tmp12 = mul i32 %tmp5, 4 ; <i32> [#uses=0]
+ %tmp1314 = zext i32 %tmp5 to i64 ; <i64> [#uses=1]
+ %tmp15 = mul i64 %tmp1314, 32 ; <i64> [#uses=0]
+ %tmp17 = mul i32 %tmp5, 4 ; <i32> [#uses=1]
+ %tmp18 = alloca i8, i32 %tmp17 ; <i8*> [#uses=1]
+ %tmp1819 = bitcast i8* %tmp18 to i32* ; <i32*> [#uses=2]
+ %tmp21 = getelementptr i32* %tmp1819, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp21, align 4
+ %tmp2223 = bitcast i32* %tmp1819 to i8* ; <i8*> [#uses=1]
+ volatile store i8* %tmp2223, i8** @p, align 4
+ %tmp25 = add i32 %n.0, 1 ; <i32> [#uses=2]
+ %tmp27 = icmp sle i32 %tmp25, 999999 ; <i1> [#uses=1]
+ %tmp2728 = zext i1 %tmp27 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp2728, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %cleanup31, label %cond_next
+
+cond_next: ; preds = %lab
+ call void @llvm.stackrestore( i8* %tmp2 )
+ ret i32 0
+
+cleanup31: ; preds = %lab
+ call void @llvm.stackrestore( i8* %tmp2 )
+ br label %lab
+}
+
+declare i8* @llvm.stacksave()
+
+declare void @llvm.stackrestore(i8*)
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-10-31-RangeCrash.ll b/src/LLVM/test/Transforms/InstCombine/2007-10-31-RangeCrash.ll
new file mode 100644
index 0000000..8105b4b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-10-31-RangeCrash.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -instcombine -disable-output
+target datalayout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f128:64:128"
+target triple = "powerpc-apple-darwin8"
+
+define i32 @test() {
+entry:
+ %tmp50.i17 = icmp slt i32 0, 4 ; <i1> [#uses=1]
+ br i1 %tmp50.i17, label %bb.i, label %calculateColorSpecificBlackLevel.exit
+
+bb.i: ; preds = %entry
+ br label %bb51.i.i
+
+bb27.i.i: ; preds = %bb51.i.i
+ %tmp31.i.i = load i16* null, align 2 ; <i16> [#uses=2]
+ %tmp35.i.i = icmp ult i16 %tmp31.i.i, 1 ; <i1> [#uses=1]
+ %tmp41.i.i = icmp ugt i16 %tmp31.i.i, -1 ; <i1> [#uses=1]
+ %bothcond.i.i = or i1 %tmp35.i.i, %tmp41.i.i ; <i1> [#uses=1]
+ %bothcond1.i.i = zext i1 %bothcond.i.i to i32 ; <i32> [#uses=1]
+ %tmp46.i.i = xor i32 %bothcond1.i.i, 1 ; <i32> [#uses=1]
+ %count.0.i.i = add i32 %count.1.i.i, %tmp46.i.i ; <i32> [#uses=1]
+ %tmp50.i.i = add i32 %x.0.i.i, 2 ; <i32> [#uses=1]
+ br label %bb51.i.i
+
+bb51.i.i: ; preds = %bb27.i.i, %bb.i
+ %count.1.i.i = phi i32 [ %count.0.i.i, %bb27.i.i ], [ 0, %bb.i ] ; <i32> [#uses=1]
+ %x.0.i.i = phi i32 [ %tmp50.i.i, %bb27.i.i ], [ 0, %bb.i ] ; <i32> [#uses=2]
+ %tmp54.i.i = icmp slt i32 %x.0.i.i, 0 ; <i1> [#uses=1]
+ br i1 %tmp54.i.i, label %bb27.i.i, label %bb57.i.i
+
+bb57.i.i: ; preds = %bb51.i.i
+ ret i32 0
+
+calculateColorSpecificBlackLevel.exit: ; preds = %entry
+ ret i32 undef
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-10-31-StringCrash.ll b/src/LLVM/test/Transforms/InstCombine/2007-10-31-StringCrash.ll
new file mode 100644
index 0000000..220f3e2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-10-31-StringCrash.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instcombine -disable-output
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+
+declare void @__darwin_gcc3_preregister_frame_info()
+
+define void @_start(i32 %argc, i8** %argv, i8** %envp) {
+entry:
+ %tmp1 = bitcast void ()* @__darwin_gcc3_preregister_frame_info to i32* ; <i32*> [#uses=1]
+ %tmp2 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ %tmp3 = icmp ne i32 %tmp2, 0 ; <i1> [#uses=1]
+ %tmp34 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp34, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %cond_true, label %return
+
+cond_true: ; preds = %entry
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-11-07-OpaqueAlignCrash.ll b/src/LLVM/test/Transforms/InstCombine/2007-11-07-OpaqueAlignCrash.ll
new file mode 100644
index 0000000..e6c9bcd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-11-07-OpaqueAlignCrash.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR1780
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+
+%opaque_t = type opaque
+%opaque2 = type opaque
+%op_ts = type {%opaque2, i32}
+
+@g = external global %opaque_t
+@h = external global %op_ts
+
+define i32 @foo() {
+entry:
+ %x = load i8* bitcast (%opaque_t* @g to i8*)
+ %y = load i32* bitcast (%op_ts* @h to i32*)
+ %z = zext i8 %x to i32
+ %r = add i32 %y, %z
+ ret i32 %r
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-11-15-CompareMiscomp.ll b/src/LLVM/test/Transforms/InstCombine/2007-11-15-CompareMiscomp.ll
new file mode 100644
index 0000000..5282739
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-11-15-CompareMiscomp.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {icmp eq i32 %In, 1}
+; PR1800
+
+define i1 @test(i32 %In) {
+ %c1 = icmp sgt i32 %In, -1
+ %c2 = icmp eq i32 %In, 1
+ %V = and i1 %c1, %c2
+ ret i1 %V
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-11-22-IcmpCrash.ll b/src/LLVM/test/Transforms/InstCombine/2007-11-22-IcmpCrash.ll
new file mode 100644
index 0000000..f71b99c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-11-22-IcmpCrash.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR1817
+
+define i1 @test1(i32 %X) {
+ %A = icmp slt i32 %X, 10
+ %B = icmp ult i32 %X, 10
+ %C = and i1 %A, %B
+ ret i1 %C
+}
+
+define i1 @test2(i32 %X) {
+ %A = icmp slt i32 %X, 10
+ %B = icmp ult i32 %X, 10
+ %C = or i1 %A, %B
+ ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-11-25-CompatibleAttributes.ll b/src/LLVM/test/Transforms/InstCombine/2007-11-25-CompatibleAttributes.ll
new file mode 100644
index 0000000..e3192a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-11-25-CompatibleAttributes.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | not grep bitcast
+; PR1716
+
+@.str = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %tmp32 = tail call i32 (i8* , ...) * bitcast (i32 (i8*, ...) * @printf to i32 (i8* , ...) *)( i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0) , i32 0 ) nounwind ; <i32> [#uses=0]
+ ret i32 undef
+}
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-12-10-ConstFoldCompare.ll b/src/LLVM/test/Transforms/InstCombine/2007-12-10-ConstFoldCompare.ll
new file mode 100644
index 0000000..6420537
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-12-10-ConstFoldCompare.ll
@@ -0,0 +1,9 @@
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+; RUN: opt < %s -instcombine -S | not grep {ret i1 0}
+; PR1850
+
+define i1 @test() {
+ %cond = icmp ule i8* inttoptr (i64 4294967297 to i8*), inttoptr (i64 5 to i8*)
+ ret i1 %cond
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-12-12-GEPScale.ll b/src/LLVM/test/Transforms/InstCombine/2007-12-12-GEPScale.ll
new file mode 100644
index 0000000..cea87f2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-12-12-GEPScale.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | not grep 1431655764
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+
+define i8* @foo([100 x {i8,i8,i8}]* %x) {
+entry:
+ %p = bitcast [100 x {i8,i8,i8}]* %x to i8*
+ %q = getelementptr i8* %p, i32 -4
+ ret i8* %q
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll b/src/LLVM/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
new file mode 100644
index 0000000..85cf9b6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep nounwind
+
+define void @bar() {
+entry:
+ call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"( )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll b/src/LLVM/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
new file mode 100644
index 0000000..cc89f6d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instcombine -S | grep {add} | count 1
+
+define i32 @foo(i32 %a) {
+entry:
+ %tmp15 = sub i32 99, %a ; <i32> [#uses=2]
+ %tmp16 = icmp slt i32 %tmp15, 0 ; <i1> [#uses=1]
+ %smax = select i1 %tmp16, i32 0, i32 %tmp15 ; <i32> [#uses=1]
+ %tmp12 = add i32 %smax, %a ; <i32> [#uses=1]
+ %tmp13 = add i32 %tmp12, 1 ; <i32> [#uses=1]
+ ret i32 %tmp13
+}
+
+define i32 @bar(i32 %a) {
+entry:
+ %tmp15 = sub i32 99, %a ; <i32> [#uses=2]
+ %tmp16 = icmp slt i32 %tmp15, 0 ; <i1> [#uses=1]
+ %smax = select i1 %tmp16, i32 0, i32 %tmp15 ; <i32> [#uses=1]
+ %tmp12 = add i32 %smax, %a ; <i32> [#uses=1]
+ ret i32 %tmp12
+}
+
+define i32 @fun(i32 %a) {
+entry:
+ %tmp15 = sub i32 99, %a ; <i32> [#uses=1]
+ %tmp16 = icmp slt i32 %a, 0 ; <i1> [#uses=1]
+ %smax = select i1 %tmp16, i32 0, i32 %tmp15 ; <i32> [#uses=1]
+ %tmp12 = add i32 %smax, %a ; <i32> [#uses=1]
+ ret i32 %tmp12
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2007-12-28-IcmpSub2.ll b/src/LLVM/test/Transforms/InstCombine/2007-12-28-IcmpSub2.ll
new file mode 100644
index 0000000..8721c83
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2007-12-28-IcmpSub2.ll
@@ -0,0 +1,89 @@
+; RUN: opt < %s -mem2reg -instcombine -S | grep "ret i32 1" | count 8
+
+define i32 @test1() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp ule i32 %sub, 0
+ %retval = select i1 %cmp, i32 0, i32 1
+ ret i32 %retval
+}
+
+define i32 @test2() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp ugt i32 %sub, 0
+ %retval = select i1 %cmp, i32 1, i32 0
+ ret i32 %retval
+}
+
+define i32 @test3() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp slt i32 %sub, 0
+ %retval = select i1 %cmp, i32 1, i32 0
+ ret i32 %retval
+}
+
+define i32 @test4() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp sle i32 %sub, 0
+ %retval = select i1 %cmp, i32 1, i32 0
+ ret i32 %retval
+}
+
+define i32 @test5() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp sge i32 %sub, 0
+ %retval = select i1 %cmp, i32 0, i32 1
+ ret i32 %retval
+}
+
+define i32 @test6() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp sgt i32 %sub, 0
+ %retval = select i1 %cmp, i32 0, i32 1
+ ret i32 %retval
+}
+
+define i32 @test7() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp eq i32 %sub, 0
+ %retval = select i1 %cmp, i32 0, i32 1
+ ret i32 %retval
+}
+
+define i32 @test8() {
+entry:
+ %z = alloca i32
+ store i32 0, i32* %z
+ %tmp = load i32* %z
+ %sub = sub i32 %tmp, 1
+ %cmp = icmp ne i32 %sub, 0
+ %retval = select i1 %cmp, i32 1, i32 0
+ ret i32 %retval
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll
new file mode 100644
index 0000000..23b6067
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll
@@ -0,0 +1,23 @@
+; Ignore stderr, we expect warnings there
+; RUN: opt < %s -instcombine 2> /dev/null -S | not grep bitcast
+
+define void @a() {
+ ret void
+}
+
+define signext i32 @b(i32* inreg %x) {
+ ret i32 0
+}
+
+define void @c(...) {
+ ret void
+}
+
+define void @g(i32* %y) {
+ call void bitcast (void ()* @a to void (i32*)*)( i32* noalias %y )
+ call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg null ) ; <<2 x i32>>:1 [#uses=0]
+ %x = call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)( i32 0 ) ; <i64> [#uses=0]
+ call void bitcast (void (...)* @c to void (i32)*)( i32 0 )
+ call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext 0 )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-06-CastCrash.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-06-CastCrash.ll
new file mode 100644
index 0000000..097a0ce
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-06-CastCrash.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define <2 x i32> @f() {
+ ret <2 x i32> undef
+}
+
+define i32 @g() {
+ %x = call i32 bitcast (<2 x i32> ()* @f to i32 ()*)( ) ; <i32> [#uses=1]
+ ret i32 %x
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-06-VoidCast.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-06-VoidCast.ll
new file mode 100644
index 0000000..407ff4d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-06-VoidCast.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | not grep bitcast
+
+define void @f(i16 %y) {
+ ret void
+}
+
+define i32 @g(i32 %y) {
+ %x = call i32 bitcast (void (i16)* @f to i32 (i32)*)( i32 %y ) ; <i32> [#uses=1]
+ ret i32 %x
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-13-AndCmpCmp.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-13-AndCmpCmp.ll
new file mode 100644
index 0000000..fbc8ba9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-13-AndCmpCmp.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep and
+; PR1907
+
+define i1 @test(i32 %c84.17) {
+ %tmp2696 = icmp ne i32 %c84.17, 34 ; <i1> [#uses=2]
+ %tmp2699 = icmp sgt i32 %c84.17, -1 ; <i1> [#uses=1]
+ %tmp2703 = and i1 %tmp2696, %tmp2699 ; <i1> [#uses=1]
+ ret i1 %tmp2703
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll
new file mode 100644
index 0000000..510a68c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | grep bitcast | count 2
+
+define signext i32 @b(i32* inreg %x) {
+ ret i32 0
+}
+
+define void @c(...) {
+ ret void
+}
+
+define void @g(i32* %y) {
+ call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)( i32 zeroext 0 ) ; <i32>:2 [#uses=0]
+ call void bitcast (void (...)* @c to void (i32*)*)( i32* sret null )
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-14-DoubleNest.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-14-DoubleNest.ll
new file mode 100644
index 0000000..6401dfd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-14-DoubleNest.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -instcombine -disable-output
+
+ %struct.FRAME.nest = type { i32, i32 (i32*)* }
+ %struct.__builtin_trampoline = type { [10 x i8] }
+
+declare i8* @llvm.init.trampoline(i8*, i8*, i8*) nounwind
+
+declare i32 @f(%struct.FRAME.nest* nest , i32*)
+
+define i32 @nest(i32 %n) {
+entry:
+ %FRAME.0 = alloca %struct.FRAME.nest, align 8 ; <%struct.FRAME.nest*> [#uses=3]
+ %TRAMP.216 = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
+ %TRAMP.216.sub = getelementptr [10 x i8]* %TRAMP.216, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp3 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %n, i32* %tmp3, align 8
+ %FRAME.06 = bitcast %struct.FRAME.nest* %FRAME.0 to i8* ; <i8*> [#uses=1]
+ %tramp = call i8* @llvm.init.trampoline( i8* %TRAMP.216.sub, i8* bitcast (i32 (%struct.FRAME.nest*, i32*)* @f to i8*), i8* %FRAME.06 ) ; <i8*> [#uses=1]
+ %tmp7 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 1 ; <i32 (i32*)**> [#uses=1]
+ %tmp89 = bitcast i8* %tramp to i32 (i32*)* ; <i32 (i32*)*> [#uses=2]
+ store i32 (i32*)* %tmp89, i32 (i32*)** %tmp7, align 8
+ %tmp2.i = call i32 %tmp89( i32* nest null ) ; <i32> [#uses=1]
+ ret i32 %tmp2.i
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-14-VarArgTrampoline.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-14-VarArgTrampoline.ll
new file mode 100644
index 0000000..aacea9d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-14-VarArgTrampoline.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -instcombine -S | grep zeroext
+
+ %struct.FRAME.nest = type { i32, i32 (...)* }
+ %struct.__builtin_trampoline = type { [10 x i8] }
+
+declare void @llvm.init.trampoline(i8*, i8*, i8*) nounwind
+declare i8* @llvm.adjust.trampoline(i8*) nounwind
+
+declare i32 @f(%struct.FRAME.nest* nest , ...)
+
+define i32 @nest(i32 %n) {
+entry:
+ %FRAME.0 = alloca %struct.FRAME.nest, align 8 ; <%struct.FRAME.nest*> [#uses=3]
+ %TRAMP.216 = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
+ %TRAMP.216.sub = getelementptr [10 x i8]* %TRAMP.216, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp3 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %n, i32* %tmp3, align 8
+ %FRAME.06 = bitcast %struct.FRAME.nest* %FRAME.0 to i8* ; <i8*> [#uses=1]
+ call void @llvm.init.trampoline( i8* %TRAMP.216.sub, i8* bitcast (i32 (%struct.FRAME.nest*, ...)* @f to i8*), i8* %FRAME.06 ) ; <i8*> [#uses=1]
+ %tramp = call i8* @llvm.adjust.trampoline( i8* %TRAMP.216.sub)
+ %tmp7 = getelementptr %struct.FRAME.nest* %FRAME.0, i32 0, i32 1 ; <i32 (...)**> [#uses=1]
+ %tmp89 = bitcast i8* %tramp to i32 (...)* ; <i32 (...)*> [#uses=2]
+ store i32 (...)* %tmp89, i32 (...)** %tmp7, align 8
+ %tmp2.i = call i32 (...)* %tmp89( i32 zeroext 0 ) ; <i32> [#uses=1]
+ ret i32 %tmp2.i
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-21-MismatchedCastAndCompare.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-21-MismatchedCastAndCompare.ll
new file mode 100644
index 0000000..5ff23a3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-21-MismatchedCastAndCompare.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR1940
+
+define i1 @test1(i8 %A, i8 %B) {
+ %a = zext i8 %A to i32
+ %b = zext i8 %B to i32
+ %c = icmp sgt i32 %a, %b
+ ret i1 %c
+; CHECK: %c = icmp ugt i8 %A, %B
+; CHECK: ret i1 %c
+}
+
+define i1 @test2(i8 %A, i8 %B) {
+ %a = sext i8 %A to i32
+ %b = sext i8 %B to i32
+ %c = icmp ugt i32 %a, %b
+ ret i1 %c
+; CHECK: %c = icmp ugt i8 %A, %B
+; CHECK: ret i1 %c
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-21-MulTrunc.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-21-MulTrunc.ll
new file mode 100644
index 0000000..87c2b75
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-21-MulTrunc.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+define i16 @test1(i16 %a) {
+ %tmp = zext i16 %a to i32 ; <i32> [#uses=2]
+ %tmp21 = lshr i32 %tmp, 8 ; <i32> [#uses=1]
+; CHECK: %tmp21 = lshr i16 %a, 8
+ %tmp5 = mul i32 %tmp, 5 ; <i32> [#uses=1]
+; CHECK: %tmp5 = mul i16 %a, 5
+ %tmp.upgrd.32 = or i32 %tmp21, %tmp5 ; <i32> [#uses=1]
+; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5
+ %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16 ; <i16> [#uses=1]
+ ret i16 %tmp.upgrd.3
+; CHECK: ret i16 %tmp.upgrd.32
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll
new file mode 100644
index 0000000..c161bcc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep select
+
+define double @fold(i1 %a, double %b) {
+%s = select i1 %a, double 0., double 1.
+%c = fdiv double %b, %s
+ret double %c
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-01-29-AddICmp.ll b/src/LLVM/test/Transforms/InstCombine/2008-01-29-AddICmp.ll
new file mode 100644
index 0000000..28a94ce
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-01-29-AddICmp.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | not grep {a.off}
+; PR1949
+
+define i1 @test1(i32 %a) {
+ %a.off = add i32 %a, 4 ; <i32> [#uses=1]
+ %C = icmp ult i32 %a.off, 4 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test2(i32 %a) {
+ %a.off = sub i32 %a, 4 ; <i32> [#uses=1]
+ %C = icmp ugt i32 %a.off, -5 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test3(i32 %a) {
+ %a.off = add i32 %a, 4 ; <i32> [#uses=1]
+ %C = icmp slt i32 %a.off, 2147483652 ; <i1> [#uses=1]
+ ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-02-13-MulURem.ll b/src/LLVM/test/Transforms/InstCombine/2008-02-13-MulURem.ll
new file mode 100644
index 0000000..a88c510
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-02-13-MulURem.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep rem
+; PR1933
+
+define i32 @fold(i32 %a) {
+ %s = mul i32 %a, 3
+ %c = urem i32 %s, 3
+ ret i32 %c
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow.ll b/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow.ll
new file mode 100644
index 0000000..af61c15
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep {ret i.* 0} | count 2
+; PR2048
+
+define i32 @i(i32 %a) {
+ %tmp1 = sdiv i32 %a, -1431655765
+ %tmp2 = sdiv i32 %tmp1, 3
+ ret i32 %tmp2
+}
+
+define i8 @j(i8 %a) {
+ %tmp1 = sdiv i8 %a, 64
+ %tmp2 = sdiv i8 %tmp1, 3
+ ret i8 %tmp2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow2.ll b/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow2.ll
new file mode 100644
index 0000000..d26dec1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-02-16-SDivOverflow2.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {sdiv i8 \%a, 9}
+; PR2048
+
+define i8 @i(i8 %a) {
+ %tmp1 = sdiv i8 %a, -3
+ %tmp2 = sdiv i8 %tmp1, -3
+ ret i8 %tmp2
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-02-23-MulSub.ll b/src/LLVM/test/Transforms/InstCombine/2008-02-23-MulSub.ll
new file mode 100644
index 0000000..bb21c4b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-02-23-MulSub.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep mul
+
+define i26 @test(i26 %a) nounwind {
+entry:
+ %_add = mul i26 %a, 2885 ; <i26> [#uses=1]
+ %_shl2 = mul i26 %a, 2884 ; <i26> [#uses=1]
+ %_sub = sub i26 %_add, %_shl2 ; <i26> [#uses=1]
+ ret i26 %_sub
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-02-28-OrFCmpCrash.ll b/src/LLVM/test/Transforms/InstCombine/2008-02-28-OrFCmpCrash.ll
new file mode 100644
index 0000000..7f8bd4f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-02-28-OrFCmpCrash.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; rdar://5771353
+
+define float @test(float %x, x86_fp80 %y) nounwind readonly {
+entry:
+ %tmp67 = fcmp uno x86_fp80 %y, 0xK00000000000000000000 ; <i1> [#uses=1]
+ %tmp71 = fcmp uno float %x, 0.000000e+00 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp67, %tmp71 ; <i1> [#uses=1]
+ br i1 %bothcond, label %bb74, label %bb80
+
+bb74: ; preds = %entry
+ ret float 0.000000e+00
+
+bb80: ; preds = %entry
+ ret float 0.000000e+00
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-03-13-IntToPtr.ll b/src/LLVM/test/Transforms/InstCombine/2008-03-13-IntToPtr.ll
new file mode 100644
index 0000000..da7e49e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-03-13-IntToPtr.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {16} | count 1
+
+define i8* @bork(i8** %qux) {
+ %tmp275 = load i8** %qux, align 1
+ %tmp275276 = ptrtoint i8* %tmp275 to i32
+ %tmp277 = add i32 %tmp275276, 16
+ %tmp277278 = inttoptr i32 %tmp277 to i8*
+ ret i8* %tmp277278
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-04-22-ByValBitcast.ll b/src/LLVM/test/Transforms/InstCombine/2008-04-22-ByValBitcast.ll
new file mode 100644
index 0000000..aa38065
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-04-22-ByValBitcast.ll
@@ -0,0 +1,15 @@
+;; The bitcast cannot be eliminated because byval arguments need
+;; the correct type, or at least a type of the correct size.
+; RUN: opt < %s -instcombine -S | grep bitcast
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9"
+ %struct.NSRect = type { [4 x float] }
+
+define void @foo(i8* %context) nounwind {
+entry:
+ %tmp1 = bitcast i8* %context to %struct.NSRect* ; <%struct.NSRect*> [#uses=1]
+ call void (i32, ...)* @bar( i32 3, %struct.NSRect* byval align 4 %tmp1 ) nounwind
+ ret void
+}
+
+declare void @bar(i32, ...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-04-28-VolatileStore.ll b/src/LLVM/test/Transforms/InstCombine/2008-04-28-VolatileStore.ll
new file mode 100644
index 0000000..6847f5e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-04-28-VolatileStore.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep {store volatile}
+
+define void @test() {
+ %votf = alloca <4 x float> ; <<4 x float>*> [#uses=1]
+ volatile store <4 x float> zeroinitializer, <4 x float>* %votf, align 16
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadDontMerge.ll b/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadDontMerge.ll
new file mode 100644
index 0000000..a24f307
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadDontMerge.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine -S | grep {load volatile} | count 2
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+@g_1 = internal global i32 0 ; <i32*> [#uses=3]
+
+define i32 @main() nounwind {
+entry:
+ %tmp93 = icmp slt i32 0, 10 ; <i1> [#uses=0]
+ %tmp34 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %b.0.reg2mem.0 = phi i32 [ 0, %entry ], [ %tmp6, %bb ] ; <i32> [#uses=1]
+ %tmp3.reg2mem.0 = phi i32 [ %tmp34, %entry ], [ %tmp3, %bb ] ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp3.reg2mem.0, 5 ; <i32> [#uses=1]
+ volatile store i32 %tmp4, i32* @g_1, align 4
+ %tmp6 = add i32 %b.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %tmp9 = icmp slt i32 %tmp6, 10 ; <i1> [#uses=1]
+ %tmp3 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br i1 %tmp9, label %bb, label %bb11
+
+bb11: ; preds = %bb
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadMerge.ll b/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadMerge.ll
new file mode 100644
index 0000000..5fb11ff
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-04-29-VolatileLoadMerge.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instcombine -S | grep {load volatile} | count 2
+; PR2262
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+@g_1 = internal global i32 0 ; <i32*> [#uses=3]
+
+define i32 @main(i32 %i) nounwind {
+entry:
+ %tmp93 = icmp slt i32 %i, 10 ; <i1> [#uses=0]
+ %tmp34 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br i1 %tmp93, label %bb11, label %bb
+
+bb: ; preds = %bb, %entry
+ %tmp3 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br label %bb11
+
+bb11: ; preds = %bb
+ %tmp4 = phi i32 [ %tmp34, %entry ], [ %tmp3, %bb ] ; <i32> [#uses=1]
+ ret i32 %tmp4
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-08-LiveStoreDelete.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-08-LiveStoreDelete.ll
new file mode 100644
index 0000000..bbd0042
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-08-LiveStoreDelete.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine -S | grep {store i8} | count 3
+; PR2297
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+define i32 @a() nounwind {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp1 = call i8* @malloc( i32 10 ) nounwind ; <i8*> [#uses=5]
+ %tmp3 = getelementptr i8* %tmp1, i32 1 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp3, align 1
+ %tmp5 = getelementptr i8* %tmp1, i32 0 ; <i8*> [#uses=1]
+ store i8 1, i8* %tmp5, align 1
+ %tmp7 = call i32 @strlen( i8* %tmp1 ) nounwind readonly ; <i32> [#uses=1]
+ %tmp9 = getelementptr i8* %tmp1, i32 0 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp9, align 1
+ %tmp11 = call i32 (...)* @b( i8* %tmp1 ) nounwind ; <i32> [#uses=0]
+ ret i32 %tmp7
+}
+
+declare i8* @malloc(i32) nounwind
+
+declare i32 @strlen(i8*) nounwind readonly
+
+declare i32 @b(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll
new file mode 100644
index 0000000..1da2856
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-08-StrLenSink.ll
@@ -0,0 +1,32 @@
+; RUN: opt -S -instcombine %s | FileCheck %s
+; PR2297
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+define i32 @a() nounwind {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp1 = call i8* @malloc( i32 10 ) nounwind ; <i8*> [#uses=5]
+ %tmp3 = getelementptr i8* %tmp1, i32 1 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp3, align 1
+ %tmp5 = getelementptr i8* %tmp1, i32 0 ; <i8*> [#uses=1]
+ store i8 1, i8* %tmp5, align 1
+; CHECK: store
+; CHECK: store
+; CHECK-NEXT: strlen
+; CHECK-NEXT: store
+ %tmp7 = call i32 @strlen( i8* %tmp1 ) nounwind readonly ; <i32> [#uses=1]
+ %tmp9 = getelementptr i8* %tmp1, i32 0 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp9, align 1
+ %tmp11 = call i32 (...)* @b( i8* %tmp1 ) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret i32 %tmp7
+}
+
+declare i8* @malloc(i32) nounwind
+
+declare i32 @strlen(i8*) nounwind readonly
+
+declare i32 @b(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-09-SinkOfInvoke.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-09-SinkOfInvoke.ll
new file mode 100644
index 0000000..f6eb248
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-09-SinkOfInvoke.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR2303
+ %"struct.std::ctype<char>" = type { %"struct.std::locale::facet", i32*, i8, i32*, i32*, i16*, i8, [256 x i8], [256 x i8], i8 }
+ %"struct.std::locale::facet" = type { i32 (...)**, i32 }
+
+declare i32* @_ZNSt6locale5facet15_S_get_c_localeEv()
+
+declare i32** @__ctype_toupper_loc() readnone
+
+declare i32** @__ctype_tolower_loc() readnone
+
+define void @_ZNSt5ctypeIcEC2EPiPKtbm(%"struct.std::ctype<char>"* %this, i32* %unnamed_arg, i16* %__table, i8 zeroext %__del, i64 %__refs) {
+entry:
+ %tmp8 = invoke i32* @_ZNSt6locale5facet15_S_get_c_localeEv( )
+ to label %invcont unwind label %lpad ; <i32*> [#uses=0]
+
+invcont: ; preds = %entry
+ %tmp32 = invoke i32** @__ctype_toupper_loc( ) readnone
+ to label %invcont31 unwind label %lpad ; <i32**> [#uses=0]
+
+invcont31: ; preds = %invcont
+ %tmp38 = invoke i32** @__ctype_tolower_loc( ) readnone
+ to label %invcont37 unwind label %lpad ; <i32**> [#uses=1]
+
+invcont37: ; preds = %invcont31
+ %tmp39 = load i32** %tmp38, align 8 ; <i32*> [#uses=1]
+ %tmp41 = getelementptr %"struct.std::ctype<char>"* %this, i32 0, i32 4 ; <i32**> [#uses=1]
+ store i32* %tmp39, i32** %tmp41, align 8
+ ret void
+
+lpad: ; preds = %invcont31, %invcont, %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-17-InfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-17-InfLoop.ll
new file mode 100644
index 0000000..2939a48
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-17-InfLoop.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR2339
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+
+declare void @BZALLOC(i32)
+
+define void @f(i32) {
+entry:
+ %blockSize100k = alloca i32 ; <i32*> [#uses=2]
+ store i32 %0, i32* %blockSize100k
+ %n = alloca i32 ; <i32*> [#uses=2]
+ load i32* %blockSize100k ; <i32>:1 [#uses=1]
+ store i32 %1, i32* %n
+ load i32* %n ; <i32>:2 [#uses=1]
+ add i32 %2, 2 ; <i32>:3 [#uses=1]
+ mul i32 %3, ptrtoint (i32* getelementptr (i32* null, i32 1) to i32) ; <i32>:4 [#uses=1]
+ call void @BZALLOC( i32 %4 )
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-18-FoldIntToPtr.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-18-FoldIntToPtr.ll
new file mode 100644
index 0000000..b34fc1e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-18-FoldIntToPtr.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 false} | count 2
+; PR2329
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define i1 @f1() {
+ ret i1 icmp eq (i8* inttoptr (i32 1 to i8*), i8* inttoptr (i32 2 to i8*))
+}
+
+define i1 @f2() {
+ ret i1 icmp eq (i8* inttoptr (i16 1 to i8*), i8* inttoptr (i16 2 to i8*))
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-22-IDivVector.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
new file mode 100644
index 0000000..f7ba99c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
@@ -0,0 +1,6 @@
+; RUN: opt < %s -instcombine -disable-output
+
+define <3 x i8> @f(<3 x i8> %i) {
+ %A = sdiv <3 x i8> %i, %i
+ ret <3 x i8> %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-22-NegValVector.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-22-NegValVector.ll
new file mode 100644
index 0000000..bf92faf
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-22-NegValVector.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | not grep sub
+
+define <3 x i8> @f(<3 x i8> %a) {
+ %A = sub <3 x i8> zeroinitializer, %a
+ %B = mul <3 x i8> %A, <i8 5, i8 5, i8 5>
+ ret <3 x i8> %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-23-CompareFold.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-23-CompareFold.ll
new file mode 100644
index 0000000..2de5af7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-23-CompareFold.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 false}
+; PR2359
+define i1 @f(i8* %x) {
+entry:
+ %tmp462 = load i8* %x, align 1 ; <i8> [#uses=1]
+ %tmp462463 = sitofp i8 %tmp462 to float ; <float> [#uses=1]
+ %tmp464 = fcmp ugt float %tmp462463, 0x47EFFFFFE0000000 ; <i1>
+ ret i1 %tmp464
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-31-AddBool.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-31-AddBool.ll
new file mode 100644
index 0000000..5416693
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-31-AddBool.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep {xor}
+; PR2389
+
+define i1 @test(i1 %a, i1 %b) {
+ %A = add i1 %a, %b
+ ret i1 %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-05-31-Bools.ll b/src/LLVM/test/Transforms/InstCombine/2008-05-31-Bools.ll
new file mode 100644
index 0000000..a0fe47a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-05-31-Bools.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -instcombine -S > %t
+; RUN: grep {xor} %t
+; RUN: grep {and} %t
+; RUN: not grep {div} %t
+
+define i1 @foo1(i1 %a, i1 %b) {
+ %A = sub i1 %a, %b
+ ret i1 %A
+}
+
+define i1 @foo2(i1 %a, i1 %b) {
+ %A = mul i1 %a, %b
+ ret i1 %A
+}
+
+define i1 @foo3(i1 %a, i1 %b) {
+ %A = udiv i1 %a, %b
+ ret i1 %A
+}
+
+define i1 @foo4(i1 %a, i1 %b) {
+ %A = sdiv i1 %a, %b
+ ret i1 %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-05-ashr-crash.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-05-ashr-crash.ll
new file mode 100644
index 0000000..5e4a9d0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-05-ashr-crash.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine
+
+define i65 @foo(i65 %x) nounwind {
+entry:
+ %tmp2 = ashr i65 %x, 65 ; <i65> [#uses=1]
+ ret i65 %tmp2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-08-ICmpPHI.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-08-ICmpPHI.ll
new file mode 100644
index 0000000..917d3ae
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-08-ICmpPHI.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -instcombine -S | grep {phi i32} | count 2
+
+define void @test() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb16, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %somebb ] ; <i32> [#uses=1]
+ %x.0 = phi i32 [ 37, %entry ], [ %tmp17, %somebb ] ; <i32> [#uses=1]
+ %tmp = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=0]
+ %tmp1 = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=0]
+ %tmp2 = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=1]
+ %tmp3 = icmp eq i32 %tmp2, 0 ; <i1> [#uses=1]
+ br i1 %tmp3, label %bb7, label %bb5
+
+bb5: ; preds = %bb
+ %tmp6 = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=0]
+ br label %bb7
+
+bb7: ; preds = %bb5, %bb
+ %tmp8 = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=0]
+ %tmp9 = tail call i32 (...)* @bork( ) nounwind ; <i32> [#uses=0]
+ %tmp11 = icmp eq i32 %x.0, 37 ; <i1> [#uses=1]
+ br i1 %tmp11, label %bb14, label %bb16
+
+bb14: ; preds = %bb7
+ %tmp15 = tail call i32 (...)* @bar( ) nounwind ; <i32> [#uses=0]
+ br label %bb16
+
+bb16: ; preds = %bb14, %bb7
+ %tmp17 = tail call i32 (...)* @zap( ) nounwind ; <i32> [#uses=1]
+ %indvar.next = add i32 %i.0, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, 42 ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %somebb
+
+somebb:
+ br label %bb
+
+return: ; preds = %bb16
+ ret void
+}
+
+declare i32 @bork(...)
+
+declare i32 @bar(...)
+
+declare i32 @zap(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-13-InfiniteLoopStore.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-13-InfiniteLoopStore.ll
new file mode 100644
index 0000000..08959c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-13-InfiniteLoopStore.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | grep {store i32} | count 2
+
+@g_139 = global i32 0 ; <i32*> [#uses=2]
+
+define void @func_56(i32 %p_60) nounwind {
+entry:
+ store i32 1, i32* @g_139, align 4
+ %tmp1 = icmp ne i32 %p_60, 0 ; <i1> [#uses=1]
+ %tmp12 = zext i1 %tmp1 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp12, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb, label %return
+
+bb: ; preds = %bb, %entry
+ store i32 1, i32* @g_139, align 4
+ br label %bb
+
+return: ; preds = %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-13-ReadOnlyCallStore.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-13-ReadOnlyCallStore.ll
new file mode 100644
index 0000000..aed1b14
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-13-ReadOnlyCallStore.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | grep {store i8} | count 2
+
+define i32 @a(i8* %s) nounwind {
+entry:
+ store i8 0, i8* %s, align 1 ; This store cannot be eliminated!
+ %tmp3 = call i32 @strlen( i8* %s ) nounwind readonly
+ %tmp5 = icmp ne i32 %tmp3, 0
+ br i1 %tmp5, label %bb, label %bb8
+
+bb: ; preds = %entry
+ store i8 0, i8* %s, align 1
+ br label %bb8
+
+bb8:
+ ret i32 %tmp3
+}
+
+declare i32 @strlen(i8*) nounwind readonly
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-19-UncondLoad.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-19-UncondLoad.ll
new file mode 100644
index 0000000..05f1c52
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-19-UncondLoad.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -S | grep load | count 3
+; PR2471
+
+declare i32 @x(i32*)
+define i32 @b(i32* %a, i32* %b) {
+entry:
+ %tmp1 = load i32* %a
+ %tmp3 = load i32* %b
+ %add = add i32 %tmp1, %tmp3
+ %call = call i32 @x( i32* %a )
+ %tobool = icmp ne i32 %add, 0
+ ; not safe to turn into an uncond load
+ %cond = select i1 %tobool, i32* %b, i32* %a
+ %tmp8 = load i32* %cond
+ ret i32 %tmp8
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-21-CompareMiscomp.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-21-CompareMiscomp.ll
new file mode 100644
index 0000000..c3371c6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-21-CompareMiscomp.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | grep {icmp eq i32 %In, 15}
+; PR2479
+; (See also PR1800.)
+
+define i1 @test(i32 %In) {
+ %c1 = icmp ugt i32 %In, 13
+ %c2 = icmp eq i32 %In, 15
+ %V = and i1 %c1, %c2
+ ret i1 %V
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-06-24-StackRestore.ll b/src/LLVM/test/Transforms/InstCombine/2008-06-24-StackRestore.ll
new file mode 100644
index 0000000..8307834
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-06-24-StackRestore.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -instcombine -S | grep {call.*llvm.stackrestore}
+; PR2488
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+@p = weak global i8* null ; <i8**> [#uses=2]
+
+define i32 @main() nounwind {
+entry:
+ %tmp248 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp2752 = alloca i32 ; <i32*> [#uses=2]
+ %tmpcast53 = bitcast i32* %tmp2752 to i8* ; <i8*> [#uses=1]
+ store i32 2, i32* %tmp2752, align 4
+ volatile store i8* %tmpcast53, i8** @p, align 4
+ br label %bb44
+
+bb: ; preds = %bb44
+ ret i32 0
+
+bb44: ; preds = %bb44, %entry
+ %indvar = phi i32 [ 0, %entry ], [ %tmp3857, %bb44 ] ; <i32> [#uses=1]
+ %tmp249 = phi i8* [ %tmp248, %entry ], [ %tmp2, %bb44 ] ; <i8*> [#uses=1]
+ %tmp3857 = add i32 %indvar, 1 ; <i32> [#uses=3]
+ call void @llvm.stackrestore( i8* %tmp249 )
+ %tmp2 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp4 = srem i32 %tmp3857, 1000 ; <i32> [#uses=2]
+ %tmp5 = add i32 %tmp4, 1 ; <i32> [#uses=1]
+ %tmp27 = alloca i32, i32 %tmp5 ; <i32*> [#uses=3]
+ %tmpcast = bitcast i32* %tmp27 to i8* ; <i8*> [#uses=1]
+ store i32 1, i32* %tmp27, align 4
+ %tmp34 = getelementptr i32* %tmp27, i32 %tmp4 ; <i32*> [#uses=1]
+ store i32 2, i32* %tmp34, align 4
+ volatile store i8* %tmpcast, i8** @p, align 4
+ %exitcond = icmp eq i32 %tmp3857, 999999 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb, label %bb44
+}
+
+declare i8* @llvm.stacksave() nounwind
+
+declare void @llvm.stackrestore(i8*) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-08-AndICmp.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-08-AndICmp.ll
new file mode 100644
index 0000000..a12f4bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-08-AndICmp.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep icmp | count 1
+; PR2330
+
+define i1 @foo(i32 %a, i32 %b) nounwind {
+entry:
+ icmp ult i32 %a, 8 ; <i1>:0 [#uses=1]
+ icmp ult i32 %b, 8 ; <i1>:1 [#uses=1]
+ and i1 %1, %0 ; <i1>:2 [#uses=1]
+ ret i1 %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-08-ShiftOneAndOne.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-08-ShiftOneAndOne.ll
new file mode 100644
index 0000000..8245b4d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-08-ShiftOneAndOne.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {icmp ne i32 \%a}
+; PR2330
+
+define i1 @foo(i32 %a) nounwind {
+entry:
+ %tmp15 = shl i32 1, %a ; <i32> [#uses=1]
+ %tmp237 = and i32 %tmp15, 1 ; <i32> [#uses=1]
+ %toBool = icmp eq i32 %tmp237, 0 ; <i1> [#uses=1]
+ ret i1 %toBool
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-08-SubAnd.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-08-SubAnd.ll
new file mode 100644
index 0000000..0091159
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-08-SubAnd.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep -v {i32 8}
+; PR2330
+
+define i32 @a(i32 %a) nounwind {
+entry:
+ %tmp2 = sub i32 8, %a ; <i32> [#uses=1]
+ %tmp3 = and i32 %tmp2, 7 ; <i32> [#uses=1]
+ ret i32 %tmp3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-08-VolatileLoadMerge.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-08-VolatileLoadMerge.ll
new file mode 100644
index 0000000..8104408
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-08-VolatileLoadMerge.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -instcombine -S | grep {load volatile} | count 2
+; PR2496
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+@g_1 = internal global i32 0 ; <i32*> [#uses=3]
+
+define i32 @main() nounwind {
+entry:
+ %tmp93 = icmp slt i32 0, 10 ; <i1> [#uses=0]
+ %tmp34 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %b.0.reg2mem.0 = phi i32 [ 0, %entry ], [ %tmp6, %bb ] ; <i32> [#uses=1]
+ %tmp3.reg2mem.0 = phi i32 [ %tmp3, %bb ], [ %tmp34, %entry ]
+ %tmp4 = add i32 %tmp3.reg2mem.0, 5 ; <i32> [#uses=1]
+ volatile store i32 %tmp4, i32* @g_1, align 4
+ %tmp6 = add i32 %b.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %tmp9 = icmp slt i32 %tmp6, 10 ; <i1> [#uses=1]
+ %tmp3 = volatile load i32* @g_1, align 4 ; <i32> [#uses=1]
+ br i1 %tmp9, label %bb, label %bb11
+
+bb11: ; preds = %bb
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-09-SubAndError.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-09-SubAndError.ll
new file mode 100644
index 0000000..47a7590
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-09-SubAndError.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep {sub i32 0}
+; PR2330
+
+define i32 @foo(i32 %a) nounwind {
+entry:
+ %A = sub i32 5, %a
+ %B = and i32 %A, 2
+ ret i32 %B
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll
new file mode 100644
index 0000000..e911532
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | grep {%C = xor i1 %A, true}
+; RUN: opt < %s -instcombine -S | grep {ret i1 false}
+; PR2539
+
+define i1 @test1(i1 %A) {
+ %B = zext i1 %A to i32
+ %C = icmp slt i32 %B, 1
+ ret i1 %C
+}
+
+
+define i1 @test2(i1 zeroext %b) {
+entry:
+ %cmptmp = icmp slt i1 %b, true ; <i1> [#uses=1]
+ ret i1 %cmptmp
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-10-ICmpBinOp.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-10-ICmpBinOp.ll
new file mode 100644
index 0000000..76e3039
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-10-ICmpBinOp.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | not grep add
+; RUN: opt < %s -instcombine -S | not grep mul
+; PR2330
+
+define i1 @f(i32 %x, i32 %y) nounwind {
+entry:
+ %A = add i32 %x, 5
+ %B = add i32 %y, 5
+ %C = icmp eq i32 %A, %B
+ ret i1 %C
+}
+
+define i1 @g(i32 %x, i32 %y) nounwind {
+entry:
+ %A = mul i32 %x, 5
+ %B = mul i32 %y, 5
+ %C = icmp eq i32 %A, %B
+ ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-11-RemAnd.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-11-RemAnd.ll
new file mode 100644
index 0000000..bf53451
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-11-RemAnd.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep rem
+; PR2330
+
+define i32 @a(i32 %b) nounwind {
+entry:
+ srem i32 %b, 8 ; <i32>:0 [#uses=1]
+ and i32 %0, 1 ; <i32>:1 [#uses=1]
+ ret i32 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-13-DivZero.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-13-DivZero.ll
new file mode 100644
index 0000000..be1f8c2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-13-DivZero.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -S | grep {lshr.*3}
+; RUN: opt < %s -instcombine -S | grep {call .*%cond}
+; PR2506
+
+; We can simplify the operand of udiv to '8', but not the operand to the
+; call. If the callee never returns, we can't assume the div is reachable.
+define i32 @a(i32 %x, i32 %y) {
+entry:
+ %tobool = icmp ne i32 %y, 0 ; <i1> [#uses=1]
+ %cond = select i1 %tobool, i32 8, i32 0 ; <i32> [#uses=2]
+ %call = call i32 @b( i32 %cond ) ; <i32> [#uses=0]
+ %div = udiv i32 %x, %cond ; <i32> [#uses=1]
+ ret i32 %div
+}
+
+declare i32 @b(i32)
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-16-fsub.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-16-fsub.ll
new file mode 100644
index 0000000..672b4e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-16-fsub.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep sub
+; PR2553
+
+define double @test(double %X) nounwind {
+ ; fsub of self can't be optimized away.
+ %Y = fsub double %X, %X
+ ret double %Y
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-07-16-sse2_storel_dq.ll b/src/LLVM/test/Transforms/InstCombine/2008-07-16-sse2_storel_dq.ll
new file mode 100644
index 0000000..501d8a6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-07-16-sse2_storel_dq.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | not grep {store }
+; PR2296
+
+@G = common global double 0.000000e+00, align 16
+
+define void @x(<2 x i64> %y) nounwind {
+entry:
+ bitcast <2 x i64> %y to <4 x i32>
+ call void @llvm.x86.sse2.storel.dq( i8* bitcast (double* @G to i8*), <4 x i32> %0 ) nounwind
+ ret void
+}
+
+declare void @llvm.x86.sse2.storel.dq(i8*, <4 x i32>) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-08-05-And.ll b/src/LLVM/test/Transforms/InstCombine/2008-08-05-And.ll
new file mode 100644
index 0000000..9773c2d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-08-05-And.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | not grep or
+; PR2629
+
+define void @f(i8* %x) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %g1 = getelementptr i8* %x, i32 0
+ %l1 = load i8* %g1, align 1
+ %s1 = sub i8 %l1, 6
+ %c1 = icmp ugt i8 %s1, 2
+ %s2 = sub i8 %l1, 10
+ %c2 = icmp ugt i8 %s2, 2
+ %a1 = and i1 %c1, %c2
+ br i1 %a1, label %incompatible, label %okay
+
+okay:
+ ret void
+
+incompatible:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-08-17-ICmpXorSignbit.ll b/src/LLVM/test/Transforms/InstCombine/2008-08-17-ICmpXorSignbit.ll
new file mode 100644
index 0000000..e9081f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-08-17-ICmpXorSignbit.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -instcombine -S | not grep xor
+
+define i1 @test1(i8 %x, i8 %y) {
+ %X = xor i8 %x, 128
+ %Y = xor i8 %y, 128
+ %tmp = icmp slt i8 %X, %Y
+ ret i1 %tmp
+}
+
+define i1 @test2(i8 %x, i8 %y) {
+ %X = xor i8 %x, 128
+ %Y = xor i8 %y, 128
+ %tmp = icmp ult i8 %X, %Y
+ ret i1 %tmp
+}
+
+define i1 @test3(i8 %x) {
+ %X = xor i8 %x, 128
+ %tmp = icmp uge i8 %X, 15
+ ret i1 %tmp
+}
+
+define i1 @test4(i8 %x, i8 %y) {
+ %X = xor i8 %x, 127
+ %Y = xor i8 %y, 127
+ %tmp = icmp slt i8 %X, %Y
+ ret i1 %tmp
+}
+
+define i1 @test5(i8 %x, i8 %y) {
+ %X = xor i8 %x, 127
+ %Y = xor i8 %y, 127
+ %tmp = icmp ult i8 %X, %Y
+ ret i1 %tmp
+}
+
+define i1 @test6(i8 %x) {
+ %X = xor i8 %x, 127
+ %tmp = icmp uge i8 %X, 15
+ ret i1 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll b/src/LLVM/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll
new file mode 100644
index 0000000..7c50141
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -instcombine
+
+define void @entry(i32 %m_task_id, i32 %start_x, i32 %end_x, i32 %start_y, i32 %end_y) {
+ br label %1
+
+; <label>:1 ; preds = %4, %0
+ %2 = icmp slt i32 0, %end_y ; <i1> [#uses=1]
+ br i1 %2, label %4, label %3
+
+; <label>:3 ; preds = %1
+ ret void
+
+; <label>:4 ; preds = %6, %1
+ %5 = icmp slt i32 0, %end_x ; <i1> [#uses=1]
+ br i1 %5, label %6, label %1
+
+; <label>:6 ; preds = %4
+ %7 = srem <2 x i32> zeroinitializer, zeroinitializer ; <<2 x i32>> [#uses=1]
+ %8 = extractelement <2 x i32> %7, i32 1 ; <i32> [#uses=1]
+ %9 = select i1 false, i32 0, i32 %8 ; <i32> [#uses=1]
+ %10 = insertelement <2 x i32> zeroinitializer, i32 %9, i32 1 ; <<2 x i32>> [#uses=1]
+ %11 = extractelement <2 x i32> %10, i32 1 ; <i32> [#uses=1]
+ %12 = insertelement <4 x i32> zeroinitializer, i32 %11, i32 3 ; <<4 x i32>> [#uses=1]
+ %13 = sitofp <4 x i32> %12 to <4 x float> ; <<4 x float>> [#uses=1]
+ store <4 x float> %13, <4 x float>* null
+ br label %4
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-09-29-FoldingOr.ll b/src/LLVM/test/Transforms/InstCombine/2008-09-29-FoldingOr.ll
new file mode 100644
index 0000000..31ea94a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-09-29-FoldingOr.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {or i1}
+; PR2844
+
+define i32 @test(i32 %p_74) {
+ %A = icmp eq i32 %p_74, 0 ; <i1> [#uses=1]
+ %B = icmp slt i32 %p_74, -638208501 ; <i1> [#uses=1]
+ %or.cond = or i1 %A, %B ; <i1> [#uses=1]
+ %iftmp.10.0 = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %iftmp.10.0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-10-11-DivCompareFold.ll b/src/LLVM/test/Transforms/InstCombine/2008-10-11-DivCompareFold.ll
new file mode 100644
index 0000000..fd36d86
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-10-11-DivCompareFold.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 false}
+; PR2697
+
+define i1 @x(i32 %x) nounwind {
+ %div = sdiv i32 %x, 65536 ; <i32> [#uses=1]
+ %cmp = icmp slt i32 %div, -65536
+ ret i1 %cmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll b/src/LLVM/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll
new file mode 100644
index 0000000..d70d052
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-10-23-ConstFoldWithoutMask.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine
+; PR2940
+
+define i32 @tstid() {
+ %var0 = inttoptr i32 1 to i8* ; <i8*> [#uses=1]
+ %var2 = ptrtoint i8* %var0 to i32 ; <i32> [#uses=1]
+ ret i32 %var2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll
new file mode 100644
index 0000000..aa077e2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 true}
+; PR2993
+
+define i1 @foo(i32 %x) {
+ %1 = srem i32 %x, -1
+ %2 = icmp eq i32 %1, 0
+ ret i1 %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-08-FCmp.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-08-FCmp.ll
new file mode 100644
index 0000000..c636288
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-08-FCmp.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR3021
+
+; When inst combining an FCMP with the LHS coming from a uitofp instruction, we
+; can't lower it to signed ICMP instructions.
+
+define i1 @test1(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp ole double %1, 0.000000e+00
+; CHECK: icmp eq i32 %val, 0
+ ret i1 %2
+}
+
+define i1 @test2(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp olt double %1, 0.000000e+00
+ ret i1 %2
+; CHECK: ret i1 false
+}
+
+define i1 @test3(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp oge double %1, 0.000000e+00
+ ret i1 %2
+; CHECK: ret i1 true
+}
+
+define i1 @test4(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp ogt double %1, 0.000000e+00
+; CHECK: icmp ne i32 %val, 0
+ ret i1 %2
+}
+
+define i1 @test5(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp ogt double %1, -4.400000e+00
+ ret i1 %2
+; CHECK: ret i1 true
+}
+
+define i1 @test6(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp olt double %1, -4.400000e+00
+ ret i1 %2
+; CHECK: ret i1 false
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
new file mode 100644
index 0000000..43af190
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR3103
+
+define i8 @test1(i8 %x, i8 %y) {
+; CHECK: @test1
+ %A = udiv i8 %x, %y
+; CHECK-NEXT: urem
+ %B = mul i8 %A, %y
+ %C = sub i8 %x, %B
+ ret i8 %C
+; CHECK-NEXT: ret
+}
+
+define i8 @test2(i8 %x, i8 %y) {
+; CHECK: @test2
+ %A = sdiv i8 %x, %y
+; CHECK-NEXT: srem
+ %B = mul i8 %A, %y
+ %C = sub i8 %x, %B
+ ret i8 %C
+; CHECK-NEXT: ret
+}
+
+define i8 @test3(i8 %x, i8 %y) {
+; CHECK: @test3
+ %A = udiv i8 %x, %y
+; CHECK-NEXT: urem
+ %B = mul i8 %A, %y
+ %C = sub i8 %B, %x
+; CHECK-NEXT: sub
+ ret i8 %C
+; CHECK-NEXT: ret
+}
+
+define i8 @test4(i8 %x) {
+; CHECK: @test4
+ %A = udiv i8 %x, 3
+; CHECK-NEXT: urem
+ %B = mul i8 %A, -3
+; CHECK-NEXT: sub
+ %C = sub i8 %x, %B
+; CHECK-NEXT: add
+ ret i8 %C
+; CHECK-NEXT: ret
+}
+
+define i32 @test5(i32 %x, i32 %y) {
+; CHECK: @test5
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = sdiv i32 %x, %y
+; CHECK-NEXT: sdiv
+ %mul = mul i32 %div, %y
+ %r = sdiv i32 %mul, %y
+ ret i32 %r
+; CHECK-NEXT: ret
+}
+
+define i32 @test6(i32 %x, i32 %y) {
+; CHECK: @test6
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = udiv i32 %x, %y
+; CHECK-NEXT: udiv
+ %mul = mul i32 %div, %y
+ %r = udiv i32 %mul, %y
+ ret i32 %r
+; CHECK-NEXT: ret
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-27-IDivVector.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-27-IDivVector.ll
new file mode 100644
index 0000000..318a80c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-27-IDivVector.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | not grep div
+
+define <2 x i8> @f(<2 x i8> %x) {
+ %A = udiv <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
+
+define <2 x i8> @g(<2 x i8> %x) {
+ %A = sdiv <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll
new file mode 100644
index 0000000..d8c53fa
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | not grep mul
+
+define <2 x i8> @f(<2 x i8> %x) {
+ %A = mul <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
+
+define <2 x i8> @g(<2 x i8> %x) {
+ %A = mul <2 x i8> %x, <i8 -1, i8 -1>
+ ret <2 x i8> %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-11-27-UDivNegative.ll b/src/LLVM/test/Transforms/InstCombine/2008-11-27-UDivNegative.ll
new file mode 100644
index 0000000..fc90bba
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-11-27-UDivNegative.ll
@@ -0,0 +1,6 @@
+; RUN: opt < %s -instcombine -S | not grep div
+
+define i8 @test(i8 %x) readnone nounwind {
+ %A = udiv i8 %x, 250
+ ret i8 %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2008-12-17-SRemNegConstVec.ll b/src/LLVM/test/Transforms/InstCombine/2008-12-17-SRemNegConstVec.ll
new file mode 100644
index 0000000..e4c7ebc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2008-12-17-SRemNegConstVec.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep {i8 2, i8 2}
+; PR2756
+
+define <2 x i8> @foo(<2 x i8> %x) {
+ %A = srem <2 x i8> %x, <i8 2, i8 -2>
+ ret <2 x i8> %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-05-i128-crash.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-05-i128-crash.ll
new file mode 100644
index 0000000..d355e0a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-05-i128-crash.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; PR3235
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define hidden i128 @"\01_gfortrani_max_value"(i32 %length, i32 %signed_flag) nounwind {
+entry:
+ switch i32 %length, label %bb13 [
+ i32 1, label %bb17
+ i32 4, label %bb9
+ i32 8, label %bb5
+ ]
+
+bb5: ; preds = %entry
+ %0 = icmp eq i32 %signed_flag, 0 ; <i1> [#uses=1]
+ %iftmp.28.0 = select i1 %0, i128 18446744073709551615, i128 9223372036854775807 ; <i128> [#uses=1]
+ ret i128 %iftmp.28.0
+
+bb9: ; preds = %entry
+ ret i128 0
+
+bb13: ; preds = %entry
+ ret i128 0
+
+bb17: ; preds = %entry
+ ret i128 0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll
new file mode 100644
index 0000000..a61a94e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -instcombine -S > %t
+; RUN: grep {, align 4} %t | count 3
+; RUN: grep {, align 8} %t | count 3
+; rdar://6480438
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+ %struct.Key = type { { i32, i32 } }
+ %struct.anon = type <{ i8, [3 x i8], i32 }>
+
+define i32 @bar(i64 %key_token2) nounwind {
+entry:
+ %iospec = alloca %struct.Key ; <%struct.Key*> [#uses=3]
+ %ret = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %0 = getelementptr %struct.Key* %iospec, i32 0, i32 0 ; <{ i32, i32 }*> [#uses=2]
+ %1 = getelementptr { i32, i32 }* %0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %1, align 4
+ %2 = getelementptr { i32, i32 }* %0, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 0, i32* %2, align 4
+ %3 = getelementptr %struct.Key* %iospec, i32 0, i32 0 ; <{ i32, i32 }*> [#uses=1]
+ %4 = bitcast { i32, i32 }* %3 to i64* ; <i64*> [#uses=1]
+ store i64 %key_token2, i64* %4, align 4
+ %5 = call i32 (...)* @foo(%struct.Key* byval align 4 %iospec, i32* %ret) nounwind ; <i32> [#uses=0]
+ %6 = load i32* %ret, align 4 ; <i32> [#uses=1]
+ ret i32 %6
+}
+
+declare i32 @foo(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-16-PointerAddrSpace.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-16-PointerAddrSpace.ll
new file mode 100644
index 0000000..ce62f35
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-16-PointerAddrSpace.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | grep {store.*addrspace(1)}
+; PR3335
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+define i32 @test(i32* %P) nounwind {
+entry:
+ %Q = bitcast i32* %P to i32 addrspace(1)*
+ store i32 0, i32 addrspace(1)* %Q, align 4
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float-specials.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float-specials.ll
new file mode 100644
index 0000000..1421347
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float-specials.ll
@@ -0,0 +1,315 @@
+; RUN: opt < %s -simplifycfg -instcombine -S | grep 0x7FF8000000000000 | count 12
+; RUN: opt < %s -simplifycfg -instcombine -S | grep {0\\.0} | count 3
+; RUN: opt < %s -simplifycfg -instcombine -S | grep {3\\.5} | count 1
+;
+
+; ModuleID = 'apf.c'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+@"\01LC" = internal constant [4 x i8] c"%f\0A\00" ; <[4 x i8]*> [#uses=1]
+
+define void @foo1() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF0000000000000, float* %x, align 4
+ store float 0x7FF8000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+declare i32 @printf(i8*, ...) nounwind
+
+define void @foo2() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF0000000000000, float* %x, align 4
+ store float 0.000000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo3() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF0000000000000, float* %x, align 4
+ store float 3.500000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo4() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF0000000000000, float* %x, align 4
+ store float 0x7FF0000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo5() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF8000000000000, float* %x, align 4
+ store float 0x7FF0000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo6() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF8000000000000, float* %x, align 4
+ store float 0.000000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo7() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF8000000000000, float* %x, align 4
+ store float 3.500000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo8() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0x7FF8000000000000, float* %x, align 4
+ store float 0x7FF8000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo9() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0.000000e+00, float* %x, align 4
+ store float 0x7FF8000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo10() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0.000000e+00, float* %x, align 4
+ store float 0x7FF0000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo11() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0.000000e+00, float* %x, align 4
+ store float 0.000000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo12() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 0.000000e+00, float* %x, align 4
+ store float 3.500000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo13() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 3.500000e+00, float* %x, align 4
+ store float 0x7FF8000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo14() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 3.500000e+00, float* %x, align 4
+ store float 0x7FF0000000000000, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo15() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 3.500000e+00, float* %x, align 4
+ store float 0.000000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define void @foo16() nounwind {
+entry:
+ %y = alloca float ; <float*> [#uses=2]
+ %x = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store float 3.500000e+00, float* %x, align 4
+ store float 3.500000e+00, float* %y, align 4
+ %0 = load float* %y, align 4 ; <float> [#uses=1]
+ %1 = fpext float %0 to double ; <double> [#uses=1]
+ %2 = load float* %x, align 4 ; <float> [#uses=1]
+ %3 = fpext float %2 to double ; <double> [#uses=1]
+ %4 = frem double %3, %1 ; <double> [#uses=1]
+ %5 = call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), double %4) nounwind ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float.ll
new file mode 100644
index 0000000..6bc7ce3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-19-fmod-constant-float.ll
@@ -0,0 +1,75 @@
+; RUN: opt < %s -simplifycfg -instcombine -S | grep 0x3FB99999A0000000 | count 2
+; RUN: opt < %s -simplifycfg -instcombine -S | grep 0xBFB99999A0000000 | count 2
+; check constant folding for 'frem'. PR 3316.
+
+; ModuleID = 'tt.c'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+define float @test1() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = frem double 1.000000e-01, 1.000000e+00 ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+define float @test2() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = frem double -1.000000e-01, 1.000000e+00 ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+define float @test3() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = frem double 1.000000e-01, -1.000000e+00 ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
+
+define float @test4() nounwind {
+entry:
+ %retval = alloca float ; <float*> [#uses=2]
+ %0 = alloca float ; <float*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %1 = frem double -1.000000e-01, -1.000000e+00 ; <double> [#uses=1]
+ %2 = fptrunc double %1 to float ; <float> [#uses=1]
+ store float %2, float* %0, align 4
+ %3 = load float* %0, align 4 ; <float> [#uses=1]
+ store float %3, float* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load float* %retval ; <float> [#uses=1]
+ ret float %retval1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-24-EmptyStruct.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-24-EmptyStruct.ll
new file mode 100644
index 0000000..4b64b48
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-24-EmptyStruct.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine
+; PR3381
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.atomic_t = type { i32 }
+ %struct.inode = type { i32, %struct.mutex }
+ %struct.list_head = type { %struct.list_head*, %struct.list_head* }
+ %struct.lock_class_key = type { }
+ %struct.mutex = type { %struct.atomic_t, %struct.rwlock_t, %struct.list_head }
+ %struct.rwlock_t = type { %struct.lock_class_key }
+
+define void @handle_event(%struct.inode* %bar) nounwind {
+entry:
+ %0 = getelementptr %struct.inode* %bar, i64 -1, i32 1, i32 1 ; <%struct.rwlock_t*> [#uses=1]
+ %1 = bitcast %struct.rwlock_t* %0 to i32* ; <i32*> [#uses=1]
+ store i32 1, i32* %1, align 4
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-31-InfIterate.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-31-InfIterate.ll
new file mode 100644
index 0000000..815c1a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-31-InfIterate.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; PR3452
+define i128 @test(i64 %A, i64 %B, i1 %C, i128 %Z, i128 %Y, i64* %P, i64* %Q) {
+entry:
+ %tmp2 = trunc i128 %Z to i64
+ %tmp4 = trunc i128 %Y to i64
+ store i64 %tmp2, i64* %P
+ store i64 %tmp4, i64* %Q
+ %x = sub i64 %tmp2, %tmp4
+ %c = sub i64 %tmp2, %tmp4
+ %tmp137 = zext i1 %C to i64
+ %tmp138 = sub i64 %c, %tmp137
+ br label %T
+
+T:
+ %G = phi i64 [%tmp138, %entry], [%tmp2, %Fal]
+ %F = zext i64 %G to i128
+ ret i128 %F
+
+Fal:
+ br label %T
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-01-31-Pressure.ll b/src/LLVM/test/Transforms/InstCombine/2009-01-31-Pressure.ll
new file mode 100644
index 0000000..c3ee9a3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-01-31-Pressure.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -S | grep {%B = add i8 %b, %x}
+; PR2698
+
+declare void @use1(i1)
+declare void @use8(i8)
+
+define void @test1(i8 %a, i8 %b, i8 %x) {
+ %A = add i8 %a, %x
+ %B = add i8 %b, %x
+ %C = icmp eq i8 %A, %B
+ call void @use1(i1 %C)
+ ret void
+}
+
+define void @test2(i8 %a, i8 %b, i8 %x) {
+ %A = add i8 %a, %x
+ %B = add i8 %b, %x
+ %C = icmp eq i8 %A, %B
+ call void @use1(i1 %C)
+ call void @use8(i8 %A)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll b/src/LLVM/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll
new file mode 100644
index 0000000..bc6a204
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-02-04-FPBitcast.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine
+; PR3468
+
+define x86_fp80 @cast() {
+ %tmp = bitcast i80 0 to x86_fp80 ; <x86_fp80> [#uses=1]
+ ret x86_fp80 %tmp
+}
+
+define i80 @invcast() {
+ %tmp = bitcast x86_fp80 0xK00000000000000000000 to i80 ; <i80> [#uses=1]
+ ret i80 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll b/src/LLVM/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
new file mode 100644
index 0000000..a51c47d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
@@ -0,0 +1,279 @@
+; RUN: opt < %s -instcombine -scalarrepl -S | not grep { = alloca}
+; rdar://6417724
+; Instcombine shouldn't do anything to this function that prevents promoting the allocas inside it.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+%"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >" = type { i32* }
+%"struct.std::_Vector_base<int,std::allocator<int> >" = type { %"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl" }
+%"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl" = type { i32*, i32*, i32* }
+%"struct.std::bidirectional_iterator_tag" = type <{ i8 }>
+%"struct.std::forward_iterator_tag" = type <{ i8 }>
+%"struct.std::input_iterator_tag" = type <{ i8 }>
+%"struct.std::random_access_iterator_tag" = type <{ i8 }>
+%"struct.std::vector<int,std::allocator<int> >" = type { %"struct.std::_Vector_base<int,std::allocator<int> >" }
+
+define i32* @_Z3fooRSt6vectorIiSaIiEE(%"struct.std::vector<int,std::allocator<int> >"* %X) {
+entry:
+ %0 = alloca %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"
+ %__first_addr.i.i = alloca %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"
+ %__last_addr.i.i = alloca %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"
+ %unnamed_arg.i = alloca %"struct.std::bidirectional_iterator_tag", align 8
+ %1 = alloca %"struct.std::bidirectional_iterator_tag"
+ %__first_addr.i = alloca %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"
+ %2 = alloca %"struct.std::bidirectional_iterator_tag"
+ %3 = alloca %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"
+ %4 = alloca i32
+ %"alloca point" = bitcast i32 0 to i32
+ store i32 42, i32* %4, align 4
+ %5 = getelementptr %"struct.std::vector<int,std::allocator<int> >"* %X, i32 0, i32 0
+ %6 = getelementptr %"struct.std::_Vector_base<int,std::allocator<int> >"* %5, i32 0, i32 0
+ %7 = getelementptr %"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl"* %6, i32 0, i32 1
+ %8 = load i32** %7, align 4
+ %9 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %3, i32 0, i32 0
+ store i32* %8, i32** %9, align 4
+ %10 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %3, i32 0, i32 0
+ %11 = load i32** %10, align 4
+ %tmp2.i = ptrtoint i32* %11 to i32
+ %tmp1.i = inttoptr i32 %tmp2.i to i32*
+ %tmp3 = ptrtoint i32* %tmp1.i to i32
+ %tmp2 = inttoptr i32 %tmp3 to i32*
+ %12 = getelementptr %"struct.std::vector<int,std::allocator<int> >"* %X, i32 0, i32 0
+ %13 = getelementptr %"struct.std::_Vector_base<int,std::allocator<int> >"* %12, i32 0, i32 0
+ %14 = getelementptr %"struct.std::_Vector_base<int,std::allocator<int> >::_Vector_impl"* %13, i32 0, i32 0
+ %15 = load i32** %14, align 4
+ %16 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %0, i32 0, i32 0
+ store i32* %15, i32** %16, align 4
+ %17 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %0, i32 0, i32 0
+ %18 = load i32** %17, align 4
+ %tmp2.i17 = ptrtoint i32* %18 to i32
+ %tmp1.i18 = inttoptr i32 %tmp2.i17 to i32*
+ %tmp8 = ptrtoint i32* %tmp1.i18 to i32
+ %tmp6 = inttoptr i32 %tmp8 to i32*
+ %19 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i, i32 0, i32 0
+ store i32* %tmp6, i32** %19
+ %20 = getelementptr %"struct.std::bidirectional_iterator_tag"* %1, i32 0, i32 0
+ %21 = load i8* %20, align 1
+ %22 = or i8 %21, 0
+ %23 = or i8 %22, 0
+ %24 = or i8 %23, 0
+ %25 = getelementptr %"struct.std::bidirectional_iterator_tag"* %2, i32 0, i32 0
+ store i8 0, i8* %25, align 1
+ %elt.i = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i, i32 0, i32 0
+ %val.i = load i32** %elt.i
+ %tmp.i = bitcast %"struct.std::bidirectional_iterator_tag"* %unnamed_arg.i to i8*
+ %tmp9.i = bitcast %"struct.std::bidirectional_iterator_tag"* %2 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp.i, i8* %tmp9.i, i64 1, i32 1, i1 false)
+ %26 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %val.i, i32** %26
+ %27 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__last_addr.i.i, i32 0, i32 0
+ store i32* %tmp2, i32** %27
+ %28 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__last_addr.i.i, i32 0, i32 0
+ %29 = load i32** %28, align 4
+ %30 = ptrtoint i32* %29 to i32
+ %31 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %32 = load i32** %31, align 4
+ %33 = ptrtoint i32* %32 to i32
+ %34 = sub i32 %30, %33
+ %35 = ashr i32 %34, 2
+ %36 = ashr i32 %35, 2
+ br label %bb12.i.i
+
+bb.i.i: ; preds = %bb12.i.i
+ %37 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %38 = load i32** %37, align 4
+ %39 = load i32* %38, align 4
+ %40 = load i32* %4, align 4
+ %41 = icmp eq i32 %39, %40
+ %42 = zext i1 %41 to i8
+ %toBool.i.i = icmp ne i8 %42, 0
+ br i1 %toBool.i.i, label %bb1.i.i, label %bb2.i.i
+
+bb1.i.i: ; preds = %bb.i.i
+ %43 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %44 = load i32** %43, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb2.i.i: ; preds = %bb.i.i
+ %45 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %46 = load i32** %45, align 4
+ %47 = getelementptr i32* %46, i64 1
+ %48 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %47, i32** %48, align 4
+ %49 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %50 = load i32** %49, align 4
+ %51 = load i32* %50, align 4
+ %52 = load i32* %4, align 4
+ %53 = icmp eq i32 %51, %52
+ %54 = zext i1 %53 to i8
+ %toBool3.i.i = icmp ne i8 %54, 0
+ br i1 %toBool3.i.i, label %bb4.i.i, label %bb5.i.i
+
+bb4.i.i: ; preds = %bb2.i.i
+ %55 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %56 = load i32** %55, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb5.i.i: ; preds = %bb2.i.i
+ %57 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %58 = load i32** %57, align 4
+ %59 = getelementptr i32* %58, i64 1
+ %60 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %59, i32** %60, align 4
+ %61 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %62 = load i32** %61, align 4
+ %63 = load i32* %62, align 4
+ %64 = load i32* %4, align 4
+ %65 = icmp eq i32 %63, %64
+ %66 = zext i1 %65 to i8
+ %toBool6.i.i = icmp ne i8 %66, 0
+ br i1 %toBool6.i.i, label %bb7.i.i, label %bb8.i.i
+
+bb7.i.i: ; preds = %bb5.i.i
+ %67 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %68 = load i32** %67, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb8.i.i: ; preds = %bb5.i.i
+ %69 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %70 = load i32** %69, align 4
+ %71 = getelementptr i32* %70, i64 1
+ %72 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %71, i32** %72, align 4
+ %73 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %74 = load i32** %73, align 4
+ %75 = load i32* %74, align 4
+ %76 = load i32* %4, align 4
+ %77 = icmp eq i32 %75, %76
+ %78 = zext i1 %77 to i8
+ %toBool9.i.i = icmp ne i8 %78, 0
+ br i1 %toBool9.i.i, label %bb10.i.i, label %bb11.i.i
+
+bb10.i.i: ; preds = %bb8.i.i
+ %79 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %80 = load i32** %79, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb11.i.i: ; preds = %bb8.i.i
+ %81 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %82 = load i32** %81, align 4
+ %83 = getelementptr i32* %82, i64 1
+ %84 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %83, i32** %84, align 4
+ %85 = sub i32 %__trip_count.0.i.i, 1
+ br label %bb12.i.i
+
+bb12.i.i: ; preds = %bb11.i.i, %entry
+ %__trip_count.0.i.i = phi i32 [ %36, %entry ], [ %85, %bb11.i.i ]
+ %86 = icmp sgt i32 %__trip_count.0.i.i, 0
+ br i1 %86, label %bb.i.i, label %bb13.i.i
+
+bb13.i.i: ; preds = %bb12.i.i
+ %87 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__last_addr.i.i, i32 0, i32 0
+ %88 = load i32** %87, align 4
+ %89 = ptrtoint i32* %88 to i32
+ %90 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %91 = load i32** %90, align 4
+ %92 = ptrtoint i32* %91 to i32
+ %93 = sub i32 %89, %92
+ %94 = ashr i32 %93, 2
+ switch i32 %94, label %bb26.i.i [
+ i32 1, label %bb22.i.i
+ i32 2, label %bb18.i.i
+ i32 3, label %bb14.i.i
+ ]
+
+bb14.i.i: ; preds = %bb13.i.i
+ %95 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %96 = load i32** %95, align 4
+ %97 = load i32* %96, align 4
+ %98 = load i32* %4, align 4
+ %99 = icmp eq i32 %97, %98
+ %100 = zext i1 %99 to i8
+ %toBool15.i.i = icmp ne i8 %100, 0
+ br i1 %toBool15.i.i, label %bb16.i.i, label %bb17.i.i
+
+bb16.i.i: ; preds = %bb14.i.i
+ %101 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %102 = load i32** %101, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb17.i.i: ; preds = %bb14.i.i
+ %103 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %104 = load i32** %103, align 4
+ %105 = getelementptr i32* %104, i64 1
+ %106 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %105, i32** %106, align 4
+ br label %bb18.i.i
+
+bb18.i.i: ; preds = %bb17.i.i, %bb13.i.i
+ %107 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %108 = load i32** %107, align 4
+ %109 = load i32* %108, align 4
+ %110 = load i32* %4, align 4
+ %111 = icmp eq i32 %109, %110
+ %112 = zext i1 %111 to i8
+ %toBool19.i.i = icmp ne i8 %112, 0
+ br i1 %toBool19.i.i, label %bb20.i.i, label %bb21.i.i
+
+bb20.i.i: ; preds = %bb18.i.i
+ %113 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %114 = load i32** %113, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb21.i.i: ; preds = %bb18.i.i
+ %115 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %116 = load i32** %115, align 4
+ %117 = getelementptr i32* %116, i64 1
+ %118 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %117, i32** %118, align 4
+ br label %bb22.i.i
+
+bb22.i.i: ; preds = %bb21.i.i, %bb13.i.i
+ %119 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %120 = load i32** %119, align 4
+ %121 = load i32* %120, align 4
+ %122 = load i32* %4, align 4
+ %123 = icmp eq i32 %121, %122
+ %124 = zext i1 %123 to i8
+ %toBool23.i.i = icmp ne i8 %124, 0
+ br i1 %toBool23.i.i, label %bb24.i.i, label %bb25.i.i
+
+bb24.i.i: ; preds = %bb22.i.i
+ %125 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %126 = load i32** %125, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+bb25.i.i: ; preds = %bb22.i.i
+ %127 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ %128 = load i32** %127, align 4
+ %129 = getelementptr i32* %128, i64 1
+ %130 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__first_addr.i.i, i32 0, i32 0
+ store i32* %129, i32** %130, align 4
+ br label %bb26.i.i
+
+bb26.i.i: ; preds = %bb25.i.i, %bb13.i.i
+ %131 = getelementptr %"struct.__gnu_cxx::__normal_iterator<int*,std::vector<int, std::allocator<int> > >"* %__last_addr.i.i, i32 0, i32 0
+ %132 = load i32** %131, align 4
+ br label %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+
+_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit: ; preds = %bb26.i.i, %bb24.i.i, %bb20.i.i, %bb16.i.i, %bb10.i.i, %bb7.i.i, %bb4.i.i, %bb1.i.i
+ %.0.0.i.i = phi i32* [ %132, %bb26.i.i ], [ %126, %bb24.i.i ], [ %114, %bb20.i.i ], [ %102, %bb16.i.i ], [ %80, %bb10.i.i ], [ %68, %bb7.i.i ], [ %56, %bb4.i.i ], [ %44, %bb1.i.i ]
+ %tmp2.i.i = ptrtoint i32* %.0.0.i.i to i32
+ %tmp1.i.i = inttoptr i32 %tmp2.i.i to i32*
+ %tmp4.i = ptrtoint i32* %tmp1.i.i to i32
+ %tmp3.i = inttoptr i32 %tmp4.i to i32*
+ %tmp8.i = ptrtoint i32* %tmp3.i to i32
+ %tmp6.i = inttoptr i32 %tmp8.i to i32*
+ %tmp12 = ptrtoint i32* %tmp6.i to i32
+ %tmp10 = inttoptr i32 %tmp12 to i32*
+ %tmp16 = ptrtoint i32* %tmp10 to i32
+ br label %return
+
+return: ; preds = %_ZSt4findIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET_S7_S7_RKT0_.exit
+ %tmp14 = inttoptr i32 %tmp16 to i32*
+ ret i32* %tmp14
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-02-21-LoadCST.ll b/src/LLVM/test/Transforms/InstCombine/2009-02-21-LoadCST.ll
new file mode 100644
index 0000000..f56fc38
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-02-21-LoadCST.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | grep {ret i32 3679669}
+; PR3595
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+@.str1 = internal constant [4 x i8] c"\B5%8\00"
+
+define i32 @test() {
+ %rhsv = load i32* bitcast ([4 x i8]* @.str1 to i32*), align 1
+ ret i32 %rhsv
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-02-25-CrashZeroSizeArray.ll b/src/LLVM/test/Transforms/InstCombine/2009-02-25-CrashZeroSizeArray.ll
new file mode 100644
index 0000000..a8349f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-02-25-CrashZeroSizeArray.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; PR3667
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define void @_ada_c32001b(i32 %tmp5) {
+entry:
+ %max289 = select i1 false, i32 %tmp5, i32 0 ; <i32> [#uses=1]
+ %tmp6 = mul i32 %max289, 4 ; <i32> [#uses=1]
+ %tmp7 = alloca i8, i32 0 ; <i8*> [#uses=1]
+ %tmp8 = bitcast i8* %tmp7 to [0 x [0 x i32]]* ; <[0 x [0 x i32]]*> [#uses=1]
+ %tmp11 = load i32* null, align 1 ; <i32> [#uses=1]
+ %tmp12 = icmp eq i32 %tmp11, 3 ; <i1> [#uses=1]
+ %tmp13 = zext i1 %tmp12 to i8 ; <i8> [#uses=1]
+ %tmp14 = ashr i32 %tmp6, 2 ; <i32> [#uses=1]
+ %tmp15 = bitcast [0 x [0 x i32]]* %tmp8 to i8* ; <i8*> [#uses=1]
+ %tmp16 = mul i32 %tmp14, 4 ; <i32> [#uses=1]
+ %tmp17 = mul i32 1, %tmp16 ; <i32> [#uses=1]
+ %tmp18 = getelementptr i8* %tmp15, i32 %tmp17 ; <i8*> [#uses=1]
+ %tmp19 = bitcast i8* %tmp18 to [0 x i32]* ; <[0 x i32]*> [#uses=1]
+ %tmp20 = bitcast [0 x i32]* %tmp19 to i32* ; <i32*> [#uses=1]
+ %tmp21 = getelementptr i32* %tmp20, i32 0 ; <i32*> [#uses=1]
+ %tmp22 = load i32* %tmp21, align 1 ; <i32> [#uses=1]
+ %tmp23 = icmp eq i32 %tmp22, 4 ; <i1> [#uses=1]
+ %tmp24 = zext i1 %tmp23 to i8 ; <i8> [#uses=1]
+ %toBool709 = icmp ne i8 %tmp13, 0 ; <i1> [#uses=1]
+ %toBool710 = icmp ne i8 %tmp24, 0 ; <i1> [#uses=1]
+ %tmp25 = and i1 %toBool709, %toBool710 ; <i1> [#uses=1]
+ %tmp26 = zext i1 %tmp25 to i8 ; <i8> [#uses=1]
+ %toBool711 = icmp ne i8 %tmp26, 0 ; <i1> [#uses=1]
+ br i1 %toBool711, label %a, label %b
+
+a: ; preds = %entry
+ ret void
+
+b: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-03-18-vector-ashr-crash.ll b/src/LLVM/test/Transforms/InstCombine/2009-03-18-vector-ashr-crash.ll
new file mode 100644
index 0000000..c617ca4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-03-18-vector-ashr-crash.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; PR3826
+
+define void @0(<4 x i16>*, <4 x i16>*) {
+ %3 = alloca <4 x i16>* ; <<4 x i16>**> [#uses=1]
+ %4 = load <4 x i16>* null, align 1 ; <<4 x i16>> [#uses=1]
+ %5 = ashr <4 x i16> %4, <i16 5, i16 5, i16 5, i16 5> ; <<4 x i16>> [#uses=1]
+ %6 = load <4 x i16>** %3 ; <<4 x i16>*> [#uses=1]
+ store <4 x i16> %5, <4 x i16>* %6, align 1
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-03-20-AShrOverShift.ll b/src/LLVM/test/Transforms/InstCombine/2009-03-20-AShrOverShift.ll
new file mode 100644
index 0000000..0a07bf3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-03-20-AShrOverShift.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {ashr i32 %val, 31}
+; PR3851
+
+define i32 @foo2(i32 %val) nounwind {
+entry:
+ %shr = ashr i32 %val, 15 ; <i32> [#uses=3]
+ %shr4 = ashr i32 %shr, 17 ; <i32> [#uses=1]
+ ret i32 %shr4
+ }
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-03-24-InfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2009-03-24-InfLoop.ll
new file mode 100644
index 0000000..4ce04a1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-03-24-InfLoop.ll
@@ -0,0 +1,9 @@
+; PR3874
+; RUN: opt < %s -instcombine | llvm-dis
+ define i1 @test(i32 %x) {
+ %A = lshr i32 3968, %x
+ %B = and i32 %A, 1
+ %C = icmp eq i32 %B, 0
+ ret i1 %C
+ }
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-04-07-MulPromoteToI96.ll b/src/LLVM/test/Transforms/InstCombine/2009-04-07-MulPromoteToI96.ll
new file mode 100644
index 0000000..244b22a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-04-07-MulPromoteToI96.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | grep {mul i64}
+; rdar://6762288
+
+; Instcombine should not promote the mul to i96 because it is definitely
+; not a legal type for the target, and we don't want a libcall.
+
+define i96 @test(i96 %a.4, i96 %b.2) {
+ %tmp1086 = trunc i96 %a.4 to i64 ; <i64> [#uses=1]
+ %tmp836 = trunc i96 %b.2 to i64 ; <i64> [#uses=1]
+ %mul185 = mul i64 %tmp1086, %tmp836 ; <i64> [#uses=1]
+ %tmp544 = zext i64 %mul185 to i96 ; <i96> [#uses=1]
+ ret i96 %tmp544
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-05-23-FCmpToICmp.ll b/src/LLVM/test/Transforms/InstCombine/2009-05-23-FCmpToICmp.ll
new file mode 100644
index 0000000..dd14c6b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-05-23-FCmpToICmp.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep cmp
+; rdar://6903175
+
+define i1 @f0(i32 *%a) nounwind {
+ %b = load i32* %a, align 4
+ %c = uitofp i32 %b to double
+ %d = fcmp ogt double %c, 0x41EFFFFFFFE00000
+ ret i1 %d
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll b/src/LLVM/test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll
new file mode 100644
index 0000000..e5355b8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-06-11-StoreAddrSpace.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep {store i32 0,}
+; PR4366
+
+define void @a() {
+ store i32 0, i32 addrspace(1)* null
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-06-16-SRemDemandedBits.ll b/src/LLVM/test/Transforms/InstCombine/2009-06-16-SRemDemandedBits.ll
new file mode 100644
index 0000000..6beedf8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-06-16-SRemDemandedBits.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep srem
+; PR3439
+
+define i32 @a(i32 %x) nounwind {
+entry:
+ %rem = srem i32 %x, 2
+ %and = and i32 %rem, 2
+ ret i32 %and
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-07-02-MaskedIntVector.ll b/src/LLVM/test/Transforms/InstCombine/2009-07-02-MaskedIntVector.ll
new file mode 100644
index 0000000..41940fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-07-02-MaskedIntVector.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine | llvm-dis
+; PR4495
+
+define i32 @test(i64 %test) {
+entry:
+ %0 = bitcast <4 x i32> undef to <16 x i8> ; <<16 x i8>> [#uses=1]
+ %t12 = shufflevector <16 x i8> %0, <16 x i8> zeroinitializer, <16 x i32> <i32 0, i32 16, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0> ; <<16 x i8>> [#uses=1]
+ %t11 = bitcast <16 x i8> %t12 to <2 x i64> ; <<2 x i64>> [#uses=1]
+ %t9 = extractelement <2 x i64> %t11, i32 0 ; <i64> [#uses=1]
+ %t10 = bitcast i64 %t9 to <2 x i32> ; <<2 x i32>> [#uses=1]
+ %t7 = bitcast i64 %test to <2 x i32> ; <<2 x i32>> [#uses=1]
+ %t6 = xor <2 x i32> %t10, %t7 ; <<2 x i32>> [#uses=1]
+ %t1 = extractelement <2 x i32> %t6, i32 0 ; <i32> [#uses=1]
+ ret i32 %t1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2009-12-17-CmpSelectNull.ll b/src/LLVM/test/Transforms/InstCombine/2009-12-17-CmpSelectNull.ll
new file mode 100644
index 0000000..fb7497b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2009-12-17-CmpSelectNull.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+@.str254 = internal constant [2 x i8] c".\00"
+@.str557 = internal constant [3 x i8] c"::\00"
+
+define i8* @demangle_qualified(i32 %isfuncname) nounwind {
+entry:
+ %tobool272 = icmp ne i32 %isfuncname, 0
+ %cond276 = select i1 %tobool272, i8* getelementptr inbounds ([2 x i8]* @.str254, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8]* @.str557, i32 0, i32 0) ; <i8*> [#uses=4]
+ %cmp.i504 = icmp eq i8* %cond276, null
+ %rval = getelementptr i8* %cond276, i1 %cmp.i504
+ ret i8* %rval
+}
+
+; CHECK: %cond276 = select i1
+; CHECK: ret i8* %cond276
diff --git a/src/LLVM/test/Transforms/InstCombine/2010-01-28-NegativeSRem.ll b/src/LLVM/test/Transforms/InstCombine/2010-01-28-NegativeSRem.ll
new file mode 100644
index 0000000..4ab9bf0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2010-01-28-NegativeSRem.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR6165
+
+define i32 @f() {
+entry:
+ br label %BB1
+
+BB1: ; preds = %BB1, %entry
+; CHECK: BB1:
+ %x = phi i32 [ -29, %entry ], [ 0, %BB1 ] ; <i32> [#uses=2]
+ %rem = srem i32 %x, 2 ; <i32> [#uses=1]
+ %t = icmp eq i32 %rem, -1 ; <i1> [#uses=1]
+ br i1 %t, label %BB2, label %BB1
+; CHECK-NOT: br i1 false
+
+BB2: ; preds = %BB1
+; CHECK: BB2:
+ ret i32 %x
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2010-03-03-ExtElim.ll b/src/LLVM/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
new file mode 100644
index 0000000..2df12d6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
@@ -0,0 +1,18 @@
+; RUN: opt -instcombine -S %s | FileCheck %s
+; PR6486
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-unknown-linux-gnu"
+
+@g_92 = common global [2 x i32*] zeroinitializer, align 4 ; <[2 x i32*]*> [#uses=1]
+@g_177 = constant i32** bitcast (i8* getelementptr (i8* bitcast ([2 x i32*]* @g_92 to i8*), i64 4) to i32**), align 4 ; <i32***> [#uses=1]
+
+define i1 @test() nounwind {
+; CHECK: @test
+ %tmp = load i32*** @g_177 ; <i32**> [#uses=1]
+ %cmp = icmp ne i32** null, %tmp ; <i1> [#uses=1]
+ %conv = zext i1 %cmp to i32 ; <i32> [#uses=1]
+ %cmp1 = icmp sle i32 0, %conv ; <i1> [#uses=1]
+ ret i1 %cmp1
+; CHECK: ret i1 true
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll b/src/LLVM/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
new file mode 100644
index 0000000..441d5f9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
@@ -0,0 +1,46 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+; <rdar://problem/8606771>
+; CHECK: @main
+define i32 @main(i32 %argc) nounwind ssp {
+entry:
+ %tmp3151 = trunc i32 %argc to i8
+; CHECK: %tmp3162 = shl i8 %tmp3151, 5
+; CHECK: and i8 %tmp3162, 64
+; CHECK-NOT: shl
+; CHECK-NOT: shr
+ %tmp3161 = or i8 %tmp3151, -17
+ %tmp3162 = and i8 %tmp3151, 122
+ %tmp3163 = xor i8 %tmp3162, -17
+ %tmp4114 = shl i8 %tmp3163, 6
+ %tmp4115 = xor i8 %tmp4114, %tmp3163
+ %tmp4120 = xor i8 %tmp3161, %tmp4115
+ %tmp4126 = lshr i8 %tmp4120, 7
+ %tmp4127 = mul i8 %tmp4126, 64
+ %tmp4086 = zext i8 %tmp4127 to i32
+; CHECK: ret i32
+ ret i32 %tmp4086
+}
+
+; rdar://8739316
+; CHECK: @foo
+define i8 @foo(i8 %arg, i8 %arg1) nounwind {
+bb:
+ %tmp = shl i8 %arg, 7
+ %tmp2 = and i8 %arg1, 84
+ %tmp3 = and i8 %arg1, -118
+ %tmp4 = and i8 %arg1, 33
+ %tmp5 = sub i8 -88, %tmp2
+ %tmp6 = and i8 %tmp5, 84
+ %tmp7 = or i8 %tmp4, %tmp6
+ %tmp8 = xor i8 %tmp, %tmp3
+ %tmp9 = or i8 %tmp7, %tmp8
+ %tmp10 = lshr i8 %tmp8, 7
+ %tmp11 = shl i8 %tmp10, 5
+
+; CHECK: %0 = lshr i8 %tmp8, 2
+; CHECK: %tmp11 = and i8 %0, 32
+
+ %tmp12 = xor i8 %tmp11, %tmp9
+ ret i8 %tmp12
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2010-11-21-SizeZeroTypeGEP.ll b/src/LLVM/test/Transforms/InstCombine/2010-11-21-SizeZeroTypeGEP.ll
new file mode 100644
index 0000000..720365c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2010-11-21-SizeZeroTypeGEP.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+define {}* @foo({}* %x, i32 %n) {
+; CHECK: @foo
+; CHECK-NOT: getelementptr
+ %p = getelementptr {}* %x, i32 %n
+ ret {}* %p
+}
+
+define i8* @bar(i64 %n, {{}, [0 x {[0 x i8]}]}* %p) {
+; CHECK: @bar
+ %g = getelementptr {{}, [0 x {[0 x i8]}]}* %p, i64 %n, i32 1, i64 %n, i32 0, i64 %n
+; CHECK: %p, i64 0, i32 1, i64 0, i32 0, i64 %n
+ ret i8* %g
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2010-11-23-Distributed.ll b/src/LLVM/test/Transforms/InstCombine/2010-11-23-Distributed.ll
new file mode 100644
index 0000000..4f8e8dc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2010-11-23-Distributed.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+define i32 @foo(i32 %x, i32 %y) {
+; CHECK: @foo
+ %add = add nsw i32 %y, %x
+ %mul = mul nsw i32 %add, %y
+ %square = mul nsw i32 %y, %y
+ %res = sub i32 %mul, %square
+ ret i32 %res
+; CHECK-NEXT: mul i32 %x, %y
+; CHECK-NEXT: ret i32
+}
+
+define i1 @bar(i64 %x, i64 %y) {
+; CHECK: @bar
+ %a = and i64 %y, %x
+; CHECK: and
+; CHECK-NOT: and
+ %not = xor i64 %a, -1
+ %b = and i64 %y, %not
+ %r = icmp eq i64 %b, 0
+ ret i1 %r
+; CHECK: ret i1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-02-14-InfLoop.ll b/src/LLVM/test/Transforms/InstCombine/2011-02-14-InfLoop.ll
new file mode 100644
index 0000000..14fa1a8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-02-14-InfLoop.ll
@@ -0,0 +1,19 @@
+; This testcase causes an infinite loop in the instruction combiner,
+; because it changes a pattern and the original pattern is almost
+; identical to the newly-generated pattern.
+; RUN: opt < %s -instcombine -disable-output
+
+;PR PR9216
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define <4 x float> @m_387(i8* noalias nocapture %A, i8* nocapture %B, <4 x i1> %C) nounwind {
+entry:
+ %movcsext20 = sext <4 x i1> %C to <4 x i32>
+ %tmp2389 = xor <4 x i32> %movcsext20, <i32 -1, i32 -1, i32 -1, i32 -1>
+ %movcand25 = and <4 x i32> %tmp2389, <i32 undef, i32 undef, i32 undef, i32 -1>
+ %movcor26 = or <4 x i32> %movcand25, zeroinitializer
+ %L2 = bitcast <4 x i32> %movcor26 to <4 x float>
+ %L3 = shufflevector <4 x float> zeroinitializer, <4 x float> %L2, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
+ ret <4 x float> %L3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-03-08-SRemMinusOneBadOpt.ll b/src/LLVM/test/Transforms/InstCombine/2011-03-08-SRemMinusOneBadOpt.ll
new file mode 100644
index 0000000..6a3e3e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-03-08-SRemMinusOneBadOpt.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR9346
+
+define i32 @test(i64 %x) nounwind {
+; CHECK: ret i32 0
+entry:
+ %or = or i64 %x, 4294967294
+ %conv = trunc i64 %or to i32
+ %rem.i = srem i32 %conv, -1
+ ret i32 %rem.i
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-05-02-VectorBoolean.ll b/src/LLVM/test/Transforms/InstCombine/2011-05-02-VectorBoolean.ll
new file mode 100644
index 0000000..02b64e3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-05-02-VectorBoolean.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine
+; PR9579
+
+define <2 x i16> @entry(<2 x i16> %a) nounwind {
+entry:
+ %a.addr = alloca <2 x i16>, align 4
+ %.compoundliteral = alloca <2 x i16>, align 4
+ store <2 x i16> %a, <2 x i16>* %a.addr, align 4
+ %tmp = load <2 x i16>* %a.addr, align 4
+ store <2 x i16> zeroinitializer, <2 x i16>* %.compoundliteral
+ %tmp1 = load <2 x i16>* %.compoundliteral
+ %cmp = icmp uge <2 x i16> %tmp, %tmp1
+ %sext = sext <2 x i1> %cmp to <2 x i16>
+ ret <2 x i16> %sext
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-05-13-InBoundsGEP.ll b/src/LLVM/test/Transforms/InstCombine/2011-05-13-InBoundsGEP.ll
new file mode 100644
index 0000000..fba7239
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-05-13-InBoundsGEP.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -S -instcombine | FileCheck %s
+; rdar://problem/9267970
+; ideally this test will run on a 32-bit host
+; must not discard GEPs that might overflow at runtime (aren't inbounds)
+
+define i32 @main(i32 %argc) {
+entry:
+ %tmp1 = add i32 %argc, -2
+ %tmp2 = add i32 %argc, 1879048192
+ %p = alloca i8
+; CHECK: getelementptr
+ %p1 = getelementptr i8* %p, i32 %tmp1
+; CHECK: getelementptr
+ %p2 = getelementptr i8* %p, i32 %tmp2
+ %cmp = icmp ult i8* %p1, %p2
+ br i1 %cmp, label %bbtrue, label %bbfalse
+bbtrue: ; preds = %entry
+ ret i32 -1
+bbfalse: ; preds = %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-05-28-swapmulsub.ll b/src/LLVM/test/Transforms/InstCombine/2011-05-28-swapmulsub.ll
new file mode 100644
index 0000000..b096d1f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-05-28-swapmulsub.ll
@@ -0,0 +1,57 @@
+; ModuleID = 'test1.c'
+; RUN: opt -S -instcombine < %s | FileCheck %s
+target triple = "x86_64-apple-macosx10.6.6"
+
+define zeroext i16 @foo1(i32 %on_off) nounwind uwtable ssp {
+entry:
+ %on_off.addr = alloca i32, align 4
+ %a = alloca i32, align 4
+ store i32 %on_off, i32* %on_off.addr, align 4
+ %tmp = load i32* %on_off.addr, align 4
+ %sub = sub i32 1, %tmp
+; CHECK-NOT: mul i32
+ %mul = mul i32 %sub, -2
+; CHECK: shl
+; CHECK-NEXT: add
+ store i32 %mul, i32* %a, align 4
+ %tmp1 = load i32* %a, align 4
+ %conv = trunc i32 %tmp1 to i16
+ ret i16 %conv
+}
+
+define zeroext i16 @foo2(i32 %on_off, i32 %q) nounwind uwtable ssp {
+entry:
+ %on_off.addr = alloca i32, align 4
+ %q.addr = alloca i32, align 4
+ %a = alloca i32, align 4
+ store i32 %on_off, i32* %on_off.addr, align 4
+ store i32 %q, i32* %q.addr, align 4
+ %tmp = load i32* %q.addr, align 4
+ %tmp1 = load i32* %on_off.addr, align 4
+ %sub = sub i32 %tmp, %tmp1
+; CHECK-NOT: mul i32
+ %mul = mul i32 %sub, -4
+; CHECK: sub i32
+; CHECK-NEXT: shl
+ store i32 %mul, i32* %a, align 4
+ %tmp2 = load i32* %a, align 4
+ %conv = trunc i32 %tmp2 to i16
+ ret i16 %conv
+}
+
+define zeroext i16 @foo3(i32 %on_off) nounwind uwtable ssp {
+entry:
+ %on_off.addr = alloca i32, align 4
+ %a = alloca i32, align 4
+ store i32 %on_off, i32* %on_off.addr, align 4
+ %tmp = load i32* %on_off.addr, align 4
+ %sub = sub i32 7, %tmp
+; CHECK-NOT: mul i32
+ %mul = mul i32 %sub, -4
+; CHECK: shl
+; CHECK-NEXT: add
+ store i32 %mul, i32* %a, align 4
+ %tmp1 = load i32* %a, align 4
+ %conv = trunc i32 %tmp1 to i16
+ ret i16 %conv
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll b/src/LLVM/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
new file mode 100644
index 0000000..2f72b73
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-06-13-nsw-alloca.ll
@@ -0,0 +1,60 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin10.0.0"
+
+define void @fu1(i32 %parm) nounwind ssp {
+ %1 = alloca i32, align 4
+ %ptr = alloca double*, align 4
+ store i32 %parm, i32* %1, align 4
+ store double* null, double** %ptr, align 4
+ %2 = load i32* %1, align 4
+ %3 = icmp ne i32 %2, 0
+ br i1 %3, label %4, label %10
+
+; <label>:4 ; preds = %0
+ %5 = load i32* %1, align 4
+ %6 = mul nsw i32 %5, 8
+; With "nsw", the alloca and its bitcast can be fused:
+ %7 = add nsw i32 %6, 2048
+; CHECK: alloca double*
+ %8 = alloca i8, i32 %7
+ %9 = bitcast i8* %8 to double*
+ store double* %9, double** %ptr, align 4
+ br label %10
+
+; <label>:10 ; preds = %4, %0
+ %11 = load double** %ptr, align 4
+ call void @bar(double* %11)
+; CHECK: ret
+ ret void
+}
+
+declare void @bar(double*)
+
+define void @fu2(i32 %parm) nounwind ssp {
+ %1 = alloca i32, align 4
+ %ptr = alloca double*, align 4
+ store i32 %parm, i32* %1, align 4
+ store double* null, double** %ptr, align 4
+ %2 = load i32* %1, align 4
+ %3 = icmp ne i32 %2, 0
+ br i1 %3, label %4, label %10
+
+; <label>:4 ; preds = %0
+ %5 = load i32* %1, align 4
+ %6 = mul nsw i32 %5, 8
+; Without "nsw", the alloca and its bitcast cannot be fused:
+ %7 = add i32 %6, 2048
+; CHECK: alloca i8
+ %8 = alloca i8, i32 %7
+; CHECK-NEXT: bitcast i8*
+ %9 = bitcast i8* %8 to double*
+ store double* %9, double** %ptr, align 4
+ br label %10
+
+; <label>:10 ; preds = %4, %0
+ %11 = load double** %ptr, align 4
+ call void @bar(double* %11)
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-09-03-Trampoline.ll b/src/LLVM/test/Transforms/InstCombine/2011-09-03-Trampoline.ll
new file mode 100644
index 0000000..5456e03
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-09-03-Trampoline.ll
@@ -0,0 +1,87 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+declare void @llvm.init.trampoline(i8*, i8*, i8*)
+declare i8* @llvm.adjust.trampoline(i8*)
+declare i32 @f(i8 * nest, i32)
+
+; Most common case
+define i32 @test0(i32 %n) {
+ %alloca = alloca [10 x i8], align 16
+ %gep = getelementptr [10 x i8]* %alloca, i32 0, i32 0
+ call void @llvm.init.trampoline(i8* %gep, i8* bitcast (i32 (i8*, i32)* @f to i8*),
+ i8* null)
+ %tramp = call i8* @llvm.adjust.trampoline(i8* %gep)
+ %function = bitcast i8* %tramp to i32(i32)*
+ %ret = call i32 %function(i32 %n)
+ ret i32 %ret
+
+; CHECK: define i32 @test0(i32 %n) {
+; CHECK: %ret = call i32 @f(i8* nest null, i32 %n)
+}
+
+define i32 @test1(i32 %n, i8* %trampmem) {
+ call void @llvm.init.trampoline(i8* %trampmem,
+ i8* bitcast (i32 (i8*, i32)* @f to i8*),
+ i8* null)
+ %tramp = call i8* @llvm.adjust.trampoline(i8* %trampmem)
+ %function = bitcast i8* %tramp to i32(i32)*
+ %ret = call i32 %function(i32 %n)
+ ret i32 %ret
+; CHECK: define i32 @test1(i32 %n, i8* %trampmem) {
+; CHECK: %ret = call i32 @f(i8* nest null, i32 %n)
+}
+
+define i32 @test2(i32 %n, i8* %trampmem) {
+ %tramp = call i8* @llvm.adjust.trampoline(i8* %trampmem)
+ %functiona = bitcast i8* %tramp to i32(i32)*
+ %ret = call i32 %functiona(i32 %n)
+ ret i32 %ret
+; CHECK: define i32 @test2(i32 %n, i8* %trampmem) {
+; CHECK: %ret = call i32 %functiona(i32 %n)
+}
+
+define i32 @test3(i32 %n, i8* %trampmem) {
+ call void @llvm.init.trampoline(i8* %trampmem,
+ i8* bitcast (i32 (i8*, i32)* @f to i8*),
+ i8* null)
+
+; CHECK: define i32 @test3(i32 %n, i8* %trampmem) {
+; CHECK: %ret0 = call i32 @f(i8* nest null, i32 %n)
+ %tramp0 = call i8* @llvm.adjust.trampoline(i8* %trampmem)
+ %function0 = bitcast i8* %tramp0 to i32(i32)*
+ %ret0 = call i32 %function0(i32 %n)
+
+ ;; Not optimized since previous call could be writing.
+ %tramp1 = call i8* @llvm.adjust.trampoline(i8* %trampmem)
+ %function1 = bitcast i8* %tramp1 to i32(i32)*
+ %ret1 = call i32 %function1(i32 %n)
+; CHECK: %ret1 = call i32 %function1(i32 %n)
+
+ ret i32 %ret1
+}
+
+define i32 @test4(i32 %n) {
+ %alloca = alloca [10 x i8], align 16
+ %gep = getelementptr [10 x i8]* %alloca, i32 0, i32 0
+ call void @llvm.init.trampoline(i8* %gep, i8* bitcast (i32 (i8*, i32)* @f to i8*),
+ i8* null)
+
+ %tramp0 = call i8* @llvm.adjust.trampoline(i8* %gep)
+ %function0 = bitcast i8* %tramp0 to i32(i32)*
+ %ret0 = call i32 %function0(i32 %n)
+
+ %tramp1 = call i8* @llvm.adjust.trampoline(i8* %gep)
+ %function1 = bitcast i8* %tramp0 to i32(i32)*
+ %ret1 = call i32 %function1(i32 %n)
+
+ %tramp2 = call i8* @llvm.adjust.trampoline(i8* %gep)
+ %function2 = bitcast i8* %tramp2 to i32(i32)*
+ %ret2 = call i32 %function2(i32 %n)
+
+ ret i32 %ret2
+
+; CHECK: define i32 @test4(i32 %n) {
+; CHECK: %ret0 = call i32 @f(i8* nest null, i32 %n)
+; CHECK: %ret1 = call i32 @f(i8* nest null, i32 %n)
+; CHECK: %ret2 = call i32 @f(i8* nest null, i32 %n)
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/2011-10-07-AlignPromotion.ll b/src/LLVM/test/Transforms/InstCombine/2011-10-07-AlignPromotion.ll
new file mode 100644
index 0000000..22061b2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/2011-10-07-AlignPromotion.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+; rdar://problem/10063307
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"
+target triple = "thumbv7-apple-ios5.0.0"
+
+%0 = type { [2 x i32] }
+%struct.CGPoint = type { float, float }
+
+define void @t(%struct.CGPoint* %a) nounwind {
+ %Point = alloca %struct.CGPoint, align 4
+ %1 = bitcast %struct.CGPoint* %a to i64*
+ %2 = bitcast %struct.CGPoint* %Point to i64*
+ %3 = load i64* %1, align 4
+ store i64 %3, i64* %2, align 4
+ call void @foo(i64* %2) nounwind
+ ret void
+; CHECK: %Point = alloca i64, align 4
+}
+
+declare void @foo(i64*)
diff --git a/src/LLVM/test/Transforms/InstCombine/CPP_min_max.ll b/src/LLVM/test/Transforms/InstCombine/CPP_min_max.ll
new file mode 100644
index 0000000..6bb0ba9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/CPP_min_max.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep select | not grep {i32\\*}
+
+; This testcase corresponds to PR362, which notices that this horrible code
+; is generated by the C++ front-end and LLVM optimizers, which has lots of
+; loads and other stuff that are unneeded.
+;
+; Instcombine should propagate the load through the select instructions to
+; allow elimination of the extra stuff by the mem2reg pass.
+
+define void @_Z5test1RiS_(i32* %x, i32* %y) {
+entry:
+ %tmp.1.i = load i32* %y ; <i32> [#uses=1]
+ %tmp.3.i = load i32* %x ; <i32> [#uses=1]
+ %tmp.4.i = icmp slt i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
+ %retval.i = select i1 %tmp.4.i, i32* %y, i32* %x ; <i32*> [#uses=1]
+ %tmp.4 = load i32* %retval.i ; <i32> [#uses=1]
+ store i32 %tmp.4, i32* %x
+ ret void
+}
+
+define void @_Z5test2RiS_(i32* %x, i32* %y) {
+entry:
+ %tmp.0 = alloca i32 ; <i32*> [#uses=2]
+ %tmp.2 = load i32* %x ; <i32> [#uses=2]
+ store i32 %tmp.2, i32* %tmp.0
+ %tmp.3.i = load i32* %y ; <i32> [#uses=1]
+ %tmp.4.i = icmp slt i32 %tmp.2, %tmp.3.i ; <i1> [#uses=1]
+ %retval.i = select i1 %tmp.4.i, i32* %y, i32* %tmp.0 ; <i32*> [#uses=1]
+ %tmp.6 = load i32* %retval.i ; <i32> [#uses=1]
+ store i32 %tmp.6, i32* %y
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/ExtractCast.ll b/src/LLVM/test/Transforms/InstCombine/ExtractCast.ll
new file mode 100644
index 0000000..5ebbefd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/ExtractCast.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -instcombine -S -o - | FileCheck %s
+
+; CHECK: @a
+define i32 @a(<4 x i64> %I) {
+entry:
+; CHECK-NOT: trunc <4 x i64>
+ %J = trunc <4 x i64> %I to <4 x i32>
+ %K = extractelement <4 x i32> %J, i32 3
+; CHECK: extractelement <4 x i64>
+; CHECK: trunc i64
+; CHECK: ret
+ ret i32 %K
+}
+
+
+; CHECK: @b
+define i32 @b(<4 x float> %I) {
+entry:
+; CHECK-NOT: fptosi <4 x float>
+ %J = fptosi <4 x float> %I to <4 x i32>
+ %K = extractelement <4 x i32> %J, i32 3
+; CHECK: extractelement <4 x float>
+; CHECK: fptosi float
+; CHECK: ret
+ ret i32 %K
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/IntPtrCast.ll b/src/LLVM/test/Transforms/InstCombine/IntPtrCast.ll
new file mode 100644
index 0000000..ef43048
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/IntPtrCast.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:32:32"
+
+define i32* @test(i32* %P) {
+ %V = ptrtoint i32* %P to i32 ; <i32> [#uses=1]
+ %P2 = inttoptr i32 %V to i32* ; <i32*> [#uses=1]
+ ret i32* %P2
+; CHECK: ret i32* %P
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/JavaCompare.ll b/src/LLVM/test/Transforms/InstCombine/JavaCompare.ll
new file mode 100644
index 0000000..266c4ad
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/JavaCompare.ll
@@ -0,0 +1,14 @@
+; This is the sequence of stuff that the Java front-end expands for a single
+; <= comparison. Check to make sure we turn it into a <= (only)
+
+; RUN: opt < %s -instcombine -S | grep {icmp sle i32 %A, %B}
+
+define i1 @le(i32 %A, i32 %B) {
+ %c1 = icmp sgt i32 %A, %B ; <i1> [#uses=1]
+ %tmp = select i1 %c1, i32 1, i32 0 ; <i32> [#uses=1]
+ %c2 = icmp slt i32 %A, %B ; <i1> [#uses=1]
+ %result = select i1 %c2, i32 -1, i32 %tmp ; <i32> [#uses=1]
+ %c3 = icmp sle i32 %result, 0 ; <i1> [#uses=1]
+ ret i1 %c3
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/LandingPadClauses.ll b/src/LLVM/test/Transforms/InstCombine/LandingPadClauses.ll
new file mode 100644
index 0000000..055bdcc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/LandingPadClauses.ll
@@ -0,0 +1,181 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+@T1 = external constant i32
+@T2 = external constant i32
+@T3 = external constant i32
+
+declare i32 @generic_personality(i32, i64, i8*, i8*)
+declare i32 @__gxx_personality_v0(i32, i64, i8*, i8*)
+
+declare void @bar()
+
+define void @foo_generic() {
+; CHECK: @foo_generic
+ invoke void @bar()
+ to label %cont.a unwind label %lpad.a
+cont.a:
+ invoke void @bar()
+ to label %cont.b unwind label %lpad.b
+cont.b:
+ invoke void @bar()
+ to label %cont.c unwind label %lpad.c
+cont.c:
+ invoke void @bar()
+ to label %cont.d unwind label %lpad.d
+cont.d:
+ invoke void @bar()
+ to label %cont.e unwind label %lpad.e
+cont.e:
+ invoke void @bar()
+ to label %cont.f unwind label %lpad.f
+cont.f:
+ invoke void @bar()
+ to label %cont.g unwind label %lpad.g
+cont.g:
+ invoke void @bar()
+ to label %cont.h unwind label %lpad.h
+cont.h:
+ invoke void @bar()
+ to label %cont.i unwind label %lpad.i
+cont.i:
+ ret void
+
+lpad.a:
+ %a = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ catch i32* @T1
+ catch i32* @T2
+ catch i32* @T1
+ catch i32* @T2
+ unreachable
+; CHECK: %a = landingpad
+; CHECK-NEXT: @T1
+; CHECK-NEXT: @T2
+; CHECK-NEXT: unreachable
+
+lpad.b:
+ %b = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ filter [0 x i32*] zeroinitializer
+ catch i32* @T1
+ unreachable
+; CHECK: %b = landingpad
+; CHECK-NEXT: filter
+; CHECK-NEXT: unreachable
+
+lpad.c:
+ %c = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ catch i32* @T1
+ filter [1 x i32*] [i32* @T1]
+ catch i32* @T2
+ unreachable
+; CHECK: %c = landingpad
+; CHECK-NEXT: @T1
+; CHECK-NEXT: filter [0 x i32*]
+; CHECK-NEXT: unreachable
+
+lpad.d:
+ %d = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ filter [3 x i32*] zeroinitializer
+ unreachable
+; CHECK: %d = landingpad
+; CHECK-NEXT: filter [1 x i32*] zeroinitializer
+; CHECK-NEXT: unreachable
+
+lpad.e:
+ %e = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ catch i32* @T1
+ filter [3 x i32*] [i32* @T1, i32* @T2, i32* @T2]
+ unreachable
+; CHECK: %e = landingpad
+; CHECK-NEXT: @T1
+; CHECK-NEXT: filter [1 x i32*] [i32* @T2]
+; CHECK-NEXT: unreachable
+
+lpad.f:
+ %f = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ filter [2 x i32*] [i32* @T2, i32* @T1]
+ filter [1 x i32*] [i32* @T1]
+ unreachable
+; CHECK: %f = landingpad
+; CHECK-NEXT: filter [1 x i32*] [i32* @T1]
+; CHECK-NEXT: unreachable
+
+lpad.g:
+ %g = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ filter [1 x i32*] [i32* @T1]
+ catch i32* @T3
+ filter [2 x i32*] [i32* @T2, i32* @T1]
+ unreachable
+; CHECK: %g = landingpad
+; CHECK-NEXT: filter [1 x i32*] [i32* @T1]
+; CHECK-NEXT: catch i32* @T3
+; CHECK-NEXT: unreachable
+
+lpad.h:
+ %h = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ filter [2 x i32*] [i32* @T1, i32* null]
+ filter [1 x i32*] zeroinitializer
+ unreachable
+; CHECK: %h = landingpad
+; CHECK-NEXT: filter [1 x i32*] zeroinitializer
+; CHECK-NEXT: unreachable
+
+lpad.i:
+ %i = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @generic_personality
+ cleanup
+ filter [0 x i32*] zeroinitializer
+ unreachable
+; CHECK: %i = landingpad
+; CHECK-NEXT: filter
+; CHECK-NEXT: unreachable
+}
+
+define void @foo_cxx() {
+; CHECK: @foo_cxx
+ invoke void @bar()
+ to label %cont.a unwind label %lpad.a
+cont.a:
+ invoke void @bar()
+ to label %cont.b unwind label %lpad.b
+cont.b:
+ invoke void @bar()
+ to label %cont.c unwind label %lpad.c
+cont.c:
+ invoke void @bar()
+ to label %cont.d unwind label %lpad.d
+cont.d:
+ ret void
+
+lpad.a:
+ %a = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ catch i32* null
+ catch i32* @T1
+ unreachable
+; CHECK: %a = landingpad
+; CHECK-NEXT: null
+; CHECK-NEXT: unreachable
+
+lpad.b:
+ %b = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ filter [1 x i32*] zeroinitializer
+ unreachable
+; CHECK: %b = landingpad
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: unreachable
+
+lpad.c:
+ %c = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ filter [2 x i32*] [i32* @T1, i32* null]
+ unreachable
+; CHECK: %c = landingpad
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: unreachable
+
+lpad.d:
+ %d = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ cleanup
+ catch i32* null
+ unreachable
+; CHECK: %d = landingpad
+; CHECK-NEXT: null
+; CHECK-NEXT: unreachable
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/README.txt b/src/LLVM/test/Transforms/InstCombine/README.txt
new file mode 100644
index 0000000..46ac500
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/README.txt
@@ -0,0 +1,4 @@
+This directory contains test cases for the instcombine transformation. The
+dated tests are actual bug tests, whereas the named tests are used to test
+for features that the this pass should be capable of performing.
+
diff --git a/src/LLVM/test/Transforms/InstCombine/add-shrink.ll b/src/LLVM/test/Transforms/InstCombine/add-shrink.ll
new file mode 100644
index 0000000..cc57478
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/add-shrink.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep {add nsw i32}
+; RUN: opt < %s -instcombine -S | grep sext | count 1
+
+; Should only have one sext and the add should be i32 instead of i64.
+
+define i64 @test1(i32 %A) {
+ %B = ashr i32 %A, 7 ; <i32> [#uses=1]
+ %C = ashr i32 %A, 9 ; <i32> [#uses=1]
+ %D = sext i32 %B to i64 ; <i64> [#uses=1]
+ %E = sext i32 %C to i64 ; <i64> [#uses=1]
+ %F = add i64 %D, %E ; <i64> [#uses=1]
+ ret i64 %F
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/add-sitofp.ll b/src/LLVM/test/Transforms/InstCombine/add-sitofp.ll
new file mode 100644
index 0000000..98a8cb4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/add-sitofp.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {add nsw i32}
+
+define double @x(i32 %a, i32 %b) nounwind {
+ %m = lshr i32 %a, 24
+ %n = and i32 %m, %b
+ %o = sitofp i32 %n to double
+ %p = fadd double %o, 1.0
+ ret double %p
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/add.ll b/src/LLVM/test/Transforms/InstCombine/add.ll
new file mode 100644
index 0000000..af85686
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/add.ll
@@ -0,0 +1,301 @@
+; This test makes sure that add instructions are properly eliminated.
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v OK | not grep add
+
+define i32 @test1(i32 %A) {
+ %B = add i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test2(i32 %A) {
+ %B = add i32 %A, 5 ; <i32> [#uses=1]
+ %C = add i32 %B, -5 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test3(i32 %A) {
+ %B = add i32 %A, 5 ; <i32> [#uses=1]
+ ;; This should get converted to an add
+ %C = sub i32 %B, 5 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test4(i32 %A, i32 %B) {
+ %C = sub i32 0, %A ; <i32> [#uses=1]
+ ; D = B + -A = B - A
+ %D = add i32 %B, %C ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test5(i32 %A, i32 %B) {
+ %C = sub i32 0, %A ; <i32> [#uses=1]
+ ; D = -A + B = B - A
+ %D = add i32 %C, %B ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test6(i32 %A) {
+ %B = mul i32 7, %A ; <i32> [#uses=1]
+ ; C = 7*A+A == 8*A == A << 3
+ %C = add i32 %B, %A ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test7(i32 %A) {
+ %B = mul i32 7, %A ; <i32> [#uses=1]
+ ; C = A+7*A == 8*A == A << 3
+ %C = add i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
+define i32 @test8(i32 %A, i32 %B) {
+ %A1 = and i32 %A, 7 ; <i32> [#uses=1]
+ %B1 = and i32 %B, 128 ; <i32> [#uses=1]
+ %C = add i32 %A1, %B1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test9(i32 %A) {
+ %B = shl i32 %A, 4 ; <i32> [#uses=2]
+ ; === shl int %A, 5
+ %C = add i32 %B, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i1 @test10(i8 %A, i8 %b) {
+ %B = add i8 %A, %b ; <i8> [#uses=1]
+ ; === A != -b
+ %c = icmp ne i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %c
+}
+
+define i1 @test11(i8 %A) {
+ %B = add i8 %A, -1 ; <i8> [#uses=1]
+ ; === A != 1
+ %c = icmp ne i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %c
+}
+
+define i32 @test12(i32 %A, i32 %B) {
+ ; Should be transformed into shl A, 1
+ %C_OK = add i32 %B, %A ; <i32> [#uses=1]
+ br label %X
+
+X: ; preds = %0
+ %D = add i32 %C_OK, %A ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test13(i32 %A, i32 %B, i32 %C) {
+ %D_OK = add i32 %A, %B ; <i32> [#uses=1]
+ %E_OK = add i32 %D_OK, %C ; <i32> [#uses=1]
+ ;; shl A, 1
+ %F = add i32 %E_OK, %A ; <i32> [#uses=1]
+ ret i32 %F
+}
+
+define i32 @test14(i32 %offset, i32 %difference) {
+ %tmp.2 = and i32 %difference, 3 ; <i32> [#uses=1]
+ %tmp.3_OK = add i32 %tmp.2, %offset ; <i32> [#uses=1]
+ %tmp.5.mask = and i32 %difference, -4 ; <i32> [#uses=1]
+ ; == add %offset, %difference
+ %tmp.8 = add i32 %tmp.3_OK, %tmp.5.mask ; <i32> [#uses=1]
+ ret i32 %tmp.8
+}
+
+define i8 @test15(i8 %A) {
+ ; Does not effect result
+ %B = add i8 %A, -64 ; <i8> [#uses=1]
+ ; Only one bit set
+ %C = and i8 %B, 16 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i8 @test16(i8 %A) {
+ ; Turn this into a XOR
+ %B = add i8 %A, 16 ; <i8> [#uses=1]
+ ; Only one bit set
+ %C = and i8 %B, 16 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i32 @test17(i32 %A) {
+ %B = xor i32 %A, -1 ; <i32> [#uses=1]
+ ; == sub int 0, %A
+ %C = add i32 %B, 1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i8 @test18(i8 %A) {
+ %B = xor i8 %A, -1 ; <i8> [#uses=1]
+ ; == sub ubyte 16, %A
+ %C = add i8 %B, 17 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i32 @test19(i1 %C) {
+ %A = select i1 %C, i32 1000, i32 10 ; <i32> [#uses=1]
+ %V = add i32 %A, 123 ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define i32 @test20(i32 %x) {
+ %tmp.2 = xor i32 %x, -2147483648 ; <i32> [#uses=1]
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i32 %tmp.2, -2147483648 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+}
+
+define i1 @test21(i32 %x) {
+ %t = add i32 %x, 4 ; <i32> [#uses=1]
+ %y = icmp eq i32 %t, 123 ; <i1> [#uses=1]
+ ret i1 %y
+}
+
+define i32 @test22(i32 %V) {
+ %V2 = add i32 %V, 10 ; <i32> [#uses=1]
+ switch i32 %V2, label %Default [
+ i32 20, label %Lab1
+ i32 30, label %Lab2
+ ]
+
+Default: ; preds = %0
+ ret i32 123
+
+Lab1: ; preds = %0
+ ret i32 12312
+
+Lab2: ; preds = %0
+ ret i32 1231231
+}
+
+define i32 @test23(i1 %C, i32 %a) {
+entry:
+ br i1 %C, label %endif, label %else
+
+else: ; preds = %entry
+ br label %endif
+
+endif: ; preds = %else, %entry
+ %b.0 = phi i32 [ 0, %entry ], [ 1, %else ] ; <i32> [#uses=1]
+ %tmp.4 = add i32 %b.0, 1 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+}
+
+define i32 @test24(i32 %A) {
+ %B = add i32 %A, 1 ; <i32> [#uses=1]
+ %C = shl i32 %B, 1 ; <i32> [#uses=1]
+ %D = sub i32 %C, 2 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i64 @test25(i64 %Y) {
+ %tmp.4 = shl i64 %Y, 2 ; <i64> [#uses=1]
+ %tmp.12 = shl i64 %Y, 2 ; <i64> [#uses=1]
+ %tmp.8 = add i64 %tmp.4, %tmp.12 ; <i64> [#uses=1]
+ ret i64 %tmp.8
+}
+
+define i32 @test26(i32 %A, i32 %B) {
+ %C = add i32 %A, %B ; <i32> [#uses=1]
+ %D = sub i32 %C, %B ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test27(i1 %C, i32 %X, i32 %Y) {
+ %A = add i32 %X, %Y ; <i32> [#uses=1]
+ %B = add i32 %Y, 123 ; <i32> [#uses=1]
+ ;; Fold add through select.
+ %C.upgrd.1 = select i1 %C, i32 %A, i32 %B ; <i32> [#uses=1]
+ %D = sub i32 %C.upgrd.1, %Y ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test28(i32 %X) {
+ %Y = add i32 %X, 1234 ; <i32> [#uses=1]
+ %Z = sub i32 42, %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test29(i32 %X, i32 %x) {
+ %tmp.2 = sub i32 %X, %x ; <i32> [#uses=2]
+ %tmp.2.mask = and i32 %tmp.2, 63 ; <i32> [#uses=1]
+ %tmp.6 = add i32 %tmp.2.mask, %x ; <i32> [#uses=1]
+ %tmp.7 = and i32 %tmp.6, 63 ; <i32> [#uses=1]
+ %tmp.9 = and i32 %tmp.2, -64 ; <i32> [#uses=1]
+ %tmp.10 = or i32 %tmp.7, %tmp.9 ; <i32> [#uses=1]
+ ret i32 %tmp.10
+}
+
+define i64 @test30(i64 %x) {
+ %tmp.2 = xor i64 %x, -9223372036854775808 ; <i64> [#uses=1]
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i64 %tmp.2, -9223372036854775808 ; <i64> [#uses=1]
+ ret i64 %tmp.4
+}
+
+define i32 @test31(i32 %A) {
+ %B = add i32 %A, 4 ; <i32> [#uses=1]
+ %C = mul i32 %B, 5 ; <i32> [#uses=1]
+ %D = sub i32 %C, 20 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test32(i32 %A) {
+ %B = add i32 %A, 4 ; <i32> [#uses=1]
+ %C = shl i32 %B, 2 ; <i32> [#uses=1]
+ %D = sub i32 %C, 16 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i8 @test33(i8 %A) {
+ %B = and i8 %A, -2 ; <i8> [#uses=1]
+ %C = add i8 %B, 1 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i8 @test34(i8 %A) {
+ %B = add i8 %A, 64 ; <i8> [#uses=1]
+ %C = and i8 %B, 12 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i32 @test35(i32 %a) {
+ %tmpnot = xor i32 %a, -1 ; <i32> [#uses=1]
+ %tmp2 = add i32 %tmpnot, %a ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @test36(i32 %a) {
+ %x = and i32 %a, -2
+ %y = and i32 %a, -126
+ %z = add i32 %x, %y
+ %q = and i32 %z, 1 ; always zero
+ ret i32 %q
+}
+
+define i1 @test37(i32 %a, i32 %b) nounwind readnone {
+ %add = add i32 %a, %b
+ %cmp = icmp eq i32 %add, %a
+ ret i1 %cmp
+}
+
+define i1 @test38(i32 %a, i32 %b) nounwind readnone {
+ %add = add i32 %a, %b
+ %cmp = icmp eq i32 %add, %b
+ ret i1 %cmp
+}
+
+define i1 @test39(i32 %a, i32 %b) nounwind readnone {
+ %add = add i32 %b, %a
+ %cmp = icmp eq i32 %add, %a
+ ret i1 %cmp
+}
+
+define i1 @test40(i32 %a, i32 %b) nounwind readnone {
+ %add = add i32 %b, %a
+ %cmp = icmp eq i32 %add, %b
+ ret i1 %cmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/add2.ll b/src/LLVM/test/Transforms/InstCombine/add2.ll
new file mode 100644
index 0000000..2050ee8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/add2.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i64 @test1(i64 %A, i32 %B) {
+ %tmp12 = zext i32 %B to i64
+ %tmp3 = shl i64 %tmp12, 32
+ %tmp5 = add i64 %tmp3, %A
+ %tmp6 = and i64 %tmp5, 123
+ ret i64 %tmp6
+; CHECK: @test1
+; CHECK-NEXT: and i64 %A, 123
+; CHECK-NEXT: ret i64
+}
+
+define i32 @test2(i32 %A) {
+ %B = and i32 %A, 7
+ %C = and i32 %A, 32
+ %F = add i32 %B, %C
+ ret i32 %F
+; CHECK: @test2
+; CHECK-NEXT: and i32 %A, 39
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test3(i32 %A) {
+ %B = and i32 %A, 128
+ %C = lshr i32 %A, 30
+ %F = add i32 %B, %C
+ ret i32 %F
+; CHECK: @test3
+; CHECK-NEXT: and
+; CHECK-NEXT: lshr
+; CHECK-NEXT: or i32 %B, %C
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test4(i32 %A) {
+ %B = add nuw i32 %A, %A
+ ret i32 %B
+; CHECK: @test4
+; CHECK-NEXT: %B = shl nuw i32 %A, 1
+; CHECK-NEXT: ret i32 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/add3.ll b/src/LLVM/test/Transforms/InstCombine/add3.ll
new file mode 100644
index 0000000..53a7b43
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/add3.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instcombine -S | grep inttoptr | count 2
+
+;; Target triple for gep raising case below.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+
+; PR1795
+define void @test2(i32 %.val24) {
+EntryBlock:
+ add i32 %.val24, -12
+ inttoptr i32 %0 to i32*
+ store i32 1, i32* %1
+ add i32 %.val24, -16
+ inttoptr i32 %2 to i32*
+ getelementptr i32* %3, i32 1
+ load i32* %4
+ tail call i32 @callee( i32 %5 )
+ ret void
+}
+
+declare i32 @callee(i32)
diff --git a/src/LLVM/test/Transforms/InstCombine/addnegneg.ll b/src/LLVM/test/Transforms/InstCombine/addnegneg.ll
new file mode 100644
index 0000000..a3a09f2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/addnegneg.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | grep { sub } | count 1
+; PR2047
+
+define i32 @l(i32 %a, i32 %b, i32 %c, i32 %d) {
+entry:
+ %b.neg = sub i32 0, %b ; <i32> [#uses=1]
+ %c.neg = sub i32 0, %c ; <i32> [#uses=1]
+ %sub4 = add i32 %c.neg, %b.neg ; <i32> [#uses=1]
+ %sub6 = add i32 %sub4, %d ; <i32> [#uses=1]
+ ret i32 %sub6
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/adjust-for-sminmax.ll b/src/LLVM/test/Transforms/InstCombine/adjust-for-sminmax.ll
new file mode 100644
index 0000000..b9b6f70
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/adjust-for-sminmax.ll
@@ -0,0 +1,85 @@
+; RUN: opt < %s -instcombine -S | grep {icmp s\[lg\]t i32 %n, 0} | count 16
+
+; Instcombine should recognize that this code can be adjusted
+; to fit the canonical smax/smin pattern.
+
+define i32 @floor_a(i32 %n) {
+ %t = icmp sgt i32 %n, -1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_a(i32 %n) {
+ %t = icmp slt i32 %n, 1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_b(i32 %n) {
+ %t = icmp sgt i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_b(i32 %n) {
+ %t = icmp slt i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_c(i32 %n) {
+ %t = icmp sge i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_c(i32 %n) {
+ %t = icmp sle i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_d(i32 %n) {
+ %t = icmp sge i32 %n, 1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_d(i32 %n) {
+ %t = icmp sle i32 %n, -1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_e(i32 %n) {
+ %t = icmp sgt i32 %n, -1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_e(i32 %n) {
+ %t = icmp slt i32 %n, 1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_f(i32 %n) {
+ %t = icmp sgt i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_f(i32 %n) {
+ %t = icmp slt i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_g(i32 %n) {
+ %t = icmp sge i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_g(i32 %n) {
+ %t = icmp sle i32 %n, 0
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @floor_h(i32 %n) {
+ %t = icmp sge i32 %n, 1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
+define i32 @ceil_h(i32 %n) {
+ %t = icmp sle i32 %n, -1
+ %m = select i1 %t, i32 %n, i32 0
+ ret i32 %m
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/align-2d-gep.ll b/src/LLVM/test/Transforms/InstCombine/align-2d-gep.ll
new file mode 100644
index 0000000..eeca5c0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/align-2d-gep.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -instcombine -S | grep {align 16} | count 1
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+; A multi-dimensional array in a nested loop doing vector stores that
+; aren't yet aligned. Instcombine can understand the addressing in the
+; Nice case to prove 16 byte alignment. In the Awkward case, the inner
+; array dimension is not even, so the stores to it won't always be
+; aligned. Instcombine should prove alignment in exactly one of the two
+; stores.
+
+@Nice = global [1001 x [20000 x double]] zeroinitializer, align 32
+@Awkward = global [1001 x [20001 x double]] zeroinitializer, align 32
+
+define void @foo() nounwind {
+entry:
+ br label %bb7.outer
+
+bb7.outer:
+ %i = phi i64 [ 0, %entry ], [ %indvar.next26, %bb11 ]
+ br label %bb1
+
+bb1:
+ %j = phi i64 [ 0, %bb7.outer ], [ %indvar.next, %bb1 ]
+
+ %t4 = getelementptr [1001 x [20000 x double]]* @Nice, i64 0, i64 %i, i64 %j
+ %q = bitcast double* %t4 to <2 x double>*
+ store <2 x double><double 0.0, double 0.0>, <2 x double>* %q, align 8
+
+ %s4 = getelementptr [1001 x [20001 x double]]* @Awkward, i64 0, i64 %i, i64 %j
+ %r = bitcast double* %s4 to <2 x double>*
+ store <2 x double><double 0.0, double 0.0>, <2 x double>* %r, align 8
+
+ %indvar.next = add i64 %j, 2
+ %exitcond = icmp eq i64 %indvar.next, 557
+ br i1 %exitcond, label %bb11, label %bb1
+
+bb11:
+ %indvar.next26 = add i64 %i, 1
+ %exitcond27 = icmp eq i64 %indvar.next26, 991
+ br i1 %exitcond27, label %return.split, label %bb7.outer
+
+return.split:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/align-addr.ll b/src/LLVM/test/Transforms/InstCombine/align-addr.ll
new file mode 100644
index 0000000..27916b9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/align-addr.ll
@@ -0,0 +1,60 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+; Instcombine should be able to prove vector alignment in the
+; presence of a few mild address computation tricks.
+
+; CHECK: @test0(
+; CHECK: align 16
+
+define void @test0(i8* %b, i64 %n, i64 %u, i64 %y) nounwind {
+entry:
+ %c = ptrtoint i8* %b to i64
+ %d = and i64 %c, -16
+ %e = inttoptr i64 %d to double*
+ %v = mul i64 %u, 2
+ %z = and i64 %y, -2
+ %t1421 = icmp eq i64 %n, 0
+ br i1 %t1421, label %return, label %bb
+
+bb:
+ %i = phi i64 [ %indvar.next, %bb ], [ 20, %entry ]
+ %j = mul i64 %i, %v
+ %h = add i64 %j, %z
+ %t8 = getelementptr double* %e, i64 %h
+ %p = bitcast double* %t8 to <2 x double>*
+ store <2 x double><double 0.0, double 0.0>, <2 x double>* %p, align 8
+ %indvar.next = add i64 %i, 1
+ %exitcond = icmp eq i64 %indvar.next, %n
+ br i1 %exitcond, label %return, label %bb
+
+return:
+ ret void
+}
+
+; When we see a unaligned load from an insufficiently aligned global or
+; alloca, increase the alignment of the load, turning it into an aligned load.
+
+; CHECK: @test1(
+; CHECK: tmp = load
+; CHECK: GLOBAL{{.*}}align 16
+
+@GLOBAL = internal global [4 x i32] zeroinitializer
+
+define <16 x i8> @test1(<2 x i64> %x) {
+entry:
+ %tmp = load <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*), align 1
+ ret <16 x i8> %tmp
+}
+
+; When a load or store lacks an explicit alignment, add one.
+
+; CHECK: @test2(
+; CHECK: load double* %p, align 8
+; CHECK: store double %n, double* %p, align 8
+
+define double @test2(double* %p, double %n) nounwind {
+ %t = load double* %p
+ store double %n, double* %p
+ ret double %t
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/align-external.ll b/src/LLVM/test/Transforms/InstCombine/align-external.ll
new file mode 100644
index 0000000..6e8ad87
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/align-external.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Don't assume that external global variables have their preferred
+; alignment. They may only have the ABI minimum alignment.
+
+; CHECK: %s = shl i64 %a, 3
+; CHECK: %r = or i64 %s, ptrtoint (i32* @A to i64)
+; CHECK: %q = add i64 %r, 1
+; CHECK: ret i64 %q
+
+target datalayout = "-i32:8:32"
+
+@A = external global i32
+@B = external global i32
+
+define i64 @foo(i64 %a) {
+ %t = ptrtoint i32* @A to i64
+ %s = shl i64 %a, 3
+ %r = or i64 %t, %s
+ %q = add i64 %r, 1
+ ret i64 %q
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/alloca.ll b/src/LLVM/test/Transforms/InstCombine/alloca.ll
new file mode 100644
index 0000000..9873198
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/alloca.ll
@@ -0,0 +1,46 @@
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; END.
+
+declare void @use(...)
+
+; Zero byte allocas should be deleted.
+; CHECK: @test
+; CHECK-NOT: alloca
+define void @test() {
+ %X = alloca [0 x i32] ; <[0 x i32]*> [#uses=1]
+ call void (...)* @use( [0 x i32]* %X )
+ %Y = alloca i32, i32 0 ; <i32*> [#uses=1]
+ call void (...)* @use( i32* %Y )
+ %Z = alloca { } ; <{ }*> [#uses=1]
+ call void (...)* @use( { }* %Z )
+ ret void
+}
+
+; Zero byte allocas should be deleted.
+; CHECK: @test2
+; CHECK-NOT: alloca
+define void @test2() {
+ %A = alloca i32 ; <i32*> [#uses=1]
+ store i32 123, i32* %A
+ ret void
+}
+
+; Zero byte allocas should be deleted.
+; CHECK: @test3
+; CHECK-NOT: alloca
+define void @test3() {
+ %A = alloca { i32 } ; <{ i32 }*> [#uses=1]
+ %B = getelementptr { i32 }* %A, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 123, i32* %B
+ ret void
+}
+
+; CHECK: @test4
+; CHECK: = zext i32 %n to i64
+; CHECK: %A = alloca i32, i64 %
+define i32* @test4(i32 %n) {
+ %A = alloca i32, i32 %n
+ ret i32* %A
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/and-compare.ll b/src/LLVM/test/Transforms/InstCombine/and-compare.ll
new file mode 100644
index 0000000..67bd605
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-compare.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep and | count 1
+
+; Should be optimized to one and.
+define i1 @test1(i32 %a, i32 %b) {
+ %tmp1 = and i32 %a, 65280 ; <i32> [#uses=1]
+ %tmp3 = and i32 %b, 65280 ; <i32> [#uses=1]
+ %tmp = icmp ne i32 %tmp1, %tmp3 ; <i1> [#uses=1]
+ ret i1 %tmp
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/and-fcmp.ll b/src/LLVM/test/Transforms/InstCombine/and-fcmp.ll
new file mode 100644
index 0000000..91868d1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-fcmp.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -instcombine -S | grep fcmp | count 3
+; RUN: opt < %s -instcombine -S | grep ret | grep 0
+
+define zeroext i8 @t1(float %x, float %y) nounwind {
+ %a = fcmp ueq float %x, %y
+ %b = fcmp ord float %x, %y
+ %c = and i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+define zeroext i8 @t2(float %x, float %y) nounwind {
+ %a = fcmp olt float %x, %y
+ %b = fcmp ord float %x, %y
+ %c = and i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+define zeroext i8 @t3(float %x, float %y) nounwind {
+ %a = fcmp oge float %x, %y
+ %b = fcmp uno float %x, %y
+ %c = and i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+define zeroext i8 @t4(float %x, float %y) nounwind {
+ %a = fcmp one float %y, %x
+ %b = fcmp ord float %x, %y
+ %c = and i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/and-not-or.ll b/src/LLVM/test/Transforms/InstCombine/and-not-or.ll
new file mode 100644
index 0000000..9dce7b4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-not-or.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -instcombine -S | grep {and i32 %x, %y} | count 4
+; RUN: opt < %s -instcombine -S | not grep {or}
+
+define i32 @func1(i32 %x, i32 %y) nounwind {
+entry:
+ %n = xor i32 %y, -1
+ %o = or i32 %n, %x
+ %a = and i32 %o, %y
+ ret i32 %a
+}
+
+define i32 @func2(i32 %x, i32 %y) nounwind {
+entry:
+ %n = xor i32 %y, -1
+ %o = or i32 %x, %n
+ %a = and i32 %o, %y
+ ret i32 %a
+}
+
+define i32 @func3(i32 %x, i32 %y) nounwind {
+entry:
+ %n = xor i32 %y, -1
+ %o = or i32 %n, %x
+ %a = and i32 %y, %o
+ ret i32 %a
+}
+
+define i32 @func4(i32 %x, i32 %y) nounwind {
+entry:
+ %n = xor i32 %y, -1
+ %o = or i32 %x, %n
+ %a = and i32 %y, %o
+ ret i32 %a
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/and-or-and.ll b/src/LLVM/test/Transforms/InstCombine/and-or-and.ll
new file mode 100644
index 0000000..36ce672
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-or-and.ll
@@ -0,0 +1,61 @@
+; If we have an 'and' of the result of an 'or', and one of the 'or' operands
+; cannot have contributed any of the resultant bits, delete the or. This
+; occurs for very common C/C++ code like this:
+;
+; struct foo { int A : 16; int B : 16; };
+; void test(struct foo *F, int X, int Y) {
+; F->A = X; F->B = Y;
+; }
+;
+; Which corresponds to test1.
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep {or }
+
+define i32 @test1(i32 %X, i32 %Y) {
+ %A = and i32 %X, 7 ; <i32> [#uses=1]
+ %B = and i32 %Y, 8 ; <i32> [#uses=1]
+ %C = or i32 %A, %B ; <i32> [#uses=1]
+ ;; This cannot include any bits from %Y!
+ %D = and i32 %C, 7 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test2(i32 %X, i8 %Y) {
+ %B = zext i8 %Y to i32 ; <i32> [#uses=1]
+ %C = or i32 %X, %B ; <i32> [#uses=1]
+ ;; This cannot include any bits from %Y!
+ %D = and i32 %C, 65536 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test3(i32 %X, i32 %Y) {
+ %B = shl i32 %Y, 1 ; <i32> [#uses=1]
+ %C = or i32 %X, %B ; <i32> [#uses=1]
+ ;; This cannot include any bits from %Y!
+ %D = and i32 %C, 1 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test4(i32 %X, i32 %Y) {
+ %B = lshr i32 %Y, 31 ; <i32> [#uses=1]
+ %C = or i32 %X, %B ; <i32> [#uses=1]
+ ;; This cannot include any bits from %Y!
+ %D = and i32 %C, 2 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @or_test1(i32 %X, i32 %Y) {
+ %A = and i32 %X, 1 ; <i32> [#uses=1]
+ ;; This cannot include any bits from X!
+ %B = or i32 %A, 1 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i8 @or_test2(i8 %X, i8 %Y) {
+ %A = shl i8 %X, 7 ; <i8> [#uses=1]
+ ;; This cannot include any bits from X!
+ %B = or i8 %A, -128 ; <i8> [#uses=1]
+ ret i8 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/and-or-not.ll b/src/LLVM/test/Transforms/InstCombine/and-or-not.ll
new file mode 100644
index 0000000..a57871f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-or-not.ll
@@ -0,0 +1,46 @@
+; RUN: opt < %s -instcombine -S | grep xor | count 4
+; RUN: opt < %s -instcombine -S | not grep and
+; RUN: opt < %s -instcombine -S | not grep { or}
+
+; PR1510
+
+; These are all equivalent to A^B
+
+define i32 @test1(i32 %a, i32 %b) {
+entry:
+ %tmp3 = or i32 %b, %a ; <i32> [#uses=1]
+ %tmp3not = xor i32 %tmp3, -1 ; <i32> [#uses=1]
+ %tmp6 = and i32 %b, %a ; <i32> [#uses=1]
+ %tmp7 = or i32 %tmp6, %tmp3not ; <i32> [#uses=1]
+ %tmp7not = xor i32 %tmp7, -1 ; <i32> [#uses=1]
+ ret i32 %tmp7not
+}
+
+define i32 @test2(i32 %a, i32 %b) {
+entry:
+ %tmp3 = or i32 %b, %a ; <i32> [#uses=1]
+ %tmp6 = and i32 %b, %a ; <i32> [#uses=1]
+ %tmp6not = xor i32 %tmp6, -1 ; <i32> [#uses=1]
+ %tmp7 = and i32 %tmp3, %tmp6not ; <i32> [#uses=1]
+ ret i32 %tmp7
+}
+
+define <4 x i32> @test3(<4 x i32> %a, <4 x i32> %b) {
+entry:
+ %tmp3 = or <4 x i32> %a, %b ; <<4 x i32>> [#uses=1]
+ %tmp3not = xor <4 x i32> %tmp3, < i32 -1, i32 -1, i32 -1, i32 -1 > ; <<4 x i32>> [#uses=1]
+ %tmp6 = and <4 x i32> %a, %b ; <<4 x i32>> [#uses=1]
+ %tmp7 = or <4 x i32> %tmp6, %tmp3not ; <<4 x i32>> [#uses=1]
+ %tmp7not = xor <4 x i32> %tmp7, < i32 -1, i32 -1, i32 -1, i32 -1 > ; <<4 x i32>> [#uses=1]
+ ret <4 x i32> %tmp7not
+}
+
+define <4 x i32> @test4(<4 x i32> %a, <4 x i32> %b) {
+entry:
+ %tmp3 = or <4 x i32> %a, %b ; <<4 x i32>> [#uses=1]
+ %tmp6 = and <4 x i32> %a, %b ; <<4 x i32>> [#uses=1]
+ %tmp6not = xor <4 x i32> %tmp6, < i32 -1, i32 -1, i32 -1, i32 -1 > ; <<4 x i32>> [#uses=1]
+ %tmp7 = and <4 x i32> %tmp3, %tmp6not ; <<4 x i32>> [#uses=1]
+ ret <4 x i32> %tmp7
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/and-or.ll b/src/LLVM/test/Transforms/InstCombine/and-or.ll
new file mode 100644
index 0000000..b4224b3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-or.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -instcombine -S | grep {and i32 %a, 1} | count 4
+; RUN: opt < %s -instcombine -S | grep {or i32 %0, %b} | count 4
+
+
+define i32 @func1(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %0 = or i32 %b, %a ; <i32> [#uses=1]
+ %1 = and i32 %0, 1 ; <i32> [#uses=1]
+ %2 = and i32 %b, -2 ; <i32> [#uses=1]
+ %3 = or i32 %1, %2 ; <i32> [#uses=1]
+ ret i32 %3
+}
+
+define i32 @func2(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %0 = or i32 %a, %b ; <i32> [#uses=1]
+ %1 = and i32 1, %0 ; <i32> [#uses=1]
+ %2 = and i32 -2, %b ; <i32> [#uses=1]
+ %3 = or i32 %1, %2 ; <i32> [#uses=1]
+ ret i32 %3
+}
+
+define i32 @func3(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %0 = or i32 %b, %a ; <i32> [#uses=1]
+ %1 = and i32 %0, 1 ; <i32> [#uses=1]
+ %2 = and i32 %b, -2 ; <i32> [#uses=1]
+ %3 = or i32 %2, %1 ; <i32> [#uses=1]
+ ret i32 %3
+}
+
+define i32 @func4(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %0 = or i32 %a, %b ; <i32> [#uses=1]
+ %1 = and i32 1, %0 ; <i32> [#uses=1]
+ %2 = and i32 -2, %b ; <i32> [#uses=1]
+ %3 = or i32 %2, %1 ; <i32> [#uses=1]
+ ret i32 %3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/and-xor-merge.ll b/src/LLVM/test/Transforms/InstCombine/and-xor-merge.ll
new file mode 100644
index 0000000..3c76838
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and-xor-merge.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | grep and | count 1
+; RUN: opt < %s -instcombine -S | grep xor | count 2
+
+; (x&z) ^ (y&z) -> (x^y)&z
+define i32 @test1(i32 %x, i32 %y, i32 %z) {
+ %tmp3 = and i32 %z, %x
+ %tmp6 = and i32 %z, %y
+ %tmp7 = xor i32 %tmp3, %tmp6
+ ret i32 %tmp7
+}
+
+; (x & y) ^ (x|y) -> x^y
+define i32 @test2(i32 %x, i32 %y, i32 %z) {
+ %tmp3 = and i32 %y, %x
+ %tmp6 = or i32 %y, %x
+ %tmp7 = xor i32 %tmp3, %tmp6
+ ret i32 %tmp7
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/and.ll b/src/LLVM/test/Transforms/InstCombine/and.ll
new file mode 100644
index 0000000..1702e63
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and.ll
@@ -0,0 +1,255 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+
+; RUN: opt < %s -instcombine -S | not grep and
+
+define i32 @test1(i32 %A) {
+ ; zero result
+ %B = and i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test2(i32 %A) {
+ ; noop
+ %B = and i32 %A, -1 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i1 @test3(i1 %A) {
+ ; always = false
+ %B = and i1 %A, false ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test4(i1 %A) {
+ ; noop
+ %B = and i1 %A, true ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i32 @test5(i32 %A) {
+ %B = and i32 %A, %A ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i1 @test6(i1 %A) {
+ %B = and i1 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+; A & ~A == 0
+define i32 @test7(i32 %A) {
+ %NotA = xor i32 %A, -1 ; <i32> [#uses=1]
+ %B = and i32 %A, %NotA ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+; AND associates
+define i8 @test8(i8 %A) {
+ %B = and i8 %A, 3 ; <i8> [#uses=1]
+ %C = and i8 %B, 4 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i1 @test9(i32 %A) {
+ ; Test of sign bit, convert to setle %A, 0
+ %B = and i32 %A, -2147483648 ; <i32> [#uses=1]
+ %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test9a(i32 %A) {
+ ; Test of sign bit, convert to setle %A, 0
+ %B = and i32 %A, -2147483648 ; <i32> [#uses=1]
+ %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i32 @test10(i32 %A) {
+ %B = and i32 %A, 12 ; <i32> [#uses=1]
+ %C = xor i32 %B, 15 ; <i32> [#uses=1]
+ ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
+ %D = and i32 %C, 1 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test11(i32 %A, i32* %P) {
+ %B = or i32 %A, 3 ; <i32> [#uses=1]
+ %C = xor i32 %B, 12 ; <i32> [#uses=2]
+ ; additional use of C
+ store i32 %C, i32* %P
+ ; %C = and uint %B, 3 --> 3
+ %D = and i32 %C, 3 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i1 @test12(i32 %A, i32 %B) {
+ %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
+ %C2 = icmp ule i32 %A, %B ; <i1> [#uses=1]
+ ; (A < B) & (A <= B) === (A < B)
+ %D = and i1 %C1, %C2 ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test13(i32 %A, i32 %B) {
+ %C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
+ %C2 = icmp ugt i32 %A, %B ; <i1> [#uses=1]
+ ; (A < B) & (A > B) === false
+ %D = and i1 %C1, %C2 ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test14(i8 %A) {
+ %B = and i8 %A, -128 ; <i8> [#uses=1]
+ %C = icmp ne i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i8 @test15(i8 %A) {
+ %B = lshr i8 %A, 7 ; <i8> [#uses=1]
+ ; Always equals zero
+ %C = and i8 %B, 2 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i8 @test16(i8 %A) {
+ %B = shl i8 %A, 2 ; <i8> [#uses=1]
+ %C = and i8 %B, 3 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; ~(~X & Y) --> (X | ~Y)
+define i8 @test17(i8 %X, i8 %Y) {
+ %B = xor i8 %X, -1 ; <i8> [#uses=1]
+ %C = and i8 %B, %Y ; <i8> [#uses=1]
+ %D = xor i8 %C, -1 ; <i8> [#uses=1]
+ ret i8 %D
+}
+
+define i1 @test18(i32 %A) {
+ %B = and i32 %A, -128 ; <i32> [#uses=1]
+ ;; C >= 128
+ %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test18a(i8 %A) {
+ %B = and i8 %A, -2 ; <i8> [#uses=1]
+ %C = icmp eq i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i32 @test19(i32 %A) {
+ %B = shl i32 %A, 3 ; <i32> [#uses=1]
+ ;; Clearing a zero bit
+ %C = and i32 %B, -2 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i8 @test20(i8 %A) {
+ %C = lshr i8 %A, 7 ; <i8> [#uses=1]
+ ;; Unneeded
+ %D = and i8 %C, 1 ; <i8> [#uses=1]
+ ret i8 %D
+}
+
+define i1 @test22(i32 %A) {
+ %B = icmp eq i32 %A, 1 ; <i1> [#uses=1]
+ %C = icmp sge i32 %A, 3 ; <i1> [#uses=1]
+ ;; false
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test23(i32 %A) {
+ %B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
+ %C = icmp sle i32 %A, 2 ; <i1> [#uses=1]
+ ;; A == 2
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test24(i32 %A) {
+ %B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
+ %C = icmp ne i32 %A, 2 ; <i1> [#uses=1]
+ ;; A > 2
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test25(i32 %A) {
+ %B = icmp sge i32 %A, 50 ; <i1> [#uses=1]
+ %C = icmp slt i32 %A, 100 ; <i1> [#uses=1]
+ ;; (A-50) <u 50
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test26(i32 %A) {
+ %B = icmp ne i32 %A, 50 ; <i1> [#uses=1]
+ %C = icmp ne i32 %A, 51 ; <i1> [#uses=1]
+ ;; (A-50) > 1
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i8 @test27(i8 %A) {
+ %B = and i8 %A, 4 ; <i8> [#uses=1]
+ %C = sub i8 %B, 16 ; <i8> [#uses=1]
+ ;; 0xF0
+ %D = and i8 %C, -16 ; <i8> [#uses=1]
+ %E = add i8 %D, 16 ; <i8> [#uses=1]
+ ret i8 %E
+}
+
+;; This is juse a zero extending shr.
+define i32 @test28(i32 %X) {
+ ;; Sign extend
+ %Y = ashr i32 %X, 24 ; <i32> [#uses=1]
+ ;; Mask out sign bits
+ %Z = and i32 %Y, 255 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test29(i8 %X) {
+ %Y = zext i8 %X to i32 ; <i32> [#uses=1]
+ ;; Zero extend makes this unneeded.
+ %Z = and i32 %Y, 255 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test30(i1 %X) {
+ %Y = zext i1 %X to i32 ; <i32> [#uses=1]
+ %Z = and i32 %Y, 1 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test31(i1 %X) {
+ %Y = zext i1 %X to i32 ; <i32> [#uses=1]
+ %Z = shl i32 %Y, 4 ; <i32> [#uses=1]
+ %A = and i32 %Z, 16 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
+define i32 @test32(i32 %In) {
+ %Y = and i32 %In, 16 ; <i32> [#uses=1]
+ %Z = lshr i32 %Y, 2 ; <i32> [#uses=1]
+ %A = and i32 %Z, 1 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
+;; Code corresponding to one-bit bitfield ^1.
+define i32 @test33(i32 %b) {
+ %tmp.4.mask = and i32 %b, 1 ; <i32> [#uses=1]
+ %tmp.10 = xor i32 %tmp.4.mask, 1 ; <i32> [#uses=1]
+ %tmp.12 = and i32 %b, -2 ; <i32> [#uses=1]
+ %tmp.13 = or i32 %tmp.12, %tmp.10 ; <i32> [#uses=1]
+ ret i32 %tmp.13
+}
+
+define i32 @test34(i32 %A, i32 %B) {
+ %tmp.2 = or i32 %B, %A ; <i32> [#uses=1]
+ %tmp.4 = and i32 %tmp.2, %B ; <i32> [#uses=1]
+ ret i32 %tmp.4
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/and2.ll b/src/LLVM/test/Transforms/InstCombine/and2.ll
new file mode 100644
index 0000000..531aedb
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/and2.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; PR1738
+define i1 @test1(double %X, double %Y) {
+ %tmp9 = fcmp ord double %X, 0.000000e+00
+ %tmp13 = fcmp ord double %Y, 0.000000e+00
+ %bothcond = and i1 %tmp13, %tmp9
+ ret i1 %bothcond
+; CHECK: fcmp ord double %Y, %X
+}
+
+define i1 @test2(i1 %X, i1 %Y) {
+ %a = and i1 %X, %Y
+ %b = and i1 %a, %X
+ ret i1 %b
+; CHECK: @test2
+; CHECK-NEXT: and i1 %X, %Y
+; CHECK-NEXT: ret
+}
+
+define i32 @test3(i32 %X, i32 %Y) {
+ %a = and i32 %X, %Y
+ %b = and i32 %Y, %a
+ ret i32 %b
+; CHECK: @test3
+; CHECK-NEXT: and i32 %X, %Y
+; CHECK-NEXT: ret
+}
+
+define i1 @test4(i32 %X) {
+ %a = icmp ult i32 %X, 31
+ %b = icmp slt i32 %X, 0
+ %c = and i1 %a, %b
+ ret i1 %c
+; CHECK: @test4
+; CHECK-NEXT: ret i1 false
+}
+
+; Make sure we don't go into an infinite loop with this test
+define <4 x i32> @test5(<4 x i32> %A) {
+ %1 = xor <4 x i32> %A, <i32 1, i32 2, i32 3, i32 4>
+ %2 = and <4 x i32> <i32 1, i32 2, i32 3, i32 4>, %1
+ ret <4 x i32> %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-add1.ll b/src/LLVM/test/Transforms/InstCombine/apint-add1.ll
new file mode 100644
index 0000000..734e15d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-add1.ll
@@ -0,0 +1,34 @@
+; This test makes sure that add instructions are properly eliminated.
+; This test is for Integer BitWidth <= 64 && BitWidth % 8 != 0.
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v OK | not grep add
+
+
+define i1 @test1(i1 %x) {
+ %tmp.2 = xor i1 %x, 1
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i1 %tmp.2, 1
+ ret i1 %tmp.4
+}
+
+define i47 @test2(i47 %x) {
+ %tmp.2 = xor i47 %x, 70368744177664
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i47 %tmp.2, 70368744177664
+ ret i47 %tmp.4
+}
+
+define i15 @test3(i15 %x) {
+ %tmp.2 = xor i15 %x, 16384
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i15 %tmp.2, 16384
+ ret i15 %tmp.4
+}
+
+define i49 @test6(i49 %x) {
+ ;; (x & 254)+1 -> (x & 254)|1
+ %tmp.2 = and i49 %x, 562949953421310
+ %tmp.4 = add i49 %tmp.2, 1
+ ret i49 %tmp.4
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-add2.ll b/src/LLVM/test/Transforms/InstCombine/apint-add2.ll
new file mode 100644
index 0000000..3de13ac
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-add2.ll
@@ -0,0 +1,46 @@
+; This test makes sure that add instructions are properly eliminated.
+; This test is for Integer BitWidth > 64 && BitWidth <= 1024.
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v OK | not grep add
+; END.
+
+define i111 @test1(i111 %x) {
+ %tmp.2 = shl i111 1, 110
+ %tmp.4 = xor i111 %x, %tmp.2
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.6 = add i111 %tmp.4, %tmp.2
+ ret i111 %tmp.6
+}
+
+define i65 @test2(i65 %x) {
+ %tmp.0 = shl i65 1, 64
+ %tmp.2 = xor i65 %x, %tmp.0
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i65 %tmp.2, %tmp.0
+ ret i65 %tmp.4
+}
+
+define i1024 @test3(i1024 %x) {
+ %tmp.0 = shl i1024 1, 1023
+ %tmp.2 = xor i1024 %x, %tmp.0
+ ;; Add of sign bit -> xor of sign bit.
+ %tmp.4 = add i1024 %tmp.2, %tmp.0
+ ret i1024 %tmp.4
+}
+
+define i128 @test4(i128 %x) {
+ ;; If we have ADD(XOR(AND(X, 0xFF), 0xF..F80), 0x80), it's a sext.
+ %tmp.5 = shl i128 1, 127
+ %tmp.1 = ashr i128 %tmp.5, 120
+ %tmp.2 = xor i128 %x, %tmp.1
+ %tmp.4 = add i128 %tmp.2, %tmp.5
+ ret i128 %tmp.4
+}
+
+define i77 @test6(i77 %x) {
+ ;; (x & 254)+1 -> (x & 254)|1
+ %tmp.2 = and i77 %x, 562949953421310
+ %tmp.4 = add i77 %tmp.2, 1
+ ret i77 %tmp.4
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-and-compare.ll b/src/LLVM/test/Transforms/InstCombine/apint-and-compare.ll
new file mode 100644
index 0000000..143327d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-and-compare.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -S | grep and | count 2
+
+; Should be optimized to one and.
+define i1 @test1(i33 %a, i33 %b) {
+ %tmp1 = and i33 %a, 65280
+ %tmp3 = and i33 %b, 65280
+ %tmp = icmp ne i33 %tmp1, %tmp3
+ ret i1 %tmp
+}
+
+define i1 @test2(i999 %a, i999 %b) {
+ %tmp1 = and i999 %a, 65280
+ %tmp3 = and i999 %b, 65280
+ %tmp = icmp ne i999 %tmp1, %tmp3
+ ret i1 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-and-or-and.ll b/src/LLVM/test/Transforms/InstCombine/apint-and-or-and.ll
new file mode 100644
index 0000000..6a9d4b2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-and-or-and.ll
@@ -0,0 +1,50 @@
+; If we have an 'and' of the result of an 'or', and one of the 'or' operands
+; cannot have contributed any of the resultant bits, delete the or. This
+; occurs for very common C/C++ code like this:
+;
+; struct foo { int A : 16; int B : 16; };
+; void test(struct foo *F, int X, int Y) {
+; F->A = X; F->B = Y;
+; }
+;
+; Which corresponds to test1.
+;
+; This tests arbitrary precision integers.
+
+; RUN: opt < %s -instcombine -S | not grep {or }
+; END.
+
+define i17 @test1(i17 %X, i17 %Y) {
+ %A = and i17 %X, 7
+ %B = and i17 %Y, 8
+ %C = or i17 %A, %B
+ %D = and i17 %C, 7 ;; This cannot include any bits from %Y!
+ ret i17 %D
+}
+
+define i49 @test3(i49 %X, i49 %Y) {
+ %B = shl i49 %Y, 1
+ %C = or i49 %X, %B
+ %D = and i49 %C, 1 ;; This cannot include any bits from %Y!
+ ret i49 %D
+}
+
+define i67 @test4(i67 %X, i67 %Y) {
+ %B = lshr i67 %Y, 66
+ %C = or i67 %X, %B
+ %D = and i67 %C, 2 ;; This cannot include any bits from %Y!
+ ret i67 %D
+}
+
+define i231 @or_test1(i231 %X, i231 %Y) {
+ %A = and i231 %X, 1
+ %B = or i231 %A, 1 ;; This cannot include any bits from X!
+ ret i231 %B
+}
+
+define i7 @or_test2(i7 %X, i7 %Y) {
+ %A = shl i7 %X, 6
+ %B = or i7 %A, 64 ;; This cannot include any bits from X!
+ ret i7 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-and-xor-merge.ll b/src/LLVM/test/Transforms/InstCombine/apint-and-xor-merge.ll
new file mode 100644
index 0000000..cac5119
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-and-xor-merge.ll
@@ -0,0 +1,22 @@
+; This test case checks that the merge of and/xor can work on arbitrary
+; precision integers.
+
+; RUN: opt < %s -instcombine -S | grep and | count 1
+; RUN: opt < %s -instcombine -S | grep xor | count 2
+
+; (x &z ) ^ (y & z) -> (x ^ y) & z
+define i57 @test1(i57 %x, i57 %y, i57 %z) {
+ %tmp3 = and i57 %z, %x
+ %tmp6 = and i57 %z, %y
+ %tmp7 = xor i57 %tmp3, %tmp6
+ ret i57 %tmp7
+}
+
+; (x & y) ^ (x | y) -> x ^ y
+define i23 @test2(i23 %x, i23 %y, i23 %z) {
+ %tmp3 = and i23 %y, %x
+ %tmp6 = or i23 %y, %x
+ %tmp7 = xor i23 %tmp3, %tmp6
+ ret i23 %tmp7
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-and1.ll b/src/LLVM/test/Transforms/InstCombine/apint-and1.ll
new file mode 100644
index 0000000..7f7bc23
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-and1.ll
@@ -0,0 +1,57 @@
+; This test makes sure that and instructions are properly eliminated.
+; This test is for Integer BitWidth <= 64 && BitWidth % 8 != 0.
+
+; RUN: opt < %s -instcombine -S | not grep {and }
+; END.
+
+define i39 @test0(i39 %A) {
+ %B = and i39 %A, 0 ; zero result
+ ret i39 %B
+}
+
+define i47 @test1(i47 %A, i47 %B) {
+ ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
+ %NotA = xor i47 %A, -1
+ %NotB = xor i47 %B, -1
+ %C1 = and i47 %NotA, %NotB
+ ret i47 %C1
+}
+
+define i15 @test2(i15 %x) {
+ %tmp.2 = and i15 %x, -1 ; noop
+ ret i15 %tmp.2
+}
+
+define i23 @test3(i23 %x) {
+ %tmp.0 = and i23 %x, 127
+ %tmp.2 = and i23 %tmp.0, 128
+ ret i23 %tmp.2
+}
+
+define i1 @test4(i37 %x) {
+ %A = and i37 %x, -2147483648
+ %B = icmp ne i37 %A, 0
+ ret i1 %B
+}
+
+define i7 @test5(i7 %A, i7* %P) {
+ %B = or i7 %A, 3
+ %C = xor i7 %B, 12
+ store i7 %C, i7* %P
+ %r = and i7 %C, 3
+ ret i7 %r
+}
+
+define i7 @test6(i7 %A, i7 %B) {
+ ;; ~(~X & Y) --> (X | ~Y)
+ %t0 = xor i7 %A, -1
+ %t1 = and i7 %t0, %B
+ %r = xor i7 %t1, -1
+ ret i7 %r
+}
+
+define i47 @test7(i47 %A) {
+ %X = ashr i47 %A, 39 ;; sign extend
+ %C1 = and i47 %X, 255
+ ret i47 %C1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-and2.ll b/src/LLVM/test/Transforms/InstCombine/apint-and2.ll
new file mode 100644
index 0000000..145f81a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-and2.ll
@@ -0,0 +1,82 @@
+; This test makes sure that and instructions are properly eliminated.
+; This test is for Integer BitWidth > 64 && BitWidth <= 1024.
+
+; RUN: opt < %s -instcombine -S | not grep {and }
+; END.
+
+
+define i999 @test0(i999 %A) {
+ %B = and i999 %A, 0 ; zero result
+ ret i999 %B
+}
+
+define i477 @test1(i477 %A, i477 %B) {
+ ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
+ %NotA = xor i477 %A, -1
+ %NotB = xor i477 %B, -1
+ %C1 = and i477 %NotA, %NotB
+ ret i477 %C1
+}
+
+define i129 @tst(i129 %A, i129 %B) {
+ ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
+ %NotA = xor i129 %A, -1
+ %NotB = xor i129 %B, -1
+ %C1 = and i129 %NotA, %NotB
+ ret i129 %C1
+}
+
+define i65 @test(i65 %A, i65 %B) {
+ ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
+ %NotA = xor i65 %A, -1
+ %NotB = xor i65 -1, %B
+ %C1 = and i65 %NotA, %NotB
+ ret i65 %C1
+}
+
+define i66 @tes(i66 %A, i66 %B) {
+ ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
+ %NotA = xor i66 %A, -1
+ %NotB = xor i66 %B, -1
+ %C1 = and i66 %NotA, %NotB
+ ret i66 %C1
+}
+
+define i1005 @test2(i1005 %x) {
+ %tmp.2 = and i1005 %x, -1 ; noop
+ ret i1005 %tmp.2
+}
+
+define i123 @test3(i123 %x) {
+ %tmp.0 = and i123 %x, 127
+ %tmp.2 = and i123 %tmp.0, 128
+ ret i123 %tmp.2
+}
+
+define i1 @test4(i737 %x) {
+ %A = and i737 %x, -2147483648
+ %B = icmp ne i737 %A, 0
+ ret i1 %B
+}
+
+define i117 @test5(i117 %A, i117* %P) {
+ %B = or i117 %A, 3
+ %C = xor i117 %B, 12
+ store i117 %C, i117* %P
+ %r = and i117 %C, 3
+ ret i117 %r
+}
+
+define i117 @test6(i117 %A, i117 %B) {
+ ;; ~(~X & Y) --> (X | ~Y)
+ %t0 = xor i117 %A, -1
+ %t1 = and i117 %t0, %B
+ %r = xor i117 %t1, -1
+ ret i117 %r
+}
+
+define i1024 @test7(i1024 %A) {
+ %X = ashr i1024 %A, 1016 ;; sign extend
+ %C1 = and i1024 %X, 255
+ ret i1024 %C1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-call-cast-target.ll b/src/LLVM/test/Transforms/InstCombine/apint-call-cast-target.ll
new file mode 100644
index 0000000..72f7570
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-call-cast-target.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | grep call | not grep bitcast
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+
+
+define i32 @main() {
+entry:
+ %tmp = call i32 bitcast (i7* (i999*)* @ctime to i32 (i99*)*)( i99* null )
+ ret i32 %tmp
+}
+
+define i7* @ctime(i999*) {
+entry:
+ %tmp = call i7* bitcast (i32 ()* @main to i7* ()*)( )
+ ret i7* %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-cast-and-cast.ll b/src/LLVM/test/Transforms/InstCombine/apint-cast-and-cast.ll
new file mode 100644
index 0000000..fe87928
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-cast-and-cast.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | not grep bitcast
+
+define i19 @test1(i43 %val) {
+ %t1 = bitcast i43 %val to i43
+ %t2 = and i43 %t1, 1
+ %t3 = trunc i43 %t2 to i19
+ ret i19 %t3
+}
+
+define i73 @test2(i677 %val) {
+ %t1 = bitcast i677 %val to i677
+ %t2 = and i677 %t1, 1
+ %t3 = trunc i677 %t2 to i73
+ ret i73 %t3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-cast-cast-to-and.ll b/src/LLVM/test/Transforms/InstCombine/apint-cast-cast-to-and.ll
new file mode 100644
index 0000000..9194970
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-cast-cast-to-and.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | not grep i41
+
+define i61 @test1(i61 %X) {
+ %Y = trunc i61 %X to i41 ;; Turn i61o an AND
+ %Z = zext i41 %Y to i61
+ ret i61 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-cast.ll b/src/LLVM/test/Transforms/InstCombine/apint-cast.ll
new file mode 100644
index 0000000..161a2c5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-cast.ll
@@ -0,0 +1,30 @@
+; Tests to make sure elimination of casts is working correctly
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+define i17 @test1(i17 %a) {
+ %tmp = zext i17 %a to i37 ; <i37> [#uses=2]
+ %tmp21 = lshr i37 %tmp, 8 ; <i37> [#uses=1]
+; CHECK: %tmp21 = lshr i17 %a, 8
+ %tmp5 = shl i37 %tmp, 8 ; <i37> [#uses=1]
+; CHECK: %tmp5 = shl i17 %a, 8
+ %tmp.upgrd.32 = or i37 %tmp21, %tmp5 ; <i37> [#uses=1]
+; CHECK: %tmp.upgrd.32 = or i17 %tmp21, %tmp5
+ %tmp.upgrd.3 = trunc i37 %tmp.upgrd.32 to i17 ; <i17> [#uses=1]
+ ret i17 %tmp.upgrd.3
+; CHECK: ret i17 %tmp.upgrd.32
+}
+
+define i167 @test2(i167 %a) {
+ %tmp = zext i167 %a to i577 ; <i577> [#uses=2]
+ %tmp21 = lshr i577 %tmp, 9 ; <i577> [#uses=1]
+; CHECK: %tmp21 = lshr i167 %a, 9
+ %tmp5 = shl i577 %tmp, 8 ; <i577> [#uses=1]
+; CHECK: %tmp5 = shl i167 %a, 8
+ %tmp.upgrd.32 = or i577 %tmp21, %tmp5 ; <i577> [#uses=1]
+; CHECK: %tmp.upgrd.32 = or i167 %tmp21, %tmp5
+ %tmp.upgrd.3 = trunc i577 %tmp.upgrd.32 to i167 ; <i167> [#uses=1]
+ ret i167 %tmp.upgrd.3
+; CHECK: ret i167 %tmp.upgrd.32
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-div1.ll b/src/LLVM/test/Transforms/InstCombine/apint-div1.ll
new file mode 100644
index 0000000..f015c89
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-div1.ll
@@ -0,0 +1,22 @@
+; This test makes sure that div instructions are properly eliminated.
+; This test is for Integer BitWidth < 64 && BitWidth % 2 != 0.
+;
+; RUN: opt < %s -instcombine -S | not grep div
+
+
+define i33 @test1(i33 %X) {
+ %Y = udiv i33 %X, 4096
+ ret i33 %Y
+}
+
+define i49 @test2(i49 %X) {
+ %tmp.0 = shl i49 4096, 17
+ %Y = udiv i49 %X, %tmp.0
+ ret i49 %Y
+}
+
+define i59 @test3(i59 %X, i1 %C) {
+ %V = select i1 %C, i59 1024, i59 4096
+ %R = udiv i59 %X, %V
+ ret i59 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-div2.ll b/src/LLVM/test/Transforms/InstCombine/apint-div2.ll
new file mode 100644
index 0000000..61a5ae8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-div2.ll
@@ -0,0 +1,22 @@
+; This test makes sure that div instructions are properly eliminated.
+; This test is for Integer BitWidth >= 64 && BitWidth <= 1024.
+;
+; RUN: opt < %s -instcombine -S | not grep div
+
+
+define i333 @test1(i333 %X) {
+ %Y = udiv i333 %X, 70368744177664
+ ret i333 %Y
+}
+
+define i499 @test2(i499 %X) {
+ %tmp.0 = shl i499 4096, 197
+ %Y = udiv i499 %X, %tmp.0
+ ret i499 %Y
+}
+
+define i599 @test3(i599 %X, i1 %C) {
+ %V = select i1 %C, i599 70368744177664, i599 4096
+ %R = udiv i599 %X, %V
+ ret i599 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-mul1.ll b/src/LLVM/test/Transforms/InstCombine/apint-mul1.ll
new file mode 100644
index 0000000..7516d1f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-mul1.ll
@@ -0,0 +1,11 @@
+; This test makes sure that mul instructions are properly eliminated.
+; This test is for Integer BitWidth < 64 && BitWidth % 2 != 0.
+;
+
+; RUN: opt < %s -instcombine -S | not grep mul
+
+
+define i17 @test1(i17 %X) {
+ %Y = mul i17 %X, 1024
+ ret i17 %Y
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-mul2.ll b/src/LLVM/test/Transforms/InstCombine/apint-mul2.ll
new file mode 100644
index 0000000..e495f45
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-mul2.ll
@@ -0,0 +1,12 @@
+; This test makes sure that mul instructions are properly eliminated.
+; This test is for Integer BitWidth >= 64 && BitWidth % 2 >= 1024.
+;
+
+; RUN: opt < %s -instcombine -S | not grep mul
+
+
+define i177 @test1(i177 %X) {
+ %C = shl i177 1, 155
+ %Y = mul i177 %X, %C
+ ret i177 %Y
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-not.ll b/src/LLVM/test/Transforms/InstCombine/apint-not.ll
new file mode 100644
index 0000000..aabac21
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-not.ll
@@ -0,0 +1,42 @@
+; This test makes sure that the xor instructions are properly eliminated
+; when arbitrary precision integers are used.
+
+; RUN: opt < %s -instcombine -S | not grep xor
+
+define i33 @test1(i33 %A) {
+ %B = xor i33 %A, -1
+ %C = xor i33 %B, -1
+ ret i33 %C
+}
+
+define i1 @test2(i52 %A, i52 %B) {
+ %cond = icmp ule i52 %A, %B ; Can change into uge
+ %Ret = xor i1 %cond, true
+ ret i1 %Ret
+}
+
+; Test that demorgans law can be instcombined
+define i47 @test3(i47 %A, i47 %B) {
+ %a = xor i47 %A, -1
+ %b = xor i47 %B, -1
+ %c = and i47 %a, %b
+ %d = xor i47 %c, -1
+ ret i47 %d
+}
+
+; Test that demorgens law can work with constants
+define i61 @test4(i61 %A, i61 %B) {
+ %a = xor i61 %A, -1
+ %c = and i61 %a, 5 ; 5 = ~c2
+ %d = xor i61 %c, -1
+ ret i61 %d
+}
+
+; test the mirror of demorgans law...
+define i71 @test5(i71 %A, i71 %B) {
+ %a = xor i71 %A, -1
+ %b = xor i71 %B, -1
+ %c = or i71 %a, %b
+ %d = xor i71 %c, -1
+ ret i71 %d
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-or1.ll b/src/LLVM/test/Transforms/InstCombine/apint-or1.ll
new file mode 100644
index 0000000..f4b37da
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-or1.ll
@@ -0,0 +1,36 @@
+; This test makes sure that or instructions are properly eliminated.
+; This test is for Integer BitWidth <= 64 && BitWidth % 2 != 0.
+;
+
+; RUN: opt < %s -instcombine -S | not grep or
+
+
+define i7 @test0(i7 %X) {
+ %Y = or i7 %X, 0
+ ret i7 %Y
+}
+
+define i17 @test1(i17 %X) {
+ %Y = or i17 %X, -1
+ ret i17 %Y
+}
+
+define i23 @test2(i23 %A) {
+ ;; A | ~A == -1
+ %NotA = xor i23 -1, %A
+ %B = or i23 %A, %NotA
+ ret i23 %B
+}
+
+define i39 @test3(i39 %V, i39 %M) {
+ ;; If we have: ((V + N) & C1) | (V & C2)
+ ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
+ ;; replace with V+N.
+ %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
+ %N = and i39 %M, 274877906944
+ %A = add i39 %V, %N
+ %B = and i39 %A, %C1
+ %D = and i39 %V, 274877906943
+ %R = or i39 %B, %D
+ ret i39 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-or2.ll b/src/LLVM/test/Transforms/InstCombine/apint-or2.ll
new file mode 100644
index 0000000..702776f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-or2.ll
@@ -0,0 +1,35 @@
+; This test makes sure that or instructions are properly eliminated.
+; This test is for Integer BitWidth > 64 && BitWidth <= 1024.
+;
+; RUN: opt < %s -instcombine -S | not grep or
+
+
+define i777 @test0(i777 %X) {
+ %Y = or i777 %X, 0
+ ret i777 %Y
+}
+
+define i117 @test1(i117 %X) {
+ %Y = or i117 %X, -1
+ ret i117 %Y
+}
+
+define i1023 @test2(i1023 %A) {
+ ;; A | ~A == -1
+ %NotA = xor i1023 -1, %A
+ %B = or i1023 %A, %NotA
+ ret i1023 %B
+}
+
+define i399 @test3(i399 %V, i399 %M) {
+ ;; If we have: ((V + N) & C1) | (V & C2)
+ ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
+ ;; replace with V+N.
+ %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
+ %N = and i399 %M, 18446742974197923840
+ %A = add i399 %V, %N
+ %B = and i399 %A, %C1
+ %D = and i399 %V, 274877906943
+ %R = or i399 %B, %D
+ ret i399 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-rem1.ll b/src/LLVM/test/Transforms/InstCombine/apint-rem1.ll
new file mode 100644
index 0000000..245d860
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-rem1.ll
@@ -0,0 +1,22 @@
+; This test makes sure that these instructions are properly eliminated.
+; This test is for Integer BitWidth < 64 && BitWidth % 2 != 0.
+;
+; RUN: opt < %s -instcombine -S | not grep rem
+
+
+define i33 @test1(i33 %A) {
+ %B = urem i33 %A, 4096
+ ret i33 %B
+}
+
+define i49 @test2(i49 %A) {
+ %B = shl i49 4096, 11
+ %Y = urem i49 %A, %B
+ ret i49 %Y
+}
+
+define i59 @test3(i59 %X, i1 %C) {
+ %V = select i1 %C, i59 70368744177664, i59 4096
+ %R = urem i59 %X, %V
+ ret i59 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-rem2.ll b/src/LLVM/test/Transforms/InstCombine/apint-rem2.ll
new file mode 100644
index 0000000..72807b9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-rem2.ll
@@ -0,0 +1,22 @@
+; This test makes sure that these instructions are properly eliminated.
+; This test is for Integer BitWidth >= 64 && BitWidth <= 1024.
+;
+; RUN: opt < %s -instcombine -S | not grep rem
+
+
+define i333 @test1(i333 %A) {
+ %B = urem i333 %A, 70368744177664
+ ret i333 %B
+}
+
+define i499 @test2(i499 %A) {
+ %B = shl i499 4096, 111
+ %Y = urem i499 %A, %B
+ ret i499 %Y
+}
+
+define i599 @test3(i599 %X, i1 %C) {
+ %V = select i1 %C, i599 70368744177664, i599 4096
+ %R = urem i599 %X, %V
+ ret i599 %R
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-select.ll b/src/LLVM/test/Transforms/InstCombine/apint-select.ll
new file mode 100644
index 0000000..2802b53
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-select.ll
@@ -0,0 +1,44 @@
+; This test makes sure that these instructions are properly eliminated.
+
+; RUN: opt < %s -instcombine -S | not grep select
+
+
+define i41 @test1(i1 %C) {
+ %V = select i1 %C, i41 1, i41 0 ; V = C
+ ret i41 %V
+}
+
+define i999 @test2(i1 %C) {
+ %V = select i1 %C, i999 0, i999 1 ; V = C
+ ret i999 %V
+}
+
+define i41 @test3(i41 %X) {
+ ;; (x <s 0) ? -1 : 0 -> ashr x, 31
+ %t = icmp slt i41 %X, 0
+ %V = select i1 %t, i41 -1, i41 0
+ ret i41 %V
+}
+
+define i1023 @test4(i1023 %X) {
+ ;; (x <s 0) ? -1 : 0 -> ashr x, 31
+ %t = icmp slt i1023 %X, 0
+ %V = select i1 %t, i1023 -1, i1023 0
+ ret i1023 %V
+}
+
+define i41 @test5(i41 %X) {
+ ;; ((X & 27) ? 27 : 0)
+ %Y = and i41 %X, 32
+ %t = icmp ne i41 %Y, 0
+ %V = select i1 %t, i41 32, i41 0
+ ret i41 %V
+}
+
+define i1023 @test6(i1023 %X) {
+ ;; ((X & 27) ? 27 : 0)
+ %Y = and i1023 %X, 64
+ %t = icmp ne i1023 %Y, 0
+ %V = select i1 %t, i1023 64, i1023 0
+ ret i1023 %V
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-shift-simplify.ll b/src/LLVM/test/Transforms/InstCombine/apint-shift-simplify.ll
new file mode 100644
index 0000000..f9e3af7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-shift-simplify.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: egrep {shl|lshr|ashr} | count 3
+
+define i41 @test0(i41 %A, i41 %B, i41 %C) {
+ %X = shl i41 %A, %C
+ %Y = shl i41 %B, %C
+ %Z = and i41 %X, %Y
+ ret i41 %Z
+}
+
+define i57 @test1(i57 %A, i57 %B, i57 %C) {
+ %X = lshr i57 %A, %C
+ %Y = lshr i57 %B, %C
+ %Z = or i57 %X, %Y
+ ret i57 %Z
+}
+
+define i49 @test2(i49 %A, i49 %B, i49 %C) {
+ %X = ashr i49 %A, %C
+ %Y = ashr i49 %B, %C
+ %Z = xor i49 %X, %Y
+ ret i49 %Z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-shift.ll b/src/LLVM/test/Transforms/InstCombine/apint-shift.ll
new file mode 100644
index 0000000..4f4f1dc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-shift.ll
@@ -0,0 +1,184 @@
+; This test makes sure that shit instructions are properly eliminated
+; even with arbitrary precision integers.
+; RUN: opt < %s -instcombine -S | not grep sh
+; END.
+
+define i47 @test1(i47 %A) {
+ %B = shl i47 %A, 0 ; <i47> [#uses=1]
+ ret i47 %B
+}
+
+define i41 @test2(i7 %X) {
+ %A = zext i7 %X to i41 ; <i41> [#uses=1]
+ %B = shl i41 0, %A ; <i41> [#uses=1]
+ ret i41 %B
+}
+
+define i41 @test3(i41 %A) {
+ %B = ashr i41 %A, 0 ; <i41> [#uses=1]
+ ret i41 %B
+}
+
+define i39 @test4(i7 %X) {
+ %A = zext i7 %X to i39 ; <i39> [#uses=1]
+ %B = ashr i39 0, %A ; <i39> [#uses=1]
+ ret i39 %B
+}
+
+define i55 @test5(i55 %A) {
+ %B = lshr i55 %A, 55 ; <i55> [#uses=1]
+ ret i55 %B
+}
+
+define i32 @test5a(i32 %A) {
+ %B = shl i32 %A, 32 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i55 @test6(i55 %A) {
+ %B = shl i55 %A, 1 ; <i55> [#uses=1]
+ %C = mul i55 %B, 3 ; <i55> [#uses=1]
+ ret i55 %C
+}
+
+define i29 @test7(i8 %X) {
+ %A = zext i8 %X to i29 ; <i29> [#uses=1]
+ %B = ashr i29 -1, %A ; <i29> [#uses=1]
+ ret i29 %B
+}
+
+define i7 @test8(i7 %A) {
+ %B = shl i7 %A, 4 ; <i7> [#uses=1]
+ %C = shl i7 %B, 3 ; <i7> [#uses=1]
+ ret i7 %C
+}
+
+define i17 @test9(i17 %A) {
+ %B = shl i17 %A, 16 ; <i17> [#uses=1]
+ %C = lshr i17 %B, 16 ; <i17> [#uses=1]
+ ret i17 %C
+}
+
+define i19 @test10(i19 %A) {
+ %B = lshr i19 %A, 18 ; <i19> [#uses=1]
+ %C = shl i19 %B, 18 ; <i19> [#uses=1]
+ ret i19 %C
+}
+
+define i23 @test11(i23 %A) {
+ %a = mul i23 %A, 3 ; <i23> [#uses=1]
+ %B = lshr i23 %a, 11 ; <i23> [#uses=1]
+ %C = shl i23 %B, 12 ; <i23> [#uses=1]
+ ret i23 %C
+}
+
+define i47 @test12(i47 %A) {
+ %B = ashr i47 %A, 8 ; <i47> [#uses=1]
+ %C = shl i47 %B, 8 ; <i47> [#uses=1]
+ ret i47 %C
+}
+
+define i18 @test13(i18 %A) {
+ %a = mul i18 %A, 3 ; <i18> [#uses=1]
+ %B = ashr i18 %a, 8 ; <i18> [#uses=1]
+ %C = shl i18 %B, 9 ; <i18> [#uses=1]
+ ret i18 %C
+}
+
+define i35 @test14(i35 %A) {
+ %B = lshr i35 %A, 4 ; <i35> [#uses=1]
+ %C = or i35 %B, 1234 ; <i35> [#uses=1]
+ %D = shl i35 %C, 4 ; <i35> [#uses=1]
+ ret i35 %D
+}
+
+define i79 @test14a(i79 %A) {
+ %B = shl i79 %A, 4 ; <i79> [#uses=1]
+ %C = and i79 %B, 1234 ; <i79> [#uses=1]
+ %D = lshr i79 %C, 4 ; <i79> [#uses=1]
+ ret i79 %D
+}
+
+define i45 @test15(i1 %C) {
+ %A = select i1 %C, i45 3, i45 1 ; <i45> [#uses=1]
+ %V = shl i45 %A, 2 ; <i45> [#uses=1]
+ ret i45 %V
+}
+
+define i53 @test15a(i1 %X) {
+ %A = select i1 %X, i8 3, i8 1 ; <i8> [#uses=1]
+ %B = zext i8 %A to i53 ; <i53> [#uses=1]
+ %V = shl i53 64, %B ; <i53> [#uses=1]
+ ret i53 %V
+}
+
+define i1 @test16(i84 %X) {
+ %tmp.3 = ashr i84 %X, 4 ; <i84> [#uses=1]
+ %tmp.6 = and i84 %tmp.3, 1 ; <i84> [#uses=1]
+ %tmp.7 = icmp ne i84 %tmp.6, 0 ; <i1> [#uses=1]
+ ret i1 %tmp.7
+}
+
+define i1 @test17(i106 %A) {
+ %B = lshr i106 %A, 3 ; <i106> [#uses=1]
+ %C = icmp eq i106 %B, 1234 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test18(i11 %A) {
+ %B = lshr i11 %A, 10 ; <i11> [#uses=1]
+ %C = icmp eq i11 %B, 123 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test19(i37 %A) {
+ %B = ashr i37 %A, 2 ; <i37> [#uses=1]
+ %C = icmp eq i37 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test19a(i39 %A) {
+ %B = ashr i39 %A, 2 ; <i39> [#uses=1]
+ %C = icmp eq i39 %B, -1 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test20(i13 %A) {
+ %B = ashr i13 %A, 12 ; <i13> [#uses=1]
+ %C = icmp eq i13 %B, 123 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test21(i12 %A) {
+ %B = shl i12 %A, 6 ; <i12> [#uses=1]
+ %C = icmp eq i12 %B, -128 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test22(i14 %A) {
+ %B = shl i14 %A, 7 ; <i14> [#uses=1]
+ %C = icmp eq i14 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i11 @test23(i44 %A) {
+ %B = shl i44 %A, 33 ; <i44> [#uses=1]
+ %C = ashr i44 %B, 33 ; <i44> [#uses=1]
+ %D = trunc i44 %C to i11 ; <i8> [#uses=1]
+ ret i11 %D
+}
+
+define i37 @test25(i37 %tmp.2, i37 %AA) {
+ %x = lshr i37 %AA, 17 ; <i37> [#uses=1]
+ %tmp.3 = lshr i37 %tmp.2, 17 ; <i37> [#uses=1]
+ %tmp.5 = add i37 %tmp.3, %x ; <i37> [#uses=1]
+ %tmp.6 = shl i37 %tmp.5, 17 ; <i37> [#uses=1]
+ ret i37 %tmp.6
+}
+
+define i40 @test26(i40 %A) {
+ %B = lshr i40 %A, 1 ; <i40> [#uses=1]
+ %C = bitcast i40 %B to i40 ; <i40> [#uses=1]
+ %D = shl i40 %C, 1 ; <i40> [#uses=1]
+ ret i40 %D
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-shl-trunc.ll b/src/LLVM/test/Transforms/InstCombine/apint-shl-trunc.ll
new file mode 100644
index 0000000..40efb83
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-shl-trunc.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep shl
+; END.
+
+define i1 @test0(i39 %X, i39 %A) {
+ %B = lshr i39 %X, %A
+ %D = trunc i39 %B to i1
+ ret i1 %D
+}
+
+define i1 @test1(i799 %X, i799 %A) {
+ %B = lshr i799 %X, %A
+ %D = trunc i799 %B to i1
+ ret i1 %D
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-sub.ll b/src/LLVM/test/Transforms/InstCombine/apint-sub.ll
new file mode 100644
index 0000000..ade1688
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-sub.ll
@@ -0,0 +1,141 @@
+; This test makes sure that sub instructions are properly eliminated
+; even with arbitrary precision integers.
+;
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v {sub i19 %Cok, %Bok} | grep -v {sub i25 0, %Aok} | not grep sub
+; END.
+
+define i23 @test1(i23 %A) {
+ %B = sub i23 %A, %A ; <i23> [#uses=1]
+ ret i23 %B
+}
+
+define i47 @test2(i47 %A) {
+ %B = sub i47 %A, 0 ; <i47> [#uses=1]
+ ret i47 %B
+}
+
+define i97 @test3(i97 %A) {
+ %B = sub i97 0, %A ; <i97> [#uses=1]
+ %C = sub i97 0, %B ; <i97> [#uses=1]
+ ret i97 %C
+}
+
+define i108 @test4(i108 %A, i108 %x) {
+ %B = sub i108 0, %A ; <i108> [#uses=1]
+ %C = sub i108 %x, %B ; <i108> [#uses=1]
+ ret i108 %C
+}
+
+define i19 @test5(i19 %A, i19 %Bok, i19 %Cok) {
+ %D = sub i19 %Bok, %Cok ; <i19> [#uses=1]
+ %E = sub i19 %A, %D ; <i19> [#uses=1]
+ ret i19 %E
+}
+
+define i57 @test6(i57 %A, i57 %B) {
+ %C = and i57 %A, %B ; <i57> [#uses=1]
+ %D = sub i57 %A, %C ; <i57> [#uses=1]
+ ret i57 %D
+}
+
+define i77 @test7(i77 %A) {
+ %B = sub i77 -1, %A ; <i77> [#uses=1]
+ ret i77 %B
+}
+
+define i27 @test8(i27 %A) {
+ %B = mul i27 9, %A ; <i27> [#uses=1]
+ %C = sub i27 %B, %A ; <i27> [#uses=1]
+ ret i27 %C
+}
+
+define i42 @test9(i42 %A) {
+ %B = mul i42 3, %A ; <i42> [#uses=1]
+ %C = sub i42 %A, %B ; <i42> [#uses=1]
+ ret i42 %C
+}
+
+define i124 @test10(i124 %A, i124 %B) {
+ %C = sub i124 0, %A ; <i124> [#uses=1]
+ %D = sub i124 0, %B ; <i124> [#uses=1]
+ %E = mul i124 %C, %D ; <i124> [#uses=1]
+ ret i124 %E
+}
+
+define i55 @test10a(i55 %A) {
+ %C = sub i55 0, %A ; <i55> [#uses=1]
+ %E = mul i55 %C, 7 ; <i55> [#uses=1]
+ ret i55 %E
+}
+
+define i1 @test11(i9 %A, i9 %B) {
+ %C = sub i9 %A, %B ; <i9> [#uses=1]
+ %cD = icmp ne i9 %C, 0 ; <i1> [#uses=1]
+ ret i1 %cD
+}
+
+define i43 @test12(i43 %A) {
+ %B = ashr i43 %A, 42 ; <i43> [#uses=1]
+ %C = sub i43 0, %B ; <i43> [#uses=1]
+ ret i43 %C
+}
+
+define i79 @test13(i79 %A) {
+ %B = lshr i79 %A, 78 ; <i79> [#uses=1]
+ %C = sub i79 0, %B ; <i79> [#uses=1]
+ ret i79 %C
+}
+
+define i1024 @test14(i1024 %A) {
+ %B = lshr i1024 %A, 1023 ; <i1024> [#uses=1]
+ %C = bitcast i1024 %B to i1024 ; <i1024> [#uses=1]
+ %D = sub i1024 0, %C ; <i1024> [#uses=1]
+ ret i1024 %D
+}
+
+define i14 @test15(i14 %A, i14 %B) {
+ %C = sub i14 0, %A ; <i14> [#uses=1]
+ %D = srem i14 %B, %C ; <i14> [#uses=1]
+ ret i14 %D
+}
+
+define i51 @test16(i51 %A) {
+ %X = sdiv i51 %A, 1123 ; <i51> [#uses=1]
+ %Y = sub i51 0, %X ; <i51> [#uses=1]
+ ret i51 %Y
+}
+
+; Can't fold subtract here because negation it might oveflow.
+; PR3142
+define i25 @test17(i25 %Aok) {
+ %B = sub i25 0, %Aok ; <i25> [#uses=1]
+ %C = sdiv i25 %B, 1234 ; <i25> [#uses=1]
+ ret i25 %C
+}
+
+define i128 @test18(i128 %Y) {
+ %tmp.4 = shl i128 %Y, 2 ; <i128> [#uses=1]
+ %tmp.12 = shl i128 %Y, 2 ; <i128> [#uses=1]
+ %tmp.8 = sub i128 %tmp.4, %tmp.12 ; <i128> [#uses=1]
+ ret i128 %tmp.8
+}
+
+define i39 @test19(i39 %X, i39 %Y) {
+ %Z = sub i39 %X, %Y ; <i39> [#uses=1]
+ %Q = add i39 %Z, %Y ; <i39> [#uses=1]
+ ret i39 %Q
+}
+
+define i1 @test20(i33 %g, i33 %h) {
+ %tmp.2 = sub i33 %g, %h ; <i33> [#uses=1]
+ %tmp.4 = icmp ne i33 %tmp.2, %g ; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
+
+define i1 @test21(i256 %g, i256 %h) {
+ %tmp.2 = sub i256 %g, %h ; <i256> [#uses=1]
+ %tmp.4 = icmp ne i256 %tmp.2, %g; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-xor1.ll b/src/LLVM/test/Transforms/InstCombine/apint-xor1.ll
new file mode 100644
index 0000000..33a6ef4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-xor1.ll
@@ -0,0 +1,50 @@
+; This test makes sure that xor instructions are properly eliminated.
+; This test is for Integer BitWidth <= 64 && BitWidth % 8 != 0.
+
+; RUN: opt < %s -instcombine -S | not grep {xor }
+
+
+define i47 @test1(i47 %A, i47 %B) {
+ ;; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
+ %A1 = and i47 %A, 70368744177664
+ %B1 = and i47 %B, 70368744177661
+ %C1 = xor i47 %A1, %B1
+ ret i47 %C1
+}
+
+define i15 @test2(i15 %x) {
+ %tmp.2 = xor i15 %x, 0
+ ret i15 %tmp.2
+}
+
+define i23 @test3(i23 %x) {
+ %tmp.2 = xor i23 %x, %x
+ ret i23 %tmp.2
+}
+
+define i37 @test4(i37 %x) {
+ ; x ^ ~x == -1
+ %NotX = xor i37 -1, %x
+ %B = xor i37 %x, %NotX
+ ret i37 %B
+}
+
+define i7 @test5(i7 %A) {
+ ;; (A|B)^B == A & (~B)
+ %t1 = or i7 %A, 23
+ %r = xor i7 %t1, 23
+ ret i7 %r
+}
+
+define i7 @test6(i7 %A) {
+ %t1 = xor i7 %A, 23
+ %r = xor i7 %t1, 23
+ ret i7 %r
+}
+
+define i47 @test7(i47 %A) {
+ ;; (A | C1) ^ C2 -> (A | C1) & ~C2 iff (C1&C2) == C2
+ %B1 = or i47 %A, 70368744177663
+ %C1 = xor i47 %B1, 703687463
+ ret i47 %C1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-xor2.ll b/src/LLVM/test/Transforms/InstCombine/apint-xor2.ll
new file mode 100644
index 0000000..28ed9e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-xor2.ll
@@ -0,0 +1,51 @@
+; This test makes sure that xor instructions are properly eliminated.
+; This test is for Integer BitWidth > 64 && BitWidth <= 1024.
+
+; RUN: opt < %s -instcombine -S | not grep {xor }
+; END.
+
+
+define i447 @test1(i447 %A, i447 %B) {
+ ;; (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
+ %A1 = and i447 %A, 70368744177664
+ %B1 = and i447 %B, 70368744177663
+ %C1 = xor i447 %A1, %B1
+ ret i447 %C1
+}
+
+define i1005 @test2(i1005 %x) {
+ %tmp.2 = xor i1005 %x, 0
+ ret i1005 %tmp.2
+}
+
+define i123 @test3(i123 %x) {
+ %tmp.2 = xor i123 %x, %x
+ ret i123 %tmp.2
+}
+
+define i737 @test4(i737 %x) {
+ ; x ^ ~x == -1
+ %NotX = xor i737 -1, %x
+ %B = xor i737 %x, %NotX
+ ret i737 %B
+}
+
+define i700 @test5(i700 %A) {
+ ;; (A|B)^B == A & (~B)
+ %t1 = or i700 %A, 288230376151711743
+ %r = xor i700 %t1, 288230376151711743
+ ret i700 %r
+}
+
+define i77 @test6(i77 %A) {
+ %t1 = xor i77 %A, 23
+ %r = xor i77 %t1, 23
+ ret i77 %r
+}
+
+define i1023 @test7(i1023 %A) {
+ ;; (A | C1) ^ C2 -> (A | C1) & ~C2 iff (C1&C2) == C2
+ %B1 = or i1023 %A, 70368744177663
+ %C1 = xor i1023 %B1, 703687463
+ ret i1023 %C1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-zext1.ll b/src/LLVM/test/Transforms/InstCombine/apint-zext1.ll
new file mode 100644
index 0000000..a05470c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-zext1.ll
@@ -0,0 +1,11 @@
+; Tests to make sure elimination of casts is working correctly
+; This test is for Integer BitWidth <= 64 && BitWidth % 2 != 0.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i47 @test_sext_zext(i11 %A) {
+ %c1 = zext i11 %A to i39
+ %c2 = sext i39 %c1 to i47
+ ret i47 %c2
+; CHECK: %c2 = zext i11 %A to i47
+; CHECK: ret i47 %c2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/apint-zext2.ll b/src/LLVM/test/Transforms/InstCombine/apint-zext2.ll
new file mode 100644
index 0000000..94b9ca9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/apint-zext2.ll
@@ -0,0 +1,11 @@
+; Tests to make sure elimination of casts is working correctly
+; This test is for Integer BitWidth > 64 && BitWidth <= 1024.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i1024 @test_sext_zext(i77 %A) {
+ %c1 = zext i77 %A to i533
+ %c2 = sext i533 %c1 to i1024
+ ret i1024 %c2
+; CHECK: %c2 = zext i77 %A to i1024
+; CHECK: ret i1024 %c2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/ashr-nop.ll b/src/LLVM/test/Transforms/InstCombine/ashr-nop.ll
new file mode 100644
index 0000000..870ede3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/ashr-nop.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | not grep ashr
+
+define i32 @foo(i32 %x) {
+ %o = and i32 %x, 1
+ %n = add i32 %o, -1
+ %t = ashr i32 %n, 17
+ ret i32 %t
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/atomic.ll b/src/LLVM/test/Transforms/InstCombine/atomic.ll
new file mode 100644
index 0000000..097cf5e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/atomic.ll
@@ -0,0 +1,24 @@
+; RUN: opt -S < %s -instcombine | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+; Check transforms involving atomic operations
+
+define i32* @test1(i8** %p) {
+; CHECK: define i32* @test1
+; CHECK: load atomic i8** %p monotonic, align 8
+ %c = bitcast i8** %p to i32**
+ %r = load atomic i32** %c monotonic, align 8
+ ret i32* %r
+}
+
+define i32 @test2(i32* %p) {
+; CHECK: define i32 @test2
+; CHECK: %x = load atomic i32* %p seq_cst, align 4
+; CHECK: shl i32 %x, 1
+ %x = load atomic i32* %p seq_cst, align 4
+ %y = load i32* %p, align 4
+ %z = add i32 %x, %y
+ ret i32 %z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/badmalloc.ll b/src/LLVM/test/Transforms/InstCombine/badmalloc.ll
new file mode 100644
index 0000000..f5a623d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/badmalloc.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+
+declare noalias i8* @malloc(i64) nounwind
+declare void @free(i8*)
+
+; PR5130
+define i1 @test1() {
+ %A = call noalias i8* @malloc(i64 4) nounwind
+ %B = icmp eq i8* %A, null
+ store i8 0, i8* %A
+
+ call void @free(i8* %A)
+ ret i1 %B
+
+; CHECK: @test1
+; CHECK: ret i1 %B
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/binop-cast.ll b/src/LLVM/test/Transforms/InstCombine/binop-cast.ll
new file mode 100644
index 0000000..27b544d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/binop-cast.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @testAdd(i32 %X, i32 %Y) {
+ %tmp = add i32 %X, %Y
+; CHECK: %tmp = add i32 %X, %Y
+ %tmp.l = bitcast i32 %tmp to i32
+ ret i32 %tmp.l
+; CHECK: ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bit-checks.ll b/src/LLVM/test/Transforms/InstCombine/bit-checks.ll
new file mode 100644
index 0000000..79a096f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bit-checks.ll
@@ -0,0 +1,372 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep {tobool}
+; END.
+define i32 @main(i32 %argc, i8** %argv) nounwind ssp {
+entry:
+ %and = and i32 %argc, 1 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 2 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %retval.0 = select i1 %or.cond, i32 2, i32 1 ; <i32> [#uses=1]
+ ret i32 %retval.0
+}
+
+define i32 @main2(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 1 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 2 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; tests to check combining (icmp eq (A & B), C) & (icmp eq (A & D), E)
+; tests to check if (icmp eq (A & B), 0) is treated like (icmp eq (A & B), B)
+; if B is a single bit constant
+
+; (icmp eq (A & B), 0) & (icmp eq (A & D), 0) -> (icmp eq (A & (B|D)), 0)
+define i32 @main3(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 0 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main3b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 16 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main3e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 0 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp ne (A & B), 0) | (icmp ne (A & D), 0) -> (icmp ne (A & (B|D)), 0)
+define i32 @main3c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main3d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 16 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main3f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp eq (A & B), B) & (icmp eq (A & D), D) -> (icmp eq (A & (B|D)), (B|D))
+define i32 @main4(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 48 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main4b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 0 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main4e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, %argc2 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, %argc3 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp ne (A & B), B) | (icmp ne (A & D), D) -> (icmp ne (A & (B|D)), (B|D))
+define i32 @main4c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 48 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main4d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main4f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, %argc2 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, %argc3 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp eq (A & B), A) & (icmp eq (A & D), A) -> (icmp eq (A & (B&D)), A)
+define i32 @main5_like(i32 %argc, i32 %argc2, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc2, 7 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 7 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main5e_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, %argc ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, %argc ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp ne (A & B), A) | (icmp ne (A & D), A) -> (icmp ne (A & (B&D)), A)
+define i32 @main5c_like(i32 %argc, i32 %argc2, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 7 ; <i1> [#uses=1]
+ %and2 = and i32 %argc2, 7 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 7 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main5f_like(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, %argc ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, %argc ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp eq (A & B), C) & (icmp eq (A & D), E) -> (icmp eq (A & (B|D)), (C|E))
+; if B, C, D, E are constant, and it's possible
+define i32 @main6(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 3 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 16 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main6b(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and, 3 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 0 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (icmp ne (A & B), C) | (icmp ne (A & D), E) -> (icmp ne (A & (B|D)), (C|E))
+; if B, C, D, E are constant, and it's possible
+define i32 @main6c(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 3 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 48 ; <i32> [#uses=1]
+ %tobool3 = icmp ne i32 %and2, 16 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @main6d(i32 %argc, i8** nocapture %argv) nounwind readnone ssp {
+entry:
+ %and = and i32 %argc, 7 ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %and, 3 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, 16 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, 0 ; <i1> [#uses=1]
+ %or.cond = or i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %or.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; test parameter permutations
+; (B & A) == B & (D & A) == D
+define i32 @main7a(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and1 = and i32 %argc2, %argc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and1, %argc2 ; <i1> [#uses=1]
+ %and2 = and i32 %argc3, %argc ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, %argc3 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; B == (A & B) & D == (A & D)
+define i32 @main7b(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and1 = and i32 %argc, %argc2 ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %argc2, %and1 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %argc3 ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %argc3, %and2 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; B == (B & A) & D == (D & A)
+define i32 @main7c(i32 %argc, i32 %argc2, i32 %argc3, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %and1 = and i32 %argc2, %argc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %argc2, %and1 ; <i1> [#uses=1]
+ %and2 = and i32 %argc3, %argc ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %argc3, %and2 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (A & (B & C)) == (B & C) & (A & (D & E)) == (D & E)
+define i32 @main7d(i32 %argc, i32 %argc2, i32 %argc3,
+ i32 %argc4, i32 %argc5, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %bc = and i32 %argc2, %argc4 ; <i32> [#uses=1]
+ %de = and i32 %argc3, %argc5 ; <i32> [#uses=1]
+ %and1 = and i32 %argc, %bc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and1, %bc ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %de ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, %de ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; ((B & C) & A) == (B & C) & ((D & E) & A) == (D & E)
+define i32 @main7e(i32 %argc, i32 %argc2, i32 %argc3,
+ i32 %argc4, i32 %argc5, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %bc = and i32 %argc2, %argc4 ; <i32> [#uses=1]
+ %de = and i32 %argc3, %argc5 ; <i32> [#uses=1]
+ %and1 = and i32 %bc, %argc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %and1, %bc ; <i1> [#uses=1]
+ %and2 = and i32 %de, %argc ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %and2, %de ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (B & C) == (A & (B & C)) & (D & E) == (A & (D & E))
+define i32 @main7f(i32 %argc, i32 %argc2, i32 %argc3,
+ i32 %argc4, i32 %argc5, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %bc = and i32 %argc2, %argc4 ; <i32> [#uses=1]
+ %de = and i32 %argc3, %argc5 ; <i32> [#uses=1]
+ %and1 = and i32 %argc, %bc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %bc, %and1 ; <i1> [#uses=1]
+ %and2 = and i32 %argc, %de ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %de, %and2 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+; (B & C) == ((B & C) & A) & (D & E) == ((D & E) & A)
+define i32 @main7g(i32 %argc, i32 %argc2, i32 %argc3,
+ i32 %argc4, i32 %argc5, i8** nocapture %argv)
+ nounwind readnone ssp {
+entry:
+ %bc = and i32 %argc2, %argc4 ; <i32> [#uses=1]
+ %de = and i32 %argc3, %argc5 ; <i32> [#uses=1]
+ %and1 = and i32 %bc, %argc ; <i32> [#uses=1]
+ %tobool = icmp eq i32 %bc, %and1 ; <i1> [#uses=1]
+ %and2 = and i32 %de, %argc ; <i32> [#uses=1]
+ %tobool3 = icmp eq i32 %de, %and2 ; <i1> [#uses=1]
+ %and.cond = and i1 %tobool, %tobool3 ; <i1> [#uses=1]
+ %storemerge = select i1 %and.cond, i32 0, i32 1 ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bit-tracking.ll b/src/LLVM/test/Transforms/InstCombine/bit-tracking.ll
new file mode 100644
index 0000000..755fc4d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bit-tracking.ll
@@ -0,0 +1,26 @@
+; This file contains various testcases that require tracking whether bits are
+; set or cleared by various instructions.
+; RUN: opt < %s -instcombine -instcombine -S |\
+; RUN: not grep %ELIM
+
+; Reduce down to a single XOR
+define i32 @test3(i32 %B) {
+ %ELIMinc = and i32 %B, 1 ; <i32> [#uses=1]
+ %tmp.5 = xor i32 %ELIMinc, 1 ; <i32> [#uses=1]
+ %ELIM7 = and i32 %B, -2 ; <i32> [#uses=1]
+ %tmp.8 = or i32 %tmp.5, %ELIM7 ; <i32> [#uses=1]
+ ret i32 %tmp.8
+}
+
+; Finally, a bigger case where we chain things together. This corresponds to
+; incrementing a single-bit bitfield, which should become just an xor.
+define i32 @test4(i32 %B) {
+ %ELIM3 = shl i32 %B, 31 ; <i32> [#uses=1]
+ %ELIM4 = ashr i32 %ELIM3, 31 ; <i32> [#uses=1]
+ %inc = add i32 %ELIM4, 1 ; <i32> [#uses=1]
+ %ELIM5 = and i32 %inc, 1 ; <i32> [#uses=1]
+ %ELIM7 = and i32 %B, -2 ; <i32> [#uses=1]
+ %tmp.8 = or i32 %ELIM5, %ELIM7 ; <i32> [#uses=1]
+ ret i32 %tmp.8
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast-sext-vector.ll b/src/LLVM/test/Transforms/InstCombine/bitcast-sext-vector.ll
new file mode 100644
index 0000000..d70bdba
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast-sext-vector.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; CHECK: sext
+; Don't fold zero/sign extensions with a bitcast between a vector and scalar.
+
+define i32 @t(<4 x i8> %src1, <4 x i8> %src2) nounwind readonly {
+entry:
+ %cmp = icmp eq <4 x i8> %src1, %src2; <<4 x i1>> [#uses=1]
+ %sext = sext <4 x i1> %cmp to <4 x i8>
+ %val = bitcast <4 x i8> %sext to i32
+ ret i32 %val
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast-store.ll b/src/LLVM/test/Transforms/InstCombine/bitcast-store.ll
new file mode 100644
index 0000000..e4a61e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast-store.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+; Instcombine should preserve metadata and alignment while
+; folding a bitcast into a store.
+
+; CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ([5 x i8*]* @G, i64 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 16, !tag !0
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+%struct.A = type { i32 (...)** }
+
+@G = external constant [5 x i8*]
+
+define void @foo(%struct.A* %a) nounwind {
+entry:
+ %0 = bitcast %struct.A* %a to i8***
+ store i8** getelementptr inbounds ([5 x i8*]* @G, i64 0, i64 2), i8*** %0, align 16, !tag !0
+ ret void
+}
+
+!0 = metadata !{metadata !"hello"}
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast-vec-canon.ll b/src/LLVM/test/Transforms/InstCombine/bitcast-vec-canon.ll
new file mode 100644
index 0000000..d27765e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast-vec-canon.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -S | grep element | count 4
+
+define double @a(<1 x i64> %y) {
+ %c = bitcast <1 x i64> %y to double
+ ret double %c
+}
+
+define i64 @b(<1 x i64> %y) {
+ %c = bitcast <1 x i64> %y to i64
+ ret i64 %c
+}
+
+define <1 x i64> @c(double %y) {
+ %c = bitcast double %y to <1 x i64>
+ ret <1 x i64> %c
+}
+
+define <1 x i64> @d(i64 %y) {
+ %c = bitcast i64 %y to <1 x i64>
+ ret <1 x i64> %c
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast-vec-uniform.ll b/src/LLVM/test/Transforms/InstCombine/bitcast-vec-uniform.ll
new file mode 100644
index 0000000..2f42d1e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast-vec-uniform.ll
@@ -0,0 +1,70 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; CHECK: @a
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <4 x i32> @a(<1 x i64> %y) {
+ %c = bitcast <2 x i64> <i64 0, i64 0> to <4 x i32>
+ ret <4 x i32> %c
+}
+
+; CHECK: @b
+; CHECK-NOT: bitcast
+; CHECK: ret
+
+define <4 x i32> @b(<1 x i64> %y) {
+ %c = bitcast <2 x i64> <i64 -1, i64 -1> to <4 x i32>
+ ret <4 x i32> %c
+}
+
+; CHECK: @foo
+; CHECK-NOT: bitcast
+; CHECK: ret
+
+; from MultiSource/Benchmarks/Bullet
+define <2 x float> @foo() {
+ %cast = bitcast i64 -1 to <2 x float>
+ ret <2 x float> %cast
+}
+
+
+; CHECK: @foo2
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <2 x double> @foo2() {
+ %cast = bitcast i128 -1 to <2 x double>
+ ret <2 x double> %cast
+}
+
+; CHECK: @foo3
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <1 x float> @foo3() {
+ %cast = bitcast i32 -1 to <1 x float>
+ ret <1 x float> %cast
+}
+
+; CHECK: @foo4
+; CHECK-NOT: bitcast
+; CHECK: ret
+define float @foo4() {
+ %cast = bitcast <1 x i32 ><i32 -1> to float
+ ret float %cast
+}
+
+; CHECK: @foo5
+; CHECK-NOT: bitcast
+; CHECK: ret
+define double @foo5() {
+ %cast = bitcast <2 x i32 ><i32 -1, i32 -1> to double
+ ret double %cast
+}
+
+
+; CHECK: @foo6
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <2 x double> @foo6() {
+ %cast = bitcast <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1> to <2 x double>
+ ret <2 x double> %cast
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast-vector-fold.ll b/src/LLVM/test/Transforms/InstCombine/bitcast-vector-fold.ll
new file mode 100644
index 0000000..8feec22
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast-vector-fold.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -instcombine -S | not grep bitcast
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+
+define <2 x i64> @test1() {
+ %tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x i64>
+ ret <2 x i64> %tmp3
+}
+
+define <4 x i32> @test2() {
+ %tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x i32>
+ ret <4 x i32> %tmp3
+}
+
+define <2 x double> @test3() {
+ %tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x double>
+ ret <2 x double> %tmp3
+}
+
+define <4 x float> @test4() {
+ %tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x float>
+ ret <4 x float> %tmp3
+}
+
+define <2 x i64> @test5() {
+ %tmp3 = bitcast <4 x float> <float 0.0, float 1.0, float 2.0, float 3.0> to <2 x i64>
+ ret <2 x i64> %tmp3
+}
+
+define <4 x i32> @test6() {
+ %tmp3 = bitcast <2 x double> <double 0.5, double 1.0> to <4 x i32>
+ ret <4 x i32> %tmp3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcast.ll b/src/LLVM/test/Transforms/InstCombine/bitcast.ll
new file mode 100644
index 0000000..8f6ae7d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcast.ll
@@ -0,0 +1,139 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; Bitcasts between vectors and scalars are valid.
+; PR4487
+define i32 @test1(i64 %a) {
+ %t1 = bitcast i64 %a to <2 x i32>
+ %t2 = bitcast i64 %a to <2 x i32>
+ %t3 = xor <2 x i32> %t1, %t2
+ %t4 = extractelement <2 x i32> %t3, i32 0
+ ret i32 %t4
+
+; CHECK: @test1
+; CHECK: ret i32 0
+}
+
+; Optimize bitcasts that are extracting low element of vector. This happens
+; because of SRoA.
+; rdar://7892780
+define float @test2(<2 x float> %A, <2 x i32> %B) {
+ %tmp28 = bitcast <2 x float> %A to i64 ; <i64> [#uses=2]
+ %tmp23 = trunc i64 %tmp28 to i32 ; <i32> [#uses=1]
+ %tmp24 = bitcast i32 %tmp23 to float ; <float> [#uses=1]
+
+ %tmp = bitcast <2 x i32> %B to i64
+ %tmp2 = trunc i64 %tmp to i32 ; <i32> [#uses=1]
+ %tmp4 = bitcast i32 %tmp2 to float ; <float> [#uses=1]
+
+ %add = fadd float %tmp24, %tmp4
+ ret float %add
+
+; CHECK: @test2
+; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 0
+; CHECK-NEXT: bitcast <2 x i32> %B to <2 x float>
+; CHECK-NEXT: %tmp4 = extractelement <2 x float> {{.*}}, i32 0
+; CHECK-NEXT: %add = fadd float %tmp24, %tmp4
+; CHECK-NEXT: ret float %add
+}
+
+; Optimize bitcasts that are extracting other elements of a vector. This
+; happens because of SRoA.
+; rdar://7892780
+define float @test3(<2 x float> %A, <2 x i64> %B) {
+ %tmp28 = bitcast <2 x float> %A to i64
+ %tmp29 = lshr i64 %tmp28, 32
+ %tmp23 = trunc i64 %tmp29 to i32
+ %tmp24 = bitcast i32 %tmp23 to float
+
+ %tmp = bitcast <2 x i64> %B to i128
+ %tmp1 = lshr i128 %tmp, 64
+ %tmp2 = trunc i128 %tmp1 to i32
+ %tmp4 = bitcast i32 %tmp2 to float
+
+ %add = fadd float %tmp24, %tmp4
+ ret float %add
+
+; CHECK: @test3
+; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 1
+; CHECK-NEXT: bitcast <2 x i64> %B to <4 x float>
+; CHECK-NEXT: %tmp4 = extractelement <4 x float> {{.*}}, i32 2
+; CHECK-NEXT: %add = fadd float %tmp24, %tmp4
+; CHECK-NEXT: ret float %add
+}
+
+
+define <2 x i32> @test4(i32 %A, i32 %B){
+ %tmp38 = zext i32 %A to i64
+ %tmp32 = zext i32 %B to i64
+ %tmp33 = shl i64 %tmp32, 32
+ %ins35 = or i64 %tmp33, %tmp38
+ %tmp43 = bitcast i64 %ins35 to <2 x i32>
+ ret <2 x i32> %tmp43
+ ; CHECK: @test4
+ ; CHECK-NEXT: insertelement <2 x i32> undef, i32 %A, i32 0
+ ; CHECK-NEXT: insertelement <2 x i32> {{.*}}, i32 %B, i32 1
+ ; CHECK-NEXT: ret <2 x i32>
+
+}
+
+; rdar://8360454
+define <2 x float> @test5(float %A, float %B) {
+ %tmp37 = bitcast float %A to i32
+ %tmp38 = zext i32 %tmp37 to i64
+ %tmp31 = bitcast float %B to i32
+ %tmp32 = zext i32 %tmp31 to i64
+ %tmp33 = shl i64 %tmp32, 32
+ %ins35 = or i64 %tmp33, %tmp38
+ %tmp43 = bitcast i64 %ins35 to <2 x float>
+ ret <2 x float> %tmp43
+ ; CHECK: @test5
+ ; CHECK-NEXT: insertelement <2 x float> undef, float %A, i32 0
+ ; CHECK-NEXT: insertelement <2 x float> {{.*}}, float %B, i32 1
+ ; CHECK-NEXT: ret <2 x float>
+}
+
+define <2 x float> @test6(float %A){
+ %tmp23 = bitcast float %A to i32 ; <i32> [#uses=1]
+ %tmp24 = zext i32 %tmp23 to i64 ; <i64> [#uses=1]
+ %tmp25 = shl i64 %tmp24, 32 ; <i64> [#uses=1]
+ %mask20 = or i64 %tmp25, 1109917696 ; <i64> [#uses=1]
+ %tmp35 = bitcast i64 %mask20 to <2 x float> ; <<2 x float>> [#uses=1]
+ ret <2 x float> %tmp35
+; CHECK: @test6
+; CHECK-NEXT: insertelement <2 x float> <float 4.200000e+01, float undef>, float %A, i32 1
+; CHECK: ret
+}
+
+define i64 @ISPC0(i64 %in) {
+ %out = and i64 %in, xor (i64 bitcast (<4 x i16> <i16 -1, i16 -1, i16 -1, i16 -1> to i64), i64 -1)
+ ret i64 %out
+; CHECK: @ISPC0
+; CHECK: ret i64 0
+}
+
+
+define i64 @Vec2(i64 %in) {
+ %out = and i64 %in, xor (i64 bitcast (<4 x i16> <i16 0, i16 0, i16 0, i16 0> to i64), i64 0)
+ ret i64 %out
+; CHECK: @Vec2
+; CHECK: ret i64 0
+}
+
+define i64 @All11(i64 %in) {
+ %out = and i64 %in, xor (i64 bitcast (<2 x float> bitcast (i64 -1 to <2 x float>) to i64), i64 -1)
+ ret i64 %out
+; CHECK: @All11
+; CHECK: ret i64 0
+}
+
+
+define i32 @All111(i32 %in) {
+ %out = and i32 %in, xor (i32 bitcast (<1 x float> bitcast (i32 -1 to <1 x float>) to i32), i32 -1)
+ ret i32 %out
+; CHECK: @All111
+; CHECK: ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/bitcount.ll b/src/LLVM/test/Transforms/InstCombine/bitcount.ll
new file mode 100644
index 0000000..d46eef5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bitcount.ll
@@ -0,0 +1,19 @@
+; Tests to make sure bit counts of constants are folded
+; RUN: opt < %s -instcombine -S | grep {ret i32 19}
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v declare | not grep llvm.ct
+
+declare i31 @llvm.ctpop.i31(i31 %val)
+declare i32 @llvm.cttz.i32(i32 %val)
+declare i33 @llvm.ctlz.i33(i33 %val)
+
+define i32 @test(i32 %A) {
+ %c1 = call i31 @llvm.ctpop.i31(i31 12415124)
+ %c2 = call i32 @llvm.cttz.i32(i32 87359874)
+ %c3 = call i33 @llvm.ctlz.i33(i33 87359874)
+ %t1 = zext i31 %c1 to i32
+ %t3 = trunc i33 %c3 to i32
+ %r1 = add i32 %t1, %c2
+ %r2 = add i32 %r1, %t3
+ ret i32 %r2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bittest.ll b/src/LLVM/test/Transforms/InstCombine/bittest.ll
new file mode 100644
index 0000000..1f5a427
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bittest.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -instcombine -simplifycfg -S |\
+; RUN: not grep {call void @abort}
+
+@b_rec.0 = external global i32 ; <i32*> [#uses=2]
+
+define void @_Z12h000007_testv(i32* %P) {
+entry:
+ %tmp.2 = load i32* @b_rec.0 ; <i32> [#uses=1]
+ %tmp.9 = or i32 %tmp.2, -989855744 ; <i32> [#uses=2]
+ %tmp.16 = and i32 %tmp.9, -805306369 ; <i32> [#uses=2]
+ %tmp.17 = and i32 %tmp.9, -973078529 ; <i32> [#uses=1]
+ store i32 %tmp.17, i32* @b_rec.0
+ %tmp.17.shrunk = bitcast i32 %tmp.16 to i32 ; <i32> [#uses=1]
+ %tmp.22 = and i32 %tmp.17.shrunk, -1073741824 ; <i32> [#uses=1]
+ %tmp.23 = icmp eq i32 %tmp.22, -1073741824 ; <i1> [#uses=1]
+ br i1 %tmp.23, label %endif.0, label %then.0
+
+then.0: ; preds = %entry
+ tail call void @abort( )
+ unreachable
+
+endif.0: ; preds = %entry
+ %tmp.17.shrunk2 = bitcast i32 %tmp.16 to i32 ; <i32> [#uses=1]
+ %tmp.27.mask = and i32 %tmp.17.shrunk2, 100663295 ; <i32> [#uses=1]
+ store i32 %tmp.27.mask, i32* %P
+ ret void
+}
+
+declare void @abort()
+
diff --git a/src/LLVM/test/Transforms/InstCombine/bswap-fold.ll b/src/LLVM/test/Transforms/InstCombine/bswap-fold.ll
new file mode 100644
index 0000000..52f4a40
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bswap-fold.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -instcombine -S | not grep call.*bswap
+
+define i1 @test1(i16 %tmp2) {
+ %tmp10 = call i16 @llvm.bswap.i16( i16 %tmp2 )
+ %tmp = icmp eq i16 %tmp10, 1
+ ret i1 %tmp
+}
+
+define i1 @test2(i32 %tmp) {
+ %tmp34 = tail call i32 @llvm.bswap.i32( i32 %tmp )
+ %tmp.upgrd.1 = icmp eq i32 %tmp34, 1
+ ret i1 %tmp.upgrd.1
+}
+
+declare i32 @llvm.bswap.i32(i32)
+
+define i1 @test3(i64 %tmp) {
+ %tmp34 = tail call i64 @llvm.bswap.i64( i64 %tmp )
+ %tmp.upgrd.2 = icmp eq i64 %tmp34, 1
+ ret i1 %tmp.upgrd.2
+}
+
+declare i64 @llvm.bswap.i64(i64)
+
+declare i16 @llvm.bswap.i16(i16)
+
+; rdar://5992453
+; A & 255
+define i32 @test4(i32 %a) nounwind {
+entry:
+ %tmp2 = tail call i32 @llvm.bswap.i32( i32 %a )
+ %tmp4 = lshr i32 %tmp2, 24
+ ret i32 %tmp4
+}
+
+; A
+define i32 @test5(i32 %a) nounwind {
+entry:
+ %tmp2 = tail call i32 @llvm.bswap.i32( i32 %a )
+ %tmp4 = tail call i32 @llvm.bswap.i32( i32 %tmp2 )
+ ret i32 %tmp4
+}
+
+; a >> 24
+define i32 @test6(i32 %a) nounwind {
+entry:
+ %tmp2 = tail call i32 @llvm.bswap.i32( i32 %a )
+ %tmp4 = and i32 %tmp2, 255
+ ret i32 %tmp4
+}
+
+; PR5284
+define i16 @test7(i32 %A) {
+ %B = tail call i32 @llvm.bswap.i32(i32 %A) nounwind
+ %C = trunc i32 %B to i16
+ %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
+ ret i16 %D
+}
+
+define i16 @test8(i64 %A) {
+ %B = tail call i64 @llvm.bswap.i64(i64 %A) nounwind
+ %C = trunc i64 %B to i16
+ %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
+ ret i16 %D
+}
+
+; Misc: Fold bswap(undef) to undef.
+define i64 @foo() {
+ %a = call i64 @llvm.bswap.i64(i64 undef)
+ ret i64 %a
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/bswap.ll b/src/LLVM/test/Transforms/InstCombine/bswap.ll
new file mode 100644
index 0000000..9ae1481
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/bswap.ll
@@ -0,0 +1,74 @@
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {call.*llvm.bswap} | count 6
+
+define i32 @test1(i32 %i) {
+ %tmp1 = lshr i32 %i, 24 ; <i32> [#uses=1]
+ %tmp3 = lshr i32 %i, 8 ; <i32> [#uses=1]
+ %tmp4 = and i32 %tmp3, 65280 ; <i32> [#uses=1]
+ %tmp5 = or i32 %tmp1, %tmp4 ; <i32> [#uses=1]
+ %tmp7 = shl i32 %i, 8 ; <i32> [#uses=1]
+ %tmp8 = and i32 %tmp7, 16711680 ; <i32> [#uses=1]
+ %tmp9 = or i32 %tmp5, %tmp8 ; <i32> [#uses=1]
+ %tmp11 = shl i32 %i, 24 ; <i32> [#uses=1]
+ %tmp12 = or i32 %tmp9, %tmp11 ; <i32> [#uses=1]
+ ret i32 %tmp12
+}
+
+define i32 @test2(i32 %arg) {
+ %tmp2 = shl i32 %arg, 24 ; <i32> [#uses=1]
+ %tmp4 = shl i32 %arg, 8 ; <i32> [#uses=1]
+ %tmp5 = and i32 %tmp4, 16711680 ; <i32> [#uses=1]
+ %tmp6 = or i32 %tmp2, %tmp5 ; <i32> [#uses=1]
+ %tmp8 = lshr i32 %arg, 8 ; <i32> [#uses=1]
+ %tmp9 = and i32 %tmp8, 65280 ; <i32> [#uses=1]
+ %tmp10 = or i32 %tmp6, %tmp9 ; <i32> [#uses=1]
+ %tmp12 = lshr i32 %arg, 24 ; <i32> [#uses=1]
+ %tmp14 = or i32 %tmp10, %tmp12 ; <i32> [#uses=1]
+ ret i32 %tmp14
+}
+
+define i16 @test3(i16 %s) {
+ %tmp2 = lshr i16 %s, 8 ; <i16> [#uses=1]
+ %tmp4 = shl i16 %s, 8 ; <i16> [#uses=1]
+ %tmp5 = or i16 %tmp2, %tmp4 ; <i16> [#uses=1]
+ ret i16 %tmp5
+}
+
+define i16 @test4(i16 %s) {
+ %tmp2 = lshr i16 %s, 8 ; <i16> [#uses=1]
+ %tmp4 = shl i16 %s, 8 ; <i16> [#uses=1]
+ %tmp5 = or i16 %tmp4, %tmp2 ; <i16> [#uses=1]
+ ret i16 %tmp5
+}
+
+define i16 @test5(i16 %a) {
+ %tmp = zext i16 %a to i32 ; <i32> [#uses=2]
+ %tmp1 = and i32 %tmp, 65280 ; <i32> [#uses=1]
+ %tmp2 = ashr i32 %tmp1, 8 ; <i32> [#uses=1]
+ %tmp2.upgrd.1 = trunc i32 %tmp2 to i16 ; <i16> [#uses=1]
+ %tmp4 = and i32 %tmp, 255 ; <i32> [#uses=1]
+ %tmp5 = shl i32 %tmp4, 8 ; <i32> [#uses=1]
+ %tmp5.upgrd.2 = trunc i32 %tmp5 to i16 ; <i16> [#uses=1]
+ %tmp.upgrd.3 = or i16 %tmp2.upgrd.1, %tmp5.upgrd.2 ; <i16> [#uses=1]
+ %tmp6 = bitcast i16 %tmp.upgrd.3 to i16 ; <i16> [#uses=1]
+ %tmp6.upgrd.4 = zext i16 %tmp6 to i32 ; <i32> [#uses=1]
+ %retval = trunc i32 %tmp6.upgrd.4 to i16 ; <i16> [#uses=1]
+ ret i16 %retval
+}
+
+; PR2842
+define i32 @test6(i32 %x) nounwind readnone {
+ %tmp = shl i32 %x, 16 ; <i32> [#uses=1]
+ %x.mask = and i32 %x, 65280 ; <i32> [#uses=1]
+ %tmp1 = lshr i32 %x, 16 ; <i32> [#uses=1]
+ %tmp2 = and i32 %tmp1, 255 ; <i32> [#uses=1]
+ %tmp3 = or i32 %x.mask, %tmp ; <i32> [#uses=1]
+ %tmp4 = or i32 %tmp3, %tmp2 ; <i32> [#uses=1]
+ %tmp5 = shl i32 %tmp4, 8 ; <i32> [#uses=1]
+ %tmp6 = lshr i32 %x, 24 ; <i32> [#uses=1]
+ %tmp7 = or i32 %tmp5, %tmp6 ; <i32> [#uses=1]
+ ret i32 %tmp7
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/call-cast-target.ll b/src/LLVM/test/Transforms/InstCombine/call-cast-target.ll
new file mode 100644
index 0000000..47661f1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/call-cast-target.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep call | not grep bitcast
+
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+
+define i32 @main() {
+entry:
+ %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+declare i8* @ctime(i32*)
+
diff --git a/src/LLVM/test/Transforms/InstCombine/call-intrinsics.ll b/src/LLVM/test/Transforms/InstCombine/call-intrinsics.ll
new file mode 100644
index 0000000..4bfc2ce
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/call-intrinsics.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine | llvm-dis
+
+@X = global i8 0 ; <i8*> [#uses=3]
+@Y = global i8 12 ; <i8*> [#uses=2]
+
+declare void @llvm.memmove.i32(i8*, i8*, i32, i32)
+
+declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
+
+declare void @llvm.memset.i32(i8*, i8, i32, i32)
+
+define void @zero_byte_test() {
+ ; These process zero bytes, so they are a noop.
+ call void @llvm.memmove.i32( i8* @X, i8* @Y, i32 0, i32 100 )
+ call void @llvm.memcpy.i32( i8* @X, i8* @Y, i32 0, i32 100 )
+ call void @llvm.memset.i32( i8* @X, i8 123, i32 0, i32 100 )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/call.ll b/src/LLVM/test/Transforms/InstCombine/call.ll
new file mode 100644
index 0000000..55bcac9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/call.ll
@@ -0,0 +1,136 @@
+; Ignore stderr, we expect warnings there
+; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
+
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+; Simple case, argument translatable without changing the value
+declare void @test1a(i8*)
+
+define void @test1(i32* %A) {
+ call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
+ ret void
+; CHECK: %1 = bitcast i32* %A to i8*
+; CHECK: call void @test1a(i8* %1)
+; CHECK: ret void
+}
+
+; More complex case, translate argument because of resolution. This is safe
+; because we have the body of the function
+define void @test2a(i8 %A) {
+ ret void
+; CHECK: ret void
+}
+
+define i32 @test2(i32 %A) {
+ call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
+ ret i32 %A
+; CHECK: %1 = trunc i32 %A to i8
+; CHECK: call void @test2a(i8 %1)
+; CHECK: ret i32 %A
+}
+
+
+; Resolving this should insert a cast from sbyte to int, following the C
+; promotion rules.
+define void @test3a(i8, ...) {unreachable }
+
+define void @test3(i8 %A, i8 %B) {
+ call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B
+)
+ ret void
+; CHECK: %1 = zext i8 %B to i32
+; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1)
+; CHECK: ret void
+}
+
+
+; test conversion of return value...
+define i8 @test4a() {
+ ret i8 0
+; CHECK: ret i8 0
+}
+
+define i32 @test4() {
+ %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
+ ret i32 %X
+; CHECK: %X = call i8 @test4a()
+; CHECK: %1 = zext i8 %X to i32
+; CHECK: ret i32 %1
+}
+
+
+; test conversion of return value... no value conversion occurs so we can do
+; this with just a prototype...
+declare i32 @test5a()
+
+define i32 @test5() {
+ %X = call i32 @test5a( ) ; <i32> [#uses=1]
+ ret i32 %X
+; CHECK: %X = call i32 @test5a()
+; CHECK: ret i32 %X
+}
+
+
+; test addition of new arguments...
+declare i32 @test6a(i32)
+
+define i32 @test6() {
+ %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
+ ret i32 %X
+; CHECK: %X = call i32 @test6a(i32 0)
+; CHECK: ret i32 %X
+}
+
+
+; test removal of arguments, only can happen with a function body
+define void @test7a() {
+ ret void
+; CHECK: ret void
+}
+
+define void @test7() {
+ call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
+ ret void
+; CHECK: call void @test7a()
+; CHECK: ret void
+}
+
+
+; rdar://7590304
+declare void @test8a()
+
+define i8* @test8() {
+ invoke void @test8a()
+ to label %invoke.cont unwind label %try.handler
+
+invoke.cont: ; preds = %entry
+ unreachable
+
+try.handler: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret i8* null
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+; Don't turn this into "unreachable": the callee and caller don't agree in
+; calling conv, but the implementation of test8a may actually end up using the
+; right calling conv.
+; CHECK: @test8() {
+; CHECK-NEXT: invoke void @test8a()
+
+
+
+; Don't turn this into a direct call, because test9x is just a prototype and
+; doing so will make it varargs.
+; rdar://9038601
+declare i8* @test9x(i8*, i8*, ...) noredzone
+define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
+entry:
+ %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
+ ret i8* %call
+; CHECK: @test9(
+; CHECK: call i8* bitcast
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/call2.ll b/src/LLVM/test/Transforms/InstCombine/call2.ll
new file mode 100644
index 0000000..b7af1cd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/call2.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine | llvm-dis
+
+; This used to crash trying to do a double-to-pointer conversion
+define i32 @bar() {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=1]
+ %tmp = call i32 (...)* bitcast (i32 (i8*)* @f to i32 (...)*)( double 3.000000e+00 ) ; <i32> [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval1
+}
+
+define i32 @f(i8* %p) {
+entry:
+ %p_addr = alloca i8* ; <i8**> [#uses=1]
+ %retval = alloca i32, align 4 ; <i32*> [#uses=1]
+ store i8* %p, i8** %p_addr
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/canonicalize_branch.ll b/src/LLVM/test/Transforms/InstCombine/canonicalize_branch.ll
new file mode 100644
index 0000000..56ad5c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/canonicalize_branch.ll
@@ -0,0 +1,69 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Test an already canonical branch to make sure we don't flip those.
+define i32 @test0(i32 %X, i32 %Y) {
+ %C = icmp eq i32 %X, %Y
+ br i1 %C, label %T, label %F, !prof !0
+
+; CHECK: @test0
+; CHECK: %C = icmp eq i32 %X, %Y
+; CHECK: br i1 %C, label %T, label %F
+
+T:
+ ret i32 12
+F:
+ ret i32 123
+}
+
+define i32 @test1(i32 %X, i32 %Y) {
+ %C = icmp ne i32 %X, %Y
+ br i1 %C, label %T, label %F, !prof !1
+
+; CHECK: @test1
+; CHECK: %C = icmp eq i32 %X, %Y
+; CHECK: br i1 %C, label %F, label %T
+
+T:
+ ret i32 12
+F:
+ ret i32 123
+}
+
+define i32 @test2(i32 %X, i32 %Y) {
+ %C = icmp ule i32 %X, %Y
+ br i1 %C, label %T, label %F, !prof !2
+
+; CHECK: @test2
+; CHECK: %C = icmp ugt i32 %X, %Y
+; CHECK: br i1 %C, label %F, label %T
+
+T:
+ ret i32 12
+F:
+ ret i32 123
+}
+
+define i32 @test3(i32 %X, i32 %Y) {
+ %C = icmp uge i32 %X, %Y
+ br i1 %C, label %T, label %F, !prof !3
+
+; CHECK: @test3
+; CHECK: %C = icmp ult i32 %X, %Y
+; CHECK: br i1 %C, label %F, label %T
+
+T:
+ ret i32 12
+F:
+ ret i32 123
+}
+
+!0 = metadata !{metadata !"branch_weights", i32 1, i32 2}
+!1 = metadata !{metadata !"branch_weights", i32 3, i32 4}
+!2 = metadata !{metadata !"branch_weights", i32 5, i32 6}
+!3 = metadata !{metadata !"branch_weights", i32 7, i32 8}
+; Base case shouldn't change.
+; CHECK: !0 = {{.*}} i32 1, i32 2}
+; Ensure that the branch metadata is reversed to match the reversals above.
+; CHECK: !1 = {{.*}} i32 4, i32 3}
+; CHECK: !2 = {{.*}} i32 6, i32 5}
+; CHECK: !3 = {{.*}} i32 8, i32 7}
diff --git a/src/LLVM/test/Transforms/InstCombine/cast-mul-select.ll b/src/LLVM/test/Transforms/InstCombine/cast-mul-select.ll
new file mode 100644
index 0000000..f55423c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/cast-mul-select.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32"
+
+define i32 @mul(i32 %x, i32 %y) {
+ %A = trunc i32 %x to i8
+ %B = trunc i32 %y to i8
+ %C = mul i8 %A, %B
+ %D = zext i8 %C to i32
+ ret i32 %D
+; CHECK: %C = mul i32 %x, %y
+; CHECK: %D = and i32 %C, 255
+; CHECK: ret i32 %D
+}
+
+define i32 @select1(i1 %cond, i32 %x, i32 %y, i32 %z) {
+ %A = trunc i32 %x to i8
+ %B = trunc i32 %y to i8
+ %C = trunc i32 %z to i8
+ %D = add i8 %A, %B
+ %E = select i1 %cond, i8 %C, i8 %D
+ %F = zext i8 %E to i32
+ ret i32 %F
+; CHECK: %D = add i32 %x, %y
+; CHECK: %E = select i1 %cond, i32 %z, i32 %D
+; CHECK: %F = and i32 %E, 255
+; CHECK: ret i32 %F
+}
+
+define i8 @select2(i1 %cond, i8 %x, i8 %y, i8 %z) {
+ %A = zext i8 %x to i32
+ %B = zext i8 %y to i32
+ %C = zext i8 %z to i32
+ %D = add i32 %A, %B
+ %E = select i1 %cond, i32 %C, i32 %D
+ %F = trunc i32 %E to i8
+ ret i8 %F
+; CHECK: %D = add i8 %x, %y
+; CHECK: %E = select i1 %cond, i8 %z, i8 %D
+; CHECK: ret i8 %E
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/cast-set.ll b/src/LLVM/test/Transforms/InstCombine/cast-set.ll
new file mode 100644
index 0000000..a0b4aea
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/cast-set.ll
@@ -0,0 +1,65 @@
+; This tests for various complex cast elimination cases instcombine should
+; handle.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i1 @test1(i32 %X) {
+ %A = bitcast i32 %X to i32 ; <i32> [#uses=1]
+ ; Convert to setne int %X, 12
+ %c = icmp ne i32 %A, 12 ; <i1> [#uses=1]
+ ret i1 %c
+; CHECK: %c = icmp ne i32 %X, 12
+; CHECK: ret i1 %c
+}
+
+define i1 @test2(i32 %X, i32 %Y) {
+ %A = bitcast i32 %X to i32 ; <i32> [#uses=1]
+ %B = bitcast i32 %Y to i32 ; <i32> [#uses=1]
+ ; Convert to setne int %X, %Y
+ %c = icmp ne i32 %A, %B ; <i1> [#uses=1]
+ ret i1 %c
+; CHECK: %c = icmp ne i32 %X, %Y
+; CHECK: ret i1 %c
+}
+
+define i32 @test4(i32 %A) {
+ %B = bitcast i32 %A to i32 ; <i32> [#uses=1]
+ %C = shl i32 %B, 2 ; <i32> [#uses=1]
+ %D = bitcast i32 %C to i32 ; <i32> [#uses=1]
+ ret i32 %D
+; CHECK: %C = shl i32 %A, 2
+; CHECK: ret i32 %C
+}
+
+define i16 @test5(i16 %A) {
+ %B = sext i16 %A to i32 ; <i32> [#uses=1]
+ %C = and i32 %B, 15 ; <i32> [#uses=1]
+ %D = trunc i32 %C to i16 ; <i16> [#uses=1]
+ ret i16 %D
+; CHECK: %C = and i16 %A, 15
+; CHECK: ret i16 %C
+}
+
+define i1 @test6(i1 %A) {
+ %B = zext i1 %A to i32 ; <i32> [#uses=1]
+ %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 %A
+}
+
+define i1 @test6a(i1 %A) {
+ %B = zext i1 %A to i32 ; <i32> [#uses=1]
+ %C = icmp ne i32 %B, -1 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @test7(i8* %A) {
+ %B = bitcast i8* %A to i32* ; <i32*> [#uses=1]
+ %C = icmp eq i32* %B, null ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: %C = icmp eq i8* %A, null
+; CHECK: ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/cast.ll b/src/LLVM/test/Transforms/InstCombine/cast.ll
new file mode 100644
index 0000000..e5a5b1a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/cast.ll
@@ -0,0 +1,679 @@
+; Tests to make sure elimination of casts is working correctly
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64"
+
+@inbuf = external global [32832 x i8] ; <[32832 x i8]*> [#uses=1]
+
+define i32 @test1(i32 %A) {
+ %c1 = bitcast i32 %A to i32 ; <i32> [#uses=1]
+ %c2 = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
+ ret i32 %c2
+; CHECK: ret i32 %A
+}
+
+define i64 @test2(i8 %A) {
+ %c1 = zext i8 %A to i16 ; <i16> [#uses=1]
+ %c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
+ %Ret = zext i32 %c2 to i64 ; <i64> [#uses=1]
+ ret i64 %Ret
+; CHECK: %Ret = zext i8 %A to i64
+; CHECK: ret i64 %Ret
+}
+
+; This function should just use bitwise AND
+define i64 @test3(i64 %A) {
+ %c1 = trunc i64 %A to i8 ; <i8> [#uses=1]
+ %c2 = zext i8 %c1 to i64 ; <i64> [#uses=1]
+ ret i64 %c2
+; CHECK: %c2 = and i64 %A, 255
+; CHECK: ret i64 %c2
+}
+
+define i32 @test4(i32 %A, i32 %B) {
+ %COND = icmp slt i32 %A, %B ; <i1> [#uses=1]
+ ; Booleans are unsigned integrals
+ %c = zext i1 %COND to i8 ; <i8> [#uses=1]
+ ; for the cast elim purpose
+ %result = zext i8 %c to i32 ; <i32> [#uses=1]
+ ret i32 %result
+; CHECK: %COND = icmp slt i32 %A, %B
+; CHECK: %result = zext i1 %COND to i32
+; CHECK: ret i32 %result
+}
+
+define i32 @test5(i1 %B) {
+ ; This cast should get folded into
+ %c = zext i1 %B to i8 ; <i8> [#uses=1]
+ ; this cast
+ %result = zext i8 %c to i32 ; <i32> [#uses=1]
+ ret i32 %result
+; CHECK: %result = zext i1 %B to i32
+; CHECK: ret i32 %result
+}
+
+define i32 @test6(i64 %A) {
+ %c1 = trunc i64 %A to i32 ; <i32> [#uses=1]
+ %res = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
+ ret i32 %res
+; CHECK: trunc i64 %A to i32
+; CHECK-NEXT: ret i32
+}
+
+define i64 @test7(i1 %A) {
+ %c1 = zext i1 %A to i32 ; <i32> [#uses=1]
+ %res = sext i32 %c1 to i64 ; <i64> [#uses=1]
+ ret i64 %res
+; CHECK: %res = zext i1 %A to i64
+; CHECK: ret i64 %res
+}
+
+define i64 @test8(i8 %A) {
+ %c1 = sext i8 %A to i64 ; <i64> [#uses=1]
+ %res = bitcast i64 %c1 to i64 ; <i64> [#uses=1]
+ ret i64 %res
+; CHECK: = sext i8 %A to i64
+; CHECK-NEXT: ret i64
+}
+
+define i16 @test9(i16 %A) {
+ %c1 = sext i16 %A to i32 ; <i32> [#uses=1]
+ %c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
+ ret i16 %c2
+; CHECK: ret i16 %A
+}
+
+define i16 @test10(i16 %A) {
+ %c1 = sext i16 %A to i32 ; <i32> [#uses=1]
+ %c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
+ ret i16 %c2
+; CHECK: ret i16 %A
+}
+
+declare void @varargs(i32, ...)
+
+define void @test11(i32* %P) {
+ %c = bitcast i32* %P to i16* ; <i16*> [#uses=1]
+ call void (i32, ...)* @varargs( i32 5, i16* %c )
+ ret void
+; CHECK: call void (i32, ...)* @varargs(i32 5, i32* %P)
+; CHECK: ret void
+}
+
+define i8* @test13(i64 %A) {
+ %c = getelementptr [0 x i8]* bitcast ([32832 x i8]* @inbuf to [0 x i8]*), i64 0, i64 %A ; <i8*> [#uses=1]
+ ret i8* %c
+; CHECK: %c = getelementptr [32832 x i8]* @inbuf, i64 0, i64 %A
+; CHECK: ret i8* %c
+}
+
+define i1 @test14(i8 %A) {
+ %c = bitcast i8 %A to i8 ; <i8> [#uses=1]
+ %X = icmp ult i8 %c, -128 ; <i1> [#uses=1]
+ ret i1 %X
+; CHECK: %X = icmp sgt i8 %A, -1
+; CHECK: ret i1 %X
+}
+
+
+; This just won't occur when there's no difference between ubyte and sbyte
+;bool %test15(ubyte %A) {
+; %c = cast ubyte %A to sbyte
+; %X = setlt sbyte %c, 0 ; setgt %A, 127
+; ret bool %X
+;}
+
+define i1 @test16(i32* %P) {
+ %c = icmp ne i32* %P, null ; <i1> [#uses=1]
+ ret i1 %c
+; CHECK: %c = icmp ne i32* %P, null
+; CHECK: ret i1 %c
+}
+
+define i16 @test17(i1 %tmp3) {
+ %c = zext i1 %tmp3 to i32 ; <i32> [#uses=1]
+ %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
+ ret i16 %t86
+; CHECK: %t86 = zext i1 %tmp3 to i16
+; CHECK: ret i16 %t86
+}
+
+define i16 @test18(i8 %tmp3) {
+ %c = sext i8 %tmp3 to i32 ; <i32> [#uses=1]
+ %t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
+ ret i16 %t86
+; CHECK: %t86 = sext i8 %tmp3 to i16
+; CHECK: ret i16 %t86
+}
+
+define i1 @test19(i32 %X) {
+ %c = sext i32 %X to i64 ; <i64> [#uses=1]
+ %Z = icmp slt i64 %c, 12345 ; <i1> [#uses=1]
+ ret i1 %Z
+; CHECK: %Z = icmp slt i32 %X, 12345
+; CHECK: ret i1 %Z
+}
+
+define i1 @test20(i1 %B) {
+ %c = zext i1 %B to i32 ; <i32> [#uses=1]
+ %D = icmp slt i32 %c, -1 ; <i1> [#uses=1]
+ ;; false
+ ret i1 %D
+; CHECK: ret i1 false
+}
+
+define i32 @test21(i32 %X) {
+ %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
+ ;; sext -> zext -> and -> nop
+ %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
+ %RV = and i32 %c2, 255 ; <i32> [#uses=1]
+ ret i32 %RV
+; CHECK: %c21 = and i32 %X, 255
+; CHECK: ret i32 %c21
+}
+
+define i32 @test22(i32 %X) {
+ %c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
+ ;; sext -> zext -> and -> nop
+ %c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
+ %RV = shl i32 %c2, 24 ; <i32> [#uses=1]
+ ret i32 %RV
+; CHECK: shl i32 %X, 24
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test23(i32 %X) {
+ ;; Turn into an AND even though X
+ %c1 = trunc i32 %X to i16 ; <i16> [#uses=1]
+ ;; and Z are signed.
+ %c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
+ ret i32 %c2
+; CHECK: %c2 = and i32 %X, 65535
+; CHECK: ret i32 %c2
+}
+
+define i1 @test24(i1 %C) {
+ %X = select i1 %C, i32 14, i32 1234 ; <i32> [#uses=1]
+ ;; Fold cast into select
+ %c = icmp ne i32 %X, 0 ; <i1> [#uses=1]
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define void @test25(i32** %P) {
+ %c = bitcast i32** %P to float** ; <float**> [#uses=1]
+ ;; Fold cast into null
+ store float* null, float** %c
+ ret void
+; CHECK: store i32* null, i32** %P
+; CHECK: ret void
+}
+
+define i32 @test26(float %F) {
+ ;; no need to cast from float->double.
+ %c = fpext float %F to double ; <double> [#uses=1]
+ %D = fptosi double %c to i32 ; <i32> [#uses=1]
+ ret i32 %D
+; CHECK: %D = fptosi float %F to i32
+; CHECK: ret i32 %D
+}
+
+define [4 x float]* @test27([9 x [4 x float]]* %A) {
+ %c = bitcast [9 x [4 x float]]* %A to [4 x float]* ; <[4 x float]*> [#uses=1]
+ ret [4 x float]* %c
+; CHECK: %c = getelementptr inbounds [9 x [4 x float]]* %A, i64 0, i64 0
+; CHECK: ret [4 x float]* %c
+}
+
+define float* @test28([4 x float]* %A) {
+ %c = bitcast [4 x float]* %A to float* ; <float*> [#uses=1]
+ ret float* %c
+; CHECK: %c = getelementptr inbounds [4 x float]* %A, i64 0, i64 0
+; CHECK: ret float* %c
+}
+
+define i32 @test29(i32 %c1, i32 %c2) {
+ %tmp1 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
+ %tmp4.mask = trunc i32 %c2 to i8 ; <i8> [#uses=1]
+ %tmp = or i8 %tmp4.mask, %tmp1 ; <i8> [#uses=1]
+ %tmp10 = zext i8 %tmp to i32 ; <i32> [#uses=1]
+ ret i32 %tmp10
+; CHECK: %tmp2 = or i32 %c2, %c1
+; CHECK: %tmp10 = and i32 %tmp2, 255
+; CHECK: ret i32 %tmp10
+}
+
+define i32 @test30(i32 %c1) {
+ %c2 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
+ %c3 = xor i8 %c2, 1 ; <i8> [#uses=1]
+ %c4 = zext i8 %c3 to i32 ; <i32> [#uses=1]
+ ret i32 %c4
+; CHECK: %c3 = and i32 %c1, 255
+; CHECK: %c4 = xor i32 %c3, 1
+; CHECK: ret i32 %c4
+}
+
+define i1 @test31(i64 %A) {
+ %B = trunc i64 %A to i32 ; <i32> [#uses=1]
+ %C = and i32 %B, 42 ; <i32> [#uses=1]
+ %D = icmp eq i32 %C, 10 ; <i1> [#uses=1]
+ ret i1 %D
+; CHECK: %C = and i64 %A, 42
+; CHECK: %D = icmp eq i64 %C, 10
+; CHECK: ret i1 %D
+}
+
+define i32 @test33(i32 %c1) {
+ %x = bitcast i32 %c1 to float ; <float> [#uses=1]
+ %y = bitcast float %x to i32 ; <i32> [#uses=1]
+ ret i32 %y
+; CHECK: ret i32 %c1
+}
+
+define i16 @test34(i16 %a) {
+ %c1 = zext i16 %a to i32 ; <i32> [#uses=1]
+ %tmp21 = lshr i32 %c1, 8 ; <i32> [#uses=1]
+ %c2 = trunc i32 %tmp21 to i16 ; <i16> [#uses=1]
+ ret i16 %c2
+; CHECK: %tmp21 = lshr i16 %a, 8
+; CHECK: ret i16 %tmp21
+}
+
+define i16 @test35(i16 %a) {
+ %c1 = bitcast i16 %a to i16 ; <i16> [#uses=1]
+ %tmp2 = lshr i16 %c1, 8 ; <i16> [#uses=1]
+ %c2 = bitcast i16 %tmp2 to i16 ; <i16> [#uses=1]
+ ret i16 %c2
+; CHECK: %tmp2 = lshr i16 %a, 8
+; CHECK: ret i16 %tmp2
+}
+
+; icmp sgt i32 %a, -1
+; rdar://6480391
+define i1 @test36(i32 %a) {
+ %b = lshr i32 %a, 31
+ %c = trunc i32 %b to i8
+ %d = icmp eq i8 %c, 0
+ ret i1 %d
+; CHECK: %d = icmp sgt i32 %a, -1
+; CHECK: ret i1 %d
+}
+
+; ret i1 false
+define i1 @test37(i32 %a) {
+ %b = lshr i32 %a, 31
+ %c = or i32 %b, 512
+ %d = trunc i32 %c to i8
+ %e = icmp eq i8 %d, 11
+ ret i1 %e
+; CHECK: ret i1 false
+}
+
+define i64 @test38(i32 %a) {
+ %1 = icmp eq i32 %a, -2
+ %2 = zext i1 %1 to i8
+ %3 = xor i8 %2, 1
+ %4 = zext i8 %3 to i64
+ ret i64 %4
+; CHECK: %1 = icmp ne i32 %a, -2
+; CHECK: %2 = zext i1 %1 to i64
+; CHECK: ret i64 %2
+}
+
+define i16 @test39(i16 %a) {
+ %tmp = zext i16 %a to i32
+ %tmp21 = lshr i32 %tmp, 8
+ %tmp5 = shl i32 %tmp, 8
+ %tmp.upgrd.32 = or i32 %tmp21, %tmp5
+ %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
+ ret i16 %tmp.upgrd.3
+; CHECK: @test39
+; CHECK: %tmp.upgrd.32 = call i16 @llvm.bswap.i16(i16 %a)
+; CHECK: ret i16 %tmp.upgrd.32
+}
+
+define i16 @test40(i16 %a) {
+ %tmp = zext i16 %a to i32
+ %tmp21 = lshr i32 %tmp, 9
+ %tmp5 = shl i32 %tmp, 8
+ %tmp.upgrd.32 = or i32 %tmp21, %tmp5
+ %tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
+ ret i16 %tmp.upgrd.3
+; CHECK: @test40
+; CHECK: %tmp21 = lshr i16 %a, 9
+; CHECK: %tmp5 = shl i16 %a, 8
+; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5
+; CHECK: ret i16 %tmp.upgrd.32
+}
+
+; PR1263
+define i32* @test41(i32* %tmp1) {
+ %tmp64 = bitcast i32* %tmp1 to { i32 }*
+ %tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0
+ ret i32* %tmp65
+; CHECK: @test41
+; CHECK: ret i32* %tmp1
+}
+
+define i32 @test42(i32 %X) {
+ %Y = trunc i32 %X to i8 ; <i8> [#uses=1]
+ %Z = zext i8 %Y to i32 ; <i32> [#uses=1]
+ ret i32 %Z
+; CHECK: @test42
+; CHECK: %Z = and i32 %X, 255
+}
+
+; rdar://6598839
+define zeroext i64 @test43(i8 zeroext %on_off) nounwind readonly {
+ %A = zext i8 %on_off to i32
+ %B = add i32 %A, -1
+ %C = sext i32 %B to i64
+ ret i64 %C ;; Should be (add (zext i8 -> i64), -1)
+; CHECK: @test43
+; CHECK-NEXT: %A = zext i8 %on_off to i64
+; CHECK-NEXT: %B = add i64 %A, -1
+; CHECK-NEXT: ret i64 %B
+}
+
+define i64 @test44(i8 %T) {
+ %A = zext i8 %T to i16
+ %B = or i16 %A, 1234
+ %C = zext i16 %B to i64
+ ret i64 %C
+; CHECK: @test44
+; CHECK-NEXT: %A = zext i8 %T to i64
+; CHECK-NEXT: %B = or i64 %A, 1234
+; CHECK-NEXT: ret i64 %B
+}
+
+define i64 @test45(i8 %A, i64 %Q) {
+ %D = trunc i64 %Q to i32 ;; should be removed
+ %B = sext i8 %A to i32
+ %C = or i32 %B, %D
+ %E = zext i32 %C to i64
+ ret i64 %E
+; CHECK: @test45
+; CHECK-NEXT: %B = sext i8 %A to i64
+; CHECK-NEXT: %C = or i64 %B, %Q
+; CHECK-NEXT: %E = and i64 %C, 4294967295
+; CHECK-NEXT: ret i64 %E
+}
+
+
+define i64 @test46(i64 %A) {
+ %B = trunc i64 %A to i32
+ %C = and i32 %B, 42
+ %D = shl i32 %C, 8
+ %E = zext i32 %D to i64
+ ret i64 %E
+; CHECK: @test46
+; CHECK-NEXT: %C = shl i64 %A, 8
+; CHECK-NEXT: %D = and i64 %C, 10752
+; CHECK-NEXT: ret i64 %D
+}
+
+define i64 @test47(i8 %A) {
+ %B = sext i8 %A to i32
+ %C = or i32 %B, 42
+ %E = zext i32 %C to i64
+ ret i64 %E
+; CHECK: @test47
+; CHECK-NEXT: %B = sext i8 %A to i64
+; CHECK-NEXT: %C = and i64 %B, 4294967253
+; CHECK-NEXT: %E = or i64 %C, 42
+; CHECK-NEXT: ret i64 %E
+}
+
+define i64 @test48(i8 %A, i8 %a) {
+ %b = zext i8 %a to i32
+ %B = zext i8 %A to i32
+ %C = shl i32 %B, 8
+ %D = or i32 %C, %b
+ %E = zext i32 %D to i64
+ ret i64 %E
+; CHECK: @test48
+; CHECK-NEXT: %b = zext i8 %a to i64
+; CHECK-NEXT: %B = zext i8 %A to i64
+; CHECK-NEXT: %C = shl nuw nsw i64 %B, 8
+; CHECK-NEXT: %D = or i64 %C, %b
+; CHECK-NEXT: ret i64 %D
+}
+
+define i64 @test49(i64 %A) {
+ %B = trunc i64 %A to i32
+ %C = or i32 %B, 1
+ %D = sext i32 %C to i64
+ ret i64 %D
+; CHECK: @test49
+; CHECK-NEXT: %C = shl i64 %A, 32
+; CHECK-NEXT: ashr exact i64 %C, 32
+; CHECK-NEXT: %D = or i64 {{.*}}, 1
+; CHECK-NEXT: ret i64 %D
+}
+
+define i64 @test50(i64 %A) {
+ %a = lshr i64 %A, 2
+ %B = trunc i64 %a to i32
+ %D = add i32 %B, -1
+ %E = sext i32 %D to i64
+ ret i64 %E
+; CHECK: @test50
+; CHECK-NEXT: shl i64 %A, 30
+; CHECK-NEXT: add i64 {{.*}}, -4294967296
+; CHECK-NEXT: %sext = ashr i64 {{.*}}, 32
+; CHECK-NEXT: ret i64 %sext
+}
+
+define i64 @test51(i64 %A, i1 %cond) {
+ %B = trunc i64 %A to i32
+ %C = and i32 %B, -2
+ %D = or i32 %B, 1
+ %E = select i1 %cond, i32 %C, i32 %D
+ %F = sext i32 %E to i64
+ ret i64 %F
+; CHECK: @test51
+
+; FIXME: disabled, see PR5997
+; HECK-NEXT: %C = and i64 %A, 4294967294
+; HECK-NEXT: %D = or i64 %A, 1
+; HECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D
+; HECK-NEXT: %sext = shl i64 %E, 32
+; HECK-NEXT: %F = ashr i64 %sext, 32
+; HECK-NEXT: ret i64 %F
+}
+
+define i32 @test52(i64 %A) {
+ %B = trunc i64 %A to i16
+ %C = or i16 %B, -32574
+ %D = and i16 %C, -25350
+ %E = zext i16 %D to i32
+ ret i32 %E
+; CHECK: @test52
+; CHECK-NEXT: %B = trunc i64 %A to i32
+; CHECK-NEXT: %C = and i32 %B, 7224
+; CHECK-NEXT: %D = or i32 %C, 32962
+; CHECK-NEXT: ret i32 %D
+}
+
+define i64 @test53(i32 %A) {
+ %B = trunc i32 %A to i16
+ %C = or i16 %B, -32574
+ %D = and i16 %C, -25350
+ %E = zext i16 %D to i64
+ ret i64 %E
+; CHECK: @test53
+; CHECK-NEXT: %B = zext i32 %A to i64
+; CHECK-NEXT: %C = and i64 %B, 7224
+; CHECK-NEXT: %D = or i64 %C, 32962
+; CHECK-NEXT: ret i64 %D
+}
+
+define i32 @test54(i64 %A) {
+ %B = trunc i64 %A to i16
+ %C = or i16 %B, -32574
+ %D = and i16 %C, -25350
+ %E = sext i16 %D to i32
+ ret i32 %E
+; CHECK: @test54
+; CHECK-NEXT: %B = trunc i64 %A to i32
+; CHECK-NEXT: %C = and i32 %B, 7224
+; CHECK-NEXT: %D = or i32 %C, -32574
+; CHECK-NEXT: ret i32 %D
+}
+
+define i64 @test55(i32 %A) {
+ %B = trunc i32 %A to i16
+ %C = or i16 %B, -32574
+ %D = and i16 %C, -25350
+ %E = sext i16 %D to i64
+ ret i64 %E
+; CHECK: @test55
+; CHECK-NEXT: %B = zext i32 %A to i64
+; CHECK-NEXT: %C = and i64 %B, 7224
+; CHECK-NEXT: %D = or i64 %C, -32574
+; CHECK-NEXT: ret i64 %D
+}
+
+define i64 @test56(i16 %A) nounwind {
+ %tmp353 = sext i16 %A to i32
+ %tmp354 = lshr i32 %tmp353, 5
+ %tmp355 = zext i32 %tmp354 to i64
+ ret i64 %tmp355
+; CHECK: @test56
+; CHECK-NEXT: %tmp353 = sext i16 %A to i64
+; CHECK-NEXT: %tmp354 = lshr i64 %tmp353, 5
+; CHECK-NEXT: %tmp355 = and i64 %tmp354, 134217727
+; CHECK-NEXT: ret i64 %tmp355
+}
+
+define i64 @test57(i64 %A) nounwind {
+ %B = trunc i64 %A to i32
+ %C = lshr i32 %B, 8
+ %E = zext i32 %C to i64
+ ret i64 %E
+; CHECK: @test57
+; CHECK-NEXT: %C = lshr i64 %A, 8
+; CHECK-NEXT: %E = and i64 %C, 16777215
+; CHECK-NEXT: ret i64 %E
+}
+
+define i64 @test58(i64 %A) nounwind {
+ %B = trunc i64 %A to i32
+ %C = lshr i32 %B, 8
+ %D = or i32 %C, 128
+ %E = zext i32 %D to i64
+ ret i64 %E
+
+; CHECK: @test58
+; CHECK-NEXT: %C = lshr i64 %A, 8
+; CHECK-NEXT: %D = and i64 %C, 16777087
+; CHECK-NEXT: %E = or i64 %D, 128
+; CHECK-NEXT: ret i64 %E
+}
+
+define i64 @test59(i8 %A, i8 %B) nounwind {
+ %C = zext i8 %A to i32
+ %D = shl i32 %C, 4
+ %E = and i32 %D, 48
+ %F = zext i8 %B to i32
+ %G = lshr i32 %F, 4
+ %H = or i32 %G, %E
+ %I = zext i32 %H to i64
+ ret i64 %I
+; CHECK: @test59
+; CHECK-NEXT: %C = zext i8 %A to i64
+; CHECK-NOT: i32
+; CHECK: %F = zext i8 %B to i64
+; CHECK-NOT: i32
+; CHECK: ret i64 %H
+}
+
+define <3 x i32> @test60(<4 x i32> %call4) nounwind {
+ %tmp11 = bitcast <4 x i32> %call4 to i128
+ %tmp9 = trunc i128 %tmp11 to i96
+ %tmp10 = bitcast i96 %tmp9 to <3 x i32>
+ ret <3 x i32> %tmp10
+
+; CHECK: @test60
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+}
+
+define <4 x i32> @test61(<3 x i32> %call4) nounwind {
+ %tmp11 = bitcast <3 x i32> %call4 to i96
+ %tmp9 = zext i96 %tmp11 to i128
+ %tmp10 = bitcast i128 %tmp9 to <4 x i32>
+ ret <4 x i32> %tmp10
+; CHECK: @test61
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+}
+
+define <4 x i32> @test62(<3 x float> %call4) nounwind {
+ %tmp11 = bitcast <3 x float> %call4 to i96
+ %tmp9 = zext i96 %tmp11 to i128
+ %tmp10 = bitcast i128 %tmp9 to <4 x i32>
+ ret <4 x i32> %tmp10
+; CHECK: @test62
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+}
+
+; PR7311 - Don't create invalid IR on scalar->vector cast.
+define <2 x float> @test63(i64 %tmp8) nounwind {
+entry:
+ %a = bitcast i64 %tmp8 to <2 x i32>
+ %vcvt.i = uitofp <2 x i32> %a to <2 x float>
+ ret <2 x float> %vcvt.i
+; CHECK: @test63
+; CHECK: bitcast
+; CHECK: uitofp
+}
+
+define <4 x float> @test64(<4 x float> %c) nounwind {
+ %t0 = bitcast <4 x float> %c to <4 x i32>
+ %t1 = bitcast <4 x i32> %t0 to <4 x float>
+ ret <4 x float> %t1
+; CHECK: @test64
+; CHECK-NEXT: ret <4 x float> %c
+}
+
+define <4 x float> @test65(<4 x float> %c) nounwind {
+ %t0 = bitcast <4 x float> %c to <2 x double>
+ %t1 = bitcast <2 x double> %t0 to <4 x float>
+ ret <4 x float> %t1
+; CHECK: @test65
+; CHECK-NEXT: ret <4 x float> %c
+}
+
+define <2 x float> @test66(<2 x float> %c) nounwind {
+ %t0 = bitcast <2 x float> %c to double
+ %t1 = bitcast double %t0 to <2 x float>
+ ret <2 x float> %t1
+; CHECK: @test66
+; CHECK-NEXT: ret <2 x float> %c
+}
+
+define float @test2c() {
+ ret float extractelement (<2 x float> bitcast (double bitcast (<2 x float> <float -1.000000e+00, float -1.000000e+00> to double) to <2 x float>), i32 0)
+; CHECK: @test2c
+; CHECK-NOT: extractelement
+}
+
+define i64 @test_mmx(<2 x i32> %c) nounwind {
+ %A = bitcast <2 x i32> %c to x86_mmx
+ %B = bitcast x86_mmx %A to <2 x i32>
+ %C = bitcast <2 x i32> %B to i64
+ ret i64 %C
+; CHECK: @test_mmx
+; CHECK-NOT: x86_mmx
+}
+
+define i64 @test_mmx_const(<2 x i32> %c) nounwind {
+ %A = bitcast <2 x i32> zeroinitializer to x86_mmx
+ %B = bitcast x86_mmx %A to <2 x i32>
+ %C = bitcast <2 x i32> %B to i64
+ ret i64 %C
+; CHECK: @test_mmx_const
+; CHECK-NOT: x86_mmx
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/cast_ptr.ll b/src/LLVM/test/Transforms/InstCombine/cast_ptr.ll
new file mode 100644
index 0000000..b524511
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/cast_ptr.ll
@@ -0,0 +1,79 @@
+; Tests to make sure elimination of casts is working correctly
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "p:32:32"
+
+; This shouldn't convert to getelementptr because the relationship
+; between the arithmetic and the layout of allocated memory is
+; entirely unknown.
+; CHECK: @test1
+; CHECK: ptrtoint
+; CHECK: add
+; CHECK: inttoptr
+define i8* @test1(i8* %t) {
+ %tmpc = ptrtoint i8* %t to i32 ; <i32> [#uses=1]
+ %tmpa = add i32 %tmpc, 32 ; <i32> [#uses=1]
+ %tv = inttoptr i32 %tmpa to i8* ; <i8*> [#uses=1]
+ ret i8* %tv
+}
+
+; These casts should be folded away.
+; CHECK: @test2
+; CHECK: icmp eq i8* %a, %b
+define i1 @test2(i8* %a, i8* %b) {
+ %tmpa = ptrtoint i8* %a to i32 ; <i32> [#uses=1]
+ %tmpb = ptrtoint i8* %b to i32 ; <i32> [#uses=1]
+ %r = icmp eq i32 %tmpa, %tmpb ; <i1> [#uses=1]
+ ret i1 %r
+}
+
+; These casts should also be folded away.
+; CHECK: @test3
+; CHECK: icmp eq i8* %a, @global
+@global = global i8 0
+define i1 @test3(i8* %a) {
+ %tmpa = ptrtoint i8* %a to i32
+ %r = icmp eq i32 %tmpa, ptrtoint (i8* @global to i32)
+ ret i1 %r
+}
+
+define i1 @test4(i32 %A) {
+ %B = inttoptr i32 %A to i8*
+ %C = icmp eq i8* %B, null
+ ret i1 %C
+; CHECK: @test4
+; CHECK-NEXT: %C = icmp eq i32 %A, 0
+; CHECK-NEXT: ret i1 %C
+}
+
+
+; Pulling the cast out of the load allows us to eliminate the load, and then
+; the whole array.
+
+ %op = type { float }
+ %unop = type { i32 }
+@Array = internal constant [1 x %op* (%op*)*] [ %op* (%op*)* @foo ] ; <[1 x %op* (%op*)*]*> [#uses=1]
+
+declare %op* @foo(%op* %X)
+
+define %unop* @test5(%op* %O) {
+ %tmp = load %unop* (%op*)** bitcast ([1 x %op* (%op*)*]* @Array to %unop* (%op*)**); <%unop* (%op*)*> [#uses=1]
+ %tmp.2 = call %unop* %tmp( %op* %O ) ; <%unop*> [#uses=1]
+ ret %unop* %tmp.2
+; CHECK: @test5
+; CHECK: call %op* @foo(%op* %O)
+}
+
+
+
+; InstCombine can not 'load (cast P)' -> cast (load P)' if the cast changes
+; the address space.
+
+define i8 @test6(i8 addrspace(1)* %source) {
+entry:
+ %arrayidx223 = bitcast i8 addrspace(1)* %source to i8*
+ %tmp4 = load i8* %arrayidx223
+ ret i8 %tmp4
+; CHECK: @test6
+; CHECK: load i8* %arrayidx223
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/compare-signs.ll b/src/LLVM/test/Transforms/InstCombine/compare-signs.ll
new file mode 100644
index 0000000..f8e4911
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/compare-signs.ll
@@ -0,0 +1,58 @@
+; RUN: opt %s -instcombine -S | FileCheck %s
+; PR5438
+
+; TODO: This should also optimize down.
+;define i32 @test1(i32 %a, i32 %b) nounwind readnone {
+;entry:
+; %0 = icmp sgt i32 %a, -1 ; <i1> [#uses=1]
+; %1 = icmp slt i32 %b, 0 ; <i1> [#uses=1]
+; %2 = xor i1 %1, %0 ; <i1> [#uses=1]
+; %3 = zext i1 %2 to i32 ; <i32> [#uses=1]
+; ret i32 %3
+;}
+
+; TODO: This optimizes partially but not all the way.
+;define i32 @test2(i32 %a, i32 %b) nounwind readnone {
+;entry:
+; %0 = and i32 %a, 8 ;<i32> [#uses=1]
+; %1 = and i32 %b, 8 ;<i32> [#uses=1]
+; %2 = icmp eq i32 %0, %1 ;<i1> [#uses=1]
+; %3 = zext i1 %2 to i32 ;<i32> [#uses=1]
+; ret i32 %3
+;}
+
+define i32 @test3(i32 %a, i32 %b) nounwind readnone {
+; CHECK: @test3
+entry:
+; CHECK: xor i32 %a, %b
+; CHECK: lshr i32 %0, 31
+; CHECK: xor i32 %1, 1
+ %0 = lshr i32 %a, 31 ; <i32> [#uses=1]
+ %1 = lshr i32 %b, 31 ; <i32> [#uses=1]
+ %2 = icmp eq i32 %0, %1 ; <i1> [#uses=1]
+ %3 = zext i1 %2 to i32 ; <i32> [#uses=1]
+ ret i32 %3
+; CHECK-NOT: icmp
+; CHECK-NOT: zext
+; CHECK: ret i32 %2
+}
+
+; Variation on @test3: checking the 2nd bit in a situation where the 5th bit
+; is one, not zero.
+define i32 @test3i(i32 %a, i32 %b) nounwind readnone {
+; CHECK: @test3i
+entry:
+; CHECK: xor i32 %a, %b
+; CHECK: lshr i32 %0, 31
+; CHECK: xor i32 %1, 1
+ %0 = lshr i32 %a, 29 ; <i32> [#uses=1]
+ %1 = lshr i32 %b, 29 ; <i32> [#uses=1]
+ %2 = or i32 %0, 35
+ %3 = or i32 %1, 35
+ %4 = icmp eq i32 %2, %3 ; <i1> [#uses=1]
+ %5 = zext i1 %4 to i32 ; <i32> [#uses=1]
+ ret i32 %5
+; CHECK-NOT: icmp
+; CHECK-NOT: zext
+; CHECK: ret i32 %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/constant-fold-compare.ll b/src/LLVM/test/Transforms/InstCombine/constant-fold-compare.ll
new file mode 100644
index 0000000..6e41e2f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/constant-fold-compare.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+
+define i32 @a() nounwind readnone {
+entry:
+ ret i32 zext (i1 icmp eq (i32 0, i32 ptrtoint (i32 ()* @a to i32)) to i32)
+}
+; CHECK: ret i32 0
diff --git a/src/LLVM/test/Transforms/InstCombine/constant-fold-gep.ll b/src/LLVM/test/Transforms/InstCombine/constant-fold-gep.ll
new file mode 100644
index 0000000..c679226
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/constant-fold-gep.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+; Constant folding should fix notionally out-of-bounds indices
+; and add inbounds keywords.
+
+%struct.X = type { [3 x i32], [3 x i32] }
+
+@Y = internal global [3 x %struct.X] zeroinitializer
+
+define void @frob() {
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 1), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 1), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 2), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 2), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 0), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 3), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 1), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 4), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 2), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 5), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 6), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 1), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 7), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 2), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 8), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 0), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 9), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 1), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 10), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 2), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 11), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 12), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 1), align 4
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 13), align 4
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 2), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 14), align 8
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 15), align 8
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 1), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 16), align 8
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 2), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 17), align 8
+; CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 1, i64 0, i32 0, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 18), align 8
+; CHECK: store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 2, i64 0, i32 0, i64 0), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 36), align 8
+; CHECK: store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 1, i64 0, i32 0, i64 1), align 8
+ store i32 1, i32* getelementptr ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 19), align 8
+ ret void
+}
+
+
+; PR8883 - Constant fold exotic gep subtract
+; CHECK: @test2
+@X = global [1000 x i8] zeroinitializer, align 16
+
+define i64 @test2() {
+entry:
+ %A = bitcast i8* getelementptr inbounds ([1000 x i8]* @X, i64 1, i64 0) to i8*
+ %B = bitcast i8* getelementptr inbounds ([1000 x i8]* @X, i64 0, i64 0) to i8*
+
+ %B2 = ptrtoint i8* %B to i64
+ %C = sub i64 0, %B2
+ %D = getelementptr i8* %A, i64 %C
+ %E = ptrtoint i8* %D to i64
+
+ ret i64 %E
+ ; CHECK: ret i64 1000
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/crash.ll b/src/LLVM/test/Transforms/InstCombine/crash.ll
new file mode 100644
index 0000000..54a77aa
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/crash.ll
@@ -0,0 +1,401 @@
+; RUN: opt < %s -instcombine -S
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128:n8:16:32"
+target triple = "i386-apple-darwin10.0"
+
+define i32 @test0(i8 %tmp2) ssp {
+entry:
+ %tmp3 = zext i8 %tmp2 to i32
+ %tmp8 = lshr i32 %tmp3, 6
+ %tmp9 = lshr i32 %tmp3, 7
+ %tmp10 = xor i32 %tmp9, 67108858
+ %tmp11 = xor i32 %tmp10, %tmp8
+ %tmp12 = xor i32 %tmp11, 0
+ ret i32 %tmp12
+}
+
+; PR4905
+define <2 x i64> @test1(<2 x i64> %x, <2 x i64> %y) nounwind {
+entry:
+ %conv.i94 = bitcast <2 x i64> %y to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %sub.i97 = sub <4 x i32> %conv.i94, undef ; <<4 x i32>> [#uses=1]
+ %conv3.i98 = bitcast <4 x i32> %sub.i97 to <2 x i64> ; <<2 x i64>> [#uses=2]
+ %conv2.i86 = bitcast <2 x i64> %conv3.i98 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %cmp.i87 = icmp sgt <4 x i32> undef, %conv2.i86 ; <<4 x i1>> [#uses=1]
+ %sext.i88 = sext <4 x i1> %cmp.i87 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %conv3.i89 = bitcast <4 x i32> %sext.i88 to <2 x i64> ; <<2 x i64>> [#uses=1]
+ %and.i = and <2 x i64> %conv3.i89, %conv3.i98 ; <<2 x i64>> [#uses=1]
+ %or.i = or <2 x i64> zeroinitializer, %and.i ; <<2 x i64>> [#uses=1]
+ %conv2.i43 = bitcast <2 x i64> %or.i to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %sub.i = sub <4 x i32> zeroinitializer, %conv2.i43 ; <<4 x i32>> [#uses=1]
+ %conv3.i44 = bitcast <4 x i32> %sub.i to <2 x i64> ; <<2 x i64>> [#uses=1]
+ ret <2 x i64> %conv3.i44
+}
+
+
+; PR4908
+define void @test2(<1 x i16>* nocapture %b, i32* nocapture %c) nounwind ssp {
+entry:
+ %arrayidx = getelementptr inbounds <1 x i16>* %b, i64 undef ; <<1 x i16>*>
+ %tmp2 = load <1 x i16>* %arrayidx ; <<1 x i16>> [#uses=1]
+ %tmp6 = bitcast <1 x i16> %tmp2 to i16 ; <i16> [#uses=1]
+ %tmp7 = zext i16 %tmp6 to i32 ; <i32> [#uses=1]
+ %ins = or i32 0, %tmp7 ; <i32> [#uses=1]
+ %arrayidx20 = getelementptr inbounds i32* %c, i64 undef ; <i32*> [#uses=1]
+ store i32 %ins, i32* %arrayidx20
+ ret void
+}
+
+; PR5262
+@tmp2 = global i64 0 ; <i64*> [#uses=1]
+
+declare void @use(i64) nounwind
+
+define void @foo(i1) nounwind align 2 {
+; <label>:1
+ br i1 %0, label %2, label %3
+
+; <label>:2 ; preds = %1
+ br label %3
+
+; <label>:3 ; preds = %2, %1
+ %4 = phi i8 [ 1, %2 ], [ 0, %1 ] ; <i8> [#uses=1]
+ %5 = icmp eq i8 %4, 0 ; <i1> [#uses=1]
+ %6 = load i64* @tmp2, align 8 ; <i64> [#uses=1]
+ %7 = select i1 %5, i64 0, i64 %6 ; <i64> [#uses=1]
+ br label %8
+
+; <label>:8 ; preds = %3
+ call void @use(i64 %7)
+ ret void
+}
+
+%t0 = type { i32, i32 }
+%t1 = type { i32, i32, i32, i32, i32* }
+
+declare %t0* @bar2(i64)
+
+define void @bar3(i1, i1) nounwind align 2 {
+; <label>:2
+ br i1 %1, label %10, label %3
+
+; <label>:3 ; preds = %2
+ %4 = getelementptr inbounds %t0* null, i64 0, i32 1 ; <i32*> [#uses=0]
+ %5 = getelementptr inbounds %t1* null, i64 0, i32 4 ; <i32**> [#uses=1]
+ %6 = load i32** %5, align 8 ; <i32*> [#uses=1]
+ %7 = icmp ne i32* %6, null ; <i1> [#uses=1]
+ %8 = zext i1 %7 to i32 ; <i32> [#uses=1]
+ %9 = add i32 %8, 0 ; <i32> [#uses=1]
+ br label %10
+
+; <label>:10 ; preds = %3, %2
+ %11 = phi i32 [ %9, %3 ], [ 0, %2 ] ; <i32> [#uses=1]
+ br i1 %1, label %12, label %13
+
+; <label>:12 ; preds = %10
+ br label %13
+
+; <label>:13 ; preds = %12, %10
+ %14 = zext i32 %11 to i64 ; <i64> [#uses=1]
+ %15 = tail call %t0* @bar2(i64 %14) nounwind ; <%0*> [#uses=0]
+ ret void
+}
+
+
+
+
+; PR5262
+; Make sure the PHI node gets put in a place where all of its operands dominate
+; it.
+define i64 @test4(i1 %c, i64* %P) nounwind align 2 {
+BB0:
+ br i1 %c, label %BB1, label %BB2
+
+BB1:
+ br label %BB2
+
+BB2:
+ %v5_ = phi i1 [ true, %BB0], [false, %BB1]
+ %v6 = load i64* %P
+ br label %l8
+
+l8:
+ br label %l10
+
+l10:
+ %v11 = select i1 %v5_, i64 0, i64 %v6
+ ret i64 %v11
+}
+
+; PR5471
+define i32 @test5a() {
+ ret i32 0
+}
+
+define void @test5() {
+ store i1 true, i1* undef
+ %1 = invoke i32 @test5a() to label %exit unwind label %exit
+exit:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+}
+
+
+; PR5673
+
+@test6g = external global i32*
+
+define arm_aapcs_vfpcc i32 @test6(i32 %argc, i8** %argv) nounwind {
+entry:
+ store i32* getelementptr (i32* bitcast (i32 (i32, i8**)* @test6 to i32*), i32 -2048), i32** @test6g, align 4
+ unreachable
+}
+
+
+; PR5827
+
+%class.RuleBasedBreakIterator = type { i64 ()* }
+%class.UStack = type { i8** }
+
+define i32 @_ZN22RuleBasedBreakIterator15checkDictionaryEi(%class.RuleBasedBreakIterator* %this, i32 %x) align 2 {
+entry:
+ %breaks = alloca %class.UStack, align 4 ; <%class.UStack*> [#uses=3]
+ call void @_ZN6UStackC1Ei(%class.UStack* %breaks, i32 0)
+ %tobool = icmp ne i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %cond.end, label %cond.false
+
+terminate.handler: ; preds = %ehcleanup
+ %exc = call i8* @llvm.eh.exception() ; <i8*> [#uses=1]
+ %0 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exc, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 1) ; <i32> [#uses=0]
+ call void @_ZSt9terminatev() noreturn nounwind
+ unreachable
+
+ehcleanup: ; preds = %cond.false
+ %exc1 = call i8* @llvm.eh.exception() ; <i8*> [#uses=2]
+ %1 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exc1, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) ; <i32> [#uses=0]
+ invoke void @_ZN6UStackD1Ev(%class.UStack* %breaks)
+ to label %cont unwind label %terminate.handler
+
+cont: ; preds = %ehcleanup
+ call void @_Unwind_Resume_or_Rethrow(i8* %exc1)
+ unreachable
+
+cond.false: ; preds = %entry
+ %tmp4 = getelementptr inbounds %class.RuleBasedBreakIterator* %this, i32 0, i32 0 ; <i64 ()**> [#uses=1]
+ %tmp5 = load i64 ()** %tmp4 ; <i64 ()*> [#uses=1]
+ %call = invoke i64 %tmp5()
+ to label %cond.end unwind label %ehcleanup ; <i64> [#uses=1]
+
+cond.end: ; preds = %cond.false, %entry
+ %cond = phi i64 [ 0, %entry ], [ %call, %cond.false ] ; <i64> [#uses=1]
+ %conv = trunc i64 %cond to i32 ; <i32> [#uses=1]
+ call void @_ZN6UStackD1Ev(%class.UStack* %breaks)
+ ret i32 %conv
+}
+
+declare void @_ZN6UStackC1Ei(%class.UStack*, i32)
+
+declare void @_ZN6UStackD1Ev(%class.UStack*)
+
+declare i32 @__gxx_personality_v0(...)
+
+declare i8* @llvm.eh.exception() nounwind readonly
+
+declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
+
+declare void @_ZSt9terminatev()
+
+declare void @_Unwind_Resume_or_Rethrow(i8*)
+
+
+
+; rdar://7590304
+define i8* @test10(i8* %self, i8* %tmp3) {
+entry:
+ store i1 true, i1* undef
+ store i1 true, i1* undef
+ invoke void @test10a()
+ to label %invoke.cont unwind label %try.handler ; <i8*> [#uses=0]
+
+invoke.cont: ; preds = %entry
+ unreachable
+
+try.handler: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ ret i8* %self
+}
+
+define void @test10a() {
+ ret void
+}
+
+
+; PR6193
+define i32 @test11(i32 %aMaskWidth, i8 %aStride) nounwind {
+entry:
+ %conv41 = sext i8 %aStride to i32
+ %neg = xor i32 %conv41, -1
+ %and42 = and i32 %aMaskWidth, %neg
+ %and47 = and i32 130, %conv41
+ %or = or i32 %and42, %and47
+ ret i32 %or
+}
+
+; PR6503
+define void @test12(i32* %A) nounwind {
+entry:
+ %tmp1 = load i32* %A
+ %cmp = icmp ugt i32 1, %tmp1 ; <i1> [#uses=1]
+ %conv = zext i1 %cmp to i32 ; <i32> [#uses=1]
+ %tmp2 = load i32* %A
+ %cmp3 = icmp ne i32 %tmp2, 0 ; <i1> [#uses=1]
+ %conv4 = zext i1 %cmp3 to i32 ; <i32> [#uses=1]
+ %or = or i32 %conv, %conv4 ; <i32> [#uses=1]
+ %cmp5 = icmp ugt i32 undef, %or ; <i1> [#uses=1]
+ %conv6 = zext i1 %cmp5 to i32 ; <i32> [#uses=0]
+ ret void
+}
+
+%s1 = type { %s2, %s2, [6 x %s2], i32, i32, i32, [1 x i32], [0 x i8] }
+%s2 = type { i64 }
+define void @test13() nounwind ssp {
+entry:
+ %0 = getelementptr inbounds %s1* null, i64 0, i32 2, i64 0, i32 0
+ %1 = bitcast i64* %0 to i32*
+ %2 = getelementptr inbounds %s1* null, i64 0, i32 2, i64 1, i32 0
+ %.pre = load i32* %1, align 8
+ %3 = lshr i32 %.pre, 19
+ %brmerge = or i1 undef, undef
+ %4 = and i32 %3, 3
+ %5 = add nsw i32 %4, 1
+ %6 = shl i32 %5, 19
+ %7 = add i32 %6, 1572864
+ %8 = and i32 %7, 1572864
+ %9 = load i64* %2, align 8
+ %trunc156 = trunc i64 %9 to i32
+ %10 = and i32 %trunc156, -1537
+ %11 = and i32 %10, -6145
+ %12 = or i32 %11, 2048
+ %13 = and i32 %12, -24577
+ %14 = or i32 %13, 16384
+ %15 = or i32 %14, 98304
+ store i32 %15, i32* undef, align 8
+ %16 = and i32 %15, -1572865
+ %17 = or i32 %16, %8
+ store i32 %17, i32* undef, align 8
+ %18 = and i32 %17, -449
+ %19 = or i32 %18, 64
+ store i32 %19, i32* undef, align 8
+ unreachable
+}
+
+
+; PR8807
+declare i32 @test14f(i8* (i8*)*) nounwind
+
+define void @test14() nounwind readnone {
+entry:
+ %tmp = bitcast i32 (i8* (i8*)*)* @test14f to i32 (i32*)*
+ %call10 = call i32 %tmp(i32* byval undef)
+ ret void
+}
+
+
+; PR8896
+@g_54 = external global [7 x i16]
+
+define void @test15(i32* %p_92) nounwind {
+entry:
+%0 = load i32* %p_92, align 4
+%1 = icmp ne i32 %0, 0
+%2 = zext i1 %1 to i32
+%3 = call i32 @func_14() nounwind
+%4 = trunc i32 %3 to i16
+%5 = sext i16 %4 to i32
+%6 = trunc i32 %5 to i16
+br i1 undef, label %"3", label %"5"
+
+"3": ; preds = %entry
+%7 = sext i16 %6 to i32
+%8 = ashr i32 %7, -1649554541
+%9 = trunc i32 %8 to i16
+br label %"5"
+
+"5": ; preds = %"3", %entry
+%10 = phi i16 [ %9, %"3" ], [ %6, %entry ]
+%11 = sext i16 %10 to i32
+%12 = xor i32 %2, %11
+%13 = sext i32 %12 to i64
+%14 = icmp ne i64 %13, 0
+br i1 %14, label %return, label %"7"
+
+"7": ; preds = %"5"
+ret void
+
+return: ; preds = %"5"
+ret void
+}
+
+declare i32 @func_14()
+
+
+define double @test16(i32 %a) nounwind {
+ %cmp = icmp slt i32 %a, 2
+ %select = select i1 %cmp, double 2.000000e+00, double 3.141592e+00
+ ret double %select
+}
+
+
+; PR8983
+%struct.basic_ios = type { i8 }
+
+define %struct.basic_ios *@test17() ssp {
+entry:
+ %add.ptr.i = getelementptr i8* null, i64 undef
+ %0 = bitcast i8* %add.ptr.i to %struct.basic_ios*
+ ret %struct.basic_ios* %0
+}
+
+; PR9013
+define void @test18() nounwind ssp {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %l_197.0 = phi i32 [ 0, %entry ], [ %sub.i, %for.inc ]
+ br label %for.inc
+
+for.inc: ; preds = %for.cond
+ %conv = and i32 %l_197.0, 255
+ %sub.i = add nsw i32 %conv, -1
+ br label %for.cond
+
+return: ; No predecessors!
+ ret void
+}
+
+; PR11275
+declare void @test18b() noreturn
+declare void @test18foo(double**)
+declare void @test18a() noreturn
+define fastcc void @test18x(i8* %t0, i1 %b) uwtable align 2 {
+entry:
+ br i1 %b, label %e1, label %e2
+e1:
+ %t2 = bitcast i8* %t0 to double**
+ invoke void @test18b() noreturn
+ to label %u unwind label %lpad
+e2:
+ %t4 = bitcast i8* %t0 to double**
+ invoke void @test18a() noreturn
+ to label %u unwind label %lpad
+lpad:
+ %t5 = phi double** [ %t2, %e1 ], [ %t4, %e2 ]
+ %lpad.nonloopexit262 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @test18foo(double** %t5)
+ unreachable
+u:
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/dce-iterate.ll b/src/LLVM/test/Transforms/InstCombine/dce-iterate.ll
new file mode 100644
index 0000000..1d2cc53
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/dce-iterate.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -instcombine -S | grep {ret double .sy}
+
+define internal double @ScaleObjectAdd(double %sx, double %sy, double %sz) nounwind {
+entry:
+ %sx34 = bitcast double %sx to i64 ; <i64> [#uses=1]
+ %sx3435 = zext i64 %sx34 to i960 ; <i960> [#uses=1]
+ %sy22 = bitcast double %sy to i64 ; <i64> [#uses=1]
+ %sy2223 = zext i64 %sy22 to i960 ; <i960> [#uses=1]
+ %sy222324 = shl i960 %sy2223, 320 ; <i960> [#uses=1]
+ %sy222324.ins = or i960 %sx3435, %sy222324 ; <i960> [#uses=1]
+ %sz10 = bitcast double %sz to i64 ; <i64> [#uses=1]
+ %sz1011 = zext i64 %sz10 to i960 ; <i960> [#uses=1]
+ %sz101112 = shl i960 %sz1011, 640 ; <i960> [#uses=1]
+ %sz101112.ins = or i960 %sy222324.ins, %sz101112
+
+ %a = trunc i960 %sz101112.ins to i64 ; <i64> [#uses=1]
+ %b = bitcast i64 %a to double ; <double> [#uses=1]
+ %c = lshr i960 %sz101112.ins, 320 ; <i960> [#uses=1]
+ %d = trunc i960 %c to i64 ; <i64> [#uses=1]
+ %e = bitcast i64 %d to double ; <double> [#uses=1]
+ %f = fadd double %b, %e
+
+ ret double %e
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/deadcode.ll b/src/LLVM/test/Transforms/InstCombine/deadcode.ll
new file mode 100644
index 0000000..f6620c7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/deadcode.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -instcombine -S | grep {ret i32 %A}
+; RUN: opt < %s -die -S | not grep call.*llvm
+
+define i32 @test(i32 %A) {
+ %X = or i1 false, false
+ br i1 %X, label %T, label %C
+
+T: ; preds = %0
+ %B = add i32 %A, 1
+ br label %C
+
+C: ; preds = %T, %0
+ %C.upgrd.1 = phi i32 [ %B, %T ], [ %A, %0 ]
+ ret i32 %C.upgrd.1
+}
+
+define i32* @test2(i32 %width) {
+ %tmp = call i8* @llvm.stacksave( )
+ %tmp14 = alloca i32, i32 %width
+ ret i32* %tmp14
+}
+
+declare i8* @llvm.stacksave()
+
+declare void @llvm.lifetime.start(i64, i8*)
+declare void @llvm.lifetime.end(i64, i8*)
+
+define void @test3() {
+ call void @llvm.lifetime.start(i64 -1, i8* undef)
+ call void @llvm.lifetime.end(i64 -1, i8* undef)
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/debuginfo.ll b/src/LLVM/test/Transforms/InstCombine/debuginfo.ll
new file mode 100644
index 0000000..f6892fc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/debuginfo.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readnone
+
+declare i8* @foo(i8*, i32, i64, i64) nounwind
+
+define hidden i8* @foobar(i8* %__dest, i32 %__val, i64 %__len) nounwind inlinehint ssp {
+entry:
+ %__dest.addr = alloca i8*, align 8
+ %__val.addr = alloca i32, align 4
+ %__len.addr = alloca i64, align 8
+ store i8* %__dest, i8** %__dest.addr, align 8, !tbaa !1
+; CHECK-NOT: call void @llvm.dbg.declare
+; CHECK: call void @llvm.dbg.value
+ call void @llvm.dbg.declare(metadata !{i8** %__dest.addr}, metadata !0), !dbg !16
+ store i32 %__val, i32* %__val.addr, align 4, !tbaa !17
+ call void @llvm.dbg.declare(metadata !{i32* %__val.addr}, metadata !7), !dbg !18
+ store i64 %__len, i64* %__len.addr, align 8, !tbaa !19
+ call void @llvm.dbg.declare(metadata !{i64* %__len.addr}, metadata !9), !dbg !20
+ %tmp = load i8** %__dest.addr, align 8, !dbg !21, !tbaa !13
+ %tmp1 = load i32* %__val.addr, align 4, !dbg !21, !tbaa !17
+ %tmp2 = load i64* %__len.addr, align 8, !dbg !21, !tbaa !19
+ %tmp3 = load i8** %__dest.addr, align 8, !dbg !21, !tbaa !13
+ %0 = call i64 @llvm.objectsize.i64(i8* %tmp3, i1 false), !dbg !21
+ %call = call i8* @foo(i8* %tmp, i32 %tmp1, i64 %tmp2, i64 %0), !dbg !21
+ ret i8* %call, !dbg !21
+}
+
+!llvm.dbg.lv.foobar = !{!0, !7, !9}
+!llvm.dbg.sp = !{!1}
+
+!0 = metadata !{i32 590081, metadata !1, metadata !"__dest", metadata !2, i32 16777294, metadata !6, i32 0} ; [ DW_TAG_arg_variable ]
+!1 = metadata !{i32 589870, i32 0, metadata !2, metadata !"foobar", metadata !"foobar", metadata !"", metadata !2, i32 79, metadata !4, i1 true, i1 true, i32 0, i32 0, i32 0, i32 256, i1 true, i8* (i8*, i32, i64)* @foobar} ; [ DW_TAG_subprogram ]
+!2 = metadata !{i32 589865, metadata !"string.h", metadata !"Game", metadata !3} ; [ DW_TAG_file_type ]
+!3 = metadata !{i32 589841, i32 0, i32 12, metadata !"bits.c", metadata !"Game", metadata !"clang version 3.0 (trunk 127710)", i1 true, i1 true, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!4 = metadata !{i32 589845, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !5, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!5 = metadata !{metadata !6}
+!6 = metadata !{i32 589839, metadata !3, metadata !"", null, i32 0, i64 64, i64 64, i64 0, i32 0, null} ; [ DW_TAG_pointer_type ]
+!7 = metadata !{i32 590081, metadata !1, metadata !"__val", metadata !2, i32 33554510, metadata !8, i32 0} ; [ DW_TAG_arg_variable ]
+!8 = metadata !{i32 589860, metadata !3, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!9 = metadata !{i32 590081, metadata !1, metadata !"__len", metadata !2, i32 50331726, metadata !10, i32 0} ; [ DW_TAG_arg_variable ]
+!10 = metadata !{i32 589846, metadata !3, metadata !"size_t", metadata !2, i32 80, i64 0, i64 0, i64 0, i32 0, metadata !11} ; [ DW_TAG_typedef ]
+!11 = metadata !{i32 589846, metadata !3, metadata !"__darwin_size_t", metadata !2, i32 90, i64 0, i64 0, i64 0, i32 0, metadata !12} ; [ DW_TAG_typedef ]
+!12 = metadata !{i32 589860, metadata !3, metadata !"long unsigned int", null, i32 0, i64 64, i64 64, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ]
+!13 = metadata !{metadata !"any pointer", metadata !14}
+!14 = metadata !{metadata !"omnipotent char", metadata !15}
+!15 = metadata !{metadata !"Simple C/C++ TBAA", null}
+!16 = metadata !{i32 78, i32 28, metadata !1, null}
+!17 = metadata !{metadata !"int", metadata !14}
+!18 = metadata !{i32 78, i32 40, metadata !1, null}
+!19 = metadata !{metadata !"long", metadata !14}
+!20 = metadata !{i32 78, i32 54, metadata !1, null}
+!21 = metadata !{i32 80, i32 3, metadata !22, null}
+!22 = metadata !{i32 589835, metadata !23, i32 80, i32 3, metadata !2, i32 7} ; [ DW_TAG_lexical_block ]
+!23 = metadata !{i32 589835, metadata !1, i32 79, i32 1, metadata !2, i32 6} ; [ DW_TAG_lexical_block ]
diff --git a/src/LLVM/test/Transforms/InstCombine/devirt.ll b/src/LLVM/test/Transforms/InstCombine/devirt.ll
new file mode 100644
index 0000000..6189dc2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/devirt.ll
@@ -0,0 +1,39 @@
+; RUN: opt -instcombine -S -o - %s | FileCheck %s
+
+; CHECK-NOT: getelementptr
+; CHECK-NOT: ptrtoint
+; CHECK: bitcast i8*
+%struct.S = type { i32 (...)** }
+
+@_ZL1p = internal constant { i64, i64 } { i64 1, i64 0 }, align 8
+
+define void @_Z1g1S(%struct.S* %s) nounwind {
+entry:
+ %tmp = load { i64, i64 }* @_ZL1p, align 8
+ %memptr.adj = extractvalue { i64, i64 } %tmp, 1
+ %0 = bitcast %struct.S* %s to i8*
+ %1 = getelementptr inbounds i8* %0, i64 %memptr.adj
+ %this.adjusted = bitcast i8* %1 to %struct.S*
+ %memptr.ptr = extractvalue { i64, i64 } %tmp, 0
+ %2 = and i64 %memptr.ptr, 1
+ %memptr.isvirtual = icmp ne i64 %2, 0
+ br i1 %memptr.isvirtual, label %memptr.virtual, label %memptr.nonvirtual
+
+memptr.virtual: ; preds = %entry
+ %3 = bitcast %struct.S* %this.adjusted to i8**
+ %memptr.vtable = load i8** %3
+ %4 = sub i64 %memptr.ptr, 1
+ %5 = getelementptr i8* %memptr.vtable, i64 %4
+ %6 = bitcast i8* %5 to void (%struct.S*)**
+ %memptr.virtualfn = load void (%struct.S*)** %6
+ br label %memptr.end
+
+memptr.nonvirtual: ; preds = %entry
+ %memptr.nonvirtualfn = inttoptr i64 %memptr.ptr to void (%struct.S*)*
+ br label %memptr.end
+
+memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
+ %7 = phi void (%struct.S*)* [ %memptr.virtualfn, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
+ call void %7(%struct.S* %this.adjusted)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/dg.exp b/src/LLVM/test/Transforms/InstCombine/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/InstCombine/div.ll b/src/LLVM/test/Transforms/InstCombine/div.ll
new file mode 100644
index 0000000..9933325
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/div.ll
@@ -0,0 +1,134 @@
+; This test makes sure that div instructions are properly eliminated.
+
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @test1(i32 %A) {
+ %B = sdiv i32 %A, 1 ; <i32> [#uses=1]
+ ret i32 %B
+; CHECK: @test1
+; CHECK-NEXT: ret i32 %A
+}
+
+define i32 @test2(i32 %A) {
+ ; => Shift
+ %B = udiv i32 %A, 8 ; <i32> [#uses=1]
+ ret i32 %B
+; CHECK: @test2
+; CHECK-NEXT: lshr i32 %A, 3
+}
+
+define i32 @test3(i32 %A) {
+ ; => 0, don't need to keep traps
+ %B = sdiv i32 0, %A ; <i32> [#uses=1]
+ ret i32 %B
+; CHECK: @test3
+; CHECK-NEXT: ret i32 0
+}
+
+define i32 @test4(i32 %A) {
+ ; 0-A
+ %B = sdiv i32 %A, -1 ; <i32> [#uses=1]
+ ret i32 %B
+; CHECK: @test4
+; CHECK-NEXT: sub i32 0, %A
+}
+
+define i32 @test5(i32 %A) {
+ %B = udiv i32 %A, -16 ; <i32> [#uses=1]
+ %C = udiv i32 %B, -4 ; <i32> [#uses=1]
+ ret i32 %C
+; CHECK: @test5
+; CHECK-NEXT: ret i32 0
+}
+
+define i1 @test6(i32 %A) {
+ %B = udiv i32 %A, 123 ; <i32> [#uses=1]
+ ; A < 123
+ %C = icmp eq i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: @test6
+; CHECK-NEXT: icmp ult i32 %A, 123
+}
+
+define i1 @test7(i32 %A) {
+ %B = udiv i32 %A, 10 ; <i32> [#uses=1]
+ ; A >= 20 && A < 30
+ %C = icmp eq i32 %B, 2 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: @test7
+; CHECK-NEXT: add i32 %A, -20
+; CHECK-NEXT: icmp ult i32
+}
+
+define i1 @test8(i8 %A) {
+ %B = udiv i8 %A, 123 ; <i8> [#uses=1]
+ ; A >= 246
+ %C = icmp eq i8 %B, 2 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: @test8
+; CHECK-NEXT: icmp ugt i8 %A, -11
+}
+
+define i1 @test9(i8 %A) {
+ %B = udiv i8 %A, 123 ; <i8> [#uses=1]
+ ; A < 246
+ %C = icmp ne i8 %B, 2 ; <i1> [#uses=1]
+ ret i1 %C
+; CHECK: @test9
+; CHECK-NEXT: icmp ult i8 %A, -10
+}
+
+define i32 @test10(i32 %X, i1 %C) {
+ %V = select i1 %C, i32 64, i32 8 ; <i32> [#uses=1]
+ %R = udiv i32 %X, %V ; <i32> [#uses=1]
+ ret i32 %R
+; CHECK: @test10
+; CHECK-NEXT: select i1 %C, i32 6, i32 3
+; CHECK-NEXT: lshr i32 %X
+}
+
+define i32 @test11(i32 %X, i1 %C) {
+ %A = select i1 %C, i32 1024, i32 32 ; <i32> [#uses=1]
+ %B = udiv i32 %X, %A ; <i32> [#uses=1]
+ ret i32 %B
+; CHECK: @test11
+; CHECK-NEXT: select i1 %C, i32 10, i32 5
+; CHECK-NEXT: lshr i32 %X
+}
+
+; PR2328
+define i32 @test12(i32 %x) nounwind {
+ %tmp3 = udiv i32 %x, %x ; 1
+ ret i32 %tmp3
+; CHECK: @test12
+; CHECK-NEXT: ret i32 1
+}
+
+define i32 @test13(i32 %x) nounwind {
+ %tmp3 = sdiv i32 %x, %x ; 1
+ ret i32 %tmp3
+; CHECK: @test13
+; CHECK-NEXT: ret i32 1
+}
+
+define i32 @test14(i8 %x) nounwind {
+ %zext = zext i8 %x to i32
+ %div = udiv i32 %zext, 257 ; 0
+ ret i32 %div
+; CHECK: @test14
+; CHECK-NEXT: ret i32 0
+}
+
+; PR9814
+define i32 @test15(i32 %a, i32 %b) nounwind {
+ %shl = shl i32 1, %b
+ %div = lshr i32 %shl, 2
+ %div2 = udiv i32 %a, %div
+ ret i32 %div2
+; CHECK: @test15
+; CHECK-NEXT: add i32 %b, -2
+; CHECK-NEXT: lshr i32 %a,
+; CHECK-NEXT: ret i32
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/enforce-known-alignment.ll b/src/LLVM/test/Transforms/InstCombine/enforce-known-alignment.ll
new file mode 100644
index 0000000..9e9be7f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/enforce-known-alignment.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -S | grep alloca | grep {align 16}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+
+define void @foo(i32) {
+ %2 = alloca [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>], align 16 ; <[3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]*> [#uses=1]
+ %3 = getelementptr [3 x <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>]* %2, i32 0, i32 0 ; <<{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>*> [#uses=1]
+ %4 = getelementptr <{ { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } } }>* %3, i32 0, i32 0 ; <{ { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }*> [#uses=1]
+ %5 = getelementptr { { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 } }* %4, i32 0, i32 0 ; <{ [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 }*> [#uses=1]
+ %6 = bitcast { [2 x { { i32 } }], [2 x i8], { i16 }, [2 x i8], i8, i8 }* %5 to { [8 x i16] }* ; <{ [8 x i16] }*> [#uses=1]
+ %7 = getelementptr { [8 x i16] }* %6, i32 0, i32 0 ; <[8 x i16]*> [#uses=1]
+ %8 = getelementptr [8 x i16]* %7, i32 0, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %8, align 16
+ call void @bar(i16* %8)
+ ret void
+}
+
+declare void @bar(i16*)
diff --git a/src/LLVM/test/Transforms/InstCombine/exact.ll b/src/LLVM/test/Transforms/InstCombine/exact.ll
new file mode 100644
index 0000000..14741e3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/exact.ll
@@ -0,0 +1,170 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; CHECK: @sdiv1
+; CHECK: sdiv i32 %x, 8
+define i32 @sdiv1(i32 %x) {
+ %y = sdiv i32 %x, 8
+ ret i32 %y
+}
+
+; CHECK: @sdiv2
+; CHECK: ashr exact i32 %x, 3
+define i32 @sdiv2(i32 %x) {
+ %y = sdiv exact i32 %x, 8
+ ret i32 %y
+}
+
+; CHECK: @sdiv3
+; CHECK: %y = srem i32 %x, 3
+; CHECK: %z = sub i32 %x, %y
+; CHECK: ret i32 %z
+define i32 @sdiv3(i32 %x) {
+ %y = sdiv i32 %x, 3
+ %z = mul i32 %y, 3
+ ret i32 %z
+}
+
+; CHECK: @sdiv4
+; CHECK: ret i32 %x
+define i32 @sdiv4(i32 %x) {
+ %y = sdiv exact i32 %x, 3
+ %z = mul i32 %y, 3
+ ret i32 %z
+}
+
+; CHECK: i32 @sdiv5
+; CHECK: %y = srem i32 %x, 3
+; CHECK: %z = sub i32 %y, %x
+; CHECK: ret i32 %z
+define i32 @sdiv5(i32 %x) {
+ %y = sdiv i32 %x, 3
+ %z = mul i32 %y, -3
+ ret i32 %z
+}
+
+; CHECK: @sdiv6
+; CHECK: %z = sub i32 0, %x
+; CHECK: ret i32 %z
+define i32 @sdiv6(i32 %x) {
+ %y = sdiv exact i32 %x, 3
+ %z = mul i32 %y, -3
+ ret i32 %z
+}
+
+; CHECK: @udiv1
+; CHECK: ret i32 %x
+define i32 @udiv1(i32 %x, i32 %w) {
+ %y = udiv exact i32 %x, %w
+ %z = mul i32 %y, %w
+ ret i32 %z
+}
+
+; CHECK: @udiv2
+; CHECK: %z = lshr exact i32 %x, %w
+; CHECK: ret i32 %z
+define i32 @udiv2(i32 %x, i32 %w) {
+ %y = shl i32 1, %w
+ %z = udiv exact i32 %x, %y
+ ret i32 %z
+}
+
+; CHECK: @ashr1
+; CHECK: %B = ashr exact i64 %A, 2
+; CHECK: ret i64 %B
+define i64 @ashr1(i64 %X) nounwind {
+ %A = shl i64 %X, 8
+ %B = ashr i64 %A, 2 ; X/4
+ ret i64 %B
+}
+
+; PR9120
+; CHECK: @ashr_icmp1
+; CHECK: %B = icmp eq i64 %X, 0
+; CHECK: ret i1 %B
+define i1 @ashr_icmp1(i64 %X) nounwind {
+ %A = ashr exact i64 %X, 2 ; X/4
+ %B = icmp eq i64 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @ashr_icmp2
+; CHECK: %Z = icmp slt i64 %X, 16
+; CHECK: ret i1 %Z
+define i1 @ashr_icmp2(i64 %X) nounwind {
+ %Y = ashr exact i64 %X, 2 ; x / 4
+ %Z = icmp slt i64 %Y, 4 ; x < 16
+ ret i1 %Z
+}
+
+; PR9998
+; Make sure we don't transform the ashr here into an sdiv
+; CHECK: @pr9998
+; CHECK: = and i32 %V, 1
+; CHECK: %Z = icmp ne
+; CHECK: ret i1 %Z
+define i1 @pr9998(i32 %V) nounwind {
+entry:
+ %W = shl i32 %V, 31
+ %X = ashr exact i32 %W, 31
+ %Y = sext i32 %X to i64
+ %Z = icmp ugt i64 %Y, 7297771788697658747
+ ret i1 %Z
+}
+
+
+; CHECK: @udiv_icmp1
+; CHECK: icmp ne i64 %X, 0
+define i1 @udiv_icmp1(i64 %X) nounwind {
+ %A = udiv exact i64 %X, 5 ; X/5
+ %B = icmp ne i64 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp1
+; CHECK: icmp eq i64 %X, 0
+define i1 @sdiv_icmp1(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, 5 ; X/5 == 0 --> x == 0
+ %B = icmp eq i64 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp2
+; CHECK: icmp eq i64 %X, 5
+define i1 @sdiv_icmp2(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, 5 ; X/5 == 1 --> x == 5
+ %B = icmp eq i64 %A, 1
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp3
+; CHECK: icmp eq i64 %X, -5
+define i1 @sdiv_icmp3(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, 5 ; X/5 == -1 --> x == -5
+ %B = icmp eq i64 %A, -1
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp4
+; CHECK: icmp eq i64 %X, 0
+define i1 @sdiv_icmp4(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, -5 ; X/-5 == 0 --> x == 0
+ %B = icmp eq i64 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp5
+; CHECK: icmp eq i64 %X, -5
+define i1 @sdiv_icmp5(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, -5 ; X/-5 == 1 --> x == -5
+ %B = icmp eq i64 %A, 1
+ ret i1 %B
+}
+
+; CHECK: @sdiv_icmp6
+; CHECK: icmp eq i64 %X, 5
+define i1 @sdiv_icmp6(i64 %X) nounwind {
+ %A = sdiv exact i64 %X, -5 ; X/-5 == 1 --> x == 5
+ %B = icmp eq i64 %A, -1
+ ret i1 %B
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/extractvalue.ll b/src/LLVM/test/Transforms/InstCombine/extractvalue.ll
new file mode 100644
index 0000000..cf36b8f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/extractvalue.ll
@@ -0,0 +1,107 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @bar({i32, i32} %a)
+declare i32 @baz(i32 %a)
+
+; CHECK: define i32 @foo
+; CHECK-NOT: extractvalue
+define i32 @foo(i32 %a, i32 %b) {
+; Instcombine should fold various combinations of insertvalue and extractvalue
+; together
+ ; Build a simple struct and pull values out again
+ %s1.1 = insertvalue {i32, i32} undef, i32 %a, 0
+ %s1 = insertvalue {i32, i32} %s1.1, i32 %b, 1
+ %v1 = extractvalue {i32, i32} %s1, 0
+ %v2 = extractvalue {i32, i32} %s1, 1
+
+ ; Build a nested struct and pull a sub struct out of it
+ ; This requires instcombine to insert a few insertvalue instructions
+ %ns1.1 = insertvalue {i32, {i32, i32}} undef, i32 %v1, 0
+ %ns1.2 = insertvalue {i32, {i32, i32}} %ns1.1, i32 %v1, 1, 0
+ %ns1 = insertvalue {i32, {i32, i32}} %ns1.2, i32 %v2, 1, 1
+ %s2 = extractvalue {i32, {i32, i32}} %ns1, 1
+ %v3 = extractvalue {i32, {i32, i32}} %ns1, 1, 1
+ call void @bar({i32, i32} %s2)
+
+ ; Use nested extractvalues to get to a value
+ %s3 = extractvalue {i32, {i32, i32}} %ns1, 1
+ %v4 = extractvalue {i32, i32} %s3, 1
+ call void @bar({i32, i32} %s3)
+
+ ; Use nested insertvalues to build a nested struct
+ %s4.1 = insertvalue {i32, i32} undef, i32 %v3, 0
+ %s4 = insertvalue {i32, i32} %s4.1, i32 %v4, 1
+ %ns2 = insertvalue {i32, {i32, i32}} undef, {i32, i32} %s4, 1
+
+ ; And now extract a single value from there
+ %v5 = extractvalue {i32, {i32, i32}} %ns2, 1, 1
+
+ ret i32 %v5
+}
+
+; CHECK: define i32 @extract2gep
+; CHECK-NEXT: [[GEP:%[a-z0-9]+]] = getelementptr inbounds {{.*}}* %pair, i32 0, i32 1
+; CHECK-NEXT: [[LOAD:%[A-Za-z0-9]+]] = load i32* [[GEP]]
+; CHECK-NEXT: store
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: extractvalue
+; CHECK: call {{.*}}(i32 [[LOAD]])
+; CHECK-NOT: extractvalue
+; CHECK: ret i32 [[LOAD]]
+define i32 @extract2gep({i32, i32}* %pair, i32* %P) {
+ ; The load + extractvalue should be converted
+ ; to an inbounds gep + smaller load.
+ ; The new load should be in the same spot as the old load.
+ %L = load {i32, i32}* %pair
+ store i32 0, i32* %P
+ br label %loop
+
+loop:
+ %E = extractvalue {i32, i32} %L, 1
+ %C = call i32 @baz(i32 %E)
+ store i32 %C, i32* %P
+ %cond = icmp eq i32 %C, 0
+ br i1 %cond, label %end, label %loop
+
+end:
+ ret i32 %E
+}
+
+; CHECK: define i32 @doubleextract2gep
+; CHECK-NEXT: [[GEP:%[a-z0-9]+]] = getelementptr inbounds {{.*}}* %arg, i32 0, i32 1, i32 1
+; CHECK-NEXT: [[LOAD:%[A-Za-z0-9]+]] = load i32* [[GEP]]
+; CHECK-NEXT: ret i32 [[LOAD]]
+define i32 @doubleextract2gep({i32, {i32, i32}}* %arg) {
+ ; The load + extractvalues should be converted
+ ; to a 3-index inbounds gep + smaller load.
+ %L = load {i32, {i32, i32}}* %arg
+ %E1 = extractvalue {i32, {i32, i32}} %L, 1
+ %E2 = extractvalue {i32, i32} %E1, 1
+ ret i32 %E2
+}
+
+; CHECK: define i32 @nogep-multiuse
+; CHECK-NEXT: load {{.*}} %pair
+; CHECK-NEXT: extractvalue
+; CHECK-NEXT: extractvalue
+; CHECK-NEXT: add
+; CHECK-NEXT: ret
+define i32 @nogep-multiuse({i32, i32}* %pair) {
+ ; The load should be left unchanged since both parts are needed.
+ %L = volatile load {i32, i32}* %pair
+ %LHS = extractvalue {i32, i32} %L, 0
+ %RHS = extractvalue {i32, i32} %L, 1
+ %R = add i32 %LHS, %RHS
+ ret i32 %R
+}
+
+; CHECK: define i32 @nogep-volatile
+; CHECK-NEXT: load volatile {{.*}} %pair
+; CHECK-NEXT: extractvalue
+; CHECK-NEXT: ret
+define i32 @nogep-volatile({i32, i32}* %pair) {
+ ; The volatile load should be left unchanged.
+ %L = volatile load {i32, i32}* %pair
+ %E = extractvalue {i32, i32} %L, 1
+ ret i32 %E
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fcmp-select.ll b/src/LLVM/test/Transforms/InstCombine/fcmp-select.ll
new file mode 100644
index 0000000..e04ab3e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fcmp-select.ll
@@ -0,0 +1,53 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; x != y ? x : y -> x if it's the right kind of != and at least
+; one of x and y is not negative zero.
+
+; CHECK: f0
+; CHECK: ret double %x
+define double @f0(double %x) nounwind readnone {
+entry:
+ %cmp = fcmp une double %x, -1.0
+ %cond = select i1 %cmp, double %x, double -1.0
+ ret double %cond
+}
+; CHECK: f1
+; CHECK: ret double -1.000000e+00
+define double @f1(double %x) nounwind readnone {
+entry:
+ %cmp = fcmp une double %x, -1.0
+ %cond = select i1 %cmp, double -1.0, double %x
+ ret double %cond
+}
+; CHECK: f2
+; CHECK: ret double %cond
+define double @f2(double %x, double %y) nounwind readnone {
+entry:
+ %cmp = fcmp une double %x, %y
+ %cond = select i1 %cmp, double %x, double %y
+ ret double %cond
+}
+; CHECK: f3
+; CHECK: ret double %cond
+define double @f3(double %x, double %y) nounwind readnone {
+entry:
+ %cmp = fcmp une double %x, %y
+ %cond = select i1 %cmp, double %y, double %x
+ ret double %cond
+}
+; CHECK: f4
+; CHECK: ret double %cond
+define double @f4(double %x) nounwind readnone {
+entry:
+ %cmp = fcmp one double %x, -1.0
+ %cond = select i1 %cmp, double %x, double -1.0
+ ret double %cond
+}
+; CHECK: f5
+; CHECK: ret double %cond
+define double @f5(double %x) nounwind readnone {
+entry:
+ %cmp = fcmp one double %x, -1.0
+ %cond = select i1 %cmp, double -1.0, double %x
+ ret double %cond
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fcmp-special.ll b/src/LLVM/test/Transforms/InstCombine/fcmp-special.ll
new file mode 100644
index 0000000..a39021e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fcmp-special.ll
@@ -0,0 +1,155 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Infinity
+
+; CHECK: inf0
+; CHECK: ret i1 false
+define i1 @inf0(double %arg) nounwind readnone {
+ %tmp = fcmp ogt double %arg, 0x7FF0000000000000
+ ret i1 %tmp
+}
+
+; CHECK: inf1
+; CHECK: ret i1 true
+define i1 @inf1(double %arg) nounwind readnone {
+ %tmp = fcmp ule double %arg, 0x7FF0000000000000
+ ret i1 %tmp
+}
+
+; Negative infinity
+
+; CHECK: ninf0
+; CHECK: ret i1 false
+define i1 @ninf0(double %arg) nounwind readnone {
+ %tmp = fcmp olt double %arg, 0xFFF0000000000000
+ ret i1 %tmp
+}
+
+; CHECK: ninf1
+; CHECK: ret i1 true
+define i1 @ninf1(double %arg) nounwind readnone {
+ %tmp = fcmp uge double %arg, 0xFFF0000000000000
+ ret i1 %tmp
+}
+
+; NaNs
+
+; CHECK: nan0
+; CHECK: ret i1 false
+define i1 @nan0(double %arg) nounwind readnone {
+ %tmp = fcmp ord double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nan1
+; CHECK: ret i1 false
+define i1 @nan1(double %arg) nounwind readnone {
+ %tmp = fcmp oeq double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nan2
+; CHECK: ret i1 false
+define i1 @nan2(double %arg) nounwind readnone {
+ %tmp = fcmp olt double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nan3
+; CHECK: ret i1 true
+define i1 @nan3(double %arg) nounwind readnone {
+ %tmp = fcmp uno double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nan4
+; CHECK: ret i1 true
+define i1 @nan4(double %arg) nounwind readnone {
+ %tmp = fcmp une double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nan5
+; CHECK: ret i1 true
+define i1 @nan5(double %arg) nounwind readnone {
+ %tmp = fcmp ult double %arg, 0x7FF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; Negative NaN.
+
+; CHECK: nnan0
+; CHECK: ret i1 false
+define i1 @nnan0(double %arg) nounwind readnone {
+ %tmp = fcmp ord double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nnan1
+; CHECK: ret i1 false
+define i1 @nnan1(double %arg) nounwind readnone {
+ %tmp = fcmp oeq double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nnan2
+; CHECK: ret i1 false
+define i1 @nnan2(double %arg) nounwind readnone {
+ %tmp = fcmp olt double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nnan3
+; CHECK: ret i1 true
+define i1 @nnan3(double %arg) nounwind readnone {
+ %tmp = fcmp uno double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nnan4
+; CHECK: ret i1 true
+define i1 @nnan4(double %arg) nounwind readnone {
+ %tmp = fcmp une double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; CHECK: nnan5
+; CHECK: ret i1 true
+define i1 @nnan5(double %arg) nounwind readnone {
+ %tmp = fcmp ult double %arg, 0xFFF00000FFFFFFFF
+ ret i1 %tmp
+}
+
+; Negative zero.
+
+; CHECK: nzero0
+; CHECK: ret i1 true
+define i1 @nzero0() {
+ %tmp = fcmp oeq double 0.0, -0.0
+ ret i1 %tmp
+}
+
+; CHECK: nzero1
+; CHECK: ret i1 false
+define i1 @nzero1() {
+ %tmp = fcmp ogt double 0.0, -0.0
+ ret i1 %tmp
+}
+
+; Misc.
+
+; CHECK: misc0
+; CHECK: %tmp = fcmp ord double %arg, 0.000000e+00
+; CHECK: ret i1 %tmp
+define i1 @misc0(double %arg) {
+ %tmp = fcmp oeq double %arg, %arg
+ ret i1 %tmp
+}
+
+; CHECK: misc1
+; CHECK: ret i1 false
+define i1 @misc1(double %arg) {
+ %tmp = fcmp one double %arg, %arg
+ ret i1 %tmp
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/fcmp.ll b/src/LLVM/test/Transforms/InstCombine/fcmp.ll
new file mode 100644
index 0000000..d08cbf5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fcmp.ll
@@ -0,0 +1,71 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define i1 @test1(float %x, float %y) nounwind {
+ %ext1 = fpext float %x to double
+ %ext2 = fpext float %y to double
+ %cmp = fcmp ogt double %ext1, %ext2
+ ret i1 %cmp
+; CHECK: @test1
+; CHECK-NEXT: fcmp ogt float %x, %y
+}
+
+define i1 @test2(float %a) nounwind {
+ %ext = fpext float %a to double
+ %cmp = fcmp ogt double %ext, 1.000000e+00
+ ret i1 %cmp
+; CHECK: @test2
+; CHECK-NEXT: fcmp ogt float %a, 1.0
+}
+
+define i1 @test3(float %a) nounwind {
+ %ext = fpext float %a to double
+ %cmp = fcmp ogt double %ext, 0x3FF0000000000001 ; more precision than float.
+ ret i1 %cmp
+; CHECK: @test3
+; CHECK-NEXT: fpext float %a to double
+}
+
+define i1 @test4(float %a) nounwind {
+ %ext = fpext float %a to double
+ %cmp = fcmp ogt double %ext, 0x36A0000000000000 ; denormal in float.
+ ret i1 %cmp
+; CHECK: @test4
+; CHECK-NEXT: fpext float %a to double
+}
+
+define i1 @test5(float %a) nounwind {
+ %neg = fsub float -0.000000e+00, %a
+ %cmp = fcmp ogt float %neg, 1.000000e+00
+ ret i1 %cmp
+; CHECK: @test5
+; CHECK-NEXT: fcmp olt float %a, -1.0
+}
+
+define i1 @test6(float %x, float %y) nounwind {
+ %neg1 = fsub float -0.000000e+00, %x
+ %neg2 = fsub float -0.000000e+00, %y
+ %cmp = fcmp olt float %neg1, %neg2
+ ret i1 %cmp
+; CHECK: @test6
+; CHECK-NEXT: fcmp ogt float %x, %y
+}
+
+define i1 @test7(float %x) nounwind readnone ssp noredzone {
+ %ext = fpext float %x to ppc_fp128
+ %cmp = fcmp ogt ppc_fp128 %ext, 0xM00000000000000000000000000000000
+ ret i1 %cmp
+; Can't convert ppc_fp128
+; CHECK: @test7
+; CHECK-NEXT: fpext float %x to ppc_fp128
+}
+
+define float @test8(float %x) nounwind readnone optsize ssp {
+ %conv = fpext float %x to double
+ %cmp = fcmp olt double %conv, 0.000000e+00
+ %conv1 = zext i1 %cmp to i32
+ %conv2 = sitofp i32 %conv1 to float
+ ret float %conv2
+; Float comparison to zero shouldn't cast to double.
+; CHECK: @test8
+; CHECK-NEXT: fcmp olt float %x, 0.000000e+00
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fdiv.ll b/src/LLVM/test/Transforms/InstCombine/fdiv.ll
new file mode 100644
index 0000000..a2cce01
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fdiv.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define float @test1(float %x) nounwind readnone ssp {
+ %div = fdiv float %x, 0x3810000000000000
+ ret float %div
+
+; CHECK: @test1
+; CHECK-NEXT: fmul float %x, 0x47D0000000000000
+}
+
+define float @test2(float %x) nounwind readnone ssp {
+ %div = fdiv float %x, 0x47E0000000000000
+ ret float %div
+
+; CHECK: @test2
+; CHECK-NEXT: fdiv float %x, 0x47E0000000000000
+}
+
+define float @test3(float %x) nounwind readnone ssp {
+ %div = fdiv float %x, 0x36A0000000000000
+ ret float %div
+
+; CHECK: @test3
+; CHECK-NEXT: fdiv float %x, 0x36A0000000000000
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fold-bin-operand.ll b/src/LLVM/test/Transforms/InstCombine/fold-bin-operand.ll
new file mode 100644
index 0000000..a8bad0d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fold-bin-operand.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+define i1 @f(i1 %x) {
+; CHECK: @f
+; CHECK: ret i1 false
+ %b = and i1 %x, icmp eq (i8* inttoptr (i32 1 to i8*), i8* inttoptr (i32 2 to i8*))
+ ret i1 %b
+}
+
+define i32 @g(i32 %x) {
+; CHECK: @g
+; CHECK: ret i32 %x
+ %b = add i32 %x, zext (i1 icmp eq (i8* inttoptr (i32 1000000 to i8*), i8* inttoptr (i32 2000000 to i8*)) to i32)
+ ret i32 %b
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/fold-calls.ll b/src/LLVM/test/Transforms/InstCombine/fold-calls.ll
new file mode 100644
index 0000000..504f874
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fold-calls.ll
@@ -0,0 +1,19 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+; This shouldn't fold, because sin(inf) is invalid.
+; CHECK: @foo
+; CHECK: %t = call double @sin(double 0x7FF0000000000000)
+define double @foo() {
+ %t = call double @sin(double 0x7FF0000000000000)
+ ret double %t
+}
+
+; This should fold.
+; CHECK: @bar
+; CHECK: ret double 0.0
+define double @bar() {
+ %t = call double @sin(double 0.0)
+ ret double %t
+}
+
+declare double @sin(double)
diff --git a/src/LLVM/test/Transforms/InstCombine/fold-vector-select.ll b/src/LLVM/test/Transforms/InstCombine/fold-vector-select.ll
new file mode 100644
index 0000000..4af2872
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fold-vector-select.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | not grep select
+
+define void @foo(<4 x i32> *%A, <4 x i32> *%B, <4 x i32> *%C, <4 x i32> *%D) {
+ %r = select <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32> zeroinitializer
+ %g = select <4 x i1> <i1 false, i1 false, i1 false, i1 false>, <4 x i32> zeroinitializer, <4 x i32> <i32 3, i32 6, i32 9, i32 1>
+ %b = select <4 x i1> <i1 false, i1 true, i1 false, i1 true>, <4 x i32> zeroinitializer, <4 x i32> <i32 7, i32 1, i32 4, i32 9>
+ %a = select <4 x i1> zeroinitializer, <4 x i32> zeroinitializer, <4 x i32> <i32 3, i32 2, i32 8, i32 5>
+ store <4 x i32> %r, <4 x i32>* %A
+ store <4 x i32> %g, <4 x i32>* %B
+ store <4 x i32> %b, <4 x i32>* %C
+ store <4 x i32> %a, <4 x i32>* %D
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fold-vector-zero.ll b/src/LLVM/test/Transforms/InstCombine/fold-vector-zero.ll
new file mode 100644
index 0000000..e1d86b6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fold-vector-zero.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -instcombine -S | not grep zeroinitializer
+
+define void @foo(i64 %A, i64 %B) {
+bb8:
+ br label %bb30
+
+bb30:
+ %s0 = phi i64 [ 0, %bb8 ], [ %r21, %bb30 ]
+ %l0 = phi i64 [ -2222, %bb8 ], [ %r23, %bb30 ]
+ %r2 = add i64 %s0, %B
+ %r3 = inttoptr i64 %r2 to <2 x double>*
+ %r4 = load <2 x double>* %r3, align 8
+ %r6 = bitcast <2 x double> %r4 to <2 x i64>
+ %r7 = bitcast <2 x double> zeroinitializer to <2 x i64>
+ %r8 = insertelement <2 x i64> undef, i64 9223372036854775807, i32 0
+ %r9 = insertelement <2 x i64> undef, i64 -9223372036854775808, i32 0
+ %r10 = insertelement <2 x i64> %r8, i64 9223372036854775807, i32 1
+ %r11 = insertelement <2 x i64> %r9, i64 -9223372036854775808, i32 1
+ %r12 = and <2 x i64> %r6, %r10
+ %r13 = and <2 x i64> %r7, %r11
+ %r14 = or <2 x i64> %r12, %r13
+ %r15 = bitcast <2 x i64> %r14 to <2 x double>
+ %r18 = add i64 %s0, %A
+ %r19 = inttoptr i64 %r18 to <2 x double>*
+ store <2 x double> %r15, <2 x double>* %r19, align 8
+ %r21 = add i64 16, %s0
+ %r23 = add i64 1, %l0
+ %r25 = icmp slt i64 %r23, 0
+ %r26 = zext i1 %r25 to i64
+ %r27 = icmp ne i64 %r26, 0
+ br i1 %r27, label %bb30, label %bb5
+
+bb5:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/fp-ret-bitcast.ll b/src/LLVM/test/Transforms/InstCombine/fp-ret-bitcast.ll
new file mode 100644
index 0000000..35ece42
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fp-ret-bitcast.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {call float bitcast} | count 1
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+ %struct.NSObject = type { %struct.objc_class* }
+ %struct.NSArray = type { %struct.NSObject }
+ %struct.objc_class = type opaque
+ %struct.objc_selector = type opaque
+
+@"\01L_OBJC_METH_VAR_NAME_112" = internal global [15 x i8] c"whiteComponent\00", section "__TEXT,__cstring,cstring_literals"
+@"\01L_OBJC_SELECTOR_REFERENCES_81" = internal global %struct.objc_selector* bitcast ([15 x i8]* @"\01L_OBJC_METH_VAR_NAME_112" to %struct.objc_selector*), section "__OBJC,__message_refs,literal_pointers,no_dead_strip"
+
+define void @bork() nounwind {
+entry:
+ %color = alloca %struct.NSArray*
+ %color.466 = alloca %struct.NSObject*
+ %tmp103 = load %struct.NSArray** %color, align 4
+ %tmp103104 = getelementptr %struct.NSArray* %tmp103, i32 0, i32 0
+ store %struct.NSObject* %tmp103104, %struct.NSObject** %color.466, align 4
+ %tmp105 = load %struct.objc_selector** @"\01L_OBJC_SELECTOR_REFERENCES_81", align 4
+ %tmp106 = load %struct.NSObject** %color.466, align 4
+ %tmp107 = call float bitcast (void (%struct.NSObject*, ...)* @objc_msgSend_fpret to float (%struct.NSObject*, %struct.objc_selector*)*)( %struct.NSObject* %tmp106, %struct.objc_selector* %tmp105 ) nounwind
+ br label %exit
+
+exit:
+ ret void
+}
+
+declare void @objc_msgSend_fpret(%struct.NSObject*, ...)
diff --git a/src/LLVM/test/Transforms/InstCombine/fpcast.ll b/src/LLVM/test/Transforms/InstCombine/fpcast.ll
new file mode 100644
index 0000000..f3f42cf
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fpcast.ll
@@ -0,0 +1,15 @@
+; Test some floating point casting cases
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i8 @test1() {
+ %x = fptoui float 2.550000e+02 to i8 ; <i8> [#uses=1]
+ ret i8 %x
+; CHECK: ret i8 -1
+}
+
+define i8 @test2() {
+ %x = fptosi float -1.000000e+00 to i8 ; <i8> [#uses=1]
+ ret i8 %x
+; CHECK: ret i8 -1
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/fpextend.ll b/src/LLVM/test/Transforms/InstCombine/fpextend.ll
new file mode 100644
index 0000000..70e0c62
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fpextend.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -instcombine -S | not grep fpext
+@X = external global float
+@Y = external global float
+
+define void @test() nounwind {
+entry:
+ %tmp = load float* @X, align 4 ; <float> [#uses=1]
+ %tmp1 = fpext float %tmp to double ; <double> [#uses=1]
+ %tmp3 = fadd double %tmp1, 0.000000e+00 ; <double> [#uses=1]
+ %tmp34 = fptrunc double %tmp3 to float ; <float> [#uses=1]
+ store float %tmp34, float* @X, align 4
+ ret void
+}
+
+define void @test3() nounwind {
+entry:
+ %tmp = load float* @X, align 4 ; <float> [#uses=1]
+ %tmp1 = fpext float %tmp to double ; <double> [#uses=1]
+ %tmp2 = load float* @Y, align 4 ; <float> [#uses=1]
+ %tmp23 = fpext float %tmp2 to double ; <double> [#uses=1]
+ %tmp5 = fdiv double %tmp1, %tmp23 ; <double> [#uses=1]
+ %tmp56 = fptrunc double %tmp5 to float ; <float> [#uses=1]
+ store float %tmp56, float* @X, align 4
+ ret void
+}
+
+define void @test4() nounwind {
+entry:
+ %tmp = load float* @X, align 4 ; <float> [#uses=1]
+ %tmp1 = fpext float %tmp to double ; <double> [#uses=1]
+ %tmp2 = fsub double -0.000000e+00, %tmp1 ; <double> [#uses=1]
+ %tmp34 = fptrunc double %tmp2 to float ; <float> [#uses=1]
+ store float %tmp34, float* @X, align 4
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/fsub.ll b/src/LLVM/test/Transforms/InstCombine/fsub.ll
new file mode 100644
index 0000000..af2fadd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/fsub.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; PR4374
+define float @test1(float %a, float %b) nounwind {
+ %t1 = fsub float %a, %b
+ %t2 = fsub float -0.000000e+00, %t1
+
+; CHECK: %t1 = fsub float %a, %b
+; CHECK-NEXT: %t2 = fsub float -0.000000e+00, %t1
+
+ ret float %t2
+}
+
+; <rdar://problem/7530098>
+define double @test2(double %x, double %y) nounwind {
+ %t1 = fadd double %x, %y
+ %t2 = fsub double %x, %t1
+
+; CHECK: %t1 = fadd double %x, %y
+; CHECK-NEXT: %t2 = fsub double %x, %t1
+
+ ret double %t2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/gep-addrspace.ll b/src/LLVM/test/Transforms/InstCombine/gep-addrspace.ll
new file mode 100644
index 0000000..dfe12db
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/gep-addrspace.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-pc-win32"
+
+%myStruct = type { float, [3 x float], [4 x float], i32 }
+
+; make sure that we are not crashing when creating an illegal type
+define void @func(%myStruct addrspace(1)* nocapture %p) nounwind {
+ST:
+ %A = getelementptr inbounds %myStruct addrspace(1)* %p, i64 0
+ %B = bitcast %myStruct addrspace(1)* %A to %myStruct*
+ %C = getelementptr inbounds %myStruct* %B, i32 0, i32 1
+ %D = getelementptr inbounds [3 x float]* %C, i32 0, i32 2
+ %E = load float* %D, align 4
+ %F = fsub float %E, undef
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/gepgep.ll b/src/LLVM/test/Transforms/InstCombine/gepgep.ll
new file mode 100644
index 0000000..9e681d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/gepgep.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+@buffer = external global [64 x float]
+
+declare void @use(i8*)
+
+define void @f() {
+ call void @use(i8* getelementptr (i8* getelementptr (i8* bitcast ([64 x float]* @buffer to i8*), i64 and (i64 sub (i64 0, i64 ptrtoint ([64 x float]* @buffer to i64)), i64 63)), i64 64))
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/getelementptr.ll b/src/LLVM/test/Transforms/InstCombine/getelementptr.ll
new file mode 100644
index 0000000..6bb2035
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/getelementptr.ll
@@ -0,0 +1,494 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64"
+%intstruct = type { i32 }
+%pair = type { i32, i32 }
+%struct.B = type { double }
+%struct.A = type { %struct.B, i32, i32 }
+
+
+@Global = constant [10 x i8] c"helloworld"
+
+; Test noop elimination
+define i32* @test1(i32* %I) {
+ %A = getelementptr i32* %I, i64 0
+ ret i32* %A
+; CHECK: @test1
+; CHECK: ret i32* %I
+}
+
+; Test noop elimination
+define i32* @test2(i32* %I) {
+ %A = getelementptr i32* %I
+ ret i32* %A
+; CHECK: @test2
+; CHECK: ret i32* %I
+}
+
+; Test that two array indexing geps fold
+define i32* @test3(i32* %I) {
+ %A = getelementptr i32* %I, i64 17
+ %B = getelementptr i32* %A, i64 4
+ ret i32* %B
+; CHECK: @test3
+; CHECK: getelementptr i32* %I, i64 21
+}
+
+; Test that two getelementptr insts fold
+define i32* @test4({ i32 }* %I) {
+ %A = getelementptr { i32 }* %I, i64 1
+ %B = getelementptr { i32 }* %A, i64 0, i32 0
+ ret i32* %B
+; CHECK: @test4
+; CHECK: getelementptr { i32 }* %I, i64 1, i32 0
+}
+
+define void @test5(i8 %B) {
+ ; This should be turned into a constexpr instead of being an instruction
+ %A = getelementptr [10 x i8]* @Global, i64 0, i64 4
+ store i8 %B, i8* %A
+ ret void
+; CHECK: @test5
+; CHECK: store i8 %B, i8* getelementptr inbounds ([10 x i8]* @Global, i64 0, i64 4)
+}
+
+
+define i32* @test7(i32* %I, i64 %C, i64 %D) {
+ %A = getelementptr i32* %I, i64 %C
+ %B = getelementptr i32* %A, i64 %D
+ ret i32* %B
+; CHECK: @test7
+; CHECK: %A.sum = add i64 %C, %D
+; CHECK: getelementptr i32* %I, i64 %A.sum
+}
+
+define i8* @test8([10 x i32]* %X) {
+ ;; Fold into the cast.
+ %A = getelementptr [10 x i32]* %X, i64 0, i64 0
+ %B = bitcast i32* %A to i8*
+ ret i8* %B
+; CHECK: @test8
+; CHECK: bitcast [10 x i32]* %X to i8*
+}
+
+define i32 @test9() {
+ %A = getelementptr { i32, double }* null, i32 0, i32 1
+ %B = ptrtoint double* %A to i32
+ ret i32 %B
+; CHECK: @test9
+; CHECK: ret i32 8
+}
+
+define i1 @test10({ i32, i32 }* %x, { i32, i32 }* %y) {
+ %tmp.1 = getelementptr { i32, i32 }* %x, i32 0, i32 1
+ %tmp.3 = getelementptr { i32, i32 }* %y, i32 0, i32 1
+ ;; seteq x, y
+ %tmp.4 = icmp eq i32* %tmp.1, %tmp.3
+ ret i1 %tmp.4
+; CHECK: @test10
+; CHECK: icmp eq { i32, i32 }* %x, %y
+}
+
+define i1 @test11({ i32, i32 }* %X) {
+ %P = getelementptr { i32, i32 }* %X, i32 0, i32 0
+ %Q = icmp eq i32* %P, null
+ ret i1 %Q
+; CHECK: @test11
+; CHECK: icmp eq { i32, i32 }* %X, null
+}
+
+
+; PR4748
+define i32 @test12(%struct.A* %a) {
+entry:
+ %g3 = getelementptr %struct.A* %a, i32 0, i32 1
+ store i32 10, i32* %g3, align 4
+
+ %g4 = getelementptr %struct.A* %a, i32 0, i32 0
+
+ %new_a = bitcast %struct.B* %g4 to %struct.A*
+
+ %g5 = getelementptr %struct.A* %new_a, i32 0, i32 1
+ %a_a = load i32* %g5, align 4
+ ret i32 %a_a
+; CHECK: @test12
+; CHECK: getelementptr %struct.A* %a, i64 0, i32 1
+; CHECK-NEXT: store i32 10, i32* %g3
+; CHECK-NEXT: ret i32 10
+}
+
+
+; PR2235
+%S = type { i32, [ 100 x i32] }
+define i1 @test13(i64 %X, %S* %P) {
+ %A = getelementptr inbounds %S* %P, i32 0, i32 1, i64 %X
+ %B = getelementptr inbounds %S* %P, i32 0, i32 0
+ %C = icmp eq i32* %A, %B
+ ret i1 %C
+; CHECK: @test13
+; CHECK: %C = icmp eq i64 %X, -1
+}
+
+
+@G = external global [3 x i8]
+define i8* @test14(i32 %Idx) {
+ %idx = zext i32 %Idx to i64
+ %tmp = getelementptr i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i64 %idx
+ ret i8* %tmp
+; CHECK: @test14
+; CHECK: getelementptr [3 x i8]* @G, i64 0, i64 %idx
+}
+
+
+; Test folding of constantexpr geps into normal geps.
+@Array = external global [40 x i32]
+define i32 *@test15(i64 %X) {
+ %A = getelementptr i32* getelementptr ([40 x i32]* @Array, i64 0, i64 0), i64 %X
+ ret i32* %A
+; CHECK: @test15
+; CHECK: getelementptr [40 x i32]* @Array, i64 0, i64 %X
+}
+
+
+define i32* @test16(i32* %X, i32 %Idx) {
+ %R = getelementptr i32* %X, i32 %Idx
+ ret i32* %R
+; CHECK: @test16
+; CHECK: sext i32 %Idx to i64
+}
+
+
+define i1 @test17(i16* %P, i32 %I, i32 %J) {
+ %X = getelementptr inbounds i16* %P, i32 %I
+ %Y = getelementptr inbounds i16* %P, i32 %J
+ %C = icmp ult i16* %X, %Y
+ ret i1 %C
+; CHECK: @test17
+; CHECK: %C = icmp slt i32 %I, %J
+}
+
+define i1 @test18(i16* %P, i32 %I) {
+ %X = getelementptr inbounds i16* %P, i32 %I
+ %C = icmp ult i16* %X, %P
+ ret i1 %C
+; CHECK: @test18
+; CHECK: %C = icmp slt i32 %I, 0
+}
+
+define i32 @test19(i32* %P, i32 %A, i32 %B) {
+ %tmp.4 = getelementptr inbounds i32* %P, i32 %A
+ %tmp.9 = getelementptr inbounds i32* %P, i32 %B
+ %tmp.10 = icmp eq i32* %tmp.4, %tmp.9
+ %tmp.11 = zext i1 %tmp.10 to i32
+ ret i32 %tmp.11
+; CHECK: @test19
+; CHECK: icmp eq i32 %A, %B
+}
+
+define i32 @test20(i32* %P, i32 %A, i32 %B) {
+ %tmp.4 = getelementptr inbounds i32* %P, i32 %A
+ %tmp.6 = icmp eq i32* %tmp.4, %P
+ %tmp.7 = zext i1 %tmp.6 to i32
+ ret i32 %tmp.7
+; CHECK: @test20
+; CHECK: icmp eq i32 %A, 0
+}
+
+
+define i32 @test21() {
+ %pbob1 = alloca %intstruct
+ %pbob2 = getelementptr %intstruct* %pbob1
+ %pbobel = getelementptr %intstruct* %pbob2, i64 0, i32 0
+ %rval = load i32* %pbobel
+ ret i32 %rval
+; CHECK: @test21
+; CHECK: getelementptr %intstruct* %pbob1, i64 0, i32 0
+}
+
+
+@A = global i32 1 ; <i32*> [#uses=1]
+@B = global i32 2 ; <i32*> [#uses=1]
+
+define i1 @test22() {
+ %C = icmp ult i32* getelementptr (i32* @A, i64 1),
+ getelementptr (i32* @B, i64 2)
+ ret i1 %C
+; CHECK: @test22
+; CHECK: icmp ult (i32* getelementptr inbounds (i32* @A, i64 1), i32* getelementptr (i32* @B, i64 2))
+}
+
+
+%X = type { [10 x i32], float }
+
+define i1 @test23() {
+ %A = getelementptr %X* null, i64 0, i32 0, i64 0 ; <i32*> [#uses=1]
+ %B = icmp ne i32* %A, null ; <i1> [#uses=1]
+ ret i1 %B
+; CHECK: @test23
+; CHECK: ret i1 false
+}
+
+define void @test25() {
+entry:
+ %tmp = getelementptr { i64, i64, i64, i64 }* null, i32 0, i32 3 ; <i64*> [#uses=1]
+ %tmp.upgrd.1 = load i64* %tmp ; <i64> [#uses=1]
+ %tmp8.ui = load i64* null ; <i64> [#uses=1]
+ %tmp8 = bitcast i64 %tmp8.ui to i64 ; <i64> [#uses=1]
+ %tmp9 = and i64 %tmp8, %tmp.upgrd.1 ; <i64> [#uses=1]
+ %sext = trunc i64 %tmp9 to i32 ; <i32> [#uses=1]
+ %tmp27.i = sext i32 %sext to i64 ; <i64> [#uses=1]
+ tail call void @foo25( i32 0, i64 %tmp27.i )
+ unreachable
+; CHECK: @test25
+}
+
+declare void @foo25(i32, i64)
+
+
+; PR1637
+define i1 @test26(i8* %arr) {
+ %X = getelementptr i8* %arr, i32 1
+ %Y = getelementptr i8* %arr, i32 1
+ %test = icmp uge i8* %X, %Y
+ ret i1 %test
+; CHECK: @test26
+; CHECK: ret i1 true
+}
+
+ %struct.__large_struct = type { [100 x i64] }
+ %struct.compat_siginfo = type { i32, i32, i32, { [29 x i32] } }
+ %struct.siginfo_t = type { i32, i32, i32, { { i32, i32, [0 x i8], %struct.sigval_t, i32 }, [88 x i8] } }
+ %struct.sigval_t = type { i8* }
+
+define i32 @test27(%struct.compat_siginfo* %to, %struct.siginfo_t* %from) {
+entry:
+ %from_addr = alloca %struct.siginfo_t*
+ %tmp344 = load %struct.siginfo_t** %from_addr, align 8
+ %tmp345 = getelementptr %struct.siginfo_t* %tmp344, i32 0, i32 3
+ %tmp346 = getelementptr { { i32, i32, [0 x i8], %struct.sigval_t, i32 }, [88 x i8] }* %tmp345, i32 0, i32 0
+ %tmp346347 = bitcast { i32, i32, [0 x i8], %struct.sigval_t, i32 }* %tmp346 to { i32, i32, %struct.sigval_t }*
+ %tmp348 = getelementptr { i32, i32, %struct.sigval_t }* %tmp346347, i32 0, i32 2
+ %tmp349 = getelementptr %struct.sigval_t* %tmp348, i32 0, i32 0
+ %tmp349350 = bitcast i8** %tmp349 to i32*
+ %tmp351 = load i32* %tmp349350, align 8
+ %tmp360 = call i32 asm sideeffect "...",
+ "=r,ir,*m,i,0,~{dirflag},~{fpsr},~{flags}"( i32 %tmp351,
+ %struct.__large_struct* null, i32 -14, i32 0 )
+ unreachable
+; CHECK: @test27
+}
+
+; PR1978
+ %struct.x = type <{ i8 }>
+@.str = internal constant [6 x i8] c"Main!\00"
+@.str1 = internal constant [12 x i8] c"destroy %p\0A\00"
+
+define i32 @test28() nounwind {
+entry:
+ %orientations = alloca [1 x [1 x %struct.x]]
+ %tmp3 = call i32 @puts( i8* getelementptr ([6 x i8]* @.str, i32 0, i32 0) ) nounwind
+ %tmp45 = getelementptr inbounds [1 x [1 x %struct.x]]* %orientations, i32 1, i32 0, i32 0
+ %orientations62 = getelementptr [1 x [1 x %struct.x]]* %orientations, i32 0, i32 0, i32 0
+ br label %bb10
+
+bb10:
+ %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %bb10 ]
+ %tmp.0.reg2mem.0.rec = mul i32 %indvar, -1
+ %tmp12.rec = add i32 %tmp.0.reg2mem.0.rec, -1
+ %tmp12 = getelementptr inbounds %struct.x* %tmp45, i32 %tmp12.rec
+ %tmp16 = call i32 (i8*, ...)* @printf( i8* getelementptr ([12 x i8]* @.str1, i32 0, i32 0), %struct.x* %tmp12 ) nounwind
+ %tmp84 = icmp eq %struct.x* %tmp12, %orientations62
+ %indvar.next = add i32 %indvar, 1
+ br i1 %tmp84, label %bb17, label %bb10
+
+bb17:
+ ret i32 0
+; CHECK: @test28
+; CHECK: icmp eq i32 %indvar, 0
+}
+
+declare i32 @puts(i8*)
+
+declare i32 @printf(i8*, ...)
+
+
+
+
+; rdar://6762290
+ %T = type <{ i64, i64, i64 }>
+define i32 @test29(i8* %start, i32 %X) nounwind {
+entry:
+ %tmp3 = load i64* null
+ %add.ptr = getelementptr i8* %start, i64 %tmp3
+ %tmp158 = load i32* null
+ %add.ptr159 = getelementptr %T* null, i32 %tmp158
+ %add.ptr209 = getelementptr i8* %start, i64 0
+ %add.ptr212 = getelementptr i8* %add.ptr209, i32 %X
+ %cmp214 = icmp ugt i8* %add.ptr212, %add.ptr
+ br i1 %cmp214, label %if.then216, label %if.end363
+
+if.then216:
+ ret i32 1
+
+if.end363:
+ ret i32 0
+; CHECK: @test29
+}
+
+
+; PR3694
+define i32 @test30(i32 %m, i32 %n) nounwind {
+entry:
+ %0 = alloca i32, i32 %n, align 4
+ %1 = bitcast i32* %0 to [0 x i32]*
+ call void @test30f(i32* %0) nounwind
+ %2 = getelementptr [0 x i32]* %1, i32 0, i32 %m
+ %3 = load i32* %2, align 4
+ ret i32 %3
+; CHECK: @test30
+; CHECK: getelementptr i32
+}
+
+declare void @test30f(i32*)
+
+
+
+define i1 @test31(i32* %A) {
+ %B = getelementptr i32* %A, i32 1
+ %C = getelementptr i32* %A, i64 1
+ %V = icmp eq i32* %B, %C
+ ret i1 %V
+; CHECK: @test31
+; CHECK: ret i1 true
+}
+
+
+; PR1345
+define i8* @test32(i8* %v) {
+ %A = alloca [4 x i8*], align 16
+ %B = getelementptr [4 x i8*]* %A, i32 0, i32 0
+ store i8* null, i8** %B
+ %C = bitcast [4 x i8*]* %A to { [16 x i8] }*
+ %D = getelementptr { [16 x i8] }* %C, i32 0, i32 0, i32 8
+ %E = bitcast i8* %D to i8**
+ store i8* %v, i8** %E
+ %F = getelementptr [4 x i8*]* %A, i32 0, i32 2
+ %G = load i8** %F
+ ret i8* %G
+; CHECK: @test32
+; CHECK: %D = getelementptr [4 x i8*]* %A, i64 0, i64 1
+; CHECK: %F = getelementptr [4 x i8*]* %A, i64 0, i64 2
+}
+
+; PR3290
+%struct.Key = type { { i32, i32 } }
+%struct.anon = type <{ i8, [3 x i8], i32 }>
+
+define i32 *@test33(%struct.Key *%A) {
+ %B = bitcast %struct.Key* %A to %struct.anon*
+ %C = getelementptr %struct.anon* %B, i32 0, i32 2
+ ret i32 *%C
+; CHECK: @test33
+; CHECK: getelementptr %struct.Key* %A, i64 0, i32 0, i32 1
+}
+
+
+
+ %T2 = type { i8*, i8 }
+define i8* @test34(i8* %Val, i64 %V) nounwind {
+entry:
+ %A = alloca %T2, align 8
+ %mrv_gep = bitcast %T2* %A to i64*
+ %B = getelementptr %T2* %A, i64 0, i32 0
+
+ store i64 %V, i64* %mrv_gep
+ %C = load i8** %B, align 8
+ ret i8* %C
+; CHECK: @test34
+; CHECK: %V.c = inttoptr i64 %V to i8*
+; CHECK: ret i8* %V.c
+}
+
+%t0 = type { i8*, [19 x i8] }
+%t1 = type { i8*, [0 x i8] }
+
+@array = external global [11 x i8]
+
+@s = external global %t0
+@"\01LC8" = external constant [17 x i8]
+
+; Instcombine should be able to fold this getelementptr.
+
+define i32 @test35() nounwind {
+ call i32 (i8*, ...)* @printf(i8* getelementptr ([17 x i8]* @"\01LC8", i32 0, i32 0),
+ i8* getelementptr (%t1* bitcast (%t0* @s to %t1*), i32 0, i32 1, i32 0)) nounwind
+ ret i32 0
+; CHECK: @test35
+; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) nounwind
+}
+
+; Instcombine should constant-fold the GEP so that indices that have
+; static array extents are within bounds of those array extents.
+; In the below, -1 is not in the range [0,11). After the transformation,
+; the same address is computed, but 3 is in the range of [0,11).
+
+define i8* @test36() nounwind {
+ ret i8* getelementptr ([11 x i8]* @array, i32 0, i64 -1)
+; CHECK: @test36
+; CHECK: ret i8* getelementptr ([11 x i8]* @array, i64 1676976733973595601, i64 4)
+}
+
+; Instcombine shouldn't assume that gep(A,0,1) != gep(A,1,0).
+@A37 = external constant [1 x i8]
+define i1 @test37() nounwind {
+; CHECK: @test37
+; CHECK: ret i1 true
+ %t = icmp eq i8* getelementptr ([1 x i8]* @A37, i64 0, i64 1),
+ getelementptr ([1 x i8]* @A37, i64 1, i64 0)
+ ret i1 %t
+}
+
+; Test index promotion
+define i32* @test38(i32* %I, i32 %n) {
+ %A = getelementptr i32* %I, i32 %n
+ ret i32* %A
+; CHECK: @test38
+; CHECK: = sext i32 %n to i64
+; CHECK: %A = getelementptr i32* %I, i64 %
+}
+
+; Test that we don't duplicate work when the second gep is a "bitcast".
+%pr10322_t = type { i8* }
+declare void @pr10322_f2(%pr10322_t*)
+declare void @pr10322_f3(i8**)
+define void @pr10322_f1(%pr10322_t* %foo) {
+entry:
+ %arrayidx8 = getelementptr inbounds %pr10322_t* %foo, i64 2
+ call void @pr10322_f2(%pr10322_t* %arrayidx8) nounwind
+ %tmp2 = getelementptr inbounds %pr10322_t* %arrayidx8, i64 0, i32 0
+ call void @pr10322_f3(i8** %tmp2) nounwind
+ ret void
+
+; CHECK: @pr10322_f1
+; CHECK: %tmp2 = getelementptr inbounds %pr10322_t* %arrayidx8, i64 0, i32 0
+}
+
+; Test that we combine the last two geps in this sequence, before we
+; would wait for gep1 and gep2 to be combined and never combine 2 and 3.
+%three_gep_t = type {i32}
+%three_gep_t2 = type {%three_gep_t}
+
+define void @three_gep_f(%three_gep_t2* %x) {
+ %gep1 = getelementptr %three_gep_t2* %x, i64 2
+ call void @three_gep_h(%three_gep_t2* %gep1)
+ %gep2 = getelementptr %three_gep_t2* %gep1, i64 0, i32 0
+ %gep3 = getelementptr %three_gep_t* %gep2, i64 0, i32 0
+ call void @three_gep_g(i32* %gep3)
+
+; CHECK: @three_gep_f
+; CHECK: %gep3 = getelementptr %three_gep_t2* %gep1, i64 0, i32 0, i32 0
+ ret void
+}
+
+declare void @three_gep_g(i32*)
+declare void @three_gep_h(%three_gep_t2*)
diff --git a/src/LLVM/test/Transforms/InstCombine/hoist_instr.ll b/src/LLVM/test/Transforms/InstCombine/hoist_instr.ll
new file mode 100644
index 0000000..3bd34d0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/hoist_instr.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+;; This tests that the div is hoisted into the then block.
+define i32 @foo(i1 %C, i32 %A, i32 %B) {
+entry:
+ br i1 %C, label %then, label %endif
+
+then: ; preds = %entry
+; CHECK: then:
+; CHECK-NEXT: sdiv i32
+ br label %endif
+
+endif: ; preds = %then, %entry
+ %X = phi i32 [ %A, %then ], [ 15, %entry ] ; <i32> [#uses=1]
+ %Y = sdiv i32 %X, 42 ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/icmp.ll b/src/LLVM/test/Transforms/InstCombine/icmp.ll
new file mode 100644
index 0000000..bdf72ac
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/icmp.ll
@@ -0,0 +1,561 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout =
+"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+define i32 @test1(i32 %X) {
+entry:
+ icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
+ zext i1 %0 to i32 ; <i32>:1 [#uses=1]
+ ret i32 %1
+; CHECK: @test1
+; CHECK: lshr i32 %X, 31
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test2(i32 %X) {
+entry:
+ icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
+ zext i1 %0 to i32 ; <i32>:1 [#uses=1]
+ ret i32 %1
+; CHECK: @test2
+; CHECK: lshr i32 %X, 31
+; CHECK-NEXT: xor i32
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test3(i32 %X) {
+entry:
+ icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
+ sext i1 %0 to i32 ; <i32>:1 [#uses=1]
+ ret i32 %1
+; CHECK: @test3
+; CHECK: ashr i32 %X, 31
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test4(i32 %X) {
+entry:
+ icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
+ sext i1 %0 to i32 ; <i32>:1 [#uses=1]
+ ret i32 %1
+; CHECK: @test4
+; CHECK: ashr i32 %X, 31
+; CHECK-NEXT: xor i32
+; CHECK-NEXT: ret i32
+}
+
+; PR4837
+define <2 x i1> @test5(<2 x i64> %x) {
+entry:
+ %V = icmp eq <2 x i64> %x, undef
+ ret <2 x i1> %V
+; CHECK: @test5
+; CHECK: ret <2 x i1> <i1 true, i1 true>
+}
+
+define i32 @test6(i32 %a, i32 %b) {
+ %c = icmp sle i32 %a, -1
+ %d = zext i1 %c to i32
+ %e = sub i32 0, %d
+ %f = and i32 %e, %b
+ ret i32 %f
+; CHECK: @test6
+; CHECK-NEXT: ashr i32 %a, 31
+; CHECK-NEXT: %f = and i32 %e, %b
+; CHECK-NEXT: ret i32 %f
+}
+
+
+define i1 @test7(i32 %x) {
+entry:
+ %a = add i32 %x, -1
+ %b = icmp ult i32 %a, %x
+ ret i1 %b
+; CHECK: @test7
+; CHECK: %b = icmp ne i32 %x, 0
+; CHECK: ret i1 %b
+}
+
+define i1 @test8(i32 %x){
+entry:
+ %a = add i32 %x, -1
+ %b = icmp eq i32 %a, %x
+ ret i1 %b
+; CHECK: @test8
+; CHECK: ret i1 false
+}
+
+define i1 @test9(i32 %x) {
+entry:
+ %a = add i32 %x, -2
+ %b = icmp ugt i32 %x, %a
+ ret i1 %b
+; CHECK: @test9
+; CHECK: icmp ugt i32 %x, 1
+; CHECK: ret i1 %b
+}
+
+define i1 @test10(i32 %x){
+entry:
+ %a = add i32 %x, -1
+ %b = icmp slt i32 %a, %x
+ ret i1 %b
+
+; CHECK: @test10
+; CHECK: %b = icmp ne i32 %x, -2147483648
+; CHECK: ret i1 %b
+}
+
+define i1 @test11(i32 %x) {
+ %a = add nsw i32 %x, 8
+ %b = icmp slt i32 %x, %a
+ ret i1 %b
+; CHECK: @test11
+; CHECK: ret i1 true
+}
+
+; PR6195
+define i1 @test12(i1 %A) {
+ %S = select i1 %A, i64 -4294967295, i64 8589934591
+ %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
+ ret i1 %B
+; CHECK: @test12
+; CHECK-NEXT: %B = select i1
+; CHECK-NEXT: ret i1 %B
+}
+
+; PR6481
+define i1 @test13(i8 %X) nounwind readnone {
+entry:
+ %cmp = icmp slt i8 undef, %X
+ ret i1 %cmp
+; CHECK: @test13
+; CHECK: ret i1 false
+}
+
+define i1 @test14(i8 %X) nounwind readnone {
+entry:
+ %cmp = icmp slt i8 undef, -128
+ ret i1 %cmp
+; CHECK: @test14
+; CHECK: ret i1 false
+}
+
+define i1 @test15() nounwind readnone {
+entry:
+ %cmp = icmp eq i8 undef, -128
+ ret i1 %cmp
+; CHECK: @test15
+; CHECK: ret i1 undef
+}
+
+define i1 @test16() nounwind readnone {
+entry:
+ %cmp = icmp ne i8 undef, -128
+ ret i1 %cmp
+; CHECK: @test16
+; CHECK: ret i1 undef
+}
+
+define i1 @test17(i32 %x) nounwind {
+ %shl = shl i32 1, %x
+ %and = and i32 %shl, 8
+ %cmp = icmp eq i32 %and, 0
+ ret i1 %cmp
+; CHECK: @test17
+; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
+}
+
+
+define i1 @test18(i32 %x) nounwind {
+ %sh = lshr i32 8, %x
+ %and = and i32 %sh, 1
+ %cmp = icmp eq i32 %and, 0
+ ret i1 %cmp
+; CHECK: @test18
+; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
+}
+
+define i1 @test19(i32 %x) nounwind {
+ %shl = shl i32 1, %x
+ %and = and i32 %shl, 8
+ %cmp = icmp eq i32 %and, 8
+ ret i1 %cmp
+; CHECK: @test19
+; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
+}
+
+define i1 @test20(i32 %x) nounwind {
+ %shl = shl i32 1, %x
+ %and = and i32 %shl, 8
+ %cmp = icmp ne i32 %and, 0
+ ret i1 %cmp
+; CHECK: @test20
+; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
+}
+
+define i1 @test21(i8 %x, i8 %y) {
+; CHECK: @test21
+; CHECK-NOT: or i8
+; CHECK: icmp ugt
+ %A = or i8 %x, 1
+ %B = icmp ugt i8 %A, 3
+ ret i1 %B
+}
+
+define i1 @test22(i8 %x, i8 %y) {
+; CHECK: @test22
+; CHECK-NOT: or i8
+; CHECK: icmp ult
+ %A = or i8 %x, 1
+ %B = icmp ult i8 %A, 4
+ ret i1 %B
+}
+
+; PR2740
+; CHECK: @test23
+; CHECK: icmp sgt i32 %x, 1328634634
+define i1 @test23(i32 %x) nounwind {
+ %i3 = sdiv i32 %x, -1328634635
+ %i4 = icmp eq i32 %i3, -1
+ ret i1 %i4
+}
+
+@X = global [1000 x i32] zeroinitializer
+
+; PR8882
+; CHECK: @test24
+; CHECK: %cmp = icmp eq i64 %i, 1000
+; CHECK: ret i1 %cmp
+define i1 @test24(i64 %i) {
+ %p1 = getelementptr inbounds i32* getelementptr inbounds ([1000 x i32]* @X, i64 0, i64 0), i64 %i
+ %cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32]* @X, i64 1, i64 0)
+ ret i1 %cmp
+}
+
+; CHECK: @test25
+; X + Z > Y + Z -> X > Y if there is no overflow.
+; CHECK: %c = icmp sgt i32 %x, %y
+; CHECK: ret i1 %c
+define i1 @test25(i32 %x, i32 %y, i32 %z) {
+ %lhs = add nsw i32 %x, %z
+ %rhs = add nsw i32 %y, %z
+ %c = icmp sgt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test26
+; X + Z > Y + Z -> X > Y if there is no overflow.
+; CHECK: %c = icmp ugt i32 %x, %y
+; CHECK: ret i1 %c
+define i1 @test26(i32 %x, i32 %y, i32 %z) {
+ %lhs = add nuw i32 %x, %z
+ %rhs = add nuw i32 %y, %z
+ %c = icmp ugt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test27
+; X - Z > Y - Z -> X > Y if there is no overflow.
+; CHECK: %c = icmp sgt i32 %x, %y
+; CHECK: ret i1 %c
+define i1 @test27(i32 %x, i32 %y, i32 %z) {
+ %lhs = sub nsw i32 %x, %z
+ %rhs = sub nsw i32 %y, %z
+ %c = icmp sgt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test28
+; X - Z > Y - Z -> X > Y if there is no overflow.
+; CHECK: %c = icmp ugt i32 %x, %y
+; CHECK: ret i1 %c
+define i1 @test28(i32 %x, i32 %y, i32 %z) {
+ %lhs = sub nuw i32 %x, %z
+ %rhs = sub nuw i32 %y, %z
+ %c = icmp ugt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test29
+; X + Y > X -> Y > 0 if there is no overflow.
+; CHECK: %c = icmp sgt i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test29(i32 %x, i32 %y) {
+ %lhs = add nsw i32 %x, %y
+ %c = icmp sgt i32 %lhs, %x
+ ret i1 %c
+}
+
+; CHECK: @test30
+; X + Y > X -> Y > 0 if there is no overflow.
+; CHECK: %c = icmp ne i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test30(i32 %x, i32 %y) {
+ %lhs = add nuw i32 %x, %y
+ %c = icmp ugt i32 %lhs, %x
+ ret i1 %c
+}
+
+; CHECK: @test31
+; X > X + Y -> 0 > Y if there is no overflow.
+; CHECK: %c = icmp slt i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test31(i32 %x, i32 %y) {
+ %rhs = add nsw i32 %x, %y
+ %c = icmp sgt i32 %x, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test32
+; X > X + Y -> 0 > Y if there is no overflow.
+; CHECK: ret i1 false
+define i1 @test32(i32 %x, i32 %y) {
+ %rhs = add nuw i32 %x, %y
+ %c = icmp ugt i32 %x, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test33
+; X - Y > X -> 0 > Y if there is no overflow.
+; CHECK: %c = icmp slt i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test33(i32 %x, i32 %y) {
+ %lhs = sub nsw i32 %x, %y
+ %c = icmp sgt i32 %lhs, %x
+ ret i1 %c
+}
+
+; CHECK: @test34
+; X - Y > X -> 0 > Y if there is no overflow.
+; CHECK: ret i1 false
+define i1 @test34(i32 %x, i32 %y) {
+ %lhs = sub nuw i32 %x, %y
+ %c = icmp ugt i32 %lhs, %x
+ ret i1 %c
+}
+
+; CHECK: @test35
+; X > X - Y -> Y > 0 if there is no overflow.
+; CHECK: %c = icmp sgt i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test35(i32 %x, i32 %y) {
+ %rhs = sub nsw i32 %x, %y
+ %c = icmp sgt i32 %x, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test36
+; X > X - Y -> Y > 0 if there is no overflow.
+; CHECK: %c = icmp ne i32 %y, 0
+; CHECK: ret i1 %c
+define i1 @test36(i32 %x, i32 %y) {
+ %rhs = sub nuw i32 %x, %y
+ %c = icmp ugt i32 %x, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test37
+; X - Y > X - Z -> Z > Y if there is no overflow.
+; CHECK: %c = icmp sgt i32 %z, %y
+; CHECK: ret i1 %c
+define i1 @test37(i32 %x, i32 %y, i32 %z) {
+ %lhs = sub nsw i32 %x, %y
+ %rhs = sub nsw i32 %x, %z
+ %c = icmp sgt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; CHECK: @test38
+; X - Y > X - Z -> Z > Y if there is no overflow.
+; CHECK: %c = icmp ugt i32 %z, %y
+; CHECK: ret i1 %c
+define i1 @test38(i32 %x, i32 %y, i32 %z) {
+ %lhs = sub nuw i32 %x, %y
+ %rhs = sub nuw i32 %x, %z
+ %c = icmp ugt i32 %lhs, %rhs
+ ret i1 %c
+}
+
+; PR9343 #1
+; CHECK: @test39
+; CHECK: %B = icmp eq i32 %X, 0
+define i1 @test39(i32 %X, i32 %Y) {
+ %A = ashr exact i32 %X, %Y
+ %B = icmp eq i32 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @test40
+; CHECK: %B = icmp ne i32 %X, 0
+define i1 @test40(i32 %X, i32 %Y) {
+ %A = lshr exact i32 %X, %Y
+ %B = icmp ne i32 %A, 0
+ ret i1 %B
+}
+
+; PR9343 #3
+; CHECK: @test41
+; CHECK: ret i1 true
+define i1 @test41(i32 %X, i32 %Y) {
+ %A = urem i32 %X, %Y
+ %B = icmp ugt i32 %Y, %A
+ ret i1 %B
+}
+
+; CHECK: @test42
+; CHECK: %B = icmp sgt i32 %Y, -1
+define i1 @test42(i32 %X, i32 %Y) {
+ %A = srem i32 %X, %Y
+ %B = icmp slt i32 %A, %Y
+ ret i1 %B
+}
+
+; CHECK: @test43
+; CHECK: %B = icmp slt i32 %Y, 0
+define i1 @test43(i32 %X, i32 %Y) {
+ %A = srem i32 %X, %Y
+ %B = icmp slt i32 %Y, %A
+ ret i1 %B
+}
+
+; CHECK: @test44
+; CHECK: %B = icmp sgt i32 %Y, -1
+define i1 @test44(i32 %X, i32 %Y) {
+ %A = srem i32 %X, %Y
+ %B = icmp slt i32 %A, %Y
+ ret i1 %B
+}
+
+; CHECK: @test45
+; CHECK: %B = icmp slt i32 %Y, 0
+define i1 @test45(i32 %X, i32 %Y) {
+ %A = srem i32 %X, %Y
+ %B = icmp slt i32 %Y, %A
+ ret i1 %B
+}
+
+; PR9343 #4
+; CHECK: @test46
+; CHECK: %C = icmp ult i32 %X, %Y
+define i1 @test46(i32 %X, i32 %Y, i32 %Z) {
+ %A = ashr exact i32 %X, %Z
+ %B = ashr exact i32 %Y, %Z
+ %C = icmp ult i32 %A, %B
+ ret i1 %C
+}
+
+; PR9343 #5
+; CHECK: @test47
+; CHECK: %C = icmp ugt i32 %X, %Y
+define i1 @test47(i32 %X, i32 %Y, i32 %Z) {
+ %A = ashr exact i32 %X, %Z
+ %B = ashr exact i32 %Y, %Z
+ %C = icmp ugt i32 %A, %B
+ ret i1 %C
+}
+
+; PR9343 #8
+; CHECK: @test48
+; CHECK: %C = icmp eq i32 %X, %Y
+define i1 @test48(i32 %X, i32 %Y, i32 %Z) {
+ %A = sdiv exact i32 %X, %Z
+ %B = sdiv exact i32 %Y, %Z
+ %C = icmp eq i32 %A, %B
+ ret i1 %C
+}
+
+; PR8469
+; CHECK: @test49
+; CHECK: ret <2 x i1> <i1 true, i1 true>
+define <2 x i1> @test49(<2 x i32> %tmp3) {
+entry:
+ %tmp11 = and <2 x i32> %tmp3, <i32 3, i32 3>
+ %cmp = icmp ult <2 x i32> %tmp11, <i32 4, i32 4>
+ ret <2 x i1> %cmp
+}
+
+; PR9343 #7
+; CHECK: @test50
+; CHECK: ret i1 true
+define i1 @test50(i16 %X, i32 %Y) {
+ %A = zext i16 %X to i32
+ %B = srem i32 %A, %Y
+ %C = icmp sgt i32 %B, -1
+ ret i1 %C
+}
+
+; CHECK: @test51
+; CHECK: ret i1 %C
+define i1 @test51(i32 %X, i32 %Y) {
+ %A = and i32 %X, 2147483648
+ %B = srem i32 %A, %Y
+ %C = icmp sgt i32 %B, -1
+ ret i1 %C
+}
+
+; CHECK: @test52
+; CHECK-NEXT: and i32 %x1, 16711935
+; CHECK-NEXT: icmp eq i32 {{.*}}, 4980863
+; CHECK-NEXT: ret i1
+define i1 @test52(i32 %x1) nounwind {
+ %conv = and i32 %x1, 255
+ %cmp = icmp eq i32 %conv, 127
+ %tmp2 = lshr i32 %x1, 16
+ %tmp3 = trunc i32 %tmp2 to i8
+ %cmp15 = icmp eq i8 %tmp3, 76
+
+ %A = and i1 %cmp, %cmp15
+ ret i1 %A
+}
+
+; PR9838
+; CHECK: @test53
+; CHECK-NEXT: ashr exact
+; CHECK-NEXT: ashr
+; CHECK-NEXT: icmp
+define i1 @test53(i32 %a, i32 %b) nounwind {
+ %x = ashr exact i32 %a, 30
+ %y = ashr i32 %b, 30
+ %z = icmp eq i32 %x, %y
+ ret i1 %z
+}
+
+; CHECK: @test54
+; CHECK-NEXT: %and = and i8 %a, -64
+; CHECK-NEXT icmp eq i8 %and, -128
+define i1 @test54(i8 %a) nounwind {
+ %ext = zext i8 %a to i32
+ %and = and i32 %ext, 192
+ %ret = icmp eq i32 %and, 128
+ ret i1 %ret
+}
+
+; CHECK: @test55
+; CHECK-NEXT: icmp eq i32 %a, -123
+define i1 @test55(i32 %a) {
+ %sub = sub i32 0, %a
+ %cmp = icmp eq i32 %sub, 123
+ ret i1 %cmp
+}
+
+; CHECK: @test56
+; CHECK-NEXT: icmp eq i32 %a, -113
+define i1 @test56(i32 %a) {
+ %sub = sub i32 10, %a
+ %cmp = icmp eq i32 %sub, 123
+ ret i1 %cmp
+}
+
+; PR10267 Don't make icmps more expensive when no other inst is subsumed.
+declare void @foo(i32)
+; CHECK: @test57
+; CHECK: %and = and i32 %a, -2
+; CHECK: %cmp = icmp ne i32 %and, 0
+define i1 @test57(i32 %a) {
+ %and = and i32 %a, -2
+ %cmp = icmp ne i32 %and, 0
+ call void @foo(i32 %and)
+ ret i1 %cmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/idioms.ll b/src/LLVM/test/Transforms/InstCombine/idioms.ll
new file mode 100644
index 0000000..6b3567f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/idioms.ll
@@ -0,0 +1,32 @@
+; RUN: opt -instcombine %s -S | FileCheck %s
+
+; Check that code corresponding to the following C function is
+; simplified into a single ASR operation:
+;
+; int test_asr(int a, int b) {
+; return a < 0 ? -(-a - 1 >> b) - 1 : a >> b;
+; }
+;
+define i32 @test_asr(i32 %a, i32 %b) {
+entry:
+ %c = icmp slt i32 %a, 0
+ br i1 %c, label %bb2, label %bb3
+
+bb2:
+ %t1 = sub i32 0, %a
+ %not = sub i32 %t1, 1
+ %d = ashr i32 %not, %b
+ %t2 = sub i32 0, %d
+ %not2 = sub i32 %t2, 1
+ br label %bb4
+bb3:
+ %e = ashr i32 %a, %b
+ br label %bb4
+bb4:
+ %f = phi i32 [ %not2, %bb2 ], [ %e, %bb3 ]
+ ret i32 %f
+; CHECK: @test_asr
+; CHECK: bb4:
+; CHECK: %f = ashr i32 %a, %b
+; CHECK: ret i32 %f
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/intrinsics.ll b/src/LLVM/test/Transforms/InstCombine/intrinsics.ll
new file mode 100644
index 0000000..f033e51
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/intrinsics.ll
@@ -0,0 +1,216 @@
+; RUN: opt %s -instcombine -S | FileCheck %s
+
+%overflow.result = type {i8, i1}
+
+declare %overflow.result @llvm.uadd.with.overflow.i8(i8, i8)
+declare %overflow.result @llvm.umul.with.overflow.i8(i8, i8)
+declare double @llvm.powi.f64(double, i32) nounwind readonly
+declare i32 @llvm.cttz.i32(i32) nounwind readnone
+declare i32 @llvm.ctlz.i32(i32) nounwind readnone
+declare i32 @llvm.ctpop.i32(i32) nounwind readnone
+declare i8 @llvm.ctlz.i8(i8) nounwind readnone
+
+define i8 @uaddtest1(i8 %A, i8 %B) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
+ %y = extractvalue %overflow.result %x, 0
+ ret i8 %y
+; CHECK: @uaddtest1
+; CHECK-NEXT: %y = add i8 %A, %B
+; CHECK-NEXT: ret i8 %y
+}
+
+define i8 @uaddtest2(i8 %A, i8 %B, i1* %overflowPtr) {
+ %and.A = and i8 %A, 127
+ %and.B = and i8 %B, 127
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %and.A, i8 %and.B)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @uaddtest2
+; CHECK-NEXT: %and.A = and i8 %A, 127
+; CHECK-NEXT: %and.B = and i8 %B, 127
+; CHECK-NEXT: %x = add nuw i8 %and.A, %and.B
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %x
+}
+
+define i8 @uaddtest3(i8 %A, i8 %B, i1* %overflowPtr) {
+ %or.A = or i8 %A, -128
+ %or.B = or i8 %B, -128
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %or.A, i8 %or.B)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @uaddtest3
+; CHECK-NEXT: %or.A = or i8 %A, -128
+; CHECK-NEXT: %or.B = or i8 %B, -128
+; CHECK-NEXT: %x = add i8 %or.A, %or.B
+; CHECK-NEXT: store i1 true, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %x
+}
+
+define i8 @uaddtest4(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 undef, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @uaddtest4
+; CHECK-NEXT: ret i8 undef
+}
+
+define i8 @uaddtest5(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 0, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @uaddtest5
+; CHECK: ret i8 %A
+}
+
+define i1 @uaddtest6(i8 %A, i8 %B) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 -4)
+ %z = extractvalue %overflow.result %x, 1
+ ret i1 %z
+; CHECK: @uaddtest6
+; CHECK-NEXT: %z = icmp ugt i8 %A, 3
+; CHECK-NEXT: ret i1 %z
+}
+
+define i8 @uaddtest7(i8 %A, i8 %B) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
+ %z = extractvalue %overflow.result %x, 0
+ ret i8 %z
+; CHECK: @uaddtest7
+; CHECK-NEXT: %z = add i8 %A, %B
+; CHECK-NEXT: ret i8 %z
+}
+
+
+define i8 @umultest1(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.umul.with.overflow.i8(i8 0, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @umultest1
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 0
+}
+
+define i8 @umultest2(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.umul.with.overflow.i8(i8 1, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @umultest2
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %A
+}
+
+%ov.result.32 = type { i32, i1 }
+declare %ov.result.32 @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone
+
+define i32 @umultest3(i32 %n) nounwind {
+ %shr = lshr i32 %n, 2
+ %mul = call %ov.result.32 @llvm.umul.with.overflow.i32(i32 %shr, i32 3)
+ %ov = extractvalue %ov.result.32 %mul, 1
+ %res = extractvalue %ov.result.32 %mul, 0
+ %ret = select i1 %ov, i32 -1, i32 %res
+ ret i32 %ret
+; CHECK: @umultest3
+; CHECK-NEXT: shr
+; CHECK-NEXT: mul nuw
+; CHECK-NEXT: ret
+}
+
+define i32 @umultest4(i32 %n) nounwind {
+ %shr = lshr i32 %n, 1
+ %mul = call %ov.result.32 @llvm.umul.with.overflow.i32(i32 %shr, i32 4)
+ %ov = extractvalue %ov.result.32 %mul, 1
+ %res = extractvalue %ov.result.32 %mul, 0
+ %ret = select i1 %ov, i32 -1, i32 %res
+ ret i32 %ret
+; CHECK: @umultest4
+; CHECK: umul.with.overflow
+}
+
+define void @powi(double %V, double *%P) {
+entry:
+ %A = tail call double @llvm.powi.f64(double %V, i32 -1) nounwind
+ volatile store double %A, double* %P
+
+ %B = tail call double @llvm.powi.f64(double %V, i32 0) nounwind
+ volatile store double %B, double* %P
+
+ %C = tail call double @llvm.powi.f64(double %V, i32 1) nounwind
+ volatile store double %C, double* %P
+ ret void
+; CHECK: @powi
+; CHECK: %A = fdiv double 1.0{{.*}}, %V
+; CHECK: store volatile double %A,
+; CHECK: store volatile double 1.0
+; CHECK: store volatile double %V
+}
+
+define i32 @cttz(i32 %a) {
+entry:
+ %or = or i32 %a, 8
+ %and = and i32 %or, -8
+ %count = tail call i32 @llvm.cttz.i32(i32 %and) nounwind readnone
+ ret i32 %count
+; CHECK: @cttz
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i32 3
+}
+
+define i8 @ctlz(i8 %a) {
+entry:
+ %or = or i8 %a, 32
+ %and = and i8 %or, 63
+ %count = tail call i8 @llvm.ctlz.i8(i8 %and) nounwind readnone
+ ret i8 %count
+; CHECK: @ctlz
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i8 2
+}
+
+define void @cmp.simplify(i32 %a, i32 %b, i1* %c) {
+entry:
+ %lz = tail call i32 @llvm.ctlz.i32(i32 %a) nounwind readnone
+ %lz.cmp = icmp eq i32 %lz, 32
+ volatile store i1 %lz.cmp, i1* %c
+ %tz = tail call i32 @llvm.cttz.i32(i32 %a) nounwind readnone
+ %tz.cmp = icmp ne i32 %tz, 32
+ volatile store i1 %tz.cmp, i1* %c
+ %pop = tail call i32 @llvm.ctpop.i32(i32 %b) nounwind readnone
+ %pop.cmp = icmp eq i32 %pop, 0
+ volatile store i1 %pop.cmp, i1* %c
+ ret void
+; CHECK: @cmp.simplify
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %lz.cmp = icmp eq i32 %a, 0
+; CHECK-NEXT: store volatile i1 %lz.cmp, i1* %c
+; CHECK-NEXT: %tz.cmp = icmp ne i32 %a, 0
+; CHECK-NEXT: store volatile i1 %tz.cmp, i1* %c
+; CHECK-NEXT: %pop.cmp = icmp eq i32 %b, 0
+; CHECK-NEXT: store volatile i1 %pop.cmp, i1* %c
+}
+
+
+define i32 @cttz_simplify1(i32 %x) nounwind readnone ssp {
+ %tmp1 = tail call i32 @llvm.ctlz.i32(i32 %x) ; <i32> [#uses=1]
+ %shr3 = lshr i32 %tmp1, 5 ; <i32> [#uses=1]
+ ret i32 %shr3
+
+; CHECK: @cttz_simplify1
+; CHECK: icmp eq i32 %x, 0
+; CHECK-NEXT: zext i1
+; CHECK-NEXT: ret i32
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/invariant.ll b/src/LLVM/test/Transforms/InstCombine/invariant.ll
new file mode 100644
index 0000000..3832380
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/invariant.ll
@@ -0,0 +1,16 @@
+; Test to make sure unused llvm.invariant.start calls are not trivially eliminated
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @g(i8*)
+
+declare {}* @llvm.invariant.start(i64, i8* nocapture) nounwind readonly
+
+define i8 @f() {
+ %a = alloca i8 ; <i8*> [#uses=4]
+ store i8 0, i8* %a
+ %i = call {}* @llvm.invariant.start(i64 1, i8* %a) ; <{}*> [#uses=0]
+ ; CHECK: call {}* @llvm.invariant.start
+ call void @g(i8* %a)
+ %r = load i8* %a ; <i8> [#uses=1]
+ ret i8 %r
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/known_align.ll b/src/LLVM/test/Transforms/InstCombine/known_align.ll
new file mode 100644
index 0000000..5382abf
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/known_align.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -instcombine -S | grep {align 1}
+; END.
+
+ %struct.p = type <{ i8, i32 }>
+@t = global %struct.p <{ i8 1, i32 10 }> ; <%struct.p*> [#uses=1]
+@u = weak global %struct.p zeroinitializer ; <%struct.p*> [#uses=1]
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp1 = alloca i32, align 4 ; <i32*> [#uses=3]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp3 = load i32* getelementptr (%struct.p* @t, i32 0, i32 1), align 1 ; <i32> [#uses=1]
+ store i32 %tmp3, i32* %tmp1, align 4
+ %tmp5 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ store i32 %tmp5, i32* getelementptr (%struct.p* @u, i32 0, i32 1), align 1
+ %tmp6 = load i32* %tmp1, align 4 ; <i32> [#uses=1]
+ store i32 %tmp6, i32* %tmp, align 4
+ %tmp7 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ store i32 %tmp7, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval8 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval8
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/load-cmp.ll b/src/LLVM/test/Transforms/InstCombine/load-cmp.ll
new file mode 100644
index 0000000..5cafb77
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/load-cmp.ll
@@ -0,0 +1,112 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+@G16 = internal constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,
+ i16 73, i16 82, i16 69, i16 68, i16 0]
+@GD = internal constant [6 x double]
+ [double -10.0, double 1.0, double 4.0, double 2.0, double -20.0, double -40.0]
+
+define i1 @test1(i32 %X) {
+ %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
+ %Q = load i16* %P
+ %R = icmp eq i16 %Q, 0
+ ret i1 %R
+; CHECK: @test1
+; CHECK-NEXT: %R = icmp eq i32 %X, 9
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test2(i32 %X) {
+ %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
+ %Q = load i16* %P
+ %R = icmp slt i16 %Q, 85
+ ret i1 %R
+; CHECK: @test2
+; CHECK-NEXT: %R = icmp ne i32 %X, 4
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test3(i32 %X) {
+ %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
+ %Q = load double* %P
+ %R = fcmp oeq double %Q, 1.0
+ ret i1 %R
+; CHECK: @test3
+; CHECK-NEXT: %R = icmp eq i32 %X, 1
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test4(i32 %X) {
+ %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
+ %Q = load i16* %P
+ %R = icmp sle i16 %Q, 73
+ ret i1 %R
+; CHECK: @test4
+; CHECK-NEXT: lshr i32 933, %X
+; CHECK-NEXT: and i32 {{.*}}, 1
+; CHECK-NEXT: %R = icmp ne i32 {{.*}}, 0
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test5(i32 %X) {
+ %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
+ %Q = load i16* %P
+ %R = icmp eq i16 %Q, 69
+ ret i1 %R
+; CHECK: @test5
+; CHECK-NEXT: icmp eq i32 %X, 2
+; CHECK-NEXT: icmp eq i32 %X, 7
+; CHECK-NEXT: %R = or i1
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test6(i32 %X) {
+ %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
+ %Q = load double* %P
+ %R = fcmp ogt double %Q, 0.0
+ ret i1 %R
+; CHECK: @test6
+; CHECK-NEXT: add i32 %X, -1
+; CHECK-NEXT: %R = icmp ult i32 {{.*}}, 3
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test7(i32 %X) {
+ %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
+ %Q = load double* %P
+ %R = fcmp olt double %Q, 0.0
+ ret i1 %R
+; CHECK: @test7
+; CHECK-NEXT: add i32 %X, -1
+; CHECK-NEXT: %R = icmp ugt i32 {{.*}}, 2
+; CHECK-NEXT: ret i1 %R
+}
+
+define i1 @test8(i32 %X) {
+ %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
+ %Q = load i16* %P
+ %R = and i16 %Q, 3
+ %S = icmp eq i16 %R, 0
+ ret i1 %S
+; CHECK: @test8
+; CHECK-NEXT: add i32 %X, -8
+; CHECK-NEXT: icmp ult i32 {{.*}}, 2
+; CHECK-NEXT: ret i1
+}
+
+@GA = internal constant [4 x { i32, i32 } ] [
+ { i32, i32 } { i32 1, i32 0 },
+ { i32, i32 } { i32 2, i32 1 },
+ { i32, i32 } { i32 3, i32 1 },
+ { i32, i32 } { i32 4, i32 0 }
+]
+
+define i1 @test9(i32 %X) {
+ %P = getelementptr inbounds [4 x { i32, i32 } ]* @GA, i32 0, i32 %X, i32 1
+ %Q = load i32* %P
+ %R = icmp eq i32 %Q, 1
+ ret i1 %R
+; CHECK: @test9
+; CHECK-NEXT: add i32 %X, -1
+; CHECK-NEXT: icmp ult i32 {{.*}}, 2
+; CHECK-NEXT: ret i1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/load-select.ll b/src/LLVM/test/Transforms/InstCombine/load-select.ll
new file mode 100644
index 0000000..f3d83dc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/load-select.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"
+
+@a = constant [2 x i32] [i32 3, i32 6] ; <[2 x i32]*> [#uses=2]
+
+define i32 @b(i32 %y) nounwind readonly {
+; CHECK: @b
+; CHECK-NOT: load
+; CHECK: ret i32
+entry:
+ %0 = icmp eq i32 %y, 0 ; <i1> [#uses=1]
+ %storemerge = select i1 %0, i32* getelementptr inbounds ([2 x i32]* @a, i32 0, i32 1), i32* getelementptr inbounds ([2 x i32]* @a, i32 0, i32 0) ; <i32*> [#uses=1]
+ %1 = load i32* %storemerge, align 4 ; <i32> [#uses=1]
+ ret i32 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/load.ll b/src/LLVM/test/Transforms/InstCombine/load.ll
new file mode 100644
index 0000000..2f95409
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/load.ll
@@ -0,0 +1,98 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | not grep load
+
+@X = constant i32 42 ; <i32*> [#uses=2]
+@X2 = constant i32 47 ; <i32*> [#uses=1]
+@Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
+@Z = constant [2 x { i32, float }] zeroinitializer ; <[2 x { i32, float }]*> [#uses=1]
+
+@GLOBAL = internal constant [4 x i32] zeroinitializer
+
+
+define i32 @test1() {
+ %B = load i32* @X ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define float @test2() {
+ %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1 ; <float*> [#uses=1]
+ %B = load float* %A ; <float> [#uses=1]
+ ret float %B
+}
+
+define i32 @test3() {
+ %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0 ; <i32*> [#uses=1]
+ %B = load i32* %A ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test4() {
+ %A = getelementptr [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0 ; <i32*> [#uses=1]
+ %B = load i32* %A ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test5(i1 %C) {
+ %Y = select i1 %C, i32* @X, i32* @X2 ; <i32*> [#uses=1]
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test7(i32 %X) {
+ %V = getelementptr i32* null, i32 %X ; <i32*> [#uses=1]
+ %R = load i32* %V ; <i32> [#uses=1]
+ ret i32 %R
+}
+
+define i32 @test8(i32* %P) {
+ store i32 1, i32* %P
+ %X = load i32* %P ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+define i32 @test9(i32* %P) {
+ %X = load i32* %P ; <i32> [#uses=1]
+ %Y = load i32* %P ; <i32> [#uses=1]
+ %Z = sub i32 %X, %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
+ br i1 %C.upgrd.1, label %T, label %F
+T: ; preds = %0
+ store i32 1, i32* %Q
+ store i32 0, i32* %P
+ br label %C
+F: ; preds = %0
+ store i32 0, i32* %P
+ br label %C
+C: ; preds = %F, %T
+ %V = load i32* %P ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define double @test11(double* %p) {
+ %t0 = getelementptr double* %p, i32 1
+ store double 2.0, double* %t0
+ %t1 = getelementptr double* %p, i32 1
+ %x = load double* %t1
+ ret double %x
+}
+
+define i32 @test12(i32* %P) {
+ %A = alloca i32
+ store i32 123, i32* %A
+ ; Cast the result of the load not the source
+ %Q = bitcast i32* %A to i32*
+ %V = load i32* %Q
+ ret i32 %V
+}
+
+define <16 x i8> @test13(<2 x i64> %x) {
+entry:
+ %tmp = load <16 x i8> * bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
+ ret <16 x i8> %tmp
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/load3.ll b/src/LLVM/test/Transforms/InstCombine/load3.ll
new file mode 100644
index 0000000..35398e1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/load3.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; Instcombine should be able to do trivial CSE of loads.
+
+define i32 @test1(i32* %p) {
+ %t0 = getelementptr i32* %p, i32 1
+ %y = load i32* %t0
+ %t1 = getelementptr i32* %p, i32 1
+ %x = load i32* %t1
+ %a = sub i32 %y, %x
+ ret i32 %a
+; CHECK: @test1
+; CHECK: ret i32 0
+}
+
+
+; PR7429
+@.str = private constant [4 x i8] c"XYZ\00"
+define float @test2() {
+ %tmp = load float* bitcast ([4 x i8]* @.str to float*), align 1
+ ret float %tmp
+
+; CHECK: @test2
+; CHECK: ret float 0x3806965600000000
+}
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/InstCombine/loadstore-alignment.ll b/src/LLVM/test/Transforms/InstCombine/loadstore-alignment.ll
new file mode 100644
index 0000000..1d932d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/loadstore-alignment.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -instcombine -S | grep {, align 16} | count 14
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@x = external global <2 x i64>, align 16
+@xx = external global [13 x <2 x i64>], align 16
+
+define <2 x i64> @static_hem() {
+ %t = getelementptr <2 x i64>* @x, i32 7
+ %tmp1 = load <2 x i64>* %t, align 1
+ ret <2 x i64> %tmp1
+}
+
+define <2 x i64> @hem(i32 %i) {
+ %t = getelementptr <2 x i64>* @x, i32 %i
+ %tmp1 = load <2 x i64>* %t, align 1
+ ret <2 x i64> %tmp1
+}
+
+define <2 x i64> @hem_2d(i32 %i, i32 %j) {
+ %t = getelementptr [13 x <2 x i64>]* @xx, i32 %i, i32 %j
+ %tmp1 = load <2 x i64>* %t, align 1
+ ret <2 x i64> %tmp1
+}
+
+define <2 x i64> @foo() {
+ %tmp1 = load <2 x i64>* @x, align 1
+ ret <2 x i64> %tmp1
+}
+
+define <2 x i64> @bar() {
+ %t = alloca <2 x i64>
+ call void @kip(<2 x i64>* %t)
+ %tmp1 = load <2 x i64>* %t, align 1
+ ret <2 x i64> %tmp1
+}
+
+define void @static_hem_store(<2 x i64> %y) {
+ %t = getelementptr <2 x i64>* @x, i32 7
+ store <2 x i64> %y, <2 x i64>* %t, align 1
+ ret void
+}
+
+define void @hem_store(i32 %i, <2 x i64> %y) {
+ %t = getelementptr <2 x i64>* @x, i32 %i
+ store <2 x i64> %y, <2 x i64>* %t, align 1
+ ret void
+}
+
+define void @hem_2d_store(i32 %i, i32 %j, <2 x i64> %y) {
+ %t = getelementptr [13 x <2 x i64>]* @xx, i32 %i, i32 %j
+ store <2 x i64> %y, <2 x i64>* %t, align 1
+ ret void
+}
+
+define void @foo_store(<2 x i64> %y) {
+ store <2 x i64> %y, <2 x i64>* @x, align 1
+ ret void
+}
+
+define void @bar_store(<2 x i64> %y) {
+ %t = alloca <2 x i64>
+ call void @kip(<2 x i64>* %t)
+ store <2 x i64> %y, <2 x i64>* %t, align 1
+ ret void
+}
+
+declare void @kip(<2 x i64>* %t)
diff --git a/src/LLVM/test/Transforms/InstCombine/logical-select.ll b/src/LLVM/test/Transforms/InstCombine/logical-select.ll
new file mode 100644
index 0000000..bb59817
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/logical-select.ll
@@ -0,0 +1,68 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+
+define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+ %e = icmp slt i32 %a, %b
+ %f = sext i1 %e to i32
+ %g = and i32 %c, %f
+ %h = xor i32 %f, -1
+ %i = and i32 %d, %h
+ %j = or i32 %g, %i
+ ret i32 %j
+; CHECK: %e = icmp slt i32 %a, %b
+; CHECK: %j = select i1 %e, i32 %c, i32 %d
+; CHECK: ret i32 %j
+}
+define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+ %e = icmp slt i32 %a, %b
+ %f = sext i1 %e to i32
+ %g = and i32 %c, %f
+ %h = xor i32 %f, -1
+ %i = and i32 %d, %h
+ %j = or i32 %i, %g
+ ret i32 %j
+; CHECK: %e = icmp slt i32 %a, %b
+; CHECK: %j = select i1 %e, i32 %c, i32 %d
+; CHECK: ret i32 %j
+}
+
+define i32 @goo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+entry:
+ %0 = icmp slt i32 %a, %b
+ %iftmp.0.0 = select i1 %0, i32 -1, i32 0
+ %1 = and i32 %iftmp.0.0, %c
+ %not = xor i32 %iftmp.0.0, -1
+ %2 = and i32 %not, %d
+ %3 = or i32 %1, %2
+ ret i32 %3
+; CHECK: %0 = icmp slt i32 %a, %b
+; CHECK: %1 = select i1 %0, i32 %c, i32 %d
+; CHECK: ret i32 %1
+}
+define i32 @poo(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+entry:
+ %0 = icmp slt i32 %a, %b
+ %iftmp.0.0 = select i1 %0, i32 -1, i32 0
+ %1 = and i32 %iftmp.0.0, %c
+ %iftmp = select i1 %0, i32 0, i32 -1
+ %2 = and i32 %iftmp, %d
+ %3 = or i32 %1, %2
+ ret i32 %3
+; CHECK: %0 = icmp slt i32 %a, %b
+; CHECK: %1 = select i1 %0, i32 %c, i32 %d
+; CHECK: ret i32 %1
+}
+
+define i32 @par(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {
+entry:
+ %0 = icmp slt i32 %a, %b
+ %iftmp.1.0 = select i1 %0, i32 -1, i32 0
+ %1 = and i32 %iftmp.1.0, %c
+ %not = xor i32 %iftmp.1.0, -1
+ %2 = and i32 %not, %d
+ %3 = or i32 %1, %2
+ ret i32 %3
+; CHECK: %0 = icmp slt i32 %a, %b
+; CHECK: %1 = select i1 %0, i32 %c, i32 %d
+; CHECK: ret i32 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/lshr-phi.ll b/src/LLVM/test/Transforms/InstCombine/lshr-phi.ll
new file mode 100644
index 0000000..76a113f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/lshr-phi.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -instcombine -S > %t
+; RUN: not grep lshr %t
+; RUN: grep add %t | count 1
+
+; Instcombine should be able to eliminate the lshr, because only
+; bits in the operand which might be non-zero will be shifted
+; off the end.
+
+define i32 @hash_string(i8* nocapture %key) nounwind readonly {
+entry:
+ %t0 = load i8* %key, align 1 ; <i8> [#uses=1]
+ %t1 = icmp eq i8 %t0, 0 ; <i1> [#uses=1]
+ br i1 %t1, label %bb2, label %bb
+
+bb: ; preds = %bb, %entry
+ %indvar = phi i64 [ 0, %entry ], [ %tmp, %bb ] ; <i64> [#uses=2]
+ %k.04 = phi i32 [ 0, %entry ], [ %t8, %bb ] ; <i32> [#uses=2]
+ %cp.05 = getelementptr i8* %key, i64 %indvar ; <i8*> [#uses=1]
+ %t2 = shl i32 %k.04, 1 ; <i32> [#uses=1]
+ %t3 = lshr i32 %k.04, 14 ; <i32> [#uses=1]
+ %t4 = add i32 %t2, %t3 ; <i32> [#uses=1]
+ %t5 = load i8* %cp.05, align 1 ; <i8> [#uses=1]
+ %t6 = sext i8 %t5 to i32 ; <i32> [#uses=1]
+ %t7 = xor i32 %t6, %t4 ; <i32> [#uses=1]
+ %t8 = and i32 %t7, 16383 ; <i32> [#uses=2]
+ %tmp = add i64 %indvar, 1 ; <i64> [#uses=2]
+ %scevgep = getelementptr i8* %key, i64 %tmp ; <i8*> [#uses=1]
+ %t9 = load i8* %scevgep, align 1 ; <i8> [#uses=1]
+ %t10 = icmp eq i8 %t9, 0 ; <i1> [#uses=1]
+ br i1 %t10, label %bb2, label %bb
+
+bb2: ; preds = %bb, %entry
+ %k.0.lcssa = phi i32 [ 0, %entry ], [ %t8, %bb ] ; <i32> [#uses=1]
+ ret i32 %k.0.lcssa
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/malloc-free-delete.ll b/src/LLVM/test/Transforms/InstCombine/malloc-free-delete.ll
new file mode 100644
index 0000000..0112607
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/malloc-free-delete.ll
@@ -0,0 +1,48 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR1201
+define i32 @main(i32 %argc, i8** %argv) {
+ %c_19 = alloca i8*
+ %malloc_206 = tail call i8* @malloc(i32 mul (i32 ptrtoint (i8* getelementptr (i8* null, i32 1) to i32), i32 10))
+ store i8* %malloc_206, i8** %c_19
+ %tmp_207 = load i8** %c_19
+ tail call void @free(i8* %tmp_207)
+ ret i32 0
+; CHECK-NOT: malloc
+; CHECK-NOT: free
+; CHECK: ret i32 0
+}
+
+declare noalias i8* @malloc(i32)
+declare void @free(i8*)
+
+define i1 @foo() {
+; CHECK: @foo
+; CHECK-NEXT: ret i1 false
+ %m = call i8* @malloc(i32 1)
+ %z = icmp eq i8* %m, null
+ call void @free(i8* %m)
+ ret i1 %z
+}
+
+declare void @llvm.lifetime.start(i64, i8*)
+declare void @llvm.lifetime.end(i64, i8*)
+
+define void @test3() {
+; CHECK: @test3
+; CHECK-NEXT: ret void
+ %a = call noalias i8* @malloc(i32 10)
+ call void @llvm.lifetime.start(i64 10, i8* %a)
+ call void @llvm.lifetime.end(i64 10, i8* %a)
+ ret void
+}
+
+;; This used to crash.
+define void @test4() {
+; CHECK: @test4
+; CHECK-NEXT: ret void
+ %A = call i8* @malloc(i32 16000)
+ %B = bitcast i8* %A to double*
+ %C = bitcast double* %B to i8*
+ call void @free(i8* %C)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/memcpy-to-load.ll b/src/LLVM/test/Transforms/InstCombine/memcpy-to-load.ll
new file mode 100644
index 0000000..04aac98
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memcpy-to-load.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | grep {load double}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+
+define void @foo(double* %X, double* %Y) {
+entry:
+ %tmp2 = bitcast double* %X to i8*
+ %tmp13 = bitcast double* %Y to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp2, i8* %tmp13, i32 8, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/memcpy.ll b/src/LLVM/test/Transforms/InstCombine/memcpy.ll
new file mode 100644
index 0000000..8a2e3aa
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memcpy.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+define void @test1(i8* %a) {
+ tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a, i8* %a, i32 100, i32 1, i1 false)
+ ret void
+; CHECK: define void @test1
+; CHECK-NEXT: ret void
+}
+
+
+; PR8267
+define void @test2(i8* %a) {
+ tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a, i8* %a, i32 100, i32 1, i1 true)
+ ret void
+; CHECK: define void @test2
+; CHECK-NEXT: call void @llvm.memcpy
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/memmove.ll b/src/LLVM/test/Transforms/InstCombine/memmove.ll
new file mode 100644
index 0000000..4ed4300
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memmove.ll
@@ -0,0 +1,39 @@
+; This test makes sure that memmove instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | not grep {call void @llvm.memmove}
+
+@S = internal constant [33 x i8] c"panic: restorelist inconsistency\00" ; <[33 x i8]*> [#uses=1]
+@h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1]
+@hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=1]
+@hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=1]
+
+define void @test1(i8* %A, i8* %B, i32 %N) {
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %A, i8* %B, i32 0, i32 1, i1 false)
+ ret void
+}
+
+define void @test2(i8* %A, i32 %N) {
+ ;; dest can't alias source since we can't write to source!
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %A, i8* getelementptr inbounds ([33 x i8]* @S, i32 0, i32 0), i32 %N, i32 1, i1 false)
+ ret void
+}
+
+define i32 @test3() {
+ %h_p = getelementptr [2 x i8]* @h, i32 0, i32 0 ; <i8*> [#uses=1]
+ %hel_p = getelementptr [4 x i8]* @hel, i32 0, i32 0 ; <i8*> [#uses=1]
+ %hello_u_p = getelementptr [8 x i8]* @hello_u, i32 0, i32 0 ; <i8*> [#uses=1]
+ %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
+ %target_p = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=3]
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %target_p, i8* %h_p, i32 2, i32 2, i1 false)
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %target_p, i8* %hel_p, i32 4, i32 4, i1 false)
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %target_p, i8* %hello_u_p, i32 8, i32 8, i1 false)
+ ret i32 0
+}
+
+; PR2370
+define void @test4(i8* %a) {
+ tail call void @llvm.memmove.p0i8.p0i8.i32(i8* %a, i8* %a, i32 100, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/memset.ll b/src/LLVM/test/Transforms/InstCombine/memset.ll
new file mode 100644
index 0000000..7f7bc9f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memset.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | not grep {call.*llvm.memset}
+
+define i32 @main() {
+ %target = alloca [1024 x i8]
+ %target_p = getelementptr [1024 x i8]* %target, i32 0, i32 0
+ call void @llvm.memset.p0i8.i32(i8* %target_p, i8 1, i32 0, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i32(i8* %target_p, i8 1, i32 1, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i32(i8* %target_p, i8 1, i32 2, i32 2, i1 false)
+ call void @llvm.memset.p0i8.i32(i8* %target_p, i8 1, i32 4, i32 4, i1 false)
+ call void @llvm.memset.p0i8.i32(i8* %target_p, i8 1, i32 8, i32 8, i1 false)
+ ret i32 0
+}
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/memset2.ll b/src/LLVM/test/Transforms/InstCombine/memset2.ll
new file mode 100644
index 0000000..87639f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memset2.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Test to check that instcombine doesn't drop the address space when optimizing
+; memset.
+%struct.Moves = type { [9 x i8], i8, i8, i8, [5 x i8] }
+
+define i32 @test(%struct.Moves addrspace(1)* nocapture %moves) {
+entry:
+; CHECK: bitcast i8 addrspace(1)* %gep to i64 addrspace(1)*
+ %gep = getelementptr inbounds %struct.Moves addrspace(1)* %moves, i32 1, i32 0, i32 9
+ call void @llvm.memset.p1i8.i64(i8 addrspace(1)* %gep, i8 0, i64 8, i32 1, i1 false)
+ ret i32 0
+}
+
+declare void @llvm.memset.p1i8.i64(i8addrspace(1)* nocapture, i8, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/memset_chk.ll b/src/LLVM/test/Transforms/InstCombine/memset_chk.ll
new file mode 100644
index 0000000..58ecda5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/memset_chk.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; rdar://7719085
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+%struct.data = type { [100 x i32], [100 x i32], [1024 x i8] }
+
+define i32 @t() nounwind ssp {
+; CHECK: @t
+; CHECK: @llvm.memset.p0i8.i64
+entry:
+ %0 = alloca %struct.data, align 8 ; <%struct.data*> [#uses=1]
+ %1 = bitcast %struct.data* %0 to i8* ; <i8*> [#uses=1]
+ %2 = call i8* @__memset_chk(i8* %1, i32 0, i64 1824, i64 1824) nounwind ; <i8*> [#uses=0]
+ ret i32 0
+}
+
+declare i8* @__memset_chk(i8*, i32, i64, i64) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/merge-icmp.ll b/src/LLVM/test/Transforms/InstCombine/merge-icmp.ll
new file mode 100644
index 0000000..00020b1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/merge-icmp.ll
@@ -0,0 +1,29 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define i1 @test1(i16* %x) {
+ %load = load i16* %x, align 4
+ %trunc = trunc i16 %load to i8
+ %cmp1 = icmp eq i8 %trunc, 127
+ %and = and i16 %load, -256
+ %cmp2 = icmp eq i16 %and, 17664
+ %or = and i1 %cmp1, %cmp2
+ ret i1 %or
+; CHECK: @test1
+; CHECK-NEXT: load i16
+; CHECK-NEXT: icmp eq i16 %load, 17791
+; CHECK-NEXT: ret i1
+}
+
+define i1 @test2(i16* %x) {
+ %load = load i16* %x, align 4
+ %and = and i16 %load, -256
+ %cmp1 = icmp eq i16 %and, 32512
+ %trunc = trunc i16 %load to i8
+ %cmp2 = icmp eq i8 %trunc, 69
+ %or = and i1 %cmp1, %cmp2
+ ret i1 %or
+; CHECK: @test2
+; CHECK-NEXT: load i16
+; CHECK-NEXT: icmp eq i16 %load, 32581
+; CHECK-NEXT: ret i1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/mul-masked-bits.ll b/src/LLVM/test/Transforms/InstCombine/mul-masked-bits.ll
new file mode 100644
index 0000000..a43d5f2
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/mul-masked-bits.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep ashr
+
+define i32 @foo(i32 %x, i32 %y) {
+ %a = and i32 %x, 7
+ %b = and i32 %y, 7
+ %c = mul i32 %a, %b
+ %d = shl i32 %c, 26
+ %e = ashr i32 %d, 26
+ ret i32 %e
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/mul.ll b/src/LLVM/test/Transforms/InstCombine/mul.ll
new file mode 100644
index 0000000..5601c20
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/mul.ll
@@ -0,0 +1,116 @@
+; This test makes sure that mul instructions are properly eliminated.
+; RUN: opt < %s -instcombine -S | not grep mul
+
+define i32 @test1(i32 %A) {
+ %B = mul i32 %A, 1 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test2(i32 %A) {
+ ; Should convert to an add instruction
+ %B = mul i32 %A, 2 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test3(i32 %A) {
+ ; This should disappear entirely
+ %B = mul i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define double @test4(double %A) {
+ ; This is safe for FP
+ %B = fmul double 1.000000e+00, %A ; <double> [#uses=1]
+ ret double %B
+}
+
+define i32 @test5(i32 %A) {
+ %B = mul i32 %A, 8 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i8 @test6(i8 %A) {
+ %B = mul i8 %A, 8 ; <i8> [#uses=1]
+ %C = mul i8 %B, 8 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i32 @test7(i32 %i) {
+ %tmp = mul i32 %i, -1 ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
+define i64 @test8(i64 %i) {
+ ; tmp = sub 0, %i
+ %j = mul i64 %i, -1 ; <i64> [#uses=1]
+ ret i64 %j
+}
+
+define i32 @test9(i32 %i) {
+ ; %j = sub 0, %i
+ %j = mul i32 %i, -1 ; <i32> [#uses=1]
+ ret i32 %j
+}
+
+define i32 @test10(i32 %a, i32 %b) {
+ %c = icmp slt i32 %a, 0 ; <i1> [#uses=1]
+ %d = zext i1 %c to i32 ; <i32> [#uses=1]
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b ; <i32> [#uses=1]
+ ret i32 %e
+}
+
+define i32 @test11(i32 %a, i32 %b) {
+ %c = icmp sle i32 %a, -1 ; <i1> [#uses=1]
+ %d = zext i1 %c to i32 ; <i32> [#uses=1]
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b ; <i32> [#uses=1]
+ ret i32 %e
+}
+
+define i32 @test12(i8 %a, i32 %b) {
+ %c = icmp ugt i8 %a, 127 ; <i1> [#uses=1]
+ %d = zext i1 %c to i32 ; <i32> [#uses=1]
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b ; <i32> [#uses=1]
+ ret i32 %e
+}
+
+; PR2642
+define internal void @test13(<4 x float>*) {
+ load <4 x float>* %0, align 1
+ fmul <4 x float> %2, < float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 >
+ store <4 x float> %3, <4 x float>* %0, align 1
+ ret void
+}
+
+define <16 x i8> @test14(<16 x i8> %a) {
+ %b = mul <16 x i8> %a, zeroinitializer
+ ret <16 x i8> %b
+}
+
+; rdar://7293527
+define i32 @test15(i32 %A, i32 %B) {
+entry:
+ %shl = shl i32 1, %B
+ %m = mul i32 %shl, %A
+ ret i32 %m
+}
+
+; X * Y (when Y is 0 or 1) --> x & (0-Y)
+define i32 @test16(i32 %b, i1 %c) {
+ %d = zext i1 %c to i32 ; <i32> [#uses=1]
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b ; <i32> [#uses=1]
+ ret i32 %e
+}
+
+; X * Y (when Y is 0 or 1) --> x & (0-Y)
+define i32 @test17(i32 %a, i32 %b) {
+ %a.lobit = lshr i32 %a, 31
+ %e = mul i32 %a.lobit, %b
+ ret i32 %e
+}
+
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/multi-use-or.ll b/src/LLVM/test/Transforms/InstCombine/multi-use-or.ll
new file mode 100644
index 0000000..8c6a0e0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/multi-use-or.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -instcombine -S | grep {fadd double .sx, .sy}
+; The 'or' has multiple uses, make sure that this doesn't prevent instcombine
+; from propagating the extends to the truncs.
+
+define double @ScaleObjectAdd(double %sx, double %sy, double %sz) nounwind {
+entry:
+ %sx34 = bitcast double %sx to i64 ; <i64> [#uses=1]
+ %sx3435 = zext i64 %sx34 to i192 ; <i192> [#uses=1]
+ %sy22 = bitcast double %sy to i64 ; <i64> [#uses=1]
+ %sy2223 = zext i64 %sy22 to i192 ; <i192> [#uses=1]
+ %sy222324 = shl i192 %sy2223, 128 ; <i192> [#uses=1]
+ %sy222324.ins = or i192 %sx3435, %sy222324 ; <i192> [#uses=1]
+
+
+ %a = trunc i192 %sy222324.ins to i64 ; <i64> [#uses=1]
+ %b = bitcast i64 %a to double ; <double> [#uses=1]
+ %c = lshr i192 %sy222324.ins, 128 ; <i192> [#uses=1]
+ %d = trunc i192 %c to i64 ; <i64> [#uses=1]
+ %e = bitcast i64 %d to double ; <double> [#uses=1]
+ %f = fadd double %b, %e
+
+; ret double %e
+ ret double %f
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/narrow.ll b/src/LLVM/test/Transforms/InstCombine/narrow.ll
new file mode 100644
index 0000000..439ad29
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/narrow.ll
@@ -0,0 +1,18 @@
+; This file contains various testcases that check to see that instcombine
+; is narrowing computations when possible.
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {ret i1 false}
+
+; test1 - Eliminating the casts in this testcase (by narrowing the AND
+; operation) allows instcombine to realize the function always returns false.
+;
+define i1 @test1(i32 %A, i32 %B) {
+ %C1 = icmp slt i32 %A, %B ; <i1> [#uses=1]
+ %ELIM1 = zext i1 %C1 to i32 ; <i32> [#uses=1]
+ %C2 = icmp sgt i32 %A, %B ; <i1> [#uses=1]
+ %ELIM2 = zext i1 %C2 to i32 ; <i32> [#uses=1]
+ %C3 = and i32 %ELIM1, %ELIM2 ; <i32> [#uses=1]
+ %ELIM3 = trunc i32 %C3 to i1 ; <i1> [#uses=1]
+ ret i1 %ELIM3
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/neon-intrinsics.ll b/src/LLVM/test/Transforms/InstCombine/neon-intrinsics.ll
new file mode 100644
index 0000000..3ad09cc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/neon-intrinsics.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; The alignment arguments for NEON load/store intrinsics can be increased
+; by instcombine. Check for this.
+
+; CHECK: vld4.v2i32({{.*}}, i32 32)
+; CHECK: vst4.v2i32({{.*}}, i32 16)
+
+@x = common global [8 x i32] zeroinitializer, align 32
+@y = common global [8 x i32] zeroinitializer, align 16
+
+%struct.__neon_int32x2x4_t = type { <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32> }
+
+define void @test() nounwind ssp {
+ %tmp1 = call %struct.__neon_int32x2x4_t @llvm.arm.neon.vld4.v2i32(i8* bitcast ([8 x i32]* @x to i8*), i32 1)
+ %tmp2 = extractvalue %struct.__neon_int32x2x4_t %tmp1, 0
+ %tmp3 = extractvalue %struct.__neon_int32x2x4_t %tmp1, 1
+ %tmp4 = extractvalue %struct.__neon_int32x2x4_t %tmp1, 2
+ %tmp5 = extractvalue %struct.__neon_int32x2x4_t %tmp1, 3
+ call void @llvm.arm.neon.vst4.v2i32(i8* bitcast ([8 x i32]* @y to i8*), <2 x i32> %tmp2, <2 x i32> %tmp3, <2 x i32> %tmp4, <2 x i32> %tmp5, i32 1)
+ ret void
+}
+
+declare %struct.__neon_int32x2x4_t @llvm.arm.neon.vld4.v2i32(i8*, i32) nounwind readonly
+declare void @llvm.arm.neon.vst4.v2i32(i8*, <2 x i32>, <2 x i32>, <2 x i32>, <2 x i32>, i32) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/no-negzero.ll b/src/LLVM/test/Transforms/InstCombine/no-negzero.ll
new file mode 100644
index 0000000..f295130
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/no-negzero.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; ModuleID = '3555a.c'
+; sqrt(fabs) cannot be negative zero, so we should eliminate the fadd.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.8"
+
+; CHECK: @mysqrt
+; CHECK-NOT: fadd
+; CHECK: ret
+define double @mysqrt(double %x) nounwind {
+entry:
+ %x_addr = alloca double ; <double*> [#uses=2]
+ %retval = alloca double, align 8 ; <double*> [#uses=2]
+ %0 = alloca double, align 8 ; <double*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store double %x, double* %x_addr
+ %1 = load double* %x_addr, align 8 ; <double> [#uses=1]
+ %2 = call double @fabs(double %1) nounwind readnone ; <double> [#uses=1]
+ %3 = call double @sqrt(double %2) nounwind readonly ; <double> [#uses=1]
+ %4 = fadd double %3, 0.000000e+00 ; <double> [#uses=1]
+ store double %4, double* %0, align 8
+ %5 = load double* %0, align 8 ; <double> [#uses=1]
+ store double %5, double* %retval, align 8
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load double* %retval ; <double> [#uses=1]
+ ret double %retval1
+}
+
+declare double @fabs(double)
+
+declare double @sqrt(double) nounwind readonly
diff --git a/src/LLVM/test/Transforms/InstCombine/not-fcmp.ll b/src/LLVM/test/Transforms/InstCombine/not-fcmp.ll
new file mode 100644
index 0000000..ad01a6b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/not-fcmp.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep "fcmp uge"
+; PR1570
+
+define i1 @f(float %X, float %Y) {
+entry:
+ %tmp3 = fcmp olt float %X, %Y ; <i1> [#uses=1]
+ %toBoolnot5 = xor i1 %tmp3, true ; <i1> [#uses=1]
+ ret i1 %toBoolnot5
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/not.ll b/src/LLVM/test/Transforms/InstCombine/not.ll
new file mode 100644
index 0000000..c3134c1
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/not.ll
@@ -0,0 +1,54 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+
+; RUN: opt < %s -instcombine -S | not grep xor
+
+define i32 @test1(i32 %A) {
+ %B = xor i32 %A, -1 ; <i32> [#uses=1]
+ %C = xor i32 %B, -1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i1 @test2(i32 %A, i32 %B) {
+ ; Can change into setge
+ %cond = icmp sle i32 %A, %B ; <i1> [#uses=1]
+ %Ret = xor i1 %cond, true ; <i1> [#uses=1]
+ ret i1 %Ret
+}
+
+; Test that demorgans law can be instcombined
+define i32 @test3(i32 %A, i32 %B) {
+ %a = xor i32 %A, -1 ; <i32> [#uses=1]
+ %b = xor i32 %B, -1 ; <i32> [#uses=1]
+ %c = and i32 %a, %b ; <i32> [#uses=1]
+ %d = xor i32 %c, -1 ; <i32> [#uses=1]
+ ret i32 %d
+}
+
+; Test that demorgens law can work with constants
+define i32 @test4(i32 %A, i32 %B) {
+ %a = xor i32 %A, -1 ; <i32> [#uses=1]
+ %c = and i32 %a, 5 ; <i32> [#uses=1]
+ %d = xor i32 %c, -1 ; <i32> [#uses=1]
+ ret i32 %d
+}
+
+; test the mirror of demorgans law...
+define i32 @test5(i32 %A, i32 %B) {
+ %a = xor i32 %A, -1 ; <i32> [#uses=1]
+ %b = xor i32 %B, -1 ; <i32> [#uses=1]
+ %c = or i32 %a, %b ; <i32> [#uses=1]
+ %d = xor i32 %c, -1 ; <i32> [#uses=1]
+ ret i32 %d
+}
+
+; PR2298
+define zeroext i8 @test6(i32 %a, i32 %b) nounwind {
+entry:
+ %tmp1not = xor i32 %a, -1 ; <i32> [#uses=1]
+ %tmp2not = xor i32 %b, -1 ; <i32> [#uses=1]
+ %tmp3 = icmp slt i32 %tmp1not, %tmp2not ; <i1> [#uses=1]
+ %retval67 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
+ ret i8 %retval67
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/nothrow.ll b/src/LLVM/test/Transforms/InstCombine/nothrow.ll
new file mode 100644
index 0000000..08d90bf
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/nothrow.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | not grep call
+; rdar://6880732
+declare double @t1(i32) readonly
+
+define void @t2() nounwind {
+ call double @t1(i32 42) ;; dead call even though callee is not nothrow.
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/nsw.ll b/src/LLVM/test/Transforms/InstCombine/nsw.ll
new file mode 100644
index 0000000..0140c2f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/nsw.ll
@@ -0,0 +1,83 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; CHECK: @sub1
+; CHECK: %y = sub i32 0, %x
+; CHECK: %z = sdiv i32 %y, 337
+; CHECK: ret i32 %z
+define i32 @sub1(i32 %x) {
+ %y = sub i32 0, %x
+ %z = sdiv i32 %y, 337
+ ret i32 %z
+}
+
+; CHECK: @sub2
+; CHECK: %z = sdiv i32 %x, -337
+; CHECK: ret i32 %z
+define i32 @sub2(i32 %x) {
+ %y = sub nsw i32 0, %x
+ %z = sdiv i32 %y, 337
+ ret i32 %z
+}
+
+; CHECK: @shl_icmp
+; CHECK: %B = icmp eq i64 %X, 0
+; CHECK: ret i1 %B
+define i1 @shl_icmp(i64 %X) nounwind {
+ %A = shl nuw i64 %X, 2 ; X/4
+ %B = icmp eq i64 %A, 0
+ ret i1 %B
+}
+
+; CHECK: @shl1
+; CHECK: %B = shl nuw nsw i64 %A, 8
+; CHECK: ret i64 %B
+define i64 @shl1(i64 %X, i64* %P) nounwind {
+ %A = and i64 %X, 312
+ store i64 %A, i64* %P ; multiple uses of A.
+ %B = shl i64 %A, 8
+ ret i64 %B
+}
+
+; CHECK: @preserve1
+; CHECK: add nsw i32 %x, 5
+define i32 @preserve1(i32 %x) nounwind {
+ %add = add nsw i32 %x, 2
+ %add3 = add nsw i32 %add, 3
+ ret i32 %add3
+}
+
+; CHECK: @nopreserve1
+; CHECK: add i8 %x, -126
+define i8 @nopreserve1(i8 %x) nounwind {
+ %add = add nsw i8 %x, 127
+ %add3 = add nsw i8 %add, 3
+ ret i8 %add3
+}
+
+; CHECK: @nopreserve2
+; CHECK: add i8 %x, 3
+define i8 @nopreserve2(i8 %x) nounwind {
+ %add = add i8 %x, 1
+ %add3 = add nsw i8 %add, 2
+ ret i8 %add3
+}
+
+; CHECK: @nopreserve3
+; CHECK: add i8 %A, %B
+; CHECK: add i8
+define i8 @nopreserve3(i8 %A, i8 %B) nounwind {
+ %x = add i8 %A, 10
+ %y = add i8 %B, 10
+ %add = add nsw i8 %x, %y
+ ret i8 %add
+}
+
+; CHECK: @nopreserve4
+; CHECK: add i8 %A, %B
+; CHECK: add i8
+define i8 @nopreserve4(i8 %A, i8 %B) nounwind {
+ %x = add nsw i8 %A, 10
+ %y = add nsw i8 %B, 10
+ %add = add nsw i8 %x, %y
+ ret i8 %add
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/objsize.ll b/src/LLVM/test/Transforms/InstCombine/objsize.ll
new file mode 100644
index 0000000..28ceb68
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/objsize.ll
@@ -0,0 +1,160 @@
+; Test a pile of objectsize bounds checking.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; We need target data to get the sizes of the arrays and structures.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+@a = private global [60 x i8] zeroinitializer, align 1 ; <[60 x i8]*>
+@.str = private constant [8 x i8] c"abcdefg\00" ; <[8 x i8]*>
+
+define i32 @foo() nounwind {
+; CHECK: @foo
+; CHECK-NEXT: ret i32 60
+ %1 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false)
+ ret i32 %1
+}
+
+define i8* @bar() nounwind {
+; CHECK: @bar
+entry:
+ %retval = alloca i8*
+ %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false)
+ %cmp = icmp ne i32 %0, -1
+; CHECK: br i1 true
+ br i1 %cmp, label %cond.true, label %cond.false
+
+cond.true:
+ %1 = load i8** %retval
+ ret i8* %1
+
+cond.false:
+ %2 = load i8** %retval
+ ret i8* %2
+}
+
+define i32 @f() nounwind {
+; CHECK: @f
+; CHECK-NEXT: ret i32 0
+ %1 = call i32 @llvm.objectsize.i32(i8* getelementptr ([60 x i8]* @a, i32 1, i32 0), i1 false)
+ ret i32 %1
+}
+
+@window = external global [0 x i8]
+
+define i1 @baz() nounwind {
+; CHECK: @baz
+; CHECK-NEXT: ret i1 true
+ %1 = tail call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 0), i1 false)
+ %2 = icmp eq i32 %1, -1
+ ret i1 %2
+}
+
+define void @test1(i8* %q, i32 %x) nounwind noinline {
+; CHECK: @test1
+; CHECK: objectsize.i32
+entry:
+ %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 10), i1 false) ; <i64> [#uses=1]
+ %1 = icmp eq i32 %0, -1 ; <i1> [#uses=1]
+ br i1 %1, label %"47", label %"46"
+
+"46": ; preds = %entry
+ unreachable
+
+"47": ; preds = %entry
+ unreachable
+}
+
+@.str5 = private constant [9 x i32] [i32 97, i32 98, i32 99, i32 100, i32 0, i32
+ 101, i32 102, i32 103, i32 0], align 4
+define i32 @test2() nounwind {
+; CHECK: @test2
+; CHECK-NEXT: ret i32 34
+ %1 = call i32 @llvm.objectsize.i32(i8* getelementptr (i8* bitcast ([9 x i32]* @.str5 to i8*), i32 2), i1 false)
+ ret i32 %1
+}
+
+; rdar://7674946
+@array = internal global [480 x float] zeroinitializer ; <[480 x float]*> [#uses=1]
+
+declare i8* @__memcpy_chk(i8*, i8*, i32, i32) nounwind
+
+declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
+
+declare i8* @__inline_memcpy_chk(i8*, i8*, i32) nounwind inlinehint
+
+define void @test3() nounwind {
+; CHECK: @test3
+entry:
+ br i1 undef, label %bb11, label %bb12
+
+bb11:
+ %0 = getelementptr inbounds float* getelementptr inbounds ([480 x float]* @array, i32 0, i32 128), i32 -127 ; <float*> [#uses=1]
+ %1 = bitcast float* %0 to i8* ; <i8*> [#uses=1]
+ %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false) ; <i32> [#uses=1]
+ %3 = call i8* @__memcpy_chk(i8* undef, i8* undef, i32 512, i32 %2) nounwind ; <i8*> [#uses=0]
+; CHECK: unreachable
+ unreachable
+
+bb12:
+ %4 = getelementptr inbounds float* getelementptr inbounds ([480 x float]* @array, i32 0, i32 128), i32 -127 ; <float*> [#uses=1]
+ %5 = bitcast float* %4 to i8* ; <i8*> [#uses=1]
+ %6 = call i8* @__inline_memcpy_chk(i8* %5, i8* undef, i32 512) nounwind inlinehint ; <i8*> [#uses=0]
+; CHECK: @__inline_memcpy_chk
+ unreachable
+}
+
+; rdar://7718857
+
+%struct.data = type { [100 x i32], [100 x i32], [1024 x i8] }
+
+define i32 @test4() nounwind ssp {
+; CHECK: @test4
+entry:
+ %0 = alloca %struct.data, align 8
+ %1 = bitcast %struct.data* %0 to i8*
+ %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false) nounwind
+; CHECK-NOT: @llvm.objectsize
+; CHECK: @llvm.memset.p0i8.i32(i8* %1, i8 0, i32 1824, i32 8, i1 false)
+ %3 = call i8* @__memset_chk(i8* %1, i32 0, i32 1824, i32 %2) nounwind
+ ret i32 0
+}
+
+; rdar://7782496
+@s = external global i8*
+
+define void @test5(i32 %n) nounwind ssp {
+; CHECK: @test5
+entry:
+ %0 = tail call noalias i8* @malloc(i32 20) nounwind
+ %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false)
+ %2 = load i8** @s, align 8
+; CHECK-NOT: @llvm.objectsize
+; CHECK: @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 10, i32 1, i1 false)
+ %3 = tail call i8* @__memcpy_chk(i8* %0, i8* %2, i32 10, i32 %1) nounwind
+ ret void
+}
+
+define void @test6(i32 %n) nounwind ssp {
+; CHECK: @test6
+entry:
+ %0 = tail call noalias i8* @malloc(i32 20) nounwind
+ %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false)
+ %2 = load i8** @s, align 8
+; CHECK-NOT: @llvm.objectsize
+; CHECK: @__memcpy_chk(i8* %0, i8* %1, i32 30, i32 20)
+ %3 = tail call i8* @__memcpy_chk(i8* %0, i8* %2, i32 30, i32 %1) nounwind
+ ret void
+}
+
+declare i8* @__memset_chk(i8*, i32, i32, i32) nounwind
+
+declare noalias i8* @malloc(i32) nounwind
+
+define i32 @test7() {
+; CHECK: @test7
+ %alloc = call noalias i8* @malloc(i32 48) nounwind
+ %gep = getelementptr inbounds i8* %alloc, i32 16
+ %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
+; CHECK-NEXT: ret i32 32
+ ret i32 %objsize
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/odr-linkage.ll b/src/LLVM/test/Transforms/InstCombine/odr-linkage.ll
new file mode 100644
index 0000000..61365b4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/odr-linkage.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -instcombine -S | grep {ret i32 10}
+
+@g1 = available_externally constant i32 1
+@g2 = linkonce_odr constant i32 2
+@g3 = weak_odr constant i32 3
+@g4 = internal constant i32 4
+
+define i32 @test() {
+ %A = load i32* @g1
+ %B = load i32* @g2
+ %C = load i32* @g3
+ %D = load i32* @g4
+
+ %a = add i32 %A, %B
+ %b = add i32 %a, %C
+ %c = add i32 %b, %D
+ ret i32 %c
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/or-fcmp.ll b/src/LLVM/test/Transforms/InstCombine/or-fcmp.ll
new file mode 100644
index 0000000..09a3c99
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/or-fcmp.ll
@@ -0,0 +1,58 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; CHECK: @t1
+define zeroext i8 @t1(float %x, float %y) nounwind {
+ %a = fcmp ueq float %x, %y ; <i1> [#uses=1]
+ %b = fcmp uno float %x, %y ; <i1> [#uses=1]
+ %c = or i1 %a, %b
+; CHECK-NOT: fcmp uno
+; CHECK: fcmp ueq
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+; CHECK: @t2
+define zeroext i8 @t2(float %x, float %y) nounwind {
+ %a = fcmp olt float %x, %y ; <i1> [#uses=1]
+ %b = fcmp oeq float %x, %y ; <i1> [#uses=1]
+; CHECK-NOT: fcmp olt
+; CHECK-NOT: fcmp oeq
+; CHECK: fcmp ole
+ %c = or i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+; CHECK: @t3
+define zeroext i8 @t3(float %x, float %y) nounwind {
+ %a = fcmp ult float %x, %y ; <i1> [#uses=1]
+ %b = fcmp uge float %x, %y ; <i1> [#uses=1]
+ %c = or i1 %a, %b
+ %retval = zext i1 %c to i8
+; CHECK: ret i8 1
+ ret i8 %retval
+}
+
+; CHECK: @t4
+define zeroext i8 @t4(float %x, float %y) nounwind {
+ %a = fcmp ult float %x, %y ; <i1> [#uses=1]
+ %b = fcmp ugt float %x, %y ; <i1> [#uses=1]
+ %c = or i1 %a, %b
+; CHECK-NOT: fcmp ult
+; CHECK-NOT: fcmp ugt
+; CHECK: fcmp une
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
+
+; CHECK: @t5
+define zeroext i8 @t5(float %x, float %y) nounwind {
+ %a = fcmp olt float %x, %y ; <i1> [#uses=1]
+ %b = fcmp oge float %x, %y ; <i1> [#uses=1]
+ %c = or i1 %a, %b
+; CHECK-NOT: fcmp olt
+; CHECK-NOT: fcmp oge
+; CHECK: fcmp ord
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/or-to-xor.ll b/src/LLVM/test/Transforms/InstCombine/or-to-xor.ll
new file mode 100644
index 0000000..1495ee4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/or-to-xor.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -instcombine -S | grep {xor i32 %a, %b} | count 4
+; RUN: opt < %s -instcombine -S | not grep {and}
+
+define i32 @func1(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %a, %b_not
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %a_not, %b
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func2(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %b_not, %a
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %a_not, %b
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func3(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %a, %b_not
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %b, %a_not
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
+
+define i32 @func4(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %b_not = xor i32 %b, -1
+ %0 = and i32 %b_not, %a
+ %a_not = xor i32 %a, -1
+ %1 = and i32 %b, %a_not
+ %2 = or i32 %0, %1
+ ret i32 %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/or-xor.ll b/src/LLVM/test/Transforms/InstCombine/or-xor.ll
new file mode 100644
index 0000000..f496dd4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/or-xor.ll
@@ -0,0 +1,94 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+define i32 @test1(i32 %x, i32 %y) nounwind {
+ %or = or i32 %x, %y
+ %not = xor i32 %or, -1
+ %z = or i32 %x, %not
+ ret i32 %z
+; CHECK: @test1
+; CHECK-NEXT: %y.not = xor i32 %y, -1
+; CHECK-NEXT: %z = or i32 %y.not, %x
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test2(i32 %x, i32 %y) nounwind {
+ %or = or i32 %x, %y
+ %not = xor i32 %or, -1
+ %z = or i32 %y, %not
+ ret i32 %z
+; CHECK: @test2
+; CHECK-NEXT: %x.not = xor i32 %x, -1
+; CHECK-NEXT: %z = or i32 %x.not, %y
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test3(i32 %x, i32 %y) nounwind {
+ %xor = xor i32 %x, %y
+ %not = xor i32 %xor, -1
+ %z = or i32 %x, %not
+ ret i32 %z
+; CHECK: @test3
+; CHECK-NEXT: %y.not = xor i32 %y, -1
+; CHECK-NEXT: %z = or i32 %y.not, %x
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test4(i32 %x, i32 %y) nounwind {
+ %xor = xor i32 %x, %y
+ %not = xor i32 %xor, -1
+ %z = or i32 %y, %not
+ ret i32 %z
+; CHECK: @test4
+; CHECK-NEXT: %x.not = xor i32 %x, -1
+; CHECK-NEXT: %z = or i32 %x.not, %y
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test5(i32 %x, i32 %y) nounwind {
+ %and = and i32 %x, %y
+ %not = xor i32 %and, -1
+ %z = or i32 %x, %not
+ ret i32 %z
+; CHECK: @test5
+; CHECK-NEXT: ret i32 -1
+}
+
+define i32 @test6(i32 %x, i32 %y) nounwind {
+ %and = and i32 %x, %y
+ %not = xor i32 %and, -1
+ %z = or i32 %y, %not
+ ret i32 %z
+; CHECK: @test6
+; CHECK-NEXT: ret i32 -1
+}
+
+define i32 @test7(i32 %x, i32 %y) nounwind {
+ %xor = xor i32 %x, %y
+ %z = or i32 %y, %xor
+ ret i32 %z
+; CHECK: @test7
+; CHECK-NEXT: %z = or i32 %x, %y
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test8(i32 %x, i32 %y) nounwind {
+ %not = xor i32 %y, -1
+ %xor = xor i32 %x, %not
+ %z = or i32 %y, %xor
+ ret i32 %z
+; CHECK: @test8
+; CHECK-NEXT: %x.not = xor i32 %x, -1
+; CHECK-NEXT: %z = or i32 %x.not, %y
+; CHECK-NEXT: ret i32 %z
+}
+
+define i32 @test9(i32 %x, i32 %y) nounwind {
+ %not = xor i32 %x, -1
+ %xor = xor i32 %not, %y
+ %z = or i32 %x, %xor
+ ret i32 %z
+; CHECK: @test9
+; CHECK-NEXT: %y.not = xor i32 %y, -1
+; CHECK-NEXT: %z = or i32 %y.not, %x
+; CHECK-NEXT: ret i32 %z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/or.ll b/src/LLVM/test/Transforms/InstCombine/or.ll
new file mode 100644
index 0000000..693fa77
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/or.ll
@@ -0,0 +1,411 @@
+; This test makes sure that these instructions are properly eliminated.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+define i32 @test1(i32 %A) {
+ %B = or i32 %A, 0
+ ret i32 %B
+; CHECK: @test1
+; CHECK: ret i32 %A
+}
+
+define i32 @test2(i32 %A) {
+ %B = or i32 %A, -1
+ ret i32 %B
+; CHECK: @test2
+; CHECK: ret i32 -1
+}
+
+define i8 @test2a(i8 %A) {
+ %B = or i8 %A, -1
+ ret i8 %B
+; CHECK: @test2a
+; CHECK: ret i8 -1
+}
+
+define i1 @test3(i1 %A) {
+ %B = or i1 %A, false
+ ret i1 %B
+; CHECK: @test3
+; CHECK: ret i1 %A
+}
+
+define i1 @test4(i1 %A) {
+ %B = or i1 %A, true
+ ret i1 %B
+; CHECK: @test4
+; CHECK: ret i1 true
+}
+
+define i1 @test5(i1 %A) {
+ %B = or i1 %A, %A
+ ret i1 %B
+; CHECK: @test5
+; CHECK: ret i1 %A
+}
+
+define i32 @test6(i32 %A) {
+ %B = or i32 %A, %A
+ ret i32 %B
+; CHECK: @test6
+; CHECK: ret i32 %A
+}
+
+; A | ~A == -1
+define i32 @test7(i32 %A) {
+ %NotA = xor i32 -1, %A
+ %B = or i32 %A, %NotA
+ ret i32 %B
+; CHECK: @test7
+; CHECK: ret i32 -1
+}
+
+define i8 @test8(i8 %A) {
+ %B = or i8 %A, -2
+ %C = or i8 %B, 1
+ ret i8 %C
+; CHECK: @test8
+; CHECK: ret i8 -1
+}
+
+; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
+define i8 @test9(i8 %A, i8 %B) {
+ %C = or i8 %A, 1
+ %D = or i8 %B, -2
+ %E = or i8 %C, %D
+ ret i8 %E
+; CHECK: @test9
+; CHECK: ret i8 -1
+}
+
+define i8 @test10(i8 %A) {
+ %B = or i8 %A, 1
+ %C = and i8 %B, -2
+ ; (X & C1) | C2 --> (X | C2) & (C1|C2)
+ %D = or i8 %C, -2
+ ret i8 %D
+; CHECK: @test10
+; CHECK: ret i8 -2
+}
+
+define i8 @test11(i8 %A) {
+ %B = or i8 %A, -2
+ %C = xor i8 %B, 13
+ ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
+ %D = or i8 %C, 1
+ %E = xor i8 %D, 12
+ ret i8 %E
+; CHECK: @test11
+; CHECK: ret i8 -1
+}
+
+define i32 @test12(i32 %A) {
+ ; Should be eliminated
+ %B = or i32 %A, 4
+ %C = and i32 %B, 8
+ ret i32 %C
+; CHECK: @test12
+; CHECK: %C = and i32 %A, 8
+; CHECK: ret i32 %C
+}
+
+define i32 @test13(i32 %A) {
+ %B = or i32 %A, 12
+ ; Always equal to 8
+ %C = and i32 %B, 8
+ ret i32 %C
+; CHECK: @test13
+; CHECK: ret i32 8
+}
+
+define i1 @test14(i32 %A, i32 %B) {
+ %C1 = icmp ult i32 %A, %B
+ %C2 = icmp ugt i32 %A, %B
+ ; (A < B) | (A > B) === A != B
+ %D = or i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test14
+; CHECK: icmp ne i32 %A, %B
+; CHECK: ret i1
+}
+
+define i1 @test15(i32 %A, i32 %B) {
+ %C1 = icmp ult i32 %A, %B
+ %C2 = icmp eq i32 %A, %B
+ ; (A < B) | (A == B) === A <= B
+ %D = or i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test15
+; CHECK: icmp ule i32 %A, %B
+; CHECK: ret i1
+}
+
+define i32 @test16(i32 %A) {
+ %B = and i32 %A, 1
+ ; -2 = ~1
+ %C = and i32 %A, -2
+ ; %D = and int %B, -1 == %B
+ %D = or i32 %B, %C
+ ret i32 %D
+; CHECK: @test16
+; CHECK: ret i32 %A
+}
+
+define i32 @test17(i32 %A) {
+ %B = and i32 %A, 1
+ %C = and i32 %A, 4
+ ; %D = and int %B, 5
+ %D = or i32 %B, %C
+ ret i32 %D
+; CHECK: @test17
+; CHECK: %D = and i32 %A, 5
+; CHECK: ret i32 %D
+}
+
+define i1 @test18(i32 %A) {
+ %B = icmp sge i32 %A, 100
+ %C = icmp slt i32 %A, 50
+ ;; (A-50) >u 50
+ %D = or i1 %B, %C
+ ret i1 %D
+; CHECK: @test18
+; CHECK: add i32
+; CHECK: icmp ugt
+; CHECK: ret i1
+}
+
+define i1 @test19(i32 %A) {
+ %B = icmp eq i32 %A, 50
+ %C = icmp eq i32 %A, 51
+ ;; (A-50) < 2
+ %D = or i1 %B, %C
+ ret i1 %D
+; CHECK: @test19
+; CHECK: add i32
+; CHECK: icmp ult
+; CHECK: ret i1
+}
+
+define i32 @test20(i32 %x) {
+ %y = and i32 %x, 123
+ %z = or i32 %y, %x
+ ret i32 %z
+; CHECK: @test20
+; CHECK: ret i32 %x
+}
+
+define i32 @test21(i32 %tmp.1) {
+ %tmp.1.mask1 = add i32 %tmp.1, 2
+ %tmp.3 = and i32 %tmp.1.mask1, -2
+ %tmp.5 = and i32 %tmp.1, 1
+ ;; add tmp.1, 2
+ %tmp.6 = or i32 %tmp.5, %tmp.3
+ ret i32 %tmp.6
+; CHECK: @test21
+; CHECK: add i32 %{{[^,]*}}, 2
+; CHECK: ret i32
+}
+
+define i32 @test22(i32 %B) {
+ %ELIM41 = and i32 %B, 1
+ %ELIM7 = and i32 %B, -2
+ %ELIM5 = or i32 %ELIM41, %ELIM7
+ ret i32 %ELIM5
+; CHECK: @test22
+; CHECK: ret i32 %B
+}
+
+define i16 @test23(i16 %A) {
+ %B = lshr i16 %A, 1
+ ;; fold or into xor
+ %C = or i16 %B, -32768
+ %D = xor i16 %C, 8193
+ ret i16 %D
+; CHECK: @test23
+; CHECK: %B = lshr i16 %A, 1
+; CHECK: %D = xor i16 %B, -24575
+; CHECK: ret i16 %D
+}
+
+; PR1738
+define i1 @test24(double %X, double %Y) {
+ %tmp9 = fcmp uno double %X, 0.000000e+00 ; <i1> [#uses=1]
+ %tmp13 = fcmp uno double %Y, 0.000000e+00 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp13, %tmp9 ; <i1> [#uses=1]
+ ret i1 %bothcond
+
+; CHECK: @test24
+; CHECK: = fcmp uno double %Y, %X
+; CHECK: ret i1
+}
+
+; PR3266 & PR5276
+define i1 @test25(i32 %A, i32 %B) {
+ %C = icmp eq i32 %A, 0
+ %D = icmp eq i32 %B, 57
+ %E = or i1 %C, %D
+ %F = xor i1 %E, -1
+ ret i1 %F
+
+; CHECK: @test25
+; CHECK: icmp ne i32 %A, 0
+; CHECK-NEXT: icmp ne i32 %B, 57
+; CHECK-NEXT: %F = and i1
+; CHECK-NEXT: ret i1 %F
+}
+
+; PR5634
+define i1 @test26(i32 %A, i32 %B) {
+ %C1 = icmp eq i32 %A, 0
+ %C2 = icmp eq i32 %B, 0
+ ; (A == 0) & (A == 0) --> (A|B) == 0
+ %D = and i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test26
+; CHECK: or i32 %A, %B
+; CHECK: icmp eq i32 {{.*}}, 0
+; CHECK: ret i1
+}
+
+define i1 @test27(i32* %A, i32* %B) {
+ %C1 = ptrtoint i32* %A to i32
+ %C2 = ptrtoint i32* %B to i32
+ %D = or i32 %C1, %C2
+ %E = icmp eq i32 %D, 0
+ ret i1 %E
+; CHECK: @test27
+; CHECK: icmp eq i32* %A, null
+; CHECK: icmp eq i32* %B, null
+; CHECK: and i1
+; CHECK: ret i1
+}
+
+; PR5634
+define i1 @test28(i32 %A, i32 %B) {
+ %C1 = icmp ne i32 %A, 0
+ %C2 = icmp ne i32 %B, 0
+ ; (A != 0) | (A != 0) --> (A|B) != 0
+ %D = or i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test28
+; CHECK: or i32 %A, %B
+; CHECK: icmp ne i32 {{.*}}, 0
+; CHECK: ret i1
+}
+
+define i1 @test29(i32* %A, i32* %B) {
+ %C1 = ptrtoint i32* %A to i32
+ %C2 = ptrtoint i32* %B to i32
+ %D = or i32 %C1, %C2
+ %E = icmp ne i32 %D, 0
+ ret i1 %E
+; CHECK: @test29
+; CHECK: icmp ne i32* %A, null
+; CHECK: icmp ne i32* %B, null
+; CHECK: or i1
+; CHECK: ret i1
+}
+
+; PR4216
+define i32 @test30(i32 %A) {
+entry:
+ %B = or i32 %A, 32962
+ %C = and i32 %A, -65536
+ %D = and i32 %B, 40186
+ %E = or i32 %D, %C
+ ret i32 %E
+; CHECK: @test30
+; CHECK: %D = and i32 %A, -58312
+; CHECK: %E = or i32 %D, 32962
+; CHECK: ret i32 %E
+}
+
+; PR4216
+define i64 @test31(i64 %A) nounwind readnone ssp noredzone {
+ %B = or i64 %A, 194
+ %D = and i64 %B, 250
+
+ %C = or i64 %A, 32768
+ %E = and i64 %C, 4294941696
+
+ %F = or i64 %D, %E
+ ret i64 %F
+; CHECK: @test31
+; CHECK-NEXT: %E = and i64 %A, 4294908984
+; CHECK-NEXT: %F = or i64 %E, 32962
+; CHECK-NEXT: ret i64 %F
+}
+
+define <4 x i32> @test32(<4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32> %vecinit6.i191) {
+ %and.i135 = sext <4 x i1> %and.i1352 to <4 x i32> ; <<4 x i32>> [#uses=2]
+ %and.i129 = and <4 x i32> %vecinit6.i176, %and.i135 ; <<4 x i32>> [#uses=1]
+ %neg.i = xor <4 x i32> %and.i135, <i32 -1, i32 -1, i32 -1, i32 -1> ; <<4 x i32>> [#uses=1]
+ %and.i = and <4 x i32> %vecinit6.i191, %neg.i ; <<4 x i32>> [#uses=1]
+ %or.i = or <4 x i32> %and.i, %and.i129 ; <<4 x i32>> [#uses=1]
+ ret <4 x i32> %or.i
+; Don't turn this into a vector select until codegen matures to handle them
+; better.
+; CHECK: @test32
+; CHECK: or <4 x i32> %and.i, %and.i129
+}
+
+define i1 @test33(i1 %X, i1 %Y) {
+ %a = or i1 %X, %Y
+ %b = or i1 %a, %X
+ ret i1 %b
+; CHECK: @test33
+; CHECK-NEXT: or i1 %X, %Y
+; CHECK-NEXT: ret
+}
+
+define i32 @test34(i32 %X, i32 %Y) {
+ %a = or i32 %X, %Y
+ %b = or i32 %Y, %a
+ ret i32 %b
+; CHECK: @test34
+; CHECK-NEXT: or i32 %X, %Y
+; CHECK-NEXT: ret
+}
+
+define i32 @test35(i32 %a, i32 %b) {
+ %1 = or i32 %a, 1135
+ %2 = or i32 %1, %b
+ ret i32 %2
+ ; CHECK: @test35
+ ; CHECK-NEXT: or i32 %a, %b
+ ; CHECK-NEXT: or i32 %1, 1135
+}
+
+define i1 @test36(i32 %x) {
+ %cmp1 = icmp eq i32 %x, 23
+ %cmp2 = icmp eq i32 %x, 24
+ %ret1 = or i1 %cmp1, %cmp2
+ %cmp3 = icmp eq i32 %x, 25
+ %ret2 = or i1 %ret1, %cmp3
+ ret i1 %ret2
+; CHECK: @test36
+; CHECK-NEXT: %x.off = add i32 %x, -23
+; CHECK-NEXT: icmp ult i32 %x.off, 3
+; CHECK-NEXT: ret i1
+}
+
+define i32 @test37(i32* %xp, i32 %y) {
+; CHECK: @test37
+; CHECK: select i1 %tobool, i32 -1, i32 %x
+ %tobool = icmp ne i32 %y, 0
+ %sext = sext i1 %tobool to i32
+ %x = load i32* %xp
+ %or = or i32 %sext, %x
+ ret i32 %or
+}
+
+define i32 @test38(i32* %xp, i32 %y) {
+; CHECK: @test38
+; CHECK: select i1 %tobool, i32 -1, i32 %x
+ %tobool = icmp ne i32 %y, 0
+ %sext = sext i1 %tobool to i32
+ %x = load i32* %xp
+ %or = or i32 %x, %sext
+ ret i32 %or
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/overflow.ll b/src/LLVM/test/Transforms/InstCombine/overflow.ll
new file mode 100644
index 0000000..9123283
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/overflow.ll
@@ -0,0 +1,133 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+; <rdar://problem/8558713>
+
+declare void @throwAnExceptionOrWhatever()
+
+; CHECK: @test1
+define i32 @test1(i32 %a, i32 %b) nounwind ssp {
+entry:
+; CHECK-NOT: sext
+ %conv = sext i32 %a to i64
+ %conv2 = sext i32 %b to i64
+ %add = add nsw i64 %conv2, %conv
+ %add.off = add i64 %add, 2147483648
+; CHECK: llvm.sadd.with.overflow.i32
+ %0 = icmp ugt i64 %add.off, 4294967295
+ br i1 %0, label %if.then, label %if.end
+
+if.then:
+ tail call void @throwAnExceptionOrWhatever() nounwind
+ br label %if.end
+
+if.end:
+; CHECK-NOT: trunc
+ %conv9 = trunc i64 %add to i32
+; CHECK: ret i32
+ ret i32 %conv9
+}
+
+; CHECK: @test2
+; This form should not be promoted for two reasons: 1) it is unprofitable to
+; promote it since the add.off instruction has another use, and 2) it is unsafe
+; because the add-with-off makes the high bits of the original add live.
+define i32 @test2(i32 %a, i32 %b, i64* %P) nounwind ssp {
+entry:
+ %conv = sext i32 %a to i64
+ %conv2 = sext i32 %b to i64
+ %add = add nsw i64 %conv2, %conv
+ %add.off = add i64 %add, 2147483648
+
+ store i64 %add.off, i64* %P
+
+; CHECK-NOT: llvm.sadd.with.overflow
+ %0 = icmp ugt i64 %add.off, 4294967295
+ br i1 %0, label %if.then, label %if.end
+
+if.then:
+ tail call void @throwAnExceptionOrWhatever() nounwind
+ br label %if.end
+
+if.end:
+ %conv9 = trunc i64 %add to i32
+; CHECK: ret i32
+ ret i32 %conv9
+}
+
+; CHECK: test3
+; PR8816
+; This is illegal to transform because the high bits of the original add are
+; live out.
+define i64 @test3(i32 %a, i32 %b) nounwind ssp {
+entry:
+ %conv = sext i32 %a to i64
+ %conv2 = sext i32 %b to i64
+ %add = add nsw i64 %conv2, %conv
+ %add.off = add i64 %add, 2147483648
+; CHECK-NOT: llvm.sadd.with.overflow
+ %0 = icmp ugt i64 %add.off, 4294967295
+ br i1 %0, label %if.then, label %if.end
+
+if.then:
+ tail call void @throwAnExceptionOrWhatever() nounwind
+ br label %if.end
+
+if.end:
+ ret i64 %add
+; CHECK: ret i64
+}
+
+; CHECK: @test4
+; Should be able to form an i8 sadd computed in an i32.
+define zeroext i8 @test4(i8 signext %a, i8 signext %b) nounwind ssp {
+entry:
+ %conv = sext i8 %a to i32
+ %conv2 = sext i8 %b to i32
+ %add = add nsw i32 %conv2, %conv
+ %add4 = add nsw i32 %add, 128
+ %cmp = icmp ugt i32 %add4, 255
+ br i1 %cmp, label %if.then, label %if.end
+; CHECK: llvm.sadd.with.overflow.i8
+if.then: ; preds = %entry
+ tail call void @throwAnExceptionOrWhatever() nounwind
+ unreachable
+
+if.end: ; preds = %entry
+ %conv7 = trunc i32 %add to i8
+ ret i8 %conv7
+; CHECK: ret i8
+}
+
+; CHECK: @test5
+; CHECK: llvm.uadd.with.overflow
+; CHECK: ret i64
+define i64 @test5(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %add = add i64 %b, %a
+ %cmp = icmp ult i64 %add, %a
+ %Q = select i1 %cmp, i64 %b, i64 42
+ ret i64 %Q
+}
+
+; CHECK: @test6
+; CHECK: llvm.uadd.with.overflow
+; CHECK: ret i64
+define i64 @test6(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %add = add i64 %b, %a
+ %cmp = icmp ult i64 %add, %b
+ %Q = select i1 %cmp, i64 %b, i64 42
+ ret i64 %Q
+}
+
+; CHECK: @test7
+; CHECK: llvm.uadd.with.overflow
+; CHECK: ret i64
+define i64 @test7(i64 %a, i64 %b) nounwind ssp {
+entry:
+ %add = add i64 %b, %a
+ %cmp = icmp ugt i64 %b, %add
+ %Q = select i1 %cmp, i64 %b, i64 42
+ ret i64 %Q
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/phi-merge-gep.ll b/src/LLVM/test/Transforms/InstCombine/phi-merge-gep.ll
new file mode 100644
index 0000000..2671749
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/phi-merge-gep.ll
@@ -0,0 +1,102 @@
+; RUN: opt < %s -S -instcombine > %t
+; RUN: grep {= getelementptr} %t | count 20
+; RUN: grep {= phi} %t | count 13
+
+; Don't push the geps through these phis, because they would require
+; two phis each, which burdens the loop with high register pressure.
+
+define void @foo(float* %Ar, float* %Ai, i64 %As, float* %Cr, float* %Ci, i64 %Cs, i64 %n) nounwind {
+entry:
+ %0 = getelementptr inbounds float* %Ar, i64 0 ; <float*> [#uses=1]
+ %1 = getelementptr inbounds float* %Ai, i64 0 ; <float*> [#uses=1]
+ %2 = mul i64 %n, %As ; <i64> [#uses=1]
+ %3 = getelementptr inbounds float* %Ar, i64 %2 ; <float*> [#uses=1]
+ %4 = mul i64 %n, %As ; <i64> [#uses=1]
+ %5 = getelementptr inbounds float* %Ai, i64 %4 ; <float*> [#uses=1]
+ %6 = mul i64 %n, 2 ; <i64> [#uses=1]
+ %7 = mul i64 %6, %As ; <i64> [#uses=1]
+ %8 = getelementptr inbounds float* %Ar, i64 %7 ; <float*> [#uses=1]
+ %9 = mul i64 %n, 2 ; <i64> [#uses=1]
+ %10 = mul i64 %9, %As ; <i64> [#uses=1]
+ %11 = getelementptr inbounds float* %Ai, i64 %10 ; <float*> [#uses=1]
+ %12 = getelementptr inbounds float* %Cr, i64 0 ; <float*> [#uses=1]
+ %13 = getelementptr inbounds float* %Ci, i64 0 ; <float*> [#uses=1]
+ %14 = mul i64 %n, %Cs ; <i64> [#uses=1]
+ %15 = getelementptr inbounds float* %Cr, i64 %14 ; <float*> [#uses=1]
+ %16 = mul i64 %n, %Cs ; <i64> [#uses=1]
+ %17 = getelementptr inbounds float* %Ci, i64 %16 ; <float*> [#uses=1]
+ %18 = mul i64 %n, 2 ; <i64> [#uses=1]
+ %19 = mul i64 %18, %Cs ; <i64> [#uses=1]
+ %20 = getelementptr inbounds float* %Cr, i64 %19 ; <float*> [#uses=1]
+ %21 = mul i64 %n, 2 ; <i64> [#uses=1]
+ %22 = mul i64 %21, %Cs ; <i64> [#uses=1]
+ %23 = getelementptr inbounds float* %Ci, i64 %22 ; <float*> [#uses=1]
+ br label %bb13
+
+bb: ; preds = %bb13
+ %24 = load float* %A0r.0, align 4 ; <float> [#uses=1]
+ %25 = load float* %A0i.0, align 4 ; <float> [#uses=1]
+ %26 = load float* %A1r.0, align 4 ; <float> [#uses=2]
+ %27 = load float* %A1i.0, align 4 ; <float> [#uses=2]
+ %28 = load float* %A2r.0, align 4 ; <float> [#uses=2]
+ %29 = load float* %A2i.0, align 4 ; <float> [#uses=2]
+ %30 = fadd float %26, %28 ; <float> [#uses=2]
+ %31 = fadd float %27, %29 ; <float> [#uses=2]
+ %32 = fsub float %26, %28 ; <float> [#uses=1]
+ %33 = fsub float %27, %29 ; <float> [#uses=1]
+ %34 = fadd float %24, %30 ; <float> [#uses=2]
+ %35 = fadd float %25, %31 ; <float> [#uses=2]
+ %36 = fmul float %30, -1.500000e+00 ; <float> [#uses=1]
+ %37 = fmul float %31, -1.500000e+00 ; <float> [#uses=1]
+ %38 = fadd float %34, %36 ; <float> [#uses=2]
+ %39 = fadd float %35, %37 ; <float> [#uses=2]
+ %40 = fmul float %32, 0x3FEBB67AE0000000 ; <float> [#uses=2]
+ %41 = fmul float %33, 0x3FEBB67AE0000000 ; <float> [#uses=2]
+ %42 = fadd float %38, %41 ; <float> [#uses=1]
+ %43 = fsub float %39, %40 ; <float> [#uses=1]
+ %44 = fsub float %38, %41 ; <float> [#uses=1]
+ %45 = fadd float %39, %40 ; <float> [#uses=1]
+ store float %34, float* %C0r.0, align 4
+ store float %35, float* %C0i.0, align 4
+ store float %42, float* %C1r.0, align 4
+ store float %43, float* %C1i.0, align 4
+ store float %44, float* %C2r.0, align 4
+ store float %45, float* %C2i.0, align 4
+ %46 = getelementptr inbounds float* %A0r.0, i64 %As ; <float*> [#uses=1]
+ %47 = getelementptr inbounds float* %A0i.0, i64 %As ; <float*> [#uses=1]
+ %48 = getelementptr inbounds float* %A1r.0, i64 %As ; <float*> [#uses=1]
+ %49 = getelementptr inbounds float* %A1i.0, i64 %As ; <float*> [#uses=1]
+ %50 = getelementptr inbounds float* %A2r.0, i64 %As ; <float*> [#uses=1]
+ %51 = getelementptr inbounds float* %A2i.0, i64 %As ; <float*> [#uses=1]
+ %52 = getelementptr inbounds float* %C0r.0, i64 %Cs ; <float*> [#uses=1]
+ %53 = getelementptr inbounds float* %C0i.0, i64 %Cs ; <float*> [#uses=1]
+ %54 = getelementptr inbounds float* %C1r.0, i64 %Cs ; <float*> [#uses=1]
+ %55 = getelementptr inbounds float* %C1i.0, i64 %Cs ; <float*> [#uses=1]
+ %56 = getelementptr inbounds float* %C2r.0, i64 %Cs ; <float*> [#uses=1]
+ %57 = getelementptr inbounds float* %C2i.0, i64 %Cs ; <float*> [#uses=1]
+ %58 = add nsw i64 %i.0, 1 ; <i64> [#uses=1]
+ br label %bb13
+
+bb13: ; preds = %bb, %entry
+ %i.0 = phi i64 [ 0, %entry ], [ %58, %bb ] ; <i64> [#uses=2]
+ %C2i.0 = phi float* [ %23, %entry ], [ %57, %bb ] ; <float*> [#uses=2]
+ %C2r.0 = phi float* [ %20, %entry ], [ %56, %bb ] ; <float*> [#uses=2]
+ %C1i.0 = phi float* [ %17, %entry ], [ %55, %bb ] ; <float*> [#uses=2]
+ %C1r.0 = phi float* [ %15, %entry ], [ %54, %bb ] ; <float*> [#uses=2]
+ %C0i.0 = phi float* [ %13, %entry ], [ %53, %bb ] ; <float*> [#uses=2]
+ %C0r.0 = phi float* [ %12, %entry ], [ %52, %bb ] ; <float*> [#uses=2]
+ %A2i.0 = phi float* [ %11, %entry ], [ %51, %bb ] ; <float*> [#uses=2]
+ %A2r.0 = phi float* [ %8, %entry ], [ %50, %bb ] ; <float*> [#uses=2]
+ %A1i.0 = phi float* [ %5, %entry ], [ %49, %bb ] ; <float*> [#uses=2]
+ %A1r.0 = phi float* [ %3, %entry ], [ %48, %bb ] ; <float*> [#uses=2]
+ %A0i.0 = phi float* [ %1, %entry ], [ %47, %bb ] ; <float*> [#uses=2]
+ %A0r.0 = phi float* [ %0, %entry ], [ %46, %bb ] ; <float*> [#uses=2]
+ %59 = icmp slt i64 %i.0, %n ; <i1> [#uses=1]
+ br i1 %59, label %bb, label %bb14
+
+bb14: ; preds = %bb13
+ br label %return
+
+return: ; preds = %bb14
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/phi.ll b/src/LLVM/test/Transforms/InstCombine/phi.ll
new file mode 100644
index 0000000..67e93b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/phi.ll
@@ -0,0 +1,622 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128:n8:16:32:64"
+
+define i32 @test1(i32 %A, i1 %b) {
+BB0:
+ br i1 %b, label %BB1, label %BB2
+
+BB1:
+ ; Combine away one argument PHI nodes
+ %B = phi i32 [ %A, %BB0 ]
+ ret i32 %B
+
+BB2:
+ ret i32 %A
+; CHECK: @test1
+; CHECK: BB1:
+; CHECK-NEXT: ret i32 %A
+}
+
+define i32 @test2(i32 %A, i1 %b) {
+BB0:
+ br i1 %b, label %BB1, label %BB2
+
+BB1:
+ br label %BB2
+
+BB2:
+ ; Combine away PHI nodes with same values
+ %B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ]
+ ret i32 %B
+; CHECK: @test2
+; CHECK: BB2:
+; CHECK-NEXT: ret i32 %A
+}
+
+define i32 @test3(i32 %A, i1 %b) {
+BB0:
+ br label %Loop
+
+Loop:
+ ; PHI has same value always.
+ %B = phi i32 [ %A, %BB0 ], [ %B, %Loop ]
+ br i1 %b, label %Loop, label %Exit
+
+Exit:
+ ret i32 %B
+; CHECK: @test3
+; CHECK: Exit:
+; CHECK-NEXT: ret i32 %A
+}
+
+define i32 @test4(i1 %b) {
+BB0:
+ ; Loop is unreachable
+ ret i32 7
+
+Loop: ; preds = %L2, %Loop
+ ; PHI has same value always.
+ %B = phi i32 [ %B, %L2 ], [ %B, %Loop ]
+ br i1 %b, label %L2, label %Loop
+
+L2: ; preds = %Loop
+ br label %Loop
+; CHECK: @test4
+; CHECK: Loop:
+; CHECK-NEXT: br i1 %b
+}
+
+define i32 @test5(i32 %A, i1 %b) {
+BB0:
+ br label %Loop
+
+Loop: ; preds = %Loop, %BB0
+ ; PHI has same value always.
+ %B = phi i32 [ %A, %BB0 ], [ undef, %Loop ]
+ br i1 %b, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ ret i32 %B
+; CHECK: @test5
+; CHECK: Loop:
+; CHECK-NEXT: br i1 %b
+; CHECK: Exit:
+; CHECK-NEXT: ret i32 %A
+}
+
+define i32 @test6(i16 %A, i1 %b) {
+BB0:
+ %X = zext i16 %A to i32
+ br i1 %b, label %BB1, label %BB2
+
+BB1:
+ %Y = zext i16 %A to i32
+ br label %BB2
+
+BB2:
+ ;; Suck casts into phi
+ %B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
+ ret i32 %B
+; CHECK: @test6
+; CHECK: BB2:
+; CHECK: zext i16 %A to i32
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test7(i32 %A, i1 %b) {
+BB0:
+ br label %Loop
+
+Loop: ; preds = %Loop, %BB0
+ ; PHI is dead.
+ %B = phi i32 [ %A, %BB0 ], [ %C, %Loop ]
+ %C = add i32 %B, 123
+ br i1 %b, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ ret i32 0
+; CHECK: @test7
+; CHECK: Loop:
+; CHECK-NEXT: br i1 %b
+}
+
+define i32* @test8({ i32, i32 } *%A, i1 %b) {
+BB0:
+ %X = getelementptr inbounds { i32, i32 } *%A, i32 0, i32 1
+ br i1 %b, label %BB1, label %BB2
+
+BB1:
+ %Y = getelementptr { i32, i32 } *%A, i32 0, i32 1
+ br label %BB2
+
+BB2:
+ ;; Suck GEPs into phi
+ %B = phi i32* [ %X, %BB0 ], [ %Y, %BB1 ]
+ ret i32* %B
+; CHECK: @test8
+; CHECK-NOT: phi
+; CHECK: BB2:
+; CHECK-NEXT: %B = getelementptr { i32, i32 }* %A
+; CHECK-NEXT: ret i32* %B
+}
+
+define i32 @test9(i32* %A, i32* %B) {
+entry:
+ %c = icmp eq i32* %A, null
+ br i1 %c, label %bb1, label %bb
+
+bb:
+ %C = load i32* %B, align 1
+ br label %bb2
+
+bb1:
+ %D = load i32* %A, align 1
+ br label %bb2
+
+bb2:
+ %E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
+ ret i32 %E
+; CHECK: @test9
+; CHECK: bb2:
+; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
+; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 1
+; CHECK-NEXT: ret i32 %E
+
+}
+
+define i32 @test10(i32* %A, i32* %B) {
+entry:
+ %c = icmp eq i32* %A, null
+ br i1 %c, label %bb1, label %bb
+
+bb:
+ %C = load i32* %B, align 16
+ br label %bb2
+
+bb1:
+ %D = load i32* %A, align 32
+ br label %bb2
+
+bb2:
+ %E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
+ ret i32 %E
+; CHECK: @test10
+; CHECK: bb2:
+; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
+; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 16
+; CHECK-NEXT: ret i32 %E
+}
+
+
+; PR1777
+declare i1 @test11a()
+
+define i1 @test11() {
+entry:
+ %a = alloca i32
+ %i = ptrtoint i32* %a to i64
+ %b = call i1 @test11a()
+ br i1 %b, label %one, label %two
+
+one:
+ %x = phi i64 [%i, %entry], [%y, %two]
+ %c = call i1 @test11a()
+ br i1 %c, label %two, label %end
+
+two:
+ %y = phi i64 [%i, %entry], [%x, %one]
+ %d = call i1 @test11a()
+ br i1 %d, label %one, label %end
+
+end:
+ %f = phi i64 [ %x, %one], [%y, %two]
+ ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
+ ; even though %f must equal %i at this point
+ %g = inttoptr i64 %f to i32*
+ store i32 10, i32* %g
+ %z = call i1 @test11a()
+ ret i1 %z
+; CHECK: @test11
+; CHECK-NOT: phi i32
+; CHECK: ret i1 %z
+}
+
+
+define i64 @test12(i1 %cond, i8* %Ptr, i64 %Val) {
+entry:
+ %tmp41 = ptrtoint i8* %Ptr to i64
+ %tmp42 = zext i64 %tmp41 to i128
+ br i1 %cond, label %end, label %two
+
+two:
+ %tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
+ %tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
+ %ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
+ br label %end
+
+end:
+ %tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
+ %tmp32 = trunc i128 %tmp869.0 to i64 ; <i64> [#uses=1]
+ %tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
+ %tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
+
+ %tmp2 = add i64 %tmp32, %tmp30
+ ret i64 %tmp2
+; CHECK: @test12
+; CHECK-NOT: zext
+; CHECK: end:
+; CHECK-NEXT: phi i64 [ 0, %entry ], [ %Val, %two ]
+; CHECK-NOT: phi
+; CHECK: ret i64
+}
+
+declare void @test13f(double, i32)
+
+define void @test13(i1 %cond, i32 %V1, double %Vald) {
+entry:
+ %tmp42 = zext i32 %V1 to i128
+ br i1 %cond, label %end, label %two
+
+two:
+ %Val = bitcast double %Vald to i64
+ %tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
+ %tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
+ %ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
+ br label %end
+
+end:
+ %tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
+ %tmp32 = trunc i128 %tmp869.0 to i32
+ %tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
+ %tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
+ %tmp31 = bitcast i64 %tmp30 to double
+
+ call void @test13f(double %tmp31, i32 %tmp32)
+ ret void
+; CHECK: @test13
+; CHECK-NOT: zext
+; CHECK: end:
+; CHECK-NEXT: phi double [ 0.000000e+00, %entry ], [ %Vald, %two ]
+; CHECK-NEXT: call void @test13f(double {{[^,]*}}, i32 %V1)
+; CHECK: ret void
+}
+
+define i640 @test14a(i320 %A, i320 %B, i1 %b1) {
+BB0:
+ %a = zext i320 %A to i640
+ %b = zext i320 %B to i640
+ br label %Loop
+
+Loop:
+ %C = phi i640 [ %a, %BB0 ], [ %b, %Loop ]
+ br i1 %b1, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ ret i640 %C
+; CHECK: @test14a
+; CHECK: Loop:
+; CHECK-NEXT: phi i320
+}
+
+define i160 @test14b(i320 %A, i320 %B, i1 %b1) {
+BB0:
+ %a = trunc i320 %A to i160
+ %b = trunc i320 %B to i160
+ br label %Loop
+
+Loop:
+ %C = phi i160 [ %a, %BB0 ], [ %b, %Loop ]
+ br i1 %b1, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ ret i160 %C
+; CHECK: @test14b
+; CHECK: Loop:
+; CHECK-NEXT: phi i160
+}
+
+declare i64 @test15a(i64)
+
+define i64 @test15b(i64 %A, i1 %b) {
+; CHECK: @test15b
+entry:
+ %i0 = zext i64 %A to i128
+ %i1 = shl i128 %i0, 64
+ %i = or i128 %i1, %i0
+ br i1 %b, label %one, label %two
+; CHECK: entry:
+; CHECK-NEXT: br i1 %b
+
+one:
+ %x = phi i128 [%i, %entry], [%y, %two]
+ %x1 = lshr i128 %x, 64
+ %x2 = trunc i128 %x1 to i64
+ %c = call i64 @test15a(i64 %x2)
+ %c1 = zext i64 %c to i128
+ br label %two
+
+; CHECK: one:
+; CHECK-NEXT: phi i64
+; CHECK-NEXT: %c = call i64 @test15a
+
+two:
+ %y = phi i128 [%i, %entry], [%c1, %one]
+ %y1 = lshr i128 %y, 64
+ %y2 = trunc i128 %y1 to i64
+ %d = call i64 @test15a(i64 %y2)
+ %d1 = trunc i64 %d to i1
+ br i1 %d1, label %one, label %end
+
+; CHECK: two:
+; CHECK-NEXT: phi i64
+; CHECK-NEXT: phi i64
+; CHECK-NEXT: %d = call i64 @test15a
+
+end:
+ %g = trunc i128 %y to i64
+ ret i64 %g
+; CHECK: end:
+; CHECK-NEXT: ret i64
+}
+
+; PR6512 - Shouldn't merge loads from different addr spaces.
+define i32 @test16(i32 addrspace(1)* %pointer1, i32 %flag, i32* %pointer2)
+nounwind {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %pointer1.addr = alloca i32 addrspace(1)*, align 4 ; <i32 addrspace(1)**>
+ %flag.addr = alloca i32, align 4 ; <i32*> [#uses=2]
+ %pointer2.addr = alloca i32*, align 4 ; <i32**> [#uses=2]
+ %res = alloca i32, align 4 ; <i32*> [#uses=4]
+ store i32 addrspace(1)* %pointer1, i32 addrspace(1)** %pointer1.addr
+ store i32 %flag, i32* %flag.addr
+ store i32* %pointer2, i32** %pointer2.addr
+ store i32 10, i32* %res
+ %tmp = load i32* %flag.addr ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %tmp, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %if.then, label %if.else
+
+return: ; preds = %if.end
+ %tmp7 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %tmp7
+
+if.end: ; preds = %if.else, %if.then
+ %tmp6 = load i32* %res ; <i32> [#uses=1]
+ store i32 %tmp6, i32* %retval
+ br label %return
+
+if.then: ; preds = %entry
+ %tmp1 = load i32 addrspace(1)** %pointer1.addr ; <i32 addrspace(1)*>
+ %arrayidx = getelementptr i32 addrspace(1)* %tmp1, i32 0 ; <i32 addrspace(1)*> [#uses=1]
+ %tmp2 = load i32 addrspace(1)* %arrayidx ; <i32> [#uses=1]
+ store i32 %tmp2, i32* %res
+ br label %if.end
+
+if.else: ; preds = %entry
+ %tmp3 = load i32** %pointer2.addr ; <i32*> [#uses=1]
+ %arrayidx4 = getelementptr i32* %tmp3, i32 0 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %arrayidx4 ; <i32> [#uses=1]
+ store i32 %tmp5, i32* %res
+ br label %if.end
+}
+
+; PR4413
+declare i32 @ext()
+; CHECK: @test17
+define i32 @test17(i1 %a) {
+entry:
+ br i1 %a, label %bb1, label %bb2
+
+bb1: ; preds = %entry
+ %0 = tail call i32 @ext() ; <i32> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb1, %entry
+ %cond = phi i1 [ true, %bb1 ], [ false, %entry ] ; <i1> [#uses=1]
+; CHECK-NOT: %val = phi i32 [ %0, %bb1 ], [ 0, %entry ]
+ %val = phi i32 [ %0, %bb1 ], [ 0, %entry ] ; <i32> [#uses=1]
+ %res = select i1 %cond, i32 %val, i32 0 ; <i32> [#uses=1]
+; CHECK: ret i32 %cond
+ ret i32 %res
+}
+
+define i1 @test18(i1 %cond) {
+ %zero = alloca i32
+ %one = alloca i32
+ br i1 %cond, label %true, label %false
+true:
+ br label %ret
+false:
+ br label %ret
+ret:
+ %ptr = phi i32* [ %zero, %true ] , [ %one, %false ]
+ %isnull = icmp eq i32* %ptr, null
+ ret i1 %isnull
+; CHECK: @test18
+; CHECK: ret i1 false
+}
+
+define i1 @test19(i1 %cond, double %x) {
+ br i1 %cond, label %true, label %false
+true:
+ br label %ret
+false:
+ br label %ret
+ret:
+ %p = phi double [ %x, %true ], [ 0x7FF0000000000000, %false ]; RHS = +infty
+ %cmp = fcmp ule double %x, %p
+ ret i1 %cmp
+; CHECK: @test19
+; CHECK: ret i1 true
+}
+
+define i1 @test20(i1 %cond) {
+ %a = alloca i32
+ %b = alloca i32
+ %c = alloca i32
+ br i1 %cond, label %true, label %false
+true:
+ br label %ret
+false:
+ br label %ret
+ret:
+ %p = phi i32* [ %a, %true ], [ %b, %false ]
+ %r = icmp eq i32* %p, %c
+ ret i1 %r
+; CHECK: @test20
+; CHECK: ret i1 false
+}
+
+define i1 @test21(i1 %c1, i1 %c2) {
+ %a = alloca i32
+ %b = alloca i32
+ %c = alloca i32
+ br i1 %c1, label %true, label %false
+true:
+ br label %loop
+false:
+ br label %loop
+loop:
+ %p = phi i32* [ %a, %true ], [ %b, %false ], [ %p, %loop ]
+ %r = icmp eq i32* %p, %c
+ br i1 %c2, label %ret, label %loop
+ret:
+ ret i1 %r
+; CHECK: @test21
+; CHECK: ret i1 false
+}
+
+define void @test22() {
+; CHECK: @test22
+entry:
+ br label %loop
+loop:
+ %phi = phi i32 [ 0, %entry ], [ %y, %loop ]
+ %y = add i32 %phi, 1
+ %o = or i32 %y, %phi
+ %e = icmp eq i32 %o, %y
+ br i1 %e, label %loop, label %ret
+; CHECK: br i1 %e
+ret:
+ ret void
+}
+
+define i32 @test23(i32 %A, i1 %b, i32 * %P) {
+BB0:
+ br label %Loop
+
+Loop: ; preds = %Loop, %BB0
+ ; PHI has same value always.
+ %B = phi i32 [ %A, %BB0 ], [ 42, %Loop ]
+ %D = add i32 %B, 19
+ store i32 %D, i32* %P
+ br i1 %b, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ %E = add i32 %B, 19
+ ret i32 %E
+; CHECK: @test23
+; CHECK: %phitmp = add i32 %A, 19
+; CHECK: Loop:
+; CHECK-NEXT: %B = phi i32 [ %phitmp, %BB0 ], [ 61, %Loop ]
+; CHECK: Exit:
+; CHECK-NEXT: ret i32 %B
+}
+
+define i32 @test24(i32 %A, i1 %cond) {
+BB0:
+ %X = add nuw nsw i32 %A, 1
+ br i1 %cond, label %BB1, label %BB2
+
+BB1:
+ %Y = add nuw i32 %A, 1
+ br label %BB2
+
+BB2:
+ %C = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
+ ret i32 %C
+; CHECK: @test24
+; CHECK-NOT: phi
+; CHECK: BB2:
+; CHECK-NEXT: %C = add nuw i32 %A, 1
+; CHECK-NEXT: ret i32 %C
+}
+
+; Same as test11, but used to be missed due to a bug.
+declare i1 @test25a()
+
+define i1 @test25() {
+entry:
+ %a = alloca i32
+ %i = ptrtoint i32* %a to i64
+ %b = call i1 @test25a()
+ br i1 %b, label %one, label %two
+
+one:
+ %x = phi i64 [%y, %two], [%i, %entry]
+ %c = call i1 @test25a()
+ br i1 %c, label %two, label %end
+
+two:
+ %y = phi i64 [%x, %one], [%i, %entry]
+ %d = call i1 @test25a()
+ br i1 %d, label %one, label %end
+
+end:
+ %f = phi i64 [ %x, %one], [%y, %two]
+ ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
+ ; even though %f must equal %i at this point
+ %g = inttoptr i64 %f to i32*
+ store i32 10, i32* %g
+ %z = call i1 @test25a()
+ ret i1 %z
+; CHECK: @test25
+; CHECK-NOT: phi i32
+; CHECK: ret i1 %z
+}
+
+declare i1 @test26a()
+
+define i1 @test26(i32 %n) {
+entry:
+ %a = alloca i32
+ %i = ptrtoint i32* %a to i64
+ %b = call i1 @test26a()
+ br label %one
+
+one:
+ %x = phi i64 [%y, %two], [%w, %three], [%i, %entry]
+ %c = call i1 @test26a()
+ switch i32 %n, label %end [
+ i32 2, label %two
+ i32 3, label %three
+ ]
+
+two:
+ %y = phi i64 [%x, %one], [%w, %three]
+ %d = call i1 @test26a()
+ switch i32 %n, label %end [
+ i32 10, label %one
+ i32 30, label %three
+ ]
+
+three:
+ %w = phi i64 [%y, %two], [%x, %one]
+ %e = call i1 @test26a()
+ br i1 %e, label %one, label %two
+
+end:
+ %f = phi i64 [ %x, %one], [%y, %two]
+ ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
+ ; even though %f must equal %i at this point
+ %g = inttoptr i64 %f to i32*
+ store i32 10, i32* %g
+ %z = call i1 @test26a()
+ ret i1 %z
+; CHECK: @test26
+; CHECK-NOT: phi i32
+; CHECK: ret i1 %z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/pr2645-0.ll b/src/LLVM/test/Transforms/InstCombine/pr2645-0.ll
new file mode 100644
index 0000000..9bcaa43
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/pr2645-0.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -instcombine -S | grep {insertelement <4 x float> undef}
+
+; Instcombine should be able to prove that none of the
+; insertelement's first operand's elements are needed.
+
+define internal void @""(i8*) {
+; <label>:1
+ bitcast i8* %0 to i32* ; <i32*>:2 [#uses=1]
+ load i32* %2, align 1 ; <i32>:3 [#uses=1]
+ getelementptr i8* %0, i32 4 ; <i8*>:4 [#uses=1]
+ bitcast i8* %4 to i32* ; <i32*>:5 [#uses=1]
+ load i32* %5, align 1 ; <i32>:6 [#uses=1]
+ br label %7
+
+; <label>:7 ; preds = %9, %1
+ %.01 = phi <4 x float> [ undef, %1 ], [ %12, %9 ] ; <<4 x float>> [#uses=1]
+ %.0 = phi i32 [ %3, %1 ], [ %15, %9 ] ; <i32> [#uses=3]
+ icmp slt i32 %.0, %6 ; <i1>:8 [#uses=1]
+ br i1 %8, label %9, label %16
+
+; <label>:9 ; preds = %7
+ sitofp i32 %.0 to float ; <float>:10 [#uses=1]
+ insertelement <4 x float> %.01, float %10, i32 0 ; <<4 x float>>:11 [#uses=1]
+ shufflevector <4 x float> %11, <4 x float> undef, <4 x i32> zeroinitializer ; <<4 x float>>:12 [#uses=2]
+ getelementptr i8* %0, i32 48 ; <i8*>:13 [#uses=1]
+ bitcast i8* %13 to <4 x float>* ; <<4 x float>*>:14 [#uses=1]
+ store <4 x float> %12, <4 x float>* %14, align 16
+ add i32 %.0, 2 ; <i32>:15 [#uses=1]
+ br label %7
+
+; <label>:16 ; preds = %7
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/pr2645-1.ll b/src/LLVM/test/Transforms/InstCombine/pr2645-1.ll
new file mode 100644
index 0000000..d320daf
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/pr2645-1.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -instcombine -S | grep shufflevector
+; PR2645
+
+; instcombine shouldn't delete the shufflevector.
+
+define internal void @""(i8*, i32, i8*) {
+; <label>:3
+ br label %4
+
+; <label>:4 ; preds = %6, %3
+ %.0 = phi i32 [ 0, %3 ], [ %19, %6 ] ; <i32> [#uses=4]
+ %5 = icmp slt i32 %.0, %1 ; <i1> [#uses=1]
+ br i1 %5, label %6, label %20
+
+; <label>:6 ; preds = %4
+ %7 = getelementptr i8* %2, i32 %.0 ; <i8*> [#uses=1]
+ %8 = bitcast i8* %7 to <4 x i16>* ; <<4 x i16>*> [#uses=1]
+ %9 = load <4 x i16>* %8, align 1 ; <<4 x i16>> [#uses=1]
+ %10 = bitcast <4 x i16> %9 to <1 x i64> ; <<1 x i64>> [#uses=1]
+ %11 = call <2 x i64> @foo(<1 x i64> %10)
+; <<2 x i64>> [#uses=1]
+ %12 = bitcast <2 x i64> %11 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %13 = bitcast <4 x i32> %12 to <8 x i16> ; <<8 x i16>> [#uses=2]
+ %14 = shufflevector <8 x i16> %13, <8 x i16> %13, <8 x i32> < i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3 > ; <<8 x i16>> [#uses=1]
+ %15 = bitcast <8 x i16> %14 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %16 = sitofp <4 x i32> %15 to <4 x float> ; <<4 x float>> [#uses=1]
+ %17 = getelementptr i8* %0, i32 %.0 ; <i8*> [#uses=1]
+ %18 = bitcast i8* %17 to <4 x float>* ; <<4 x float>*> [#uses=1]
+ store <4 x float> %16, <4 x float>* %18, align 1
+ %19 = add i32 %.0, 1 ; <i32> [#uses=1]
+ br label %4
+
+; <label>:20 ; preds = %4
+ call void @llvm.x86.mmx.emms( )
+ ret void
+}
+
+declare <2 x i64> @foo(<1 x i64>)
+declare void @llvm.x86.mmx.emms( )
diff --git a/src/LLVM/test/Transforms/InstCombine/pr2996.ll b/src/LLVM/test/Transforms/InstCombine/pr2996.ll
new file mode 100644
index 0000000..ff3245d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/pr2996.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine
+; PR2996
+
+define void @func_53(i16 signext %p_56) nounwind {
+entry:
+ %0 = icmp sgt i16 %p_56, -1 ; <i1> [#uses=1]
+ %iftmp.0.0 = select i1 %0, i32 -1, i32 0 ; <i32> [#uses=1]
+ %1 = call i32 (...)* @func_4(i32 %iftmp.0.0) nounwind ; <i32> [#uses=0]
+ ret void
+}
+
+declare i32 @func_4(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/pr8547.ll b/src/LLVM/test/Transforms/InstCombine/pr8547.ll
new file mode 100644
index 0000000..485f4d9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/pr8547.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; Converting the 2 shifts to SHL 6 without the AND is wrong. PR 8547.
+
+@g_2 = global i32 0, align 4
+@.str = constant [10 x i8] c"g_2 = %d\0A\00"
+
+declare i32 @printf(i8*, ...)
+
+define i32 @main() nounwind {
+codeRepl:
+ br label %for.cond
+
+for.cond: ; preds = %for.cond, %codeRepl
+ %storemerge = phi i32 [ 0, %codeRepl ], [ 5, %for.cond ]
+ store i32 %storemerge, i32* @g_2, align 4
+ %shl = shl i32 %storemerge, 30
+ %conv2 = lshr i32 %shl, 24
+; CHECK: %0 = shl nuw nsw i32 %storemerge, 6
+; CHECK: %conv2 = and i32 %0, 64
+ %tobool = icmp eq i32 %conv2, 0
+ br i1 %tobool, label %for.cond, label %codeRepl2
+
+codeRepl2: ; preds = %for.cond
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.str, i64 0, i64 0), i32 %conv2) nounwind
+ ret i32 0
+}
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/InstCombine/preserve-sminmax.ll b/src/LLVM/test/Transforms/InstCombine/preserve-sminmax.ll
new file mode 100644
index 0000000..00232cc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/preserve-sminmax.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Instcombine normally would fold the sdiv into the comparison,
+; making "icmp slt i32 %h, 2", but in this case the sdiv has
+; another use, so it wouldn't a big win, and it would also
+; obfuscate an otherise obvious smax pattern to the point where
+; other analyses wouldn't recognize it.
+
+define i32 @foo(i32 %h) {
+ %sd = sdiv i32 %h, 2
+ %t = icmp slt i32 %sd, 1
+ %r = select i1 %t, i32 %sd, i32 1
+ ret i32 %r
+}
+
+; CHECK: %sd = sdiv i32 %h, 2
+; CHECK: %t = icmp slt i32 %sd, 1
+; CHECK: %r = select i1 %t, i32 %sd, i32 1
+; CHECK: ret i32 %r
+
+define i32 @bar(i32 %h) {
+ %sd = sdiv i32 %h, 2
+ %t = icmp sgt i32 %sd, 1
+ %r = select i1 %t, i32 %sd, i32 1
+ ret i32 %r
+}
+
+; CHECK: %sd = sdiv i32 %h, 2
+; CHECK: %t = icmp sgt i32 %sd, 1
+; CHECK: %r = select i1 %t, i32 %sd, i32 1
+; CHECK: ret i32 %r
+
diff --git a/src/LLVM/test/Transforms/InstCombine/ptr-int-cast.ll b/src/LLVM/test/Transforms/InstCombine/ptr-int-cast.ll
new file mode 100644
index 0000000..9524d44
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/ptr-int-cast.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+define i1 @test1(i32 *%x) nounwind {
+entry:
+; CHECK: test1
+; CHECK: ptrtoint i32* %x to i64
+ %0 = ptrtoint i32* %x to i1
+ ret i1 %0
+}
+
+define i32* @test2(i128 %x) nounwind {
+entry:
+; CHECK: test2
+; CHECK: inttoptr i64 %0 to i32*
+ %0 = inttoptr i128 %x to i32*
+ ret i32* %0
+}
+
+; PR3574
+; CHECK: f0
+; CHECK: %1 = zext i32 %a0 to i64
+; CHECK: ret i64 %1
+define i64 @f0(i32 %a0) nounwind {
+ %t0 = inttoptr i32 %a0 to i8*
+ %t1 = ptrtoint i8* %t0 to i64
+ ret i64 %t1
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/rem.ll b/src/LLVM/test/Transforms/InstCombine/rem.ll
new file mode 100644
index 0000000..7a1b3bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/rem.ll
@@ -0,0 +1,88 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | not grep rem
+; END.
+
+define i32 @test1(i32 %A) {
+ %B = srem i32 %A, 1 ; ISA constant 0
+ ret i32 %B
+}
+
+define i32 @test2(i32 %A) { ; 0 % X = 0, we don't need to preserve traps
+ %B = srem i32 0, %A
+ ret i32 %B
+}
+
+define i32 @test3(i32 %A) {
+ %B = urem i32 %A, 8
+ ret i32 %B
+}
+
+define i1 @test3a(i32 %A) {
+ %B = srem i32 %A, -8
+ %C = icmp ne i32 %B, 0
+ ret i1 %C
+}
+
+define i32 @test4(i32 %X, i1 %C) {
+ %V = select i1 %C, i32 1, i32 8
+ %R = urem i32 %X, %V
+ ret i32 %R
+}
+
+define i32 @test5(i32 %X, i8 %B) {
+ %shift.upgrd.1 = zext i8 %B to i32
+ %Amt = shl i32 32, %shift.upgrd.1
+ %V = urem i32 %X, %Amt
+ ret i32 %V
+}
+
+define i32 @test6(i32 %A) {
+ %B = srem i32 %A, 0 ;; undef
+ ret i32 %B
+}
+
+define i32 @test7(i32 %A) {
+ %B = mul i32 %A, 8
+ %C = srem i32 %B, 4
+ ret i32 %C
+}
+
+define i32 @test8(i32 %A) {
+ %B = shl i32 %A, 4
+ %C = srem i32 %B, 8
+ ret i32 %C
+}
+
+define i32 @test9(i32 %A) {
+ %B = mul i32 %A, 64
+ %C = urem i32 %B, 32
+ ret i32 %C
+}
+
+define i32 @test10(i8 %c) {
+ %tmp.1 = zext i8 %c to i32
+ %tmp.2 = mul i32 %tmp.1, 4
+ %tmp.3 = sext i32 %tmp.2 to i64
+ %tmp.5 = urem i64 %tmp.3, 4
+ %tmp.6 = trunc i64 %tmp.5 to i32
+ ret i32 %tmp.6
+}
+
+define i32 @test11(i32 %i) {
+ %tmp.1 = and i32 %i, -2
+ %tmp.3 = mul i32 %tmp.1, 2
+ %tmp.5 = urem i32 %tmp.3, 4
+ ret i32 %tmp.5
+}
+
+define i32 @test12(i32 %i) {
+ %tmp.1 = and i32 %i, -4
+ %tmp.5 = srem i32 %tmp.1, 2
+ ret i32 %tmp.5
+}
+
+define i32 @test13(i32 %i) {
+ %x = srem i32 %i, %i
+ ret i32 %x
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sdiv-1.ll b/src/LLVM/test/Transforms/InstCombine/sdiv-1.ll
new file mode 100644
index 0000000..c46b5ea
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sdiv-1.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -inline -S | not grep '-715827882'
+; PR3142
+
+define i32 @a(i32 %X) nounwind readnone {
+entry:
+ %0 = sub i32 0, %X
+ %1 = sdiv i32 %0, -3
+ ret i32 %1
+}
+
+define i32 @b(i32 %X) nounwind readnone {
+entry:
+ %0 = call i32 @a(i32 -2147483648)
+ ret i32 %0
+}
+
+define i32 @c(i32 %X) nounwind readnone {
+entry:
+ %0 = sub i32 0, -2147483648
+ %1 = sdiv i32 %0, -3
+ ret i32 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sdiv-2.ll b/src/LLVM/test/Transforms/InstCombine/sdiv-2.ll
new file mode 100644
index 0000000..0e4c008
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sdiv-2.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -instcombine -disable-output
+; PR3144
+
+define fastcc i32 @func(i32 %length) nounwind {
+entry:
+ %0 = icmp ne i32 %length, -1 ; <i1> [#uses=1]
+ %iftmp.13.0 = select i1 %0, i128 0, i128 200000000 ; <i128> [#uses=2]
+ %1 = sdiv i128 %iftmp.13.0, 10 ; <i128> [#uses=1]
+ br label %bb5
+
+bb5: ; preds = %bb8, %entry
+ %v.0 = phi i128 [ 0, %entry ], [ %6, %bb8 ] ; <i128> [#uses=2]
+ %2 = icmp sgt i128 %v.0, %1 ; <i1> [#uses=1]
+ br i1 %2, label %overflow, label %bb7
+
+bb7: ; preds = %bb5
+ %3 = mul i128 %v.0, 10 ; <i128> [#uses=2]
+ %4 = sub i128 %iftmp.13.0, 0 ; <i128> [#uses=1]
+ %5 = icmp slt i128 %4, %3 ; <i1> [#uses=1]
+ br i1 %5, label %overflow, label %bb8
+
+bb8: ; preds = %bb7
+ %6 = add i128 0, %3 ; <i128> [#uses=1]
+ br label %bb5
+
+overflow: ; preds = %bb7, %bb5
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sdiv-shift.ll b/src/LLVM/test/Transforms/InstCombine/sdiv-shift.ll
new file mode 100644
index 0000000..f4d2b36
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sdiv-shift.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep div
+
+define i32 @a(i16 zeroext %x, i32 %y) nounwind {
+entry:
+ %conv = zext i16 %x to i32
+ %s = shl i32 2, %y
+ %d = sdiv i32 %conv, %s
+ ret i32 %d
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/select-2.ll b/src/LLVM/test/Transforms/InstCombine/select-2.ll
new file mode 100644
index 0000000..a76addc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/select-2.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -S | grep select | count 2
+
+; Make sure instcombine don't fold select into operands. We don't want to emit
+; select of two integers unless it's selecting 0 / 1.
+
+define i32 @t1(i32 %c, i32 %x) nounwind {
+ %t1 = icmp eq i32 %c, 0
+ %t2 = lshr i32 %x, 18
+ %t3 = select i1 %t1, i32 %t2, i32 %x
+ ret i32 %t3
+}
+
+define i32 @t2(i32 %c, i32 %x) nounwind {
+ %t1 = icmp eq i32 %c, 0
+ %t2 = and i32 %x, 18
+ %t3 = select i1 %t1, i32 %t2, i32 %x
+ ret i32 %t3
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/select-crash.ll b/src/LLVM/test/Transforms/InstCombine/select-crash.ll
new file mode 100644
index 0000000..18af152
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/select-crash.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; Formerly crashed, PR8490.
+
+define fastcc double @gimp_operation_color_balance_map(float %value, double %highlights) nounwind readnone inlinehint {
+entry:
+; CHECK: gimp_operation_color_balance_map
+; CHECK: fsub double -0.000000
+ %conv = fpext float %value to double
+ %div = fdiv double %conv, 1.600000e+01
+ %add = fadd double %div, 1.000000e+00
+ %div1 = fdiv double 1.000000e+00, %add
+ %sub = fsub double 1.075000e+00, %div1
+ %sub24 = fsub double 1.000000e+00, %sub
+ %add26 = fadd double %sub, 1.000000e+00
+ %cmp86 = fcmp ogt double %highlights, 0.000000e+00
+ %cond90 = select i1 %cmp86, double %sub24, double %add26
+ %mul91 = fmul double %highlights, %cond90
+ %add94 = fadd double undef, %mul91
+ ret double %add94
+}
+
+; PR10180: same crash, but with vectors
+define <4 x float> @foo(i1 %b, <4 x float> %x, <4 x float> %y, <4 x float> %z) {
+; CHECK: @foo
+; CHECK: fsub <4 x float>
+; CHECK: select
+; CHECK: fadd <4 x float>
+ %a = fadd <4 x float> %x, %y
+ %sub = fsub <4 x float> %x, %z
+ %sel = select i1 %b, <4 x float> %a, <4 x float> %sub
+ ret <4 x float> %sel
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/select-load-call.ll b/src/LLVM/test/Transforms/InstCombine/select-load-call.ll
new file mode 100644
index 0000000..bef0cf8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/select-load-call.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | grep {ret i32 1}
+
+declare void @test2()
+
+define i32 @test(i1 %cond, i32 *%P) {
+ %A = alloca i32
+ store i32 1, i32* %P
+ store i32 1, i32* %A
+
+ call void @test2() readonly
+
+ %P2 = select i1 %cond, i32 *%P, i32* %A
+ %V = load i32* %P2
+ ret i32 %V
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/select.ll b/src/LLVM/test/Transforms/InstCombine/select.ll
new file mode 100644
index 0000000..11f9b5b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/select.ll
@@ -0,0 +1,811 @@
+; This test makes sure that these instructions are properly eliminated.
+; PR1822
+
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @test1(i32 %A, i32 %B) {
+ %C = select i1 false, i32 %A, i32 %B
+ ret i32 %C
+; CHECK: @test1
+; CHECK: ret i32 %B
+}
+
+define i32 @test2(i32 %A, i32 %B) {
+ %C = select i1 true, i32 %A, i32 %B
+ ret i32 %C
+; CHECK: @test2
+; CHECK: ret i32 %A
+}
+
+
+define i32 @test3(i1 %C, i32 %I) {
+ ; V = I
+ %V = select i1 %C, i32 %I, i32 %I
+ ret i32 %V
+; CHECK: @test3
+; CHECK: ret i32 %I
+}
+
+define i1 @test4(i1 %C) {
+ ; V = C
+ %V = select i1 %C, i1 true, i1 false
+ ret i1 %V
+; CHECK: @test4
+; CHECK: ret i1 %C
+}
+
+define i1 @test5(i1 %C) {
+ ; V = !C
+ %V = select i1 %C, i1 false, i1 true
+ ret i1 %V
+; CHECK: @test5
+; CHECK: xor i1 %C, true
+; CHECK: ret i1
+}
+
+define i32 @test6(i1 %C) {
+ ; V = cast C to int
+ %V = select i1 %C, i32 1, i32 0
+ ret i32 %V
+; CHECK: @test6
+; CHECK: %V = zext i1 %C to i32
+; CHECK: ret i32 %V
+}
+
+define i1 @test7(i1 %C, i1 %X) {
+ ; R = or C, X
+ %R = select i1 %C, i1 true, i1 %X
+ ret i1 %R
+; CHECK: @test7
+; CHECK: %R = or i1 %C, %X
+; CHECK: ret i1 %R
+}
+
+define i1 @test8(i1 %C, i1 %X) {
+ ; R = and C, X
+ %R = select i1 %C, i1 %X, i1 false
+ ret i1 %R
+; CHECK: @test8
+; CHECK: %R = and i1 %C, %X
+; CHECK: ret i1 %R
+}
+
+define i1 @test9(i1 %C, i1 %X) {
+ ; R = and !C, X
+ %R = select i1 %C, i1 false, i1 %X
+ ret i1 %R
+; CHECK: @test9
+; CHECK: xor i1 %C, true
+; CHECK: %R = and i1
+; CHECK: ret i1 %R
+}
+
+define i1 @test10(i1 %C, i1 %X) {
+ ; R = or !C, X
+ %R = select i1 %C, i1 %X, i1 true
+ ret i1 %R
+; CHECK: @test10
+; CHECK: xor i1 %C, true
+; CHECK: %R = or i1
+; CHECK: ret i1 %R
+}
+
+define i32 @test11(i32 %a) {
+ %C = icmp eq i32 %a, 0
+ %R = select i1 %C, i32 0, i32 1
+ ret i32 %R
+; CHECK: @test11
+; CHECK: icmp ne i32 %a, 0
+; CHECK: %R = zext i1
+; CHECK: ret i32 %R
+}
+
+define i32 @test12(i1 %cond, i32 %a) {
+ %b = or i32 %a, 1
+ %c = select i1 %cond, i32 %b, i32 %a
+ ret i32 %c
+; CHECK: @test12
+; CHECK: %b = zext i1 %cond to i32
+; CHECK: %c = or i32 %b, %a
+; CHECK: ret i32 %c
+}
+
+define i32 @test12a(i1 %cond, i32 %a) {
+ %b = ashr i32 %a, 1
+ %c = select i1 %cond, i32 %b, i32 %a
+ ret i32 %c
+; CHECK: @test12a
+; CHECK: %b = zext i1 %cond to i32
+; CHECK: %c = ashr i32 %a, %b
+; CHECK: ret i32 %c
+}
+
+define i32 @test12b(i1 %cond, i32 %a) {
+ %b = ashr i32 %a, 1
+ %c = select i1 %cond, i32 %a, i32 %b
+ ret i32 %c
+; CHECK: @test12b
+; CHECK: zext i1 %cond to i32
+; CHECK: %b = xor i32
+; CHECK: %c = ashr i32 %a, %b
+; CHECK: ret i32 %c
+}
+
+define i32 @test13(i32 %a, i32 %b) {
+ %C = icmp eq i32 %a, %b
+ %V = select i1 %C, i32 %a, i32 %b
+ ret i32 %V
+; CHECK: @test13
+; CHECK: ret i32 %b
+}
+
+define i32 @test13a(i32 %a, i32 %b) {
+ %C = icmp ne i32 %a, %b
+ %V = select i1 %C, i32 %a, i32 %b
+ ret i32 %V
+; CHECK: @test13a
+; CHECK: ret i32 %a
+}
+
+define i32 @test13b(i32 %a, i32 %b) {
+ %C = icmp eq i32 %a, %b
+ %V = select i1 %C, i32 %b, i32 %a
+ ret i32 %V
+; CHECK: @test13b
+; CHECK: ret i32 %a
+}
+
+define i1 @test14a(i1 %C, i32 %X) {
+ %V = select i1 %C, i32 %X, i32 0
+ ; (X < 1) | !C
+ %R = icmp slt i32 %V, 1
+ ret i1 %R
+; CHECK: @test14a
+; CHECK: icmp slt i32 %X, 1
+; CHECK: xor i1 %C, true
+; CHECK: or i1
+; CHECK: ret i1 %R
+}
+
+define i1 @test14b(i1 %C, i32 %X) {
+ %V = select i1 %C, i32 0, i32 %X
+ ; (X < 1) | C
+ %R = icmp slt i32 %V, 1
+ ret i1 %R
+; CHECK: @test14b
+; CHECK: icmp slt i32 %X, 1
+; CHECK: or i1
+; CHECK: ret i1 %R
+}
+
+;; Code sequence for (X & 16) ? 16 : 0
+define i32 @test15a(i32 %X) {
+ %t1 = and i32 %X, 16
+ %t2 = icmp eq i32 %t1, 0
+ %t3 = select i1 %t2, i32 0, i32 16
+ ret i32 %t3
+; CHECK: @test15a
+; CHECK: %t1 = and i32 %X, 16
+; CHECK: ret i32 %t1
+}
+
+;; Code sequence for (X & 32) ? 0 : 24
+define i32 @test15b(i32 %X) {
+ %t1 = and i32 %X, 32
+ %t2 = icmp eq i32 %t1, 0
+ %t3 = select i1 %t2, i32 32, i32 0
+ ret i32 %t3
+; CHECK: @test15b
+; CHECK: %t1 = and i32 %X, 32
+; CHECK: xor i32 %t1, 32
+; CHECK: ret i32
+}
+
+;; Alternate code sequence for (X & 16) ? 16 : 0
+define i32 @test15c(i32 %X) {
+ %t1 = and i32 %X, 16
+ %t2 = icmp eq i32 %t1, 16
+ %t3 = select i1 %t2, i32 16, i32 0
+ ret i32 %t3
+; CHECK: @test15c
+; CHECK: %t1 = and i32 %X, 16
+; CHECK: ret i32 %t1
+}
+
+;; Alternate code sequence for (X & 16) ? 16 : 0
+define i32 @test15d(i32 %X) {
+ %t1 = and i32 %X, 16
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 16, i32 0
+ ret i32 %t3
+; CHECK: @test15d
+; CHECK: %t1 = and i32 %X, 16
+; CHECK: ret i32 %t1
+}
+
+;; (a & 128) ? 256 : 0
+define i32 @test15e(i32 %X) {
+ %t1 = and i32 %X, 128
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 256, i32 0
+ ret i32 %t3
+; CHECK: @test15e
+; CHECK: %t1 = shl i32 %X, 1
+; CHECK: and i32 %t1, 256
+; CHECK: ret i32
+}
+
+;; (a & 128) ? 0 : 256
+define i32 @test15f(i32 %X) {
+ %t1 = and i32 %X, 128
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 0, i32 256
+ ret i32 %t3
+; CHECK: @test15f
+; CHECK: %t1 = shl i32 %X, 1
+; CHECK: and i32 %t1, 256
+; CHECK: xor i32 %{{.*}}, 256
+; CHECK: ret i32
+}
+
+;; (a & 8) ? -1 : -9
+define i32 @test15g(i32 %X) {
+ %t1 = and i32 %X, 8
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 -1, i32 -9
+ ret i32 %t3
+; CHECK: @test15g
+; CHECK-NEXT: %1 = or i32 %X, -9
+; CHECK-NEXT: ret i32 %1
+}
+
+;; (a & 8) ? -9 : -1
+define i32 @test15h(i32 %X) {
+ %t1 = and i32 %X, 8
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 -9, i32 -1
+ ret i32 %t3
+; CHECK: @test15h
+; CHECK-NEXT: %1 = or i32 %X, -9
+; CHECK-NEXT: %2 = xor i32 %1, 8
+; CHECK-NEXT: ret i32 %2
+}
+
+;; (a & 2) ? 577 : 1089
+define i32 @test15i(i32 %X) {
+ %t1 = and i32 %X, 2
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 577, i32 1089
+ ret i32 %t3
+; CHECK: @test15i
+; CHECK-NEXT: %t1 = shl i32 %X, 8
+; CHECK-NEXT: %1 = and i32 %t1, 512
+; CHECK-NEXT: %2 = xor i32 %1, 512
+; CHECK-NEXT: %3 = add i32 %2, 577
+; CHECK-NEXT: ret i32 %3
+}
+
+;; (a & 2) ? 1089 : 577
+define i32 @test15j(i32 %X) {
+ %t1 = and i32 %X, 2
+ %t2 = icmp ne i32 %t1, 0
+ %t3 = select i1 %t2, i32 1089, i32 577
+ ret i32 %t3
+; CHECK: @test15j
+; CHECK-NEXT: %t1 = shl i32 %X, 8
+; CHECK-NEXT: %1 = and i32 %t1, 512
+; CHECK-NEXT: %2 = add i32 %1, 577
+; CHECK-NEXT: ret i32 %2
+}
+
+define i32 @test16(i1 %C, i32* %P) {
+ %P2 = select i1 %C, i32* %P, i32* null
+ %V = load i32* %P2
+ ret i32 %V
+; CHECK: @test16
+; CHECK-NEXT: %V = load i32* %P
+; CHECK: ret i32 %V
+}
+
+define i1 @test17(i32* %X, i1 %C) {
+ %R = select i1 %C, i32* %X, i32* null
+ %RV = icmp eq i32* %R, null
+ ret i1 %RV
+; CHECK: @test17
+; CHECK: icmp eq i32* %X, null
+; CHECK: xor i1 %C, true
+; CHECK: %RV = or i1
+; CHECK: ret i1 %RV
+}
+
+define i32 @test18(i32 %X, i32 %Y, i1 %C) {
+ %R = select i1 %C, i32 %X, i32 0
+ %V = sdiv i32 %Y, %R
+ ret i32 %V
+; CHECK: @test18
+; CHECK: %V = sdiv i32 %Y, %X
+; CHECK: ret i32 %V
+}
+
+define i32 @test19(i32 %x) {
+ %tmp = icmp ugt i32 %x, 2147483647
+ %retval = select i1 %tmp, i32 -1, i32 0
+ ret i32 %retval
+; CHECK: @test19
+; CHECK-NEXT: ashr i32 %x, 31
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test20(i32 %x) {
+ %tmp = icmp slt i32 %x, 0
+ %retval = select i1 %tmp, i32 -1, i32 0
+ ret i32 %retval
+; CHECK: @test20
+; CHECK-NEXT: ashr i32 %x, 31
+; CHECK-NEXT: ret i32
+}
+
+define i64 @test21(i32 %x) {
+ %tmp = icmp slt i32 %x, 0
+ %retval = select i1 %tmp, i64 -1, i64 0
+ ret i64 %retval
+; CHECK: @test21
+; CHECK-NEXT: ashr i32 %x, 31
+; CHECK-NEXT: sext i32
+; CHECK-NEXT: ret i64
+}
+
+define i16 @test22(i32 %x) {
+ %tmp = icmp slt i32 %x, 0
+ %retval = select i1 %tmp, i16 -1, i16 0
+ ret i16 %retval
+; CHECK: @test22
+; CHECK-NEXT: ashr i32 %x, 31
+; CHECK-NEXT: trunc i32
+; CHECK-NEXT: ret i16
+}
+
+define i1 @test23(i1 %a, i1 %b) {
+ %c = select i1 %a, i1 %b, i1 %a
+ ret i1 %c
+; CHECK: @test23
+; CHECK-NEXT: %c = and i1 %a, %b
+; CHECK-NEXT: ret i1 %c
+}
+
+define i1 @test24(i1 %a, i1 %b) {
+ %c = select i1 %a, i1 %a, i1 %b
+ ret i1 %c
+; CHECK: @test24
+; CHECK-NEXT: %c = or i1 %a, %b
+; CHECK-NEXT: ret i1 %c
+}
+
+define i32 @test25(i1 %c) {
+entry:
+ br i1 %c, label %jump, label %ret
+jump:
+ br label %ret
+ret:
+ %a = phi i1 [true, %jump], [false, %entry]
+ %b = select i1 %a, i32 10, i32 20
+ ret i32 %b
+; CHECK: @test25
+; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
+; CHECK-NEXT: ret i32 %a
+}
+
+define i32 @test26(i1 %cond) {
+entry:
+ br i1 %cond, label %jump, label %ret
+jump:
+ %c = or i1 false, false
+ br label %ret
+ret:
+ %a = phi i1 [true, %jump], [%c, %entry]
+ %b = select i1 %a, i32 10, i32 20
+ ret i32 %b
+; CHECK: @test26
+; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
+; CHECK-NEXT: ret i32 %a
+}
+
+define i32 @test27(i1 %c, i32 %A, i32 %B) {
+entry:
+ br i1 %c, label %jump, label %ret
+jump:
+ br label %ret
+ret:
+ %a = phi i1 [true, %jump], [false, %entry]
+ %b = select i1 %a, i32 %A, i32 %B
+ ret i32 %b
+; CHECK: @test27
+; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
+; CHECK-NEXT: ret i32 %a
+}
+
+define i32 @test28(i1 %cond, i32 %A, i32 %B) {
+entry:
+ br i1 %cond, label %jump, label %ret
+jump:
+ br label %ret
+ret:
+ %c = phi i32 [%A, %jump], [%B, %entry]
+ %a = phi i1 [true, %jump], [false, %entry]
+ %b = select i1 %a, i32 %A, i32 %c
+ ret i32 %b
+; CHECK: @test28
+; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
+; CHECK-NEXT: ret i32 %a
+}
+
+define i32 @test29(i1 %cond, i32 %A, i32 %B) {
+entry:
+ br i1 %cond, label %jump, label %ret
+jump:
+ br label %ret
+ret:
+ %c = phi i32 [%A, %jump], [%B, %entry]
+ %a = phi i1 [true, %jump], [false, %entry]
+ br label %next
+
+next:
+ %b = select i1 %a, i32 %A, i32 %c
+ ret i32 %b
+; CHECK: @test29
+; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
+; CHECK: ret i32 %a
+}
+
+
+; SMAX(SMAX(x, y), x) -> SMAX(x, y)
+define i32 @test30(i32 %x, i32 %y) {
+ %cmp = icmp sgt i32 %x, %y
+ %cond = select i1 %cmp, i32 %x, i32 %y
+
+ %cmp5 = icmp sgt i32 %cond, %x
+ %retval = select i1 %cmp5, i32 %cond, i32 %x
+ ret i32 %retval
+; CHECK: @test30
+; CHECK: ret i32 %cond
+}
+
+; UMAX(UMAX(x, y), x) -> UMAX(x, y)
+define i32 @test31(i32 %x, i32 %y) {
+ %cmp = icmp ugt i32 %x, %y
+ %cond = select i1 %cmp, i32 %x, i32 %y
+ %cmp5 = icmp ugt i32 %cond, %x
+ %retval = select i1 %cmp5, i32 %cond, i32 %x
+ ret i32 %retval
+; CHECK: @test31
+; CHECK: ret i32 %cond
+}
+
+; SMIN(SMIN(x, y), x) -> SMIN(x, y)
+define i32 @test32(i32 %x, i32 %y) {
+ %cmp = icmp sgt i32 %x, %y
+ %cond = select i1 %cmp, i32 %y, i32 %x
+ %cmp5 = icmp sgt i32 %cond, %x
+ %retval = select i1 %cmp5, i32 %x, i32 %cond
+ ret i32 %retval
+; CHECK: @test32
+; CHECK: ret i32 %cond
+}
+
+; MAX(MIN(x, y), x) -> x
+define i32 @test33(i32 %x, i32 %y) {
+ %cmp = icmp sgt i32 %x, %y
+ %cond = select i1 %cmp, i32 %y, i32 %x
+ %cmp5 = icmp sgt i32 %cond, %x
+ %retval = select i1 %cmp5, i32 %cond, i32 %x
+ ret i32 %retval
+; CHECK: @test33
+; CHECK: ret i32 %x
+}
+
+; MIN(MAX(x, y), x) -> x
+define i32 @test34(i32 %x, i32 %y) {
+ %cmp = icmp sgt i32 %x, %y
+ %cond = select i1 %cmp, i32 %x, i32 %y
+ %cmp5 = icmp sgt i32 %cond, %x
+ %retval = select i1 %cmp5, i32 %x, i32 %cond
+ ret i32 %retval
+; CHECK: @test34
+; CHECK: ret i32 %x
+}
+
+define i32 @test35(i32 %x) {
+ %cmp = icmp sge i32 %x, 0
+ %cond = select i1 %cmp, i32 60, i32 100
+ ret i32 %cond
+; CHECK: @test35
+; CHECK: ashr i32 %x, 31
+; CHECK: and i32 {{.*}}, 40
+; CHECK: add i32 {{.*}}, 60
+; CHECK: ret
+}
+
+define i32 @test36(i32 %x) {
+ %cmp = icmp slt i32 %x, 0
+ %cond = select i1 %cmp, i32 60, i32 100
+ ret i32 %cond
+; CHECK: @test36
+; CHECK: ashr i32 %x, 31
+; CHECK: and i32 {{.*}}, -40
+; CHECK: add i32 {{.*}}, 100
+; CHECK: ret
+}
+
+define i32 @test37(i32 %x) {
+ %cmp = icmp sgt i32 %x, -1
+ %cond = select i1 %cmp, i32 1, i32 -1
+ ret i32 %cond
+; CHECK: @test37
+; CHECK: ashr i32 %x, 31
+; CHECK: or i32 {{.*}}, 1
+; CHECK: ret
+}
+
+define i1 @test38(i1 %cond) {
+ %zero = alloca i32
+ %one = alloca i32
+ %ptr = select i1 %cond, i32* %zero, i32* %one
+ %isnull = icmp eq i32* %ptr, null
+ ret i1 %isnull
+; CHECK: @test38
+; CHECK: ret i1 false
+}
+
+define i1 @test39(i1 %cond, double %x) {
+ %s = select i1 %cond, double %x, double 0x7FF0000000000000 ; RHS = +infty
+ %cmp = fcmp ule double %x, %s
+ ret i1 %cmp
+; CHECK: @test39
+; CHECK: ret i1 true
+}
+
+define i1 @test40(i1 %cond) {
+ %a = alloca i32
+ %b = alloca i32
+ %c = alloca i32
+ %s = select i1 %cond, i32* %a, i32* %b
+ %r = icmp eq i32* %s, %c
+ ret i1 %r
+; CHECK: @test40
+; CHECK: ret i1 false
+}
+
+define i32 @test41(i1 %cond, i32 %x, i32 %y) {
+ %z = and i32 %x, %y
+ %s = select i1 %cond, i32 %y, i32 %z
+ %r = and i32 %x, %s
+ ret i32 %r
+; CHECK: @test41
+; CHECK-NEXT: and i32 %x, %y
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test42(i32 %x, i32 %y) {
+ %b = add i32 %y, -1
+ %cond = icmp eq i32 %x, 0
+ %c = select i1 %cond, i32 %b, i32 %y
+ ret i32 %c
+; CHECK: @test42
+; CHECK-NEXT: %cond = icmp eq i32 %x, 0
+; CHECK-NEXT: %b = sext i1 %cond to i32
+; CHECK-NEXT: %c = add i32 %b, %y
+; CHECK-NEXT: ret i32 %c
+}
+
+define i64 @test43(i32 %a) nounwind {
+ %a_ext = sext i32 %a to i64
+ %is_a_nonnegative = icmp sgt i32 %a, -1
+ %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0
+ ret i64 %max
+; CHECK: @test43
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonnegative = icmp slt i64 %a_ext, 0
+; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 0, i64 %a_ext
+; CHECK-NEXT: ret i64 %max
+}
+
+define i64 @test44(i32 %a) nounwind {
+ %a_ext = sext i32 %a to i64
+ %is_a_nonpositive = icmp slt i32 %a, 1
+ %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 0
+ ret i64 %min
+; CHECK: @test44
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonpositive = icmp sgt i64 %a_ext, 0
+; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 0, i64 %a_ext
+; CHECK-NEXT: ret i64 %min
+}
+define i64 @test45(i32 %a) nounwind {
+ %a_ext = zext i32 %a to i64
+ %is_a_nonnegative = icmp ugt i32 %a, 2
+ %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 3
+ ret i64 %max
+; CHECK: @test45
+; CHECK-NEXT: %a_ext = zext i32 %a to i64
+; CHECK-NEXT: %is_a_nonnegative = icmp ult i64 %a_ext, 3
+; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 3, i64 %a_ext
+; CHECK-NEXT: ret i64 %max
+}
+
+define i64 @test46(i32 %a) nounwind {
+ %a_ext = zext i32 %a to i64
+ %is_a_nonpositive = icmp ult i32 %a, 3
+ %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
+ ret i64 %min
+; CHECK: @test46
+; CHECK-NEXT: %a_ext = zext i32 %a to i64
+; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
+; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
+; CHECK-NEXT: ret i64 %min
+}
+define i64 @test47(i32 %a) nounwind {
+ %a_ext = sext i32 %a to i64
+ %is_a_nonnegative = icmp ugt i32 %a, 2
+ %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 3
+ ret i64 %max
+; CHECK: @test47
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonnegative = icmp ult i64 %a_ext, 3
+; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 3, i64 %a_ext
+; CHECK-NEXT: ret i64 %max
+}
+
+define i64 @test48(i32 %a) nounwind {
+ %a_ext = sext i32 %a to i64
+ %is_a_nonpositive = icmp ult i32 %a, 3
+ %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
+ ret i64 %min
+; CHECK: @test48
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
+; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
+; CHECK-NEXT: ret i64 %min
+}
+
+define i64 @test49(i32 %a) nounwind {
+ %a_ext = sext i32 %a to i64
+ %is_a_nonpositive = icmp ult i32 %a, 3
+ %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
+ ret i64 %min
+; CHECK: @test49
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
+; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
+; CHECK-NEXT: ret i64 %min
+}
+define i64 @test50(i32 %a) nounwind {
+ %is_a_nonpositive = icmp ult i32 %a, 3
+ %a_ext = sext i32 %a to i64
+ %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
+ ret i64 %min
+; CHECK: @test50
+; CHECK-NEXT: %a_ext = sext i32 %a to i64
+; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
+; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
+; CHECK-NEXT: ret i64 %min
+}
+
+; PR8994
+
+; This select instruction can't be eliminated because trying to do so would
+; change the number of vector elements. This used to assert.
+define i48 @test51(<3 x i1> %icmp, <3 x i16> %tmp) {
+; CHECK: @test51
+ %select = select <3 x i1> %icmp, <3 x i16> zeroinitializer, <3 x i16> %tmp
+; CHECK: select <3 x i1>
+ %tmp2 = bitcast <3 x i16> %select to i48
+ ret i48 %tmp2
+}
+
+; PR8575
+
+define i32 @test52(i32 %n, i32 %m) nounwind {
+; CHECK: @test52
+ %cmp = icmp sgt i32 %n, %m
+ %. = select i1 %cmp, i32 1, i32 3
+ %add = add nsw i32 %., 3
+ %storemerge = select i1 %cmp, i32 %., i32 %add
+; CHECK: select i1 %cmp, i32 1, i32 6
+ ret i32 %storemerge
+}
+
+; PR9454
+define i32 @test53(i32 %x) nounwind {
+ %and = and i32 %x, 2
+ %cmp = icmp eq i32 %and, %x
+ %sel = select i1 %cmp, i32 2, i32 1
+ ret i32 %sel
+; CHECK: @test53
+; CHECK: select i1 %cmp
+; CHECK: ret
+}
+
+define i32 @test54(i32 %X, i32 %Y) {
+ %A = ashr exact i32 %X, %Y
+ %B = icmp eq i32 %A, 0
+ %C = select i1 %B, i32 %A, i32 1
+ ret i32 %C
+; CHECK: @test54
+; CHECK-NOT: ashr
+; CHECK-NOT: select
+; CHECK: icmp ne i32 %X, 0
+; CHECK: zext
+; CHECK: ret
+}
+
+define i1 @test55(i1 %X, i32 %Y, i32 %Z) {
+ %A = ashr exact i32 %Y, %Z
+ %B = select i1 %X, i32 %Y, i32 %A
+ %C = icmp eq i32 %B, 0
+ ret i1 %C
+; CHECK: @test55
+; CHECK-NOT: ashr
+; CHECK-NOT: select
+; CHECK: icmp eq
+; CHECK: ret i1
+}
+
+define i32 @test56(i16 %x) nounwind {
+ %tobool = icmp eq i16 %x, 0
+ %conv = zext i16 %x to i32
+ %cond = select i1 %tobool, i32 0, i32 %conv
+ ret i32 %cond
+; CHECK: @test56
+; CHECK-NEXT: zext
+; CHECK-NEXT: ret
+}
+
+define i32 @test57(i32 %x, i32 %y) nounwind {
+ %and = and i32 %x, %y
+ %tobool = icmp eq i32 %x, 0
+ %.and = select i1 %tobool, i32 0, i32 %and
+ ret i32 %.and
+; CHECK: @test57
+; CHECK-NEXT: and i32 %x, %y
+; CHECK-NEXT: ret
+}
+
+define i32 @test58(i16 %x) nounwind {
+ %tobool = icmp ne i16 %x, 1
+ %conv = zext i16 %x to i32
+ %cond = select i1 %tobool, i32 %conv, i32 1
+ ret i32 %cond
+; CHECK: @test58
+; CHECK-NEXT: zext
+; CHECK-NEXT: ret
+}
+
+define i32 @test59(i32 %x, i32 %y) nounwind {
+ %and = and i32 %x, %y
+ %tobool = icmp ne i32 %x, %y
+ %.and = select i1 %tobool, i32 %and, i32 %y
+ ret i32 %.and
+; CHECK: @test59
+; CHECK-NEXT: and i32 %x, %y
+; CHECK-NEXT: ret
+}
+
+define i1 @test60(i32 %x, i1* %y) nounwind {
+ %cmp = icmp eq i32 %x, 0
+ %load = load i1* %y, align 1
+ %cmp1 = icmp slt i32 %x, 1
+ %sel = select i1 %cmp, i1 %load, i1 %cmp1
+ ret i1 %sel
+; CHECK: @test60
+; CHECK: select
+}
+
+@glbl = constant i32 10
+define i32 @test61(i32* %ptr) {
+ %A = load i32* %ptr
+ %B = icmp eq i32* %ptr, @glbl
+ %C = select i1 %B, i32 %A, i32 10
+ ret i32 %C
+; CHECK: @test61
+; CHECK: ret i32 10
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/set.ll b/src/LLVM/test/Transforms/InstCombine/set.ll
new file mode 100644
index 0000000..4cad0769f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/set.ll
@@ -0,0 +1,171 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | not grep icmp
+; END.
+
+@X = external global i32 ; <i32*> [#uses=2]
+
+define i1 @test1(i32 %A) {
+ %B = icmp eq i32 %A, %A ; <i1> [#uses=1]
+ ; Never true
+ %C = icmp eq i32* @X, null ; <i1> [#uses=1]
+ %D = and i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test2(i32 %A) {
+ %B = icmp ne i32 %A, %A ; <i1> [#uses=1]
+ ; Never false
+ %C = icmp ne i32* @X, null ; <i1> [#uses=1]
+ %D = or i1 %B, %C ; <i1> [#uses=1]
+ ret i1 %D
+}
+
+define i1 @test3(i32 %A) {
+ %B = icmp slt i32 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+
+define i1 @test4(i32 %A) {
+ %B = icmp sgt i32 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test5(i32 %A) {
+ %B = icmp sle i32 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test6(i32 %A) {
+ %B = icmp sge i32 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test7(i32 %A) {
+ ; true
+ %B = icmp uge i32 %A, 0 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test8(i32 %A) {
+ ; false
+ %B = icmp ult i32 %A, 0 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+;; test operations on boolean values these should all be eliminated$a
+define i1 @test9(i1 %A) {
+ ; false
+ %B = icmp ult i1 %A, false ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test10(i1 %A) {
+ ; false
+ %B = icmp ugt i1 %A, true ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test11(i1 %A) {
+ ; true
+ %B = icmp ule i1 %A, true ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test12(i1 %A) {
+ ; true
+ %B = icmp uge i1 %A, false ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test13(i1 %A, i1 %B) {
+ ; A | ~B
+ %C = icmp uge i1 %A, %B ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test14(i1 %A, i1 %B) {
+ ; ~(A ^ B)
+ %C = icmp eq i1 %A, %B ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test16(i32 %A) {
+ %B = and i32 %A, 5 ; <i32> [#uses=1]
+ ; Is never true
+ %C = icmp eq i32 %B, 8 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test17(i8 %A) {
+ %B = or i8 %A, 1 ; <i8> [#uses=1]
+ ; Always false
+ %C = icmp eq i8 %B, 2 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test18(i1 %C, i32 %a) {
+entry:
+ br i1 %C, label %endif, label %else
+
+else: ; preds = %entry
+ br label %endif
+
+endif: ; preds = %else, %entry
+ %b.0 = phi i32 [ 0, %entry ], [ 1, %else ] ; <i32> [#uses=1]
+ %tmp.4 = icmp slt i32 %b.0, 123 ; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
+
+define i1 @test19(i1 %A, i1 %B) {
+ %a = zext i1 %A to i32 ; <i32> [#uses=1]
+ %b = zext i1 %B to i32 ; <i32> [#uses=1]
+ %C = icmp eq i32 %a, %b ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i32 @test20(i32 %A) {
+ %B = and i32 %A, 1 ; <i32> [#uses=1]
+ %C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
+ %D = zext i1 %C to i32 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test21(i32 %a) {
+ %tmp.6 = and i32 %a, 4 ; <i32> [#uses=1]
+ %not.tmp.7 = icmp ne i32 %tmp.6, 0 ; <i1> [#uses=1]
+ %retval = zext i1 %not.tmp.7 to i32 ; <i32> [#uses=1]
+ ret i32 %retval
+}
+
+define i1 @test22(i32 %A, i32 %X) {
+ %B = and i32 %A, 100663295 ; <i32> [#uses=1]
+ %C = icmp ult i32 %B, 268435456 ; <i1> [#uses=1]
+ %Y = and i32 %X, 7 ; <i32> [#uses=1]
+ %Z = icmp sgt i32 %Y, -1 ; <i1> [#uses=1]
+ %R = or i1 %C, %Z ; <i1> [#uses=1]
+ ret i1 %R
+}
+
+define i32 @test23(i32 %a) {
+ %tmp.1 = and i32 %a, 1 ; <i32> [#uses=1]
+ %tmp.2 = icmp eq i32 %tmp.1, 0 ; <i1> [#uses=1]
+ %tmp.3 = zext i1 %tmp.2 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
+
+define i32 @test24(i32 %a) {
+ %tmp1 = and i32 %a, 4 ; <i32> [#uses=1]
+ %tmp.1 = lshr i32 %tmp1, 2 ; <i32> [#uses=1]
+ %tmp.2 = icmp eq i32 %tmp.1, 0 ; <i1> [#uses=1]
+ %tmp.3 = zext i1 %tmp.2 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
+
+define i1 @test25(i32 %A) {
+ %B = and i32 %A, 2 ; <i32> [#uses=1]
+ %C = icmp ugt i32 %B, 2 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/setcc-strength-reduce.ll b/src/LLVM/test/Transforms/InstCombine/setcc-strength-reduce.ll
new file mode 100644
index 0000000..3acc708
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/setcc-strength-reduce.ll
@@ -0,0 +1,37 @@
+; This test ensures that "strength reduction" of conditional expressions are
+; working. Basically this boils down to converting setlt,gt,le,ge instructions
+; into equivalent setne,eq instructions.
+;
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep -v {icmp eq} | grep -v {icmp ne} | not grep icmp
+; END.
+
+define i1 @test1(i32 %A) {
+ ; setne %A, 0
+ %B = icmp uge i32 %A, 1 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test2(i32 %A) {
+ ; setne %A, 0
+ %B = icmp ugt i32 %A, 0 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test3(i8 %A) {
+ ; setne %A, -128
+ %B = icmp sge i8 %A, -127 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test4(i8 %A) {
+ ; setne %A, 127
+ %B = icmp sle i8 %A, 126 ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i1 @test5(i8 %A) {
+ ; setne %A, 127
+ %B = icmp slt i8 %A, 127 ; <i1> [#uses=1]
+ ret i1 %B
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sext.ll b/src/LLVM/test/Transforms/InstCombine/sext.ll
new file mode 100644
index 0000000..f49a2ef
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sext.ll
@@ -0,0 +1,186 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+declare i32 @llvm.ctpop.i32(i32)
+declare i32 @llvm.ctlz.i32(i32)
+declare i32 @llvm.cttz.i32(i32)
+
+define i64 @test1(i32 %x) {
+ %t = call i32 @llvm.ctpop.i32(i32 %x)
+ %s = sext i32 %t to i64
+ ret i64 %s
+
+; CHECK: @test1
+; CHECK: zext i32 %t
+}
+
+define i64 @test2(i32 %x) {
+ %t = call i32 @llvm.ctlz.i32(i32 %x)
+ %s = sext i32 %t to i64
+ ret i64 %s
+
+; CHECK: @test2
+; CHECK: zext i32 %t
+}
+
+define i64 @test3(i32 %x) {
+ %t = call i32 @llvm.cttz.i32(i32 %x)
+ %s = sext i32 %t to i64
+ ret i64 %s
+
+; CHECK: @test3
+; CHECK: zext i32 %t
+}
+
+define i64 @test4(i32 %x) {
+ %t = udiv i32 %x, 3
+ %s = sext i32 %t to i64
+ ret i64 %s
+
+; CHECK: @test4
+; CHECK: zext i32 %t
+}
+
+define i64 @test5(i32 %x) {
+ %t = urem i32 %x, 30000
+ %s = sext i32 %t to i64
+ ret i64 %s
+; CHECK: @test5
+; CHECK: zext i32 %t
+}
+
+define i64 @test6(i32 %x) {
+ %u = lshr i32 %x, 3
+ %t = mul i32 %u, 3
+ %s = sext i32 %t to i64
+ ret i64 %s
+; CHECK: @test6
+; CHECK: zext i32 %t
+}
+
+define i64 @test7(i32 %x) {
+ %t = and i32 %x, 511
+ %u = sub i32 20000, %t
+ %s = sext i32 %u to i64
+ ret i64 %s
+; CHECK: @test7
+; CHECK: zext i32 %u to i64
+}
+
+define i32 @test8(i8 %a, i32 %f, i1 %p, i32* %z) {
+ %d = lshr i32 %f, 24
+ %e = select i1 %p, i32 %d, i32 0
+ %s = trunc i32 %e to i16
+ %n = sext i16 %s to i32
+ ret i32 %n
+; CHECK: @test8
+; CHECK: %d = lshr i32 %f, 24
+; CHECK: %n = select i1 %p, i32 %d, i32 0
+; CHECK: ret i32 %n
+}
+
+; rdar://6013816
+define i16 @test9(i16 %t, i1 %cond) nounwind {
+entry:
+ br i1 %cond, label %T, label %F
+T:
+ %t2 = sext i16 %t to i32
+ br label %F
+
+F:
+ %V = phi i32 [%t2, %T], [42, %entry]
+ %W = trunc i32 %V to i16
+ ret i16 %W
+; CHECK: @test9
+; CHECK: T:
+; CHECK-NEXT: br label %F
+; CHECK: F:
+; CHECK-NEXT: phi i16
+; CHECK-NEXT: ret i16
+}
+
+; PR2638
+define i32 @test10(i32 %i) nounwind {
+entry:
+ %tmp12 = trunc i32 %i to i8
+ %tmp16 = shl i8 %tmp12, 6
+ %a = ashr i8 %tmp16, 6
+ %b = sext i8 %a to i32
+ ret i32 %b
+; CHECK: @test10
+; CHECK: shl i32 %i, 30
+; CHECK-NEXT: ashr exact i32
+; CHECK-NEXT: ret i32
+}
+
+define void @test11(<2 x i16> %srcA, <2 x i16> %srcB, <2 x i16>* %dst) {
+ %cmp = icmp eq <2 x i16> %srcB, %srcA
+ %sext = sext <2 x i1> %cmp to <2 x i16>
+ %tmask = ashr <2 x i16> %sext, <i16 15, i16 15>
+ store <2 x i16> %tmask, <2 x i16>* %dst
+ ret void
+; CHECK: @test11
+; CHECK-NEXT: icmp eq
+; CHECK-NEXT: sext <2 x i1>
+; CHECK-NEXT: store <2 x i16>
+; CHECK-NEXT: ret
+}
+
+define i64 @test12(i32 %x) nounwind {
+ %shr = lshr i32 %x, 1
+ %sub = sub nsw i32 0, %shr
+ %conv = sext i32 %sub to i64
+ ret i64 %conv
+; CHECK: @test12
+; CHECK: sext
+; CHECK: ret
+}
+
+define i32 @test13(i32 %x) nounwind {
+ %and = and i32 %x, 8
+ %cmp = icmp eq i32 %and, 0
+ %ext = sext i1 %cmp to i32
+ ret i32 %ext
+; CHECK: @test13
+; CHECK-NEXT: %and = lshr i32 %x, 3
+; CHECK-NEXT: %1 = and i32 %and, 1
+; CHECK-NEXT: %sext = add i32 %1, -1
+; CHECK-NEXT: ret i32 %sext
+}
+
+define i32 @test14(i16 %x) nounwind {
+ %and = and i16 %x, 16
+ %cmp = icmp ne i16 %and, 16
+ %ext = sext i1 %cmp to i32
+ ret i32 %ext
+; CHECK: @test14
+; CHECK-NEXT: %and = lshr i16 %x, 4
+; CHECK-NEXT: %1 = and i16 %and, 1
+; CHECK-NEXT: %sext = add i16 %1, -1
+; CHECK-NEXT: %ext = sext i16 %sext to i32
+; CHECK-NEXT: ret i32 %ext
+}
+
+define i32 @test15(i32 %x) nounwind {
+ %and = and i32 %x, 16
+ %cmp = icmp ne i32 %and, 0
+ %ext = sext i1 %cmp to i32
+ ret i32 %ext
+; CHECK: @test15
+; CHECK-NEXT: %1 = shl i32 %x, 27
+; CHECK-NEXT: %sext = ashr i32 %1, 31
+; CHECK-NEXT: ret i32 %sext
+}
+
+define i32 @test16(i16 %x) nounwind {
+ %and = and i16 %x, 8
+ %cmp = icmp eq i16 %and, 8
+ %ext = sext i1 %cmp to i32
+ ret i32 %ext
+; CHECK: @test16
+; CHECK-NEXT: %1 = shl i16 %x, 12
+; CHECK-NEXT: %sext = ashr i16 %1, 15
+; CHECK-NEXT: %ext = sext i16 %sext to i32
+; CHECK-NEXT: ret i32 %ext
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/shift-sra.ll b/src/LLVM/test/Transforms/InstCombine/shift-sra.ll
new file mode 100644
index 0000000..f17b83f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/shift-sra.ll
@@ -0,0 +1,78 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+
+define i32 @test1(i32 %X, i8 %A) {
+ %shift.upgrd.1 = zext i8 %A to i32 ; <i32> [#uses=1]
+ ; can be logical shift.
+ %Y = ashr i32 %X, %shift.upgrd.1 ; <i32> [#uses=1]
+ %Z = and i32 %Y, 1 ; <i32> [#uses=1]
+ ret i32 %Z
+; CHECK: @test1
+; CHECK: lshr i32 %X, %shift.upgrd.1
+}
+
+define i32 @test2(i8 %tmp) {
+ %tmp3 = zext i8 %tmp to i32 ; <i32> [#uses=1]
+ %tmp4 = add i32 %tmp3, 7 ; <i32> [#uses=1]
+ %tmp5 = ashr i32 %tmp4, 3 ; <i32> [#uses=1]
+ ret i32 %tmp5
+; CHECK: @test2
+; CHECK: lshr i32 %tmp4, 3
+}
+
+define i64 @test3(i1 %X, i64 %Y, i1 %Cond) {
+ br i1 %Cond, label %T, label %F
+T:
+ %X2 = sext i1 %X to i64
+ br label %C
+F:
+ %Y2 = ashr i64 %Y, 63
+ br label %C
+C:
+ %P = phi i64 [%X2, %T], [%Y2, %F]
+ %S = ashr i64 %P, 12
+ ret i64 %S
+
+; CHECK: @test3
+; CHECK: %P = phi i64
+; CHECK-NEXT: ret i64 %P
+}
+
+define i64 @test4(i1 %X, i64 %Y, i1 %Cond) {
+ br i1 %Cond, label %T, label %F
+T:
+ %X2 = sext i1 %X to i64
+ br label %C
+F:
+ %Y2 = ashr i64 %Y, 63
+ br label %C
+C:
+ %P = phi i64 [%X2, %T], [%Y2, %F]
+ %R = shl i64 %P, 12
+ %S = ashr i64 %R, 12
+ ret i64 %S
+
+; CHECK: @test4
+; CHECK: %P = phi i64
+; CHECK-NEXT: ret i64 %P
+}
+
+; rdar://7732987
+define i32 @test5(i32 %Y) {
+ br i1 undef, label %A, label %C
+A:
+ br i1 undef, label %B, label %D
+B:
+ br label %D
+C:
+ br i1 undef, label %D, label %E
+D:
+ %P = phi i32 [0, %A], [0, %B], [%Y, %C]
+ %S = ashr i32 %P, 16
+ ret i32 %S
+; CHECK: @test5
+; CHECK: %P = phi i32
+; CHECK-NEXT: ashr i32 %P, 16
+E:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/shift.ll b/src/LLVM/test/Transforms/InstCombine/shift.ll
new file mode 100644
index 0000000..70fb4c8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/shift.ll
@@ -0,0 +1,544 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @test1(i32 %A) {
+; CHECK: @test1
+; CHECK: ret i32 %A
+ %B = shl i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test2(i8 %A) {
+; CHECK: @test2
+; CHECK: ret i32 0
+ %shift.upgrd.1 = zext i8 %A to i32 ; <i32> [#uses=1]
+ %B = shl i32 0, %shift.upgrd.1 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test3(i32 %A) {
+; CHECK: @test3
+; CHECK: ret i32 %A
+ %B = ashr i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test4(i8 %A) {
+; CHECK: @test4
+; CHECK: ret i32 0
+ %shift.upgrd.2 = zext i8 %A to i32 ; <i32> [#uses=1]
+ %B = ashr i32 0, %shift.upgrd.2 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+
+define i32 @test5(i32 %A) {
+; CHECK: @test5
+; CHECK: ret i32 undef
+ %B = lshr i32 %A, 32 ;; shift all bits out
+ ret i32 %B
+}
+
+define i32 @test5a(i32 %A) {
+; CHECK: @test5a
+; CHECK: ret i32 undef
+ %B = shl i32 %A, 32 ;; shift all bits out
+ ret i32 %B
+}
+
+define i32 @test5b() {
+; CHECK: @test5b
+; CHECK: ret i32 -1
+ %B = ashr i32 undef, 2 ;; top two bits must be equal, so not undef
+ ret i32 %B
+}
+
+define i32 @test5b2(i32 %A) {
+; CHECK: @test5b2
+; CHECK: ret i32 -1
+ %B = ashr i32 undef, %A ;; top %A bits must be equal, so not undef
+ ret i32 %B
+}
+
+define i32 @test6(i32 %A) {
+; CHECK: @test6
+; CHECK-NEXT: mul i32 %A, 6
+; CHECK-NEXT: ret i32
+ %B = shl i32 %A, 1 ;; convert to an mul instruction
+ %C = mul i32 %B, 3
+ ret i32 %C
+}
+
+define i32 @test7(i8 %A) {
+; CHECK: @test7
+; CHECK-NEXT: ret i32 -1
+ %shift.upgrd.3 = zext i8 %A to i32
+ %B = ashr i32 -1, %shift.upgrd.3 ;; Always equal to -1
+ ret i32 %B
+}
+
+;; (A << 5) << 3 === A << 8 == 0
+define i8 @test8(i8 %A) {
+; CHECK: @test8
+; CHECK: ret i8 0
+ %B = shl i8 %A, 5 ; <i8> [#uses=1]
+ %C = shl i8 %B, 3 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; (A << 7) >> 7 === A & 1
+define i8 @test9(i8 %A) {
+; CHECK: @test9
+; CHECK-NEXT: and i8 %A, 1
+; CHECK-NEXT: ret i8
+ %B = shl i8 %A, 7 ; <i8> [#uses=1]
+ %C = lshr i8 %B, 7 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; (A >> 7) << 7 === A & 128
+define i8 @test10(i8 %A) {
+; CHECK: @test10
+; CHECK-NEXT: and i8 %A, -128
+; CHECK-NEXT: ret i8
+ %B = lshr i8 %A, 7 ; <i8> [#uses=1]
+ %C = shl i8 %B, 7 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; (A >> 3) << 4 === (A & 0x1F) << 1
+define i8 @test11(i8 %A) {
+; CHECK: @test11
+; CHECK-NEXT: mul i8 %A, 6
+; CHECK-NEXT: and i8
+; CHECK-NEXT: ret i8
+ %a = mul i8 %A, 3 ; <i8> [#uses=1]
+ %B = lshr i8 %a, 3 ; <i8> [#uses=1]
+ %C = shl i8 %B, 4 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; (A >> 8) << 8 === A & -256
+define i32 @test12(i32 %A) {
+; CHECK: @test12
+; CHECK-NEXT: and i32 %A, -256
+; CHECK-NEXT: ret i32
+ %B = ashr i32 %A, 8 ; <i32> [#uses=1]
+ %C = shl i32 %B, 8 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+;; (A >> 3) << 4 === (A & -8) * 2
+define i8 @test13(i8 %A) {
+; CHECK: @test13
+; CHECK-NEXT: mul i8 %A, 6
+; CHECK-NEXT: and i8
+; CHECK-NEXT: ret i8
+ %a = mul i8 %A, 3 ; <i8> [#uses=1]
+ %B = ashr i8 %a, 3 ; <i8> [#uses=1]
+ %C = shl i8 %B, 4 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
+define i32 @test14(i32 %A) {
+; CHECK: @test14
+; CHECK-NEXT: %B = and i32 %A, -19760
+; CHECK-NEXT: or i32 %B, 19744
+; CHECK-NEXT: ret i32
+ %B = lshr i32 %A, 4 ; <i32> [#uses=1]
+ %C = or i32 %B, 1234 ; <i32> [#uses=1]
+ %D = shl i32 %C, 4 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
+define i32 @test14a(i32 %A) {
+; CHECK: @test14a
+; CHECK-NEXT: and i32 %A, 77
+; CHECK-NEXT: ret i32
+ %B = shl i32 %A, 4 ; <i32> [#uses=1]
+ %C = and i32 %B, 1234 ; <i32> [#uses=1]
+ %D = lshr i32 %C, 4 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test15(i1 %C) {
+; CHECK: @test15
+; CHECK-NEXT: select i1 %C, i32 12, i32 4
+; CHECK-NEXT: ret i32
+ %A = select i1 %C, i32 3, i32 1 ; <i32> [#uses=1]
+ %V = shl i32 %A, 2 ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define i32 @test15a(i1 %C) {
+; CHECK: @test15a
+; CHECK-NEXT: select i1 %C, i32 512, i32 128
+; CHECK-NEXT: ret i32
+ %A = select i1 %C, i8 3, i8 1 ; <i8> [#uses=1]
+ %shift.upgrd.4 = zext i8 %A to i32 ; <i32> [#uses=1]
+ %V = shl i32 64, %shift.upgrd.4 ; <i32> [#uses=1]
+ ret i32 %V
+}
+
+define i1 @test16(i32 %X) {
+; CHECK: @test16
+; CHECK-NEXT: and i32 %X, 16
+; CHECK-NEXT: icmp ne i32
+; CHECK-NEXT: ret i1
+ %tmp.3 = ashr i32 %X, 4
+ %tmp.6 = and i32 %tmp.3, 1
+ %tmp.7 = icmp ne i32 %tmp.6, 0
+ ret i1 %tmp.7
+}
+
+define i1 @test17(i32 %A) {
+; CHECK: @test17
+; CHECK-NEXT: and i32 %A, -8
+; CHECK-NEXT: icmp eq i32
+; CHECK-NEXT: ret i1
+ %B = lshr i32 %A, 3 ; <i32> [#uses=1]
+ %C = icmp eq i32 %B, 1234 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+
+define i1 @test18(i8 %A) {
+; CHECK: @test18
+; CHECK: ret i1 false
+
+ %B = lshr i8 %A, 7 ; <i8> [#uses=1]
+ ;; false
+ %C = icmp eq i8 %B, 123 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test19(i32 %A) {
+; CHECK: @test19
+; CHECK-NEXT: icmp ult i32 %A, 4
+; CHECK-NEXT: ret i1
+ %B = ashr i32 %A, 2 ; <i32> [#uses=1]
+ ;; (X & -4) == 0
+ %C = icmp eq i32 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+
+define i1 @test19a(i32 %A) {
+; CHECK: @test19a
+; CHECK-NEXT: and i32 %A, -4
+; CHECK-NEXT: icmp eq i32
+; CHECK-NEXT: ret i1
+ %B = ashr i32 %A, 2 ; <i32> [#uses=1]
+ ;; (X & -4) == -4
+ %C = icmp eq i32 %B, -1 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test20(i8 %A) {
+; CHECK: @test20
+; CHECK: ret i1 false
+ %B = ashr i8 %A, 7 ; <i8> [#uses=1]
+ ;; false
+ %C = icmp eq i8 %B, 123 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test21(i8 %A) {
+; CHECK: @test21
+; CHECK-NEXT: and i8 %A, 15
+; CHECK-NEXT: icmp eq i8
+; CHECK-NEXT: ret i1
+ %B = shl i8 %A, 4 ; <i8> [#uses=1]
+ %C = icmp eq i8 %B, -128 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i1 @test22(i8 %A) {
+; CHECK: @test22
+; CHECK-NEXT: and i8 %A, 15
+; CHECK-NEXT: icmp eq i8
+; CHECK-NEXT: ret i1
+ %B = shl i8 %A, 4 ; <i8> [#uses=1]
+ %C = icmp eq i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i8 @test23(i32 %A) {
+; CHECK: @test23
+; CHECK-NEXT: trunc i32 %A to i8
+; CHECK-NEXT: ret i8
+
+ ;; casts not needed
+ %B = shl i32 %A, 24 ; <i32> [#uses=1]
+ %C = ashr i32 %B, 24 ; <i32> [#uses=1]
+ %D = trunc i32 %C to i8 ; <i8> [#uses=1]
+ ret i8 %D
+}
+
+define i8 @test24(i8 %X) {
+; CHECK: @test24
+; CHECK-NEXT: and i8 %X, 3
+; CHECK-NEXT: ret i8
+ %Y = and i8 %X, -5 ; <i8> [#uses=1]
+ %Z = shl i8 %Y, 5 ; <i8> [#uses=1]
+ %Q = ashr i8 %Z, 5 ; <i8> [#uses=1]
+ ret i8 %Q
+}
+
+define i32 @test25(i32 %tmp.2, i32 %AA) {
+; CHECK: @test25
+; CHECK-NEXT: and i32 %tmp.2, -131072
+; CHECK-NEXT: add i32 %{{[^,]*}}, %AA
+; CHECK-NEXT: and i32 %{{[^,]*}}, -131072
+; CHECK-NEXT: ret i32
+ %x = lshr i32 %AA, 17 ; <i32> [#uses=1]
+ %tmp.3 = lshr i32 %tmp.2, 17 ; <i32> [#uses=1]
+ %tmp.5 = add i32 %tmp.3, %x ; <i32> [#uses=1]
+ %tmp.6 = shl i32 %tmp.5, 17 ; <i32> [#uses=1]
+ ret i32 %tmp.6
+}
+
+;; handle casts between shifts.
+define i32 @test26(i32 %A) {
+; CHECK: @test26
+; CHECK-NEXT: and i32 %A, -2
+; CHECK-NEXT: ret i32
+ %B = lshr i32 %A, 1 ; <i32> [#uses=1]
+ %C = bitcast i32 %B to i32 ; <i32> [#uses=1]
+ %D = shl i32 %C, 1 ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+
+define i1 @test27(i32 %x) nounwind {
+; CHECK: @test27
+; CHECK-NEXT: and i32 %x, 8
+; CHECK-NEXT: icmp ne i32
+; CHECK-NEXT: ret i1
+ %y = lshr i32 %x, 3
+ %z = trunc i32 %y to i1
+ ret i1 %z
+}
+
+define i8 @test28(i8 %x) {
+entry:
+; CHECK: @test28
+; CHECK: icmp slt i8 %x, 0
+; CHECK-NEXT: br i1
+ %tmp1 = lshr i8 %x, 7
+ %cond1 = icmp ne i8 %tmp1, 0
+ br i1 %cond1, label %bb1, label %bb2
+
+bb1:
+ ret i8 0
+
+bb2:
+ ret i8 1
+}
+
+define i8 @test28a(i8 %x, i8 %y) {
+entry:
+; This shouldn't be transformed.
+; CHECK: @test28a
+; CHECK: %tmp1 = lshr i8 %x, 7
+; CHECK: %cond1 = icmp eq i8 %tmp1, 0
+; CHECK: br i1 %cond1, label %bb2, label %bb1
+ %tmp1 = lshr i8 %x, 7
+ %cond1 = icmp ne i8 %tmp1, 0
+ br i1 %cond1, label %bb1, label %bb2
+bb1:
+ ret i8 %tmp1
+bb2:
+ %tmp2 = add i8 %tmp1, %y
+ ret i8 %tmp2
+}
+
+
+define i32 @test29(i64 %d18) {
+entry:
+ %tmp916 = lshr i64 %d18, 32
+ %tmp917 = trunc i64 %tmp916 to i32
+ %tmp10 = lshr i32 %tmp917, 31
+ ret i32 %tmp10
+; CHECK: @test29
+; CHECK: %tmp916 = lshr i64 %d18, 63
+; CHECK: %tmp10 = trunc i64 %tmp916 to i32
+}
+
+
+define i32 @test30(i32 %A, i32 %B, i32 %C) {
+ %X = shl i32 %A, %C
+ %Y = shl i32 %B, %C
+ %Z = and i32 %X, %Y
+ ret i32 %Z
+; CHECK: @test30
+; CHECK: %X1 = and i32 %A, %B
+; CHECK: %Z = shl i32 %X1, %C
+}
+
+define i32 @test31(i32 %A, i32 %B, i32 %C) {
+ %X = lshr i32 %A, %C
+ %Y = lshr i32 %B, %C
+ %Z = or i32 %X, %Y
+ ret i32 %Z
+; CHECK: @test31
+; CHECK: %X1 = or i32 %A, %B
+; CHECK: %Z = lshr i32 %X1, %C
+}
+
+define i32 @test32(i32 %A, i32 %B, i32 %C) {
+ %X = ashr i32 %A, %C
+ %Y = ashr i32 %B, %C
+ %Z = xor i32 %X, %Y
+ ret i32 %Z
+; CHECK: @test32
+; CHECK: %X1 = xor i32 %A, %B
+; CHECK: %Z = ashr i32 %X1, %C
+; CHECK: ret i32 %Z
+}
+
+define i1 @test33(i32 %X) {
+ %tmp1 = shl i32 %X, 7
+ %tmp2 = icmp slt i32 %tmp1, 0
+ ret i1 %tmp2
+; CHECK: @test33
+; CHECK: %tmp1.mask = and i32 %X, 16777216
+; CHECK: %tmp2 = icmp ne i32 %tmp1.mask, 0
+}
+
+define i1 @test34(i32 %X) {
+ %tmp1 = lshr i32 %X, 7
+ %tmp2 = icmp slt i32 %tmp1, 0
+ ret i1 %tmp2
+; CHECK: @test34
+; CHECK: ret i1 false
+}
+
+define i1 @test35(i32 %X) {
+ %tmp1 = ashr i32 %X, 7
+ %tmp2 = icmp slt i32 %tmp1, 0
+ ret i1 %tmp2
+; CHECK: @test35
+; CHECK: %tmp2 = icmp slt i32 %X, 0
+; CHECK: ret i1 %tmp2
+}
+
+define i128 @test36(i128 %A, i128 %B) {
+entry:
+ %tmp27 = shl i128 %A, 64
+ %tmp23 = shl i128 %B, 64
+ %ins = or i128 %tmp23, %tmp27
+ %tmp45 = lshr i128 %ins, 64
+ ret i128 %tmp45
+
+; CHECK: @test36
+; CHECK: %tmp231 = or i128 %B, %A
+; CHECK: %ins = and i128 %tmp231, 18446744073709551615
+; CHECK: ret i128 %ins
+}
+
+define i64 @test37(i128 %A, i32 %B) {
+entry:
+ %tmp27 = shl i128 %A, 64
+ %tmp22 = zext i32 %B to i128
+ %tmp23 = shl i128 %tmp22, 96
+ %ins = or i128 %tmp23, %tmp27
+ %tmp45 = lshr i128 %ins, 64
+ %tmp46 = trunc i128 %tmp45 to i64
+ ret i64 %tmp46
+
+; CHECK: @test37
+; CHECK: %tmp23 = shl nuw nsw i128 %tmp22, 32
+; CHECK: %ins = or i128 %tmp23, %A
+; CHECK: %tmp46 = trunc i128 %ins to i64
+}
+
+define i32 @test38(i32 %x) nounwind readnone {
+ %rem = srem i32 %x, 32
+ %shl = shl i32 1, %rem
+ ret i32 %shl
+; CHECK: @test38
+; CHECK-NEXT: and i32 %x, 31
+; CHECK-NEXT: shl i32 1
+; CHECK-NEXT: ret i32
+}
+
+; <rdar://problem/8756731>
+; CHECK: @test39
+define i8 @test39(i32 %a0) {
+entry:
+ %tmp4 = trunc i32 %a0 to i8
+; CHECK: and i8 %tmp49, 64
+ %tmp5 = shl i8 %tmp4, 5
+ %tmp48 = and i8 %tmp5, 32
+ %tmp49 = lshr i8 %tmp48, 5
+ %tmp50 = mul i8 %tmp49, 64
+ %tmp51 = xor i8 %tmp50, %tmp5
+; CHECK: and i8 %0, 16
+ %tmp52 = and i8 %tmp51, -128
+ %tmp53 = lshr i8 %tmp52, 7
+ %tmp54 = mul i8 %tmp53, 16
+ %tmp55 = xor i8 %tmp54, %tmp51
+; CHECK: ret i8 %tmp551
+ ret i8 %tmp55
+}
+
+; PR9809
+define i32 @test40(i32 %a, i32 %b) nounwind {
+ %shl1 = shl i32 1, %b
+ %shl2 = shl i32 %shl1, 2
+ %div = udiv i32 %a, %shl2
+ ret i32 %div
+; CHECK: @test40
+; CHECK-NEXT: add i32 %b, 2
+; CHECK-NEXT: lshr i32 %a
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test41(i32 %a, i32 %b) nounwind {
+ %1 = shl i32 1, %b
+ %2 = shl i32 %1, 3
+ ret i32 %2
+; CHECK: @test41
+; CHECK-NEXT: shl i32 8, %b
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test42(i32 %a, i32 %b) nounwind {
+ %div = lshr i32 4096, %b ; must be exact otherwise we'd divide by zero
+ %div2 = udiv i32 %a, %div
+ ret i32 %div2
+; CHECK: @test42
+; CHECK-NEXT: lshr exact i32 4096, %b
+}
+
+define i32 @test43(i32 %a, i32 %b) nounwind {
+ %div = shl i32 4096, %b ; must be exact otherwise we'd divide by zero
+ %div2 = udiv i32 %a, %div
+ ret i32 %div2
+; CHECK: @test43
+; CHECK-NEXT: add i32 %b, 12
+; CHECK-NEXT: lshr
+; CHECK-NEXT: ret
+}
+
+define i32 @test44(i32 %a) nounwind {
+ %y = shl nuw i32 %a, 1
+ %z = shl i32 %y, 4
+ ret i32 %z
+; CHECK: @test44
+; CHECK-NEXT: %y = shl i32 %a, 5
+; CHECK-NEXT: ret i32 %y
+}
+
+define i32 @test45(i32 %a) nounwind {
+ %y = lshr exact i32 %a, 1
+ %z = lshr i32 %y, 4
+ ret i32 %z
+; CHECK: @test45
+; CHECK-NEXT: %y = lshr i32 %a, 5
+; CHECK-NEXT: ret i32 %y
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/shufflemask-undef.ll b/src/LLVM/test/Transforms/InstCombine/shufflemask-undef.ll
new file mode 100644
index 0000000..cf87aef
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/shufflemask-undef.ll
@@ -0,0 +1,109 @@
+; RUN: opt < %s -instcombine -S | not grep {shufflevector.\*i32 8}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9"
+ %struct.ActiveTextureTargets = type { i64, i64, i64, i64, i64, i64 }
+ %struct.AlphaTest = type { float, i16, i8, i8 }
+ %struct.ArrayRange = type { i8, i8, i8, i8 }
+ %struct.BlendMode = type { i16, i16, i16, i16, %struct.IColor4, i16, i16, i8, i8, i8, i8 }
+ %struct.ClearColor = type { double, %struct.IColor4, %struct.IColor4, float, i32 }
+ %struct.ClipPlane = type { i32, [6 x %struct.IColor4] }
+ %struct.ColorBuffer = type { i16, i8, i8, [8 x i16], [0 x i32] }
+ %struct.ColorMatrix = type { [16 x float]*, %struct.ImagingColorScale }
+ %struct.Convolution = type { %struct.IColor4, %struct.ImagingColorScale, i16, i16, [0 x i32], float*, i32, i32 }
+ %struct.DepthTest = type { i16, i16, i8, i8, i8, i8, double, double }
+ %struct.FixedFunction = type { %struct.PPStreamToken* }
+ %struct.FogMode = type { %struct.IColor4, float, float, float, float, float, i16, i16, i16, i8, i8 }
+ %struct.HintMode = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16 }
+ %struct.Histogram = type { %struct.ProgramLimits*, i32, i16, i8, i8 }
+ %struct.ImagingColorScale = type { %struct.TCoord2, %struct.TCoord2, %struct.TCoord2, %struct.TCoord2 }
+ %struct.ImagingSubset = type { %struct.Convolution, %struct.Convolution, %struct.Convolution, %struct.ColorMatrix, %struct.Minmax, %struct.Histogram, %struct.ImagingColorScale, %struct.ImagingColorScale, %struct.ImagingColorScale, %struct.ImagingColorScale, i32, [0 x i32] }
+ %struct.Light = type { %struct.IColor4, %struct.IColor4, %struct.IColor4, %struct.IColor4, %struct.PointLineLimits, float, float, float, float, float, %struct.PointLineLimits, float, %struct.PointLineLimits, float, %struct.PointLineLimits, float, float, float, float, float }
+ %struct.LightModel = type { %struct.IColor4, [8 x %struct.Light], [2 x %struct.Material], i32, i16, i16, i16, i8, i8, i8, i8, i8, i8 }
+ %struct.LightProduct = type { %struct.IColor4, %struct.IColor4, %struct.IColor4 }
+ %struct.LineMode = type { float, i32, i16, i16, i8, i8, i8, i8 }
+ %struct.LogicOp = type { i16, i8, i8 }
+ %struct.MaskMode = type { i32, [3 x i32], i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.Material = type { %struct.IColor4, %struct.IColor4, %struct.IColor4, %struct.IColor4, float, float, float, float, [8 x %struct.LightProduct], %struct.IColor4, [8 x i32] }
+ %struct.Minmax = type { %struct.MinmaxTable*, i16, i8, i8, [0 x i32] }
+ %struct.MinmaxTable = type { %struct.IColor4, %struct.IColor4 }
+ %struct.Mipmaplevel = type { [4 x i32], [4 x i32], [4 x float], [4 x i32], i32, i32, float*, i8*, i16, i16, i16, i16, [2 x float] }
+ %struct.Multisample = type { float, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.PipelineProgramState = type { i8, i8, i8, i8, [0 x i32], %struct.IColor4* }
+ %struct.PixelMap = type { i32*, float*, float*, float*, float*, float*, float*, float*, float*, i32*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
+ %struct.PixelMode = type { float, float, %struct.PixelStore, %struct.PixelTransfer, %struct.PixelMap, %struct.ImagingSubset, i32, i32 }
+ %struct.PixelPack = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8 }
+ %struct.PixelStore = type { %struct.PixelPack, %struct.PixelPack }
+ %struct.PixelTransfer = type { float, float, float, float, float, float, float, float, float, float, i32, i32, float, float, float, float, float, float, float, float, float, float, float, float }
+ %struct.PluginBufferData = type { i32 }
+ %struct.PointLineLimits = type { float, float, float }
+ %struct.PointMode = type { float, float, float, float, %struct.PointLineLimits, float, i8, i8, i8, i8, i16, i16, i32, i16, i16 }
+ %struct.PolygonMode = type { [128 x i8], float, float, i16, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.ProgramLimits = type { i32, i32, i32, i32 }
+ %struct.RegisterCombiners = type { i8, i8, i8, i8, i32, [2 x %struct.IColor4], [8 x %struct.RegisterCombinersPerStageState], %struct.RegisterCombinersFinalStageState }
+ %struct.RegisterCombinersFinalStageState = type { i8, i8, i8, i8, [7 x %struct.RegisterCombinersPerVariableState] }
+ %struct.RegisterCombinersPerPortionState = type { [4 x %struct.RegisterCombinersPerVariableState], i8, i8, i8, i8, i16, i16, i16, i16, i16, i16 }
+ %struct.RegisterCombinersPerStageState = type { [2 x %struct.RegisterCombinersPerPortionState], [2 x %struct.IColor4] }
+ %struct.RegisterCombinersPerVariableState = type { i16, i16, i16, i16 }
+ %struct.SWRSurfaceRec = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8*, [4 x i8*], i32 }
+ %struct.ScissorTest = type { %struct.ProgramLimits, i8, i8, i8, i8 }
+ %struct.State = type <{ i16, i16, i16, i16, i32, i32, [256 x %struct.IColor4], [128 x %struct.IColor4], %struct.Viewport, %struct.Transform, %struct.LightModel, %struct.ActiveTextureTargets, %struct.AlphaTest, %struct.BlendMode, %struct.ClearColor, %struct.ColorBuffer, %struct.DepthTest, %struct.ArrayRange, %struct.FogMode, %struct.HintMode, %struct.LineMode, %struct.LogicOp, %struct.MaskMode, %struct.PixelMode, %struct.PointMode, %struct.PolygonMode, %struct.ScissorTest, i32, %struct.StencilTest, [8 x %struct.TextureMode], [16 x %struct.TextureImageMode], %struct.ArrayRange, [8 x %struct.TextureCoordGen], %struct.ClipPlane, %struct.Multisample, %struct.RegisterCombiners, %struct.ArrayRange, %struct.ArrayRange, [3 x %struct.PipelineProgramState], %struct.ArrayRange, %struct.TransformFeedback, i32*, %struct.FixedFunction, [3 x i32], [3 x i32] }>
+ %struct.StencilTest = type { [3 x { i32, i32, i16, i16, i16, i16 }], i32, [4 x i8] }
+ %struct.TextureCoordGen = type { { i16, i16, %struct.IColor4, %struct.IColor4 }, { i16, i16, %struct.IColor4, %struct.IColor4 }, { i16, i16, %struct.IColor4, %struct.IColor4 }, { i16, i16, %struct.IColor4, %struct.IColor4 }, i8, i8, i8, i8 }
+ %struct.TextureGeomState = type { i16, i16, i16, i16, i16, i8, i8, i8, i8, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, [6 x i16], [6 x i16] }
+ %struct.TextureImageMode = type { float }
+ %struct.TextureLevel = type { i32, i32, i16, i16, i16, i8, i8, i16, i16, i16, i16, i8* }
+ %struct.TextureMode = type { %struct.IColor4, i32, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, float, float, i16, i16, i16, i16, i16, i16, [4 x i16], i8, i8, i8, i8, [3 x float], [4 x float], float, float }
+ %struct.TextureParamState = type { i16, i16, i16, i16, i16, i16, %struct.IColor4, float, float, float, float, i16, i16, i16, i16, float, i16, i8, i8, i32, i8* }
+ %struct.TextureRec = type { [4 x float], %struct.TextureState*, %struct.Mipmaplevel*, %struct.Mipmaplevel*, float, float, float, float, i8, i8, i8, i8, i16, i16, i16, i16, i32, float, [2 x %struct.PPStreamToken] }
+ %struct.TextureState = type { i16, i8, i8, i16, i16, float, i32, %struct.SWRSurfaceRec*, %struct.TextureParamState, %struct.TextureGeomState, [0 x i32], i8*, i32, %struct.TextureLevel, [1 x [15 x %struct.TextureLevel]] }
+ %struct.Transform = type <{ [24 x [16 x float]], [24 x [16 x float]], [16 x float], float, float, float, float, float, i8, i8, i8, i8, i32, i32, i32, i16, i16, i8, i8, i8, i8, i32 }>
+ %struct.TransformFeedback = type { i8, i8, i8, i8, [0 x i32], [16 x i32], [16 x i32] }
+ %struct.Viewport = type { float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, double, double, i32, i32, i32, i32, float, float, float, float }
+ %struct.IColor4 = type { float, float, float, float }
+ %struct.TCoord2 = type { float, float }
+ %struct.VMGPStack = type { [6 x <4 x float>*], <4 x float>*, i32, i32, <4 x float>*, <4 x float>**, i32, i32, i32, i32, i32, i32 }
+ %struct.VMTextures = type { [16 x %struct.TextureRec*] }
+ %struct.PPStreamToken = type { { i16, i16, i32 } }
+ %struct._VMConstants = type { <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, <4 x float>, float, float, float, float, float, float, float, float, float, float, float, float, [256 x float], [528 x i8], { void (i8*, i8*, i32, i8*)*, float (float)*, float (float)*, float (float)*, i32 (float)* } }
+
+define i32 @foo(%struct.State* %dst, <4 x float>* %prgrm, <4 x float>** %buffs, %struct._VMConstants* %cnstn, %struct.PPStreamToken* %pstrm, %struct.PluginBufferData* %gpctx, %struct.VMTextures* %txtrs, %struct.VMGPStack* %gpstk) nounwind {
+bb266.i:
+ getelementptr <4 x float>* null, i32 11 ; <<4 x float>*>:0 [#uses=1]
+ load <4 x float>* %0, align 16 ; <<4 x float>>:1 [#uses=1]
+ shufflevector <4 x float> %1, <4 x float> undef, <4 x i32> < i32 0, i32 1, i32 1, i32 1 > ; <<4 x float>>:2 [#uses=1]
+ shufflevector <4 x float> %2, <4 x float> undef, <4 x i32> < i32 0, i32 4, i32 1, i32 5 > ; <<4 x float>>:3 [#uses=1]
+ shufflevector <4 x float> undef, <4 x float> undef, <4 x i32> < i32 0, i32 4, i32 1, i32 5 > ; <<4 x float>>:4 [#uses=1]
+ shufflevector <4 x float> %4, <4 x float> %3, <4 x i32> < i32 6, i32 7, i32 2, i32 3 > ; <<4 x float>>:5 [#uses=1]
+ fmul <4 x float> %5, zeroinitializer ; <<4 x float>>:6 [#uses=2]
+ fmul <4 x float> %6, %6 ; <<4 x float>>:7 [#uses=1]
+ fadd <4 x float> zeroinitializer, %7 ; <<4 x float>>:8 [#uses=1]
+ call <4 x float> @llvm.x86.sse.max.ps( <4 x float> zeroinitializer, <4 x float> %8 ) nounwind readnone ; <<4 x float>>:9 [#uses=1]
+ %phitmp40 = bitcast <4 x float> %9 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %tmp4109.i = and <4 x i32> %phitmp40, < i32 8388607, i32 8388607, i32 8388607, i32 8388607 > ; <<4 x i32>> [#uses=1]
+ %tmp4116.i = or <4 x i32> %tmp4109.i, < i32 1065353216, i32 1065353216, i32 1065353216, i32 1065353216 > ; <<4 x i32>> [#uses=1]
+ %tmp4117.i = bitcast <4 x i32> %tmp4116.i to <4 x float> ; <<4 x float>> [#uses=1]
+ fadd <4 x float> %tmp4117.i, zeroinitializer ; <<4 x float>>:10 [#uses=1]
+ fmul <4 x float> %10, < float 5.000000e-01, float 5.000000e-01, float 5.000000e-01, float 5.000000e-01 > ; <<4 x float>>:11 [#uses=1]
+ call <4 x float> @llvm.x86.sse.max.ps( <4 x float> %11, <4 x float> zeroinitializer ) nounwind readnone ; <<4 x float>>:12 [#uses=1]
+ call <4 x float> @llvm.x86.sse.min.ps( <4 x float> %12, <4 x float> zeroinitializer ) nounwind readnone ; <<4 x float>>:13 [#uses=1]
+ %tmp4170.i = call <4 x float> @llvm.x86.sse.cmp.ps( <4 x float> %13, <4 x float> zeroinitializer, i8 2 ) nounwind ; <<4 x float>> [#uses=1]
+ bitcast <4 x float> %tmp4170.i to <16 x i8> ; <<16 x i8>>:14 [#uses=1]
+ call i32 @llvm.x86.sse2.pmovmskb.128( <16 x i8> %14 ) nounwind readnone ; <i32>:15 [#uses=1]
+ icmp eq i32 %15, 0 ; <i1>:16 [#uses=1]
+ br i1 %16, label %bb5574.i, label %bb4521.i
+
+bb4521.i: ; preds = %bb266.i
+ unreachable
+
+bb5574.i: ; preds = %bb266.i
+ unreachable
+}
+
+declare <4 x float> @llvm.x86.sse.cmp.ps(<4 x float>, <4 x float>, i8) nounwind readnone
+
+declare i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8>) nounwind readnone
+
+declare <4 x float> @llvm.x86.sse.max.ps(<4 x float>, <4 x float>) nounwind readnone
+
+declare <4 x float> @llvm.x86.sse.min.ps(<4 x float>, <4 x float>) nounwind readnone
diff --git a/src/LLVM/test/Transforms/InstCombine/shufflevec-constant.ll b/src/LLVM/test/Transforms/InstCombine/shufflevec-constant.ll
new file mode 100644
index 0000000..29ae5a7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/shufflevec-constant.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep {ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0x7FF0000000000000, float 0x7FF0000000000000>}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9"
+
+define <4 x float> @__inff4() nounwind readnone {
+entry:
+ %tmp14 = extractelement <1 x double> bitcast (<2 x float> <float 0x7FF0000000000000, float 0x7FF0000000000000> to <1 x double>), i32 0 ; <double> [#uses=1]
+ %tmp4 = bitcast double %tmp14 to i64 ; <i64> [#uses=1]
+ %tmp3 = bitcast i64 %tmp4 to <2 x float> ; <<2 x float>> [#uses=1]
+ %tmp8 = shufflevector <2 x float> %tmp3, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef> ; <<4 x float>> [#uses=1]
+ %tmp9 = shufflevector <4 x float> zeroinitializer, <4 x float> %tmp8, <4 x i32> <i32 0, i32 1, i32 4, i32 5> ; <<4 x float>> [#uses=0]
+ ret <4 x float> %tmp9
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sign-test-and-or.ll b/src/LLVM/test/Transforms/InstCombine/sign-test-and-or.ll
new file mode 100644
index 0000000..47f5f30
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sign-test-and-or.ll
@@ -0,0 +1,79 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+declare void @foo()
+
+define void @test1(i32 %a, i32 %b) nounwind {
+ %1 = icmp slt i32 %a, 0
+ %2 = icmp slt i32 %b, 0
+ %or.cond = or i1 %1, %2
+ br i1 %or.cond, label %if.then, label %if.end
+
+; CHECK: @test1
+; CHECK-NEXT: %1 = or i32 %a, %b
+; CHECK-NEXT: %2 = icmp slt i32 %1, 0
+; CHECK-NEXT: br
+
+if.then:
+ tail call void @foo() nounwind
+ ret void
+
+if.end:
+ ret void
+}
+
+define void @test2(i32 %a, i32 %b) nounwind {
+ %1 = icmp sgt i32 %a, -1
+ %2 = icmp sgt i32 %b, -1
+ %or.cond = or i1 %1, %2
+ br i1 %or.cond, label %if.then, label %if.end
+
+; CHECK: @test2
+; CHECK-NEXT: %1 = and i32 %a, %b
+; CHECK-NEXT: %2 = icmp sgt i32 %1, -1
+; CHECK-NEXT: br
+
+if.then:
+ tail call void @foo() nounwind
+ ret void
+
+if.end:
+ ret void
+}
+
+define void @test3(i32 %a, i32 %b) nounwind {
+ %1 = icmp slt i32 %a, 0
+ %2 = icmp slt i32 %b, 0
+ %or.cond = and i1 %1, %2
+ br i1 %or.cond, label %if.then, label %if.end
+
+; CHECK: @test3
+; CHECK-NEXT: %1 = and i32 %a, %b
+; CHECK-NEXT: %2 = icmp slt i32 %1, 0
+; CHECK-NEXT: br
+
+if.then:
+ tail call void @foo() nounwind
+ ret void
+
+if.end:
+ ret void
+}
+
+define void @test4(i32 %a, i32 %b) nounwind {
+ %1 = icmp sgt i32 %a, -1
+ %2 = icmp sgt i32 %b, -1
+ %or.cond = and i1 %1, %2
+ br i1 %or.cond, label %if.then, label %if.end
+
+; CHECK: @test4
+; CHECK-NEXT: %1 = or i32 %a, %b
+; CHECK-NEXT: %2 = icmp sgt i32 %1, -1
+; CHECK-NEXT: br
+
+if.then:
+ tail call void @foo() nounwind
+ ret void
+
+if.end:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/signed-comparison.ll b/src/LLVM/test/Transforms/InstCombine/signed-comparison.ll
new file mode 100644
index 0000000..9a08c64
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/signed-comparison.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -instcombine -S > %t
+; RUN: not grep zext %t
+; RUN: not grep slt %t
+; RUN: grep {icmp ult} %t
+
+; Instcombine should convert the zext+slt into a simple ult.
+
+define void @foo(double* %p) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %bb ]
+ %t0 = and i64 %indvar, 65535
+ %t1 = getelementptr double* %p, i64 %t0
+ %t2 = load double* %t1, align 8
+ %t3 = fmul double %t2, 2.2
+ store double %t3, double* %t1, align 8
+ %i.04 = trunc i64 %indvar to i16
+ %t4 = add i16 %i.04, 1
+ %t5 = zext i16 %t4 to i32
+ %t6 = icmp slt i32 %t5, 500
+ %indvar.next = add i64 %indvar, 1
+ br i1 %t6, label %bb, label %return
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/signext.ll b/src/LLVM/test/Transforms/InstCombine/signext.ll
new file mode 100644
index 0000000..b841533
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/signext.ll
@@ -0,0 +1,87 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128:n8:16:32:64"
+
+define i32 @test1(i32 %x) {
+ %tmp.1 = and i32 %x, 65535 ; <i32> [#uses=1]
+ %tmp.2 = xor i32 %tmp.1, -32768 ; <i32> [#uses=1]
+ %tmp.3 = add i32 %tmp.2, 32768 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+; CHECK: @test1
+; CHECK: %sext = shl i32 %x, 16
+; CHECK: %tmp.3 = ashr exact i32 %sext, 16
+; CHECK: ret i32 %tmp.3
+}
+
+define i32 @test2(i32 %x) {
+ %tmp.1 = and i32 %x, 65535 ; <i32> [#uses=1]
+ %tmp.2 = xor i32 %tmp.1, 32768 ; <i32> [#uses=1]
+ %tmp.3 = add i32 %tmp.2, -32768 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+; CHECK: @test2
+; CHECK: %sext = shl i32 %x, 16
+; CHECK: %tmp.3 = ashr exact i32 %sext, 16
+; CHECK: ret i32 %tmp.3
+}
+
+define i32 @test3(i16 %P) {
+ %tmp.1 = zext i16 %P to i32 ; <i32> [#uses=1]
+ %tmp.4 = xor i32 %tmp.1, 32768 ; <i32> [#uses=1]
+ %tmp.5 = add i32 %tmp.4, -32768 ; <i32> [#uses=1]
+ ret i32 %tmp.5
+; CHECK: @test3
+; CHECK: %tmp.5 = sext i16 %P to i32
+; CHECK: ret i32 %tmp.5
+}
+
+define i32 @test4(i16 %P) {
+ %tmp.1 = zext i16 %P to i32 ; <i32> [#uses=1]
+ %tmp.4 = xor i32 %tmp.1, 32768 ; <i32> [#uses=1]
+ %tmp.5 = add i32 %tmp.4, -32768 ; <i32> [#uses=1]
+ ret i32 %tmp.5
+; CHECK: @test4
+; CHECK: %tmp.5 = sext i16 %P to i32
+; CHECK: ret i32 %tmp.5
+}
+
+define i32 @test5(i32 %x) {
+ %tmp.1 = and i32 %x, 255 ; <i32> [#uses=1]
+ %tmp.2 = xor i32 %tmp.1, 128 ; <i32> [#uses=1]
+ %tmp.3 = add i32 %tmp.2, -128 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+; CHECK: @test5
+; CHECK: %sext = shl i32 %x, 24
+; CHECK: %tmp.3 = ashr exact i32 %sext, 24
+; CHECK: ret i32 %tmp.3
+}
+
+define i32 @test6(i32 %x) {
+ %tmp.2 = shl i32 %x, 16 ; <i32> [#uses=1]
+ %tmp.4 = ashr i32 %tmp.2, 16 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+; CHECK: @test6
+; CHECK: %tmp.2 = shl i32 %x, 16
+; CHECK: %tmp.4 = ashr exact i32 %tmp.2, 16
+; CHECK: ret i32 %tmp.4
+}
+
+define i32 @test7(i16 %P) {
+ %tmp.1 = zext i16 %P to i32 ; <i32> [#uses=1]
+ %sext1 = shl i32 %tmp.1, 16 ; <i32> [#uses=1]
+ %tmp.5 = ashr i32 %sext1, 16 ; <i32> [#uses=1]
+ ret i32 %tmp.5
+; CHECK: @test7
+; CHECK: %tmp.5 = sext i16 %P to i32
+; CHECK: ret i32 %tmp.5
+}
+
+define i32 @test8(i32 %x) nounwind readnone {
+entry:
+ %shr = lshr i32 %x, 5 ; <i32> [#uses=1]
+ %xor = xor i32 %shr, 67108864 ; <i32> [#uses=1]
+ %sub = add i32 %xor, -67108864 ; <i32> [#uses=1]
+ ret i32 %sub
+; CHECK: @test8
+; CHECK: %shr = ashr i32 %x, 5
+; CHECK: ret i32 %shr
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/simplify-demanded-bits-pointer.ll b/src/LLVM/test/Transforms/InstCombine/simplify-demanded-bits-pointer.ll
new file mode 100644
index 0000000..6d2193f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/simplify-demanded-bits-pointer.ll
@@ -0,0 +1,84 @@
+; RUN: opt < %s -instcombine -disable-output
+
+; SimplifyDemandedBits should cope with pointer types.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.VEC_rtx_base = type { i32, i32, [1 x %struct.rtx_def*] }
+ %struct.VEC_rtx_gc = type { %struct.VEC_rtx_base }
+ %struct.block_symbol = type { [3 x %struct.rtunion], %struct.object_block*, i64 }
+ %struct.object_block = type { %struct.section*, i32, i64, %struct.VEC_rtx_gc*, %struct.VEC_rtx_gc* }
+ %struct.omp_clause_subcode = type { i32 }
+ %struct.rtunion = type { i8* }
+ %struct.rtx_def = type { i16, i8, i8, %struct.u }
+ %struct.section = type { %struct.unnamed_section }
+ %struct.u = type { %struct.block_symbol }
+ %struct.unnamed_section = type { %struct.omp_clause_subcode, void (i8*)*, i8*, %struct.section* }
+
+define fastcc void @cse_insn(%struct.rtx_def* %insn, %struct.rtx_def* %libcall_insn) nounwind {
+entry:
+ br i1 undef, label %bb43, label %bb88
+
+bb43: ; preds = %entry
+ br label %bb88
+
+bb88: ; preds = %bb43, %entry
+ br i1 undef, label %bb95, label %bb107
+
+bb95: ; preds = %bb88
+ unreachable
+
+bb107: ; preds = %bb88
+ %0 = load i16* undef, align 8 ; <i16> [#uses=1]
+ %1 = icmp eq i16 %0, 38 ; <i1> [#uses=1]
+ %src_eqv_here.0 = select i1 %1, %struct.rtx_def* null, %struct.rtx_def* null ; <%struct.rtx_def*> [#uses=1]
+ br i1 undef, label %bb127, label %bb125
+
+bb125: ; preds = %bb107
+ br i1 undef, label %bb127, label %bb126
+
+bb126: ; preds = %bb125
+ br i1 undef, label %bb129, label %bb133
+
+bb127: ; preds = %bb125, %bb107
+ unreachable
+
+bb129: ; preds = %bb126
+ br label %bb133
+
+bb133: ; preds = %bb129, %bb126
+ br i1 undef, label %bb134, label %bb146
+
+bb134: ; preds = %bb133
+ unreachable
+
+bb146: ; preds = %bb133
+ br i1 undef, label %bb180, label %bb186
+
+bb180: ; preds = %bb146
+ %2 = icmp eq %struct.rtx_def* null, null ; <i1> [#uses=1]
+ %3 = zext i1 %2 to i8 ; <i8> [#uses=1]
+ %4 = icmp ne %struct.rtx_def* %src_eqv_here.0, null ; <i1> [#uses=1]
+ %5 = zext i1 %4 to i8 ; <i8> [#uses=1]
+ %toBool181 = icmp ne i8 %3, 0 ; <i1> [#uses=1]
+ %toBool182 = icmp ne i8 %5, 0 ; <i1> [#uses=1]
+ %6 = and i1 %toBool181, %toBool182 ; <i1> [#uses=1]
+ %7 = zext i1 %6 to i8 ; <i8> [#uses=1]
+ %toBool183 = icmp ne i8 %7, 0 ; <i1> [#uses=1]
+ br i1 %toBool183, label %bb184, label %bb186
+
+bb184: ; preds = %bb180
+ br i1 undef, label %bb185, label %bb186
+
+bb185: ; preds = %bb184
+ br label %bb186
+
+bb186: ; preds = %bb185, %bb184, %bb180, %bb146
+ br i1 undef, label %bb190, label %bb195
+
+bb190: ; preds = %bb186
+ unreachable
+
+bb195: ; preds = %bb186
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/sink_instruction.ll b/src/LLVM/test/Transforms/InstCombine/sink_instruction.ll
new file mode 100644
index 0000000..29d202a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sink_instruction.ll
@@ -0,0 +1,56 @@
+; RUN: opt -instcombine %s -S | FileCheck %s
+
+;; This tests that the instructions in the entry blocks are sunk into each
+;; arm of the 'if'.
+
+define i32 @test1(i1 %C, i32 %A, i32 %B) {
+; CHECK: @test1
+entry:
+ %tmp.2 = sdiv i32 %A, %B ; <i32> [#uses=1]
+ %tmp.9 = add i32 %B, %A ; <i32> [#uses=1]
+ br i1 %C, label %then, label %endif
+
+then: ; preds = %entry
+ ret i32 %tmp.9
+
+endif: ; preds = %entry
+; CHECK: sdiv i32
+; CHECK-NEXT: ret i32
+ ret i32 %tmp.2
+}
+
+
+;; PHI use, sink divide before call.
+define i32 @test2(i32 %x) nounwind ssp {
+; CHECK: @test2
+; CHECK-NOT: sdiv i32
+entry:
+ br label %bb
+
+bb: ; preds = %bb2, %entry
+ %x_addr.17 = phi i32 [ %x, %entry ], [ %x_addr.0, %bb2 ] ; <i32> [#uses=4]
+ %i.06 = phi i32 [ 0, %entry ], [ %4, %bb2 ] ; <i32> [#uses=1]
+ %0 = add nsw i32 %x_addr.17, 1 ; <i32> [#uses=1]
+ %1 = sdiv i32 %0, %x_addr.17 ; <i32> [#uses=1]
+ %2 = icmp eq i32 %x_addr.17, 0 ; <i1> [#uses=1]
+ br i1 %2, label %bb1, label %bb2
+
+bb1: ; preds = %bb
+; CHECK: bb1:
+; CHECK-NEXT: add nsw i32 %x_addr.17, 1
+; CHECK-NEXT: sdiv i32
+; CHECK-NEXT: tail call i32 @bar()
+ %3 = tail call i32 @bar() nounwind ; <i32> [#uses=0]
+ br label %bb2
+
+bb2: ; preds = %bb, %bb1
+ %x_addr.0 = phi i32 [ %1, %bb1 ], [ %x_addr.17, %bb ] ; <i32> [#uses=2]
+ %4 = add nsw i32 %i.06, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %4, 1000000 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb4, label %bb
+
+bb4: ; preds = %bb2
+ ret i32 %x_addr.0
+}
+
+declare i32 @bar()
diff --git a/src/LLVM/test/Transforms/InstCombine/sitofp.ll b/src/LLVM/test/Transforms/InstCombine/sitofp.ll
new file mode 100644
index 0000000..bd31b89
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sitofp.ll
@@ -0,0 +1,55 @@
+; RUN: opt < %s -instcombine -S | not grep itofp
+
+define i1 @test1(i8 %A) {
+ %B = sitofp i8 %A to double
+ %C = fcmp ult double %B, 128.0
+ ret i1 %C ; True!
+}
+define i1 @test2(i8 %A) {
+ %B = sitofp i8 %A to double
+ %C = fcmp ugt double %B, -128.1
+ ret i1 %C ; True!
+}
+
+define i1 @test3(i8 %A) {
+ %B = sitofp i8 %A to double
+ %C = fcmp ule double %B, 127.0
+ ret i1 %C ; true!
+}
+
+define i1 @test4(i8 %A) {
+ %B = sitofp i8 %A to double
+ %C = fcmp ult double %B, 127.0
+ ret i1 %C ; A != 127
+}
+
+define i32 @test5(i32 %A) {
+ %B = sitofp i32 %A to double
+ %C = fptosi double %B to i32
+ %D = uitofp i32 %C to double
+ %E = fptoui double %D to i32
+ ret i32 %E
+}
+
+define i32 @test6(i32 %A) {
+ %B = and i32 %A, 7 ; <i32> [#uses=1]
+ %C = and i32 %A, 32 ; <i32> [#uses=1]
+ %D = sitofp i32 %B to double ; <double> [#uses=1]
+ %E = sitofp i32 %C to double ; <double> [#uses=1]
+ %F = fadd double %D, %E ; <double> [#uses=1]
+ %G = fptosi double %F to i32 ; <i32> [#uses=1]
+ ret i32 %G
+}
+
+define i32 @test7(i32 %a) nounwind {
+ %b = sitofp i32 %a to double ; <double> [#uses=1]
+ %c = fptoui double %b to i32 ; <i32> [#uses=1]
+ ret i32 %c
+}
+
+define i32 @test8(i32 %a) nounwind {
+ %b = uitofp i32 %a to double ; <double> [#uses=1]
+ %c = fptosi double %b to i32 ; <i32> [#uses=1]
+ ret i32 %c
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/sqrt.ll b/src/LLVM/test/Transforms/InstCombine/sqrt.ll
new file mode 100644
index 0000000..cc78417
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sqrt.ll
@@ -0,0 +1,54 @@
+; RUN: opt -S -instcombine %s | FileCheck %s
+
+define float @test1(float %x) nounwind readnone ssp {
+entry:
+; CHECK: @test1
+; CHECK-NOT: fpext
+; CHECK-NOT: sqrt(
+; CHECK: sqrtf(
+; CHECK-NOT: fptrunc
+ %conv = fpext float %x to double ; <double> [#uses=1]
+ %call = tail call double @sqrt(double %conv) readnone nounwind ; <double> [#uses=1]
+ %conv1 = fptrunc double %call to float ; <float> [#uses=1]
+; CHECK: ret float
+ ret float %conv1
+}
+
+; PR8096
+define float @test2(float %x) nounwind readnone ssp {
+entry:
+; CHECK: @test2
+; CHECK-NOT: fpext
+; CHECK-NOT: sqrt(
+; CHECK: sqrtf(
+; CHECK-NOT: fptrunc
+ %conv = fpext float %x to double ; <double> [#uses=1]
+ %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1]
+ %conv1 = fptrunc double %call to float ; <float> [#uses=1]
+; CHECK: ret float
+ ret float %conv1
+}
+
+; rdar://9763193
+; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another
+; use of sqrt result.
+define float @test3(float* %v) nounwind uwtable ssp {
+entry:
+; CHECK: @test3
+; CHECK: sqrt(
+; CHECK-NOT: sqrtf(
+; CHECK: fptrunc
+ %arrayidx13 = getelementptr inbounds float* %v, i64 2
+ %tmp14 = load float* %arrayidx13
+ %mul18 = fmul float %tmp14, %tmp14
+ %add19 = fadd float undef, %mul18
+ %conv = fpext float %add19 to double
+ %call34 = call double @sqrt(double %conv) readnone
+ %call36 = call i32 (double)* @foo(double %call34) nounwind
+ %conv38 = fptrunc double %call34 to float
+ ret float %conv38
+}
+
+declare i32 @foo(double)
+
+declare double @sqrt(double) readnone
diff --git a/src/LLVM/test/Transforms/InstCombine/srem-simplify-bug.ll b/src/LLVM/test/Transforms/InstCombine/srem-simplify-bug.ll
new file mode 100644
index 0000000..af824a4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/srem-simplify-bug.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {ret i1 false}
+; PR2276
+
+define i1 @f(i32 %x) {
+ %A = or i32 %x, 1
+ %B = srem i32 %A, 1
+ %C = icmp ne i32 %B, 0
+ ret i1 %C
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/srem.ll b/src/LLVM/test/Transforms/InstCombine/srem.ll
new file mode 100644
index 0000000..beefe4f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/srem.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep srem
+
+define i64 @foo(i64 %x1, i64 %y2) {
+ %r = sdiv i64 %x1, %y2
+ %r7 = mul i64 %r, %y2
+ %r8 = sub i64 %x1, %r7
+ ret i64 %r8
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/srem1.ll b/src/LLVM/test/Transforms/InstCombine/srem1.ll
new file mode 100644
index 0000000..f18690c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/srem1.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine
+; PR2670
+
+@g_127 = external global i32 ; <i32*> [#uses=1]
+
+define i32 @func_56(i32 %p_58, i32 %p_59, i32 %p_61, i16 signext %p_62) nounwind {
+entry:
+ %call = call i32 (...)* @rshift_s_s( i32 %p_61, i32 1 ) ; <i32> [#uses=1]
+ %conv = sext i32 %call to i64 ; <i64> [#uses=1]
+ %or = or i64 -1734012817166602727, %conv ; <i64> [#uses=1]
+ %rem = srem i64 %or, 1 ; <i64> [#uses=1]
+ %cmp = icmp eq i64 %rem, 1 ; <i1> [#uses=1]
+ %cmp.ext = zext i1 %cmp to i32 ; <i32> [#uses=1]
+ store i32 %cmp.ext, i32* @g_127
+ ret i32 undef
+}
+
+declare i32 @rshift_s_s(...)
diff --git a/src/LLVM/test/Transforms/InstCombine/stack-overalign.ll b/src/LLVM/test/Transforms/InstCombine/stack-overalign.ll
new file mode 100644
index 0000000..2fc8414
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/stack-overalign.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instcombine -S | grep {align 32} | count 1
+
+; It's tempting to have an instcombine in which the src pointer of a
+; memcpy is aligned up to the alignment of the destination, however
+; there are pitfalls. If the src is an alloca, aligning it beyond what
+; the target's stack pointer is aligned at will require dynamic
+; stack realignment, which can require functions that don't otherwise
+; need a frame pointer to need one.
+;
+; Abstaining from this transform is not the only way to approach this
+; issue. Some late phase could be smart enough to reduce alloca
+; alignments when they are greater than they need to be. Or, codegen
+; could do dynamic alignment for just the one alloca, and leave the
+; main stack pointer at its standard alignment.
+
+@dst = global [1024 x i8] zeroinitializer, align 32
+
+define void @foo() nounwind {
+entry:
+ %src = alloca [1024 x i8], align 1
+ %src1 = getelementptr [1024 x i8]* %src, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* getelementptr inbounds ([1024 x i8]* @dst, i32 0, i32 0), i8* %src1, i32 1024, i32 1, i1 false)
+ call void @frob(i8* %src1) nounwind
+ ret void
+}
+
+declare void @frob(i8*)
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/stacksaverestore.ll b/src/LLVM/test/Transforms/InstCombine/stacksaverestore.ll
new file mode 100644
index 0000000..4396f8e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/stacksaverestore.ll
@@ -0,0 +1,56 @@
+; RUN: opt < %s -instcombine -S | grep {call.*stackrestore} | count 1
+
+declare i8* @llvm.stacksave()
+declare void @llvm.stackrestore(i8*)
+
+;; Test that llvm.stackrestore is removed when possible.
+define i32* @test1(i32 %P) {
+ %tmp = call i8* @llvm.stacksave( )
+ call void @llvm.stackrestore( i8* %tmp ) ;; not restoring anything
+ %A = alloca i32, i32 %P
+ ret i32* %A
+}
+
+define void @test2(i8* %X) {
+ call void @llvm.stackrestore( i8* %X ) ;; no allocas before return.
+ ret void
+}
+
+define void @foo(i32 %size) nounwind {
+entry:
+ %tmp118124 = icmp sgt i32 %size, 0 ; <i1> [#uses=1]
+ br i1 %tmp118124, label %bb.preheader, label %return
+
+bb.preheader: ; preds = %entry
+ %tmp25 = add i32 %size, -1 ; <i32> [#uses=1]
+ %tmp125 = icmp slt i32 %size, 1 ; <i1> [#uses=1]
+ %smax = select i1 %tmp125, i32 1, i32 %size ; <i32> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.preheader
+ %i.0.reg2mem.0 = phi i32 [ 0, %bb.preheader ], [ %indvar.next, %bb ] ; <i32> [#uses=2]
+ %tmp = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp23 = alloca i8, i32 %size ; <i8*> [#uses=2]
+ %tmp27 = getelementptr i8* %tmp23, i32 %tmp25 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp27, align 1
+ %tmp28 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp52 = alloca i8, i32 %size ; <i8*> [#uses=1]
+ %tmp53 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp77 = alloca i8, i32 %size ; <i8*> [#uses=1]
+ %tmp78 = call i8* @llvm.stacksave( ) ; <i8*> [#uses=1]
+ %tmp102 = alloca i8, i32 %size ; <i8*> [#uses=1]
+ call void @bar( i32 %i.0.reg2mem.0, i8* %tmp23, i8* %tmp52, i8* %tmp77, i8* %tmp102, i32 %size ) nounwind
+ call void @llvm.stackrestore( i8* %tmp78 )
+ call void @llvm.stackrestore( i8* %tmp53 )
+ call void @llvm.stackrestore( i8* %tmp28 )
+ call void @llvm.stackrestore( i8* %tmp )
+ %indvar.next = add i32 %i.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, %smax ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %bb
+
+return: ; preds = %bb, %entry
+ ret void
+}
+
+declare void @bar(i32, i8*, i8*, i8*, i8*, i32)
+
diff --git a/src/LLVM/test/Transforms/InstCombine/store.ll b/src/LLVM/test/Transforms/InstCombine/store.ll
new file mode 100644
index 0000000..bff57c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/store.ll
@@ -0,0 +1,85 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define void @test1(i32* %P) {
+ store i32 undef, i32* %P
+ store i32 123, i32* undef
+ store i32 124, i32* null
+ ret void
+; CHECK: @test1(
+; CHECK-NEXT: store i32 123, i32* undef
+; CHECK-NEXT: store i32 undef, i32* null
+; CHECK-NEXT: ret void
+}
+
+define void @test2(i32* %P) {
+ %X = load i32* %P ; <i32> [#uses=1]
+ %Y = add i32 %X, 0 ; <i32> [#uses=1]
+ store i32 %Y, i32* %P
+ ret void
+; CHECK: @test2
+; CHECK-NEXT: ret void
+}
+
+;; Simple sinking tests
+
+; "if then else"
+define i32 @test3(i1 %C) {
+ %A = alloca i32
+ br i1 %C, label %Cond, label %Cond2
+
+Cond:
+ store i32 -987654321, i32* %A
+ br label %Cont
+
+Cond2:
+ store i32 47, i32* %A
+ br label %Cont
+
+Cont:
+ %V = load i32* %A
+ ret i32 %V
+; CHECK: @test3
+; CHECK-NOT: alloca
+; CHECK: Cont:
+; CHECK-NEXT: %storemerge = phi i32 [ 47, %Cond2 ], [ -987654321, %Cond ]
+; CHECK-NEXT: ret i32 %storemerge
+}
+
+; "if then"
+define i32 @test4(i1 %C) {
+ %A = alloca i32
+ store i32 47, i32* %A
+ br i1 %C, label %Cond, label %Cont
+
+Cond:
+ store i32 -987654321, i32* %A
+ br label %Cont
+
+Cont:
+ %V = load i32* %A
+ ret i32 %V
+; CHECK: @test4
+; CHECK-NOT: alloca
+; CHECK: Cont:
+; CHECK-NEXT: %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %0 ]
+; CHECK-NEXT: ret i32 %storemerge
+}
+
+; "if then"
+define void @test5(i1 %C, i32* %P) {
+ store i32 47, i32* %P, align 1
+ br i1 %C, label %Cond, label %Cont
+
+Cond:
+ store i32 -987654321, i32* %P, align 1
+ br label %Cont
+
+Cont:
+ ret void
+; CHECK: @test5
+; CHECK: Cont:
+; CHECK-NEXT: %storemerge = phi i32
+; CHECK-NEXT: store i32 %storemerge, i32* %P, align 1
+; CHECK-NEXT: ret void
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/strcpy_chk-64.ll b/src/LLVM/test/Transforms/InstCombine/strcpy_chk-64.ll
new file mode 100644
index 0000000..036fcbe
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/strcpy_chk-64.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define void @func(i8* %i) nounwind ssp {
+; CHECK: @func
+; CHECK: @__strcpy_chk(i8* %arraydecay, i8* %i, i64 32)
+entry:
+ %s = alloca [32 x i8], align 16
+ %arraydecay = getelementptr inbounds [32 x i8]* %s, i32 0, i32 0
+ %call = call i8* @__strcpy_chk(i8* %arraydecay, i8* %i, i64 32)
+ call void @func2(i8* %arraydecay)
+ ret void
+}
+
+declare i8* @__strcpy_chk(i8*, i8*, i64) nounwind
+
+declare void @func2(i8*)
diff --git a/src/LLVM/test/Transforms/InstCombine/strcpy_chk.ll b/src/LLVM/test/Transforms/InstCombine/strcpy_chk.ll
new file mode 100644
index 0000000..8835a0b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/strcpy_chk.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+@a = common global [60 x i8] zeroinitializer, align 1 ; <[60 x i8]*> [#uses=1]
+@.str = private constant [8 x i8] c"abcdefg\00" ; <[8 x i8]*> [#uses=1]
+
+define i8* @foo() nounwind {
+; CHECK: @foo
+; CHECK-NEXT: call i8* @strcpy
+ %call = call i8* @__strcpy_chk(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0), i32 60) ; <i8*> [#uses=1]
+ ret i8* %call
+}
+
+declare i8* @__strcpy_chk(i8*, i8*, i32) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/sub.ll b/src/LLVM/test/Transforms/InstCombine/sub.ll
new file mode 100644
index 0000000..6bc0d83
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/sub.ll
@@ -0,0 +1,303 @@
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+; Optimize subtracts.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @test1(i32 %A) {
+ %B = sub i32 %A, %A
+ ret i32 %B
+; CHECK: @test1
+; CHECK: ret i32 0
+}
+
+define i32 @test2(i32 %A) {
+ %B = sub i32 %A, 0
+ ret i32 %B
+; CHECK: @test2
+; CHECK: ret i32 %A
+}
+
+define i32 @test3(i32 %A) {
+ %B = sub i32 0, %A
+ %C = sub i32 0, %B
+ ret i32 %C
+; CHECK: @test3
+; CHECK: ret i32 %A
+}
+
+define i32 @test4(i32 %A, i32 %x) {
+ %B = sub i32 0, %A
+ %C = sub i32 %x, %B
+ ret i32 %C
+; CHECK: @test4
+; CHECK: %C = add i32 %x, %A
+; CHECK: ret i32 %C
+}
+
+define i32 @test5(i32 %A, i32 %B, i32 %C) {
+ %D = sub i32 %B, %C
+ %E = sub i32 %A, %D
+ ret i32 %E
+; CHECK: @test5
+; CHECK: %D1 = sub i32 %C, %B
+; CHECK: %E = add
+; CHECK: ret i32 %E
+}
+
+define i32 @test6(i32 %A, i32 %B) {
+ %C = and i32 %A, %B
+ %D = sub i32 %A, %C
+ ret i32 %D
+; CHECK: @test6
+; CHECK-NEXT: xor i32 %B, -1
+; CHECK-NEXT: %D = and i32
+; CHECK-NEXT: ret i32 %D
+}
+
+define i32 @test7(i32 %A) {
+ %B = sub i32 -1, %A
+ ret i32 %B
+; CHECK: @test7
+; CHECK: %B = xor i32 %A, -1
+; CHECK: ret i32 %B
+}
+
+define i32 @test8(i32 %A) {
+ %B = mul i32 9, %A
+ %C = sub i32 %B, %A
+ ret i32 %C
+; CHECK: @test8
+; CHECK: %C = shl i32 %A, 3
+; CHECK: ret i32 %C
+}
+
+define i32 @test9(i32 %A) {
+ %B = mul i32 3, %A
+ %C = sub i32 %A, %B
+ ret i32 %C
+; CHECK: @test9
+; CHECK: %C = mul i32 %A, -2
+; CHECK: ret i32 %C
+}
+
+define i32 @test10(i32 %A, i32 %B) {
+ %C = sub i32 0, %A
+ %D = sub i32 0, %B
+ %E = mul i32 %C, %D
+ ret i32 %E
+; CHECK: @test10
+; CHECK: %E = mul i32 %A, %B
+; CHECK: ret i32 %E
+}
+
+define i32 @test10a(i32 %A) {
+ %C = sub i32 0, %A
+ %E = mul i32 %C, 7
+ ret i32 %E
+; CHECK: @test10a
+; CHECK: %E = mul i32 %A, -7
+; CHECK: ret i32 %E
+}
+
+define i1 @test11(i8 %A, i8 %B) {
+ %C = sub i8 %A, %B
+ %cD = icmp ne i8 %C, 0
+ ret i1 %cD
+; CHECK: @test11
+; CHECK: %cD = icmp ne i8 %A, %B
+; CHECK: ret i1 %cD
+}
+
+define i32 @test12(i32 %A) {
+ %B = ashr i32 %A, 31
+ %C = sub i32 0, %B
+ ret i32 %C
+; CHECK: @test12
+; CHECK: %C = lshr i32 %A, 31
+; CHECK: ret i32 %C
+}
+
+define i32 @test13(i32 %A) {
+ %B = lshr i32 %A, 31
+ %C = sub i32 0, %B
+ ret i32 %C
+; CHECK: @test13
+; CHECK: %C = ashr i32 %A, 31
+; CHECK: ret i32 %C
+}
+
+define i32 @test14(i32 %A) {
+ %B = lshr i32 %A, 31
+ %C = bitcast i32 %B to i32
+ %D = sub i32 0, %C
+ ret i32 %D
+; CHECK: @test14
+; CHECK: %D = ashr i32 %A, 31
+; CHECK: ret i32 %D
+}
+
+define i32 @test15(i32 %A, i32 %B) {
+ %C = sub i32 0, %A
+ %D = srem i32 %B, %C
+ ret i32 %D
+; CHECK: @test15
+; CHECK: %D = srem i32 %B, %A
+; CHECK: ret i32 %D
+}
+
+define i32 @test16(i32 %A) {
+ %X = sdiv i32 %A, 1123
+ %Y = sub i32 0, %X
+ ret i32 %Y
+; CHECK: @test16
+; CHECK: %Y = sdiv i32 %A, -1123
+; CHECK: ret i32 %Y
+}
+
+; Can't fold subtract here because negation it might oveflow.
+; PR3142
+define i32 @test17(i32 %A) {
+ %B = sub i32 0, %A
+ %C = sdiv i32 %B, 1234
+ ret i32 %C
+; CHECK: @test17
+; CHECK: %B = sub i32 0, %A
+; CHECK: %C = sdiv i32 %B, 1234
+; CHECK: ret i32 %C
+}
+
+define i64 @test18(i64 %Y) {
+ %tmp.4 = shl i64 %Y, 2
+ %tmp.12 = shl i64 %Y, 2
+ %tmp.8 = sub i64 %tmp.4, %tmp.12
+ ret i64 %tmp.8
+; CHECK: @test18
+; CHECK: ret i64 0
+}
+
+define i32 @test19(i32 %X, i32 %Y) {
+ %Z = sub i32 %X, %Y
+ %Q = add i32 %Z, %Y
+ ret i32 %Q
+; CHECK: @test19
+; CHECK: ret i32 %X
+}
+
+define i1 @test20(i32 %g, i32 %h) {
+ %tmp.2 = sub i32 %g, %h
+ %tmp.4 = icmp ne i32 %tmp.2, %g
+ ret i1 %tmp.4
+; CHECK: @test20
+; CHECK: %tmp.4 = icmp ne i32 %h, 0
+; CHECK: ret i1 %tmp.4
+}
+
+define i1 @test21(i32 %g, i32 %h) {
+ %tmp.2 = sub i32 %g, %h
+ %tmp.4 = icmp ne i32 %tmp.2, %g
+ ret i1 %tmp.4
+; CHECK: @test21
+; CHECK: %tmp.4 = icmp ne i32 %h, 0
+; CHECK: ret i1 %tmp.4
+}
+
+; PR2298
+define zeroext i1 @test22(i32 %a, i32 %b) nounwind {
+ %tmp2 = sub i32 0, %a
+ %tmp4 = sub i32 0, %b
+ %tmp5 = icmp eq i32 %tmp2, %tmp4
+ ret i1 %tmp5
+; CHECK: @test22
+; CHECK: %tmp5 = icmp eq i32 %b, %a
+; CHECK: ret i1 %tmp5
+}
+
+; rdar://7362831
+define i32 @test23(i8* %P, i64 %A){
+ %B = getelementptr inbounds i8* %P, i64 %A
+ %C = ptrtoint i8* %B to i64
+ %D = trunc i64 %C to i32
+ %E = ptrtoint i8* %P to i64
+ %F = trunc i64 %E to i32
+ %G = sub i32 %D, %F
+ ret i32 %G
+; CHECK: @test23
+; CHECK-NEXT: = trunc i64 %A to i32
+; CHECK-NEXT: ret i32
+}
+
+define i64 @test24(i8* %P, i64 %A){
+ %B = getelementptr inbounds i8* %P, i64 %A
+ %C = ptrtoint i8* %B to i64
+ %E = ptrtoint i8* %P to i64
+ %G = sub i64 %C, %E
+ ret i64 %G
+; CHECK: @test24
+; CHECK-NEXT: ret i64 %A
+}
+
+define i64 @test24a(i8* %P, i64 %A){
+ %B = getelementptr inbounds i8* %P, i64 %A
+ %C = ptrtoint i8* %B to i64
+ %E = ptrtoint i8* %P to i64
+ %G = sub i64 %E, %C
+ ret i64 %G
+; CHECK: @test24a
+; CHECK-NEXT: sub i64 0, %A
+; CHECK-NEXT: ret i64
+}
+
+@Arr = external global [42 x i16]
+
+define i64 @test24b(i8* %P, i64 %A){
+ %B = getelementptr inbounds [42 x i16]* @Arr, i64 0, i64 %A
+ %C = ptrtoint i16* %B to i64
+ %G = sub i64 %C, ptrtoint ([42 x i16]* @Arr to i64)
+ ret i64 %G
+; CHECK: @test24b
+; CHECK-NEXT: shl nuw i64 %A, 1
+; CHECK-NEXT: ret i64
+}
+
+
+define i64 @test25(i8* %P, i64 %A){
+ %B = getelementptr inbounds [42 x i16]* @Arr, i64 0, i64 %A
+ %C = ptrtoint i16* %B to i64
+ %G = sub i64 %C, ptrtoint (i16* getelementptr ([42 x i16]* @Arr, i64 1, i64 0) to i64)
+ ret i64 %G
+; CHECK: @test25
+; CHECK-NEXT: shl nuw i64 %A, 1
+; CHECK-NEXT: add i64 {{.*}}, -84
+; CHECK-NEXT: ret i64
+}
+
+define i32 @test26(i32 %x) {
+ %shl = shl i32 3, %x
+ %neg = sub i32 0, %shl
+ ret i32 %neg
+; CHECK: @test26
+; CHECK-NEXT: shl i32 -3
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test27(i32 %x, i32 %y) {
+ %mul = mul i32 %y, -8
+ %sub = sub i32 %x, %mul
+ ret i32 %sub
+; CHECK: @test27
+; CHECK-NEXT: shl i32 %y, 3
+; CHECK-NEXT: add i32
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test28(i32 %x, i32 %y, i32 %z) {
+ %neg = sub i32 0, %z
+ %mul = mul i32 %neg, %y
+ %sub = sub i32 %x, %mul
+ ret i32 %sub
+; CHECK: @test28
+; CHECK-NEXT: mul i32 %z, %y
+; CHECK-NEXT: add i32
+; CHECK-NEXT: ret i32
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/trunc.ll b/src/LLVM/test/Transforms/InstCombine/trunc.ll
new file mode 100644
index 0000000..6ec342a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/trunc.ll
@@ -0,0 +1,119 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+; Instcombine should be able to eliminate all of these ext casts.
+
+declare void @use(i32)
+
+define i64 @test1(i64 %a) {
+ %b = trunc i64 %a to i32
+ %c = and i32 %b, 15
+ %d = zext i32 %c to i64
+ call void @use(i32 %b)
+ ret i64 %d
+; CHECK: @test1
+; CHECK: %d = and i64 %a, 15
+; CHECK: ret i64 %d
+}
+define i64 @test2(i64 %a) {
+ %b = trunc i64 %a to i32
+ %c = shl i32 %b, 4
+ %q = ashr i32 %c, 4
+ %d = sext i32 %q to i64
+ call void @use(i32 %b)
+ ret i64 %d
+; CHECK: @test2
+; CHECK: shl i64 %a, 36
+; CHECK: %d = ashr exact i64 {{.*}}, 36
+; CHECK: ret i64 %d
+}
+define i64 @test3(i64 %a) {
+ %b = trunc i64 %a to i32
+ %c = and i32 %b, 8
+ %d = zext i32 %c to i64
+ call void @use(i32 %b)
+ ret i64 %d
+; CHECK: @test3
+; CHECK: %d = and i64 %a, 8
+; CHECK: ret i64 %d
+}
+define i64 @test4(i64 %a) {
+ %b = trunc i64 %a to i32
+ %c = and i32 %b, 8
+ %x = xor i32 %c, 8
+ %d = zext i32 %x to i64
+ call void @use(i32 %b)
+ ret i64 %d
+; CHECK: @test4
+; CHECK: = and i64 %a, 8
+; CHECK: %d = xor i64 {{.*}}, 8
+; CHECK: ret i64 %d
+}
+
+define i32 @test5(i32 %A) {
+ %B = zext i32 %A to i128
+ %C = lshr i128 %B, 16
+ %D = trunc i128 %C to i32
+ ret i32 %D
+; CHECK: @test5
+; CHECK: %C = lshr i32 %A, 16
+; CHECK: ret i32 %C
+}
+
+define i32 @test6(i64 %A) {
+ %B = zext i64 %A to i128
+ %C = lshr i128 %B, 32
+ %D = trunc i128 %C to i32
+ ret i32 %D
+; CHECK: @test6
+; CHECK: %C = lshr i64 %A, 32
+; CHECK: %D = trunc i64 %C to i32
+; CHECK: ret i32 %D
+}
+
+define i92 @test7(i64 %A) {
+ %B = zext i64 %A to i128
+ %C = lshr i128 %B, 32
+ %D = trunc i128 %C to i92
+ ret i92 %D
+; CHECK: @test7
+; CHECK: %B = zext i64 %A to i92
+; CHECK: %C = lshr i92 %B, 32
+; CHECK: ret i92 %C
+}
+
+define i64 @test8(i32 %A, i32 %B) {
+ %tmp38 = zext i32 %A to i128
+ %tmp32 = zext i32 %B to i128
+ %tmp33 = shl i128 %tmp32, 32
+ %ins35 = or i128 %tmp33, %tmp38
+ %tmp42 = trunc i128 %ins35 to i64
+ ret i64 %tmp42
+; CHECK: @test8
+; CHECK: %tmp38 = zext i32 %A to i64
+; CHECK: %tmp32 = zext i32 %B to i64
+; CHECK: %tmp33 = shl nuw i64 %tmp32, 32
+; CHECK: %ins35 = or i64 %tmp33, %tmp38
+; CHECK: ret i64 %ins35
+}
+
+define i8 @test9(i32 %X) {
+ %Y = and i32 %X, 42
+ %Z = trunc i32 %Y to i8
+ ret i8 %Z
+; CHECK: @test9
+; CHECK: trunc
+; CHECK: and
+; CHECK: ret
+}
+
+; rdar://8808586
+define i8 @test10(i32 %X) {
+ %Y = trunc i32 %X to i8
+ %Z = and i8 %Y, 42
+ ret i8 %Z
+; CHECK: @test10
+; CHECK: trunc
+; CHECK: and
+; CHECK: ret
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-0.ll b/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-0.ll
new file mode 100644
index 0000000..bfdd98c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-0.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep {ret i64 0} | count 2
+
+define i64 @foo(i32 %x) nounwind {
+ %y = lshr i32 %x, 1
+ %r = udiv i32 %y, -1
+ %z = sext i32 %r to i64
+ ret i64 %z
+}
+define i64 @bar(i32 %x) nounwind {
+ %y = lshr i32 %x, 31
+ %r = udiv i32 %y, 3
+ %z = sext i32 %r to i64
+ ret i64 %z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-1.ll b/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-1.ll
new file mode 100644
index 0000000..d95e8f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/udiv-simplify-bug-1.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S > %t1.ll
+; RUN: grep udiv %t1.ll | count 2
+; RUN: grep zext %t1.ll | count 2
+; PR2274
+
+; The udiv instructions shouldn't be optimized away, and the
+; sext instructions should be optimized to zext.
+
+define i64 @bar(i32 %x) nounwind {
+ %y = lshr i32 %x, 30
+ %r = udiv i32 %y, 3
+ %z = sext i32 %r to i64
+ ret i64 %z
+}
+define i64 @qux(i32 %x, i32 %v) nounwind {
+ %y = lshr i32 %x, 31
+ %r = udiv i32 %y, %v
+ %z = sext i32 %r to i64
+ ret i64 %z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/udiv_select_to_select_shift.ll b/src/LLVM/test/Transforms/InstCombine/udiv_select_to_select_shift.ll
new file mode 100644
index 0000000..34ff8bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/udiv_select_to_select_shift.ll
@@ -0,0 +1,17 @@
+; Test that this transform works:
+; udiv X, (Select Cond, C1, C2) --> Select Cond, (shr X, C1), (shr X, C2)
+;
+; RUN: opt < %s -instcombine -S -o %t
+; RUN: not grep select %t
+; RUN: grep lshr %t | count 2
+; RUN: not grep udiv %t
+
+define i64 @test(i64 %X, i1 %Cond ) {
+entry:
+ %divisor1 = select i1 %Cond, i64 16, i64 8
+ %quotient1 = udiv i64 %X, %divisor1
+ %divisor2 = select i1 %Cond, i64 8, i64 0
+ %quotient2 = udiv i64 %X, %divisor2
+ %sum = add i64 %quotient1, %quotient2
+ ret i64 %sum
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/udivrem-change-width.ll b/src/LLVM/test/Transforms/InstCombine/udivrem-change-width.ll
new file mode 100644
index 0000000..b388a3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/udivrem-change-width.ll
@@ -0,0 +1,62 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+; PR4548
+define i8 @udiv_i8(i8 %a, i8 %b) nounwind {
+ %conv = zext i8 %a to i32
+ %conv2 = zext i8 %b to i32
+ %div = udiv i32 %conv, %conv2
+ %conv3 = trunc i32 %div to i8
+ ret i8 %conv3
+; CHECK: @udiv_i8
+; CHECK: udiv i8 %a, %b
+}
+
+define i8 @urem_i8(i8 %a, i8 %b) nounwind {
+ %conv = zext i8 %a to i32
+ %conv2 = zext i8 %b to i32
+ %div = urem i32 %conv, %conv2
+ %conv3 = trunc i32 %div to i8
+ ret i8 %conv3
+; CHECK: @urem_i8
+; CHECK: urem i8 %a, %b
+}
+
+define i32 @udiv_i32(i8 %a, i8 %b) nounwind {
+ %conv = zext i8 %a to i32
+ %conv2 = zext i8 %b to i32
+ %div = udiv i32 %conv, %conv2
+ ret i32 %div
+; CHECK: @udiv_i32
+; CHECK: udiv i8 %a, %b
+; CHECK: zext
+}
+
+define i32 @urem_i32(i8 %a, i8 %b) nounwind {
+ %conv = zext i8 %a to i32
+ %conv2 = zext i8 %b to i32
+ %div = urem i32 %conv, %conv2
+ ret i32 %div
+; CHECK: @urem_i32
+; CHECK: urem i8 %a, %b
+; CHECK: zext
+}
+
+define i32 @udiv_i32_c(i8 %a) nounwind {
+ %conv = zext i8 %a to i32
+ %div = udiv i32 %conv, 10
+ ret i32 %div
+; CHECK: @udiv_i32_c
+; CHECK: udiv i8 %a, 10
+; CHECK: zext
+}
+
+define i32 @urem_i32_c(i8 %a) nounwind {
+ %conv = zext i8 %a to i32
+ %div = urem i32 %conv, 10
+ ret i32 %div
+; CHECK: @urem_i32_c
+; CHECK: urem i8 %a, 10
+; CHECK: zext
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/urem-simplify-bug.ll b/src/LLVM/test/Transforms/InstCombine/urem-simplify-bug.ll
new file mode 100644
index 0000000..229f1a8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/urem-simplify-bug.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -instcombine -S | grep {= or i32 %x, -5}
+
+@.str = internal constant [5 x i8] c"foo\0A\00" ; <[5 x i8]*> [#uses=1]
+@.str1 = internal constant [5 x i8] c"bar\0A\00" ; <[5 x i8]*> [#uses=1]
+
+define i32 @main() nounwind {
+entry:
+ %x = call i32 @func_11( ) nounwind ; <i32> [#uses=1]
+ %tmp3 = or i32 %x, -5 ; <i32> [#uses=1]
+ %tmp5 = urem i32 251, %tmp3 ; <i32> [#uses=1]
+ %tmp6 = icmp ne i32 %tmp5, 0 ; <i1> [#uses=1]
+ %tmp67 = zext i1 %tmp6 to i32 ; <i32> [#uses=1]
+ %tmp9 = urem i32 %tmp67, 95 ; <i32> [#uses=1]
+ %tmp10 = and i32 %tmp9, 1 ; <i32> [#uses=1]
+ %tmp12 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
+ br i1 %tmp12, label %bb14, label %bb
+
+bb: ; preds = %entry
+ br label %bb15
+
+bb14: ; preds = %entry
+ br label %bb15
+
+bb15: ; preds = %bb14, %bb
+ %iftmp.0.0 = phi i8* [ getelementptr ([5 x i8]* @.str1, i32 0, i32 0), %bb14 ], [ getelementptr ([5 x i8]* @.str, i32 0, i32 0), %bb ] ; <i8*> [#uses=1]
+ %tmp17 = call i32 (i8*, ...)* @printf( i8* %iftmp.0.0 ) nounwind ; <i32> [#uses=0]
+ ret i32 0
+}
+
+declare i32 @func_11()
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/InstCombine/urem.ll b/src/LLVM/test/Transforms/InstCombine/urem.ll
new file mode 100644
index 0000000..5108422
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/urem.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | grep urem
+
+define i64 @rem_unsigned(i64 %x1, i64 %y2) {
+ %r = udiv i64 %x1, %y2
+ %r7 = mul i64 %r, %y2
+ %r8 = sub i64 %x1, %r7
+ ret i64 %r8
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_demanded_elts.ll b/src/LLVM/test/Transforms/InstCombine/vec_demanded_elts.ll
new file mode 100644
index 0000000..87c731a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_demanded_elts.ll
@@ -0,0 +1,165 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i16 @test1(float %f) {
+entry:
+; CHECK: @test1
+; CHECK: fmul float
+; CHECK-NOT: insertelement {{.*}} 0.00
+; CHECK-NOT: call {{.*}} @llvm.x86.sse.mul
+; CHECK-NOT: call {{.*}} @llvm.x86.sse.sub
+; CHECK: ret
+ %tmp = insertelement <4 x float> undef, float %f, i32 0 ; <<4 x float>> [#uses=1]
+ %tmp10 = insertelement <4 x float> %tmp, float 0.000000e+00, i32 1 ; <<4 x float>> [#uses=1]
+ %tmp11 = insertelement <4 x float> %tmp10, float 0.000000e+00, i32 2 ; <<4 x float>> [#uses=1]
+ %tmp12 = insertelement <4 x float> %tmp11, float 0.000000e+00, i32 3 ; <<4 x float>> [#uses=1]
+ %tmp28 = tail call <4 x float> @llvm.x86.sse.sub.ss( <4 x float> %tmp12, <4 x float> < float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1]
+ %tmp37 = tail call <4 x float> @llvm.x86.sse.mul.ss( <4 x float> %tmp28, <4 x float> < float 5.000000e-01, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1]
+ %tmp48 = tail call <4 x float> @llvm.x86.sse.min.ss( <4 x float> %tmp37, <4 x float> < float 6.553500e+04, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1]
+ %tmp59 = tail call <4 x float> @llvm.x86.sse.max.ss( <4 x float> %tmp48, <4 x float> zeroinitializer ) ; <<4 x float>> [#uses=1]
+ %tmp.upgrd.1 = tail call i32 @llvm.x86.sse.cvttss2si( <4 x float> %tmp59 ) ; <i32> [#uses=1]
+ %tmp69 = trunc i32 %tmp.upgrd.1 to i16 ; <i16> [#uses=1]
+ ret i16 %tmp69
+}
+
+define i32 @test2(float %f) {
+; CHECK: @test2
+; CHECK-NOT: insertelement
+; CHECK-NOT: extractelement
+; CHECK: ret
+ %tmp5 = fmul float %f, %f
+ %tmp9 = insertelement <4 x float> undef, float %tmp5, i32 0
+ %tmp10 = insertelement <4 x float> %tmp9, float 0.000000e+00, i32 1
+ %tmp11 = insertelement <4 x float> %tmp10, float 0.000000e+00, i32 2
+ %tmp12 = insertelement <4 x float> %tmp11, float 0.000000e+00, i32 3
+ %tmp19 = bitcast <4 x float> %tmp12 to <4 x i32>
+ %tmp21 = extractelement <4 x i32> %tmp19, i32 0
+ ret i32 %tmp21
+}
+
+define i64 @test3(float %f, double %d) {
+; CHECK: @test3
+; CHECK-NOT: insertelement {{.*}} 0.00
+; CHECK: ret
+entry:
+ %v00 = insertelement <4 x float> undef, float %f, i32 0
+ %v01 = insertelement <4 x float> %v00, float 0.000000e+00, i32 1
+ %v02 = insertelement <4 x float> %v01, float 0.000000e+00, i32 2
+ %v03 = insertelement <4 x float> %v02, float 0.000000e+00, i32 3
+ %tmp0 = tail call i32 @llvm.x86.sse.cvtss2si(<4 x float> %v03)
+ %v10 = insertelement <4 x float> undef, float %f, i32 0
+ %v11 = insertelement <4 x float> %v10, float 0.000000e+00, i32 1
+ %v12 = insertelement <4 x float> %v11, float 0.000000e+00, i32 2
+ %v13 = insertelement <4 x float> %v12, float 0.000000e+00, i32 3
+ %tmp1 = tail call i64 @llvm.x86.sse.cvtss2si64(<4 x float> %v13)
+ %v20 = insertelement <4 x float> undef, float %f, i32 0
+ %v21 = insertelement <4 x float> %v20, float 0.000000e+00, i32 1
+ %v22 = insertelement <4 x float> %v21, float 0.000000e+00, i32 2
+ %v23 = insertelement <4 x float> %v22, float 0.000000e+00, i32 3
+ %tmp2 = tail call i32 @llvm.x86.sse.cvttss2si(<4 x float> %v23)
+ %v30 = insertelement <4 x float> undef, float %f, i32 0
+ %v31 = insertelement <4 x float> %v30, float 0.000000e+00, i32 1
+ %v32 = insertelement <4 x float> %v31, float 0.000000e+00, i32 2
+ %v33 = insertelement <4 x float> %v32, float 0.000000e+00, i32 3
+ %tmp3 = tail call i64 @llvm.x86.sse.cvttss2si64(<4 x float> %v33)
+ %v40 = insertelement <2 x double> undef, double %d, i32 0
+ %v41 = insertelement <2 x double> %v40, double 0.000000e+00, i32 1
+ %tmp4 = tail call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> %v41)
+ %v50 = insertelement <2 x double> undef, double %d, i32 0
+ %v51 = insertelement <2 x double> %v50, double 0.000000e+00, i32 1
+ %tmp5 = tail call i64 @llvm.x86.sse2.cvtsd2si64(<2 x double> %v51)
+ %v60 = insertelement <2 x double> undef, double %d, i32 0
+ %v61 = insertelement <2 x double> %v60, double 0.000000e+00, i32 1
+ %tmp6 = tail call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> %v61)
+ %v70 = insertelement <2 x double> undef, double %d, i32 0
+ %v71 = insertelement <2 x double> %v70, double 0.000000e+00, i32 1
+ %tmp7 = tail call i64 @llvm.x86.sse2.cvttsd2si64(<2 x double> %v71)
+ %tmp8 = add i32 %tmp0, %tmp2
+ %tmp9 = add i32 %tmp4, %tmp6
+ %tmp10 = add i32 %tmp8, %tmp9
+ %tmp11 = sext i32 %tmp10 to i64
+ %tmp12 = add i64 %tmp1, %tmp3
+ %tmp13 = add i64 %tmp5, %tmp7
+ %tmp14 = add i64 %tmp12, %tmp13
+ %tmp15 = add i64 %tmp11, %tmp14
+ ret i64 %tmp15
+}
+
+define void @get_image() nounwind {
+; CHECK: @get_image
+; CHECK-NOT: extractelement
+; CHECK: unreachable
+entry:
+ %0 = call i32 @fgetc(i8* null) nounwind ; <i32> [#uses=1]
+ %1 = trunc i32 %0 to i8 ; <i8> [#uses=1]
+ %tmp2 = insertelement <100 x i8> zeroinitializer, i8 %1, i32 1 ; <<100 x i8>> [#uses=1]
+ %tmp1 = extractelement <100 x i8> %tmp2, i32 0 ; <i8> [#uses=1]
+ %2 = icmp eq i8 %tmp1, 80 ; <i1> [#uses=1]
+ br i1 %2, label %bb2, label %bb3
+
+bb2: ; preds = %entry
+ br label %bb3
+
+bb3: ; preds = %bb2, %entry
+ unreachable
+}
+
+; PR4340
+define void @vac(<4 x float>* nocapture %a) nounwind {
+; CHECK: @vac
+; CHECK-NOT: load
+; CHECK: ret
+entry:
+ %tmp1 = load <4 x float>* %a ; <<4 x float>> [#uses=1]
+ %vecins = insertelement <4 x float> %tmp1, float 0.000000e+00, i32 0 ; <<4 x float>> [#uses=1]
+ %vecins4 = insertelement <4 x float> %vecins, float 0.000000e+00, i32 1; <<4 x float>> [#uses=1]
+ %vecins6 = insertelement <4 x float> %vecins4, float 0.000000e+00, i32 2; <<4 x float>> [#uses=1]
+ %vecins8 = insertelement <4 x float> %vecins6, float 0.000000e+00, i32 3; <<4 x float>> [#uses=1]
+ store <4 x float> %vecins8, <4 x float>* %a
+ ret void
+}
+
+declare i32 @fgetc(i8*)
+
+declare <4 x float> @llvm.x86.sse.sub.ss(<4 x float>, <4 x float>)
+
+declare <4 x float> @llvm.x86.sse.mul.ss(<4 x float>, <4 x float>)
+
+declare <4 x float> @llvm.x86.sse.min.ss(<4 x float>, <4 x float>)
+
+declare <4 x float> @llvm.x86.sse.max.ss(<4 x float>, <4 x float>)
+
+declare i32 @llvm.x86.sse.cvtss2si(<4 x float>)
+declare i64 @llvm.x86.sse.cvtss2si64(<4 x float>)
+declare i32 @llvm.x86.sse.cvttss2si(<4 x float>)
+declare i64 @llvm.x86.sse.cvttss2si64(<4 x float>)
+declare i32 @llvm.x86.sse2.cvtsd2si(<2 x double>)
+declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>)
+declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>)
+declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>)
+
+; <rdar://problem/6945110>
+define <4 x i32> @kernel3_vertical(<4 x i16> * %src, <8 x i16> * %foo) nounwind {
+entry:
+ %tmp = load <4 x i16>* %src
+ %tmp1 = load <8 x i16>* %foo
+; CHECK: %tmp2 = shufflevector
+ %tmp2 = shufflevector <4 x i16> %tmp, <4 x i16> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
+; pmovzxwd ignores the upper 64-bits of its input; -instcombine should remove this shuffle:
+; CHECK-NOT: shufflevector
+ %tmp3 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
+; CHECK-NEXT: pmovzxwd
+ %0 = call <4 x i32> @llvm.x86.sse41.pmovzxwd(<8 x i16> %tmp3)
+ ret <4 x i32> %0
+}
+declare <4 x i32> @llvm.x86.sse41.pmovzxwd(<8 x i16>) nounwind readnone
+
+define <4 x float> @dead_shuffle_elt(<4 x float> %x, <2 x float> %y) nounwind {
+entry:
+; CHECK: define <4 x float> @dead_shuffle_elt
+; CHECK: shufflevector <2 x float> %y, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
+ %shuffle.i = shufflevector <2 x float> %y, <2 x float> %y, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+ %shuffle9.i = shufflevector <4 x float> %x, <4 x float> %shuffle.i, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
+ ret <4 x float> %shuffle9.i
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_extract_elt.ll b/src/LLVM/test/Transforms/InstCombine/vec_extract_elt.ll
new file mode 100644
index 0000000..5599fc9
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_extract_elt.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | not grep extractelement
+
+define i32 @test(float %f) {
+ %tmp7 = insertelement <4 x float> undef, float %f, i32 0 ; <<4 x float>> [#uses=1]
+ %tmp17 = bitcast <4 x float> %tmp7 to <4 x i32> ; <<4 x i32>> [#uses=1]
+ %tmp19 = extractelement <4 x i32> %tmp17, i32 0 ; <i32> [#uses=1]
+ ret i32 %tmp19
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_insertelt.ll b/src/LLVM/test/Transforms/InstCombine/vec_insertelt.ll
new file mode 100644
index 0000000..35882f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_insertelt.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -instcombine -S | grep {ret <4 x i32> %A}
+
+; PR1286
+define <4 x i32> @test1(<4 x i32> %A) {
+ %B = insertelement <4 x i32> %A, i32 undef, i32 1
+ ret <4 x i32> %B
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_narrow.ll b/src/LLVM/test/Transforms/InstCombine/vec_narrow.ll
new file mode 100644
index 0000000..4ccbedc
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_narrow.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | grep {fadd float}
+
+
+define float @test(<4 x float> %A, <4 x float> %B, float %f) {
+ %C = insertelement <4 x float> %A, float %f, i32 0 ; <%V> [#uses=1]
+ %D = fadd <4 x float> %C, %B ; <%V> [#uses=1]
+ %E = extractelement <4 x float> %D, i32 0 ; <float> [#uses=1]
+ ret float %E
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_sext.ll b/src/LLVM/test/Transforms/InstCombine/vec_sext.ll
new file mode 100644
index 0000000..d7ab96b
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_sext.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define <4 x i32> @psignd_3(<4 x i32> %a, <4 x i32> %b) nounwind ssp {
+entry:
+ %cmp = icmp slt <4 x i32> %b, zeroinitializer
+ %sext = sext <4 x i1> %cmp to <4 x i32>
+ %sub = sub nsw <4 x i32> zeroinitializer, %a
+ %0 = icmp slt <4 x i32> %sext, zeroinitializer
+ %sext3 = sext <4 x i1> %0 to <4 x i32>
+ %1 = xor <4 x i32> %sext3, <i32 -1, i32 -1, i32 -1, i32 -1>
+ %2 = and <4 x i32> %a, %1
+ %3 = and <4 x i32> %sext3, %sub
+ %cond = or <4 x i32> %2, %3
+ ret <4 x i32> %cond
+
+; CHECK: ashr <4 x i32> %b, <i32 31, i32 31, i32 31, i32 31>
+; CHECK: sub nsw <4 x i32> zeroinitializer, %a
+; CHECK: xor <4 x i32> %b.lobit, <i32 -1, i32 -1, i32 -1, i32 -1>
+; CHECK: and <4 x i32> %a, %0
+; CHECK: and <4 x i32> %b.lobit, %sub
+; CHECK: or <4 x i32> %1, %2
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/vec_shuffle.ll b/src/LLVM/test/Transforms/InstCombine/vec_shuffle.ll
new file mode 100644
index 0000000..f2822c3
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vec_shuffle.ll
@@ -0,0 +1,109 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define <4 x float> @test1(<4 x float> %v1) {
+; CHECK: @test1
+; CHECK: ret <4 x float> %v1
+ %v2 = shufflevector <4 x float> %v1, <4 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+ ret <4 x float> %v2
+}
+
+define <4 x float> @test2(<4 x float> %v1) {
+; CHECK: @test2
+; CHECK: ret <4 x float> %v1
+ %v2 = shufflevector <4 x float> %v1, <4 x float> %v1, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
+ ret <4 x float> %v2
+}
+
+define float @test3(<4 x float> %A, <4 x float> %B, float %f) {
+; CHECK: @test3
+; CHECK: ret float %f
+ %C = insertelement <4 x float> %A, float %f, i32 0
+ %D = shufflevector <4 x float> %C, <4 x float> %B, <4 x i32> <i32 5, i32 0, i32 2, i32 7>
+ %E = extractelement <4 x float> %D, i32 1
+ ret float %E
+}
+
+define i32 @test4(<4 x i32> %X) {
+; CHECK: @test4
+; CHECK-NEXT: extractelement
+; CHECK-NEXT: ret
+ %tmp152.i53899.i = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> zeroinitializer
+ %tmp34 = extractelement <4 x i32> %tmp152.i53899.i, i32 0
+ ret i32 %tmp34
+}
+
+define i32 @test5(<4 x i32> %X) {
+; CHECK: @test5
+; CHECK-NEXT: extractelement
+; CHECK-NEXT: ret
+ %tmp152.i53899.i = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 undef, i32 undef>
+ %tmp34 = extractelement <4 x i32> %tmp152.i53899.i, i32 0
+ ret i32 %tmp34
+}
+
+define float @test6(<4 x float> %X) {
+; CHECK: @test6
+; CHECK-NEXT: extractelement
+; CHECK-NEXT: ret
+ %X1 = bitcast <4 x float> %X to <4 x i32>
+ %tmp152.i53899.i = shufflevector <4 x i32> %X1, <4 x i32> undef, <4 x i32> zeroinitializer
+ %tmp152.i53900.i = bitcast <4 x i32> %tmp152.i53899.i to <4 x float>
+ %tmp34 = extractelement <4 x float> %tmp152.i53900.i, i32 0
+ ret float %tmp34
+}
+
+define <4 x float> @test7(<4 x float> %tmp45.i) {
+; CHECK: @test7
+; CHECK-NEXT: ret <4 x float> %tmp45.i
+ %tmp1642.i = shufflevector <4 x float> %tmp45.i, <4 x float> undef, <4 x i32> < i32 0, i32 1, i32 6, i32 7 >
+ ret <4 x float> %tmp1642.i
+}
+
+; This should turn into a single shuffle.
+define <4 x float> @test8(<4 x float> %tmp, <4 x float> %tmp1) {
+; CHECK: @test8
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+ %tmp4 = extractelement <4 x float> %tmp, i32 1
+ %tmp2 = extractelement <4 x float> %tmp, i32 3
+ %tmp1.upgrd.1 = extractelement <4 x float> %tmp1, i32 0
+ %tmp128 = insertelement <4 x float> undef, float %tmp4, i32 0
+ %tmp130 = insertelement <4 x float> %tmp128, float undef, i32 1
+ %tmp132 = insertelement <4 x float> %tmp130, float %tmp2, i32 2
+ %tmp134 = insertelement <4 x float> %tmp132, float %tmp1.upgrd.1, i32 3
+ ret <4 x float> %tmp134
+}
+
+; Test fold of two shuffles where the first shuffle vectors inputs are a
+; different length then the second.
+define <4 x i8> @test9(<16 x i8> %tmp6) nounwind {
+; CHECK: @test9
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+ %tmp7 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> < i32 13, i32 9, i32 4, i32 13 > ; <<4 x i8>> [#uses=1]
+ %tmp9 = shufflevector <4 x i8> %tmp7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 > ; <<4 x i8>> [#uses=1]
+ ret <4 x i8> %tmp9
+}
+
+; Same as test9, but make sure that "undef" mask values are not confused with
+; mask values of 2*N, where N is the mask length. These shuffles should not
+; be folded (because [8,9,4,8] may not be a mask supported by the target).
+define <4 x i8> @test9a(<16 x i8> %tmp6) nounwind {
+; CHECK: @test9a
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+ %tmp7 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> < i32 undef, i32 9, i32 4, i32 8 > ; <<4 x i8>> [#uses=1]
+ %tmp9 = shufflevector <4 x i8> %tmp7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 > ; <<4 x i8>> [#uses=1]
+ ret <4 x i8> %tmp9
+}
+
+; Redundant vector splats should be removed. Radar 8597790.
+define <4 x i32> @test10(<4 x i32> %tmp5) nounwind {
+; CHECK: @test10
+; CHECK-NEXT: shufflevector
+; CHECK-NEXT: ret
+ %tmp6 = shufflevector <4 x i32> %tmp5, <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
+ %tmp7 = shufflevector <4 x i32> %tmp6, <4 x i32> undef, <4 x i32> zeroinitializer
+ ret <4 x i32> %tmp7
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/vector-casts.ll b/src/LLVM/test/Transforms/InstCombine/vector-casts.ll
new file mode 100644
index 0000000..7bbf53c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vector-casts.ll
@@ -0,0 +1,151 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; This turns into a&1 != 0
+define <2 x i1> @test1(<2 x i64> %a) {
+ %t = trunc <2 x i64> %a to <2 x i1>
+ ret <2 x i1> %t
+
+; CHECK: @test1
+; CHECK: and <2 x i64> %a, <i64 1, i64 1>
+; CHECK: icmp ne <2 x i64> %1, zeroinitializer
+}
+
+; The ashr turns into an lshr.
+define <2 x i64> @test2(<2 x i64> %a) {
+ %b = and <2 x i64> %a, <i64 65535, i64 65535>
+ %t = ashr <2 x i64> %b, <i64 1, i64 1>
+ ret <2 x i64> %t
+
+; CHECK: @test2
+; CHECK: and <2 x i64> %a, <i64 65535, i64 65535>
+; CHECK: lshr <2 x i64> %b, <i64 1, i64 1>
+}
+
+
+
+define <2 x i64> @test3(<4 x float> %a, <4 x float> %b) nounwind readnone {
+entry:
+ %cmp = fcmp ord <4 x float> %a, zeroinitializer
+ %sext = sext <4 x i1> %cmp to <4 x i32>
+ %cmp4 = fcmp ord <4 x float> %b, zeroinitializer
+ %sext5 = sext <4 x i1> %cmp4 to <4 x i32>
+ %and = and <4 x i32> %sext, %sext5
+ %conv = bitcast <4 x i32> %and to <2 x i64>
+ ret <2 x i64> %conv
+
+; CHECK: @test3
+; CHECK: fcmp ord <4 x float> %a, %b
+}
+
+define <2 x i64> @test4(<4 x float> %a, <4 x float> %b) nounwind readnone {
+entry:
+ %cmp = fcmp uno <4 x float> %a, zeroinitializer
+ %sext = sext <4 x i1> %cmp to <4 x i32>
+ %cmp4 = fcmp uno <4 x float> %b, zeroinitializer
+ %sext5 = sext <4 x i1> %cmp4 to <4 x i32>
+ %or = or <4 x i32> %sext, %sext5
+ %conv = bitcast <4 x i32> %or to <2 x i64>
+ ret <2 x i64> %conv
+; CHECK: @test4
+; CHECK: fcmp uno <4 x float> %a, %b
+}
+
+
+; rdar://7434900
+define <2 x i64> @test5(<4 x float> %a, <4 x float> %b) nounwind readnone {
+entry:
+ %cmp = fcmp ult <4 x float> %a, zeroinitializer
+ %sext = sext <4 x i1> %cmp to <4 x i32>
+ %cmp4 = fcmp ult <4 x float> %b, zeroinitializer
+ %sext5 = sext <4 x i1> %cmp4 to <4 x i32>
+ %and = and <4 x i32> %sext, %sext5
+ %conv = bitcast <4 x i32> %and to <2 x i64>
+ ret <2 x i64> %conv
+
+; CHECK: @test5
+; CHECK: sext <4 x i1> %cmp to <4 x i32>
+; CHECK: sext <4 x i1> %cmp4 to <4 x i32>
+}
+
+
+define void @convert(<2 x i32>* %dst.addr, <2 x i64> %src) nounwind {
+entry:
+ %val = trunc <2 x i64> %src to <2 x i32>
+ %add = add <2 x i32> %val, <i32 1, i32 1>
+ store <2 x i32> %add, <2 x i32>* %dst.addr
+ ret void
+}
+
+define <2 x i65> @foo(<2 x i64> %t) {
+ %a = trunc <2 x i64> %t to <2 x i32>
+ %b = zext <2 x i32> %a to <2 x i65>
+ ret <2 x i65> %b
+}
+define <2 x i64> @bar(<2 x i65> %t) {
+ %a = trunc <2 x i65> %t to <2 x i32>
+ %b = zext <2 x i32> %a to <2 x i64>
+ ret <2 x i64> %b
+}
+define <2 x i65> @foos(<2 x i64> %t) {
+ %a = trunc <2 x i64> %t to <2 x i32>
+ %b = sext <2 x i32> %a to <2 x i65>
+ ret <2 x i65> %b
+}
+define <2 x i64> @bars(<2 x i65> %t) {
+ %a = trunc <2 x i65> %t to <2 x i32>
+ %b = sext <2 x i32> %a to <2 x i64>
+ ret <2 x i64> %b
+}
+define <2 x i64> @quxs(<2 x i64> %t) {
+ %a = trunc <2 x i64> %t to <2 x i32>
+ %b = sext <2 x i32> %a to <2 x i64>
+ ret <2 x i64> %b
+}
+define <2 x i64> @quxt(<2 x i64> %t) {
+ %a = shl <2 x i64> %t, <i64 32, i64 32>
+ %b = ashr <2 x i64> %a, <i64 32, i64 32>
+ ret <2 x i64> %b
+}
+define <2 x double> @fa(<2 x double> %t) {
+ %a = fptrunc <2 x double> %t to <2 x float>
+ %b = fpext <2 x float> %a to <2 x double>
+ ret <2 x double> %b
+}
+define <2 x double> @fb(<2 x double> %t) {
+ %a = fptoui <2 x double> %t to <2 x i64>
+ %b = uitofp <2 x i64> %a to <2 x double>
+ ret <2 x double> %b
+}
+define <2 x double> @fc(<2 x double> %t) {
+ %a = fptosi <2 x double> %t to <2 x i64>
+ %b = sitofp <2 x i64> %a to <2 x double>
+ ret <2 x double> %b
+}
+
+; PR9228
+; This was a crasher, so no CHECK statements.
+define <4 x float> @f(i32 %a) nounwind alwaysinline {
+; CHECK: @f
+entry:
+ %dim = insertelement <4 x i32> undef, i32 %a, i32 0
+ %dim30 = insertelement <4 x i32> %dim, i32 %a, i32 1
+ %dim31 = insertelement <4 x i32> %dim30, i32 %a, i32 2
+ %dim32 = insertelement <4 x i32> %dim31, i32 %a, i32 3
+
+ %offset_ptr = getelementptr <4 x float>* null, i32 1
+ %offset_int = ptrtoint <4 x float>* %offset_ptr to i64
+ %sizeof32 = trunc i64 %offset_int to i32
+
+ %smearinsert33 = insertelement <4 x i32> undef, i32 %sizeof32, i32 0
+ %smearinsert34 = insertelement <4 x i32> %smearinsert33, i32 %sizeof32, i32 1
+ %smearinsert35 = insertelement <4 x i32> %smearinsert34, i32 %sizeof32, i32 2
+ %smearinsert36 = insertelement <4 x i32> %smearinsert35, i32 %sizeof32, i32 3
+
+ %delta_scale = mul <4 x i32> %dim32, %smearinsert36
+ %offset_delta = add <4 x i32> zeroinitializer, %delta_scale
+
+ %offset_varying_delta = add <4 x i32> %offset_delta, undef
+
+ ret <4 x float> undef
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/vector-srem.ll b/src/LLVM/test/Transforms/InstCombine/vector-srem.ll
new file mode 100644
index 0000000..acb11c5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/vector-srem.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instcombine -S | grep {srem <4 x i32>}
+
+define <4 x i32> @foo(<4 x i32> %t, <4 x i32> %u)
+{
+ %k = sdiv <4 x i32> %t, %u
+ %l = mul <4 x i32> %k, %u
+ %m = sub <4 x i32> %t, %l
+ ret <4 x i32> %m
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/volatile_store.ll b/src/LLVM/test/Transforms/InstCombine/volatile_store.ll
new file mode 100644
index 0000000..0518e5a
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/volatile_store.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -instcombine -S | grep {store volatile}
+; RUN: opt < %s -instcombine -S | grep {load volatile}
+
+@x = weak global i32 0 ; <i32*> [#uses=2]
+
+define void @self_assign_1() {
+entry:
+ %tmp = volatile load i32* @x ; <i32> [#uses=1]
+ volatile store i32 %tmp, i32* @x
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/x86-crc32-demanded.ll b/src/LLVM/test/Transforms/InstCombine/x86-crc32-demanded.ll
new file mode 100644
index 0000000..878b97d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/x86-crc32-demanded.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; crc32 with 64-bit destination zeros high 32-bit.
+; rdar://9467055
+
+define i64 @test() nounwind {
+entry:
+; CHECK: test
+; CHECK: tail call i64 @llvm.x86.sse42.crc32.64.64
+; CHECK-NOT: and
+; CHECK: ret
+ %0 = tail call i64 @llvm.x86.sse42.crc32.64.64(i64 0, i64 4) nounwind
+ %1 = and i64 %0, 4294967295
+ ret i64 %1
+}
+
+declare i64 @llvm.x86.sse42.crc32.64.64(i64, i64) nounwind readnone
diff --git a/src/LLVM/test/Transforms/InstCombine/xor-undef.ll b/src/LLVM/test/Transforms/InstCombine/xor-undef.ll
new file mode 100644
index 0000000..cf72955
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/xor-undef.ll
@@ -0,0 +1,6 @@
+; RUN: opt < %s -instcombine -S | grep zeroinitializer
+
+define <2 x i64> @f() {
+ %tmp = xor <2 x i64> undef, undef
+ ret <2 x i64> %tmp
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/xor.ll b/src/LLVM/test/Transforms/InstCombine/xor.ll
new file mode 100644
index 0000000..0808716
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/xor.ll
@@ -0,0 +1,193 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | \
+; RUN: not grep {xor }
+; END.
+@G1 = global i32 0 ; <i32*> [#uses=1]
+@G2 = global i32 0 ; <i32*> [#uses=1]
+
+define i1 @test0(i1 %A) {
+ %B = xor i1 %A, false ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i32 @test1(i32 %A) {
+ %B = xor i32 %A, 0 ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i1 @test2(i1 %A) {
+ %B = xor i1 %A, %A ; <i1> [#uses=1]
+ ret i1 %B
+}
+
+define i32 @test3(i32 %A) {
+ %B = xor i32 %A, %A ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test4(i32 %A) {
+ %NotA = xor i32 -1, %A ; <i32> [#uses=1]
+ %B = xor i32 %A, %NotA ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define i32 @test5(i32 %A) {
+ %t1 = or i32 %A, 123 ; <i32> [#uses=1]
+ %r = xor i32 %t1, 123 ; <i32> [#uses=1]
+ ret i32 %r
+}
+
+define i8 @test6(i8 %A) {
+ %B = xor i8 %A, 17 ; <i8> [#uses=1]
+ %C = xor i8 %B, 17 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i32 @test7(i32 %A, i32 %B) {
+ %A1 = and i32 %A, 7 ; <i32> [#uses=1]
+ %B1 = and i32 %B, 128 ; <i32> [#uses=1]
+ %C1 = xor i32 %A1, %B1 ; <i32> [#uses=1]
+ ret i32 %C1
+}
+
+define i8 @test8(i1 %c) {
+ %d = xor i1 %c, true ; <i1> [#uses=1]
+ br i1 %d, label %True, label %False
+
+True: ; preds = %0
+ ret i8 1
+
+False: ; preds = %0
+ ret i8 3
+}
+
+define i1 @test9(i8 %A) {
+ %B = xor i8 %A, 123 ; <i8> [#uses=1]
+ %C = icmp eq i8 %B, 34 ; <i1> [#uses=1]
+ ret i1 %C
+}
+
+define i8 @test10(i8 %A) {
+ %B = and i8 %A, 3 ; <i8> [#uses=1]
+ %C = xor i8 %B, 4 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i8 @test11(i8 %A) {
+ %B = or i8 %A, 12 ; <i8> [#uses=1]
+ %C = xor i8 %B, 4 ; <i8> [#uses=1]
+ ret i8 %C
+}
+
+define i1 @test12(i8 %A) {
+ %B = xor i8 %A, 4 ; <i8> [#uses=1]
+ %c = icmp ne i8 %B, 0 ; <i1> [#uses=1]
+ ret i1 %c
+}
+
+define i1 @test13(i8 %A, i8 %B) {
+ %C = icmp ult i8 %A, %B ; <i1> [#uses=1]
+ %D = icmp ugt i8 %A, %B ; <i1> [#uses=1]
+ %E = xor i1 %C, %D ; <i1> [#uses=1]
+ ret i1 %E
+}
+
+define i1 @test14(i8 %A, i8 %B) {
+ %C = icmp eq i8 %A, %B ; <i1> [#uses=1]
+ %D = icmp ne i8 %B, %A ; <i1> [#uses=1]
+ %E = xor i1 %C, %D ; <i1> [#uses=1]
+ ret i1 %E
+}
+
+define i32 @test15(i32 %A) {
+ %B = add i32 %A, -1 ; <i32> [#uses=1]
+ %C = xor i32 %B, -1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test16(i32 %A) {
+ %B = add i32 %A, 123 ; <i32> [#uses=1]
+ %C = xor i32 %B, -1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test17(i32 %A) {
+ %B = sub i32 123, %A ; <i32> [#uses=1]
+ %C = xor i32 %B, -1 ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test18(i32 %A) {
+ %B = xor i32 %A, -1 ; <i32> [#uses=1]
+ %C = sub i32 123, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+define i32 @test19(i32 %A, i32 %B) {
+ %C = xor i32 %A, %B ; <i32> [#uses=1]
+ %D = xor i32 %C, %A ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define void @test20(i32 %A, i32 %B) {
+ %tmp.2 = xor i32 %B, %A ; <i32> [#uses=2]
+ %tmp.5 = xor i32 %tmp.2, %B ; <i32> [#uses=2]
+ %tmp.8 = xor i32 %tmp.5, %tmp.2 ; <i32> [#uses=1]
+ store i32 %tmp.8, i32* @G1
+ store i32 %tmp.5, i32* @G2
+ ret void
+}
+
+define i32 @test21(i1 %C, i32 %A, i32 %B) {
+ %C2 = xor i1 %C, true ; <i1> [#uses=1]
+ %D = select i1 %C2, i32 %A, i32 %B ; <i32> [#uses=1]
+ ret i32 %D
+}
+
+define i32 @test22(i1 %X) {
+ %Y = xor i1 %X, true ; <i1> [#uses=1]
+ %Z = zext i1 %Y to i32 ; <i32> [#uses=1]
+ %Q = xor i32 %Z, 1 ; <i32> [#uses=1]
+ ret i32 %Q
+}
+
+define i1 @test23(i32 %a, i32 %b) {
+ %tmp.2 = xor i32 %b, %a ; <i32> [#uses=1]
+ %tmp.4 = icmp eq i32 %tmp.2, %a ; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
+
+define i1 @test24(i32 %c, i32 %d) {
+ %tmp.2 = xor i32 %d, %c ; <i32> [#uses=1]
+ %tmp.4 = icmp ne i32 %tmp.2, %c ; <i1> [#uses=1]
+ ret i1 %tmp.4
+}
+
+define i32 @test25(i32 %g, i32 %h) {
+ %h2 = xor i32 %h, -1 ; <i32> [#uses=1]
+ %tmp2 = and i32 %h2, %g ; <i32> [#uses=1]
+ %tmp4 = xor i32 %tmp2, %g ; <i32> [#uses=1]
+ ret i32 %tmp4
+}
+
+define i32 @test26(i32 %a, i32 %b) {
+ %b2 = xor i32 %b, -1 ; <i32> [#uses=1]
+ %tmp2 = xor i32 %a, %b2 ; <i32> [#uses=1]
+ %tmp4 = and i32 %tmp2, %a ; <i32> [#uses=1]
+ ret i32 %tmp4
+}
+
+define i32 @test27(i32 %b, i32 %c, i32 %d) {
+ %tmp2 = xor i32 %d, %b ; <i32> [#uses=1]
+ %tmp5 = xor i32 %d, %c ; <i32> [#uses=1]
+ %tmp = icmp eq i32 %tmp2, %tmp5 ; <i1> [#uses=1]
+ %tmp6 = zext i1 %tmp to i32 ; <i32> [#uses=1]
+ ret i32 %tmp6
+}
+
+define i32 @test28(i32 %indvar) {
+ %tmp7 = add i32 %indvar, -2147483647 ; <i32> [#uses=1]
+ %tmp214 = xor i32 %tmp7, -2147483648 ; <i32> [#uses=1]
+ ret i32 %tmp214
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/xor2.ll b/src/LLVM/test/Transforms/InstCombine/xor2.ll
new file mode 100644
index 0000000..47d1da7
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/xor2.ll
@@ -0,0 +1,53 @@
+; This test makes sure that these instructions are properly eliminated.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; PR1253
+define i1 @test0(i32 %A) {
+; CHECK: @test0
+; CHECK: %C = icmp slt i32 %A, 0
+ %B = xor i32 %A, -2147483648
+ %C = icmp sgt i32 %B, -1
+ ret i1 %C
+}
+
+define i1 @test1(i32 %A) {
+; CHECK: @test1
+; CHECK: %C = icmp slt i32 %A, 0
+ %B = xor i32 %A, 12345
+ %C = icmp slt i32 %B, 0
+ ret i1 %C
+}
+
+; PR1014
+define i32 @test2(i32 %tmp1) {
+; CHECK: @test2
+; CHECK-NEXT: and i32 %tmp1, 32
+; CHECK-NEXT: or i32 %ovm, 8
+; CHECK-NEXT: ret i32
+ %ovm = and i32 %tmp1, 32
+ %ov3 = add i32 %ovm, 145
+ %ov110 = xor i32 %ov3, 153
+ ret i32 %ov110
+}
+
+define i32 @test3(i32 %tmp1) {
+; CHECK: @test3
+; CHECK-NEXT: and i32 %tmp1, 32
+; CHECK-NEXT: or i32 %ovm, 8
+; CHECK-NEXT: ret i32
+ %ovm = or i32 %tmp1, 145
+ %ov31 = and i32 %ovm, 177
+ %ov110 = xor i32 %ov31, 153
+ ret i32 %ov110
+}
+
+define i32 @test4(i32 %A, i32 %B) {
+ %1 = xor i32 %A, -1
+ %2 = ashr i32 %1, %B
+ %3 = xor i32 %2, -1
+ ret i32 %3
+; CHECK: @test4
+; CHECK: %1 = ashr i32 %A, %B
+; CHECK: ret i32 %1
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/zero-point-zero-add.ll b/src/LLVM/test/Transforms/InstCombine/zero-point-zero-add.ll
new file mode 100644
index 0000000..d07a9f4
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zero-point-zero-add.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instcombine -S | grep 0.0 | count 1
+
+declare double @abs(double)
+
+define double @test(double %X) {
+ %Y = fadd double %X, 0.0 ;; Should be a single add x, 0.0
+ %Z = fadd double %Y, 0.0
+ ret double %Z
+}
+
+define double @test1(double %X) {
+ %Y = call double @abs(double %X)
+ %Z = fadd double %Y, 0.0
+ ret double %Z
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/zeroext-and-reduce.ll b/src/LLVM/test/Transforms/InstCombine/zeroext-and-reduce.ll
new file mode 100644
index 0000000..6093533
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zeroext-and-reduce.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instcombine -S | \
+; RUN: grep {and i32 %Y, 8}
+
+define i32 @test1(i8 %X) {
+ %Y = zext i8 %X to i32 ; <i32> [#uses=1]
+ %Z = and i32 %Y, 65544 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+
diff --git a/src/LLVM/test/Transforms/InstCombine/zext-bool-add-sub.ll b/src/LLVM/test/Transforms/InstCombine/zext-bool-add-sub.ll
new file mode 100644
index 0000000..1164273
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zext-bool-add-sub.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instcombine -S | not grep zext
+
+define i32 @a(i1 %x) {
+entry:
+ %y = zext i1 %x to i32
+ %res = add i32 %y, 1
+ ret i32 %res
+}
+
+define i32 @b(i1 %x) {
+entry:
+ %y = zext i1 %x to i32
+ %res = add i32 %y, -1
+ ret i32 %res
+}
+
+define i32 @c(i1 %x) {
+entry:
+ %y = zext i1 %x to i32
+ %res = sub i32 0, %y
+ ret i32 %res
+}
+
+define i32 @d(i1 %x) {
+entry:
+ %y = zext i1 %x to i32
+ %res = sub i32 3, %y
+ ret i32 %res
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/zext-fold.ll b/src/LLVM/test/Transforms/InstCombine/zext-fold.ll
new file mode 100644
index 0000000..9521101
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zext-fold.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | grep {zext } | count 1
+; PR1570
+
+define i32 @test2(float %X, float %Y) {
+entry:
+ %tmp3 = fcmp uno float %X, %Y ; <i1> [#uses=1]
+ %tmp34 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
+ %tmp = xor i8 %tmp34, 1 ; <i8> [#uses=1]
+ %toBoolnot5 = zext i8 %tmp to i32 ; <i32> [#uses=1]
+ ret i32 %toBoolnot5
+}
+
diff --git a/src/LLVM/test/Transforms/InstCombine/zext-or-icmp.ll b/src/LLVM/test/Transforms/InstCombine/zext-or-icmp.ll
new file mode 100644
index 0000000..ddc6083
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zext-or-icmp.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -instcombine -S | grep icmp | count 1
+
+ %struct.FooBar = type <{ i8, i8, [2 x i8], i8, i8, i8, i8, i16, i16, [4 x i8], [8 x %struct.Rock] }>
+ %struct.Rock = type { i16, i16 }
+@some_idx = internal constant [4 x i8] c"\0A\0B\0E\0F" ; <[4 x i8]*> [#uses=1]
+
+define zeroext i8 @t(%struct.FooBar* %up, i8 zeroext %intra_flag, i32 %blk_i) nounwind {
+entry:
+ %tmp2 = lshr i32 %blk_i, 1 ; <i32> [#uses=1]
+ %tmp3 = and i32 %tmp2, 2 ; <i32> [#uses=1]
+ %tmp5 = and i32 %blk_i, 1 ; <i32> [#uses=1]
+ %tmp6 = or i32 %tmp3, %tmp5 ; <i32> [#uses=1]
+ %tmp8 = getelementptr %struct.FooBar* %up, i32 0, i32 7 ; <i16*> [#uses=1]
+ %tmp9 = load i16* %tmp8, align 1 ; <i16> [#uses=1]
+ %tmp910 = zext i16 %tmp9 to i32 ; <i32> [#uses=1]
+ %tmp12 = getelementptr [4 x i8]* @some_idx, i32 0, i32 %tmp6 ; <i8*> [#uses=1]
+ %tmp13 = load i8* %tmp12, align 1 ; <i8> [#uses=1]
+ %tmp1314 = zext i8 %tmp13 to i32 ; <i32> [#uses=1]
+ %tmp151 = lshr i32 %tmp910, %tmp1314 ; <i32> [#uses=1]
+ %tmp1516 = trunc i32 %tmp151 to i8 ; <i8> [#uses=1]
+ %tmp18 = getelementptr %struct.FooBar* %up, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp19 = load i8* %tmp18, align 1 ; <i8> [#uses=1]
+ %tmp22 = and i8 %tmp1516, %tmp19 ; <i8> [#uses=1]
+ %tmp24 = getelementptr %struct.FooBar* %up, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp25 = load i8* %tmp24, align 1 ; <i8> [#uses=1]
+ %tmp26.mask = and i8 %tmp25, 1 ; <i8> [#uses=1]
+ %toBool = icmp eq i8 %tmp26.mask, 0 ; <i1> [#uses=1]
+ %toBool.not = xor i1 %toBool, true ; <i1> [#uses=1]
+ %toBool33 = icmp eq i8 %intra_flag, 0 ; <i1> [#uses=1]
+ %bothcond = or i1 %toBool.not, %toBool33 ; <i1> [#uses=1]
+ %iftmp.1.0 = select i1 %bothcond, i8 0, i8 1 ; <i8> [#uses=1]
+ %tmp40 = or i8 %tmp22, %iftmp.1.0 ; <i8> [#uses=1]
+ %tmp432 = and i8 %tmp40, 1 ; <i8> [#uses=1]
+ ret i8 %tmp432
+}
diff --git a/src/LLVM/test/Transforms/InstCombine/zext.ll b/src/LLVM/test/Transforms/InstCombine/zext.ll
new file mode 100644
index 0000000..295e44d
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstCombine/zext.ll
@@ -0,0 +1,11 @@
+; Tests to make sure elimination of casts is working correctly
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i64 @test_sext_zext(i16 %A) {
+ %c1 = zext i16 %A to i32 ; <i32> [#uses=1]
+ %c2 = sext i32 %c1 to i64 ; <i64> [#uses=1]
+ ret i64 %c2
+; CHECK-NOT: %c1
+; CHECK: %c2 = zext i16 %A to i64
+; CHECK: ret i64 %c2
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Boolean.ll b/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Boolean.ll
new file mode 100644
index 0000000..3aa1bd6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Boolean.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i1 @add(i1 %x) {
+; CHECK: @add
+ %z = add i1 %x, %x
+ ret i1 %z
+; CHECK: ret i1 false
+}
+
+define i1 @sub(i1 %x) {
+; CHECK: @sub
+ %z = sub i1 false, %x
+ ret i1 %z
+; CHECK: ret i1 %x
+}
+
+define i1 @mul(i1 %x) {
+; CHECK: @mul
+ %z = mul i1 %x, %x
+ ret i1 %z
+; CHECK: ret i1 %x
+}
+
+define i1 @ne(i1 %x) {
+; CHECK: @ne
+ %z = icmp ne i1 %x, 0
+ ret i1 %z
+; CHECK: ret i1 %x
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Distribute.ll b/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Distribute.ll
new file mode 100644
index 0000000..d20abd6
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/2010-12-20-Distribute.ll
@@ -0,0 +1,62 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @factorize(i32 %x, i32 %y) {
+; CHECK: @factorize
+; (X | 1) & (X | 2) -> X | (1 & 2) -> X
+ %l = or i32 %x, 1
+ %r = or i32 %x, 2
+ %z = and i32 %l, %r
+ ret i32 %z
+; CHECK: ret i32 %x
+}
+
+define i32 @factorize2(i32 %x) {
+; CHECK: @factorize2
+; 3*X - 2*X -> X
+ %l = mul i32 3, %x
+ %r = mul i32 2, %x
+ %z = sub i32 %l, %r
+ ret i32 %z
+; CHECK: ret i32 %x
+}
+
+define i32 @factorize3(i32 %x, i32 %a, i32 %b) {
+; CHECK: @factorize3
+; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B
+ %aORb = or i32 %a, %b
+ %l = or i32 %x, %aORb
+ %r = or i32 %x, %b
+ %z = and i32 %l, %r
+ ret i32 %z
+; CHECK: ret i32 %r
+}
+
+define i32 @factorize4(i32 %x, i32 %y) {
+; CHECK: @factorize4
+ %sh = shl i32 %y, 1
+ %ml = mul i32 %sh, %x
+ %mr = mul i32 %x, %y
+ %s = sub i32 %ml, %mr
+ ret i32 %s
+; CHECK: ret i32 %mr
+}
+
+define i32 @factorize5(i32 %x, i32 %y) {
+; CHECK: @factorize5
+ %sh = mul i32 %y, 2
+ %ml = mul i32 %sh, %x
+ %mr = mul i32 %x, %y
+ %s = sub i32 %ml, %mr
+ ret i32 %s
+; CHECK: ret i32 %mr
+}
+
+define i32 @expand(i32 %x) {
+; CHECK: @expand
+; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
+ %a = and i32 %x, 1
+ %b = or i32 %a, 2
+ %c = and i32 %b, 1
+ ret i32 %c
+; CHECK: ret i32 %a
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/2011-01-14-Thread.ll b/src/LLVM/test/Transforms/InstSimplify/2011-01-14-Thread.ll
new file mode 100644
index 0000000..8fc4dc5
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/2011-01-14-Thread.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @shift_select(i1 %cond) {
+; CHECK: @shift_select
+ %s = select i1 %cond, i32 0, i32 1
+ %r = lshr i32 %s, 1
+ ret i32 %r
+; CHECK: ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/2011-02-01-Vector.ll b/src/LLVM/test/Transforms/InstSimplify/2011-02-01-Vector.ll
new file mode 100644
index 0000000..3039a66
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/2011-02-01-Vector.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define <2 x i32> @sdiv(<2 x i32> %x) {
+; CHECK: @sdiv
+ %div = sdiv <2 x i32> %x, <i32 1, i32 1>
+ ret <2 x i32> %div
+; CHECK: ret <2 x i32> %x
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll b/src/LLVM/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
new file mode 100644
index 0000000..d10c61f
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+declare void @bar()
+
+define void @test1() {
+entry:
+ invoke void @bar() to label %cont unwind label %lpad
+cont:
+ ret void
+lpad:
+ %ex = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0 cleanup
+ %exc_ptr = extractvalue { i8*, i32 } %ex, 0
+ %filter = extractvalue { i8*, i32 } %ex, 1
+ %exc_ptr2 = insertvalue { i8*, i32 } undef, i8* %exc_ptr, 0
+ %filter2 = insertvalue { i8*, i32 } %exc_ptr2, i32 %filter, 1
+ resume { i8*, i32 } %filter2
+; CHECK: @test1
+; CHECK-NOT: extractvalue
+; CHECK-NOT: insertvalue
+}
+
+declare i32 @__gxx_personality_v0(i32, i64, i8*, i8*)
+
+define { i8, i32 } @test2({ i8*, i32 } %x) {
+ %ex = extractvalue { i8*, i32 } %x, 1
+ %ins = insertvalue { i8, i32 } undef, i32 %ex, 1
+ ret { i8, i32 } %ins
+; CHECK: @test2
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/compare.ll b/src/LLVM/test/Transforms/InstSimplify/compare.ll
new file mode 100644
index 0000000..2cbd641
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/compare.ll
@@ -0,0 +1,325 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+target datalayout = "p:32:32"
+
+define i1 @ptrtoint() {
+; CHECK: @ptrtoint
+ %a = alloca i8
+ %tmp = ptrtoint i8* %a to i32
+ %r = icmp eq i32 %tmp, 0
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @zext(i32 %x) {
+; CHECK: @zext
+ %e1 = zext i32 %x to i64
+ %e2 = zext i32 %x to i64
+ %r = icmp eq i64 %e1, %e2
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @zext2(i1 %x) {
+; CHECK: @zext2
+ %e = zext i1 %x to i32
+ %c = icmp ne i32 %e, 0
+ ret i1 %c
+; CHECK: ret i1 %x
+}
+
+define i1 @zext3() {
+; CHECK: @zext3
+ %e = zext i1 1 to i32
+ %c = icmp ne i32 %e, 0
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @sext(i32 %x) {
+; CHECK: @sext
+ %e1 = sext i32 %x to i64
+ %e2 = sext i32 %x to i64
+ %r = icmp eq i64 %e1, %e2
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @sext2(i1 %x) {
+; CHECK: @sext2
+ %e = sext i1 %x to i32
+ %c = icmp ne i32 %e, 0
+ ret i1 %c
+; CHECK: ret i1 %x
+}
+
+define i1 @sext3() {
+; CHECK: @sext3
+ %e = sext i1 1 to i32
+ %c = icmp ne i32 %e, 0
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @add(i32 %x, i32 %y) {
+; CHECK: @add
+ %l = lshr i32 %x, 1
+ %q = lshr i32 %y, 1
+ %r = or i32 %q, 1
+ %s = add i32 %l, %r
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @add2(i8 %x, i8 %y) {
+; CHECK: @add2
+ %l = or i8 %x, 128
+ %r = or i8 %y, 129
+ %s = add i8 %l, %r
+ %c = icmp eq i8 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @add3(i8 %x, i8 %y) {
+; CHECK: @add3
+ %l = zext i8 %x to i32
+ %r = zext i8 %y to i32
+ %s = add i32 %l, %r
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 %c
+}
+
+define i1 @add4(i32 %x, i32 %y) {
+; CHECK: @add4
+ %z = add nsw i32 %y, 1
+ %s1 = add nsw i32 %x, %y
+ %s2 = add nsw i32 %x, %z
+ %c = icmp slt i32 %s1, %s2
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @add5(i32 %x, i32 %y) {
+; CHECK: @add5
+ %z = add nuw i32 %y, 1
+ %s1 = add nuw i32 %x, %z
+ %s2 = add nuw i32 %x, %y
+ %c = icmp ugt i32 %s1, %s2
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @addpowtwo(i32 %x, i32 %y) {
+; CHECK: @addpowtwo
+ %l = lshr i32 %x, 1
+ %r = shl i32 1, %y
+ %s = add i32 %l, %r
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @or(i32 %x) {
+; CHECK: @or
+ %o = or i32 %x, 1
+ %c = icmp eq i32 %o, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @shl(i32 %x) {
+; CHECK: @shl
+ %s = shl i32 1, %x
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @lshr1(i32 %x) {
+; CHECK: @lshr1
+ %s = lshr i32 -1, %x
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @lshr2(i32 %x) {
+; CHECK: @lshr2
+ %s = lshr i32 %x, 30
+ %c = icmp ugt i32 %s, 8
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @ashr1(i32 %x) {
+; CHECK: @ashr1
+ %s = ashr i32 -1, %x
+ %c = icmp eq i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @ashr2(i32 %x) {
+; CHECK: @ashr2
+ %s = ashr i32 %x, 30
+ %c = icmp slt i32 %s, -5
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @select1(i1 %cond) {
+; CHECK: @select1
+ %s = select i1 %cond, i32 1, i32 0
+ %c = icmp eq i32 %s, 1
+ ret i1 %c
+; CHECK: ret i1 %cond
+}
+
+define i1 @select2(i1 %cond) {
+; CHECK: @select2
+ %x = zext i1 %cond to i32
+ %s = select i1 %cond, i32 %x, i32 0
+ %c = icmp ne i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 %cond
+}
+
+define i1 @select3(i1 %cond) {
+; CHECK: @select3
+ %x = zext i1 %cond to i32
+ %s = select i1 %cond, i32 1, i32 %x
+ %c = icmp ne i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 %cond
+}
+
+define i1 @select4(i1 %cond) {
+; CHECK: @select4
+ %invert = xor i1 %cond, 1
+ %s = select i1 %invert, i32 0, i32 1
+ %c = icmp ne i32 %s, 0
+ ret i1 %c
+; CHECK: ret i1 %cond
+}
+
+define i1 @urem1(i32 %X, i32 %Y) {
+; CHECK: @urem1
+ %A = urem i32 %X, %Y
+ %B = icmp ult i32 %A, %Y
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @urem2(i32 %X, i32 %Y) {
+; CHECK: @urem2
+ %A = urem i32 %X, %Y
+ %B = icmp eq i32 %A, %Y
+ ret i1 %B
+; CHECK: ret i1 false
+}
+
+define i1 @urem3(i32 %X) {
+; CHECK: @urem3
+ %A = urem i32 %X, 10
+ %B = icmp ult i32 %A, 15
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @urem4(i32 %X) {
+; CHECK: @urem4
+ %A = urem i32 %X, 15
+ %B = icmp ult i32 %A, 10
+ ret i1 %B
+; CHECK: ret i1 %B
+}
+
+define i1 @urem5(i16 %X, i32 %Y) {
+; CHECK: @urem5
+ %A = zext i16 %X to i32
+ %B = urem i32 %A, %Y
+ %C = icmp slt i32 %B, %Y
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @urem6(i32 %X, i32 %Y) {
+; CHECK: @urem6
+ %A = urem i32 %X, %Y
+ %B = icmp ugt i32 %Y, %A
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @srem1(i32 %X) {
+; CHECK: @srem1
+ %A = srem i32 %X, -5
+ %B = icmp sgt i32 %A, 5
+ ret i1 %B
+; CHECK: ret i1 false
+}
+
+; PR9343 #15
+; CHECK: @srem2
+; CHECK: ret i1 false
+define i1 @srem2(i16 %X, i32 %Y) {
+ %A = zext i16 %X to i32
+ %B = add nsw i32 %A, 1
+ %C = srem i32 %B, %Y
+ %D = icmp slt i32 %C, 0
+ ret i1 %D
+}
+
+; CHECK: @srem3
+; CHECK-NEXT: ret i1 false
+define i1 @srem3(i16 %X, i32 %Y) {
+ %A = zext i16 %X to i32
+ %B = or i32 2147483648, %A
+ %C = sub nsw i32 1, %B
+ %D = srem i32 %C, %Y
+ %E = icmp slt i32 %D, 0
+ ret i1 %E
+}
+
+define i1 @udiv1(i32 %X) {
+; CHECK: @udiv1
+ %A = udiv i32 %X, 1000000
+ %B = icmp ult i32 %A, 5000
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @udiv2(i32 %X, i32 %Y, i32 %Z) {
+; CHECK: @udiv2
+ %A = udiv exact i32 10, %Z
+ %B = udiv exact i32 20, %Z
+ %C = icmp ult i32 %A, %B
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @sdiv1(i32 %X) {
+; CHECK: @sdiv1
+ %A = sdiv i32 %X, 1000000
+ %B = icmp slt i32 %A, 3000
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @or1(i32 %X) {
+; CHECK: @or1
+ %A = or i32 %X, 62
+ %B = icmp ult i32 %A, 50
+ ret i1 %B
+; CHECK: ret i1 false
+}
+
+define i1 @and1(i32 %X) {
+; CHECK: @and1
+ %A = and i32 %X, 62
+ %B = icmp ugt i32 %A, 70
+ ret i1 %B
+; CHECK: ret i1 false
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/dg.exp b/src/LLVM/test/Transforms/InstSimplify/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/InstSimplify/exact-nsw-nuw.ll b/src/LLVM/test/Transforms/InstSimplify/exact-nsw-nuw.ll
new file mode 100644
index 0000000..f3a804e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/exact-nsw-nuw.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+; PR8862
+
+; CHECK: @shift1
+; CHECK: ret i32 %A
+define i32 @shift1(i32 %A, i32 %B) {
+ %C = lshr exact i32 %A, %B
+ %D = shl nuw i32 %C, %B
+ ret i32 %D
+}
+
+; CHECK: @shift2
+; CHECK: lshr
+; CHECK: ret i32 %D
+define i32 @shift2(i32 %A, i32 %B) {
+ %C = lshr i32 %A, %B
+ %D = shl nuw i32 %C, %B
+ ret i32 %D
+}
+
+; CHECK: @shift3
+; CHECK: ret i32 %A
+define i32 @shift3(i32 %A, i32 %B) {
+ %C = ashr exact i32 %A, %B
+ %D = shl nuw i32 %C, %B
+ ret i32 %D
+}
+
+; CHECK: @shift4
+; CHECK: ret i32 %A
+define i32 @shift4(i32 %A, i32 %B) {
+ %C = shl nuw i32 %A, %B
+ %D = lshr i32 %C, %B
+ ret i32 %D
+}
+
+; CHECK: @shift5
+; CHECK: ret i32 %A
+define i32 @shift5(i32 %A, i32 %B) {
+ %C = shl nsw i32 %A, %B
+ %D = ashr i32 %C, %B
+ ret i32 %D
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/fdiv.ll b/src/LLVM/test/Transforms/InstSimplify/fdiv.ll
new file mode 100644
index 0000000..9d85154
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/fdiv.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define double @fdiv_of_undef(double %X) {
+; CHECK: @fdiv_of_undef
+; undef / X -> undef
+ %r = fdiv double undef, %X
+ ret double %r
+; CHECK: ret double undef
+}
+
+define double @fdiv_by_undef(double %X) {
+; CHECK: @fdiv_by_undef
+; X / undef -> undef
+ %r = fdiv double %X, undef
+ ret double %r
+; CHECK: ret double undef
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/maxmin.ll b/src/LLVM/test/Transforms/InstSimplify/maxmin.ll
new file mode 100644
index 0000000..e921214
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/maxmin.ll
@@ -0,0 +1,269 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i1 @max1(i32 %x, i32 %y) {
+; CHECK: @max1
+ %c = icmp sgt i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp slt i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @max2(i32 %x, i32 %y) {
+; CHECK: @max2
+ %c = icmp sge i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp sge i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @max3(i32 %x, i32 %y) {
+; CHECK: @max3
+ %c = icmp ugt i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp ult i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @max4(i32 %x, i32 %y) {
+; CHECK: @max4
+ %c = icmp uge i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp uge i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @max5(i32 %x, i32 %y) {
+; CHECK: @max5
+ %c = icmp sgt i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp sgt i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @max6(i32 %x, i32 %y) {
+; CHECK: @max6
+ %c = icmp sge i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp sle i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @max7(i32 %x, i32 %y) {
+; CHECK: @max7
+ %c = icmp ugt i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp ugt i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @max8(i32 %x, i32 %y) {
+; CHECK: @max8
+ %c = icmp uge i32 %x, %y
+ %m = select i1 %c, i32 %x, i32 %y
+ %r = icmp ule i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @min1(i32 %x, i32 %y) {
+; CHECK: @min1
+ %c = icmp sgt i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp sgt i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @min2(i32 %x, i32 %y) {
+; CHECK: @min2
+ %c = icmp sge i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp sle i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @min3(i32 %x, i32 %y) {
+; CHECK: @min3
+ %c = icmp ugt i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp ugt i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @min4(i32 %x, i32 %y) {
+; CHECK: @min4
+ %c = icmp uge i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp ule i32 %m, %x
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @min5(i32 %x, i32 %y) {
+; CHECK: @min5
+ %c = icmp sgt i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp slt i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @min6(i32 %x, i32 %y) {
+; CHECK: @min6
+ %c = icmp sge i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp sge i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @min7(i32 %x, i32 %y) {
+; CHECK: @min7
+ %c = icmp ugt i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp ult i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 false
+}
+
+define i1 @min8(i32 %x, i32 %y) {
+; CHECK: @min8
+ %c = icmp uge i32 %x, %y
+ %m = select i1 %c, i32 %y, i32 %x
+ %r = icmp uge i32 %x, %m
+ ret i1 %r
+; CHECK: ret i1 true
+}
+
+define i1 @maxmin1(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin1
+ %c1 = icmp sge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp sge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp sge i32 %max, %min
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @maxmin2(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin2
+ %c1 = icmp sge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp sge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp sgt i32 %min, %max
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @maxmin3(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin3
+ %c1 = icmp sge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp sge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp sle i32 %min, %max
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @maxmin4(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin4
+ %c1 = icmp sge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp sge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp slt i32 %max, %min
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @maxmin5(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin5
+ %c1 = icmp uge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp uge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp uge i32 %max, %min
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @maxmin6(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin6
+ %c1 = icmp uge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp uge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp ugt i32 %min, %max
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @maxmin7(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin7
+ %c1 = icmp uge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp uge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp ule i32 %min, %max
+ ret i1 %c
+; CHECK: ret i1 true
+}
+
+define i1 @maxmin8(i32 %x, i32 %y, i32 %z) {
+; CHECK: @maxmin8
+ %c1 = icmp uge i32 %x, %y
+ %max = select i1 %c1, i32 %x, i32 %y
+ %c2 = icmp uge i32 %x, %z
+ %min = select i1 %c2, i32 %z, i32 %x
+ %c = icmp ult i32 %max, %min
+ ret i1 %c
+; CHECK: ret i1 false
+}
+
+define i1 @eqcmp1(i32 %x, i32 %y) {
+; CHECK: @eqcmp1
+ %c = icmp sge i32 %x, %y
+ %max = select i1 %c, i32 %x, i32 %y
+ %r = icmp eq i32 %max, %x
+ ret i1 %r
+; CHECK: ret i1 %c
+}
+
+define i1 @eqcmp2(i32 %x, i32 %y) {
+; CHECK: @eqcmp2
+ %c = icmp sge i32 %x, %y
+ %max = select i1 %c, i32 %x, i32 %y
+ %r = icmp eq i32 %x, %max
+ ret i1 %r
+; CHECK: ret i1 %c
+}
+
+define i1 @eqcmp3(i32 %x, i32 %y) {
+; CHECK: @eqcmp3
+ %c = icmp uge i32 %x, %y
+ %max = select i1 %c, i32 %x, i32 %y
+ %r = icmp eq i32 %max, %x
+ ret i1 %r
+; CHECK: ret i1 %c
+}
+
+define i1 @eqcmp4(i32 %x, i32 %y) {
+; CHECK: @eqcmp4
+ %c = icmp uge i32 %x, %y
+ %max = select i1 %c, i32 %x, i32 %y
+ %r = icmp eq i32 %x, %max
+ ret i1 %r
+; CHECK: ret i1 %c
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/reassociate.ll b/src/LLVM/test/Transforms/InstSimplify/reassociate.ll
new file mode 100644
index 0000000..3c8169e
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/reassociate.ll
@@ -0,0 +1,186 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @add1(i32 %x) {
+; CHECK: @add1
+; (X + -1) + 1 -> X
+ %l = add i32 %x, -1
+ %r = add i32 %l, 1
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @and1(i32 %x, i32 %y) {
+; CHECK: @and1
+; (X & Y) & X -> X & Y
+ %l = and i32 %x, %y
+ %r = and i32 %l, %x
+ ret i32 %r
+; CHECK: ret i32 %l
+}
+
+define i32 @and2(i32 %x, i32 %y) {
+; CHECK: @and2
+; X & (X & Y) -> X & Y
+ %r = and i32 %x, %y
+ %l = and i32 %x, %r
+ ret i32 %l
+; CHECK: ret i32 %r
+}
+
+define i32 @or1(i32 %x, i32 %y) {
+; CHECK: @or1
+; (X | Y) | X -> X | Y
+ %l = or i32 %x, %y
+ %r = or i32 %l, %x
+ ret i32 %r
+; CHECK: ret i32 %l
+}
+
+define i32 @or2(i32 %x, i32 %y) {
+; CHECK: @or2
+; X | (X | Y) -> X | Y
+ %r = or i32 %x, %y
+ %l = or i32 %x, %r
+ ret i32 %l
+; CHECK: ret i32 %r
+}
+
+define i32 @xor1(i32 %x, i32 %y) {
+; CHECK: @xor1
+; (X ^ Y) ^ X = Y
+ %l = xor i32 %x, %y
+ %r = xor i32 %l, %x
+ ret i32 %r
+; CHECK: ret i32 %y
+}
+
+define i32 @xor2(i32 %x, i32 %y) {
+; CHECK: @xor2
+; X ^ (X ^ Y) = Y
+ %r = xor i32 %x, %y
+ %l = xor i32 %x, %r
+ ret i32 %l
+; CHECK: ret i32 %y
+}
+
+define i32 @sub1(i32 %x, i32 %y) {
+; CHECK: @sub1
+ %d = sub i32 %x, %y
+ %r = sub i32 %x, %d
+ ret i32 %r
+; CHECK: ret i32 %y
+}
+
+define i32 @sub2(i32 %x) {
+; CHECK: @sub2
+; X - (X + 1) -> -1
+ %xp1 = add i32 %x, 1
+ %r = sub i32 %x, %xp1
+ ret i32 %r
+; CHECK: ret i32 -1
+}
+
+define i32 @sub3(i32 %x, i32 %y) {
+; CHECK: @sub3
+; ((X + 1) + Y) - (Y + 1) -> X
+ %xp1 = add i32 %x, 1
+ %lhs = add i32 %xp1, %y
+ %rhs = add i32 %y, 1
+ %r = sub i32 %lhs, %rhs
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @sdiv1(i32 %x, i32 %y) {
+; CHECK: @sdiv1
+; (no overflow X * Y) / Y -> X
+ %mul = mul nsw i32 %x, %y
+ %r = sdiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @sdiv2(i32 %x, i32 %y) {
+; CHECK: @sdiv2
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = sdiv i32 %x, %y
+ %mul = mul i32 %div, %y
+ %r = sdiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %div
+}
+
+define i32 @sdiv3(i32 %x, i32 %y) {
+; CHECK: @sdiv3
+; (X rem Y) / Y -> 0
+ %rem = srem i32 %x, %y
+ %div = sdiv i32 %rem, %y
+ ret i32 %div
+; CHECK: ret i32 0
+}
+
+define i32 @sdiv4(i32 %x, i32 %y) {
+; CHECK: @sdiv4
+; (X / Y) * Y -> X if the division is exact
+ %div = sdiv exact i32 %x, %y
+ %mul = mul i32 %div, %y
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
+define i32 @sdiv5(i32 %x, i32 %y) {
+; CHECK: @sdiv5
+; Y * (X / Y) -> X if the division is exact
+ %div = sdiv exact i32 %x, %y
+ %mul = mul i32 %y, %div
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
+
+define i32 @udiv1(i32 %x, i32 %y) {
+; CHECK: @udiv1
+; (no overflow X * Y) / Y -> X
+ %mul = mul nuw i32 %x, %y
+ %r = udiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %x
+}
+
+define i32 @udiv2(i32 %x, i32 %y) {
+; CHECK: @udiv2
+; (((X / Y) * Y) / Y) -> X / Y
+ %div = udiv i32 %x, %y
+ %mul = mul i32 %div, %y
+ %r = udiv i32 %mul, %y
+ ret i32 %r
+; CHECK: ret i32 %div
+}
+
+define i32 @udiv3(i32 %x, i32 %y) {
+; CHECK: @udiv3
+; (X rem Y) / Y -> 0
+ %rem = urem i32 %x, %y
+ %div = udiv i32 %rem, %y
+ ret i32 %div
+; CHECK: ret i32 0
+}
+
+define i32 @udiv4(i32 %x, i32 %y) {
+; CHECK: @udiv4
+; (X / Y) * Y -> X if the division is exact
+ %div = udiv exact i32 %x, %y
+ %mul = mul i32 %div, %y
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
+define i32 @udiv5(i32 %x, i32 %y) {
+; CHECK: @udiv5
+; Y * (X / Y) -> X if the division is exact
+ %div = udiv exact i32 %x, %y
+ %mul = mul i32 %y, %div
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
diff --git a/src/LLVM/test/Transforms/InstSimplify/rem.ll b/src/LLVM/test/Transforms/InstSimplify/rem.ll
new file mode 100644
index 0000000..4c8f87c
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/rem.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i32 @select1(i32 %x, i1 %b) {
+; CHECK: @select1
+ %rhs = select i1 %b, i32 %x, i32 1
+ %rem = srem i32 %x, %rhs
+ ret i32 %rem
+; CHECK: ret i32 0
+}
+
+define i32 @select2(i32 %x, i1 %b) {
+; CHECK: @select2
+ %rhs = select i1 %b, i32 %x, i32 1
+ %rem = urem i32 %x, %rhs
+ ret i32 %rem
+; CHECK: ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/InstSimplify/undef.ll b/src/LLVM/test/Transforms/InstSimplify/undef.ll
new file mode 100644
index 0000000..8134cc8
--- /dev/null
+++ b/src/LLVM/test/Transforms/InstSimplify/undef.ll
@@ -0,0 +1,127 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+; @test0
+; CHECK: ret i64 undef
+define i64 @test0() {
+ %r = mul i64 undef, undef
+ ret i64 %r
+}
+
+; @test1
+; CHECK: ret i64 undef
+define i64 @test1() {
+ %r = mul i64 3, undef
+ ret i64 %r
+}
+
+; @test2
+; CHECK: ret i64 undef
+define i64 @test2() {
+ %r = mul i64 undef, 3
+ ret i64 %r
+}
+
+; @test3
+; CHECK: ret i64 0
+define i64 @test3() {
+ %r = mul i64 undef, 6
+ ret i64 %r
+}
+
+; @test4
+; CHECK: ret i64 0
+define i64 @test4() {
+ %r = mul i64 6, undef
+ ret i64 %r
+}
+
+; @test5
+; CHECK: ret i64 undef
+define i64 @test5() {
+ %r = and i64 undef, undef
+ ret i64 %r
+}
+
+; @test6
+; CHECK: ret i64 undef
+define i64 @test6() {
+ %r = or i64 undef, undef
+ ret i64 %r
+}
+
+; @test7
+; CHECK: ret i64 undef
+define i64 @test7() {
+ %r = udiv i64 undef, 1
+ ret i64 %r
+}
+
+; @test8
+; CHECK: ret i64 undef
+define i64 @test8() {
+ %r = sdiv i64 undef, 1
+ ret i64 %r
+}
+
+; @test9
+; CHECK: ret i64 0
+define i64 @test9() {
+ %r = urem i64 undef, 1
+ ret i64 %r
+}
+
+; @test10
+; CHECK: ret i64 0
+define i64 @test10() {
+ %r = srem i64 undef, 1
+ ret i64 %r
+}
+
+; @test11
+; CHECK: ret i64 undef
+define i64 @test11() {
+ %r = shl i64 undef, undef
+ ret i64 %r
+}
+
+; @test12
+; CHECK: ret i64 undef
+define i64 @test12() {
+ %r = ashr i64 undef, undef
+ ret i64 %r
+}
+
+; @test13
+; CHECK: ret i64 undef
+define i64 @test13() {
+ %r = lshr i64 undef, undef
+ ret i64 %r
+}
+
+; @test14
+; CHECK: ret i1 undef
+define i1 @test14() {
+ %r = icmp slt i64 undef, undef
+ ret i1 %r
+}
+
+; @test15
+; CHECK: ret i1 undef
+define i1 @test15() {
+ %r = icmp ult i64 undef, undef
+ ret i1 %r
+}
+
+; @test16
+; CHECK: ret i64 undef
+define i64 @test16(i64 %a) {
+ %r = select i1 undef, i64 %a, i64 undef
+ ret i64 %r
+}
+
+; @test17
+; CHECK: ret i64 undef
+define i64 @test17(i64 %a) {
+ %r = select i1 undef, i64 undef, i64 %a
+ ret i64 %r
+}
diff --git a/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll b/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll
new file mode 100644
index 0000000..a85e834
--- /dev/null
+++ b/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll
@@ -0,0 +1,27 @@
+; No arguments means internalize all but main
+; RUN: opt < %s -internalize -S | grep internal | count 4
+; Internalize all but foo and j
+; RUN: opt < %s -internalize -internalize-public-api-list foo -internalize-public-api-list j -S | grep internal | count 3
+; Non existent files should be treated as if they were empty (so internalize all but main)
+; RUN: opt < %s -internalize -internalize-public-api-file /nonexistent/file 2> /dev/null -S | grep internal | count 4
+; RUN: opt < %s -internalize -internalize-public-api-list bar -internalize-public-api-list foo -internalize-public-api-file /nonexistent/file 2> /dev/null -S | grep internal | count 3
+; -file and -list options should be merged, the .apifile contains foo and j
+; RUN: opt < %s -internalize -internalize-public-api-list bar -internalize-public-api-file %s.apifile -S | grep internal | count 2
+
+@i = weak global i32 0 ; <i32*> [#uses=0]
+@j = weak global i32 0 ; <i32*> [#uses=0]
+
+define void @main(...) {
+entry:
+ ret void
+}
+
+define void @foo(...) {
+entry:
+ ret void
+}
+
+define void @bar(...) {
+entry:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll.apifile b/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll.apifile
new file mode 100644
index 0000000..f6c58b8
--- /dev/null
+++ b/src/LLVM/test/Transforms/Internalize/2008-05-09-AllButMain.ll.apifile
@@ -0,0 +1,2 @@
+foo
+j
diff --git a/src/LLVM/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll b/src/LLVM/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll
new file mode 100644
index 0000000..7b18a04
--- /dev/null
+++ b/src/LLVM/test/Transforms/Internalize/2009-01-05-InternalizeAliases.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -internalize -S | grep internal | count 3
+
+@A = global i32 0
+@B = alias i32* @A
+@C = alias i32* @B
+
+define i32 @main() {
+ %tmp = load i32* @C
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/Internalize/available_externally.ll b/src/LLVM/test/Transforms/Internalize/available_externally.ll
new file mode 100644
index 0000000..a2cf23f
--- /dev/null
+++ b/src/LLVM/test/Transforms/Internalize/available_externally.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -internalize -internalize-public-api-list foo -S | FileCheck %s
+
+; CHECK: define void @foo
+define void @foo() {
+ ret void
+}
+
+; CHECK: define internal void @zed
+define void @zed() {
+ ret void
+}
+
+; CHECK: define available_externally void @bar
+define available_externally void @bar() {
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Internalize/dg.exp b/src/LLVM/test/Transforms/Internalize/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/Internalize/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll b/src/LLVM/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll
new file mode 100644
index 0000000..b5d1065
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/2008-11-27-EntryMunge.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -jump-threading -S | grep {ret i32 0}
+; PR3138
+
+define i32 @jt() {
+entry:
+ br i1 true, label %bb3, label %bb
+
+bb: ; preds = %entry
+ unreachable
+
+bb3: ; preds = %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/2010-08-26-and.ll b/src/LLVM/test/Transforms/JumpThreading/2010-08-26-and.ll
new file mode 100644
index 0000000..2d6caf7
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/2010-08-26-and.ll
@@ -0,0 +1,162 @@
+; RUN: opt -jump-threading -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+%class.StringSwitch = type { i8*, i32, i32, i8 }
+
+@.str = private constant [4 x i8] c"red\00" ; <[4 x i8]*> [#uses=1]
+@.str1 = private constant [7 x i8] c"orange\00" ; <[7 x i8]*> [#uses=1]
+@.str2 = private constant [7 x i8] c"yellow\00" ; <[7 x i8]*> [#uses=1]
+@.str3 = private constant [6 x i8] c"green\00" ; <[6 x i8]*> [#uses=1]
+@.str4 = private constant [5 x i8] c"blue\00" ; <[5 x i8]*> [#uses=1]
+@.str5 = private constant [7 x i8] c"indigo\00" ; <[7 x i8]*> [#uses=1]
+@.str6 = private constant [7 x i8] c"violet\00" ; <[7 x i8]*> [#uses=1]
+@.str7 = private constant [12 x i8] c"Color = %d\0A\00" ; <[12 x i8]*> [#uses=1]
+
+define i32 @main(i32 %argc, i8** nocapture %argv) nounwind ssp {
+entry:
+ %cmp142 = icmp sgt i32 %argc, 1 ; <i1> [#uses=1]
+ br i1 %cmp142, label %bb.nph, label %for.end
+
+bb.nph: ; preds = %entry
+ %tmp = add i32 %argc, -2 ; <i32> [#uses=1]
+ %tmp144 = zext i32 %tmp to i64 ; <i64> [#uses=1]
+ %tmp145 = add i64 %tmp144, 1 ; <i64> [#uses=1]
+ br label %land.lhs.true.i
+
+land.lhs.true.i: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134, %bb.nph
+ %retval.0.i.pre161 = phi i32 [ undef, %bb.nph ], [ %retval.0.i.pre, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134 ] ; <i32> [#uses=3]
+ %indvar = phi i64 [ 0, %bb.nph ], [ %tmp146, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134 ] ; <i64> [#uses=1]
+ %tmp146 = add i64 %indvar, 1 ; <i64> [#uses=3]
+ %arrayidx = getelementptr i8** %argv, i64 %tmp146 ; <i8**> [#uses=1]
+ %tmp6 = load i8** %arrayidx, align 8 ; <i8*> [#uses=8]
+ %call.i.i = call i64 @strlen(i8* %tmp6) nounwind ; <i64> [#uses=1]
+ %conv.i.i = trunc i64 %call.i.i to i32 ; <i32> [#uses=6]\
+; CHECK: switch i32 %conv.i.i
+; CHECK-NOT: if.then.i40
+; CHECK: }
+ switch i32 %conv.i.i, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit [
+ i32 3, label %land.lhs.true5.i
+ i32 6, label %land.lhs.true5.i37
+ ]
+
+land.lhs.true5.i: ; preds = %land.lhs.true.i
+ %call.i = call i32 @memcmp(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i8* %tmp6, i64 4) nounwind ; <i32> [#uses=1]
+ %cmp9.i = icmp eq i32 %call.i, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i, label %_ZN12StringSwitchI5ColorE4CaseILj4EEERS1_RAT__KcRKS0_.exit, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+
+_ZN12StringSwitchI5ColorE4CaseILj4EEERS1_RAT__KcRKS0_.exit: ; preds = %land.lhs.true5.i
+ br label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+
+land.lhs.true5.i37: ; preds = %land.lhs.true.i
+ %call.i35 = call i32 @memcmp(i8* getelementptr inbounds ([7 x i8]* @.str1, i64 0, i64 0), i8* %tmp6, i64 7) nounwind ; <i32> [#uses=1]
+ %cmp9.i36 = icmp eq i32 %call.i35, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i36, label %if.then.i40, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+
+if.then.i40: ; preds = %land.lhs.true5.i37
+ br label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+
+_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit: ; preds = %if.then.i40, %land.lhs.true5.i37, %_ZN12StringSwitchI5ColorE4CaseILj4EEERS1_RAT__KcRKS0_.exit, %land.lhs.true5.i, %land.lhs.true.i
+ %retval.0.i.pre159 = phi i32 [ 1, %_ZN12StringSwitchI5ColorE4CaseILj4EEERS1_RAT__KcRKS0_.exit ], [ %retval.0.i.pre161, %land.lhs.true5.i37 ], [ 2, %if.then.i40 ], [ %retval.0.i.pre161, %land.lhs.true5.i ], [ %retval.0.i.pre161, %land.lhs.true.i ] ; <i32> [#uses=2]
+ %tmp2.i44 = phi i8 [ 1, %_ZN12StringSwitchI5ColorE4CaseILj4EEERS1_RAT__KcRKS0_.exit ], [ 0, %land.lhs.true5.i37 ], [ 1, %if.then.i40 ], [ 0, %land.lhs.true5.i ], [ 0, %land.lhs.true.i ] ; <i8> [#uses=3]
+ %tobool.i46 = icmp eq i8 %tmp2.i44, 0 ; <i1> [#uses=1]
+ %cmp.i49 = icmp eq i32 %conv.i.i, 6 ; <i1> [#uses=1]
+ %or.cond = and i1 %tobool.i46, %cmp.i49 ; <i1> [#uses=1]
+ br i1 %or.cond, label %land.lhs.true5.i55, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60
+
+land.lhs.true5.i55: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+ %call.i53 = call i32 @memcmp(i8* getelementptr inbounds ([7 x i8]* @.str2, i64 0, i64 0), i8* %tmp6, i64 7) nounwind ; <i32> [#uses=1]
+ %cmp9.i54 = icmp eq i32 %call.i53, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i54, label %if.then.i58, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60
+
+if.then.i58: ; preds = %land.lhs.true5.i55
+ br label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60
+
+_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60: ; preds = %if.then.i58, %land.lhs.true5.i55, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit
+ %retval.0.i.pre158 = phi i32 [ %retval.0.i.pre159, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit ], [ %retval.0.i.pre159, %land.lhs.true5.i55 ], [ 3, %if.then.i58 ] ; <i32> [#uses=2]
+ %tmp2.i63 = phi i8 [ %tmp2.i44, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit ], [ %tmp2.i44, %land.lhs.true5.i55 ], [ 1, %if.then.i58 ] ; <i8> [#uses=3]
+ %tmp14.i64 = and i8 %tmp2.i63, 1 ; <i8> [#uses=1]
+ %tobool.i65 = icmp eq i8 %tmp14.i64, 0 ; <i1> [#uses=1]
+ %cmp.i68 = icmp eq i32 %conv.i.i, 5 ; <i1> [#uses=1]
+ %or.cond168 = and i1 %tobool.i65, %cmp.i68 ; <i1> [#uses=1]
+ br i1 %or.cond168, label %land.lhs.true5.i74, label %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit
+
+land.lhs.true5.i74: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60
+ %call.i72 = call i32 @memcmp(i8* getelementptr inbounds ([6 x i8]* @.str3, i64 0, i64 0), i8* %tmp6, i64 6) nounwind ; <i32> [#uses=1]
+ %cmp9.i73 = icmp eq i32 %call.i72, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i73, label %if.then.i77, label %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit
+
+if.then.i77: ; preds = %land.lhs.true5.i74
+ br label %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit
+
+_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit: ; preds = %if.then.i77, %land.lhs.true5.i74, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60
+ %retval.0.i.pre157 = phi i32 [ %retval.0.i.pre158, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60 ], [ %retval.0.i.pre158, %land.lhs.true5.i74 ], [ 4, %if.then.i77 ] ; <i32> [#uses=2]
+ %tmp2.i81 = phi i8 [ %tmp2.i63, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit60 ], [ %tmp2.i63, %land.lhs.true5.i74 ], [ 1, %if.then.i77 ] ; <i8> [#uses=3]
+ %tmp14.i82 = and i8 %tmp2.i81, 1 ; <i8> [#uses=1]
+ %tobool.i83 = icmp eq i8 %tmp14.i82, 0 ; <i1> [#uses=1]
+ %cmp.i86 = icmp eq i32 %conv.i.i, 4 ; <i1> [#uses=1]
+ %or.cond169 = and i1 %tobool.i83, %cmp.i86 ; <i1> [#uses=1]
+ br i1 %or.cond169, label %land.lhs.true5.i92, label %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit
+
+land.lhs.true5.i92: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit
+ %call.i90 = call i32 @memcmp(i8* getelementptr inbounds ([5 x i8]* @.str4, i64 0, i64 0), i8* %tmp6, i64 5) nounwind ; <i32> [#uses=1]
+ %cmp9.i91 = icmp eq i32 %call.i90, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i91, label %if.then.i95, label %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit
+
+if.then.i95: ; preds = %land.lhs.true5.i92
+ br label %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit
+
+_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit: ; preds = %if.then.i95, %land.lhs.true5.i92, %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit
+ %retval.0.i.pre156 = phi i32 [ %retval.0.i.pre157, %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit ], [ %retval.0.i.pre157, %land.lhs.true5.i92 ], [ 5, %if.then.i95 ] ; <i32> [#uses=2]
+ %tmp2.i99 = phi i8 [ %tmp2.i81, %_ZN12StringSwitchI5ColorE4CaseILj6EEERS1_RAT__KcRKS0_.exit ], [ %tmp2.i81, %land.lhs.true5.i92 ], [ 1, %if.then.i95 ] ; <i8> [#uses=3]
+ %tmp14.i100 = and i8 %tmp2.i99, 1 ; <i8> [#uses=1]
+ %tobool.i101 = icmp eq i8 %tmp14.i100, 0 ; <i1> [#uses=1]
+ %cmp.i104 = icmp eq i32 %conv.i.i, 6 ; <i1> [#uses=1]
+ %or.cond170 = and i1 %tobool.i101, %cmp.i104 ; <i1> [#uses=1]
+ br i1 %or.cond170, label %land.lhs.true5.i110, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115
+
+land.lhs.true5.i110: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit
+ %call.i108 = call i32 @memcmp(i8* getelementptr inbounds ([7 x i8]* @.str5, i64 0, i64 0), i8* %tmp6, i64 7) nounwind ; <i32> [#uses=1]
+ %cmp9.i109 = icmp eq i32 %call.i108, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i109, label %if.then.i113, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115
+
+if.then.i113: ; preds = %land.lhs.true5.i110
+ br label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115
+
+_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115: ; preds = %if.then.i113, %land.lhs.true5.i110, %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit
+ %retval.0.i.pre155 = phi i32 [ %retval.0.i.pre156, %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit ], [ %retval.0.i.pre156, %land.lhs.true5.i110 ], [ 6, %if.then.i113 ] ; <i32> [#uses=2]
+ %tmp2.i118 = phi i8 [ %tmp2.i99, %_ZN12StringSwitchI5ColorE4CaseILj5EEERS1_RAT__KcRKS0_.exit ], [ %tmp2.i99, %land.lhs.true5.i110 ], [ 1, %if.then.i113 ] ; <i8> [#uses=3]
+ %tmp14.i119 = and i8 %tmp2.i118, 1 ; <i8> [#uses=1]
+ %tobool.i120 = icmp eq i8 %tmp14.i119, 0 ; <i1> [#uses=1]
+ %cmp.i123 = icmp eq i32 %conv.i.i, 6 ; <i1> [#uses=1]
+ %or.cond171 = and i1 %tobool.i120, %cmp.i123 ; <i1> [#uses=1]
+ br i1 %or.cond171, label %land.lhs.true5.i129, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134
+
+land.lhs.true5.i129: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115
+ %call.i127 = call i32 @memcmp(i8* getelementptr inbounds ([7 x i8]* @.str6, i64 0, i64 0), i8* %tmp6, i64 7) nounwind ; <i32> [#uses=1]
+ %cmp9.i128 = icmp eq i32 %call.i127, 0 ; <i1> [#uses=1]
+ br i1 %cmp9.i128, label %if.then.i132, label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134
+
+if.then.i132: ; preds = %land.lhs.true5.i129
+ br label %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134
+
+_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134: ; preds = %if.then.i132, %land.lhs.true5.i129, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115
+ %retval.0.i.pre = phi i32 [ %retval.0.i.pre155, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115 ], [ %retval.0.i.pre155, %land.lhs.true5.i129 ], [ 7, %if.then.i132 ] ; <i32> [#uses=2]
+ %tmp2.i137 = phi i8 [ %tmp2.i118, %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit115 ], [ %tmp2.i118, %land.lhs.true5.i129 ], [ 1, %if.then.i132 ] ; <i8> [#uses=1]
+ %tmp7.i138 = and i8 %tmp2.i137, 1 ; <i8> [#uses=1]
+ %tobool.i139 = icmp eq i8 %tmp7.i138, 0 ; <i1> [#uses=1]
+ %retval.0.i = select i1 %tobool.i139, i32 0, i32 %retval.0.i.pre ; <i32> [#uses=1]
+ %call22 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str7, i64 0, i64 0), i32 %retval.0.i) ; <i32> [#uses=0]
+ %exitcond = icmp eq i64 %tmp146, %tmp145 ; <i1> [#uses=1]
+ br i1 %exitcond, label %for.end, label %land.lhs.true.i
+
+for.end: ; preds = %_ZN12StringSwitchI5ColorE4CaseILj7EEERS1_RAT__KcRKS0_.exit134, %entry
+ ret i32 0
+}
+
+declare i32 @printf(i8* nocapture, ...) nounwind
+
+declare i32 @memcmp(i8* nocapture, i8* nocapture, i64) nounwind readonly
+
+declare i64 @strlen(i8* nocapture) nounwind readonly
diff --git a/src/LLVM/test/Transforms/JumpThreading/2011-04-02-SimplifyDeadBlock.ll b/src/LLVM/test/Transforms/JumpThreading/2011-04-02-SimplifyDeadBlock.ll
new file mode 100644
index 0000000..76dd2d1
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/2011-04-02-SimplifyDeadBlock.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -jump-threading
+; PR9446
+; Just check that it doesn't crash
+
+define void @int327() nounwind {
+entry:
+ unreachable
+
+for.cond: ; preds = %for.cond4
+ %tobool3 = icmp eq i8 undef, 0
+ br i1 %tobool3, label %for.cond23, label %for.cond4
+
+for.cond4: ; preds = %for.cond
+ br label %for.cond
+
+for.cond23: ; preds = %for.body28, %for.cond23, %for.cond
+ %conv321 = phi i32 [ %conv32, %for.body28 ], [ 0, %for.cond ], [ %conv321, %for.cond23 ]
+ %l_266.0 = phi i32 [ %phitmp, %for.body28 ], [ 0, %for.cond ], [ 0, %for.cond23 ]
+ %cmp26 = icmp eq i32 %l_266.0, 0
+ br i1 %cmp26, label %for.body28, label %for.cond23
+
+for.body28: ; preds = %for.cond23
+ %and = and i32 %conv321, 1
+ %conv32 = zext i8 undef to i32
+ %add = add nsw i32 %l_266.0, 1
+ %phitmp = and i32 %add, 255
+ br label %for.cond23
+
+if.end43: ; No predecessors!
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/JumpThreading/2011-04-14-InfLoop.ll b/src/LLVM/test/Transforms/JumpThreading/2011-04-14-InfLoop.ll
new file mode 100644
index 0000000..46aaa00
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/2011-04-14-InfLoop.ll
@@ -0,0 +1,31 @@
+; RUN: opt -jump-threading < %s
+; <rdar://problem/9284786>
+
+%0 = type <{ i64, i16, i64, i8, i8 }>
+
+@g_338 = external global %0, align 8
+
+define void @func_1() nounwind ssp {
+entry:
+ ret void
+
+for.cond1177:
+ %inc1187 = add nsw i32 0, 1
+ %cmp1179 = icmp slt i32 %inc1187, 5
+ br i1 %cmp1179, label %for.cond1177, label %land.rhs1320
+
+land.rhs1320:
+ %tmp1324 = volatile load i64* getelementptr inbounds (%0* @g_338, i64 0, i32 2), align 1, !tbaa !0
+ br label %if.end.i
+
+if.end.i:
+ %tobool.pr.i = phi i1 [ false, %if.end.i ], [ false, %land.rhs1320 ]
+ br i1 %tobool.pr.i, label %return, label %if.end.i
+
+return:
+ ret void
+}
+
+!0 = metadata !{metadata !"long long", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
diff --git a/src/LLVM/test/Transforms/JumpThreading/and-and-cond.ll b/src/LLVM/test/Transforms/JumpThreading/and-and-cond.ll
new file mode 100644
index 0000000..765d940
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/and-and-cond.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -jump-threading -mem2reg -instcombine -simplifycfg -S | FileCheck %s
+
+declare i32 @f1()
+declare i32 @f2()
+declare void @f3()
+
+define i32 @test(i1 %cond, i1 %cond2, i1 %cond3) {
+; CHECK: test
+ br i1 %cond, label %T1, label %F1
+
+; CHECK-NOT: T1:
+T1:
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+; CHECK: Merge:
+; CHECK: %v1 = call i32 @f1()
+; CHECK-NEXT: %D = and i1 %cond2, %cond3
+; CHECK-NEXT: br i1 %D
+ %A = phi i1 [true, %T1], [false, %F1]
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ %C = and i1 %A, %cond2
+ %D = and i1 %C, %cond3
+ br i1 %D, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/and-cond.ll b/src/LLVM/test/Transforms/JumpThreading/and-cond.ll
new file mode 100644
index 0000000..0159bb3
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/and-cond.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -jump-threading -mem2reg -instcombine -simplifycfg -S | FileCheck %s
+
+declare i32 @f1()
+declare i32 @f2()
+declare void @f3()
+
+define i32 @test(i1 %cond, i1 %cond2) {
+; CHECK: test
+ br i1 %cond, label %T1, label %F1
+
+; CHECK-NOT: T1
+T1:
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+; CHECK: Merge:
+; CHECK: %v1 = call i32 @f1()
+; CHECK-NEXT: br i1 %cond2
+ %A = phi i1 [true, %T1], [false, %F1]
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ %C = and i1 %A, %cond2
+ br i1 %C, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/basic.ll b/src/LLVM/test/Transforms/JumpThreading/basic.ll
new file mode 100644
index 0000000..4627137
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/basic.ll
@@ -0,0 +1,478 @@
+; RUN: opt %s -jump-threading -S | FileCheck %s
+
+declare i32 @f1()
+declare i32 @f2()
+declare void @f3()
+
+define i32 @test1(i1 %cond) {
+; CHECK: @test1
+
+ br i1 %cond, label %T1, label %F1
+
+T1:
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+ %A = phi i1 [true, %T1], [false, %F1]
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ br i1 %A, label %T2, label %F2
+
+T2:
+; CHECK: T2:
+; CHECK: ret i32 %v1
+ call void @f3()
+ ret i32 %B
+
+F2:
+; CHECK: F2:
+; CHECK: ret i32 %v2
+ ret i32 %B
+}
+
+
+;; cond is known false on Entry -> F1 edge!
+define i32 @test2(i1 %cond) {
+; CHECK: @test2
+Entry:
+ br i1 %cond, label %T1, label %F1
+
+T1:
+; CHECK: %v1 = call i32 @f1()
+; CHECK: ret i32 47
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ br i1 %cond, label %Merge, label %F2
+
+Merge:
+ %B = phi i32 [47, %T1], [192, %F1]
+ ret i32 %B
+
+F2:
+ call void @f3()
+ ret i32 12
+}
+
+
+; Undef handling.
+define i32 @test3(i1 %cond) {
+; CHECK: @test3
+; CHECK-NEXT: T1:
+; CHECK-NEXT: ret i32 42
+ br i1 undef, label %T1, label %F1
+
+T1:
+ ret i32 42
+
+F1:
+ ret i32 17
+}
+
+define i32 @test4(i1 %cond, i1 %cond2) {
+; CHECK: @test4
+
+ br i1 %cond, label %T1, label %F1
+
+T1:
+; CHECK: %v1 = call i32 @f1()
+; CHECK-NEXT: br label %T
+
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+; CHECK: %v2 = call i32 @f2()
+; CHECK-NEXT: br i1 %cond2,
+ br label %Merge
+
+Merge:
+ %A = phi i1 [undef, %T1], [%cond2, %F1]
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ br i1 %A, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+}
+
+
+;; This tests that the branch in 'merge' can be cloned up into T1.
+define i32 @test5(i1 %cond, i1 %cond2) {
+; CHECK: @test5
+
+ br i1 %cond, label %T1, label %F1
+
+T1:
+; CHECK: T1:
+; CHECK-NEXT: %v1 = call i32 @f1()
+; CHECK-NEXT: %cond3 = icmp eq i32 %v1, 412
+; CHECK-NEXT: br i1 %cond3, label %T2, label %F2
+
+ %v1 = call i32 @f1()
+ %cond3 = icmp eq i32 %v1, 412
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+ %A = phi i1 [%cond3, %T1], [%cond2, %F1]
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ br i1 %A, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+}
+
+
+;; Lexically duplicated conditionals should be threaded.
+
+
+define i32 @test6(i32 %A) {
+; CHECK: @test6
+ %tmp455 = icmp eq i32 %A, 42
+ br i1 %tmp455, label %BB1, label %BB2
+
+; CHECK: call i32 @f2()
+; CHECK-NEXT: ret i32 3
+
+; CHECK: call i32 @f1()
+; CHECK-NOT: br
+; CHECK: call void @f3()
+; CHECK-NOT: br
+; CHECK: ret i32 4
+
+BB2:
+ call i32 @f1()
+ br label %BB1
+
+
+BB1:
+ %tmp459 = icmp eq i32 %A, 42
+ br i1 %tmp459, label %BB3, label %BB4
+
+BB3:
+ call i32 @f2()
+ ret i32 3
+
+BB4:
+ call void @f3()
+ ret i32 4
+}
+
+
+;; This tests that the branch in 'merge' can be cloned up into T1.
+;; rdar://7367025
+define i32 @test7(i1 %cond, i1 %cond2) {
+Entry:
+; CHECK: @test7
+ %v1 = call i32 @f1()
+ br i1 %cond, label %Merge, label %F1
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+ %B = phi i32 [%v1, %Entry], [%v2, %F1]
+ %M = icmp ne i32 %B, %v1
+ %N = icmp eq i32 %B, 47
+ %O = and i1 %M, %N
+ br i1 %O, label %T2, label %F2
+
+; CHECK: Merge:
+; CHECK-NOT: phi
+; CHECK-NEXT: %v2 = call i32 @f2()
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+; CHECK: F2:
+; CHECK-NEXT: phi i32
+}
+
+
+declare i1 @test8a()
+
+define i32 @test8b(i1 %cond, i1 %cond2) {
+; CHECK: @test8b
+T0:
+ %A = call i1 @test8a()
+ br i1 %A, label %T1, label %F1
+
+; CHECK: T0:
+; CHECK-NEXT: call
+; CHECK-NEXT: br i1 %A, label %T1, label %Y
+
+T1:
+ %B = call i1 @test8a()
+ br i1 %B, label %T2, label %F1
+
+; CHECK: T1:
+; CHECK-NEXT: call
+; CHECK-NEXT: br i1 %B, label %T2, label %Y
+T2:
+ %C = call i1 @test8a()
+ br i1 %cond, label %T3, label %F1
+
+; CHECK: T2:
+; CHECK-NEXT: call
+; CHECK-NEXT: br i1 %cond, label %T3, label %Y
+T3:
+ ret i32 0
+
+F1:
+ %D = phi i32 [0, %T0], [0, %T1], [1, %T2]
+ %E = icmp eq i32 %D, 1
+ %F = and i1 %E, %cond
+ br i1 %F, label %X, label %Y
+X:
+ call i1 @test8a()
+ ret i32 1
+Y:
+ ret i32 2
+}
+
+
+;;; Verify that we can handle constraint propagation through "xor x, 1".
+define i32 @test9(i1 %cond, i1 %cond2) {
+Entry:
+; CHECK: @test9
+ %v1 = call i32 @f1()
+ br i1 %cond, label %Merge, label %F1
+
+; CHECK: Entry:
+; CHECK-NEXT: %v1 = call i32 @f1()
+; CHECK-NEXT: br i1 %cond, label %F2, label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+ %B = phi i32 [%v1, %Entry], [%v2, %F1]
+ %M = icmp eq i32 %B, %v1
+ %M1 = xor i1 %M, 1
+ %N = icmp eq i32 %B, 47
+ %O = and i1 %M1, %N
+ br i1 %O, label %T2, label %F2
+
+; CHECK: Merge:
+; CHECK-NOT: phi
+; CHECK-NEXT: %v2 = call i32 @f2()
+
+T2:
+ %Q = zext i1 %M to i32
+ ret i32 %Q
+
+F2:
+ ret i32 %B
+; CHECK: F2:
+; CHECK-NEXT: phi i32
+}
+
+
+
+; CHECK: @test10
+declare i32 @test10f1()
+declare i32 @test10f2()
+declare void @test10f3()
+
+;; Non-local condition threading.
+define i32 @test10g(i1 %cond) {
+; CHECK: @test10g
+; CHECK-NEXT: br i1 %cond, label %T2, label %F2
+ br i1 %cond, label %T1, label %F1
+
+T1:
+ %v1 = call i32 @test10f1()
+ br label %Merge
+
+; CHECK: %v1 = call i32 @test10f1()
+; CHECK-NEXT: call void @f3()
+; CHECK-NEXT: ret i32 %v1
+
+F1:
+ %v2 = call i32 @test10f2()
+ br label %Merge
+
+Merge:
+ %B = phi i32 [%v1, %T1], [%v2, %F1]
+ br i1 %cond, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 %B
+
+F2:
+ ret i32 %B
+}
+
+
+; Impossible conditional constraints should get threaded. BB3 is dead here.
+define i32 @test11(i32 %A) {
+; CHECK: @test11
+; CHECK-NEXT: icmp
+; CHECK-NEXT: br i1 %tmp455, label %BB4, label %BB2
+ %tmp455 = icmp eq i32 %A, 42
+ br i1 %tmp455, label %BB1, label %BB2
+
+BB2:
+; CHECK: call i32 @f1()
+; CHECK-NEXT: ret i32 %C
+ %C = call i32 @f1()
+ ret i32 %C
+
+
+BB1:
+ %tmp459 = icmp eq i32 %A, 43
+ br i1 %tmp459, label %BB3, label %BB4
+
+BB3:
+ call i32 @f2()
+ ret i32 3
+
+BB4:
+ call void @f3()
+ ret i32 4
+}
+
+;; Correlated value through boolean expression. GCC PR18046.
+define void @test12(i32 %A) {
+; CHECK: @test12
+entry:
+ %cond = icmp eq i32 %A, 0
+ br i1 %cond, label %bb, label %bb1
+; Should branch to the return block instead of through BB1.
+; CHECK: entry:
+; CHECK-NEXT: %cond = icmp eq i32 %A, 0
+; CHECK-NEXT: br i1 %cond, label %bb1, label %return
+
+bb:
+ %B = call i32 @test10f2()
+ br label %bb1
+
+bb1:
+ %C = phi i32 [ %A, %entry ], [ %B, %bb ]
+ %cond4 = icmp eq i32 %C, 0
+ br i1 %cond4, label %bb2, label %return
+
+; CHECK: bb1:
+; CHECK-NEXT: %B = call i32 @test10f2()
+; CHECK-NEXT: %cond4 = icmp eq i32 %B, 0
+; CHECK-NEXT: br i1 %cond4, label %bb2, label %return
+
+bb2:
+ %D = call i32 @test10f2()
+ ret void
+
+return:
+ ret void
+}
+
+
+;; Duplicate condition to avoid xor of cond.
+;; rdar://7391699
+define i32 @test13(i1 %cond, i1 %cond2) {
+Entry:
+; CHECK: @test13
+ %v1 = call i32 @f1()
+ br i1 %cond, label %Merge, label %F1
+
+F1:
+ br label %Merge
+
+Merge:
+ %B = phi i1 [true, %Entry], [%cond2, %F1]
+ %C = phi i32 [192, %Entry], [%v1, %F1]
+ %M = icmp eq i32 %C, 192
+ %N = xor i1 %B, %M
+ br i1 %N, label %T2, label %F2
+
+T2:
+ ret i32 123
+
+F2:
+ ret i32 %v1
+
+; CHECK: br i1 %cond, label %F2, label %Merge
+
+; CHECK: Merge:
+; CHECK-NEXT: %M = icmp eq i32 %v1, 192
+; CHECK-NEXT: %N = xor i1 %cond2, %M
+; CHECK-NEXT: br i1 %N, label %T2, label %F2
+}
+
+; CHECK: @test14
+define i32 @test14(i32 %in) {
+entry:
+ %A = icmp eq i32 %in, 0
+; CHECK: br i1 %A, label %right_ret, label %merge
+ br i1 %A, label %left, label %right
+
+; CHECK-NOT: left:
+left:
+ br label %merge
+
+; CHECK-NOT: right:
+right:
+ %B = call i32 @f1()
+ br label %merge
+
+merge:
+; CHECK-NOT: %C = phi i32 [%in, %left], [%B, %right]
+ %C = phi i32 [%in, %left], [%B, %right]
+ %D = add i32 %C, 1
+ %E = icmp eq i32 %D, 2
+ br i1 %E, label %left_ret, label %right_ret
+
+; CHECK: left_ret:
+left_ret:
+ ret i32 0
+
+right_ret:
+ ret i32 1
+}
+
+; PR5652
+; CHECK: @test15
+define i32 @test15(i32 %len) {
+entry:
+; CHECK: icmp ult i32 %len, 13
+ %tmp = icmp ult i32 %len, 13
+ br i1 %tmp, label %check, label %exit0
+
+exit0:
+ ret i32 0
+
+check:
+ %tmp9 = icmp ult i32 %len, 21
+ br i1 %tmp9, label %exit1, label %exit2
+
+exit2:
+; CHECK-NOT: ret i32 2
+ ret i32 2
+
+exit1:
+ ret i32 1
+; CHECK: }
+}
+
diff --git a/src/LLVM/test/Transforms/JumpThreading/branch-no-const.ll b/src/LLVM/test/Transforms/JumpThreading/branch-no-const.ll
new file mode 100644
index 0000000..16867b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/branch-no-const.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -jump-threading -S | not grep phi
+
+declare i8 @mcguffin()
+
+define i32 @test(i1 %foo, i8 %b) {
+entry:
+ %a = call i8 @mcguffin()
+ br i1 %foo, label %bb1, label %bb2
+bb1:
+ br label %jt
+bb2:
+ br label %jt
+jt:
+ %x = phi i8 [%a, %bb1], [%b, %bb2]
+ %A = icmp eq i8 %x, %a
+ br i1 %A, label %rt, label %rf
+rt:
+ ret i32 7
+rf:
+ ret i32 8
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/compare.ll b/src/LLVM/test/Transforms/JumpThreading/compare.ll
new file mode 100644
index 0000000..581785c
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/compare.ll
@@ -0,0 +1,30 @@
+; There should be no phi nodes left.
+; RUN: opt < %s -jump-threading -S | not grep {phi i32}
+
+declare i32 @f1()
+declare i32 @f2()
+declare void @f3()
+
+define i32 @test(i1 %cond) {
+ br i1 %cond, label %T1, label %F1
+
+T1:
+ %v1 = call i32 @f1()
+ br label %Merge
+
+F1:
+ %v2 = call i32 @f2()
+ br label %Merge
+
+Merge:
+ %B = phi i32 [%v1, %T1], [12, %F1]
+ %A = icmp ne i32 %B, 42
+ br i1 %A, label %T2, label %F2
+
+T2:
+ call void @f3()
+ ret i32 1
+
+F2:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/crash.ll b/src/LLVM/test/Transforms/JumpThreading/crash.ll
new file mode 100644
index 0000000..2115dd3
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/crash.ll
@@ -0,0 +1,513 @@
+; RUN: opt < %s -jump-threading -disable-output
+; PR2285
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.system__secondary_stack__mark_id = type { i64, i64 }
+
+define void @_ada_c35507b() {
+entry:
+ br label %bb
+
+bb: ; preds = %bb13, %entry
+ %ch.0 = phi i8 [ 0, %entry ], [ 0, %bb13 ] ; <i8> [#uses=1]
+ %tmp11 = icmp ugt i8 %ch.0, 31 ; <i1> [#uses=1]
+ %tmp120 = call %struct.system__secondary_stack__mark_id @system__secondary_stack__ss_mark( ) ; <%struct.system__secondary_stack__mark_id> [#uses=1]
+ br i1 %tmp11, label %bb110, label %bb13
+
+bb13: ; preds = %bb
+ br label %bb
+
+bb110: ; preds = %bb
+ %mrv_gr124 = extractvalue %struct.system__secondary_stack__mark_id %tmp120, 1 ; <i64> [#uses=0]
+ unreachable
+}
+
+declare %struct.system__secondary_stack__mark_id @system__secondary_stack__ss_mark()
+
+
+
+define fastcc void @findratio(double* nocapture %res1, double* nocapture %res2) nounwind ssp {
+entry:
+ br label %bb12
+
+bb6.us:
+ %tmp = icmp eq i32 undef, undef
+ %tmp1 = fsub double undef, undef
+ %tmp2 = fcmp ult double %tmp1, 0.000000e+00
+ br i1 %tmp, label %bb6.us, label %bb13
+
+
+bb12:
+ %tmp3 = fcmp ult double undef, 0.000000e+00
+ br label %bb13
+
+bb13:
+ %.lcssa31 = phi double [ undef, %bb12 ], [ %tmp1, %bb6.us ]
+ %.lcssa30 = phi i1 [ %tmp3, %bb12 ], [ %tmp2, %bb6.us ]
+ br i1 %.lcssa30, label %bb15, label %bb61
+
+bb15:
+ %tmp4 = fsub double -0.000000e+00, %.lcssa31
+ ret void
+
+
+bb61:
+ ret void
+}
+
+
+; PR5258
+define i32 @test(i1 %cond, i1 %cond2, i32 %a) {
+A:
+ br i1 %cond, label %F, label %A1
+F:
+ br label %A1
+
+A1:
+ %d = phi i1 [false, %A], [true, %F]
+ %e = add i32 %a, %a
+ br i1 %d, label %B, label %G
+
+G:
+ br i1 %cond2, label %B, label %D
+
+B:
+ %f = phi i32 [%e, %G], [%e, %A1]
+ %b = add i32 0, 0
+ switch i32 %a, label %C [
+ i32 7, label %D
+ i32 8, label %D
+ i32 9, label %D
+ ]
+
+C:
+ br label %D
+
+D:
+ %c = phi i32 [%e, %B], [%e, %B], [%e, %B], [%f, %C], [%e, %G]
+ ret i32 %c
+E:
+ ret i32 412
+}
+
+
+define i32 @test2() nounwind {
+entry:
+ br i1 true, label %decDivideOp.exit, label %bb7.i
+
+bb7.i: ; preds = %bb7.i, %entry
+ br label %bb7.i
+
+decDivideOp.exit: ; preds = %entry
+ ret i32 undef
+}
+
+
+; PR3298
+
+define i32 @test3(i32 %p_79, i32 %p_80) nounwind {
+entry:
+ br label %bb7
+
+bb1: ; preds = %bb2
+ br label %bb2
+
+bb2: ; preds = %bb7, %bb1
+ %l_82.0 = phi i8 [ 0, %bb1 ], [ %l_82.1, %bb7 ] ; <i8> [#uses=3]
+ br i1 true, label %bb3, label %bb1
+
+bb3: ; preds = %bb2
+ %0 = icmp eq i32 %p_80_addr.1, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb7, label %bb6
+
+bb5: ; preds = %bb6
+ %1 = icmp eq i8 %l_82.0, 0 ; <i1> [#uses=1]
+ br i1 %1, label %bb1.i, label %bb.i
+
+bb.i: ; preds = %bb5
+ br label %safe_div_func_char_s_s.exit
+
+bb1.i: ; preds = %bb5
+ br label %safe_div_func_char_s_s.exit
+
+safe_div_func_char_s_s.exit: ; preds = %bb1.i, %bb.i
+ br label %bb6
+
+bb6: ; preds = %safe_div_func_char_s_s.exit, %bb3
+ %p_80_addr.0 = phi i32 [ %p_80_addr.1, %bb3 ], [ 1, %safe_div_func_char_s_s.exit ] ; <i32> [#uses=2]
+ %2 = icmp eq i32 %p_80_addr.0, 0 ; <i1> [#uses=1]
+ br i1 %2, label %bb7, label %bb5
+
+bb7: ; preds = %bb6, %bb3, %entry
+ %l_82.1 = phi i8 [ 1, %entry ], [ %l_82.0, %bb3 ], [ %l_82.0, %bb6 ] ; <i8> [#uses=2]
+ %p_80_addr.1 = phi i32 [ 0, %entry ], [ %p_80_addr.1, %bb3 ], [ %p_80_addr.0, %bb6 ] ; <i32> [#uses=4]
+ %3 = icmp eq i32 %p_80_addr.1, 0 ; <i1> [#uses=1]
+ br i1 %3, label %bb8, label %bb2
+
+bb8: ; preds = %bb7
+ %4 = sext i8 %l_82.1 to i32 ; <i32> [#uses=0]
+ ret i32 0
+}
+
+
+; PR3353
+
+define i32 @test4(i8 %X) {
+entry:
+ %Y = add i8 %X, 1
+ %Z = add i8 %Y, 1
+ br label %bb33.i
+
+bb33.i: ; preds = %bb33.i, %bb32.i
+ switch i8 %Y, label %bb32.i [
+ i8 39, label %bb35.split.i
+ i8 13, label %bb33.i
+ ]
+
+bb35.split.i:
+ ret i32 5
+bb32.i:
+ ret i32 1
+}
+
+
+define fastcc void @test5(i1 %tmp, i32 %tmp1) nounwind ssp {
+entry:
+ br i1 %tmp, label %bb12, label %bb13
+
+
+bb12:
+ br label %bb13
+
+bb13:
+ %.lcssa31 = phi i32 [ undef, %bb12 ], [ %tmp1, %entry ]
+ %A = and i1 undef, undef
+ br i1 %A, label %bb15, label %bb61
+
+bb15:
+ ret void
+
+
+bb61:
+ ret void
+}
+
+
+; PR5640
+define fastcc void @test6(i1 %tmp, i1 %tmp1) nounwind ssp {
+entry:
+ br i1 %tmp, label %bb12, label %bb14
+
+bb12:
+ br label %bb14
+
+bb14:
+ %A = phi i1 [ %A, %bb13 ], [ true, %bb12 ], [%tmp1, %entry]
+ br label %bb13
+
+bb13:
+ br i1 %A, label %bb14, label %bb61
+
+
+bb61:
+ ret void
+}
+
+
+; PR5698
+define void @test7(i32 %x) {
+entry:
+ br label %tailrecurse
+
+tailrecurse:
+ switch i32 %x, label %return [
+ i32 2, label %bb2
+ i32 3, label %bb
+ ]
+
+bb:
+ switch i32 %x, label %return [
+ i32 2, label %bb2
+ i32 3, label %tailrecurse
+ ]
+
+bb2:
+ ret void
+
+return:
+ ret void
+}
+
+; PR6119
+define i32 @test8(i32 %action) nounwind {
+entry:
+ switch i32 %action, label %lor.rhs [
+ i32 1, label %if.then
+ i32 0, label %lor.end
+ ]
+
+if.then: ; preds = %for.cond, %lor.end, %entry
+ ret i32 undef
+
+lor.rhs: ; preds = %entry
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %entry
+ %cmp103 = xor i1 undef, undef ; <i1> [#uses=1]
+ br i1 %cmp103, label %for.cond, label %if.then
+
+for.cond: ; preds = %for.body, %lor.end
+ br i1 undef, label %if.then, label %for.body
+
+for.body: ; preds = %for.cond
+ br label %for.cond
+}
+
+; PR6119
+define i32 @test9(i32 %action) nounwind {
+entry:
+ switch i32 %action, label %lor.rhs [
+ i32 1, label %if.then
+ i32 0, label %lor.end
+ ]
+
+if.then: ; preds = %for.cond, %lor.end, %entry
+ ret i32 undef
+
+lor.rhs: ; preds = %entry
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %entry
+ %0 = phi i1 [ undef, %lor.rhs ], [ true, %entry ] ; <i1> [#uses=1]
+ %cmp103 = xor i1 undef, %0 ; <i1> [#uses=1]
+ br i1 %cmp103, label %for.cond, label %if.then
+
+for.cond: ; preds = %for.body, %lor.end
+ br i1 undef, label %if.then, label %for.body
+
+for.body: ; preds = %for.cond
+ br label %for.cond
+}
+
+; PR6119
+define i32 @test10(i32 %action, i32 %type) nounwind {
+entry:
+ %cmp2 = icmp eq i32 %type, 0 ; <i1> [#uses=1]
+ switch i32 %action, label %lor.rhs [
+ i32 1, label %if.then
+ i32 0, label %lor.end
+ ]
+
+if.then: ; preds = %for.cond, %lor.end, %entry
+ ret i32 undef
+
+lor.rhs: ; preds = %entry
+ %cmp101 = icmp eq i32 %action, 2 ; <i1> [#uses=1]
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %entry
+ %0 = phi i1 [ %cmp101, %lor.rhs ], [ true, %entry ] ; <i1> [#uses=1]
+ %cmp103 = xor i1 %cmp2, %0 ; <i1> [#uses=1]
+ br i1 %cmp103, label %for.cond, label %if.then
+
+for.cond: ; preds = %for.body, %lor.end
+ br i1 undef, label %if.then, label %for.body
+
+for.body: ; preds = %for.cond
+ br label %for.cond
+}
+
+
+; PR6305
+define void @test11() nounwind {
+entry:
+ br label %A
+
+A: ; preds = %entry
+ call void undef(i64 ptrtoint (i8* blockaddress(@test11, %A) to i64)) nounwind
+ unreachable
+}
+
+; PR6743
+define void @test12() nounwind ssp {
+entry:
+ br label %lbl_51
+
+lbl_51: ; preds = %if.then, %entry
+ %tmp3 = phi i1 [ false, %if.then ], [ undef, %entry ] ; <i1> [#uses=2]
+ br i1 %tmp3, label %if.end12, label %if.then
+
+if.then: ; preds = %lbl_51
+ br i1 %tmp3, label %lbl_51, label %if.end12
+
+if.end12: ; preds = %if.then, %lbl_51
+ ret void
+}
+
+
+
+; PR7356
+define i32 @test13(i32* %P, i8* %Ptr) {
+entry:
+ indirectbr i8* %Ptr, [label %BrBlock, label %B2]
+
+B2:
+ store i32 4, i32 *%P
+ br label %BrBlock
+
+BrBlock:
+ %L = load i32* %P
+ %C = icmp eq i32 %L, 42
+ br i1 %C, label %T, label %F
+
+T:
+ ret i32 123
+F:
+ ret i32 1422
+}
+
+
+; PR7498
+define void @test14() nounwind {
+entry:
+ %cmp33 = icmp slt i8 undef, 0 ; <i1> [#uses=1]
+ %tobool = icmp eq i8 undef, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %land.end69, label %land.rhs
+
+land.rhs: ; preds = %entry
+ br label %land.end69
+
+land.end69: ; preds = %land.rhs, %entry
+ %0 = phi i1 [ undef, %land.rhs ], [ true, %entry ] ; <i1> [#uses=1]
+ %cmp71 = or i1 true, %0 ; <i1> [#uses=1]
+ %cmp73 = xor i1 %cmp33, %cmp71 ; <i1> [#uses=1]
+ br i1 %cmp73, label %if.then, label %if.end
+
+if.then: ; preds = %land.end69
+ ret void
+
+if.end: ; preds = %land.end69
+ ret void
+}
+
+; PR7647
+define void @test15() nounwind {
+entry:
+ ret void
+
+if.then237:
+ br label %lbl_664
+
+lbl_596: ; preds = %lbl_664, %for.end37
+ volatile store i64 undef, i64* undef, align 4
+ br label %for.cond111
+
+for.cond111: ; preds = %safe_sub_func_int64_t_s_s.exit, %lbl_596
+ %storemerge = phi i8 [ undef, %cond.true.i100 ], [ 22, %lbl_596 ] ; <i8> [#uses=1]
+ %l_678.5 = phi i64 [ %l_678.3, %cond.true.i100 ], [ undef, %lbl_596 ] ; <i64> [#uses=2]
+ %cmp114 = icmp slt i8 %storemerge, -2 ; <i1> [#uses=1]
+ br i1 %cmp114, label %lbl_664, label %if.end949
+
+lbl_664: ; preds = %for.end1058, %if.then237, %for.cond111
+ %l_678.3 = phi i64 [ %l_678.5, %for.cond111 ], [ %l_678.2, %for.cond1035 ], [ 5, %if.then237 ] ; <i64> [#uses=1]
+ %tobool118 = icmp eq i32 undef, 0 ; <i1> [#uses=1]
+ br i1 %tobool118, label %cond.true.i100, label %lbl_596
+
+cond.true.i100: ; preds = %for.inc120
+ br label %for.cond111
+
+lbl_709:
+ br label %if.end949
+
+for.cond603: ; preds = %for.body607, %if.end336
+ br i1 undef, label %for.cond603, label %if.end949
+
+if.end949: ; preds = %for.cond603, %lbl_709, %for.cond111
+ %l_678.2 = phi i64 [ %l_678.5, %for.cond111 ], [ undef, %lbl_709 ], [ 5, %for.cond603 ] ; <i64> [#uses=1]
+ br label %for.body1016
+
+for.body1016: ; preds = %for.cond1012
+ br label %for.body1016
+
+for.cond1035: ; preds = %for.inc1055, %if.then1026
+ br i1 undef, label %for.cond1040, label %lbl_664
+
+for.cond1040: ; preds = %for.body1044, %for.cond1035
+ ret void
+}
+
+; PR7755
+define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp {
+entry:
+ %cmp = icmp sgt i32 undef, 1 ; <i1> [#uses=1]
+ br i1 %c, label %land.end, label %land.rhs
+
+land.rhs: ; preds = %entry
+ br i1 %c2, label %lor.lhs.false.i, label %land.end
+
+lor.lhs.false.i: ; preds = %land.rhs
+ br i1 %c3, label %land.end, label %land.end
+
+land.end:
+ %0 = phi i1 [ true, %entry ], [ false, %land.rhs ], [false, %lor.lhs.false.i], [false, %lor.lhs.false.i] ; <i1> [#uses=1]
+ %cmp12 = and i1 %cmp, %0
+ %xor1 = xor i1 %cmp12, %c4
+ br i1 %xor1, label %if.then, label %if.end
+
+if.then:
+ ret void
+
+if.end:
+ ret void
+}
+
+define void @test17() {
+entry:
+ br i1 undef, label %bb269.us.us, label %bb269.us.us.us
+
+bb269.us.us.us:
+ %indvar = phi i64 [ %indvar.next, %bb287.us.us.us ], [ 0, %entry ]
+ %0 = icmp eq i16 undef, 0
+ br i1 %0, label %bb287.us.us.us, label %bb286.us.us.us
+
+bb287.us.us.us:
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 4
+ br i1 %exitcond, label %bb288.bb289.loopexit_crit_edge, label %bb269.us.us.us
+
+bb286.us.us.us:
+ unreachable
+
+bb269.us.us:
+ unreachable
+
+bb288.bb289.loopexit_crit_edge:
+ unreachable
+}
+
+; PR 8247
+%struct.S1 = type { i8, i8 }
+@func_89.l_245 = internal constant %struct.S1 { i8 33, i8 6 }, align 1
+define void @func_89(i16 zeroext %p_90, %struct.S1* nocapture %p_91, i32* nocapture %p_92) nounwind ssp {
+entry:
+ store i32 0, i32* %p_92, align 4
+ br i1 false, label %lbl_260, label %if.else
+
+if.else: ; preds = %entry
+ br label %for.cond
+
+for.cond: ; preds = %lbl_260, %if.else
+ %l_245.0 = phi i16 [ %l_245.1, %lbl_260 ], [ 33, %if.else ]
+ %l_261.0 = phi i32 [ %and, %lbl_260 ], [ 255, %if.else ]
+ %tobool21 = icmp ult i16 %l_245.0, 256
+ br i1 %tobool21, label %if.end, label %lbl_260
+
+lbl_260: ; preds = %for.cond, %entry
+ %l_245.1 = phi i16 [ 1569, %entry ], [ %l_245.0, %for.cond ]
+ %l_261.1 = phi i32 [ 255, %entry ], [ %l_261.0, %for.cond ]
+ %and = and i32 %l_261.1, 1
+ br label %for.cond
+
+if.end: ; preds = %for.cond
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/degenerate-phi.ll b/src/LLVM/test/Transforms/JumpThreading/degenerate-phi.ll
new file mode 100644
index 0000000..35d9fde
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/degenerate-phi.ll
@@ -0,0 +1,24 @@
+; RUN: opt -jump-threading -disable-output %s
+; PR9112
+
+; This is actually a test for value tracking. Jump threading produces
+; "%phi = phi i16" when it removes all edges leading to %unreachable.
+; The .ll parser won't let us write that directly since it's invalid code.
+
+define void @func() nounwind {
+entry:
+ br label %bb
+
+bb:
+ br label %bb
+
+unreachable:
+ %phi = phi i16 [ %add, %unreachable ], [ 0, %next ]
+ %add = add i16 0, %phi
+ %cmp = icmp slt i16 %phi, 0
+ br i1 %cmp, label %unreachable, label %next
+
+next:
+ br label %unreachable
+}
+
diff --git a/src/LLVM/test/Transforms/JumpThreading/dg.exp b/src/LLVM/test/Transforms/JumpThreading/dg.exp
new file mode 100644
index 0000000..de42dad
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.ll]]
diff --git a/src/LLVM/test/Transforms/JumpThreading/indirectbr.ll b/src/LLVM/test/Transforms/JumpThreading/indirectbr.ll
new file mode 100644
index 0000000..141277f
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/indirectbr.ll
@@ -0,0 +1,94 @@
+; RUN: opt -S < %s -jump-threading | FileCheck %s
+
+; Keep block addresses alive.
+@addresses = constant [4 x i8*] [
+ i8* blockaddress(@test1, %L1), i8* blockaddress(@test1, %L2),
+ i8* blockaddress(@test2, %L1), i8* blockaddress(@test2, %L2)
+]
+
+declare void @bar()
+declare void @baz()
+
+
+
+; Check basic jump threading for indirectbr instructions.
+
+; CHECK: void @test1
+; CHECK: br i1 %tobool, label %L1, label %indirectgoto
+; CHECK-NOT: if.else:
+; CHECK: L1:
+; CHECK: indirectbr i8* %address, [label %L1, label %L2]
+define void @test1(i32 %i, i8* %address) nounwind {
+entry:
+ %rem = srem i32 %i, 2
+ %tobool = icmp ne i32 %rem, 0
+ br i1 %tobool, label %indirectgoto, label %if.else
+
+if.else: ; preds = %entry
+ br label %indirectgoto
+
+L1: ; preds = %indirectgoto
+ call void @bar()
+ ret void
+
+L2: ; preds = %indirectgoto
+ call void @baz()
+ ret void
+
+indirectgoto: ; preds = %if.else, %entry
+ %indirect.goto.dest = phi i8* [ %address, %if.else ], [ blockaddress(@test1, %L1), %entry ]
+ indirectbr i8* %indirect.goto.dest, [label %L1, label %L2]
+}
+
+
+; Check constant folding of indirectbr
+
+; CHECK: void @test2
+; CHECK: entry:
+; CHECK-NEXT: br label %L1
+; CHECK: L1:
+; CHECK-NEXT: call void @bar
+; CHECK-NEXT: ret void
+define void @test2() nounwind {
+entry:
+ indirectbr i8* blockaddress(@test2, %L1), [label %L1, label %L2]
+
+L1: ; preds = %indirectgoto
+ call void @bar()
+ ret void
+
+L2: ; preds = %indirectgoto
+ call void @baz()
+ ret void
+}
+
+
+; PR4151
+; Don't merge address-taken blocks.
+@.str = private unnamed_addr constant [4 x i8] c"%p\0A\00"
+
+; CHECK: @test3
+; CHECK: __here:
+; CHECK: blockaddress(@test3, %__here)
+; CHECK: __here1:
+; CHECK: blockaddress(@test3, %__here1)
+; CHECK: __here3:
+; CHECK: blockaddress(@test3, %__here3)
+define void @test3() nounwind ssp noredzone {
+entry:
+ br label %__here
+
+__here: ; preds = %entry
+ %call = call i32 (...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here) to i64)) nounwind noredzone
+ br label %__here1
+
+__here1: ; preds = %__here
+ %call2 = call i32 (...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here1) to i64)) nounwind noredzone
+ br label %__here3
+
+__here3: ; preds = %__here1
+ %call4 = call i32 (...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here3) to i64)) nounwind noredzone
+ ret void
+}
+
+declare i32 @printf(...) noredzone
diff --git a/src/LLVM/test/Transforms/JumpThreading/lvi-load.ll b/src/LLVM/test/Transforms/JumpThreading/lvi-load.ll
new file mode 100644
index 0000000..2a4cf92
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/lvi-load.ll
@@ -0,0 +1,49 @@
+; RUN: opt -S -jump-threading -dce < %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.4"
+
+%"struct.llvm::PATypeHolder" = type { %"struct.llvm::Type"* }
+%"struct.llvm::PointerIntPair<llvm::Use**,2u,llvm::Use::PrevPtrTag,llvm::PointerLikeTypeTraits<llvm::Use**> >" = type { i64 }
+%"struct.llvm::Type" = type opaque
+%"struct.llvm::Use" = type { %"struct.llvm::Value"*, %"struct.llvm::Use"*, %"struct.llvm::PointerIntPair<llvm::Use**,2u,llvm::Use::PrevPtrTag,llvm::PointerLikeTypeTraits<llvm::Use**> >" }
+%"struct.llvm::Value" = type { i32 (...)**, i8, i8, i16, %"struct.llvm::PATypeHolder", %"struct.llvm::Use"*, %"struct.llvm::ValueName"* }
+%"struct.llvm::ValueName" = type opaque
+
+@_ZZN4llvm4castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_E8__func__ = internal constant [5 x i8] c"cast\00", align 8 ; <[5 x i8]*> [#uses=1]
+@.str = private constant [31 x i8] c"include/llvm/Support/Casting.h\00", align 8 ; <[31 x i8]*> [#uses=1]
+@.str1 = private constant [59 x i8] c"isa<X>(Val) && \22cast<Ty>() argument of incompatible type!\22\00", align 8 ; <[59 x i8]*> [#uses=1]
+
+; CHECK: Z3fooPN4llvm5ValueE
+define zeroext i8 @_Z3fooPN4llvm5ValueE(%"struct.llvm::Value"* %V) ssp {
+entry:
+ %0 = getelementptr inbounds %"struct.llvm::Value"* %V, i64 0, i32 1 ; <i8*> [#uses=1]
+ %1 = load i8* %0, align 8 ; <i8> [#uses=2]
+ %2 = icmp ugt i8 %1, 20 ; <i1> [#uses=1]
+ br i1 %2, label %bb.i, label %bb2
+
+bb.i: ; preds = %entry
+ %toBoolnot.i.i = icmp ult i8 %1, 21 ; <i1> [#uses=1]
+ br i1 %toBoolnot.i.i, label %bb6.i.i, label %_ZN4llvm8dyn_castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit
+
+; CHECK-NOT: assert
+bb6.i.i: ; preds = %bb.i
+ tail call void @__assert_rtn(i8* getelementptr inbounds ([5 x i8]* @_ZZN4llvm4castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_E8__func__, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8]* @.str, i64 0, i64 0), i32 202, i8* getelementptr inbounds ([59 x i8]* @.str1, i64 0, i64 0)) noreturn
+ unreachable
+
+_ZN4llvm8dyn_castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit: ; preds = %bb.i
+; CHECK-NOT: null
+ %3 = icmp eq %"struct.llvm::Value"* %V, null ; <i1> [#uses=1]
+ br i1 %3, label %bb2, label %bb
+
+bb: ; preds = %_ZN4llvm8dyn_castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit
+ tail call void @_ZNK4llvm5Value4dumpEv(%"struct.llvm::Value"* %V)
+; CHECK: ret
+ ret i8 1
+
+bb2: ; preds = %entry, %_ZN4llvm8dyn_castINS_11InstructionEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit
+ ret i8 0
+}
+
+declare void @__assert_rtn(i8*, i8*, i32, i8*) noreturn
+
+declare void @_ZNK4llvm5Value4dumpEv(%"struct.llvm::Value"*)
diff --git a/src/LLVM/test/Transforms/JumpThreading/no-irreducible-loops.ll b/src/LLVM/test/Transforms/JumpThreading/no-irreducible-loops.ll
new file mode 100644
index 0000000..7c7fe39
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/no-irreducible-loops.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -jump-threading -loop-rotate -instcombine -indvars -loop-unroll -simplifycfg -S -verify-dom-info -verify-loop-info > %t
+; RUN: grep {store volatile} %t | count 3
+; RUN: not grep {br label} %t
+
+; Jump threading should not prevent this loop from being unrolled.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+@v1 = external global i32 ; <i32*> [#uses=2]
+
+define i32 @unroll() nounwind {
+entry:
+ br label %bb4
+
+bb: ; preds = %bb4
+ %0 = icmp eq i32 %i.0, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb1, label %bb2
+
+bb1: ; preds = %bb
+ volatile store i32 1000, i32* @v1, align 4
+ br label %bb3
+
+bb2: ; preds = %bb
+ volatile store i32 1001, i32* @v1, align 4
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %1 = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb4
+
+bb4: ; preds = %bb3, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %1, %bb3 ] ; <i32> [#uses=3]
+ %2 = icmp sgt i32 %i.0, 2 ; <i1> [#uses=1]
+ br i1 %2, label %bb5, label %bb
+
+bb5: ; preds = %bb4
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/or-undef.ll b/src/LLVM/test/Transforms/JumpThreading/or-undef.ll
new file mode 100644
index 0000000..6e35992
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/or-undef.ll
@@ -0,0 +1,69 @@
+; RUN: opt -jump-threading -S %s | FileCheck %s
+; rdar://7620633
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0"
+
+define void @test1(i8* %args, i32 %from_tty) nounwind optsize ssp {
+entry:
+ %tmp = call i8* @f3(void (i8*)* null, i8* null) nounwind ; <i8*> [#uses=1]
+ %tmp1 = icmp eq i8* %args, null ; <i1> [#uses=1]
+ br i1 %tmp1, label %bb2, label %bb
+
+; CHECK: entry:
+; CHECK-NEXT: %tmp = call i8* @f3
+; CHECK-NEXT: %tmp1 = icmp eq i8* %args, null
+; CHECK-NEXT: br i1 %tmp1, label %bb7, label %bb
+
+bb: ; preds = %entry
+ %tmp2 = call noalias i8** @buildargv(i8* %args) nounwind ; <i8**> [#uses=4]
+ %tmp3 = icmp eq i8** %tmp2, null ; <i1> [#uses=1]
+ br i1 %tmp3, label %bb2, label %bb1
+
+bb1: ; preds = %bb
+ call void @f2(i8** %tmp2) nounwind
+ br label %bb2
+
+bb2: ; preds = %bb1, %bb, %entry
+ %argv.0 = phi i8** [ %tmp2, %bb1 ], [ %tmp2, %bb ], [ undef, %entry ] ; <i8**> [#uses=4]
+ %tmp5 = icmp eq i8* %args, null ; <i1> [#uses=1]
+ %tmp6 = icmp eq i8** %argv.0, null ; <i1> [#uses=1]
+ %tmp7 = or i1 %tmp5, %tmp6 ; <i1> [#uses=1]
+ br i1 %tmp7, label %bb7, label %bb5
+
+bb5: ; preds = %bb2
+ %tmp8 = load i8** %argv.0, align 8 ; <i8*> [#uses=1]
+ %tmp9 = icmp eq i8* %tmp8, null ; <i1> [#uses=1]
+ br i1 %tmp9, label %bb7, label %bb6
+
+bb6: ; preds = %bb5
+ %tmp10 = load i8** %argv.0, align 8 ; <i8*> [#uses=1]
+ %tmp11 = load i8* %tmp10, align 1 ; <i8> [#uses=1]
+ %tmp12 = icmp eq i8 %tmp11, 0 ; <i1> [#uses=1]
+ br i1 %tmp12, label %bb7, label %bb8
+
+bb7: ; preds = %bb6, %bb5, %bb2
+ call void @f1() nounwind optsize ssp
+ br label %bb9
+
+bb8: ; preds = %bb6
+ %tmp13 = load i8** %argv.0, align 8 ; <i8*> [#uses=1]
+ %tmp14 = call i64 @f5(i8* %tmp13) nounwind ; <i64> [#uses=0]
+ br label %bb9
+
+bb9: ; preds = %bb8, %bb7
+ call void @f4(i8* %tmp) nounwind
+ ret void
+}
+
+declare noalias i8** @buildargv(i8*)
+
+declare void @f2(i8**)
+
+declare void @f4(i8*)
+
+declare i8* @f3(void (i8*)*, i8*)
+
+declare void @f1()
+
+declare i64 @f5(i8*)
diff --git a/src/LLVM/test/Transforms/JumpThreading/pr9331.ll b/src/LLVM/test/Transforms/JumpThreading/pr9331.ll
new file mode 100644
index 0000000..4c06d52
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/pr9331.ll
@@ -0,0 +1,50 @@
+; RUN: opt -jump-threading -S < %s
+
+define void @func(i8 zeroext %p_44) nounwind {
+entry:
+ br i1 false, label %for.cond2, label %if.end50
+
+for.cond2: ; preds = %for.inc46, %lor.end, %entry
+ %p_44.addr.1 = phi i8 [ %p_44.addr.1, %lor.end ], [ %p_44, %entry ], [ %p_44.addr.1, %for.inc46 ]
+ br i1 undef, label %for.inc46, label %for.body5
+
+for.body5: ; preds = %for.cond2
+ br i1 undef, label %lbl_465, label %if.then9
+
+if.then9: ; preds = %for.body5
+ br label %return
+
+lbl_465: ; preds = %lbl_465, %for.body5
+ %tobool19 = icmp eq i8 undef, 0
+ br i1 %tobool19, label %if.end21, label %lbl_465
+
+if.end21: ; preds = %lbl_465
+ %conv23 = zext i8 %p_44.addr.1 to i64
+ %xor = xor i64 %conv23, 1
+ %tobool.i = icmp eq i64 %conv23, 0
+ br i1 %tobool.i, label %cond.false.i, label %safe_mod_func_uint64_t_u_u.exit
+
+cond.false.i: ; preds = %if.end21
+ %div.i = udiv i64 %xor, %conv23
+ br label %safe_mod_func_uint64_t_u_u.exit
+
+safe_mod_func_uint64_t_u_u.exit: ; preds = %cond.false.i, %if.end21
+ %cond.i = phi i64 [ %div.i, %cond.false.i ], [ %conv23, %if.end21 ]
+ %tobool28 = icmp eq i64 %cond.i, 0
+ br i1 %tobool28, label %lor.rhs, label %lor.end
+
+lor.rhs: ; preds = %safe_mod_func_uint64_t_u_u.exit
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %safe_mod_func_uint64_t_u_u.exit
+ br label %for.cond2
+
+for.inc46: ; preds = %for.cond2
+ br label %for.cond2
+
+if.end50: ; preds = %entry
+ br label %return
+
+return: ; preds = %if.end50, %if.then9
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/select.ll b/src/LLVM/test/Transforms/JumpThreading/select.ll
new file mode 100644
index 0000000..8a81857
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/select.ll
@@ -0,0 +1,123 @@
+; RUN: opt -S -jump-threading < %s | FileCheck %s
+
+declare void @foo()
+declare void @bar()
+declare void @baz()
+declare void @quux()
+
+
+; Jump threading of branch with select as condition.
+; Mostly theoretical since instruction combining simplifies all selects of
+; booleans where at least one operand is true/false/undef.
+
+; CHECK: @test_br
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %cond, label %L1,
+define void @test_br(i1 %cond, i1 %value) nounwind {
+entry:
+ br i1 %cond, label %L0, label %L3
+L0:
+ %expr = select i1 %cond, i1 true, i1 %value
+ br i1 %expr, label %L1, label %L2
+
+L1:
+ call void @foo()
+ ret void
+L2:
+ call void @bar()
+ ret void
+L3:
+ call void @baz()
+ br label %L0
+}
+
+
+; Jump threading of switch with select as condition.
+
+; CHECK: @test_switch
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %cond, label %L1,
+define void @test_switch(i1 %cond, i8 %value) nounwind {
+entry:
+ br i1 %cond, label %L0, label %L4
+L0:
+ %expr = select i1 %cond, i8 1, i8 %value
+ switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
+
+L1:
+ call void @foo()
+ ret void
+L2:
+ call void @bar()
+ ret void
+L3:
+ call void @baz()
+ ret void
+L4:
+ call void @quux()
+ br label %L0
+}
+
+; Make sure the blocks in the indirectbr test aren't trivially removable as
+; successors by taking their addresses.
+@anchor = constant [3 x i8*] [
+ i8* blockaddress(@test_indirectbr, %L1),
+ i8* blockaddress(@test_indirectbr, %L2),
+ i8* blockaddress(@test_indirectbr, %L3)
+]
+
+
+; Jump threading of indirectbr with select as address.
+
+; CHECK: @test_indirectbr
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %cond, label %L1, label %L3
+define void @test_indirectbr(i1 %cond, i8* %address) nounwind {
+entry:
+ br i1 %cond, label %L0, label %L3
+L0:
+ %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr, %L1), i8* %address
+ indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
+
+L1:
+ call void @foo()
+ ret void
+L2:
+ call void @bar()
+ ret void
+L3:
+ call void @baz()
+ ret void
+}
+
+
+; A more complicated case: the condition is a select based on a comparison.
+
+; CHECK: @test_switch_cmp
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %cond, label %L0, label %[[THREADED:[A-Za-z.0-9]+]]
+; CHECK: [[THREADED]]:
+; CHECK-NEXT: call void @quux
+; CHECK-NEXT: br label %L1
+define void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind {
+entry:
+ br i1 %cond, label %L0, label %L4
+L0:
+ %val.phi = phi i32 [%val, %entry], [-1, %L4]
+ %cmp = icmp slt i32 %val.phi, 0
+ %expr = select i1 %cmp, i8 1, i8 %value
+ switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
+
+L1:
+ call void @foo()
+ ret void
+L2:
+ call void @bar()
+ ret void
+L3:
+ call void @baz()
+ ret void
+L4:
+ call void @quux()
+ br label %L0
+}
diff --git a/src/LLVM/test/Transforms/JumpThreading/thread-loads.ll b/src/LLVM/test/Transforms/JumpThreading/thread-loads.ll
new file mode 100644
index 0000000..cce23ea
--- /dev/null
+++ b/src/LLVM/test/Transforms/JumpThreading/thread-loads.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -jump-threading -S | FileCheck %s
+; rdar://6402033
+
+; Test that we can thread through the block with the partially redundant load (%2).
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i32 @foo(i32* %P) nounwind {
+; CHECK: foo
+entry:
+ %0 = tail call i32 (...)* @f1() nounwind ; <i32> [#uses=1]
+ %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
+ br i1 %1, label %bb1, label %bb
+
+bb: ; preds = %entry
+; CHECK: bb1.thread:
+; CHECK: store
+; CHECK: br label %bb3
+ store i32 42, i32* %P, align 4
+ br label %bb1
+
+bb1: ; preds = %entry, %bb
+ %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ] ; <i32> [#uses=2]
+ %2 = load i32* %P, align 4 ; <i32> [#uses=1]
+ %3 = icmp sgt i32 %2, 36 ; <i1> [#uses=1]
+ br i1 %3, label %bb3, label %bb2
+
+bb2: ; preds = %bb1
+ %4 = tail call i32 (...)* @f2() nounwind ; <i32> [#uses=0]
+ ret i32 %res.0
+
+bb3: ; preds = %bb1
+; CHECK: bb3:
+; CHECK: %res.01 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ]
+; CHECK: ret i32 %res.01
+ ret i32 %res.0
+}
+
+declare i32 @f1(...)
+
+declare i32 @f2(...)
diff --git a/src/LLVM/test/Transforms/LCSSA/2006-06-03-IncorrectIDFPhis.ll b/src/LLVM/test/Transforms/LCSSA/2006-06-03-IncorrectIDFPhis.ll
new file mode 100644
index 0000000..7574319
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2006-06-03-IncorrectIDFPhis.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -loop-simplify -lcssa -S | \
+; RUN: grep {%%SJE.0.0.lcssa = phi .struct.SetJmpMapEntry}
+
+ %struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
+
+define void @__llvm_sjljeh_try_catching_longjmp_exception() {
+entry:
+ br i1 false, label %UnifiedReturnBlock, label %no_exit
+no_exit: ; preds = %endif, %entry
+ %SJE.0.0 = phi %struct.SetJmpMapEntry* [ %tmp.24, %endif ], [ null, %entry ] ; <%struct.SetJmpMapEntry*> [#uses=1]
+ br i1 false, label %then, label %endif
+then: ; preds = %no_exit
+ %tmp.20 = getelementptr %struct.SetJmpMapEntry* %SJE.0.0, i32 0, i32 1 ; <i32*> [#uses=0]
+ ret void
+endif: ; preds = %no_exit
+ %tmp.24 = load %struct.SetJmpMapEntry** null ; <%struct.SetJmpMapEntry*> [#uses=1]
+ br i1 false, label %UnifiedReturnBlock, label %no_exit
+UnifiedReturnBlock: ; preds = %endif, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LCSSA/2006-06-12-MultipleExitsSameBlock.ll b/src/LLVM/test/Transforms/LCSSA/2006-06-12-MultipleExitsSameBlock.ll
new file mode 100644
index 0000000..f573571
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2006-06-12-MultipleExitsSameBlock.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -lcssa -S | \
+; RUN: grep {%X.1.lcssa}
+; RUN: opt < %s -lcssa -S | \
+; RUN: not grep {%X.1.lcssa1}
+
+declare i1 @c1()
+
+declare i1 @c2()
+
+define i32 @foo() {
+entry:
+ br label %loop_begin
+loop_begin: ; preds = %loop_body.2, %entry
+ br i1 true, label %loop_body.1, label %loop_exit2
+loop_body.1: ; preds = %loop_begin
+ %X.1 = add i32 0, 1 ; <i32> [#uses=1]
+ %rel.1 = call i1 @c1( ) ; <i1> [#uses=1]
+ br i1 %rel.1, label %loop_exit, label %loop_body.2
+loop_body.2: ; preds = %loop_body.1
+ %rel.2 = call i1 @c2( ) ; <i1> [#uses=1]
+ br i1 %rel.2, label %loop_exit, label %loop_begin
+loop_exit: ; preds = %loop_body.2, %loop_body.1
+ ret i32 %X.1
+loop_exit2: ; preds = %loop_begin
+ ret i32 1
+}
+
diff --git a/src/LLVM/test/Transforms/LCSSA/2006-07-09-NoDominator.ll b/src/LLVM/test/Transforms/LCSSA/2006-07-09-NoDominator.ll
new file mode 100644
index 0000000..d8005e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2006-07-09-NoDominator.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -lcssa
+
+ %struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
+
+define void @__llvm_sjljeh_try_catching_longjmp_exception() {
+entry:
+ br label %loopentry
+loopentry: ; preds = %endif, %entry
+ %SJE.0 = phi %struct.SetJmpMapEntry* [ null, %entry ], [ %tmp.25, %endif ] ; <%struct.SetJmpMapEntry*> [#uses=1]
+ br i1 false, label %no_exit, label %loopexit
+no_exit: ; preds = %loopentry
+ br i1 false, label %then, label %endif
+then: ; preds = %no_exit
+ %tmp.21 = getelementptr %struct.SetJmpMapEntry* %SJE.0, i32 0, i32 1 ; <i32*> [#uses=0]
+ br label %return
+endif: ; preds = %no_exit
+ %tmp.25 = load %struct.SetJmpMapEntry** null ; <%struct.SetJmpMapEntry*> [#uses=1]
+ br label %loopentry
+loopexit: ; preds = %loopentry
+ br label %return
+return: ; preds = %loopexit, %then
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock-2.ll b/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock-2.ll
new file mode 100644
index 0000000..0deedfc
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock-2.ll
@@ -0,0 +1,145 @@
+; RUN: opt < %s -lcssa -disable-output -verify-dom-info -verify-loop-info
+; PR977
+; END.
+declare i32 @opost_block()
+
+define void @write_chan() {
+entry:
+ br i1 false, label %shortcirc_next.0, label %shortcirc_done.0
+shortcirc_next.0: ; preds = %entry
+ br label %shortcirc_done.0
+shortcirc_done.0: ; preds = %shortcirc_next.0, %entry
+ br i1 false, label %shortcirc_next.1, label %shortcirc_done.1
+shortcirc_next.1: ; preds = %shortcirc_done.0
+ br label %shortcirc_done.1
+shortcirc_done.1: ; preds = %shortcirc_next.1, %shortcirc_done.0
+ br i1 false, label %then.0, label %endif.0
+then.0: ; preds = %shortcirc_done.1
+ br i1 false, label %then.1, label %endif.1
+then.1: ; preds = %then.0
+ br label %return
+after_ret.0: ; No predecessors!
+ br label %endif.1
+endif.1: ; preds = %after_ret.0, %then.0
+ br label %endif.0
+endif.0: ; preds = %endif.1, %shortcirc_done.1
+ br label %loopentry.0
+loopentry.0: ; preds = %endif.12, %endif.0
+ br i1 false, label %then.2, label %endif.2
+then.2: ; preds = %loopentry.0
+ br label %loopexit.0
+dead_block_after_break.0: ; No predecessors!
+ br label %endif.2
+endif.2: ; preds = %dead_block_after_break.0, %loopentry.0
+ br i1 false, label %shortcirc_done.2, label %shortcirc_next.2
+shortcirc_next.2: ; preds = %endif.2
+ br i1 false, label %shortcirc_next.3, label %shortcirc_done.3
+shortcirc_next.3: ; preds = %shortcirc_next.2
+ br label %shortcirc_done.3
+shortcirc_done.3: ; preds = %shortcirc_next.3, %shortcirc_next.2
+ br label %shortcirc_done.2
+shortcirc_done.2: ; preds = %shortcirc_done.3, %endif.2
+ br i1 false, label %then.3, label %endif.3
+then.3: ; preds = %shortcirc_done.2
+ br label %loopexit.0
+dead_block_after_break.1: ; No predecessors!
+ br label %endif.3
+endif.3: ; preds = %dead_block_after_break.1, %shortcirc_done.2
+ br i1 false, label %shortcirc_next.4, label %shortcirc_done.4
+shortcirc_next.4: ; preds = %endif.3
+ br label %shortcirc_done.4
+shortcirc_done.4: ; preds = %shortcirc_next.4, %endif.3
+ br i1 false, label %then.4, label %else
+then.4: ; preds = %shortcirc_done.4
+ br label %loopentry.1
+loopentry.1: ; preds = %endif.8, %then.4
+ br i1 false, label %no_exit, label %loopexit.1
+no_exit: ; preds = %loopentry.1
+ %tmp.94 = call i32 @opost_block( ) ; <i32> [#uses=1]
+ br i1 false, label %then.5, label %endif.5
+then.5: ; preds = %no_exit
+ br i1 false, label %then.6, label %endif.6
+then.6: ; preds = %then.5
+ br label %loopexit.1
+dead_block_after_break.2: ; No predecessors!
+ br label %endif.6
+endif.6: ; preds = %dead_block_after_break.2, %then.5
+ br label %break_out
+dead_block_after_goto.0: ; No predecessors!
+ br label %endif.5
+endif.5: ; preds = %dead_block_after_goto.0, %no_exit
+ br i1 false, label %then.7, label %endif.7
+then.7: ; preds = %endif.5
+ br label %loopexit.1
+dead_block_after_break.3: ; No predecessors!
+ br label %endif.7
+endif.7: ; preds = %dead_block_after_break.3, %endif.5
+ switch i32 1, label %switchexit [
+ i32 4, label %label.2
+ i32 2, label %label.1
+ i32 1, label %label.0
+ ]
+label.0: ; preds = %endif.7
+ br label %switchexit
+dead_block_after_break.4: ; No predecessors!
+ br label %label.1
+label.1: ; preds = %dead_block_after_break.4, %endif.7
+ br label %switchexit
+dead_block_after_break.5: ; No predecessors!
+ br label %label.2
+label.2: ; preds = %dead_block_after_break.5, %endif.7
+ br label %switchexit
+dead_block_after_break.6: ; No predecessors!
+ br label %switchexit
+switchexit: ; preds = %dead_block_after_break.6, %label.2, %label.1, %label.0, %endif.7
+ br i1 false, label %then.8, label %endif.8
+then.8: ; preds = %switchexit
+ br label %loopexit.1
+dead_block_after_break.7: ; No predecessors!
+ br label %endif.8
+endif.8: ; preds = %dead_block_after_break.7, %switchexit
+ br label %loopentry.1
+loopexit.1: ; preds = %then.8, %then.7, %then.6, %loopentry.1
+ br i1 false, label %then.9, label %endif.9
+then.9: ; preds = %loopexit.1
+ br label %endif.9
+endif.9: ; preds = %then.9, %loopexit.1
+ br label %endif.4
+else: ; preds = %shortcirc_done.4
+ br i1 false, label %then.10, label %endif.10
+then.10: ; preds = %else
+ br label %break_out
+dead_block_after_goto.1: ; No predecessors!
+ br label %endif.10
+endif.10: ; preds = %dead_block_after_goto.1, %else
+ br label %endif.4
+endif.4: ; preds = %endif.10, %endif.9
+ br i1 false, label %then.11, label %endif.11
+then.11: ; preds = %endif.4
+ br label %loopexit.0
+dead_block_after_break.8: ; No predecessors!
+ br label %endif.11
+endif.11: ; preds = %dead_block_after_break.8, %endif.4
+ br i1 false, label %then.12, label %endif.12
+then.12: ; preds = %endif.11
+ br label %loopexit.0
+dead_block_after_break.9: ; No predecessors!
+ br label %endif.12
+endif.12: ; preds = %dead_block_after_break.9, %endif.11
+ br label %loopentry.0
+loopexit.0: ; preds = %then.12, %then.11, %then.3, %then.2
+ br label %break_out
+break_out: ; preds = %loopexit.0, %then.10, %endif.6
+ %retval.3 = phi i32 [ 0, %loopexit.0 ], [ %tmp.94, %endif.6 ], [ 0, %then.10 ] ; <i32> [#uses=0]
+ br i1 false, label %cond_true, label %cond_false
+cond_true: ; preds = %break_out
+ br label %cond_continue
+cond_false: ; preds = %break_out
+ br label %cond_continue
+cond_continue: ; preds = %cond_false, %cond_true
+ br label %return
+after_ret.1: ; No predecessors!
+ br label %return
+return: ; preds = %after_ret.1, %cond_continue, %then.1
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock.ll b/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock.ll
new file mode 100644
index 0000000..b053f17
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2006-10-31-UnreachableBlock.ll
@@ -0,0 +1,184 @@
+; RUN: opt < %s -lcssa -disable-output
+; PR977
+; END.
+
+define void @process_backlog() {
+entry:
+ br label %loopentry.preheader
+loopentry.preheader: ; preds = %dead_block_after_break, %entry
+ %work.0.ph = phi i32 [ %inc, %dead_block_after_break ], [ 0, %entry ] ; <i32> [#uses=0]
+ br label %loopentry
+loopentry: ; preds = %endif.1, %loopentry.preheader
+ br i1 false, label %then.i, label %loopentry.__skb_dequeue67.exit_crit_edge
+loopentry.__skb_dequeue67.exit_crit_edge: ; preds = %loopentry
+ br label %__skb_dequeue67.exit
+then.i: ; preds = %loopentry
+ br label %__skb_dequeue67.exit
+__skb_dequeue67.exit: ; preds = %then.i, %loopentry.__skb_dequeue67.exit_crit_edge
+ br i1 false, label %then.0, label %__skb_dequeue67.exit.endif.0_crit_edge
+__skb_dequeue67.exit.endif.0_crit_edge: ; preds = %__skb_dequeue67.exit
+ br label %endif.0
+then.0: ; preds = %__skb_dequeue67.exit
+ br label %job_done
+dead_block_after_goto: ; No predecessors!
+ unreachable
+endif.0: ; preds = %__skb_dequeue67.exit.endif.0_crit_edge
+ br i1 false, label %then.0.i, label %endif.0.endif.0.i_crit_edge
+endif.0.endif.0.i_crit_edge: ; preds = %endif.0
+ br label %endif.0.i
+then.0.i: ; preds = %endif.0
+ br label %endif.0.i
+endif.0.i: ; preds = %then.0.i, %endif.0.endif.0.i_crit_edge
+ br i1 false, label %then.i.i, label %endif.0.i.skb_bond.exit.i_crit_edge
+endif.0.i.skb_bond.exit.i_crit_edge: ; preds = %endif.0.i
+ br label %skb_bond.exit.i
+then.i.i: ; preds = %endif.0.i
+ br label %skb_bond.exit.i
+skb_bond.exit.i: ; preds = %then.i.i, %endif.0.i.skb_bond.exit.i_crit_edge
+ br label %loopentry.0.i
+loopentry.0.i: ; preds = %loopentry.0.i.backedge, %skb_bond.exit.i
+ br i1 false, label %loopentry.0.i.no_exit.0.i_crit_edge, label %loopentry.0.i.loopexit.0.i_crit_edge
+loopentry.0.i.loopexit.0.i_crit_edge: ; preds = %loopentry.0.i
+ br label %loopexit.0.i
+loopentry.0.i.no_exit.0.i_crit_edge: ; preds = %loopentry.0.i
+ br label %no_exit.0.i
+no_exit.0.i: ; preds = %then.3.i.no_exit.0.i_crit_edge, %loopentry.0.i.no_exit.0.i_crit_edge
+ br i1 false, label %no_exit.0.i.shortcirc_done.0.i_crit_edge, label %shortcirc_next.0.i
+no_exit.0.i.shortcirc_done.0.i_crit_edge: ; preds = %no_exit.0.i
+ br label %shortcirc_done.0.i
+shortcirc_next.0.i: ; preds = %no_exit.0.i
+ br label %shortcirc_done.0.i
+shortcirc_done.0.i: ; preds = %shortcirc_next.0.i, %no_exit.0.i.shortcirc_done.0.i_crit_edge
+ br i1 false, label %then.1.i, label %endif.1.i
+then.1.i: ; preds = %shortcirc_done.0.i
+ br i1 false, label %then.2.i, label %then.1.i.endif.2.i_crit_edge
+then.1.i.endif.2.i_crit_edge: ; preds = %then.1.i
+ br label %endif.2.i
+then.2.i: ; preds = %then.1.i
+ br i1 false, label %then.3.i, label %else.0.i
+then.3.i: ; preds = %then.2.i
+ br i1 false, label %then.3.i.no_exit.0.i_crit_edge, label %then.3.i.loopexit.0.i_crit_edge
+then.3.i.loopexit.0.i_crit_edge: ; preds = %then.3.i
+ br label %loopexit.0.i
+then.3.i.no_exit.0.i_crit_edge: ; preds = %then.3.i
+ br label %no_exit.0.i
+else.0.i: ; preds = %then.2.i
+ br label %endif.2.i
+endif.3.i: ; No predecessors!
+ unreachable
+endif.2.i: ; preds = %else.0.i, %then.1.i.endif.2.i_crit_edge
+ br label %loopentry.0.i.backedge
+endif.1.i: ; preds = %shortcirc_done.0.i
+ br label %loopentry.0.i.backedge
+loopentry.0.i.backedge: ; preds = %endif.1.i, %endif.2.i
+ br label %loopentry.0.i
+loopexit.0.i: ; preds = %then.3.i.loopexit.0.i_crit_edge, %loopentry.0.i.loopexit.0.i_crit_edge
+ br label %loopentry.1.i
+loopentry.1.i: ; preds = %loopentry.1.i.backedge, %loopexit.0.i
+ br i1 false, label %loopentry.1.i.no_exit.1.i_crit_edge, label %loopentry.1.i.loopexit.1.i_crit_edge
+loopentry.1.i.loopexit.1.i_crit_edge: ; preds = %loopentry.1.i
+ br label %loopexit.1.i
+loopentry.1.i.no_exit.1.i_crit_edge: ; preds = %loopentry.1.i
+ br label %no_exit.1.i
+no_exit.1.i: ; preds = %then.6.i.no_exit.1.i_crit_edge, %loopentry.1.i.no_exit.1.i_crit_edge
+ br i1 false, label %shortcirc_next.1.i, label %no_exit.1.i.shortcirc_done.1.i_crit_edge
+no_exit.1.i.shortcirc_done.1.i_crit_edge: ; preds = %no_exit.1.i
+ br label %shortcirc_done.1.i
+shortcirc_next.1.i: ; preds = %no_exit.1.i
+ br i1 false, label %shortcirc_next.1.i.shortcirc_done.2.i_crit_edge, label %shortcirc_next.2.i
+shortcirc_next.1.i.shortcirc_done.2.i_crit_edge: ; preds = %shortcirc_next.1.i
+ br label %shortcirc_done.2.i
+shortcirc_next.2.i: ; preds = %shortcirc_next.1.i
+ br label %shortcirc_done.2.i
+shortcirc_done.2.i: ; preds = %shortcirc_next.2.i, %shortcirc_next.1.i.shortcirc_done.2.i_crit_edge
+ br label %shortcirc_done.1.i
+shortcirc_done.1.i: ; preds = %shortcirc_done.2.i, %no_exit.1.i.shortcirc_done.1.i_crit_edge
+ br i1 false, label %then.4.i, label %endif.4.i
+then.4.i: ; preds = %shortcirc_done.1.i
+ br i1 false, label %then.5.i, label %then.4.i.endif.5.i_crit_edge
+then.4.i.endif.5.i_crit_edge: ; preds = %then.4.i
+ br label %endif.5.i
+then.5.i: ; preds = %then.4.i
+ br i1 false, label %then.6.i, label %else.1.i
+then.6.i: ; preds = %then.5.i
+ br i1 false, label %then.6.i.no_exit.1.i_crit_edge, label %then.6.i.loopexit.1.i_crit_edge
+then.6.i.loopexit.1.i_crit_edge: ; preds = %then.6.i
+ br label %loopexit.1.i
+then.6.i.no_exit.1.i_crit_edge: ; preds = %then.6.i
+ br label %no_exit.1.i
+else.1.i: ; preds = %then.5.i
+ br label %endif.5.i
+endif.6.i: ; No predecessors!
+ unreachable
+endif.5.i: ; preds = %else.1.i, %then.4.i.endif.5.i_crit_edge
+ br label %loopentry.1.i.backedge
+endif.4.i: ; preds = %shortcirc_done.1.i
+ br label %loopentry.1.i.backedge
+loopentry.1.i.backedge: ; preds = %endif.4.i, %endif.5.i
+ br label %loopentry.1.i
+loopexit.1.i: ; preds = %then.6.i.loopexit.1.i_crit_edge, %loopentry.1.i.loopexit.1.i_crit_edge
+ br i1 false, label %then.7.i, label %else.2.i
+then.7.i: ; preds = %loopexit.1.i
+ br i1 false, label %then.8.i, label %else.3.i
+then.8.i: ; preds = %then.7.i
+ br label %netif_receive_skb.exit
+else.3.i: ; preds = %then.7.i
+ br label %netif_receive_skb.exit
+endif.8.i: ; No predecessors!
+ unreachable
+else.2.i: ; preds = %loopexit.1.i
+ br i1 false, label %else.2.i.shortcirc_done.i.i_crit_edge, label %shortcirc_next.i.i
+else.2.i.shortcirc_done.i.i_crit_edge: ; preds = %else.2.i
+ br label %shortcirc_done.i.i
+shortcirc_next.i.i: ; preds = %else.2.i
+ br label %shortcirc_done.i.i
+shortcirc_done.i.i: ; preds = %shortcirc_next.i.i, %else.2.i.shortcirc_done.i.i_crit_edge
+ br i1 false, label %then.i1.i, label %shortcirc_done.i.i.kfree_skb65.exit.i_crit_edge
+shortcirc_done.i.i.kfree_skb65.exit.i_crit_edge: ; preds = %shortcirc_done.i.i
+ br label %kfree_skb65.exit.i
+then.i1.i: ; preds = %shortcirc_done.i.i
+ br label %kfree_skb65.exit.i
+kfree_skb65.exit.i: ; preds = %then.i1.i, %shortcirc_done.i.i.kfree_skb65.exit.i_crit_edge
+ br label %netif_receive_skb.exit
+netif_receive_skb.exit: ; preds = %kfree_skb65.exit.i, %else.3.i, %then.8.i
+ br i1 false, label %then.i1, label %netif_receive_skb.exit.dev_put69.exit_crit_edge
+netif_receive_skb.exit.dev_put69.exit_crit_edge: ; preds = %netif_receive_skb.exit
+ br label %dev_put69.exit
+then.i1: ; preds = %netif_receive_skb.exit
+ br label %dev_put69.exit
+dev_put69.exit: ; preds = %then.i1, %netif_receive_skb.exit.dev_put69.exit_crit_edge
+ %inc = add i32 0, 1 ; <i32> [#uses=1]
+ br i1 false, label %dev_put69.exit.shortcirc_done_crit_edge, label %shortcirc_next
+dev_put69.exit.shortcirc_done_crit_edge: ; preds = %dev_put69.exit
+ br label %shortcirc_done
+shortcirc_next: ; preds = %dev_put69.exit
+ br label %shortcirc_done
+shortcirc_done: ; preds = %shortcirc_next, %dev_put69.exit.shortcirc_done_crit_edge
+ br i1 false, label %then.1, label %endif.1
+then.1: ; preds = %shortcirc_done
+ ret void
+dead_block_after_break: ; No predecessors!
+ br label %loopentry.preheader
+endif.1: ; preds = %shortcirc_done
+ br label %loopentry
+loopexit: ; No predecessors!
+ unreachable
+after_ret.0: ; No predecessors!
+ br label %job_done
+job_done: ; preds = %after_ret.0, %then.0
+ br label %loopentry.i
+loopentry.i: ; preds = %no_exit.i, %job_done
+ br i1 false, label %no_exit.i, label %clear_bit62.exit
+no_exit.i: ; preds = %loopentry.i
+ br label %loopentry.i
+clear_bit62.exit: ; preds = %loopentry.i
+ br i1 false, label %then.2, label %endif.2
+then.2: ; preds = %clear_bit62.exit
+ ret void
+endif.2: ; preds = %clear_bit62.exit
+ ret void
+after_ret.1: ; No predecessors!
+ ret void
+return: ; No predecessors!
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-2.ll b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-2.ll
new file mode 100644
index 0000000..2c5815c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-2.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -loop-rotate -licm -loop-unswitch -disable-output
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ br label %bb7
+
+bb7: ; preds = %bb7, %entry
+ %tmp39 = load <4 x float>* null ; <<4 x float>> [#uses=1]
+ %tmp40 = fadd <4 x float> %tmp39, < float 2.000000e+00, float 3.000000e+00, float 1.000000e+00, float 0.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp43 = fadd <4 x float> %tmp40, < float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 2.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp46 = fadd <4 x float> %tmp43, < float 3.000000e+00, float 0.000000e+00, float 2.000000e+00, float 4.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp49 = fadd <4 x float> %tmp46, < float 0.000000e+00, float 4.000000e+00, float 6.000000e+00, float 1.000000e+00 > ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp49, <4 x float>* null
+ br i1 false, label %bb7, label %bb56
+
+bb56: ; preds = %bb7
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-3.ll b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-3.ll
new file mode 100644
index 0000000..7e0d3c6
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM-3.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -loop-rotate -licm -loop-unswitch -disable-output
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ br label %bb
+
+bb: ; preds = %bb56, %entry
+ br label %bb7
+
+bb7: ; preds = %bb7, %bb
+ %tmp39 = load <4 x float>* null ; <<4 x float>> [#uses=1]
+ %tmp40 = fadd <4 x float> %tmp39, < float 2.000000e+00, float 3.000000e+00, float 1.000000e+00, float 0.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp43 = fadd <4 x float> %tmp40, < float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 2.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp46 = fadd <4 x float> %tmp43, < float 3.000000e+00, float 0.000000e+00, float 2.000000e+00, float 4.000000e+00 > ; <<4 x float>> [#uses=1]
+ %tmp49 = fadd <4 x float> %tmp46, < float 0.000000e+00, float 4.000000e+00, float 6.000000e+00, float 1.000000e+00 > ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp49, <4 x float>* null
+ br i1 false, label %bb7, label %bb56
+
+bb56: ; preds = %bb7
+ br i1 false, label %bb, label %bb64
+
+bb64: ; preds = %bb56
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM.ll b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM.ll
new file mode 100644
index 0000000..8c07aa2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/2007-07-12-LICM.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -loop-rotate -licm -loop-unswitch -disable-output
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ br label %bb7
+
+bb7: ; preds = %bb7, %entry
+ %tmp39 = load <4 x float>* null ; <<4 x float>> [#uses=1]
+ %tmp40 = fadd <4 x float> %tmp39, < float 2.000000e+00, float 3.000000e+00, float 1.000000e+00, float 0.000000e+00 > ; <<4 x float>> [#uses=0]
+ store <4 x float> zeroinitializer, <4 x float>* null
+ br i1 false, label %bb7, label %bb56
+
+bb56: ; preds = %bb7
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/basictest.ll b/src/LLVM/test/Transforms/LCSSA/basictest.ll
new file mode 100644
index 0000000..bcfd370
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/basictest.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -lcssa -S | \
+; RUN: grep {X3.lcssa = phi i32}
+; RUN: opt < %s -lcssa -S | \
+; RUN: grep {X4 = add i32 3, %X3.lcssa}
+
+define void @lcssa(i1 %S2) {
+entry:
+ br label %loop.interior
+loop.interior: ; preds = %post.if, %entry
+ br i1 %S2, label %if.true, label %if.false
+if.true: ; preds = %loop.interior
+ %X1 = add i32 0, 0 ; <i32> [#uses=1]
+ br label %post.if
+if.false: ; preds = %loop.interior
+ %X2 = add i32 0, 1 ; <i32> [#uses=1]
+ br label %post.if
+post.if: ; preds = %if.false, %if.true
+ %X3 = phi i32 [ %X1, %if.true ], [ %X2, %if.false ] ; <i32> [#uses=1]
+ br i1 %S2, label %loop.exit, label %loop.interior
+loop.exit: ; preds = %post.if
+ %X4 = add i32 3, %X3 ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LCSSA/dg.exp b/src/LLVM/test/Transforms/LCSSA/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LCSSA/indirectbr.ll b/src/LLVM/test/Transforms/LCSSA/indirectbr.ll
new file mode 100644
index 0000000..9656448
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/indirectbr.ll
@@ -0,0 +1,542 @@
+; RUN: opt < %s -lcssa -verify-loop-info -verify-dom-info -disable-output
+; PR5437
+
+; LCSSA should work correctly in the case of an indirectbr that exits
+; the loop, and the loop has exits with predecessors not within the loop
+; (and btw these edges are unsplittable due to the indirectbr).
+
+define i32 @js_Interpret() nounwind {
+entry:
+ br i1 undef, label %"4", label %"3"
+
+"3": ; preds = %entry
+ ret i32 0
+
+"4": ; preds = %entry
+ br i1 undef, label %"6", label %"5"
+
+"5": ; preds = %"4"
+ unreachable
+
+"6": ; preds = %"4"
+ br i1 undef, label %"10", label %"13"
+
+"10": ; preds = %"6"
+ br i1 undef, label %"22", label %"15"
+
+"13": ; preds = %"6"
+ unreachable
+
+"15": ; preds = %"23", %"10"
+ unreachable
+
+"22": ; preds = %"10"
+ br label %"23"
+
+"23": ; preds = %"1375", %"22"
+ %0 = phi i32 [ undef, %"22" ], [ %1, %"1375" ] ; <i32> [#uses=1]
+ indirectbr i8* undef, [label %"15", label %"24", label %"25", label %"26", label %"27", label %"28", label %"29", label %"30", label %"32", label %"32", label %"33", label %"167", label %"173", label %"173", label %"173", label %"173", label %"173", label %"192", label %"193", label %"194", label %"196", label %"206", label %"231", label %"241", label %"251", label %"261", label %"307", label %"353", label %"354", label %"355", label %"361", label %"367", label %"400", label %"433", label %"466", label %"499", label %"509", label %"519", label %"529", label %"571", label %"589", label %"607", label %"635", label %"655", label %"664", label %"671", label %"680", label %"687", label %"692", label %"698", label %"704", label %"715", label %"715", label %"716", label %"725", label %"725", label %"725", label %"725", label %"724", label %"724", label %"724", label %"724", label %"737", label %"737", label %"737", label %"737", label %"761", label %"758", label %"759", label %"760", label %"766", label %"763", label %"764", label %"765", label %"771", label %"768", label %"769", label %"770", label %"780", label %"777", label %"778", label %"779", label %"821", label %"826", label %"831", label %"832", label %"833", label %"836", label %"836", label %"886", label %"905", label %"978", label %"978", label %"1136", label %"1166", label %"1179", label %"1201", label %"1212", label %"1212", label %"1274", label %"1284", label %"1284", label %"1346", label %"1347", label %"1348", label %"1349", label %"1350", label %"1353", label %"1353", label %"1353", label %"1355", label %"1355", label %"1357", label %"1357", label %"1358", label %"1359", label %"1374", label %"1375", label %"1376", label %"1377", label %"1378", label %"1379", label %"1386", label %"1395", label %"1394", label %"1425", label %"1426", label %"1440", label %"1449", label %"1455", label %"1461", label %"1471", label %"1482", label %"1484", label %"1486", label %"1489", label %"1489", label %"1492", label %"1494", label %"1494", label %"1497", label %"1499", label %"1499", label %"1515", label %"1546", label %"1546", label %"1566", label %"1584", label %"1587", label %"1591", label %"1605", label %"1609", label %"1609", label %"1640", label %"1648", label %"1651", label %"1703", label %"1710", label %"1718", label %"1724", label %"1725", label %"1726", label %"1727", label %"1728", label %"1731", label %"1732", label %"1733", label %"1734", label %"1735", label %"1741", label %"1750", label %"1752", label %"1754", label %"1755", label %"1757", label %"1759", label %"1761", label %"1764", label %"1764", label %"1766", label %"1768", label %"1775", label %"1775", label %"1781", label %"1781", label %"1790", label %"1827", label %"1836", label %"1836", label %"1845", label %"1845", label %"1848", label %"1849", label %"1851", label %"1853", label %"1856", label %"1861", label %"1861"]
+
+"24": ; preds = %"23"
+ unreachable
+
+"25": ; preds = %"23"
+ unreachable
+
+"26": ; preds = %"23"
+ unreachable
+
+"27": ; preds = %"23"
+ unreachable
+
+"28": ; preds = %"23"
+ unreachable
+
+"29": ; preds = %"23"
+ unreachable
+
+"30": ; preds = %"23"
+ unreachable
+
+"32": ; preds = %"23", %"23"
+ unreachable
+
+"33": ; preds = %"23"
+ unreachable
+
+"167": ; preds = %"23"
+ unreachable
+
+"173": ; preds = %"23", %"23", %"23", %"23", %"23"
+ unreachable
+
+"192": ; preds = %"23"
+ unreachable
+
+"193": ; preds = %"23"
+ unreachable
+
+"194": ; preds = %"23"
+ unreachable
+
+"196": ; preds = %"23"
+ unreachable
+
+"206": ; preds = %"23"
+ unreachable
+
+"231": ; preds = %"23"
+ unreachable
+
+"241": ; preds = %"23"
+ unreachable
+
+"251": ; preds = %"23"
+ unreachable
+
+"261": ; preds = %"23"
+ unreachable
+
+"307": ; preds = %"23"
+ unreachable
+
+"353": ; preds = %"23"
+ unreachable
+
+"354": ; preds = %"23"
+ unreachable
+
+"355": ; preds = %"23"
+ unreachable
+
+"361": ; preds = %"23"
+ unreachable
+
+"367": ; preds = %"23"
+ unreachable
+
+"400": ; preds = %"23"
+ unreachable
+
+"433": ; preds = %"23"
+ unreachable
+
+"466": ; preds = %"23"
+ unreachable
+
+"499": ; preds = %"23"
+ unreachable
+
+"509": ; preds = %"23"
+ unreachable
+
+"519": ; preds = %"23"
+ unreachable
+
+"529": ; preds = %"23"
+ unreachable
+
+"571": ; preds = %"23"
+ unreachable
+
+"589": ; preds = %"23"
+ unreachable
+
+"607": ; preds = %"23"
+ unreachable
+
+"635": ; preds = %"23"
+ unreachable
+
+"655": ; preds = %"23"
+ unreachable
+
+"664": ; preds = %"23"
+ unreachable
+
+"671": ; preds = %"23"
+ unreachable
+
+"680": ; preds = %"23"
+ unreachable
+
+"687": ; preds = %"23"
+ unreachable
+
+"692": ; preds = %"23"
+ br label %"1862"
+
+"698": ; preds = %"23"
+ unreachable
+
+"704": ; preds = %"23"
+ unreachable
+
+"715": ; preds = %"23", %"23"
+ unreachable
+
+"716": ; preds = %"23"
+ unreachable
+
+"724": ; preds = %"23", %"23", %"23", %"23"
+ unreachable
+
+"725": ; preds = %"23", %"23", %"23", %"23"
+ unreachable
+
+"737": ; preds = %"23", %"23", %"23", %"23"
+ unreachable
+
+"758": ; preds = %"23"
+ unreachable
+
+"759": ; preds = %"23"
+ unreachable
+
+"760": ; preds = %"23"
+ unreachable
+
+"761": ; preds = %"23"
+ unreachable
+
+"763": ; preds = %"23"
+ unreachable
+
+"764": ; preds = %"23"
+ unreachable
+
+"765": ; preds = %"23"
+ br label %"766"
+
+"766": ; preds = %"765", %"23"
+ unreachable
+
+"768": ; preds = %"23"
+ unreachable
+
+"769": ; preds = %"23"
+ unreachable
+
+"770": ; preds = %"23"
+ unreachable
+
+"771": ; preds = %"23"
+ unreachable
+
+"777": ; preds = %"23"
+ unreachable
+
+"778": ; preds = %"23"
+ unreachable
+
+"779": ; preds = %"23"
+ unreachable
+
+"780": ; preds = %"23"
+ unreachable
+
+"821": ; preds = %"23"
+ unreachable
+
+"826": ; preds = %"23"
+ unreachable
+
+"831": ; preds = %"23"
+ unreachable
+
+"832": ; preds = %"23"
+ unreachable
+
+"833": ; preds = %"23"
+ unreachable
+
+"836": ; preds = %"23", %"23"
+ unreachable
+
+"886": ; preds = %"23"
+ unreachable
+
+"905": ; preds = %"23"
+ unreachable
+
+"978": ; preds = %"23", %"23"
+ unreachable
+
+"1136": ; preds = %"23"
+ unreachable
+
+"1166": ; preds = %"23"
+ unreachable
+
+"1179": ; preds = %"23"
+ unreachable
+
+"1201": ; preds = %"23"
+ unreachable
+
+"1212": ; preds = %"23", %"23"
+ unreachable
+
+"1274": ; preds = %"23"
+ unreachable
+
+"1284": ; preds = %"23", %"23"
+ unreachable
+
+"1346": ; preds = %"23"
+ unreachable
+
+"1347": ; preds = %"23"
+ unreachable
+
+"1348": ; preds = %"23"
+ unreachable
+
+"1349": ; preds = %"23"
+ unreachable
+
+"1350": ; preds = %"23"
+ unreachable
+
+"1353": ; preds = %"23", %"23", %"23"
+ unreachable
+
+"1355": ; preds = %"23", %"23"
+ unreachable
+
+"1357": ; preds = %"23", %"23"
+ unreachable
+
+"1358": ; preds = %"23"
+ unreachable
+
+"1359": ; preds = %"23"
+ unreachable
+
+"1374": ; preds = %"23"
+ unreachable
+
+"1375": ; preds = %"23"
+ %1 = zext i8 undef to i32 ; <i32> [#uses=1]
+ br label %"23"
+
+"1376": ; preds = %"23"
+ unreachable
+
+"1377": ; preds = %"23"
+ unreachable
+
+"1378": ; preds = %"23"
+ unreachable
+
+"1379": ; preds = %"23"
+ unreachable
+
+"1386": ; preds = %"23"
+ unreachable
+
+"1394": ; preds = %"23"
+ unreachable
+
+"1395": ; preds = %"23"
+ unreachable
+
+"1425": ; preds = %"23"
+ unreachable
+
+"1426": ; preds = %"23"
+ unreachable
+
+"1440": ; preds = %"23"
+ unreachable
+
+"1449": ; preds = %"23"
+ unreachable
+
+"1455": ; preds = %"23"
+ unreachable
+
+"1461": ; preds = %"23"
+ unreachable
+
+"1471": ; preds = %"23"
+ unreachable
+
+"1482": ; preds = %"23"
+ unreachable
+
+"1484": ; preds = %"23"
+ unreachable
+
+"1486": ; preds = %"23"
+ unreachable
+
+"1489": ; preds = %"23", %"23"
+ unreachable
+
+"1492": ; preds = %"23"
+ unreachable
+
+"1494": ; preds = %"23", %"23"
+ unreachable
+
+"1497": ; preds = %"23"
+ unreachable
+
+"1499": ; preds = %"23", %"23"
+ unreachable
+
+"1515": ; preds = %"23"
+ unreachable
+
+"1546": ; preds = %"23", %"23"
+ unreachable
+
+"1566": ; preds = %"23"
+ br i1 undef, label %"1569", label %"1568"
+
+"1568": ; preds = %"1566"
+ unreachable
+
+"1569": ; preds = %"1566"
+ unreachable
+
+"1584": ; preds = %"23"
+ unreachable
+
+"1587": ; preds = %"23"
+ unreachable
+
+"1591": ; preds = %"23"
+ unreachable
+
+"1605": ; preds = %"23"
+ unreachable
+
+"1609": ; preds = %"23", %"23"
+ unreachable
+
+"1640": ; preds = %"23"
+ unreachable
+
+"1648": ; preds = %"23"
+ unreachable
+
+"1651": ; preds = %"23"
+ unreachable
+
+"1703": ; preds = %"23"
+ unreachable
+
+"1710": ; preds = %"23"
+ unreachable
+
+"1718": ; preds = %"23"
+ unreachable
+
+"1724": ; preds = %"23"
+ unreachable
+
+"1725": ; preds = %"23"
+ unreachable
+
+"1726": ; preds = %"23"
+ unreachable
+
+"1727": ; preds = %"23"
+ unreachable
+
+"1728": ; preds = %"23"
+ unreachable
+
+"1731": ; preds = %"23"
+ unreachable
+
+"1732": ; preds = %"23"
+ unreachable
+
+"1733": ; preds = %"23"
+ unreachable
+
+"1734": ; preds = %"23"
+ unreachable
+
+"1735": ; preds = %"23"
+ unreachable
+
+"1741": ; preds = %"23"
+ unreachable
+
+"1750": ; preds = %"23"
+ unreachable
+
+"1752": ; preds = %"23"
+ unreachable
+
+"1754": ; preds = %"23"
+ unreachable
+
+"1755": ; preds = %"23"
+ unreachable
+
+"1757": ; preds = %"23"
+ unreachable
+
+"1759": ; preds = %"23"
+ unreachable
+
+"1761": ; preds = %"23"
+ unreachable
+
+"1764": ; preds = %"23", %"23"
+ %2 = icmp eq i32 %0, 168 ; <i1> [#uses=0]
+ unreachable
+
+"1766": ; preds = %"23"
+ unreachable
+
+"1768": ; preds = %"23"
+ unreachable
+
+"1775": ; preds = %"23", %"23"
+ unreachable
+
+"1781": ; preds = %"23", %"23"
+ unreachable
+
+"1790": ; preds = %"23"
+ unreachable
+
+"1827": ; preds = %"23"
+ unreachable
+
+"1836": ; preds = %"23", %"23"
+ br label %"1862"
+
+"1845": ; preds = %"23", %"23"
+ unreachable
+
+"1848": ; preds = %"23"
+ unreachable
+
+"1849": ; preds = %"23"
+ unreachable
+
+"1851": ; preds = %"23"
+ unreachable
+
+"1853": ; preds = %"23"
+ unreachable
+
+"1856": ; preds = %"23"
+ unreachable
+
+"1861": ; preds = %"23", %"23"
+ unreachable
+
+"41": ; preds = %"23", %"23"
+ unreachable
+
+"1862": ; preds = %"1836", %"692"
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/invoke-dest.ll b/src/LLVM/test/Transforms/LCSSA/invoke-dest.ll
new file mode 100644
index 0000000..22b3202
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/invoke-dest.ll
@@ -0,0 +1,151 @@
+; RUN: opt < %s -lcssa
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+
+@.str12 = external constant [3 x i8], align 1 ; <[3 x i8]*> [#uses=1]
+@.str17175 = external constant [4 x i8], align 1 ; <[4 x i8]*> [#uses=1]
+@.str21179 = external constant [12 x i8], align 1 ; <[12 x i8]*> [#uses=1]
+@.str25183 = external constant [10 x i8], align 1 ; <[10 x i8]*> [#uses=1]
+@.str32190 = external constant [92 x i8], align 1 ; <[92 x i8]*> [#uses=1]
+@.str41 = external constant [25 x i8], align 1 ; <[25 x i8]*> [#uses=1]
+
+define void @_ZN8EtherBus10initializeEv() {
+entry:
+ br i1 undef, label %_ZN7cObjectnwEj.exit, label %bb.i
+
+bb.i: ; preds = %entry
+ br label %_ZN7cObjectnwEj.exit
+
+_ZN7cObjectnwEj.exit: ; preds = %bb.i, %entry
+ invoke void @_ZN7cObjectC2EPKc(i8* undef, i8* getelementptr ([12 x i8]* @.str21179, i32 0, i32 0))
+ to label %bb1 unwind label %lpad
+
+bb1: ; preds = %_ZN7cObjectnwEj.exit
+ br i1 undef, label %_ZNK5cGate4sizeEv.exit, label %bb.i110
+
+bb.i110: ; preds = %bb1
+ br label %_ZNK5cGate4sizeEv.exit
+
+_ZNK5cGate4sizeEv.exit: ; preds = %bb.i110, %bb1
+ br i1 undef, label %_ZNK5cGate4sizeEv.exit122, label %bb.i120
+
+bb.i120: ; preds = %_ZNK5cGate4sizeEv.exit
+ br label %_ZNK5cGate4sizeEv.exit122
+
+_ZNK5cGate4sizeEv.exit122: ; preds = %bb.i120, %_ZNK5cGate4sizeEv.exit
+ br i1 undef, label %bb8, label %bb2
+
+bb2: ; preds = %_ZNK5cGate4sizeEv.exit122
+ unreachable
+
+bb8: ; preds = %_ZNK5cGate4sizeEv.exit122
+ %tmp = invoke i8* @_ZN7cModule3parEPKc(i8* undef, i8* getelementptr ([10 x i8]* @.str25183, i32 0, i32 0))
+ to label %invcont9 unwind label %lpad119 ; <i8*> [#uses=1]
+
+invcont9: ; preds = %bb8
+ %tmp1 = invoke i8* @_ZN4cPar11stringValueEv(i8* %tmp)
+ to label %invcont10 unwind label %lpad119 ; <i8*> [#uses=1]
+
+invcont10: ; preds = %invcont9
+ invoke void @_ZN8EtherBus8tokenizeEPKcRSt6vectorIdSaIdEE(i8* null, i8* %tmp1, i8* undef)
+ to label %invcont11 unwind label %lpad119
+
+invcont11: ; preds = %invcont10
+ br i1 undef, label %bb12, label %bb18
+
+bb12: ; preds = %invcont11
+ invoke void (i8*, i8*, ...)* @_ZN6cEnvir6printfEPKcz(i8* null, i8* getelementptr ([3 x i8]* @.str12, i32 0, i32 0), i32 undef)
+ to label %bb.i.i159 unwind label %lpad119
+
+bb.i.i159: ; preds = %bb12
+ unreachable
+
+bb18: ; preds = %invcont11
+ br i1 undef, label %bb32, label %bb34
+
+bb32: ; preds = %bb18
+ br i1 undef, label %bb.i.i123, label %bb34
+
+bb.i.i123: ; preds = %bb32
+ br label %bb34
+
+bb34: ; preds = %bb.i.i123, %bb32, %bb18
+ %tmp2 = invoke i8* @_Znaj(i32 undef)
+ to label %invcont35 unwind label %lpad119 ; <i8*> [#uses=0]
+
+invcont35: ; preds = %bb34
+ br i1 undef, label %bb49, label %bb61
+
+bb49: ; preds = %invcont35
+ invoke void (i8*, i8*, ...)* @_ZNK13cSimpleModule5errorEPKcz(i8* undef, i8* getelementptr ([92 x i8]* @.str32190, i32 0, i32 0))
+ to label %bb51 unwind label %lpad119
+
+bb51: ; preds = %bb49
+ unreachable
+
+bb61: ; preds = %invcont35
+ br label %bb106
+
+.noexc: ; preds = %bb106
+ invoke void @_ZN7cObjectC2EPKc(i8* undef, i8* getelementptr ([25 x i8]* @.str41, i32 0, i32 0))
+ to label %bb102 unwind label %lpad123
+
+bb102: ; preds = %.noexc
+ invoke void undef(i8* undef, i8 zeroext 1)
+ to label %invcont103 unwind label %lpad119
+
+invcont103: ; preds = %bb102
+ invoke void undef(i8* undef, double 1.000000e+07)
+ to label %invcont104 unwind label %lpad119
+
+invcont104: ; preds = %invcont103
+ %tmp3 = invoke i32 @_ZN13cSimpleModule11sendDelayedEP8cMessagedPKci(i8* undef, i8* undef, double 0.000000e+00, i8* getelementptr ([4 x i8]* @.str17175, i32 0, i32 0), i32 undef)
+ to label %invcont105 unwind label %lpad119 ; <i32> [#uses=0]
+
+invcont105: ; preds = %invcont104
+ br label %bb106
+
+bb106: ; preds = %invcont105, %bb61
+ %tmp4 = invoke i8* @_Znaj(i32 124)
+ to label %.noexc unwind label %lpad119 ; <i8*> [#uses=1]
+
+lpad: ; preds = %_ZN7cObjectnwEj.exit
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ br label %Unwind
+
+lpad119: ; preds = %bb106, %invcont104, %invcont103, %bb102, %bb49, %bb34, %bb12, %invcont10, %invcont9, %bb8
+ %exn119 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+
+lpad123: ; preds = %.noexc
+ %exn123 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ %tmp5 = icmp eq i8* %tmp4, null ; <i1> [#uses=1]
+ br i1 %tmp5, label %Unwind, label %bb.i2
+
+bb.i2: ; preds = %lpad123
+ br label %Unwind
+
+Unwind: ; preds = %bb.i2, %lpad123, %lpad
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @_ZN8EtherBus8tokenizeEPKcRSt6vectorIdSaIdEE(i8* nocapture, i8*, i8*)
+
+declare i8* @_Znaj(i32)
+
+declare void @_ZN6cEnvir6printfEPKcz(i8* nocapture, i8* nocapture, ...)
+
+declare void @_ZNK13cSimpleModule5errorEPKcz(i8* nocapture, i8* nocapture, ...) noreturn
+
+declare i8* @_ZN7cModule3parEPKc(i8*, i8*)
+
+declare i32 @_ZN13cSimpleModule11sendDelayedEP8cMessagedPKci(i8*, i8*, double, i8*, i32)
+
+declare void @_ZN7cObjectC2EPKc(i8*, i8*)
+
+declare i8* @_ZN4cPar11stringValueEv(i8*)
diff --git a/src/LLVM/test/Transforms/LCSSA/unreachable-use.ll b/src/LLVM/test/Transforms/LCSSA/unreachable-use.ll
new file mode 100644
index 0000000..c389c9c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/unreachable-use.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -lcssa -S -verify-loop-info | grep {\[%\]tmp33 = load i1\\*\\* \[%\]tmp}
+; PR6546
+
+; LCSSA doesn't need to transform uses in blocks not reachable
+; from the entry block.
+
+define fastcc void @dfs() nounwind {
+bb:
+ br label %bb44
+
+bb44:
+ br i1 undef, label %bb7, label %bb45
+
+bb7:
+ %tmp = bitcast i1** undef to i1**
+ br label %bb15
+
+bb15:
+ br label %bb44
+
+bb32:
+ %tmp33 = load i1** %tmp, align 8
+ br label %bb45
+
+bb45:
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LCSSA/unused-phis.ll b/src/LLVM/test/Transforms/LCSSA/unused-phis.ll
new file mode 100644
index 0000000..aa2ab96
--- /dev/null
+++ b/src/LLVM/test/Transforms/LCSSA/unused-phis.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -lcssa -S | FileCheck %s
+; CHECK: exit1:
+; CHECK: .lcssa =
+; CHECK: exit2:
+; CHECK: .lcssa2 =
+; CHECK: exit3:
+; CHECK-NOT: .lcssa1 =
+
+; Test to ensure that when there are multiple exit blocks, PHI nodes are
+; only inserted by LCSSA when there is a use dominated by a given exit
+; block.
+
+declare void @printf(i32 %i)
+
+define i32 @unused_phis() nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i32 [0, %entry], [1, %then2]
+ br i1 undef, label %exit1, label %then1
+
+then1:
+ br i1 undef, label %exit2, label %then2
+
+then2:
+ br i1 undef, label %exit3, label %loop
+
+exit1:
+ call void @printf(i32 %i)
+ ret i32 %i
+
+exit2:
+ ret i32 %i
+
+exit3:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-26-LoopExitNotDominated.ll b/src/LLVM/test/Transforms/LICM/2003-02-26-LoopExitNotDominated.ll
new file mode 100644
index 0000000..66706aa
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-26-LoopExitNotDominated.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -basicaa -licm -disable-output
+
+;%MoveArray = external global [64 x ulong]
+
+define void @InitMoveArray() {
+bb3:
+ %X = alloca [2 x i64] ; <[2 x i64]*> [#uses=1]
+ br i1 false, label %bb13, label %bb4
+bb4: ; preds = %bb3
+ %reg3011 = getelementptr [2 x i64]* %X, i64 0, i64 0 ; <i64*> [#uses=1]
+ br label %bb8
+bb8: ; preds = %bb8, %bb4
+ store i64 0, i64* %reg3011
+ br i1 false, label %bb8, label %bb13
+bb13: ; preds = %bb8, %bb3
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-27-NestedLoopExitBlocks.ll b/src/LLVM/test/Transforms/LICM/2003-02-27-NestedLoopExitBlocks.ll
new file mode 100644
index 0000000..58a59be
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-27-NestedLoopExitBlocks.ll
@@ -0,0 +1,17 @@
+; Exit blocks need to be updated for all nested loops...
+
+; RUN: opt < %s -loop-simplify
+
+define i32 @yyparse() {
+bb0:
+ br i1 false, label %UnifiedExitNode, label %bb19
+bb19: ; preds = %bb28, %bb0
+ br i1 false, label %bb28, label %UnifiedExitNode
+bb28: ; preds = %bb32, %bb19
+ br i1 false, label %bb32, label %bb19
+bb32: ; preds = %bb28
+ br i1 false, label %UnifiedExitNode, label %bb28
+UnifiedExitNode: ; preds = %bb32, %bb19, %bb0
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderExitNodeUpdate.ll b/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderExitNodeUpdate.ll
new file mode 100644
index 0000000..bfc54e8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderExitNodeUpdate.ll
@@ -0,0 +1,16 @@
+; This testcase fails because preheader insertion is not updating exit node
+; information for loops.
+
+; RUN: opt < %s -licm
+
+define i32 @main(i32 %argc, i8** %argv) {
+bb0:
+ br i1 false, label %bb7, label %bb5
+bb5: ; preds = %bb5, %bb0
+ br i1 false, label %bb5, label %bb7
+bb7: ; preds = %bb7, %bb5, %bb0
+ br i1 false, label %bb7, label %bb10
+bb10: ; preds = %bb7
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderProblem.ll b/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderProblem.ll
new file mode 100644
index 0000000..c89dd57
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-27-PreheaderProblem.ll
@@ -0,0 +1,24 @@
+; Here we have a case where there are two loops and LICM is hoisting an
+; instruction from one loop into the other loop! This is obviously bad and
+; happens because preheader insertion doesn't insert a preheader for this
+; case... bad.
+
+; RUN: opt < %s -licm -loop-deletion -simplifycfg -S | \
+; RUN: not grep {br }
+
+define i32 @main(i32 %argc) {
+; <label>:0
+ br label %bb5
+bb5: ; preds = %bb5, %0
+ %I = phi i32 [ 0, %0 ], [ %I2, %bb5 ] ; <i32> [#uses=1]
+ %I2 = add i32 %I, 1 ; <i32> [#uses=2]
+ %c = icmp eq i32 %I2, 10 ; <i1> [#uses=1]
+ br i1 %c, label %bb5, label %bb8
+bb8: ; preds = %bb8, %bb5
+ %cann-indvar = phi i32 [ 0, %bb8 ], [ 0, %bb5 ] ; <i32> [#uses=0]
+ %X = add i32 %argc, %argc ; <i32> [#uses=1]
+ br i1 false, label %bb8, label %bb10
+bb10: ; preds = %bb8
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-27-StoreSinkPHIs.ll b/src/LLVM/test/Transforms/LICM/2003-02-27-StoreSinkPHIs.ll
new file mode 100644
index 0000000..efd8d8a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-27-StoreSinkPHIs.ll
@@ -0,0 +1,15 @@
+; LICM is adding stores before phi nodes. bad.
+
+; RUN: opt < %s -licm
+
+define i1 @test(i1 %c) {
+; <label>:0
+ br i1 %c, label %Loop, label %Out
+Loop: ; preds = %Loop, %0
+ store i32 0, i32* null
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %Loop, %0
+ %X = phi i1 [ %c, %0 ], [ true, %Loop ] ; <i1> [#uses=1]
+ ret i1 %X
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-02-28-PromoteDifferentType.ll b/src/LLVM/test/Transforms/LICM/2003-02-28-PromoteDifferentType.ll
new file mode 100644
index 0000000..8f1eb5f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-02-28-PromoteDifferentType.ll
@@ -0,0 +1,15 @@
+; Test that hoisting is disabled for pointers of different types...
+;
+; RUN: opt < %s -licm
+
+define void @test(i32* %P) {
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ store i32 5, i32* %P
+ %P2 = bitcast i32* %P to i8* ; <i8*> [#uses=1]
+ store i8 4, i8* %P2
+ br i1 true, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2003-05-02-LoadHoist.ll b/src/LLVM/test/Transforms/LICM/2003-05-02-LoadHoist.ll
new file mode 100644
index 0000000..ec59c0c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-05-02-LoadHoist.ll
@@ -0,0 +1,23 @@
+; This testcase tests for a problem where LICM hoists loads out of a loop
+; despite the fact that calls to unknown functions may modify what is being
+; loaded from. Basically if the load gets hoisted, the subtract gets turned
+; into a constant zero.
+;
+; RUN: opt < %s -licm -gvn -instcombine -S | grep load
+
+@X = global i32 7 ; <i32*> [#uses=2]
+
+declare void @foo()
+
+define i32 @test(i1 %c) {
+ %A = load i32* @X ; <i32> [#uses=1]
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ call void @foo( )
+ ;; Should not hoist this load!
+ %B = load i32* @X ; <i32> [#uses=1]
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %Loop
+ %C = sub i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
diff --git a/src/LLVM/test/Transforms/LICM/2003-12-11-SinkingToPHI.ll b/src/LLVM/test/Transforms/LICM/2003-12-11-SinkingToPHI.ll
new file mode 100644
index 0000000..e4912a4
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2003-12-11-SinkingToPHI.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -licm | lli
+
+define i32 @main() {
+entry:
+ br label %Loop
+Loop: ; preds = %LoopCont, %entry
+ br i1 true, label %LoopCont, label %Out
+LoopCont: ; preds = %Loop
+ %X = add i32 1, 0 ; <i32> [#uses=1]
+ br i1 true, label %Out, label %Loop
+Out: ; preds = %LoopCont, %Loop
+ %V = phi i32 [ 2, %Loop ], [ %X, %LoopCont ] ; <i32> [#uses=1]
+ %V2 = sub i32 %V, 1 ; <i32> [#uses=1]
+ ret i32 %V2
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2004-09-14-AliasAnalysisInvalidate.ll b/src/LLVM/test/Transforms/LICM/2004-09-14-AliasAnalysisInvalidate.ll
new file mode 100644
index 0000000..1832fe2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2004-09-14-AliasAnalysisInvalidate.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -globalsmodref-aa -licm -disable-output
+
+@PL_regcomp_parse = internal global i8* null ; <i8**> [#uses=2]
+
+define void @test() {
+ br label %Outer
+Outer: ; preds = %Next, %0
+ br label %Inner
+Inner: ; preds = %Inner, %Outer
+ %tmp.114.i.i.i = load i8** @PL_regcomp_parse ; <i8*> [#uses=1]
+ %tmp.115.i.i.i = load i8* %tmp.114.i.i.i ; <i8> [#uses=0]
+ store i8* null, i8** @PL_regcomp_parse
+ br i1 false, label %Inner, label %Next
+Next: ; preds = %Inner
+ br i1 false, label %Outer, label %Exit
+Exit: ; preds = %Next
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2004-11-17-UndefIndexCrash.ll b/src/LLVM/test/Transforms/LICM/2004-11-17-UndefIndexCrash.ll
new file mode 100644
index 0000000..d91e5f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2004-11-17-UndefIndexCrash.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -licm -disable-output
+ %struct.roadlet = type { i8*, %struct.vehicle*, [8 x %struct.roadlet*], [8 x %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)*] }
+ %struct.vehicle = type { %struct.roadlet*, i8*, i32, i32, %union.._631., i32 }
+ %union.._631. = type { i32 }
+
+declare %struct.roadlet* @_Z11return_nullP7roadletP7vehicle9direction(%struct.roadlet*, %struct.vehicle*, i32)
+
+declare %struct.roadlet* @_Z14lane_switch_okP7roadletP7vehicle9direction(%struct.roadlet*, %struct.vehicle*, i32)
+
+define void @main() {
+__main.entry:
+ br label %invoke_cont.3
+invoke_cont.3: ; preds = %invoke_cont.3, %__main.entry
+ %tmp.34.i.i502.7 = getelementptr %struct.roadlet* null, i32 0, i32 3, i32 7 ; <%struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)**> [#uses=1]
+ store %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)* @_Z11return_nullP7roadletP7vehicle9direction, %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)** %tmp.34.i.i502.7
+ store %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)* @_Z14lane_switch_okP7roadletP7vehicle9direction, %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)** null
+ %tmp.4.i.i339 = getelementptr %struct.roadlet* null, i32 0, i32 3, i32 undef ; <%struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)**> [#uses=1]
+ store %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)* @_Z11return_nullP7roadletP7vehicle9direction, %struct.roadlet* (%struct.roadlet*, %struct.vehicle*, i32)** %tmp.4.i.i339
+ br label %invoke_cont.3
+}
diff --git a/src/LLVM/test/Transforms/LICM/2006-09-12-DeadUserOfSunkInstr.ll b/src/LLVM/test/Transforms/LICM/2006-09-12-DeadUserOfSunkInstr.ll
new file mode 100644
index 0000000..21b313c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2006-09-12-DeadUserOfSunkInstr.ll
@@ -0,0 +1,148 @@
+; RUN: opt < %s -licm -disable-output
+; PR908
+; END.
+
+ %struct.alloc_chain = type { i8*, %struct.alloc_chain* }
+ %struct.oggpack_buffer = type { i32, i32, i8*, i8*, i32 }
+ %struct.vorbis_block = type { float**, %struct.oggpack_buffer, i32, i32, i32, i32, i32, i32, i64, i64, %struct.vorbis_dsp_state*, i8*, i32, i32, i32, %struct.alloc_chain*, i32, i32, i32, i32, i8* }
+ %struct.vorbis_dsp_state = type { i32, %struct.vorbis_info*, float**, float**, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i8* }
+ %struct.vorbis_info = type { i32, i32, i32, i32, i32, i32, i32, i8* }
+
+define fastcc void @_01forward() {
+entry:
+ br i1 false, label %bb222.preheader, label %bb241
+cond_true67: ; preds = %cond_true87
+ br label %cond_next80
+cond_next80: ; preds = %cond_true87, %cond_true67
+ br label %bb83
+bb83.preheader: ; preds = %cond_true226
+ br i1 false, label %bb83.us.preheader, label %bb83.preheader1
+bb83.us.preheader: ; preds = %bb83.preheader
+ br label %bb83.us
+bb83.us: ; preds = %cond_next80.us, %bb83.us.preheader
+ br i1 false, label %cond_true87.us, label %cond_next92.loopexit2
+cond_next80.us: ; preds = %bb59.loopexit.us, %cond_true67.us
+ br label %bb83.us
+cond_true67.us: ; preds = %bb59.loopexit.us
+ br label %cond_next80.us
+cond_next.us: ; preds = %cond_true56.us, %cond_true38.us
+ br i1 false, label %cond_true56.us, label %bb59.loopexit.us
+cond_true38.us: ; preds = %cond_true56.us
+ br label %cond_next.us
+cond_true56.us: ; preds = %cond_true87.us, %cond_next.us
+ br i1 false, label %cond_true38.us, label %cond_next.us
+cond_true87.us: ; preds = %bb83.us
+ br label %cond_true56.us
+bb59.loopexit.us: ; preds = %cond_next.us
+ br i1 false, label %cond_true67.us, label %cond_next80.us
+bb83.preheader1: ; preds = %bb83.preheader
+ br label %bb83
+bb83: ; preds = %bb83.preheader1, %cond_next80
+ br i1 false, label %cond_next92.loopexit, label %cond_true87
+cond_true87: ; preds = %bb83
+ br i1 false, label %cond_true67, label %cond_next80
+cond_next92.loopexit: ; preds = %bb83
+ br label %cond_next92
+cond_next92.loopexit2: ; preds = %bb83.us
+ br label %cond_next92
+cond_next92: ; preds = %cond_true226, %cond_next92.loopexit2, %cond_next92.loopexit
+ br i1 false, label %cond_true218.loopexit, label %bb222
+cond_true139: ; preds = %cond_true202
+ br i1 false, label %cond_next195, label %cond_true155
+cond_true155: ; preds = %cond_true139
+ br i1 false, label %cond_true249.i.preheader, label %_encodepart.exit
+cond_true.i: ; preds = %cond_true115.i
+ br i1 false, label %bb60.i.preheader, label %cond_next97.i
+bb60.i.preheader: ; preds = %cond_true.i
+ br label %bb60.i
+bb60.i: ; preds = %cond_true63.i, %bb60.i.preheader
+ br i1 false, label %cond_true63.i, label %cond_next97.i.loopexit
+cond_true63.i: ; preds = %bb60.i
+ br i1 false, label %bb60.i, label %cond_next97.i.loopexit
+bb86.i.preheader: ; preds = %cond_true115.i
+ br label %bb86.i
+bb86.i: ; preds = %cond_true93.i, %bb86.i.preheader
+ br i1 false, label %cond_true93.i, label %cond_next97.i.loopexit3
+cond_true93.i: ; preds = %bb86.i
+ br i1 false, label %cond_next97.i.loopexit3, label %bb86.i
+cond_next97.i.loopexit: ; preds = %cond_true63.i, %bb60.i
+ br label %cond_next97.i
+cond_next97.i.loopexit3: ; preds = %cond_true93.i, %bb86.i
+ br label %cond_next97.i
+cond_next97.i: ; preds = %cond_next97.i.loopexit3, %cond_next97.i.loopexit, %cond_true.i
+ br i1 false, label %bb118.i.loopexit, label %cond_true115.i
+cond_true115.i.preheader: ; preds = %cond_true249.i
+ br label %cond_true115.i
+cond_true115.i: ; preds = %cond_true115.i.preheader, %cond_next97.i
+ br i1 false, label %cond_true.i, label %bb86.i.preheader
+bb118.i.loopexit: ; preds = %cond_next97.i
+ br label %bb118.i
+bb118.i: ; preds = %cond_true249.i, %bb118.i.loopexit
+ br i1 false, label %cond_next204.i, label %cond_true128.i
+cond_true128.i: ; preds = %bb118.i
+ br i1 false, label %cond_true199.i.preheader, label %cond_next204.i
+cond_true199.i.preheader: ; preds = %cond_true128.i
+ br label %cond_true199.i
+cond_true199.i.us: ; No predecessors!
+ br i1 false, label %cond_true167.i.us, label %cond_next187.i.us
+cond_next187.i.us: ; preds = %bb170.i.loopexit.us, %bb170.i.us.cond_next187.i.us_crit_edge, %cond_true199.i.us
+ unreachable
+bb170.i.us.cond_next187.i.us_crit_edge: ; preds = %bb170.i.loopexit.us
+ br label %cond_next187.i.us
+cond_true167.i.us: ; preds = %cond_true167.i.us, %cond_true199.i.us
+ br i1 false, label %cond_true167.i.us, label %bb170.i.loopexit.us
+bb170.i.loopexit.us: ; preds = %cond_true167.i.us
+ br i1 false, label %cond_next187.i.us, label %bb170.i.us.cond_next187.i.us_crit_edge
+cond_true199.i: ; preds = %cond_true199.i, %cond_true199.i.preheader
+ br i1 false, label %cond_next204.i.loopexit, label %cond_true199.i
+cond_next204.i.loopexit: ; preds = %cond_true199.i
+ br label %cond_next204.i
+cond_next204.i: ; preds = %cond_next204.i.loopexit, %cond_true128.i, %bb118.i
+ br label %bb233.i
+cond_true230.i: ; No predecessors!
+ %exitcond155 = icmp eq i32 0, %tmp16.i ; <i1> [#uses=0]
+ unreachable
+bb233.i: ; preds = %cond_next204.i
+ br i1 false, label %_encodepart.exit.loopexit, label %cond_true249.i
+cond_true249.i.preheader: ; preds = %cond_true155
+ br label %cond_true249.i
+cond_true249.i: ; preds = %cond_true249.i.preheader, %bb233.i
+ %tmp16.i = bitcast i32 0 to i32 ; <i32> [#uses=1]
+ br i1 false, label %cond_true115.i.preheader, label %bb118.i
+_encodepart.exit.loopexit: ; preds = %bb233.i
+ br label %_encodepart.exit
+_encodepart.exit: ; preds = %_encodepart.exit.loopexit, %cond_true155
+ br label %cond_next195
+cond_next195: ; preds = %cond_true202, %_encodepart.exit, %cond_true139
+ br i1 false, label %bb205.loopexit, label %cond_true202
+cond_true202.preheader: ; preds = %cond_true218
+ br label %cond_true202
+cond_true202: ; preds = %cond_true202.preheader, %cond_next195
+ br i1 false, label %cond_next195, label %cond_true139
+bb205.loopexit: ; preds = %cond_next195
+ br label %bb205
+bb205: ; preds = %cond_true218, %bb205.loopexit
+ br i1 false, label %cond_true218, label %bb222.outer105.loopexit
+cond_true218.loopexit: ; preds = %cond_next92
+ br label %cond_true218
+cond_true218: ; preds = %cond_true218.loopexit, %bb205
+ br i1 false, label %cond_true202.preheader, label %bb205
+bb222.preheader: ; preds = %entry
+ br label %bb222.outer
+bb222.outer: ; preds = %bb229, %bb222.preheader
+ br label %bb222.outer105
+bb222.outer105.loopexit: ; preds = %bb205
+ br label %bb222.outer105
+bb222.outer105: ; preds = %bb222.outer105.loopexit, %bb222.outer
+ br label %bb222
+bb222: ; preds = %bb222.outer105, %cond_next92
+ br i1 false, label %cond_true226, label %bb229
+cond_true226: ; preds = %bb222
+ br i1 false, label %bb83.preheader, label %cond_next92
+bb229: ; preds = %bb222
+ br i1 false, label %bb222.outer, label %bb241.loopexit
+bb241.loopexit: ; preds = %bb229
+ br label %bb241
+bb241: ; preds = %bb241.loopexit, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LICM/2007-05-22-VolatileSink.ll b/src/LLVM/test/Transforms/LICM/2007-05-22-VolatileSink.ll
new file mode 100644
index 0000000..bbc9143
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2007-05-22-VolatileSink.ll
@@ -0,0 +1,56 @@
+; RUN: opt < %s -licm -S | grep {store volatile}
+; PR1435
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-apple-darwin8"
+
+define void @Transpose(i32* %DataIn, i32* %DataOut) {
+entry:
+ %buffer = alloca [64 x i32], align 16 ; <[64 x i32]*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ br label %bb6
+
+bb: ; preds = %bb6
+ %tmp2 = volatile load i32* %DataIn ; <i32> [#uses=1]
+ %tmp3 = getelementptr [64 x i32]* %buffer, i32 0, i32 %i.0 ; <i32*> [#uses=1]
+ store i32 %tmp2, i32* %tmp3
+ %tmp5 = add i32 %i.0, 1 ; <i32> [#uses=1]
+ br label %bb6
+
+bb6: ; preds = %bb, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %tmp5, %bb ] ; <i32> [#uses=3]
+ %tmp8 = icmp sle i32 %i.0, 63 ; <i1> [#uses=1]
+ %tmp89 = zext i1 %tmp8 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp89, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb, label %bb30
+
+bb12: ; preds = %bb22
+ %tmp14 = mul i32 %j.1, 8 ; <i32> [#uses=1]
+ %tmp16 = add i32 %tmp14, %i.1 ; <i32> [#uses=1]
+ %tmp17 = getelementptr [64 x i32]* %buffer, i32 0, i32 %tmp16 ; <i32*> [#uses=1]
+ %tmp18 = load i32* %tmp17 ; <i32> [#uses=1]
+ volatile store i32 %tmp18, i32* %DataOut
+ %tmp21 = add i32 %j.1, 1 ; <i32> [#uses=1]
+ br label %bb22
+
+bb22: ; preds = %bb30, %bb12
+ %j.1 = phi i32 [ %tmp21, %bb12 ], [ 0, %bb30 ] ; <i32> [#uses=4]
+ %tmp24 = icmp sle i32 %j.1, 7 ; <i1> [#uses=1]
+ %tmp2425 = zext i1 %tmp24 to i8 ; <i8> [#uses=1]
+ %toBool26 = icmp ne i8 %tmp2425, 0 ; <i1> [#uses=1]
+ br i1 %toBool26, label %bb12, label %bb27
+
+bb27: ; preds = %bb22
+ %tmp29 = add i32 %i.1, 1 ; <i32> [#uses=1]
+ br label %bb30
+
+bb30: ; preds = %bb27, %bb6
+ %j.0 = phi i32 [ %j.1, %bb27 ], [ undef, %bb6 ] ; <i32> [#uses=0]
+ %i.1 = phi i32 [ %tmp29, %bb27 ], [ 0, %bb6 ] ; <i32> [#uses=3]
+ %tmp32 = icmp sle i32 %i.1, 7 ; <i1> [#uses=1]
+ %tmp3233 = zext i1 %tmp32 to i8 ; <i8> [#uses=1]
+ %toBool34 = icmp ne i8 %tmp3233, 0 ; <i1> [#uses=1]
+ br i1 %toBool34, label %bb22, label %return
+
+return: ; preds = %bb30
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LICM/2007-07-30-AliasSet.ll b/src/LLVM/test/Transforms/LICM/2007-07-30-AliasSet.ll
new file mode 100644
index 0000000..8ecd1bc
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2007-07-30-AliasSet.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -licm -loop-unswitch -disable-output
+ %struct.III_scalefac_t = type { [22 x i32], [13 x [3 x i32]] }
+ %struct.gr_info = type { i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], [3 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32*, [4 x i32] }
+
+define i32 @scale_bitcount_lsf(%struct.III_scalefac_t* %scalefac, %struct.gr_info* %cod_info) {
+entry:
+ br i1 false, label %bb28, label %bb133.preheader
+
+bb133.preheader: ; preds = %entry
+ ret i32 0
+
+bb28: ; preds = %entry
+ br i1 false, label %bb63.outer, label %bb79
+
+bb63.outer: ; preds = %bb73, %bb28
+ br i1 false, label %bb35, label %bb73
+
+bb35: ; preds = %cond_next60, %bb63.outer
+ %window.34 = phi i32 [ %tmp62, %cond_next60 ], [ 0, %bb63.outer ] ; <i32> [#uses=1]
+ %tmp44 = getelementptr [4 x i32]* null, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp46 = load i32* %tmp44, align 4 ; <i32> [#uses=0]
+ br i1 false, label %cond_true50, label %cond_next60
+
+cond_true50: ; preds = %bb35
+ %tmp59 = getelementptr [4 x i32]* null, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp59, align 4
+ br label %cond_next60
+
+cond_next60: ; preds = %cond_true50, %bb35
+ %tmp62 = add i32 %window.34, 1 ; <i32> [#uses=1]
+ br i1 false, label %bb35, label %bb73
+
+bb73: ; preds = %cond_next60, %bb63.outer
+ %tmp76 = icmp slt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp76, label %bb63.outer, label %bb79
+
+bb79: ; preds = %bb73, %bb28
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LICM/2007-09-17-PromoteValue.ll b/src/LLVM/test/Transforms/LICM/2007-09-17-PromoteValue.ll
new file mode 100644
index 0000000..31abd8c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2007-09-17-PromoteValue.ll
@@ -0,0 +1,61 @@
+; ModuleID = 'PR1657.bc'
+; Do not promote getelementptr because it may exposes load from a null pointer
+; and store from a null pointer which are covered by
+; icmp eq %struct.decision* null, null condition.
+; RUN: opt < %s -licm -S | not grep promoted
+ %struct.decision = type { i8, %struct.decision* }
+
+define i32 @main() {
+entry:
+ br label %blah.i
+
+blah.i: ; preds = %cond_true.i, %entry
+ %tmp3.i = icmp eq %struct.decision* null, null ; <i1> [#uses=1]
+ br i1 %tmp3.i, label %clear_modes.exit, label %cond_true.i
+
+cond_true.i: ; preds = %blah.i
+ %tmp1.i = getelementptr %struct.decision* null, i32 0, i32 0 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp1.i
+ br label %blah.i
+
+clear_modes.exit: ; preds = %blah.i
+ call void @exit( i32 0 )
+ unreachable
+}
+
+define i32 @f(i8* %ptr) {
+entry:
+ br label %loop.head
+
+loop.head: ; preds = %cond.true, %entry
+ %x = phi i8* [ %ptr, %entry ], [ %ptr.i, %cond.true ] ; <i8*> [#uses=1]
+ %tmp3.i = icmp ne i8* %ptr, %x ; <i1> [#uses=1]
+ br i1 %tmp3.i, label %cond.true, label %exit
+
+cond.true: ; preds = %loop.head
+ %ptr.i = getelementptr i8* %ptr, i32 0 ; <i8*> [#uses=2]
+ store i8 0, i8* %ptr.i
+ br label %loop.head
+
+exit: ; preds = %loop.head
+ ret i32 0
+}
+
+define i32 @f2(i8* %p, i8* %q) {
+entry:
+ br label %loop.head
+
+loop.head: ; preds = %cond.true, %entry
+ %tmp3.i = icmp eq i8* null, %q ; <i1> [#uses=1]
+ br i1 %tmp3.i, label %exit, label %cond.true
+
+cond.true: ; preds = %loop.head
+ %ptr.i = getelementptr i8* %p, i32 0 ; <i8*> [#uses=2]
+ store i8 0, i8* %ptr.i
+ br label %loop.head
+
+exit: ; preds = %loop.head
+ ret i32 0
+}
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/LICM/2007-09-24-PromoteNullValue.ll b/src/LLVM/test/Transforms/LICM/2007-09-24-PromoteNullValue.ll
new file mode 100644
index 0000000..916f479
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2007-09-24-PromoteNullValue.ll
@@ -0,0 +1,46 @@
+; Do not promote null value because it may be unsafe to do so.
+; RUN: opt < %s -licm -S | not grep promoted
+
+define i32 @f(i32 %foo, i32 %bar, i32 %com) {
+entry:
+ %tmp2 = icmp eq i32 %foo, 0 ; <i1> [#uses=1]
+ br i1 %tmp2, label %cond_next, label %cond_true
+
+cond_true: ; preds = %entry
+ br label %return
+
+cond_next: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb15, %cond_next
+ switch i32 %bar, label %bb15 [
+ i32 1, label %bb6
+ ]
+
+bb6: ; preds = %bb
+ %tmp8 = icmp eq i32 %com, 0 ; <i1> [#uses=1]
+ br i1 %tmp8, label %cond_next14, label %cond_true11
+
+cond_true11: ; preds = %bb6
+ br label %return
+
+cond_next14: ; preds = %bb6
+ store i8 0, i8* null
+ br label %bb15
+
+bb15: ; preds = %cond_next14, %bb
+ br label %bb
+
+return: ; preds = %cond_true11, %cond_true
+ %storemerge = phi i32 [ 0, %cond_true ], [ undef, %cond_true11 ] ; <i32> [#uses=1]
+ ret i32 %storemerge
+}
+
+define i32 @kdMain() {
+entry:
+ %tmp1 = call i32 @f( i32 0, i32 1, i32 1 ) ; <i32> [#uses=0]
+ call void @exit( i32 0 )
+ unreachable
+}
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/LICM/2007-10-01-PromoteSafeValue.ll b/src/LLVM/test/Transforms/LICM/2007-10-01-PromoteSafeValue.ll
new file mode 100644
index 0000000..e3d0d02
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2007-10-01-PromoteSafeValue.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -licm -S | FileCheck %s
+; Promote value if at least one use is safe
+
+
+define i32 @f2(i32* %p, i8* %q) {
+entry:
+ br label %loop.head
+
+loop.head: ; preds = %cond.true, %entry
+ store i32 20, i32* %p
+ %tmp3.i = icmp eq i8* null, %q ; <i1> [#uses=1]
+ br i1 %tmp3.i, label %exit, label %cond.true
+
+cond.true: ; preds = %loop.head
+ store i32 40, i32* %p
+ br label %loop.head
+
+; CHECK: exit:
+; CHECK: store i32 20, i32* %p
+exit: ; preds = %loop.head
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/2008-05-20-AliasSetVAArg.ll b/src/LLVM/test/Transforms/LICM/2008-05-20-AliasSetVAArg.ll
new file mode 100644
index 0000000..a5a7bf8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2008-05-20-AliasSetVAArg.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -licm -disable-output
+; PR2346
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-pc-linux-gnu"
+ %struct._zval_struct = type { %union._double, i32, i8, i8, i8, i8 }
+ %union._double = type { double }
+
+define i8* @zend_fetch_resource(%struct._zval_struct** %passed_id, i32 %default_id, i8* %resource_type_name, i32* %found_resource_type, i32 %num_resource_types, ...) {
+entry:
+ br label %whilebody.i.i
+
+whilebody.i.i: ; preds = %whilebody.i.i, %entry
+ br i1 false, label %ifthen.i.i, label %whilebody.i.i
+
+ifthen.i.i: ; preds = %whilebody.i.i
+ br label %forcond
+
+forcond: ; preds = %forbody, %ifthen.i.i
+ br i1 false, label %forbody, label %afterfor
+
+forbody: ; preds = %forcond
+ va_arg i8** null, i32 ; <i32>:0 [#uses=0]
+ br i1 false, label %ifthen59, label %forcond
+
+ifthen59: ; preds = %forbody
+ unreachable
+
+afterfor: ; preds = %forcond
+ ret i8* null
+}
diff --git a/src/LLVM/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll b/src/LLVM/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll
new file mode 100644
index 0000000..d4df26e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -basicaa -licm -S | FileCheck %s
+
+@a = external constant float*
+
+define void @test(i32 %count) {
+entry:
+ br label %forcond
+
+; CHECK: %tmp3 = load float** @a
+; CHECK: br label %forcond
+
+forcond:
+ %i.0 = phi i32 [ 0, %entry ], [ %inc, %forbody ]
+ %cmp = icmp ult i32 %i.0, %count
+ br i1 %cmp, label %forbody, label %afterfor
+
+; CHECK: %i.0 = phi i32 [ 0, %entry ], [ %inc, %forbody ]
+; CHECK: %cmp = icmp ult i32 %i.0, %count
+; CHECK: br i1 %cmp, label %forbody, label %afterfor
+
+forbody:
+ %tmp3 = load float** @a
+ %arrayidx = getelementptr float* %tmp3, i32 %i.0
+ %tmp7 = uitofp i32 %i.0 to float
+ store float %tmp7, float* %arrayidx
+ %inc = add i32 %i.0, 1
+ br label %forcond
+
+; CHECK: %arrayidx = getelementptr float* %tmp3, i32 %i.0
+; CHECK: %tmp7 = uitofp i32 %i.0 to float
+; CHECK: store float %tmp7, float* %arrayidx
+; CHECK: %inc = add i32 %i.0, 1
+; CHECK: br label %forcond
+
+afterfor:
+ ret void
+}
+
+; CHECK: ret void
diff --git a/src/LLVM/test/Transforms/LICM/2009-12-10-LICM-Indbr-Crash.ll b/src/LLVM/test/Transforms/LICM/2009-12-10-LICM-Indbr-Crash.ll
new file mode 100644
index 0000000..e3cdbb3
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2009-12-10-LICM-Indbr-Crash.ll
@@ -0,0 +1,21 @@
+; Test for rdar://7452967
+; RUN: opt < %s -licm -disable-output
+define void @foo (i8* %v)
+{
+ entry:
+ br i1 undef, label %preheader, label %return
+
+ preheader:
+ br i1 undef, label %loop, label %return
+
+ loop:
+ indirectbr i8* undef, [label %preheader, label %stuff]
+
+ stuff:
+ %0 = load i8* undef, align 1
+ br label %loop
+
+ return:
+ ret void
+
+}
diff --git a/src/LLVM/test/Transforms/LICM/2011-04-06-HoistMissedASTUpdate.ll b/src/LLVM/test/Transforms/LICM/2011-04-06-HoistMissedASTUpdate.ll
new file mode 100644
index 0000000..fd114f4
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2011-04-06-HoistMissedASTUpdate.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -basicaa -licm -S | FileCheck %s
+; PR9630
+
+@g_39 = external global i16, align 2
+
+declare i32* @func_84(i32** nocapture) nounwind readonly
+
+declare i32** @func_108(i32*** nocapture) nounwind readonly
+
+define void @func() nounwind {
+entry:
+ br label %for.body4.lr.ph
+
+for.body4.lr.ph:
+ br label %for.body4
+
+; CHECK: for.body4:
+; CHECK: load volatile i16* @g_39
+
+for.body4:
+ %l_612.11 = phi i32* [ undef, %for.body4.lr.ph ], [ %call19, %for.body4 ]
+ %tmp7 = volatile load i16* @g_39, align 2
+ %call = call i32** @func_108(i32*** undef)
+ %call19 = call i32* @func_84(i32** %call)
+ br i1 false, label %for.body4, label %for.cond.loopexit
+
+for.cond.loopexit:
+ br i1 false, label %for.body4.lr.ph, label %for.end26
+
+for.end26:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LICM/2011-04-06-PromoteResultOfPromotion.ll b/src/LLVM/test/Transforms/LICM/2011-04-06-PromoteResultOfPromotion.ll
new file mode 100644
index 0000000..86c2679
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2011-04-06-PromoteResultOfPromotion.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -tbaa -licm -S | FileCheck %s
+; PR9634
+
+@g_58 = common global i32 0, align 4
+@g_116 = common global i32* null, align 8
+
+define void @f() nounwind {
+
+; CHECK: entry:
+; CHECK: alloca [9 x i16]
+; CHECK: load i32* @g_58
+; CHECK: br label %for.body
+
+entry:
+ %l_87.i = alloca [9 x i16], align 16
+ br label %for.body
+
+for.body: ; preds = %entry, %for.inc
+ %inc12 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ store i32* @g_58, i32** @g_116, align 8, !tbaa !0
+ %tmp2 = load i32** @g_116, align 8, !tbaa !0
+ %tmp3 = load i32* %tmp2, !tbaa !4
+ %or = or i32 %tmp3, 10
+ store i32 %or, i32* %tmp2, !tbaa !4
+ %inc = add nsw i32 %inc12, 1
+ %cmp = icmp slt i32 %inc, 4
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.inc
+ ret void
+}
+
+!0 = metadata !{metadata !"any pointer", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
+!3 = metadata !{metadata !"short", metadata !1}
+!4 = metadata !{metadata !"int", metadata !1}
diff --git a/src/LLVM/test/Transforms/LICM/2011-04-09-RAUW-AST.ll b/src/LLVM/test/Transforms/LICM/2011-04-09-RAUW-AST.ll
new file mode 100644
index 0000000..4285bd1
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2011-04-09-RAUW-AST.ll
@@ -0,0 +1,49 @@
+; RUN: opt < %s -loop-rotate -licm -S | FileCheck %s
+; PR9604
+
+@g_3 = global i32 0, align 4
+@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00"
+
+define i32 @main() nounwind {
+entry:
+ %tmp = load i32* @g_3, align 4
+ %tobool = icmp eq i32 %tmp, 0
+ br i1 %tobool, label %for.cond, label %if.then
+
+if.then: ; preds = %entry
+ br label %for.cond
+
+for.cond: ; preds = %for.inc10, %if.then, %entry
+ %g.0 = phi i32* [ %g.0, %for.inc10 ], [ @g_3, %entry ], [ null, %if.then ]
+ %x.0 = phi i32 [ %inc12, %for.inc10 ], [ 0, %entry ], [ 0, %if.then ]
+ %cmp = icmp slt i32 %x.0, 5
+ br i1 %cmp, label %for.cond4, label %for.end13
+
+for.cond4: ; preds = %for.body7, %for.cond
+ %y.0 = phi i32 [ %inc, %for.body7 ], [ 0, %for.cond ]
+ %cmp6 = icmp slt i32 %y.0, 5
+ br i1 %cmp6, label %for.body7, label %for.inc10
+
+; CHECK: for.body7:
+; CHECK-NEXT: phi
+; CHECK-NEXT: store i32 0
+; CHECK-NEXT: store i32 1
+
+for.body7: ; preds = %for.cond4
+ store i32 0, i32* @g_3, align 4
+ store i32 1, i32* %g.0, align 4
+ %inc = add nsw i32 %y.0, 1
+ br label %for.cond4
+
+for.inc10: ; preds = %for.cond4
+ %inc12 = add nsw i32 %x.0, 1
+ br label %for.cond
+
+for.end13: ; preds = %for.cond
+ %tmp14 = load i32* @g_3, align 4
+ %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i32 %tmp14) nounwind
+ ret i32 0
+}
+
+declare i32 @printf(i8* nocapture, ...) nounwind
+
diff --git a/src/LLVM/test/Transforms/LICM/2011-07-06-Alignment.ll b/src/LLVM/test/Transforms/LICM/2011-07-06-Alignment.ll
new file mode 100644
index 0000000..f97b701
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/2011-07-06-Alignment.ll
@@ -0,0 +1,26 @@
+; RUN: opt -licm -S %s | FileCheck %s
+
+@A = common global [1024 x float] zeroinitializer, align 4
+
+define i32 @main() nounwind {
+entry:
+ br label %for.cond
+
+for.cond:
+ %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %entry ]
+ %arrayidx = getelementptr [1024 x float]* @A, i64 0, i64 3
+ %vecidx = bitcast float* %arrayidx to <4 x float>*
+ store <4 x float> zeroinitializer, <4 x float>* %vecidx, align 4
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp ne i64 %indvar, 1024
+ br i1 %exitcond, label %for.body, label %for.end
+
+for.body:
+ br label %for.cond
+
+for.end:
+ ret i32 0
+}
+
+;CHECK: store <4 x float> {{.*}} align 4
+
diff --git a/src/LLVM/test/Transforms/LICM/Preserve-LCSSA.ll b/src/LLVM/test/Transforms/LICM/Preserve-LCSSA.ll
new file mode 100644
index 0000000..832d762
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/Preserve-LCSSA.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -loop-rotate -licm -loop-unswitch -disable-output -verify-loop-info -verify-dom-info
+
+define i32 @stringSearch_Clib(i32 %count) {
+entry:
+ br i1 false, label %bb36, label %bb44
+
+bb4: ; preds = %bb36
+ br i1 false, label %cond_next, label %cond_true
+
+cond_true: ; preds = %bb4
+ ret i32 0
+
+cond_next: ; preds = %bb4
+ ret i32 0
+
+bb36: ; preds = %bb41, %entry
+ br i1 false, label %bb4, label %bb41
+
+bb41: ; preds = %bb36
+ %ttmp2 = icmp slt i32 0, %count ; <i1> [#uses=1]
+ br i1 %ttmp2, label %bb36, label %bb44
+
+bb44: ; preds = %bb41, %entry
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LICM/atomics.ll b/src/LLVM/test/Transforms/LICM/atomics.ll
new file mode 100644
index 0000000..3902152
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/atomics.ll
@@ -0,0 +1,79 @@
+; RUN: opt < %s -S -basicaa -licm | FileCheck %s
+
+; Check that we can hoist unordered loads
+define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
+ %val = load atomic i32* %y unordered, align 4
+ %inc = add nsw i32 %i, 1
+ %exitcond = icmp eq i32 %inc, %val
+ br i1 %exitcond, label %end, label %loop
+
+end:
+ ret i32 %val
+; CHECK: define i32 @test1(
+; CHECK: load atomic
+; CHECK-NEXT: br label %loop
+}
+
+; Check that we don't sink/hoist monotonic loads
+; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
+; use monotonic for spinlock-like constructs.)
+define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
+entry:
+ br label %loop
+
+loop:
+ %val = load atomic i32* %y monotonic, align 4
+ %exitcond = icmp ne i32 %val, 0
+ br i1 %exitcond, label %end, label %loop
+
+end:
+ ret i32 %val
+; CHECK: define i32 @test2(
+; CHECK: load atomic
+; CHECK-NEXT: %exitcond = icmp ne
+; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
+}
+
+; Check that we hoist unordered around monotonic.
+; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
+; smart yet.)
+define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
+entry:
+ br label %loop
+
+loop:
+ %vala = load atomic i32* %y monotonic, align 4
+ %valb = load atomic i32* %x unordered, align 4
+ %exitcond = icmp ne i32 %vala, %valb
+ br i1 %exitcond, label %end, label %loop
+
+end:
+ ret i32 %vala
+; CHECK: define i32 @test3(
+; CHECK: load atomic i32* %x unordered
+; CHECK-NEXT: br label %loop
+}
+
+; Don't try to "sink" unordered stores yet; it is legal, but the machinery
+; isn't there.
+define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
+entry:
+ br label %loop
+
+loop:
+ %vala = load atomic i32* %y monotonic, align 4
+ store atomic i32 %vala, i32* %x unordered, align 4
+ %exitcond = icmp ne i32 %vala, 0
+ br i1 %exitcond, label %end, label %loop
+
+end:
+ ret i32 %vala
+; CHECK: define i32 @test4(
+; CHECK: load atomic i32* %y monotonic
+; CHECK-NEXT: store atomic
+}
diff --git a/src/LLVM/test/Transforms/LICM/basictest.ll b/src/LLVM/test/Transforms/LICM/basictest.ll
new file mode 100644
index 0000000..dcb5364
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/basictest.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -licm | llvm-dis
+
+define void @testfunc(i32 %i) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %j = phi i32 [ 0, %0 ], [ %Next, %Loop ] ; <i32> [#uses=1]
+ %i2 = mul i32 %i, 17 ; <i32> [#uses=1]
+ %Next = add i32 %j, %i2 ; <i32> [#uses=2]
+ %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %Out, label %Loop
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/crash.ll b/src/LLVM/test/Transforms/LICM/crash.ll
new file mode 100644
index 0000000..ff7fa0b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/crash.ll
@@ -0,0 +1,74 @@
+; RUN: opt -licm %s -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+
+; PR8068
+@g_12 = external global i8, align 1
+define void @test1() nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.cond, %bb.nph
+ store i8 0, i8* @g_12, align 1
+ %tmp6 = load i8* @g_12, align 1
+ br label %for.cond
+
+for.cond: ; preds = %for.body
+ store i8 %tmp6, i8* @g_12, align 1
+ br i1 false, label %for.cond.for.end10_crit_edge, label %for.body
+
+for.cond.for.end10_crit_edge: ; preds = %for.cond
+ br label %for.end10
+
+for.end10: ; preds = %for.cond.for.end10_crit_edge, %entry
+ ret void
+}
+
+; PR8067
+@g_8 = external global i32, align 4
+
+define void @test2() noreturn nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %tmp7 = load i32* @g_8, align 4
+ store i32* @g_8, i32** undef, align 16
+ store i32 undef, i32* @g_8, align 4
+ br label %for.body
+}
+
+; PR8102
+define void @test3() {
+entry:
+ %__first = alloca { i32* }
+ br i1 undef, label %for.cond, label %for.end
+
+for.cond: ; preds = %for.cond, %entry
+ %tmp1 = getelementptr { i32*}* %__first, i32 0, i32 0
+ %tmp2 = load i32** %tmp1, align 4
+ %call = tail call i32* @test3helper(i32* %tmp2)
+ %tmp3 = getelementptr { i32*}* %__first, i32 0, i32 0
+ store i32* %call, i32** %tmp3, align 4
+ br i1 false, label %for.cond, label %for.end
+
+for.end: ; preds = %for.cond, %entry
+ ret void
+}
+
+declare i32* @test3helper(i32*)
+
+
+; PR8602
+@g_47 = external global i32, align 4
+
+define void @test4() noreturn nounwind {
+ br label %1
+
+; <label>:1 ; preds = %1, %0
+ volatile store i32* @g_47, i32** undef, align 8
+ store i32 undef, i32* @g_47, align 4
+ br label %1
+}
diff --git a/src/LLVM/test/Transforms/LICM/debug-value.ll b/src/LLVM/test/Transforms/LICM/debug-value.ll
new file mode 100644
index 0000000..889d4e2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/debug-value.ll
@@ -0,0 +1,62 @@
+; RUN: opt -licm -basicaa < %s -S | FileCheck %s
+
+define void @dgefa() nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.cond.backedge, %entry
+ br i1 undef, label %if.then, label %for.cond.backedge, !dbg !11
+
+for.cond.backedge: ; preds = %for.body61, %for.body61.us, %for.body
+ br i1 undef, label %for.end104, label %for.body, !dbg !15
+
+if.then: ; preds = %for.body
+ br i1 undef, label %if.then27, label %if.end.if.end.split_crit_edge.critedge, !dbg !16
+
+if.then27: ; preds = %if.then
+; CHECK: tail call void @llvm.dbg.value
+ tail call void @llvm.dbg.value(metadata !18, i64 0, metadata !19), !dbg !21
+ br label %for.body61.us
+
+if.end.if.end.split_crit_edge.critedge: ; preds = %if.then
+ br label %for.body61
+
+for.body61.us: ; preds = %for.body61.us, %if.then27
+ br i1 undef, label %for.cond.backedge, label %for.body61.us, !dbg !23
+
+for.body61: ; preds = %for.body61, %if.end.if.end.split_crit_edge.critedge
+ br i1 undef, label %for.cond.backedge, label %for.body61, !dbg !23
+
+for.end104: ; preds = %for.cond.backedge
+ ret void, !dbg !24
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0, !6, !9, !10}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"idamax", metadata !"idamax", metadata !"", metadata !1, i32 112, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"/Volumes/Lalgate/work/llvm/projects/llvm-test/SingleSource/Benchmarks/CoyoteBench/lpbench.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"/Volumes/Lalgate/work/llvm/projects/llvm-test/SingleSource/Benchmarks/CoyoteBench/lpbench.c", metadata !"/private/tmp", metadata !"clang version 2.9 (trunk 127169)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{metadata !5}
+!5 = metadata !{i32 589860, metadata !2, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!6 = metadata !{i32 589870, i32 0, metadata !1, metadata !"dscal", metadata !"dscal", metadata !"", metadata !1, i32 206, metadata !7, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null} ; [ DW_TAG_subprogram ]
+!7 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!8 = metadata !{null}
+!9 = metadata !{i32 589870, i32 0, metadata !1, metadata !"daxpy", metadata !"daxpy", metadata !"", metadata !1, i32 230, metadata !7, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null} ; [ DW_TAG_subprogram ]
+!10 = metadata !{i32 589870, i32 0, metadata !1, metadata !"dgefa", metadata !"dgefa", metadata !"", metadata !1, i32 267, metadata !7, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, null} ; [ DW_TAG_subprogram ]
+!11 = metadata !{i32 281, i32 9, metadata !12, null}
+!12 = metadata !{i32 589835, metadata !13, i32 272, i32 5, metadata !1, i32 32} ; [ DW_TAG_lexical_block ]
+!13 = metadata !{i32 589835, metadata !14, i32 271, i32 5, metadata !1, i32 31} ; [ DW_TAG_lexical_block ]
+!14 = metadata !{i32 589835, metadata !10, i32 267, i32 1, metadata !1, i32 30} ; [ DW_TAG_lexical_block ]
+!15 = metadata !{i32 271, i32 5, metadata !14, null}
+!16 = metadata !{i32 284, i32 10, metadata !17, null}
+!17 = metadata !{i32 589835, metadata !12, i32 282, i32 9, metadata !1, i32 33} ; [ DW_TAG_lexical_block ]
+!18 = metadata !{double undef}
+!19 = metadata !{i32 590080, metadata !14, metadata !"temp", metadata !1, i32 268, metadata !20, i32 0} ; [ DW_TAG_auto_variable ]
+!20 = metadata !{i32 589860, metadata !2, metadata !"double", null, i32 0, i64 64, i64 64, i64 0, i32 0, i32 4} ; [ DW_TAG_base_type ]
+!21 = metadata !{i32 286, i32 14, metadata !22, null}
+!22 = metadata !{i32 589835, metadata !17, i32 285, i32 13, metadata !1, i32 34} ; [ DW_TAG_lexical_block ]
+!23 = metadata !{i32 296, i32 13, metadata !17, null}
+!24 = metadata !{i32 313, i32 1, metadata !14, null}
diff --git a/src/LLVM/test/Transforms/LICM/dg.exp b/src/LLVM/test/Transforms/LICM/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LICM/hoisting.ll b/src/LLVM/test/Transforms/LICM/hoisting.ll
new file mode 100644
index 0000000..1e4131d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/hoisting.ll
@@ -0,0 +1,66 @@
+; RUN: opt < %s -licm -S | FileCheck %s
+
+@X = global i32 0 ; <i32*> [#uses=1]
+
+declare void @foo()
+
+; This testcase tests for a problem where LICM hoists
+; potentially trapping instructions when they are not guaranteed to execute.
+define i32 @test1(i1 %c) {
+; CHECK: @test1
+ %A = load i32* @X ; <i32> [#uses=2]
+ br label %Loop
+Loop: ; preds = %LoopTail, %0
+ call void @foo( )
+ br i1 %c, label %LoopTail, label %IfUnEqual
+
+IfUnEqual: ; preds = %Loop
+; CHECK: IfUnEqual:
+; CHECK-NEXT: sdiv i32 4, %A
+ %B1 = sdiv i32 4, %A ; <i32> [#uses=1]
+ br label %LoopTail
+
+LoopTail: ; preds = %IfUnEqual, %Loop
+ %B = phi i32 [ 0, %Loop ], [ %B1, %IfUnEqual ] ; <i32> [#uses=1]
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %LoopTail
+ %C = sub i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+
+declare void @foo2(i32)
+
+
+;; It is ok and desirable to hoist this potentially trapping instruction.
+define i32 @test2(i1 %c) {
+; CHECK: @test2
+; CHECK-NEXT: load i32* @X
+; CHECK-NEXT: %B = sdiv i32 4, %A
+ %A = load i32* @X ; <i32> [#uses=2]
+ br label %Loop
+Loop:
+ ;; Should have hoisted this div!
+ %B = sdiv i32 4, %A ; <i32> [#uses=2]
+ call void @foo2( i32 %B )
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %Loop
+ %C = sub i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
+
+
+; This loop invariant instruction should be constant folded, not hoisted.
+define i32 @test3(i1 %c) {
+; CHECK: define i32 @test3
+; CHECK: call void @foo2(i32 6)
+ %A = load i32* @X ; <i32> [#uses=2]
+ br label %Loop
+Loop:
+ %B = add i32 4, 2 ; <i32> [#uses=2]
+ call void @foo2( i32 %B )
+ br i1 %c, label %Loop, label %Out
+Out: ; preds = %Loop
+ %C = sub i32 %A, %B ; <i32> [#uses=1]
+ ret i32 %C
+}
diff --git a/src/LLVM/test/Transforms/LICM/no-preheader-test.ll b/src/LLVM/test/Transforms/LICM/no-preheader-test.ll
new file mode 100644
index 0000000..c3eb336
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/no-preheader-test.ll
@@ -0,0 +1,20 @@
+; Test that LICM works when there is not a loop-preheader
+; RUN: opt < %s -licm | llvm-dis
+
+define void @testfunc(i32 %i.s, i1 %ifcond) {
+ br i1 %ifcond, label %Then, label %Else
+Then: ; preds = %0
+ br label %Loop
+Else: ; preds = %0
+ br label %Loop
+Loop: ; preds = %Loop, %Else, %Then
+ %j = phi i32 [ 0, %Then ], [ 12, %Else ], [ %Next, %Loop ] ; <i32> [#uses=1]
+ %i = bitcast i32 %i.s to i32 ; <i32> [#uses=1]
+ %i2 = mul i32 %i, 17 ; <i32> [#uses=1]
+ %Next = add i32 %j, %i2 ; <i32> [#uses=2]
+ %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %Out, label %Loop
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LICM/scalar-promote-memmodel.ll b/src/LLVM/test/Transforms/LICM/scalar-promote-memmodel.ll
new file mode 100644
index 0000000..23d70f5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/scalar-promote-memmodel.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -basicaa -licm -S | FileCheck %s
+
+; Make sure we don't hoist a conditionally-executed store out of the loop;
+; it would violate the concurrency memory model
+
+@g = common global i32 0, align 4
+
+define void @bar(i32 %n, i32 %b) nounwind uwtable ssp {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %inc5, %for.inc ]
+ %cmp = icmp slt i32 %i.0, %n
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %tobool = icmp eq i32 %b, 0
+ br i1 %tobool, label %for.inc, label %if.then
+
+if.then: ; preds = %for.body
+ %tmp3 = load i32* @g, align 4
+ %inc = add nsw i32 %tmp3, 1
+ store i32 %inc, i32* @g, align 4
+ br label %for.inc
+
+; CHECK: load i32*
+; CHECK-NEXT: add
+; CHECK-NEXT: store i32
+
+for.inc: ; preds = %for.body, %if.then
+ %inc5 = add nsw i32 %i.0, 1
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LICM/scalar_promote.ll b/src/LLVM/test/Transforms/LICM/scalar_promote.ll
new file mode 100644
index 0000000..a1e9342
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/scalar_promote.ll
@@ -0,0 +1,150 @@
+; RUN: opt < %s -basicaa -licm -S | FileCheck %s
+target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
+
+@X = global i32 7 ; <i32*> [#uses=4]
+
+define void @test1(i32 %i) {
+Entry:
+ br label %Loop
+; CHECK: @test1
+; CHECK: Entry:
+; CHECK-NEXT: load i32* @X
+; CHECK-NEXT: br label %Loop
+
+
+Loop: ; preds = %Loop, %0
+ %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] ; <i32> [#uses=1]
+ %x = load i32* @X ; <i32> [#uses=1]
+ %x2 = add i32 %x, 1 ; <i32> [#uses=1]
+ store i32 %x2, i32* @X
+ %Next = add i32 %j, 1 ; <i32> [#uses=2]
+ %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %Out, label %Loop
+
+Out:
+ ret void
+; CHECK: Out:
+; CHECK-NEXT: store i32 %x2, i32* @X
+; CHECK-NEXT: ret void
+
+}
+
+define void @test2(i32 %i) {
+Entry:
+ br label %Loop
+; CHECK: @test2
+; CHECK: Entry:
+; CHECK-NEXT: %.promoted = load i32* getelementptr inbounds (i32* @X, i64 1)
+; CHECK-NEXT: br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %X1 = getelementptr i32* @X, i64 1 ; <i32*> [#uses=1]
+ %A = load i32* %X1 ; <i32> [#uses=1]
+ %V = add i32 %A, 1 ; <i32> [#uses=1]
+ %X2 = getelementptr i32* @X, i64 1 ; <i32*> [#uses=1]
+ store i32 %V, i32* %X2
+ br i1 false, label %Loop, label %Exit
+
+Exit: ; preds = %Loop
+ ret void
+; CHECK: Exit:
+; CHECK-NEXT: store i32 %V, i32* getelementptr inbounds (i32* @X, i64 1)
+; CHECK-NEXT: ret void
+}
+
+
+
+define void @test3(i32 %i) {
+; CHECK: @test3
+ br label %Loop
+Loop:
+ ; Should not promote this to a register
+ %x = volatile load i32* @X
+ %x2 = add i32 %x, 1
+ store i32 %x2, i32* @X
+ br i1 true, label %Out, label %Loop
+
+; CHECK: Loop:
+; CHECK-NEXT: load volatile
+
+Out: ; preds = %Loop
+ ret void
+}
+
+; PR8041
+define void @test4(i8* %x, i8 %n) {
+; CHECK: @test4
+ %handle1 = alloca i8*
+ %handle2 = alloca i8*
+ store i8* %x, i8** %handle1
+ br label %loop
+
+loop:
+ %tmp = getelementptr i8* %x, i64 8
+ store i8* %tmp, i8** %handle2
+ br label %subloop
+
+subloop:
+ %count = phi i8 [ 0, %loop ], [ %nextcount, %subloop ]
+ %offsetx2 = load i8** %handle2
+ store i8 %n, i8* %offsetx2
+ %newoffsetx2 = getelementptr i8* %offsetx2, i64 -1
+ store i8* %newoffsetx2, i8** %handle2
+ %nextcount = add i8 %count, 1
+ %innerexitcond = icmp sge i8 %nextcount, 8
+ br i1 %innerexitcond, label %innerexit, label %subloop
+
+; Should have promoted 'handle2' accesses.
+; CHECK: subloop:
+; CHECK-NEXT: phi i8* [
+; CHECK-NEXT: %count = phi i8 [
+; CHECK-NEXT: store i8 %n
+; CHECK-NOT: store
+; CHECK: br i1
+
+innerexit:
+ %offsetx1 = load i8** %handle1
+ %val = load i8* %offsetx1
+ %cond = icmp eq i8 %val, %n
+ br i1 %cond, label %exit, label %loop
+
+; Should not have promoted offsetx1 loads.
+; CHECK: innerexit:
+; CHECK: %val = load i8* %offsetx1
+; CHECK: %cond = icmp eq i8 %val, %n
+; CHECK: br i1 %cond, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+define void @test5(i32 %i, i32** noalias %P2) {
+Entry:
+ br label %Loop
+; CHECK: @test5
+; CHECK: Entry:
+; CHECK-NEXT: load i32* @X
+; CHECK-NEXT: br label %Loop
+
+
+Loop: ; preds = %Loop, %0
+ %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] ; <i32> [#uses=1]
+ %x = load i32* @X ; <i32> [#uses=1]
+ %x2 = add i32 %x, 1 ; <i32> [#uses=1]
+ store i32 %x2, i32* @X
+
+ volatile store i32* @X, i32** %P2
+
+ %Next = add i32 %j, 1 ; <i32> [#uses=2]
+ %cond = icmp eq i32 %Next, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %Out, label %Loop
+
+Out:
+ ret void
+; CHECK: Out:
+; CHECK-NEXT: store i32 %x2, i32* @X
+; CHECK-NEXT: ret void
+
+}
+
+
diff --git a/src/LLVM/test/Transforms/LICM/sinking.ll b/src/LLVM/test/Transforms/LICM/sinking.ll
new file mode 100644
index 0000000..68e4b64
--- /dev/null
+++ b/src/LLVM/test/Transforms/LICM/sinking.ll
@@ -0,0 +1,249 @@
+; RUN: opt < %s -basicaa -licm -S | FileCheck %s
+
+declare i32 @strlen(i8*) readonly
+
+declare void @foo()
+
+; Sink readonly function.
+define i32 @test1(i8* %P) {
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ %A = call i32 @strlen( i8* %P ) readonly
+ br i1 false, label %Loop, label %Out
+
+Out: ; preds = %Loop
+ ret i32 %A
+; CHECK: @test1
+; CHECK: Out:
+; CHECK-NEXT: call i32 @strlen
+; CHECK-NEXT: ret i32 %A
+}
+
+declare double @sin(double) readnone
+
+; Sink readnone function out of loop with unknown memory behavior.
+define double @test2(double %X) {
+ br label %Loop
+
+Loop: ; preds = %Loop, %0
+ call void @foo( )
+ %A = call double @sin( double %X ) readnone
+ br i1 true, label %Loop, label %Out
+
+Out: ; preds = %Loop
+ ret double %A
+; CHECK: @test2
+; CHECK: Out:
+; CHECK-NEXT: call double @sin
+; CHECK-NEXT: ret double %A
+}
+
+; This testcase checks to make sure the sinker does not cause problems with
+; critical edges.
+define void @test3() {
+Entry:
+ br i1 false, label %Loop, label %Exit
+Loop:
+ %X = add i32 0, 1
+ br i1 false, label %Loop, label %Exit
+Exit:
+ %Y = phi i32 [ 0, %Entry ], [ %X, %Loop ]
+ ret void
+
+; CHECK: @test3
+; CHECK: Exit.loopexit:
+; CHECK-NEXT: %X = add i32 0, 1
+; CHECK-NEXT: br label %Exit
+
+}
+
+; If the result of an instruction is only used outside of the loop, sink
+; the instruction to the exit blocks instead of executing it on every
+; iteration of the loop.
+;
+define i32 @test4(i32 %N) {
+Entry:
+ br label %Loop
+Loop: ; preds = %Loop, %Entry
+ %N_addr.0.pn = phi i32 [ %dec, %Loop ], [ %N, %Entry ]
+ %tmp.6 = mul i32 %N, %N_addr.0.pn ; <i32> [#uses=1]
+ %tmp.7 = sub i32 %tmp.6, %N ; <i32> [#uses=1]
+ %dec = add i32 %N_addr.0.pn, -1 ; <i32> [#uses=1]
+ %tmp.1 = icmp ne i32 %N_addr.0.pn, 1 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret i32 %tmp.7
+; CHECK: @test4
+; CHECK: Out:
+; CHECK-NEXT: mul i32 %N, %N_addr.0.pn
+; CHECK-NEXT: sub i32 %tmp.6, %N
+; CHECK-NEXT: ret i32
+}
+
+; To reduce register pressure, if a load is hoistable out of the loop, and the
+; result of the load is only used outside of the loop, sink the load instead of
+; hoisting it!
+;
+@X = global i32 5 ; <i32*> [#uses=1]
+
+define i32 @test5(i32 %N) {
+Entry:
+ br label %Loop
+Loop: ; preds = %Loop, %Entry
+ %N_addr.0.pn = phi i32 [ %dec, %Loop ], [ %N, %Entry ]
+ %tmp.6 = load i32* @X ; <i32> [#uses=1]
+ %dec = add i32 %N_addr.0.pn, -1 ; <i32> [#uses=1]
+ %tmp.1 = icmp ne i32 %N_addr.0.pn, 1 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret i32 %tmp.6
+; CHECK: @test5
+; CHECK: Out:
+; CHECK-NEXT: %tmp.6 = load i32* @X
+; CHECK-NEXT: ret i32 %tmp.6
+}
+
+
+
+; The loop sinker was running from the bottom of the loop to the top, causing
+; it to miss opportunities to sink instructions that depended on sinking other
+; instructions from the loop. Instead they got hoisted, which is better than
+; leaving them in the loop, but increases register pressure pointlessly.
+
+ %Ty = type { i32, i32 }
+@X2 = external global %Ty
+
+define i32 @test6() {
+ br label %Loop
+Loop:
+ %dead = getelementptr %Ty* @X2, i64 0, i32 0
+ %sunk2 = load i32* %dead
+ br i1 false, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret i32 %sunk2
+; CHECK: @test6
+; CHECK: Out:
+; CHECK-NEXT: %dead = getelementptr %Ty* @X2, i64 0, i32 0
+; CHECK-NEXT: %sunk2 = load i32* %dead
+; CHECK-NEXT: ret i32 %sunk2
+}
+
+
+
+; This testcase ensures that we can sink instructions from loops with
+; multiple exits.
+;
+define i32 @test7(i32 %N, i1 %C) {
+Entry:
+ br label %Loop
+Loop: ; preds = %ContLoop, %Entry
+ %N_addr.0.pn = phi i32 [ %dec, %ContLoop ], [ %N, %Entry ]
+ %tmp.6 = mul i32 %N, %N_addr.0.pn
+ %tmp.7 = sub i32 %tmp.6, %N ; <i32> [#uses=2]
+ %dec = add i32 %N_addr.0.pn, -1 ; <i32> [#uses=1]
+ br i1 %C, label %ContLoop, label %Out1
+ContLoop:
+ %tmp.1 = icmp ne i32 %N_addr.0.pn, 1
+ br i1 %tmp.1, label %Loop, label %Out2
+Out1: ; preds = %Loop
+ ret i32 %tmp.7
+Out2: ; preds = %ContLoop
+ ret i32 %tmp.7
+; CHECK: @test7
+; CHECK: Out1:
+; CHECK-NEXT: mul i32 %N, %N_addr.0.pn
+; CHECK-NEXT: sub i32 %tmp.6, %N
+; CHECK-NEXT: ret
+; CHECK: Out2:
+; CHECK-NEXT: mul i32 %N, %N_addr.0.pn
+; CHECK-NEXT: sub i32 %tmp.6
+; CHECK-NEXT: ret
+}
+
+
+; This testcase checks to make sure we can sink values which are only live on
+; some exits out of the loop, and that we can do so without breaking dominator
+; info.
+define i32 @test8(i1 %C1, i1 %C2, i32* %P, i32* %Q) {
+Entry:
+ br label %Loop
+Loop: ; preds = %Cont, %Entry
+ br i1 %C1, label %Cont, label %exit1
+Cont: ; preds = %Loop
+ %X = load i32* %P ; <i32> [#uses=2]
+ store i32 %X, i32* %Q
+ %V = add i32 %X, 1 ; <i32> [#uses=1]
+ br i1 %C2, label %Loop, label %exit2
+exit1: ; preds = %Loop
+ ret i32 0
+exit2: ; preds = %Cont
+ ret i32 %V
+; CHECK: @test8
+; CHECK: exit1:
+; CHECK-NEXT: ret i32 0
+; CHECK: exit2:
+; CHECK-NEXT: %V = add i32 %X, 1
+; CHECK-NEXT: ret i32 %V
+}
+
+
+define void @test9() {
+loopentry.2.i:
+ br i1 false, label %no_exit.1.i.preheader, label %loopentry.3.i.preheader
+no_exit.1.i.preheader: ; preds = %loopentry.2.i
+ br label %no_exit.1.i
+no_exit.1.i: ; preds = %endif.8.i, %no_exit.1.i.preheader
+ br i1 false, label %return.i, label %endif.8.i
+endif.8.i: ; preds = %no_exit.1.i
+ %inc.1.i = add i32 0, 1 ; <i32> [#uses=1]
+ br i1 false, label %no_exit.1.i, label %loopentry.3.i.preheader.loopexit
+loopentry.3.i.preheader.loopexit: ; preds = %endif.8.i
+ br label %loopentry.3.i.preheader
+loopentry.3.i.preheader: ; preds = %loopentry.3.i.preheader.loopexit, %loopentry.2.i
+ %arg_num.0.i.ph13000 = phi i32 [ 0, %loopentry.2.i ], [ %inc.1.i, %loopentry.3.i.preheader.loopexit ] ; <i32> [#uses=0]
+ ret void
+return.i: ; preds = %no_exit.1.i
+ ret void
+
+; CHECK: @test9
+; CHECK: loopentry.3.i.preheader.loopexit:
+; CHECK-NEXT: %inc.1.i = add i32 0, 1
+; CHECK-NEXT: br label %loopentry.3.i.preheader
+}
+
+
+; Potentially trapping instructions may be sunk as long as they are guaranteed
+; to be executed.
+define i32 @test10(i32 %N) {
+Entry:
+ br label %Loop
+Loop: ; preds = %Loop, %Entry
+ %N_addr.0.pn = phi i32 [ %dec, %Loop ], [ %N, %Entry ] ; <i32> [#uses=3]
+ %tmp.6 = sdiv i32 %N, %N_addr.0.pn ; <i32> [#uses=1]
+ %dec = add i32 %N_addr.0.pn, -1 ; <i32> [#uses=1]
+ %tmp.1 = icmp ne i32 %N_addr.0.pn, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret i32 %tmp.6
+
+; CHECK: @test10
+; CHECK: Out:
+; CHECK-NEXT: %tmp.6 = sdiv i32 %N, %N_addr.0.pn
+; CHECK-NEXT: ret i32 %tmp.6
+}
+
+; Should delete, not sink, dead instructions.
+define void @test11() {
+ br label %Loop
+Loop:
+ %dead = getelementptr %Ty* @X2, i64 0, i32 0
+ br i1 false, label %Loop, label %Out
+Out:
+ ret void
+; CHECK: @test11
+; CHECK: Out:
+; CHECK-NEXT: ret void
+}
+
+
diff --git a/src/LLVM/test/Transforms/LoopDeletion/2007-07-23-InfiniteLoop.ll b/src/LLVM/test/Transforms/LoopDeletion/2007-07-23-InfiniteLoop.ll
new file mode 100644
index 0000000..bcc73fd
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/2007-07-23-InfiniteLoop.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -loop-deletion -S | grep switch
+; PR 1564
+
+define fastcc void @out() {
+ start:
+ br label %loop
+ unreachable:
+ unreachable
+ loop:
+ switch i32 0, label %unreachable [
+ i32 0, label %loop
+ ]
+}
diff --git a/src/LLVM/test/Transforms/LoopDeletion/2008-05-06-Phi.ll b/src/LLVM/test/Transforms/LoopDeletion/2008-05-06-Phi.ll
new file mode 100644
index 0000000..ff6a30d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/2008-05-06-Phi.ll
@@ -0,0 +1,109 @@
+; RUN: opt < %s -inline -instcombine -jump-threading -licm -loop-unswitch -instcombine -indvars -loop-deletion -gvn -simplifycfg -verify -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9"
+ %struct.BF_BitstreamElement = type { i32, i16 }
+ %struct.BF_BitstreamPart = type { i32, %struct.BF_BitstreamElement* }
+ %struct.BF_PartHolder = type { i32, %struct.BF_BitstreamPart* }
+ %struct.Bit_stream_struc = type { i8*, i32, %struct.FILE*, i8*, i32, i32, i32, i32 }
+ %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+ %struct.III_scalefac_t = type { [22 x i32], [13 x [3 x i32]] }
+ %struct.III_side_info_t = type { i32, i32, i32, [2 x [4 x i32]], [2 x %struct.anon] }
+ %struct.__sFILEX = type opaque
+ %struct.__sbuf = type { i8*, i32 }
+ %struct.anon = type { [2 x %struct.gr_info_ss] }
+ %struct.gr_info = type { i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], [3 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32*, [4 x i32] }
+ %struct.gr_info_ss = type { %struct.gr_info }
+ %struct.lame_global_flags = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, i32, i32, i32, float, float, float, float, i32, i32, i32, i32, i32, i32, i32, i32 }
+@scaleFactorsPH = external global [2 x [2 x %struct.BF_PartHolder*]] ; <[2 x [2 x %struct.BF_PartHolder*]]*> [#uses=1]
+@slen1_tab = external constant [16 x i32] ; <[16 x i32]*> [#uses=1]
+
+declare %struct.BF_PartHolder* @BF_addElement(%struct.BF_PartHolder*, %struct.BF_BitstreamElement*) nounwind
+
+define %struct.BF_PartHolder* @BF_addEntry(%struct.BF_PartHolder* %thePH, i32 %value, i32 %length) nounwind {
+entry:
+ %myElement = alloca %struct.BF_BitstreamElement ; <%struct.BF_BitstreamElement*> [#uses=2]
+ %tmp1 = getelementptr %struct.BF_BitstreamElement* %myElement, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 %value, i32* %tmp1, align 8
+ %tmp7 = icmp eq i32 %length, 0 ; <i1> [#uses=1]
+ br i1 %tmp7, label %bb13, label %bb
+
+bb: ; preds = %entry
+ %tmp10 = call %struct.BF_PartHolder* @BF_addElement( %struct.BF_PartHolder* %thePH, %struct.BF_BitstreamElement* %myElement ) nounwind ; <%struct.BF_PartHolder*> [#uses=1]
+ ret %struct.BF_PartHolder* %tmp10
+
+bb13: ; preds = %entry
+ ret %struct.BF_PartHolder* %thePH
+}
+
+define void @III_format_bitstream(%struct.lame_global_flags* %gfp, i32 %bitsPerFrame, [2 x [576 x i32]]* %l3_enc, %struct.III_side_info_t* %l3_side, [2 x %struct.III_scalefac_t]* %scalefac, %struct.Bit_stream_struc* %in_bs) nounwind {
+entry:
+ call fastcc void @encodeMainData( %struct.lame_global_flags* %gfp, [2 x [576 x i32]]* %l3_enc, %struct.III_side_info_t* %l3_side, [2 x %struct.III_scalefac_t]* %scalefac ) nounwind
+ unreachable
+}
+
+define internal fastcc void @encodeMainData(%struct.lame_global_flags* %gfp, [2 x [576 x i32]]* %l3_enc, %struct.III_side_info_t* %si, [2 x %struct.III_scalefac_t]* %scalefac) nounwind {
+entry:
+ %tmp69 = getelementptr %struct.lame_global_flags* %gfp, i32 0, i32 43 ; <i32*> [#uses=1]
+ %tmp70 = load i32* %tmp69, align 4 ; <i32> [#uses=1]
+ %tmp71 = icmp eq i32 %tmp70, 1 ; <i1> [#uses=1]
+ br i1 %tmp71, label %bb352, label %bb498
+
+bb113: ; preds = %bb132
+ %tmp123 = getelementptr [2 x %struct.III_scalefac_t]* %scalefac, i32 0, i32 0, i32 1, i32 %sfb.0, i32 %window.0 ; <i32*> [#uses=1]
+ %tmp124 = load i32* %tmp123, align 4 ; <i32> [#uses=1]
+ %tmp126 = load %struct.BF_PartHolder** %tmp80, align 4 ; <%struct.BF_PartHolder*> [#uses=1]
+ %tmp128 = call %struct.BF_PartHolder* @BF_addEntry( %struct.BF_PartHolder* %tmp126, i32 %tmp124, i32 %tmp93 ) nounwind ; <%struct.BF_PartHolder*> [#uses=1]
+ store %struct.BF_PartHolder* %tmp128, %struct.BF_PartHolder** %tmp80, align 4
+ %tmp131 = add i32 %window.0, 1 ; <i32> [#uses=1]
+ br label %bb132
+
+bb132: ; preds = %bb140, %bb113
+ %window.0 = phi i32 [ %tmp131, %bb113 ], [ 0, %bb140 ] ; <i32> [#uses=3]
+ %tmp134 = icmp slt i32 %window.0, 3 ; <i1> [#uses=1]
+ br i1 %tmp134, label %bb113, label %bb137
+
+bb137: ; preds = %bb132
+ %tmp139 = add i32 %sfb.0, 1 ; <i32> [#uses=1]
+ br label %bb140
+
+bb140: ; preds = %bb341, %bb137
+ %sfb.0 = phi i32 [ %tmp139, %bb137 ], [ 0, %bb341 ] ; <i32> [#uses=3]
+ %tmp142 = icmp slt i32 %sfb.0, 6 ; <i1> [#uses=1]
+ br i1 %tmp142, label %bb132, label %bb174
+
+bb166: ; preds = %bb174
+ %tmp160 = load %struct.BF_PartHolder** %tmp80, align 4 ; <%struct.BF_PartHolder*> [#uses=1]
+ %tmp162 = call %struct.BF_PartHolder* @BF_addEntry( %struct.BF_PartHolder* %tmp160, i32 0, i32 0 ) nounwind ; <%struct.BF_PartHolder*> [#uses=0]
+ unreachable
+
+bb174: ; preds = %bb140
+ %tmp176 = icmp slt i32 6, 12 ; <i1> [#uses=1]
+ br i1 %tmp176, label %bb166, label %bb341
+
+bb341: ; preds = %bb352, %bb174
+ %tmp80 = getelementptr [2 x [2 x %struct.BF_PartHolder*]]* @scaleFactorsPH, i32 0, i32 0, i32 0 ; <%struct.BF_PartHolder**> [#uses=3]
+ %tmp92 = getelementptr [16 x i32]* @slen1_tab, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp93 = load i32* %tmp92, align 4 ; <i32> [#uses=1]
+ br label %bb140
+
+bb352: ; preds = %entry
+ %tmp354 = icmp slt i32 0, 2 ; <i1> [#uses=1]
+ br i1 %tmp354, label %bb341, label %return
+
+bb498: ; preds = %entry
+ ret void
+
+return: ; preds = %bb352
+ ret void
+}
+
+define void @getframebits(%struct.lame_global_flags* %gfp, i32* %bitsPerFrame, i32* %mean_bits) nounwind {
+entry:
+ unreachable
+}
+
+define i32 @lame_encode_buffer(%struct.lame_global_flags* %gfp, i16* %buffer_l, i16* %buffer_r, i32 %nsamples, i8* %mp3buf, i32 %mp3buf_size) nounwind {
+entry:
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopDeletion/2011-06-21-phioperands.ll b/src/LLVM/test/Transforms/LoopDeletion/2011-06-21-phioperands.ll
new file mode 100644
index 0000000..40c6629
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/2011-06-21-phioperands.ll
@@ -0,0 +1,182 @@
+; RUN: opt %s -loop-deletion -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+%0 = type { %"class.llvm::SmallVectorImpl", [1 x %"union.llvm::SmallVectorBase::U"] }
+%"class.clang::SourceLocation" = type { i32 }
+%"class.clang::driver::Arg" = type { %"class.clang::driver::Option"*, %"class.clang::driver::Arg"*, i32, i8, %0 }
+%"class.clang::driver::Option" = type { i32 (...)**, i32, %"class.clang::SourceLocation", i8*, %"class.clang::driver::OptionGroup"*, %"class.clang::driver::Option"*, i8 }
+%"class.clang::driver::OptionGroup" = type { %"class.clang::driver::Option" }
+%"class.llvm::SmallVectorBase" = type { i8*, i8*, i8*, %"union.llvm::SmallVectorBase::U" }
+%"class.llvm::SmallVectorImpl" = type { %"class.llvm::SmallVectorTemplateBase" }
+%"class.llvm::SmallVectorTemplateBase" = type { %"class.llvm::SmallVectorTemplateCommon" }
+%"class.llvm::SmallVectorTemplateCommon" = type { %"class.llvm::SmallVectorBase" }
+%"union.llvm::SmallVectorBase::U" = type { x86_fp80 }
+
+define void @_ZNK5clang6driver7ArgList20AddAllArgsTranslatedERN4llvm11SmallVectorIPKcLj16EEENS0_12OptSpecifierES5_b(i1 zeroext %Joined) nounwind align 2 {
+entry:
+ br i1 undef, label %entry.split.us, label %entry.entry.split_crit_edge
+
+entry.entry.split_crit_edge: ; preds = %entry
+ br label %entry.split
+
+entry.split.us: ; preds = %entry
+ br label %for.cond.i14.us
+
+for.cond.i14.us: ; preds = %for.inc.i38.us, %entry.split.us
+ br i1 true, label %for.cond.i50.us-lcssa.us, label %if.end.i23.us
+
+for.inc.i38.us: ; preds = %if.end.i23.us
+ br label %for.cond.i14.us
+
+if.end.i23.us: ; preds = %for.cond.i14.us
+ br i1 true, label %for.cond.i50.us-lcssa.us, label %for.inc.i38.us
+
+for.cond.i50.us-lcssa.us: ; preds = %if.end.i23.us, %for.cond.i14.us
+ br label %for.cond.i50
+
+entry.split: ; preds = %entry.entry.split_crit_edge
+ br label %for.cond.i14
+
+for.cond.i14: ; preds = %for.inc.i38, %entry.split
+ br i1 undef, label %for.cond.i50.us-lcssa, label %if.end.i23
+
+if.end.i23: ; preds = %for.cond.i14
+ br i1 undef, label %for.cond.i50.us-lcssa, label %for.inc.i38
+
+for.inc.i38: ; preds = %if.end.i23
+ br label %for.cond.i14
+
+for.cond.i50.us-lcssa: ; preds = %if.end.i23, %for.cond.i14
+ br label %for.cond.i50
+
+for.cond.i50: ; preds = %for.cond.i50.us-lcssa, %for.cond.i50.us-lcssa.us
+ br label %for.cond
+
+for.cond.loopexit.us-lcssa: ; preds = %if.end.i, %for.cond.i
+ br label %for.cond.loopexit
+
+for.cond.loopexit: ; preds = %for.cond.loopexit.us-lcssa.us, %for.cond.loopexit.us-lcssa
+ br label %for.cond
+
+for.cond: ; preds = %for.cond.loopexit, %for.cond.i50
+ br i1 undef, label %for.end, label %for.body
+
+for.body: ; preds = %for.cond
+ br i1 %Joined, label %if.then, label %if.else
+
+if.then: ; preds = %for.body
+ br i1 undef, label %cond.false.i.i, label %_ZN4llvm9StringRefC1EPKc.exit
+
+cond.false.i.i: ; preds = %if.then
+ unreachable
+
+_ZN4llvm9StringRefC1EPKc.exit: ; preds = %if.then
+ br i1 undef, label %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit, label %cond.false.i.i91
+
+cond.false.i.i91: ; preds = %_ZN4llvm9StringRefC1EPKc.exit
+ unreachable
+
+_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit: ; preds = %_ZN4llvm9StringRefC1EPKc.exit
+ br i1 undef, label %cond.false.i.i.i, label %if.end13.i.i.i.i
+
+if.end13.i.i.i.i: ; preds = %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit
+ br i1 undef, label %land.lhs.true16.i.i.i.i, label %if.end19.i.i.i.i
+
+land.lhs.true16.i.i.i.i: ; preds = %if.end13.i.i.i.i
+ br i1 undef, label %cond.false.i.i.i, label %_ZNK4llvm5Twine8isBinaryEv.exit8.i.i.i.i
+
+_ZNK4llvm5Twine8isBinaryEv.exit8.i.i.i.i: ; preds = %land.lhs.true16.i.i.i.i
+ br i1 undef, label %cond.false.i.i.i, label %if.end19.i.i.i.i
+
+if.end19.i.i.i.i: ; preds = %_ZNK4llvm5Twine8isBinaryEv.exit8.i.i.i.i, %if.end13.i.i.i.i
+ br i1 undef, label %land.lhs.true22.i.i.i.i, label %_ZN4llvmplERKNS_9StringRefEPKc.exit
+
+land.lhs.true22.i.i.i.i: ; preds = %if.end19.i.i.i.i
+ br i1 undef, label %cond.false.i.i.i, label %_ZNK4llvm5Twine8isBinaryEv.exit.i.i.i.i
+
+_ZNK4llvm5Twine8isBinaryEv.exit.i.i.i.i: ; preds = %land.lhs.true22.i.i.i.i
+ br i1 undef, label %cond.false.i.i.i, label %_ZN4llvmplERKNS_9StringRefEPKc.exit
+
+cond.false.i.i.i: ; preds = %_ZNK4llvm5Twine8isBinaryEv.exit.i.i.i.i, %land.lhs.true22.i.i.i.i, %_ZNK4llvm5Twine8isBinaryEv.exit8.i.i.i.i, %land.lhs.true16.i.i.i.i, %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit
+ unreachable
+
+_ZN4llvmplERKNS_9StringRefEPKc.exit: ; preds = %_ZNK4llvm5Twine8isBinaryEv.exit.i.i.i.i, %if.end19.i.i.i.i
+ br i1 undef, label %Retry.i, label %if.end.i99
+
+Retry.i: ; preds = %if.end.i99, %_ZN4llvmplERKNS_9StringRefEPKc.exit
+ br i1 undef, label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit, label %new.notnull.i
+
+new.notnull.i: ; preds = %Retry.i
+ br label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit
+
+if.end.i99: ; preds = %_ZN4llvmplERKNS_9StringRefEPKc.exit
+ br label %Retry.i
+
+_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit: ; preds = %new.notnull.i, %Retry.i
+ br label %for.cond.i.preheader
+
+if.else: ; preds = %for.body
+ br i1 undef, label %Retry.i108, label %if.end.i113
+
+Retry.i108: ; preds = %if.end.i113, %if.else
+ br i1 undef, label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit114, label %new.notnull.i110
+
+new.notnull.i110: ; preds = %Retry.i108
+ br label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit114
+
+if.end.i113: ; preds = %if.else
+ br label %Retry.i108
+
+_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit114: ; preds = %new.notnull.i110, %Retry.i108
+ br i1 undef, label %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit125, label %cond.false.i.i123
+
+cond.false.i.i123: ; preds = %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit114
+ unreachable
+
+_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit125: ; preds = %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit114
+ br i1 undef, label %Retry.i134, label %if.end.i139
+
+Retry.i134: ; preds = %if.end.i139, %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit125
+ br i1 undef, label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit140, label %new.notnull.i136
+
+new.notnull.i136: ; preds = %Retry.i134
+ br label %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit140
+
+if.end.i139: ; preds = %_ZNK5clang6driver3Arg8getValueERKNS0_7ArgListEj.exit125
+ br label %Retry.i134
+
+_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit140: ; preds = %new.notnull.i136, %Retry.i134
+ br label %for.cond.i.preheader
+
+for.cond.i.preheader: ; preds = %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit140, %_ZN4llvm15SmallVectorImplIPKcE9push_backERKS2_.exit
+ br i1 undef, label %for.cond.i.preheader.split.us, label %for.cond.i.preheader.for.cond.i.preheader.split_crit_edge
+
+for.cond.i.preheader.for.cond.i.preheader.split_crit_edge: ; preds = %for.cond.i.preheader
+ br label %for.cond.i.preheader.split
+
+for.cond.i.preheader.split.us: ; preds = %for.cond.i.preheader
+ br label %for.cond.i.us
+
+for.cond.i.us: ; preds = %if.end.i.us, %for.cond.i.preheader.split.us
+ br i1 true, label %for.cond.loopexit.us-lcssa.us, label %if.end.i.us
+
+if.end.i.us: ; preds = %for.cond.i.us
+ br i1 true, label %for.cond.loopexit.us-lcssa.us, label %for.cond.i.us
+
+for.cond.loopexit.us-lcssa.us: ; preds = %if.end.i.us, %for.cond.i.us
+ %tmp178218.us.lcssa = phi %"class.clang::driver::Arg"** [ undef, %if.end.i.us ], [ undef, %for.cond.i.us ]
+ br label %for.cond.loopexit
+
+for.cond.i.preheader.split: ; preds = %for.cond.i.preheader.for.cond.i.preheader.split_crit_edge
+ br label %for.cond.i
+
+for.cond.i: ; preds = %if.end.i, %for.cond.i.preheader.split
+ br i1 undef, label %for.cond.loopexit.us-lcssa, label %if.end.i
+
+if.end.i: ; preds = %for.cond.i
+ br i1 undef, label %for.cond.loopexit.us-lcssa, label %for.cond.i
+
+for.end: ; preds = %for.cond
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopDeletion/dcetest.ll b/src/LLVM/test/Transforms/LoopDeletion/dcetest.ll
new file mode 100644
index 0000000..0a415a3
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/dcetest.ll
@@ -0,0 +1,36 @@
+; This is the test case taken from Appel's book that illustrates a hard case
+; that SCCP gets right, and when followed by ADCE, is completely eliminated
+;
+; RUN: opt < %s -sccp -simplifycfg -indvars -loop-deletion -dce -simplifycfg -S | not grep br
+
+define i32 @"test function"(i32 %i0, i32 %j0) {
+BB1:
+ br label %BB2
+
+BB2: ; preds = %BB7, %BB1
+ %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ] ; <i32> [#uses=2]
+ %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ] ; <i32> [#uses=4]
+ %kcond = icmp slt i32 %k2, 100 ; <i1> [#uses=1]
+ br i1 %kcond, label %BB3, label %BB4
+
+BB3: ; preds = %BB2
+ %jcond = icmp slt i32 %j2, 20 ; <i1> [#uses=1]
+ br i1 %jcond, label %BB5, label %BB6
+
+BB4: ; preds = %BB2
+ ret i32 %j2
+
+BB5: ; preds = %BB3
+ %k3 = add i32 %k2, 1 ; <i32> [#uses=1]
+ br label %BB7
+
+BB6: ; preds = %BB3
+ %k5 = add i32 %k2, 1 ; <i32> [#uses=1]
+ br label %BB7
+
+BB7: ; preds = %BB6, %BB5
+ %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ] ; <i32> [#uses=1]
+ %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ] ; <i32> [#uses=1]
+ br label %BB2
+}
+
diff --git a/src/LLVM/test/Transforms/LoopDeletion/dg.exp b/src/LLVM/test/Transforms/LoopDeletion/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopDeletion/multiple-exit-conditions.ll b/src/LLVM/test/Transforms/LoopDeletion/multiple-exit-conditions.ll
new file mode 100644
index 0000000..87f8f46
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/multiple-exit-conditions.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -loop-deletion -S | FileCheck %s
+
+; ScalarEvolution can prove the loop iteration is finite, even though
+; it can't represent the exact trip count as an expression. That's
+; good enough to let the loop be deleted.
+
+; CHECK: entry:
+; CHECK-NEXT: br label %return
+
+; CHECK: return:
+; CHECK-NEXT: ret void
+
+define void @foo(i64 %n, i64 %m) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb ]
+ %t0 = add i64 %x.0, 1
+ %t1 = icmp slt i64 %x.0, %n
+ %t3 = icmp sgt i64 %x.0, %m
+ %t4 = and i1 %t1, %t3
+ br i1 %t4, label %bb, label %return
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopDeletion/multiple-exits.ll b/src/LLVM/test/Transforms/LoopDeletion/multiple-exits.ll
new file mode 100644
index 0000000..6af413b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/multiple-exits.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -loop-deletion -S | FileCheck %s
+
+; Checks whether dead loops with multiple exits can be eliminated
+
+; CHECK: entry:
+; CHECK-NEXT: br label %return
+
+; CHECK: return:
+; CHECK-NEXT: ret void
+
+define void @foo(i64 %n, i64 %m) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %x.0 = phi i64 [ 0, %entry ], [ %t0, %bb2 ]
+ %t0 = add i64 %x.0, 1
+ %t1 = icmp slt i64 %x.0, %n
+ br i1 %t1, label %bb2, label %return
+bb2:
+ %t2 = icmp slt i64 %x.0, %m
+ br i1 %t1, label %bb, label %return
+
+return:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopDeletion/simplify-then-delete.ll b/src/LLVM/test/Transforms/LoopDeletion/simplify-then-delete.ll
new file mode 100644
index 0000000..5a21672
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopDeletion/simplify-then-delete.ll
@@ -0,0 +1,65 @@
+; RUN: opt < %s -S -indvars -loop-deletion -simplifycfg | FileCheck %s
+; PR5794
+
+; Indvars and loop deletion should be able to eliminate all looping
+; in this testcase.
+
+; CHECK: define i32 @pmat(i32 %m, i32 %n, double* %y) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i32 0
+; CHECK-NEXT: }
+
+target datalayout = "e-p:64:64:64"
+
+define i32 @pmat(i32 %m, i32 %n, double* %y) nounwind {
+entry:
+ %cmp4 = icmp sgt i32 %m, 0
+ br i1 %cmp4, label %bb.n10, label %w.e12
+
+w.c:
+ %cmp = icmp slt i32 %inc11, %m
+ br i1 %cmp, label %w.c2.p, label %w.c.w.e12c
+
+w.c.w.e12c:
+ br label %w.c.w.e12c.s
+
+w.c.w.e12c.s:
+ br label %w.e12
+
+bb.n10:
+ %cmp51 = icmp sgt i32 %n, 0
+ br i1 %cmp51, label %bb.n10.w.c.w.e12c.sc, label %bb.n10.bb.n10.sc
+
+bb.n10.bb.n10.sc:
+ br label %bb.n10.s
+
+bb.n10.w.c.w.e12c.sc:
+ br label %w.c.w.e12c.s
+
+bb.n10.s:
+ br label %w.c2.p
+
+w.c2.p:
+ %i.05 = phi i32 [ 0, %bb.n10.s ], [ %inc11, %w.c ]
+ br i1 false, label %bb.n, label %w.e
+
+w.c2:
+ br i1 undef, label %w.b6, label %w.c2.w.ec
+
+w.c2.w.ec:
+ br label %w.e
+
+bb.n:
+ br label %w.b6
+
+w.b6:
+ br label %w.c2
+
+w.e:
+ %i.08 = phi i32 [ undef, %w.c2.w.ec ], [ %i.05, %w.c2.p ]
+ %inc11 = add nsw i32 %i.08, 1
+ br label %w.c
+
+w.e12:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LoopIdiom/basic.ll b/src/LLVM/test/Transforms/LoopIdiom/basic.ll
new file mode 100644
index 0000000..46ab7e5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopIdiom/basic.ll
@@ -0,0 +1,386 @@
+; RUN: opt -basicaa -loop-idiom < %s -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define void @test1(i8* %Base, i64 %Size) nounwind ssp {
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ store i8 0, i8* %I.0.014, align 1
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test1
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
+; CHECK-NOT: store
+}
+
+; This is a loop that was rotated but where the blocks weren't merged. This
+; shouldn't perturb us.
+define void @test1a(i8* %Base, i64 %Size) nounwind ssp {
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body.cont ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ store i8 0, i8* %I.0.014, align 1
+ %indvar.next = add i64 %indvar, 1
+ br label %for.body.cont
+for.body.cont:
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test1a
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
+; CHECK-NOT: store
+}
+
+
+define void @test2(i32* %Base, i64 %Size) nounwind ssp {
+entry:
+ %cmp10 = icmp eq i64 %Size, 0
+ br i1 %cmp10, label %for.end, label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
+ %add.ptr.i = getelementptr i32* %Base, i64 %i.011
+ store i32 16843009, i32* %add.ptr.i, align 4
+ %inc = add nsw i64 %i.011, 1
+ %exitcond = icmp eq i64 %inc, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test2
+; CHECK: br i1 %cmp10,
+; CHECK: %0 = mul i64 %Size, 4
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base1, i8 1, i64 %0, i32 4, i1 false)
+; CHECK-NOT: store
+}
+
+; This is a case where there is an extra may-aliased store in the loop, we can't
+; promote the memset.
+define void @test3(i32* %Base, i64 %Size, i8 *%MayAlias) nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.011 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
+ %add.ptr.i = getelementptr i32* %Base, i64 %i.011
+ store i32 16843009, i32* %add.ptr.i, align 4
+
+ store i8 42, i8* %MayAlias
+ %inc = add nsw i64 %i.011, 1
+ %exitcond = icmp eq i64 %inc, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %entry
+ ret void
+; CHECK: @test3
+; CHECK-NOT: memset
+; CHECK: ret void
+}
+
+
+;; TODO: We should be able to promote this memset. Not yet though.
+define void @test4(i8* %Base) nounwind ssp {
+bb.nph: ; preds = %entry
+ %Base100 = getelementptr i8* %Base, i64 1000
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ store i8 0, i8* %I.0.014, align 1
+
+ ;; Store beyond the range memset, should be safe to promote.
+ store i8 42, i8* %Base100
+
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 100
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK-TODO: @test4
+; CHECK-TODO: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 100, i32 1, i1 false)
+; CHECK-TODO-NOT: store
+}
+
+; This can't be promoted: the memset is a store of a loop variant value.
+define void @test5(i8* %Base, i64 %Size) nounwind ssp {
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+
+ %V = trunc i64 %indvar to i8
+ store i8 %V, i8* %I.0.014, align 1
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test5
+; CHECK-NOT: memset
+; CHECK: ret void
+}
+
+
+;; memcpy formation
+define void @test6(i64 %Size) nounwind ssp {
+bb.nph:
+ %Base = alloca i8, i32 10000
+ %Dest = alloca i8, i32 10000
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ %DestI = getelementptr i8* %Dest, i64 %indvar
+ %V = load i8* %I.0.014, align 1
+ store i8 %V, i8* %DestI, align 1
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test6
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dest, i8* %Base, i64 %Size, i32 1, i1 false)
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+
+; This is a loop that was rotated but where the blocks weren't merged. This
+; shouldn't perturb us.
+define void @test7(i8* %Base, i64 %Size) nounwind ssp {
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body.cont ]
+ br label %for.body.cont
+for.body.cont:
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ store i8 0, i8* %I.0.014, align 1
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test7
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %Base, i8 0, i64 %Size, i32 1, i1 false)
+; CHECK-NOT: store
+}
+
+; This is a loop should not be transformed, it only executes one iteration.
+define void @test8(i64* %Ptr, i64 %Size) nounwind ssp {
+bb.nph: ; preds = %entry
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %PI = getelementptr i64* %Ptr, i64 %indvar
+ store i64 0, i64 *%PI
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 1
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test8
+; CHECK: store i64 0, i64* %PI
+}
+
+declare i8* @external(i8*)
+
+;; This cannot be transformed into a memcpy, because the read-from location is
+;; mutated by the loop.
+define void @test9(i64 %Size) nounwind ssp {
+bb.nph:
+ %Base = alloca i8, i32 10000
+ %Dest = alloca i8, i32 10000
+
+ %BaseAlias = call i8* @external(i8* %Base)
+ br label %for.body
+
+for.body: ; preds = %bb.nph, %for.body
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %for.body ]
+ %I.0.014 = getelementptr i8* %Base, i64 %indvar
+ %DestI = getelementptr i8* %Dest, i64 %indvar
+ %V = load i8* %I.0.014, align 1
+ store i8 %V, i8* %DestI, align 1
+
+ ;; This store can clobber the input.
+ store i8 4, i8* %BaseAlias
+
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, %Size
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+; CHECK: @test9
+; CHECK-NOT: llvm.memcpy
+; CHECK: ret void
+}
+
+; Two dimensional nested loop should be promoted to one big memset.
+define void @test10(i8* %X) nounwind ssp {
+entry:
+ br label %bb.nph
+
+bb.nph: ; preds = %entry, %for.inc10
+ %i.04 = phi i32 [ 0, %entry ], [ %inc12, %for.inc10 ]
+ br label %for.body5
+
+for.body5: ; preds = %for.body5, %bb.nph
+ %j.02 = phi i32 [ 0, %bb.nph ], [ %inc, %for.body5 ]
+ %mul = mul nsw i32 %i.04, 100
+ %add = add nsw i32 %j.02, %mul
+ %idxprom = sext i32 %add to i64
+ %arrayidx = getelementptr inbounds i8* %X, i64 %idxprom
+ store i8 0, i8* %arrayidx, align 1
+ %inc = add nsw i32 %j.02, 1
+ %cmp4 = icmp eq i32 %inc, 100
+ br i1 %cmp4, label %for.inc10, label %for.body5
+
+for.inc10: ; preds = %for.body5
+ %inc12 = add nsw i32 %i.04, 1
+ %cmp = icmp eq i32 %inc12, 100
+ br i1 %cmp, label %for.end13, label %bb.nph
+
+for.end13: ; preds = %for.inc10
+ ret void
+; CHECK: @test10
+; CHECK: entry:
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %X, i8 0, i64 10000, i32 1, i1 false)
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+; On darwin10 (which is the triple in this .ll file) this loop can be turned
+; into a memset_pattern call.
+; rdar://9009151
+define void @test11_pattern(i32* nocapture %P) nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
+ %arrayidx = getelementptr i32* %P, i64 %indvar
+ store i32 1, i32* %arrayidx, align 4
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 10000
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret void
+; CHECK: @test11_pattern
+; CHECK-NEXT: entry:
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: memset_pattern
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+; Store of null should turn into memset of zero.
+define void @test12(i32** nocapture %P) nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
+ %arrayidx = getelementptr i32** %P, i64 %indvar
+ store i32* null, i32** %arrayidx, align 4
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 10000
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret void
+; CHECK: @test12
+; CHECK-NEXT: entry:
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* %P1, i8 0, i64 80000, i32 4, i1 false)
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+@G = global i32 5
+
+; This store-of-address loop can be turned into a memset_pattern call.
+; rdar://9009151
+define void @test13_pattern(i32** nocapture %P) nounwind ssp {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
+ %arrayidx = getelementptr i32** %P, i64 %indvar
+ store i32* @G, i32** %arrayidx, align 4
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp eq i64 %indvar.next, 10000
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret void
+; CHECK: @test13_pattern
+; CHECK-NEXT: entry:
+; CHECK-NEXT: bitcast
+; CHECK-NEXT: memset_pattern
+; CHECK-NOT: store
+; CHECK: ret void
+}
+
+
+
+; PR9815 - This is a partial overlap case that cannot be safely transformed
+; into a memcpy.
+@g_50 = global [7 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1, i32 0, i32 0], align 16
+
+define i32 @test14() nounwind {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.inc, %for.body.lr.ph
+ %tmp5 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
+ %add = add nsw i32 %tmp5, 4
+ %idxprom = sext i32 %add to i64
+ %arrayidx = getelementptr inbounds [7 x i32]* @g_50, i32 0, i64 %idxprom
+ %tmp2 = load i32* %arrayidx, align 4
+ %add4 = add nsw i32 %tmp5, 5
+ %idxprom5 = sext i32 %add4 to i64
+ %arrayidx6 = getelementptr inbounds [7 x i32]* @g_50, i32 0, i64 %idxprom5
+ store i32 %tmp2, i32* %arrayidx6, align 4
+ %inc = add nsw i32 %tmp5, 1
+ %cmp = icmp slt i32 %inc, 2
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.inc
+ %tmp8 = load i32* getelementptr inbounds ([7 x i32]* @g_50, i32 0, i64 6), align 4
+ ret i32 %tmp8
+; CHECK: @test14
+; CHECK: for.body:
+; CHECK: load i32
+; CHECK: store i32
+; CHECK: br i1 %cmp
+
+}
+
+
diff --git a/src/LLVM/test/Transforms/LoopIdiom/debug-line.ll b/src/LLVM/test/Transforms/LoopIdiom/debug-line.ll
new file mode 100644
index 0000000..d31662d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopIdiom/debug-line.ll
@@ -0,0 +1,49 @@
+; RUN: opt -loop-idiom < %s -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+
+define void @foo(double* nocapture %a) nounwind ssp {
+entry:
+ tail call void @llvm.dbg.value(metadata !{double* %a}, i64 0, metadata !5), !dbg !8
+ tail call void @llvm.dbg.value(metadata !9, i64 0, metadata !10), !dbg !14
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ]
+ %arrayidx = getelementptr double* %a, i64 %indvar
+; CHECK: call void @llvm.memset{{.+}} !dbg
+ store double 0.000000e+00, double* %arrayidx, align 8, !dbg !15
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp ne i64 %indvar.next, 1000
+ br i1 %exitcond, label %for.body, label %for.end, !dbg !14
+
+for.end: ; preds = %for.body
+ tail call void @llvm.dbg.value(metadata !{null}, i64 0, metadata !10), !dbg !16
+ ret void, !dbg !17
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 2, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, void (double*)* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"li.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"li.c", metadata !"/private/tmp", metadata !"clang version 2.9 (trunk 127165:127174)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 590081, metadata !0, metadata !"a", metadata !1, i32 16777218, metadata !6, i32 0} ; [ DW_TAG_arg_variable ]
+!6 = metadata !{i32 589839, metadata !2, metadata !"", null, i32 0, i64 64, i64 64, i64 0, i32 0, metadata !7} ; [ DW_TAG_pointer_type ]
+!7 = metadata !{i32 589860, metadata !2, metadata !"double", null, i32 0, i64 64, i64 64, i64 0, i32 0, i32 4} ; [ DW_TAG_base_type ]
+!8 = metadata !{i32 2, i32 18, metadata !0, null}
+!9 = metadata !{i32 0}
+!10 = metadata !{i32 590080, metadata !11, metadata !"i", metadata !1, i32 3, metadata !13, i32 0} ; [ DW_TAG_auto_variable ]
+!11 = metadata !{i32 589835, metadata !12, i32 3, i32 3, metadata !1, i32 1} ; [ DW_TAG_lexical_block ]
+!12 = metadata !{i32 589835, metadata !0, i32 2, i32 21, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
+!13 = metadata !{i32 589860, metadata !2, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!14 = metadata !{i32 3, i32 3, metadata !12, null}
+!15 = metadata !{i32 4, i32 5, metadata !11, null}
+!16 = metadata !{i32 3, i32 29, metadata !11, null}
+!17 = metadata !{i32 5, i32 1, metadata !12, null}
diff --git a/src/LLVM/test/Transforms/LoopIdiom/dg.exp b/src/LLVM/test/Transforms/LoopIdiom/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopIdiom/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopIdiom/memset_noidiom.ll b/src/LLVM/test/Transforms/LoopIdiom/memset_noidiom.ll
new file mode 100644
index 0000000..168eb95
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopIdiom/memset_noidiom.ll
@@ -0,0 +1,30 @@
+; RUN: opt -loop-idiom < %s -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; CHECK: @memset
+; CHECK-NOT: llvm.memset
+define i8* @memset(i8* %b, i32 %c, i64 %len) nounwind uwtable ssp {
+entry:
+ %cmp1 = icmp ult i64 0, %len
+ br i1 %cmp1, label %for.body.lr.ph, label %for.end
+
+for.body.lr.ph: ; preds = %entry
+ %conv6 = trunc i32 %c to i8
+ br label %for.body
+
+for.body: ; preds = %for.body.lr.ph, %for.body
+ %indvar = phi i64 [ 0, %for.body.lr.ph ], [ %indvar.next, %for.body ]
+ %p.02 = getelementptr i8* %b, i64 %indvar
+ store i8 %conv6, i8* %p.02, align 1
+ %indvar.next = add i64 %indvar, 1
+ %exitcond = icmp ne i64 %indvar.next, %len
+ br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge
+
+for.cond.for.end_crit_edge: ; preds = %for.body
+ br label %for.end
+
+for.end: ; preds = %for.cond.for.end_crit_edge, %entry
+ ret i8* %b
+}
+
diff --git a/src/LLVM/test/Transforms/LoopRotate/2009-01-25-SingleEntryPhi.ll b/src/LLVM/test/Transforms/LoopRotate/2009-01-25-SingleEntryPhi.ll
new file mode 100644
index 0000000..7036d2d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/2009-01-25-SingleEntryPhi.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -loop-rotate -verify-dom-info -verify-loop-info -disable-output
+; PR3408
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+ %struct.Cls = type { i32, i8, [2 x %struct.Cls*], [2 x %struct.Lit*] }
+ %struct.Lit = type { i8 }
+
+define void @picosat_main_bb13.i.i71.outer_bb132.i.i.i.outer(%struct.Cls**, %struct.Cls**, i32 %collect.i.i.i.1.lcssa, i32 %lcollect.i.i.i.2.lcssa, %struct.Cls*** %rhead.tmp.0236.out, i32* %collect.i.i.i.2.out, i32* %lcollect.i.i.i.3.ph.ph.ph.out) nounwind {
+newFuncRoot:
+ br label %codeRepl
+
+bb133.i.i.i.exitStub: ; preds = %codeRepl
+ ret void
+
+bb130.i.i.i: ; preds = %codeRepl
+ %rhead.tmp.0236.lcssa82 = phi %struct.Cls** [ null, %codeRepl ] ; <%struct.Cls**> [#uses=0]
+ br label %codeRepl
+
+codeRepl: ; preds = %bb130.i.i.i, %newFuncRoot
+ br i1 false, label %bb130.i.i.i, label %bb133.i.i.i.exitStub
+}
diff --git a/src/LLVM/test/Transforms/LoopRotate/PhiRename-1.ll b/src/LLVM/test/Transforms/LoopRotate/PhiRename-1.ll
new file mode 100644
index 0000000..202e43a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/PhiRename-1.ll
@@ -0,0 +1,94 @@
+; RUN: opt < %s -loop-rotate -verify-dom-info -verify-loop-info -S | not grep {\\\[ .tmp224}
+; END.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+
+ %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
+ %struct.Index_Map = type { i32, %struct.item_set** }
+ %struct.Item = type { [4 x i16], %struct.rule* }
+ %struct.__sFILEX = type opaque
+ %struct.__sbuf = type { i8*, i32 }
+ %struct.dimension = type { i16*, %struct.Index_Map, %struct.mapping*, i32, %struct.plankMap* }
+ %struct.item_set = type { i32, i32, %struct.operator*, [2 x %struct.item_set*], %struct.item_set*, i16*, %struct.Item*, %struct.Item* }
+ %struct.list = type { i8*, %struct.list* }
+ %struct.mapping = type { %struct.list**, i32, i32, i32, %struct.item_set** }
+ %struct.nonterminal = type { i8*, i32, i32, i32, %struct.plankMap*, %struct.rule* }
+ %struct.operator = type { i8*, i8, i32, i32, i32, i32, %struct.table* }
+ %struct.pattern = type { %struct.nonterminal*, %struct.operator*, [2 x %struct.nonterminal*] }
+ %struct.plank = type { i8*, %struct.list*, i32 }
+ %struct.plankMap = type { %struct.list*, i32, %struct.stateMap* }
+ %struct.rule = type { [4 x i16], i32, i32, i32, %struct.nonterminal*, %struct.pattern*, i8 }
+ %struct.stateMap = type { i8*, %struct.plank*, i32, i16* }
+ %struct.table = type { %struct.operator*, %struct.list*, i16*, [2 x %struct.dimension*], %struct.item_set** }
+@outfile = external global %struct.FILE* ; <%struct.FILE**> [#uses=1]
+@str1 = external constant [11 x i8] ; <[11 x i8]*> [#uses=1]
+@operators = weak global %struct.list* null ; <%struct.list**> [#uses=1]
+
+
+
+define i32 @opsOfArity(i32 %arity) {
+entry:
+ %arity_addr = alloca i32 ; <i32*> [#uses=2]
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=2]
+ %c = alloca i32, align 4 ; <i32*> [#uses=4]
+ %l = alloca %struct.list*, align 4 ; <%struct.list**> [#uses=5]
+ %op = alloca %struct.operator*, align 4 ; <%struct.operator**> [#uses=3]
+ store i32 %arity, i32* %arity_addr
+ store i32 0, i32* %c
+ %tmp1 = load %struct.list** @operators ; <%struct.list*> [#uses=1]
+ store %struct.list* %tmp1, %struct.list** %l
+ br label %bb21
+
+bb: ; preds = %bb21
+ %tmp3 = getelementptr %struct.list* %tmp22, i32 0, i32 0 ; <i8**> [#uses=1]
+ %tmp4 = load i8** %tmp3 ; <i8*> [#uses=1]
+ %tmp45 = bitcast i8* %tmp4 to %struct.operator* ; <%struct.operator*> [#uses=1]
+ store %struct.operator* %tmp45, %struct.operator** %op
+ %tmp6 = load %struct.operator** %op ; <%struct.operator*> [#uses=1]
+ %tmp7 = getelementptr %struct.operator* %tmp6, i32 0, i32 5 ; <i32*> [#uses=1]
+ %tmp8 = load i32* %tmp7 ; <i32> [#uses=1]
+ %tmp9 = load i32* %arity_addr ; <i32> [#uses=1]
+ icmp eq i32 %tmp8, %tmp9 ; <i1>:0 [#uses=1]
+ zext i1 %0 to i8 ; <i8>:1 [#uses=1]
+ icmp ne i8 %1, 0 ; <i1>:2 [#uses=1]
+ br i1 %2, label %cond_true, label %cond_next
+
+cond_true: ; preds = %bb
+ %tmp10 = load %struct.operator** %op ; <%struct.operator*> [#uses=1]
+ %tmp11 = getelementptr %struct.operator* %tmp10, i32 0, i32 2 ; <i32*> [#uses=1]
+ %tmp12 = load i32* %tmp11 ; <i32> [#uses=1]
+ %tmp13 = load %struct.FILE** @outfile ; <%struct.FILE*> [#uses=1]
+ %tmp14 = getelementptr [11 x i8]* @str1, i32 0, i32 0 ; <i8*> [#uses=1]
+ %tmp15 = call i32 (%struct.FILE*, i8*, ...)* @fprintf( %struct.FILE* %tmp13, i8* %tmp14, i32 %tmp12 ) ; <i32> [#uses=0]
+ %tmp16 = load i32* %c ; <i32> [#uses=1]
+ %tmp17 = add i32 %tmp16, 1 ; <i32> [#uses=1]
+ store i32 %tmp17, i32* %c
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %bb
+ %tmp19 = getelementptr %struct.list* %tmp22, i32 0, i32 1 ; <%struct.list**> [#uses=1]
+ %tmp20 = load %struct.list** %tmp19 ; <%struct.list*> [#uses=1]
+ store %struct.list* %tmp20, %struct.list** %l
+ br label %bb21
+
+bb21: ; preds = %cond_next, %entry
+ %l.in = phi %struct.list** [ @operators, %entry ], [ %tmp19, %cond_next ]
+ %tmp22 = load %struct.list** %l.in ; <%struct.list*> [#uses=1]
+ icmp ne %struct.list* %tmp22, null ; <i1>:3 [#uses=1]
+ zext i1 %3 to i8 ; <i8>:4 [#uses=1]
+ icmp ne i8 %4, 0 ; <i1>:5 [#uses=1]
+ br i1 %5, label %bb, label %bb23
+
+bb23: ; preds = %bb21
+ %tmp24 = load i32* %c ; <i32> [#uses=1]
+ store i32 %tmp24, i32* %tmp
+ %tmp25 = load i32* %tmp ; <i32> [#uses=1]
+ store i32 %tmp25, i32* %retval
+ br label %return
+
+return: ; preds = %bb23
+ %retval26 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval26
+}
+
+declare i32 @fprintf(%struct.FILE*, i8*, ...)
diff --git a/src/LLVM/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll b/src/LLVM/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll
new file mode 100644
index 0000000..09372ed
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/PhiSelfRefernce-1.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -loop-rotate -verify-dom-info -verify-loop-info -disable-output
+; ModuleID = 'PhiSelfRefernce-1.bc'
+
+define void @snrm2(i32 %incx) {
+entry:
+ br i1 false, label %START, label %return
+
+START: ; preds = %entry
+ br i1 false, label %bb85, label %cond_false93
+
+bb52: ; preds = %bb85
+ br i1 false, label %bb307, label %cond_next71
+
+cond_next71: ; preds = %bb52
+ ret void
+
+bb85: ; preds = %START
+ br i1 false, label %bb52, label %bb88
+
+bb88: ; preds = %bb85
+ ret void
+
+cond_false93: ; preds = %START
+ ret void
+
+bb243: ; preds = %bb307
+ br label %bb307
+
+bb307: ; preds = %bb243, %bb52
+ %sx_addr.2.pn = phi float* [ %sx_addr.5, %bb243 ], [ null, %bb52 ] ; <float*> [#uses=1]
+ %sx_addr.5 = getelementptr float* %sx_addr.2.pn, i32 %incx ; <float*> [#uses=1]
+ br i1 false, label %bb243, label %bb310
+
+bb310: ; preds = %bb307
+ ret void
+
+return: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopRotate/basic.ll b/src/LLVM/test/Transforms/LoopRotate/basic.ll
new file mode 100644
index 0000000..b7bcb21
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/basic.ll
@@ -0,0 +1,35 @@
+; RUN: opt -S -loop-rotate %s | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; PR5319 - The "arrayidx" gep should be hoisted, not duplicated. We should
+; end up with one phi node.
+define void @test1() nounwind ssp {
+; CHECK: @test1
+entry:
+ %array = alloca [20 x i32], align 16
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %cmp = icmp slt i32 %i.0, 100
+ %arrayidx = getelementptr inbounds [20 x i32]* %array, i64 0, i64 0
+ br i1 %cmp, label %for.body, label %for.end
+
+; CHECK: for.body:
+; CHECK-NEXT: phi i32 [ 0
+; CHECK-NEXT: store i32 0
+
+for.body: ; preds = %for.cond
+ store i32 0, i32* %arrayidx, align 16
+ %inc = add nsw i32 %i.0, 1
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ %arrayidx.lcssa = phi i32* [ %arrayidx, %for.cond ]
+ call void @g(i32* %arrayidx.lcssa) nounwind
+ ret void
+}
+
+declare void @g(i32*)
+
diff --git a/src/LLVM/test/Transforms/LoopRotate/crash.ll b/src/LLVM/test/Transforms/LoopRotate/crash.ll
new file mode 100644
index 0000000..954b834
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/crash.ll
@@ -0,0 +1,155 @@
+; RUN: opt -loop-rotate %s -disable-output -verify-dom-info -verify-loop-info
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; PR8955 - Rotating an outer loop that has a condbr for a latch block.
+define void @test1() nounwind ssp {
+entry:
+ br label %lbl_283
+
+lbl_283: ; preds = %if.end, %entry
+ br i1 undef, label %if.else, label %if.then
+
+if.then: ; preds = %lbl_283
+ br i1 undef, label %if.end, label %for.condthread-pre-split
+
+for.condthread-pre-split: ; preds = %if.then
+ br label %for.cond
+
+for.cond: ; preds = %for.cond, %for.condthread-pre-split
+ br i1 undef, label %lbl_281, label %for.cond
+
+lbl_281: ; preds = %if.end, %for.cond
+ br label %if.end
+
+if.end: ; preds = %lbl_281, %if.then
+ br i1 undef, label %lbl_283, label %lbl_281
+
+if.else: ; preds = %lbl_283
+ ret void
+}
+
+ %struct.relation = type { [4 x i16], i32, [4 x i16], i32, i32 }
+
+define void @test2() {
+entry:
+ br i1 false, label %bb139, label %bb10.i44
+bb10.i44: ; preds = %entry
+ ret void
+bb127: ; preds = %bb139
+ br label %bb139
+bb139: ; preds = %bb127, %entry
+ br i1 false, label %bb127, label %bb142
+bb142: ; preds = %bb139
+ %r91.0.lcssa = phi %struct.relation* [ null, %bb139 ] ; <%struct.relation*> [#uses=0]
+ ret void
+}
+
+
+define void @test3() {
+entry:
+ br i1 false, label %bb139, label %cond_true
+cond_true: ; preds = %entry
+ ret void
+bb90: ; preds = %bb139
+ br i1 false, label %bb136, label %cond_next121
+cond_next121: ; preds = %bb90
+ br i1 false, label %bb136, label %bb127
+bb127: ; preds = %cond_next121
+ br label %bb136
+bb136: ; preds = %bb127, %cond_next121, %bb90
+ %changes.1 = phi i32 [ %changes.2, %bb90 ], [ %changes.2, %cond_next121 ], [ 1, %bb127 ] ; <i32> [#uses=1]
+ br label %bb139
+bb139: ; preds = %bb136, %entry
+ %changes.2 = phi i32 [ %changes.1, %bb136 ], [ 0, %entry ] ; <i32> [#uses=3]
+ br i1 false, label %bb90, label %bb142
+bb142: ; preds = %bb139
+ %changes.2.lcssa = phi i32 [ %changes.2, %bb139 ] ; <i32> [#uses=0]
+ ret void
+}
+
+define void @test4() {
+entry:
+ br i1 false, label %cond_false485, label %bb405
+bb405: ; preds = %entry
+ ret void
+cond_false485: ; preds = %entry
+ br label %bb830
+bb511: ; preds = %bb830
+ br i1 false, label %bb816, label %bb830
+cond_next667: ; preds = %bb816
+ br i1 false, label %cond_next695, label %bb680
+bb676: ; preds = %bb680
+ br label %bb680
+bb680: ; preds = %bb676, %cond_next667
+ %iftmp.68.0 = zext i1 false to i8 ; <i8> [#uses=1]
+ br i1 false, label %bb676, label %cond_next695
+cond_next695: ; preds = %bb680, %cond_next667
+ %iftmp.68.2 = phi i8 [ %iftmp.68.0, %bb680 ], [ undef, %cond_next667 ] ; <i8> [#uses=0]
+ ret void
+bb816: ; preds = %bb816, %bb511
+ br i1 false, label %cond_next667, label %bb816
+bb830: ; preds = %bb511, %cond_false485
+ br i1 false, label %bb511, label %bb835
+bb835: ; preds = %bb830
+ ret void
+}
+
+ %struct.NSArray = type { %struct.NSObject }
+ %struct.NSObject = type { %struct.objc_class* }
+ %struct.NSRange = type { i64, i64 }
+ %struct._message_ref_t = type { %struct.NSObject* (%struct.NSObject*, %struct._message_ref_t*, ...)*, %struct.objc_selector* }
+ %struct.objc_class = type opaque
+ %struct.objc_selector = type opaque
+@"\01L_OBJC_MESSAGE_REF_26" = external global %struct._message_ref_t ; <%struct._message_ref_t*> [#uses=1]
+
+define %struct.NSArray* @test5(%struct.NSArray* %self, %struct._message_ref_t* %_cmd) {
+entry:
+ br label %bb116
+
+bb116: ; preds = %bb131, %entry
+ %tmp123 = call %struct.NSRange null( %struct.NSObject* null, %struct._message_ref_t* @"\01L_OBJC_MESSAGE_REF_26", %struct.NSArray* null ) ; <%struct.NSRange> [#uses=1]
+ br i1 false, label %bb141, label %bb131
+
+bb131: ; preds = %bb116
+ %mrv_gr125 = extractvalue %struct.NSRange %tmp123, 1 ; <i64> [#uses=0]
+ br label %bb116
+
+bb141: ; preds = %bb116
+ ret %struct.NSArray* null
+}
+
+define void @test6(i8* %msg) {
+entry:
+ br label %bb15
+bb6: ; preds = %bb15
+ %gep.upgrd.1 = zext i32 %offset.1 to i64 ; <i64> [#uses=1]
+ %tmp11 = getelementptr i8* %msg, i64 %gep.upgrd.1 ; <i8*> [#uses=0]
+ br label %bb15
+bb15: ; preds = %bb6, %entry
+ %offset.1 = add i32 0, 1 ; <i32> [#uses=2]
+ br i1 false, label %bb6, label %bb17
+bb17: ; preds = %bb15
+ %offset.1.lcssa = phi i32 [ %offset.1, %bb15 ] ; <i32> [#uses=0]
+ %payload_type.1.lcssa = phi i32 [ 0, %bb15 ] ; <i32> [#uses=0]
+ ret void
+}
+
+
+
+
+; PR9523 - Non-canonical loop.
+define void @test7(i8* %P) nounwind {
+entry:
+ indirectbr i8* %P, [label %"3", label %"5"]
+
+"3": ; preds = %"4", %entry
+ br i1 undef, label %"5", label %"4"
+
+"4": ; preds = %"3"
+ br label %"3"
+
+"5": ; preds = %"3", %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopRotate/dbgvalue.ll b/src/LLVM/test/Transforms/LoopRotate/dbgvalue.ll
new file mode 100644
index 0000000..9287178
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/dbgvalue.ll
@@ -0,0 +1,59 @@
+; RUN: opt -S -loop-rotate %s | FileCheck %s
+
+; CHECK: entry
+; CHECK-NEXT: call void @llvm.dbg.value(metadata !{i32 %x}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+define i32 @tak(i32 %x, i32 %y, i32 %z) nounwind ssp {
+entry:
+ br label %tailrecurse
+
+tailrecurse: ; preds = %if.then, %entry
+ %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]
+ %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]
+ %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]
+ tail call void @llvm.dbg.value(metadata !{i32 %x.tr}, i64 0, metadata !6), !dbg !7
+ tail call void @llvm.dbg.value(metadata !{i32 %y.tr}, i64 0, metadata !8), !dbg !9
+ tail call void @llvm.dbg.value(metadata !{i32 %z.tr}, i64 0, metadata !10), !dbg !11
+ %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !12
+ br i1 %cmp, label %if.then, label %if.end, !dbg !12
+
+if.then: ; preds = %tailrecurse
+ %sub = sub nsw i32 %x.tr, 1, !dbg !14
+ %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !14
+ %sub6 = sub nsw i32 %y.tr, 1, !dbg !14
+ %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !14
+ %sub11 = sub nsw i32 %z.tr, 1, !dbg !14
+ %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !14
+ br label %tailrecurse
+
+if.end: ; preds = %tailrecurse
+ br label %return, !dbg !16
+
+return: ; preds = %if.end
+ ret i32 %z.tr, !dbg !17
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"tak", metadata !"tak", metadata !"", metadata !1, i32 32, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, i32 (i32, i32, i32)* @tak} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", metadata !"/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", metadata !"/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame", metadata !"clang version 2.9 (trunk 125492)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{metadata !5}
+!5 = metadata !{i32 589860, metadata !2, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!6 = metadata !{i32 590081, metadata !0, metadata !"x", metadata !1, i32 32, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!7 = metadata !{i32 32, i32 13, metadata !0, null}
+!8 = metadata !{i32 590081, metadata !0, metadata !"y", metadata !1, i32 32, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!9 = metadata !{i32 32, i32 20, metadata !0, null}
+!10 = metadata !{i32 590081, metadata !0, metadata !"z", metadata !1, i32 32, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!11 = metadata !{i32 32, i32 27, metadata !0, null}
+!12 = metadata !{i32 33, i32 3, metadata !13, null}
+!13 = metadata !{i32 589835, metadata !0, i32 32, i32 30, metadata !1, i32 6} ; [ DW_TAG_lexical_block ]
+!14 = metadata !{i32 34, i32 5, metadata !15, null}
+!15 = metadata !{i32 589835, metadata !13, i32 33, i32 14, metadata !1, i32 7} ; [ DW_TAG_lexical_block ]
+!16 = metadata !{i32 36, i32 3, metadata !13, null}
+!17 = metadata !{i32 37, i32 1, metadata !13, null}
diff --git a/src/LLVM/test/Transforms/LoopRotate/dg.exp b/src/LLVM/test/Transforms/LoopRotate/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopRotate/indirectbr.ll b/src/LLVM/test/Transforms/LoopRotate/indirectbr.ll
new file mode 100644
index 0000000..9c82aa8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/indirectbr.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -S -loop-rotate -disable-output -verify-loop-info -verify-dom-info
+; PR5502
+
+define void @z80_do_opcodes() nounwind {
+entry:
+ br label %while.cond
+
+while.cond: ; preds = %end_opcode, %entry
+ br label %while.body
+
+while.body: ; preds = %while.cond
+ br label %indirectgoto
+
+run_opcode: ; preds = %indirectgoto
+ %tmp276 = load i8* undef ; <i8> [#uses=1]
+ br label %indirectgoto
+
+if.else295: ; preds = %divide_late
+ br label %end_opcode
+
+end_opcode: ; preds = %indirectgoto, %sw.default42406, %sw.default, %if.else295
+ %opcode.2 = phi i8 [ %opcode.0, %indirectgoto ], [ 0, %sw.default42406 ], [ undef, %sw.default ], [ %opcode.0, %if.else295 ] ; <i8> [#uses=0]
+ switch i32 undef, label %while.cond [
+ i32 221, label %sw.bb11691
+ i32 253, label %sw.bb30351
+ ]
+
+sw.bb11691: ; preds = %end_opcode
+ br label %sw.default
+
+sw.default: ; preds = %sw.bb11691
+ br label %end_opcode
+
+sw.bb30351: ; preds = %end_opcode
+ br label %sw.default42406
+
+sw.default42406: ; preds = %sw.bb30351
+ br label %end_opcode
+
+indirectgoto: ; preds = %run_opcode, %while.body
+ %opcode.0 = phi i8 [ undef, %while.body ], [ %tmp276, %run_opcode ] ; <i8> [#uses=2]
+ indirectbr i8* undef, [label %run_opcode, label %if.else295, label %end_opcode]
+}
diff --git a/src/LLVM/test/Transforms/LoopRotate/phi-duplicate.ll b/src/LLVM/test/Transforms/LoopRotate/phi-duplicate.ll
new file mode 100644
index 0000000..7372830
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/phi-duplicate.ll
@@ -0,0 +1,40 @@
+; RUN: opt -S %s -loop-rotate | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0"
+
+; PR5837
+define void @test(i32 %N, double* %G) nounwind ssp {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ %j.0 = phi i64 [ 1, %entry ], [ %inc, %for.body ] ; <i64> [#uses=5]
+ %cmp = icmp slt i64 %j.0, 1000 ; <i1> [#uses=1]
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %arrayidx = getelementptr inbounds double* %G, i64 %j.0 ; <double*> [#uses=1]
+ %tmp3 = load double* %arrayidx ; <double> [#uses=1]
+ %sub = sub i64 %j.0, 1 ; <i64> [#uses=1]
+ %arrayidx6 = getelementptr inbounds double* %G, i64 %sub ; <double*> [#uses=1]
+ %tmp7 = load double* %arrayidx6 ; <double> [#uses=1]
+ %add = fadd double %tmp3, %tmp7 ; <double> [#uses=1]
+ %arrayidx10 = getelementptr inbounds double* %G, i64 %j.0 ; <double*> [#uses=1]
+ store double %add, double* %arrayidx10
+ %inc = add nsw i64 %j.0, 1 ; <i64> [#uses=1]
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
+
+; Should only end up with one phi.
+; CHECK: define void @test
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %for.body
+; CHECK: for.body:
+; CHECK-NEXT: %j.01 = phi i64
+; CHECK-NOT: br
+; CHECK: br i1 %cmp, label %for.body, label %for.end
+; CHECK: for.end:
+; CHECK-NEXT: ret void
diff --git a/src/LLVM/test/Transforms/LoopRotate/pr2639.ll b/src/LLVM/test/Transforms/LoopRotate/pr2639.ll
new file mode 100644
index 0000000..da9a3a2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/pr2639.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -loop-deletion -loop-rotate -verify-dom-info -verify-loop-info -disable-output
+; PR 2639
+
+ %struct.HexxagonMove = type { i8, i8, i32 }
+
+define void @_ZN16HexxagonMoveList7addMoveER12HexxagonMove() {
+entry:
+ br i1 false, label %bb9.preheader, label %bb11
+
+bb9.preheader: ; preds = %entry
+ br label %bb9
+
+bb1: ; preds = %bb9
+ br i1 false, label %bb3, label %bb8
+
+bb3: ; preds = %bb1
+ br label %bb5
+
+bb4: ; preds = %bb5
+ br label %bb5
+
+bb5: ; preds = %bb4, %bb3
+ %exitcond = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb7, label %bb4
+
+bb7: ; preds = %bb5
+ store %struct.HexxagonMove* null, %struct.HexxagonMove** null, align 4
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb1
+ br label %bb9
+
+bb9: ; preds = %bb8, %bb9.preheader
+ br i1 false, label %bb11, label %bb1
+
+bb11: ; preds = %bb9, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopRotate/preserve-scev.ll b/src/LLVM/test/Transforms/LoopRotate/preserve-scev.ll
new file mode 100644
index 0000000..7bd2232
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopRotate/preserve-scev.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -loop-rotate -loop-reduce -verify-dom-info -verify-loop-info -disable-output
+
+define fastcc void @foo() nounwind {
+BB:
+ br label %BB1
+
+BB1: ; preds = %BB19, %BB
+ br label %BB4
+
+BB2: ; preds = %BB4
+ %tmp = bitcast i32 undef to i32 ; <i32> [#uses=1]
+ br label %BB4
+
+BB4: ; preds = %BB3, %BB1
+ %tmp5 = phi i32 [ undef, %BB1 ], [ %tmp, %BB2 ] ; <i32> [#uses=1]
+ br i1 false, label %BB8, label %BB2
+
+BB8: ; preds = %BB6
+ %tmp7 = bitcast i32 %tmp5 to i32 ; <i32> [#uses=2]
+ br i1 false, label %BB9, label %BB13
+
+BB9: ; preds = %BB12, %BB8
+ %tmp10 = phi i32 [ %tmp11, %BB12 ], [ %tmp7, %BB8 ] ; <i32> [#uses=2]
+ %tmp11 = add i32 %tmp10, 1 ; <i32> [#uses=1]
+ br label %BB12
+
+BB12: ; preds = %BB9
+ br i1 false, label %BB9, label %BB17
+
+BB13: ; preds = %BB15, %BB8
+ %tmp14 = phi i32 [ %tmp16, %BB15 ], [ %tmp7, %BB8 ] ; <i32> [#uses=1]
+ br label %BB15
+
+BB15: ; preds = %BB13
+ %tmp16 = add i32 %tmp14, -1 ; <i32> [#uses=1]
+ br i1 false, label %BB13, label %BB18
+
+BB17: ; preds = %BB12
+ br label %BB19
+
+BB18: ; preds = %BB15
+ br label %BB19
+
+BB19: ; preds = %BB18, %BB17
+ %tmp20 = phi i32 [ %tmp10, %BB17 ], [ undef, %BB18 ] ; <i32> [#uses=0]
+ br label %BB1
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2003-04-25-AssertFail.ll b/src/LLVM/test/Transforms/LoopSimplify/2003-04-25-AssertFail.ll
new file mode 100644
index 0000000..d33d0ac
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2003-04-25-AssertFail.ll
@@ -0,0 +1,20 @@
+; This testcase exposed a problem with the loop identification pass (LoopInfo).
+; Basically, it was incorrectly calculating the loop nesting information.
+;
+; RUN: opt < %s -loop-simplify
+
+define i32 @yylex() {
+ br label %loopentry.0
+loopentry.0: ; preds = %else.4, %0
+ br label %loopexit.2
+loopexit.2: ; preds = %else.4, %loopexit.2, %loopentry.0
+ br i1 false, label %loopexit.2, label %else.4
+yy_find_action: ; preds = %else.4
+ br label %else.4
+else.4: ; preds = %yy_find_action, %loopexit.2
+ switch i32 0, label %loopexit.2 [
+ i32 2, label %yy_find_action
+ i32 0, label %loopentry.0
+ ]
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll b/src/LLVM/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll
new file mode 100644
index 0000000..ecd33fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2003-05-12-PreheaderExitOfChild.ll
@@ -0,0 +1,42 @@
+; This (complex) testcase causes an assertion failure because a preheader is
+; inserted for the "fail" loop, but the exit block of a loop is not updated
+; to be the preheader instead of the exit loop itself.
+
+; RUN: opt < %s -loop-simplify
+define i32 @re_match_2() {
+ br label %loopentry.1
+loopentry.1: ; preds = %endif.82, %0
+ br label %shortcirc_done.36
+shortcirc_done.36: ; preds = %loopentry.1
+ br i1 false, label %fail, label %endif.40
+endif.40: ; preds = %shortcirc_done.36
+ br label %loopexit.20
+loopentry.20: ; preds = %endif.46
+ br label %loopexit.20
+loopexit.20: ; preds = %loopentry.20, %endif.40
+ br label %loopentry.21
+loopentry.21: ; preds = %no_exit.19, %loopexit.20
+ br i1 false, label %no_exit.19, label %loopexit.21
+no_exit.19: ; preds = %loopentry.21
+ br i1 false, label %fail, label %loopentry.21
+loopexit.21: ; preds = %loopentry.21
+ br label %endif.45
+endif.45: ; preds = %loopexit.21
+ br label %cond_true.15
+cond_true.15: ; preds = %endif.45
+ br i1 false, label %fail, label %endif.46
+endif.46: ; preds = %cond_true.15
+ br label %loopentry.20
+fail: ; preds = %loopexit.37, %cond_true.15, %no_exit.19, %shortcirc_done.36
+ br label %then.80
+then.80: ; preds = %fail
+ br label %endif.81
+endif.81: ; preds = %then.80
+ br label %loopexit.37
+loopexit.37: ; preds = %endif.81
+ br i1 false, label %fail, label %endif.82
+endif.82: ; preds = %loopexit.37
+ br label %loopentry.1
+}
+
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll b/src/LLVM/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll
new file mode 100644
index 0000000..b338e96
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2003-08-15-PreheadersFail.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -instcombine -simplifycfg -licm -disable-output
+target datalayout = "e-p:32:32"
+@yy_base = external global [787 x i16] ; <[787 x i16]*> [#uses=1]
+@yy_state_ptr = external global i32* ; <i32**> [#uses=3]
+@yy_state_buf = external global [16386 x i32] ; <[16386 x i32]*> [#uses=1]
+@yy_lp = external global i32 ; <i32*> [#uses=1]
+
+define i32 @_yylex() {
+ br label %loopentry.0
+loopentry.0: ; preds = %else.26, %0
+ store i32* getelementptr ([16386 x i32]* @yy_state_buf, i64 0, i64 0), i32** @yy_state_ptr
+ %tmp.35 = load i32** @yy_state_ptr ; <i32*> [#uses=2]
+ %inc.0 = getelementptr i32* %tmp.35, i64 1 ; <i32*> [#uses=1]
+ store i32* %inc.0, i32** @yy_state_ptr
+ %tmp.36 = load i32* null ; <i32> [#uses=1]
+ store i32 %tmp.36, i32* %tmp.35
+ br label %loopexit.2
+loopexit.2: ; preds = %else.26, %loopexit.2, %loopentry.0
+ store i8* null, i8** null
+ %tmp.91 = load i32* null ; <i32> [#uses=1]
+ %tmp.92 = sext i32 %tmp.91 to i64 ; <i64> [#uses=1]
+ %tmp.93 = getelementptr [787 x i16]* @yy_base, i64 0, i64 %tmp.92 ; <i16*> [#uses=1]
+ %tmp.94 = load i16* %tmp.93 ; <i16> [#uses=1]
+ %tmp.95 = icmp ne i16 %tmp.94, 4394 ; <i1> [#uses=1]
+ br i1 %tmp.95, label %loopexit.2, label %yy_find_action
+yy_find_action: ; preds = %else.26, %loopexit.2
+ br label %loopentry.3
+loopentry.3: ; preds = %then.9, %shortcirc_done.0, %yy_find_action
+ %tmp.105 = load i32* @yy_lp ; <i32> [#uses=1]
+ %tmp.106 = icmp ne i32 %tmp.105, 0 ; <i1> [#uses=1]
+ br i1 %tmp.106, label %shortcirc_next.0, label %shortcirc_done.0
+shortcirc_next.0: ; preds = %loopentry.3
+ %tmp.114 = load i16* null ; <i16> [#uses=1]
+ %tmp.115 = sext i16 %tmp.114 to i32 ; <i32> [#uses=1]
+ %tmp.116 = icmp slt i32 0, %tmp.115 ; <i1> [#uses=1]
+ br label %shortcirc_done.0
+shortcirc_done.0: ; preds = %shortcirc_next.0, %loopentry.3
+ %shortcirc_val.0 = phi i1 [ false, %loopentry.3 ], [ %tmp.116, %shortcirc_next.0 ] ; <i1> [#uses=1]
+ br i1 %shortcirc_val.0, label %else.0, label %loopentry.3
+else.0: ; preds = %shortcirc_done.0
+ %tmp.144 = load i32* null ; <i32> [#uses=1]
+ %tmp.145 = and i32 %tmp.144, 8192 ; <i32> [#uses=1]
+ %tmp.146 = icmp ne i32 %tmp.145, 0 ; <i1> [#uses=1]
+ br i1 %tmp.146, label %then.9, label %else.26
+then.9: ; preds = %else.0
+ br label %loopentry.3
+else.26: ; preds = %else.0
+ switch i32 0, label %loopentry.0 [
+ i32 2, label %yy_find_action
+ i32 0, label %loopexit.2
+ ]
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll b/src/LLVM/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll
new file mode 100644
index 0000000..249f685
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll
@@ -0,0 +1,36 @@
+; LoopSimplify is breaking LICM on this testcase because the exit blocks from
+; the loop are reachable from more than just the exit nodes: the exit blocks
+; have predecessors from outside of the loop!
+;
+; This is distilled from a monsterous crafty example.
+
+; RUN: opt < %s -licm -disable-output
+
+
+@G = weak global i32 0 ; <i32*> [#uses=7]
+
+define i32 @main() {
+entry:
+ store i32 123, i32* @G
+ br label %loopentry.i
+loopentry.i: ; preds = %endif.1.i, %entry
+ %tmp.0.i = load i32* @G ; <i32> [#uses=1]
+ %tmp.1.i = icmp eq i32 %tmp.0.i, 123 ; <i1> [#uses=1]
+ br i1 %tmp.1.i, label %Out.i, label %endif.0.i
+endif.0.i: ; preds = %loopentry.i
+ %tmp.3.i = load i32* @G ; <i32> [#uses=1]
+ %tmp.4.i = icmp eq i32 %tmp.3.i, 126 ; <i1> [#uses=1]
+ br i1 %tmp.4.i, label %ExitBlock.i, label %endif.1.i
+endif.1.i: ; preds = %endif.0.i
+ %tmp.6.i = load i32* @G ; <i32> [#uses=1]
+ %inc.i = add i32 %tmp.6.i, 1 ; <i32> [#uses=1]
+ store i32 %inc.i, i32* @G
+ br label %loopentry.i
+Out.i: ; preds = %loopentry.i
+ store i32 0, i32* @G
+ br label %ExitBlock.i
+ExitBlock.i: ; preds = %Out.i, %endif.0.i
+ %tmp.7.i = load i32* @G ; <i32> [#uses=1]
+ ret i32 %tmp.7.i
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll b/src/LLVM/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll
new file mode 100644
index 0000000..a83eea3
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2004-02-05-DominatorInfoCorruption.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -loop-simplify -verify -licm -disable-output
+
+define void @.subst_48() {
+entry:
+ br label %loopentry.0
+loopentry.0: ; preds = %loopentry.0, %entry
+ br i1 false, label %loopentry.0, label %loopentry.2
+loopentry.2: ; preds = %loopentry.2, %loopentry.0
+ %tmp.968 = icmp sle i32 0, 3 ; <i1> [#uses=1]
+ br i1 %tmp.968, label %loopentry.2, label %UnifiedReturnBlock
+UnifiedReturnBlock: ; preds = %loopentry.2
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll b/src/LLVM/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll
new file mode 100644
index 0000000..c443215
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2004-03-15-IncorrectDomUpdate.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -loop-simplify -licm -disable-output
+define void @main() {
+entry:
+ br i1 false, label %Out, label %loop
+loop: ; preds = %loop, %entry
+ %LI = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %LI, label %loop, label %Out
+Out: ; preds = %loop, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll b/src/LLVM/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll
new file mode 100644
index 0000000..92a736d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2004-04-01-IncorrectDomUpdate.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -loop-simplify -licm -disable-output
+
+; This is PR306
+
+define void @NormalizeCoeffsVecFFE() {
+entry:
+ br label %loopentry.0
+loopentry.0: ; preds = %no_exit.0, %entry
+ br i1 false, label %loopentry.1, label %no_exit.0
+no_exit.0: ; preds = %loopentry.0
+ br i1 false, label %loopentry.0, label %loopentry.1
+loopentry.1: ; preds = %no_exit.1, %no_exit.0, %loopentry.0
+ br i1 false, label %no_exit.1, label %loopexit.1
+no_exit.1: ; preds = %loopentry.1
+ %tmp.43 = icmp eq i16 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.43, label %loopentry.1, label %loopexit.1
+loopexit.1: ; preds = %no_exit.1, %loopentry.1
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll b/src/LLVM/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll
new file mode 100644
index 0000000..3ef2e31
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2004-04-12-LoopSimplify-SwitchBackedges.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -loop-simplify -disable-output
+
+define void @test() {
+loopentry.0:
+ br label %loopentry.1
+loopentry.1: ; preds = %then.6, %then.6, %loopentry.1, %loopentry.0
+ %pixel.4 = phi i32 [ 0, %loopentry.0 ], [ %pixel.4, %loopentry.1 ], [ %tmp.370, %then.6 ], [ %tmp.370, %then.6 ] ; <i32> [#uses=1]
+ br i1 false, label %then.6, label %loopentry.1
+then.6: ; preds = %loopentry.1
+ %tmp.370 = add i32 0, 0 ; <i32> [#uses=2]
+ switch i32 0, label %label.7 [
+ i32 6408, label %loopentry.1
+ i32 32841, label %loopentry.1
+ ]
+label.7: ; preds = %then.6
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll b/src/LLVM/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
new file mode 100644
index 0000000..b892bc5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -scalarrepl -loop-simplify -licm -disable-output -verify-dom-info -verify-loop-info
+
+define void @inflate() {
+entry:
+ br label %loopentry.0.outer1111
+loopentry.0.outer1111: ; preds = %then.41, %label.11, %loopentry.0.outer1111, %entry
+ %left.0.ph1107 = phi i32 [ %tmp.1172, %then.41 ], [ 0, %entry ], [ %tmp.1172, %label.11 ], [ %left.0.ph1107, %loopentry.0.outer1111 ] ; <i32> [#uses=2]
+ %tmp.1172 = sub i32 %left.0.ph1107, 0 ; <i32> [#uses=2]
+ switch i32 0, label %label.11 [
+ i32 23, label %loopentry.0.outer1111
+ i32 13, label %then.41
+ ]
+label.11: ; preds = %loopentry.0.outer1111
+ br label %loopentry.0.outer1111
+then.41: ; preds = %loopentry.0.outer1111
+ br label %loopentry.0.outer1111
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2007-10-28-InvokeCrash.ll b/src/LLVM/test/Transforms/LoopSimplify/2007-10-28-InvokeCrash.ll
new file mode 100644
index 0000000..e91d141
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2007-10-28-InvokeCrash.ll
@@ -0,0 +1,29 @@
+; RUN: llvm-as < %s | opt -loop-simplify -disable-output
+; PR1752
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32"
+target triple = "i686-pc-mingw32"
+
+define void @func() {
+bb_init:
+ br label %bb_main
+
+bb_main:
+ br label %invcont17.normaldest
+
+invcont17.normaldest917: ; No predecessors!
+ %tmp23 = invoke i32 @foo()
+ to label %invcont17.normaldest unwind label %invcont17.normaldest.normaldest
+
+invcont17.normaldest: ; preds = %invcont17.normaldest917, %bb_main
+ br label %bb_main
+
+invcont17.normaldest.normaldest: ; No predecessors!
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ store i32 %tmp23, i32* undef
+ br label %bb_main
+}
+
+declare i32 @foo()
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2010-07-15-IncorrectDomFrontierUpdate.ll b/src/LLVM/test/Transforms/LoopSimplify/2010-07-15-IncorrectDomFrontierUpdate.ll
new file mode 100644
index 0000000..f179da2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2010-07-15-IncorrectDomFrontierUpdate.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -domfrontier -loop-simplify -domfrontier -verify-dom-info -analyze
+
+
+define void @a() nounwind {
+entry:
+ br i1 undef, label %bb37, label %bb1.i
+
+bb1.i: ; preds = %bb1.i, %bb
+ %indvar = phi i64 [ %indvar.next, %bb1.i ], [ 0, %entry ] ; <i64> [#uses=1]
+ %indvar.next = add i64 %indvar, 1 ; <i64> [#uses=2]
+ %exitcond = icmp eq i64 %indvar.next, 576 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb37, label %bb1.i
+
+bb37: ; preds = %bb1.i, %bb
+ br label %return
+
+
+return: ; preds = %bb39
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/2010-12-26-PHIInfiniteLoop.ll b/src/LLVM/test/Transforms/LoopSimplify/2010-12-26-PHIInfiniteLoop.ll
new file mode 100644
index 0000000..00f520b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/2010-12-26-PHIInfiniteLoop.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -loop-simplify -S
+; PR8702
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-freebsd9.0"
+
+declare void @foo(i32 %x)
+
+define fastcc void @inm_merge() nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %while.cond36.i, %entry
+ br i1 undef, label %do.body, label %for.body
+
+for.body: ; preds = %for.cond
+ br i1 undef, label %while.cond36.i, label %if.end44
+
+if.end44: ; preds = %for.body
+ %call49 = call fastcc i32 @inm_get_source()
+ br i1 undef, label %if.end54, label %for.cond64
+
+if.end54: ; preds = %if.end44
+ br label %while.cond36.i
+
+while.cond36.i: ; preds = %if.end54, %for.body
+ br label %for.cond
+
+for.cond64: ; preds = %if.end88, %for.cond64, %if.end44
+ %error.161 = phi i32 [ %error.161, %for.cond64 ], [ %error.161, %if.end88 ], [ %call49, %if.end44 ]
+ call void @foo(i32 %error.161)
+ br i1 undef, label %for.cond64, label %if.end88
+
+if.end88: ; preds = %for.cond64
+ br i1 undef, label %for.cond64, label %if.end98
+
+if.end98: ; preds = %if.end88
+ unreachable
+
+do.body: ; preds = %for.cond
+ unreachable
+}
+
+declare fastcc i32 @inm_get_source() nounwind
diff --git a/src/LLVM/test/Transforms/LoopSimplify/basictest.ll b/src/LLVM/test/Transforms/LoopSimplify/basictest.ll
new file mode 100644
index 0000000..73de01d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/basictest.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -loop-simplify
+
+; This function should get a preheader inserted before BB3, that is jumped
+; to by BB1 & BB2
+;
+
+define void @test() {
+ br i1 true, label %BB1, label %BB2
+BB1: ; preds = %0
+ br label %BB3
+BB2: ; preds = %0
+ br label %BB3
+BB3: ; preds = %BB3, %BB2, %BB1
+ br label %BB3
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/dg.exp b/src/LLVM/test/Transforms/LoopSimplify/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopSimplify/hardertest.ll b/src/LLVM/test/Transforms/LoopSimplify/hardertest.ll
new file mode 100644
index 0000000..821bc78
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/hardertest.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -loop-simplify
+
+define void @foo(i1 %C) {
+ br i1 %C, label %T, label %F
+T: ; preds = %0
+ br label %Loop
+F: ; preds = %0
+ br label %Loop
+Loop: ; preds = %L2, %Loop, %F, %T
+ %Val = phi i32 [ 0, %T ], [ 1, %F ], [ 2, %Loop ], [ 3, %L2 ] ; <i32> [#uses=0]
+ br i1 %C, label %Loop, label %L2
+L2: ; preds = %Loop
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/indirectbr-backedge.ll b/src/LLVM/test/Transforms/LoopSimplify/indirectbr-backedge.ll
new file mode 100644
index 0000000..7eabc09
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/indirectbr-backedge.ll
@@ -0,0 +1,35 @@
+; RUN: opt -loop-simplify -S < %s | FileCheck %s
+
+; LoopSimplify shouldn't split loop backedges that use indirectbr.
+
+; CHECK: bb1: ; preds = %bb5, %bb
+; CHECK-NEXT: indirectbr
+
+; CHECK: bb5: ; preds = %bb1
+; CHECK-NEXT: br label %bb1{{$}}
+
+define void @foo(i8* %p) nounwind {
+bb:
+ br label %bb1
+
+bb1: ; preds = %bb5, %bb1, %bb
+ indirectbr i8* %p, [label %bb6, label %bb7, label %bb1, label %bb2, label %bb3, label %bb5, label %bb4]
+
+bb2: ; preds = %bb1
+ ret void
+
+bb3: ; preds = %bb1
+ ret void
+
+bb4: ; preds = %bb1
+ ret void
+
+bb5: ; preds = %bb1
+ br label %bb1
+
+bb6: ; preds = %bb1
+ ret void
+
+bb7: ; preds = %bb1
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/indirectbr.ll b/src/LLVM/test/Transforms/LoopSimplify/indirectbr.ll
new file mode 100644
index 0000000..9814d4a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/indirectbr.ll
@@ -0,0 +1,100 @@
+; RUN: opt < %s -loop-simplify -lcssa -verify-loop-info -verify-dom-info -S \
+; RUN: | grep -F {indirectbr i8* %x, \[label %L0, label %L1\]} \
+; RUN: | count 6
+
+; LoopSimplify should not try to transform loops when indirectbr is involved.
+
+define void @entry(i8* %x) {
+entry:
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+
+L0:
+ br label %L0
+
+L1:
+ ret void
+}
+
+define void @backedge(i8* %x) {
+entry:
+ br label %L0
+
+L0:
+ br label %L1
+
+L1:
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+}
+
+define i64 @exit(i8* %x) {
+entry:
+ br label %L2
+
+L2:
+ %z = bitcast i64 0 to i64
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+
+L0:
+ br label %L2
+
+L1:
+ ret i64 %z
+}
+
+define i64 @criticalexit(i8* %x, i1 %a) {
+entry:
+ br i1 %a, label %L1, label %L2
+
+L2:
+ %z = bitcast i64 0 to i64
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+
+L0:
+ br label %L2
+
+L1:
+ %y = phi i64 [ %z, %L2 ], [ 1, %entry ]
+ ret i64 %y
+}
+
+define i64 @exit_backedge(i8* %x) {
+entry:
+ br label %L0
+
+L0:
+ %z = bitcast i64 0 to i64
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+
+L1:
+ ret i64 %z
+}
+
+define i64 @criticalexit_backedge(i8* %x, i1 %a) {
+entry:
+ br i1 %a, label %L0, label %L1
+
+L0:
+ %z = bitcast i64 0 to i64
+ indirectbr i8* %x, [ label %L0, label %L1 ]
+
+L1:
+ %y = phi i64 [ %z, %L0 ], [ 1, %entry ]
+ ret i64 %y
+}
+
+define void @pr5502() nounwind {
+entry:
+ br label %while.cond
+
+while.cond:
+ br i1 undef, label %while.body, label %while.end
+
+while.body:
+ indirectbr i8* undef, [label %end_opcode, label %end_opcode]
+
+end_opcode:
+ br i1 false, label %end_opcode, label %while.cond
+
+while.end:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/merge-exits.ll b/src/LLVM/test/Transforms/LoopSimplify/merge-exits.ll
new file mode 100644
index 0000000..40ad2f4
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/merge-exits.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -loop-simplify -loop-rotate -instcombine -indvars -S -verify-loop-info -verify-dom-info > %t
+; RUN: not grep sext %t
+; RUN: grep {phi i64} %t | count 1
+
+; Loopsimplify should be able to merge the two loop exits
+; into one, so that loop rotate can rotate the loop, so
+; that indvars can promote the induction variable to i64
+; without needing casts.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
+
+define float @t(float* %pTmp1, float* %peakWeight, i32 %bandEdgeIndex) nounwind {
+entry:
+ %t0 = load float* %peakWeight, align 4 ; <float> [#uses=1]
+ br label %bb1
+
+bb: ; preds = %bb2
+ %t1 = sext i32 %hiPart.0 to i64 ; <i64> [#uses=1]
+ %t2 = getelementptr float* %pTmp1, i64 %t1 ; <float*> [#uses=1]
+ %t3 = load float* %t2, align 4 ; <float> [#uses=1]
+ %t4 = fadd float %t3, %distERBhi.0 ; <float> [#uses=1]
+ %t5 = add i32 %hiPart.0, 1 ; <i32> [#uses=2]
+ %t6 = sext i32 %t5 to i64 ; <i64> [#uses=1]
+ %t7 = getelementptr float* %peakWeight, i64 %t6 ; <float*> [#uses=1]
+ %t8 = load float* %t7, align 4 ; <float> [#uses=1]
+ %t9 = fadd float %t8, %peakCount.0 ; <float> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb, %entry
+ %peakCount.0 = phi float [ %t0, %entry ], [ %t9, %bb ] ; <float> [#uses=2]
+ %hiPart.0 = phi i32 [ 0, %entry ], [ %t5, %bb ] ; <i32> [#uses=3]
+ %distERBhi.0 = phi float [ 0.000000e+00, %entry ], [ %t4, %bb ] ; <float> [#uses=3]
+ %t10 = fcmp uge float %distERBhi.0, 2.500000e+00 ; <i1> [#uses=1]
+ br i1 %t10, label %bb3, label %bb2
+
+bb2: ; preds = %bb1
+ %t11 = add i32 %bandEdgeIndex, -1 ; <i32> [#uses=1]
+ %t12 = icmp sgt i32 %t11, %hiPart.0 ; <i1> [#uses=1]
+ br i1 %t12, label %bb, label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %t13 = fdiv float %peakCount.0, %distERBhi.0 ; <float> [#uses=1]
+ ret float %t13
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/phi-node-simplify.ll b/src/LLVM/test/Transforms/LoopSimplify/phi-node-simplify.ll
new file mode 100644
index 0000000..9cc18ed
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/phi-node-simplify.ll
@@ -0,0 +1,55 @@
+; Loop Simplify should turn phi nodes like X = phi [X, Y] into just Y, eliminating them.
+; RUN: opt < %s -loop-simplify -S | grep phi | count 6
+
+@A = weak global [3000000 x i32] zeroinitializer ; <[3000000 x i32]*> [#uses=1]
+@B = weak global [20000 x i32] zeroinitializer ; <[20000 x i32]*> [#uses=1]
+@C = weak global [100 x i32] zeroinitializer ; <[100 x i32]*> [#uses=1]
+@Z = weak global i32 0 ; <i32*> [#uses=2]
+
+define i32 @main() {
+entry:
+ tail call void @__main( )
+ br label %loopentry.1
+loopentry.1: ; preds = %loopexit.1, %entry
+ %indvar20 = phi i32 [ 0, %entry ], [ %indvar.next21, %loopexit.1 ] ; <i32> [#uses=1]
+ %a.1 = phi i32* [ getelementptr ([3000000 x i32]* @A, i32 0, i32 0), %entry ], [ %inc.0, %loopexit.1 ] ; <i32*> [#uses=1]
+ br label %no_exit.2
+no_exit.2: ; preds = %loopexit.2, %no_exit.2, %loopentry.1
+ %a.0.4.ph = phi i32* [ %a.1, %loopentry.1 ], [ %inc.0, %loopexit.2 ], [ %a.0.4.ph, %no_exit.2 ] ; <i32*> [#uses=3]
+ %b.1.4.ph = phi i32* [ getelementptr ([20000 x i32]* @B, i32 0, i32 0), %loopentry.1 ], [ %inc.1, %loopexit.2 ], [ %b.1.4.ph, %no_exit.2 ] ; <i32*> [#uses=3]
+ %indvar17 = phi i32 [ 0, %loopentry.1 ], [ %indvar.next18, %loopexit.2 ], [ %indvar17, %no_exit.2 ] ; <i32> [#uses=2]
+ %indvar = phi i32 [ %indvar.next, %no_exit.2 ], [ 0, %loopexit.2 ], [ 0, %loopentry.1 ] ; <i32> [#uses=5]
+ %b.1.4.rec = bitcast i32 %indvar to i32 ; <i32> [#uses=1]
+ %gep.upgrd.1 = zext i32 %indvar to i64 ; <i64> [#uses=1]
+ %c.2.4 = getelementptr [100 x i32]* @C, i32 0, i64 %gep.upgrd.1 ; <i32*> [#uses=1]
+ %gep.upgrd.2 = zext i32 %indvar to i64 ; <i64> [#uses=1]
+ %a.0.4 = getelementptr i32* %a.0.4.ph, i64 %gep.upgrd.2 ; <i32*> [#uses=1]
+ %gep.upgrd.3 = zext i32 %indvar to i64 ; <i64> [#uses=1]
+ %b.1.4 = getelementptr i32* %b.1.4.ph, i64 %gep.upgrd.3 ; <i32*> [#uses=1]
+ %inc.0.rec = add i32 %b.1.4.rec, 1 ; <i32> [#uses=2]
+ %inc.0 = getelementptr i32* %a.0.4.ph, i32 %inc.0.rec ; <i32*> [#uses=2]
+ %tmp.13 = load i32* %a.0.4 ; <i32> [#uses=1]
+ %inc.1 = getelementptr i32* %b.1.4.ph, i32 %inc.0.rec ; <i32*> [#uses=1]
+ %tmp.15 = load i32* %b.1.4 ; <i32> [#uses=1]
+ %tmp.18 = load i32* %c.2.4 ; <i32> [#uses=1]
+ %tmp.16 = mul i32 %tmp.15, %tmp.13 ; <i32> [#uses=1]
+ %tmp.19 = mul i32 %tmp.16, %tmp.18 ; <i32> [#uses=1]
+ %tmp.20 = load i32* @Z ; <i32> [#uses=1]
+ %tmp.21 = add i32 %tmp.19, %tmp.20 ; <i32> [#uses=1]
+ store i32 %tmp.21, i32* @Z
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, 100 ; <i1> [#uses=1]
+ br i1 %exitcond, label %loopexit.2, label %no_exit.2
+loopexit.2: ; preds = %no_exit.2
+ %indvar.next18 = add i32 %indvar17, 1 ; <i32> [#uses=2]
+ %exitcond19 = icmp eq i32 %indvar.next18, 200 ; <i1> [#uses=1]
+ br i1 %exitcond19, label %loopexit.1, label %no_exit.2
+loopexit.1: ; preds = %loopexit.2
+ %indvar.next21 = add i32 %indvar20, 1 ; <i32> [#uses=2]
+ %exitcond22 = icmp eq i32 %indvar.next21, 300 ; <i1> [#uses=1]
+ br i1 %exitcond22, label %return, label %loopentry.1
+return: ; preds = %loopexit.1
+ ret i32 undef
+}
+
+declare void @__main()
diff --git a/src/LLVM/test/Transforms/LoopSimplify/preserve-scev.ll b/src/LLVM/test/Transforms/LoopSimplify/preserve-scev.ll
new file mode 100644
index 0000000..23ac7f2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/preserve-scev.ll
@@ -0,0 +1,138 @@
+; RUN: opt -S < %s -indvars | opt -analyze -iv-users | grep {%cmp = icmp slt i32} | grep {= \{%\\.ph,+,1\}<%for.cond>}
+; PR8079
+
+; LoopSimplify should invalidate indvars when splitting out the
+; inner loop.
+
+@maxStat = external global i32
+
+define i32 @test() nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %if.then5, %if.end, %entry
+ %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
+ %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
+ %add = add i32 %0, 1
+ %cmp = icmp slt i32 %0, 1
+ %tmp1 = load i32* @maxStat, align 4
+ br i1 %cmp, label %for.body, label %for.cond14.preheader
+
+for.cond14.preheader: ; preds = %for.cond
+ %cmp1726 = icmp sgt i32 %tmp1, 0
+ br i1 %cmp1726, label %for.body18, label %return
+
+for.body: ; preds = %for.cond
+ %cmp2 = icmp sgt i32 %tmp1, 100
+ br i1 %cmp2, label %return, label %if.end
+
+if.end: ; preds = %for.body
+ %cmp4 = icmp sgt i32 %tmp1, -1
+ br i1 %cmp4, label %if.then5, label %for.cond
+
+if.then5: ; preds = %if.end
+ call void @foo() nounwind
+ %inc = add i32 %cuts.1, 1
+ br label %for.cond
+
+for.body18: ; preds = %for.body18, %for.cond14.preheader
+ %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
+ call void @foo() nounwind
+ %1 = add nsw i32 %i13.027, 1
+ %tmp16 = load i32* @maxStat, align 4
+ %cmp17 = icmp slt i32 %1, %tmp16
+ br i1 %cmp17, label %for.body18, label %return
+
+return: ; preds = %for.body18, %for.body, %for.cond14.preheader
+ ret i32 0
+}
+
+declare void @foo() nounwind
+
+; Notify SCEV when removing an ExitingBlock.
+; CHECK: @mergeExit
+; CHECK: while.cond191:
+; CHECK: br i1 %or.cond, label %while.body197
+; CHECK-NOT: land.rhs:
+; CHECK: ret
+define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp {
+entry:
+ br i1 undef, label %if.then124, label %if.end126
+
+if.then124: ; preds = %entry
+ unreachable
+
+if.end126: ; preds = %entry
+ br i1 undef, label %while.body.lr.ph, label %if.end591
+
+while.body.lr.ph: ; preds = %if.end126
+ br i1 undef, label %if.end140, label %if.then137
+
+if.then137: ; preds = %while.body.lr.ph
+ unreachable
+
+if.end140: ; preds = %while.body.lr.ph
+ br i1 undef, label %while.cond191.outer, label %if.then148
+
+if.then148: ; preds = %if.end140
+ unreachable
+
+while.cond191.outer: ; preds = %if.then205, %if.end140
+ br label %while.cond191
+
+while.cond191: ; preds = %while.body197, %while.cond191.outer
+ %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ]
+ br i1 undef, label %land.rhs, label %if.then216
+
+land.rhs: ; preds = %while.cond191
+ %inc = add i32 %CppIndex.0, 1
+ %cmp196 = icmp ult i32 %inc, %MapAttrCount
+ br i1 %cmp196, label %while.body197, label %if.then216
+
+while.body197: ; preds = %land.rhs
+ br i1 undef, label %if.then205, label %while.cond191
+
+if.then205: ; preds = %while.body197
+ br label %while.cond191.outer
+
+if.then216: ; preds = %land.rhs, %while.cond191
+ br i1 undef, label %if.else, label %if.then221
+
+if.then221: ; preds = %if.then216
+ unreachable
+
+if.else: ; preds = %if.then216
+ br i1 undef, label %if.then266, label %if.end340
+
+if.then266: ; preds = %if.else
+ switch i32 undef, label %if.else329 [
+ i32 17, label %if.then285
+ i32 19, label %if.then285
+ i32 18, label %if.then285
+ i32 15, label %if.then285
+ ]
+
+if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266
+ br i1 undef, label %if.then317, label %if.else324
+
+if.then317: ; preds = %if.then285
+ br label %if.end340
+
+if.else324: ; preds = %if.then285
+ unreachable
+
+if.else329: ; preds = %if.then266
+ unreachable
+
+if.end340: ; preds = %if.then317, %if.else
+ unreachable
+
+if.end591: ; preds = %if.end126
+ br i1 undef, label %cond.end, label %cond.false
+
+cond.false: ; preds = %if.end591
+ unreachable
+
+cond.end: ; preds = %if.end591
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopSimplify/single-backedge.ll b/src/LLVM/test/Transforms/LoopSimplify/single-backedge.ll
new file mode 100644
index 0000000..6f50597
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/single-backedge.ll
@@ -0,0 +1,23 @@
+; The loop canonicalization pass should guarantee that there is one backedge
+; for all loops. This allows the -indvars pass to recognize the %IV
+; induction variable in this testcase.
+
+; RUN: opt < %s -indvars -S | FileCheck %s
+; CHECK: Loop.backedge:
+; CHECK-NOT: br
+; CHECK: br label %Loop
+
+define i32 @test(i1 %C) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %BE2, %BE1, %0
+ %IV = phi i32 [ 1, %0 ], [ %IV2, %BE1 ], [ %IV2, %BE2 ] ; <i32> [#uses=2]
+ store i32 %IV, i32* null
+ %IV2 = add i32 %IV, 2 ; <i32> [#uses=2]
+ br i1 %C, label %BE1, label %BE2
+BE1: ; preds = %Loop
+ br label %Loop
+BE2: ; preds = %Loop
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/LoopSimplify/unreachable-loop-pred.ll b/src/LLVM/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
new file mode 100644
index 0000000..76b7bb2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopSimplify/unreachable-loop-pred.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -loop-simplify -disable-output -verify-loop-info -verify-dom-info < %s
+; PR5235
+
+; When loopsimplify inserts a preheader for this loop, it should add the new
+; block to the enclosing loop and not get confused by the unreachable
+; bogus loop entry.
+
+define void @is_extract_cab() nounwind {
+entry:
+ br label %header
+
+header: ; preds = %if.end206, %cond.end66, %if.end23
+ br label %while.body115
+
+while.body115: ; preds = %9, %if.end192, %if.end101
+ br i1 undef, label %header, label %while.body115
+
+foo:
+ br label %while.body115
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-15-AddRecIV.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-15-AddRecIV.ll
new file mode 100644
index 0000000..0c567a7
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-15-AddRecIV.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -loop-reduce -disable-output
+
+define void @try_swap() {
+entry:
+ br i1 false, label %cond_continue.0.i, label %cond_false.0.i
+cond_false.0.i: ; preds = %entry
+ ret void
+cond_continue.0.i: ; preds = %entry
+ br i1 false, label %cond_continue.1.i, label %cond_false.1.i
+cond_false.1.i: ; preds = %cond_continue.0.i
+ ret void
+cond_continue.1.i: ; preds = %cond_continue.0.i
+ br i1 false, label %endif.3.i, label %else.0.i
+endif.3.i: ; preds = %cond_continue.1.i
+ br i1 false, label %my_irand.exit82, label %endif.0.i62
+else.0.i: ; preds = %cond_continue.1.i
+ ret void
+endif.0.i62: ; preds = %endif.3.i
+ ret void
+my_irand.exit82: ; preds = %endif.3.i
+ br i1 false, label %else.2, label %then.4
+then.4: ; preds = %my_irand.exit82
+ ret void
+else.2: ; preds = %my_irand.exit82
+ br i1 false, label %find_affected_nets.exit, label %loopentry.1.i107.outer.preheader
+loopentry.1.i107.outer.preheader: ; preds = %else.2
+ ret void
+find_affected_nets.exit: ; preds = %else.2
+ br i1 false, label %save_region_occ.exit, label %loopentry.1
+save_region_occ.exit: ; preds = %find_affected_nets.exit
+ br i1 false, label %no_exit.1.preheader, label %loopexit.1
+loopentry.1: ; preds = %find_affected_nets.exit
+ ret void
+no_exit.1.preheader: ; preds = %save_region_occ.exit
+ ret void
+loopexit.1: ; preds = %save_region_occ.exit
+ br i1 false, label %then.10, label %loopentry.3
+then.10: ; preds = %loopexit.1
+ ret void
+loopentry.3: ; preds = %endif.16, %loopexit.1
+ %indvar342 = phi i32 [ %indvar.next343, %endif.16 ], [ 0, %loopexit.1 ] ; <i32> [#uses=2]
+ br i1 false, label %loopexit.3, label %endif.16
+endif.16: ; preds = %loopentry.3
+ %indvar.next343 = add i32 %indvar342, 1 ; <i32> [#uses=1]
+ br label %loopentry.3
+loopexit.3: ; preds = %loopentry.3
+ br label %loopentry.4
+loopentry.4: ; preds = %loopentry.4, %loopexit.3
+ %indvar340 = phi i32 [ 0, %loopexit.3 ], [ %indvar.next341, %loopentry.4 ] ; <i32> [#uses=2]
+ %tmp. = add i32 %indvar340, %indvar342 ; <i32> [#uses=1]
+ %tmp.526 = load i32** null ; <i32*> [#uses=1]
+ %gep.upgrd.1 = zext i32 %tmp. to i64 ; <i64> [#uses=1]
+ %tmp.528 = getelementptr i32* %tmp.526, i64 %gep.upgrd.1 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp.528
+ %indvar.next341 = add i32 %indvar340, 1 ; <i32> [#uses=1]
+ br label %loopentry.4
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-17-OutOfLoopVariant.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-17-OutOfLoopVariant.ll
new file mode 100644
index 0000000..ca851f6
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-08-17-OutOfLoopVariant.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -loop-reduce -disable-output
+
+define i32 @image_to_texture(i32 %indvar454) {
+loopentry.1.outer:
+ %j.2.1.ph = bitcast i32 %indvar454 to i32 ; <i32> [#uses=1]
+ br label %loopentry.1
+loopentry.1: ; preds = %loopentry.1, %loopentry.1.outer
+ %i.3 = phi i32 [ 0, %loopentry.1.outer ], [ %i.3.be, %loopentry.1 ] ; <i32> [#uses=2]
+ %tmp.390 = load i32* null ; <i32> [#uses=1]
+ %tmp.392 = mul i32 %tmp.390, %j.2.1.ph ; <i32> [#uses=1]
+ %tmp.394 = add i32 %tmp.392, %i.3 ; <i32> [#uses=1]
+ %i.3.be = add i32 %i.3, 1 ; <i32> [#uses=1]
+ br i1 false, label %loopentry.1, label %label.6
+label.6: ; preds = %loopentry.1
+ ret i32 %tmp.394
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2005-09-12-UsesOutOutsideOfLoop.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-09-12-UsesOutOutsideOfLoop.ll
new file mode 100644
index 0000000..820a679
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2005-09-12-UsesOutOutsideOfLoop.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -loop-reduce -disable-output
+
+define void @main() {
+entry:
+ br label %loopentry.0
+loopentry.0: ; preds = %then.5, %entry
+ %arg_index.1.ph = phi i32 [ 1, %entry ], [ %arg_index.1.ph.be, %then.5 ] ; <i32> [#uses=1]
+ br i1 false, label %no_exit.0, label %loopexit.0
+no_exit.0: ; preds = %loopentry.0
+ %arg_index.1.1 = add i32 0, %arg_index.1.ph ; <i32> [#uses=2]
+ br i1 false, label %then.i55, label %endif.i61
+then.i55: ; preds = %no_exit.0
+ br i1 false, label %then.4, label %else.1
+endif.i61: ; preds = %no_exit.0
+ ret void
+then.4: ; preds = %then.i55
+ %tmp.19993 = add i32 %arg_index.1.1, 2 ; <i32> [#uses=0]
+ ret void
+else.1: ; preds = %then.i55
+ br i1 false, label %then.i86, label %loopexit.i97
+then.i86: ; preds = %else.1
+ ret void
+loopexit.i97: ; preds = %else.1
+ br i1 false, label %then.5, label %else.2
+then.5: ; preds = %loopexit.i97
+ %arg_index.1.ph.be = add i32 %arg_index.1.1, 2 ; <i32> [#uses=1]
+ br label %loopentry.0
+else.2: ; preds = %loopexit.i97
+ ret void
+loopexit.0: ; preds = %loopentry.0
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2007-04-23-UseIterator.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2007-04-23-UseIterator.ll
new file mode 100644
index 0000000..4429e5c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2007-04-23-UseIterator.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -loop-reduce -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+
+target triple = "i686-apple-darwin9"
+
+define i8* @foo( i8* %ABC) {
+entry:
+ switch i8 0, label %bb129 [
+ i8 0, label %UnifiedReturnBlock
+ i8 9, label %UnifiedReturnBlock
+ i8 32, label %UnifiedReturnBlock
+ i8 35, label %UnifiedReturnBlock
+ i8 37, label %bb16.preheader
+ ]
+
+bb16.preheader: ; preds = %entry
+ br label %bb16
+
+bb16: ; preds = %cond_next102, %bb16.preheader
+ %indvar = phi i32 [ %indvar.next, %cond_next102 ], [ 0, %bb16.preheader ] ; <i32> [#uses=2]
+ %ABC.2146.0.rec = mul i32 %indvar, 3 ; <i32> [#uses=1]
+ br i1 false, label %UnifiedReturnBlock.loopexit, label %cond_next102
+
+cond_next102: ; preds = %bb16
+ %tmp138145.rec = add i32 %ABC.2146.0.rec, 3 ; <i32> [#uses=1]
+ %tmp138145 = getelementptr i8* %ABC, i32 %tmp138145.rec ; <i8*> [#uses=4]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ switch i8 0, label %bb129.loopexit [
+ i8 0, label %UnifiedReturnBlock.loopexit
+ i8 9, label %UnifiedReturnBlock.loopexit
+ i8 32, label %UnifiedReturnBlock.loopexit
+ i8 35, label %UnifiedReturnBlock.loopexit
+ i8 37, label %bb16
+ ]
+
+bb129.loopexit: ; preds = %cond_next102
+ br label %bb129
+
+bb129: ; preds = %bb129.loopexit, %entry
+ ret i8* null
+
+UnifiedReturnBlock.loopexit: ; preds = %cond_next102, %cond_next102, %cond_next102, %cond_next102, %bb16
+ %UnifiedRetVal.ph = phi i8* [ %tmp138145, %cond_next102 ], [ %tmp138145, %cond_next102 ], [ %tmp138145, %cond_next102 ], [ %tmp138145, %cond_next102 ], [ null, %bb16 ] ; <i8*> [#uses=0]
+ br label %UnifiedReturnBlock
+
+UnifiedReturnBlock: ; preds = %UnifiedReturnBlock.loopexit, %entry, %entry, %entry, %entry
+ ret i8* null
+}
+
+define i8* @bar() {
+entry:
+ switch i8 0, label %bb158 [
+ i8 37, label %bb74
+ i8 58, label %cond_true
+ i8 64, label %bb11
+ ]
+
+bb11: ; preds = %entry
+ ret i8* null
+
+cond_true: ; preds = %entry
+ ret i8* null
+
+bb74: ; preds = %entry
+ ret i8* null
+
+bb158: ; preds = %entry
+ ret i8* null
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll
new file mode 100644
index 0000000..90477d1
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -loop-reduce -S | grep add | count 2
+; PR 2662
+@g_3 = common global i16 0 ; <i16*> [#uses=2]
+@"\01LC" = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+define void @func_1() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %l_2.0.reg2mem.0 = phi i16 [ 0, %entry ], [ %t1, %bb ] ; <i16> [#uses=2]
+ %t0 = shl i16 %l_2.0.reg2mem.0, 1 ; <i16>:0 [#uses=1]
+ volatile store i16 %t0, i16* @g_3, align 2
+ %t1 = add i16 %l_2.0.reg2mem.0, -3 ; <i16>:1 [#uses=2]
+ %t2 = icmp slt i16 %t1, 1 ; <i1>:2 [#uses=1]
+ br i1 %t2, label %bb, label %return
+
+return: ; preds = %bb
+ ret void
+}
+
+define i32 @main() nounwind {
+entry:
+ tail call void @func_1( ) nounwind
+ volatile load i16* @g_3, align 2 ; <i16>:0 [#uses=1]
+ zext i16 %0 to i32 ; <i32>:1 [#uses=1]
+ tail call i32 (i8*, ...)* @printf( i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), i32 %1 ) nounwind ; <i32>:2 [#uses=0]
+ ret i32 0
+}
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-14-ShadowIV.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-14-ShadowIV.ll
new file mode 100644
index 0000000..c650d8c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-08-14-ShadowIV.ll
@@ -0,0 +1,99 @@
+; RUN: opt < %s -loop-reduce -S | grep "phi double" | count 1
+
+define void @foobar(i32 %n) nounwind {
+entry:
+ icmp eq i32 %n, 0 ; <i1>:0 [#uses=2]
+ br i1 %0, label %return, label %bb.nph
+
+bb.nph: ; preds = %entry
+ %umax = select i1 %0, i32 1, i32 %n ; <i32> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %i.03 = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
+ tail call void @bar( i32 %i.03 ) nounwind
+ uitofp i32 %i.03 to double ; <double>:1 [#uses=1]
+ tail call void @foo( double %1 ) nounwind
+ %indvar.next = add i32 %i.03, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, %umax ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %bb
+
+return: ; preds = %bb, %entry
+ ret void
+}
+
+; Unable to eliminate cast because the mantissa bits for double are not enough
+; to hold all of i64 IV bits.
+define void @foobar2(i64 %n) nounwind {
+entry:
+ icmp eq i64 %n, 0 ; <i1>:0 [#uses=2]
+ br i1 %0, label %return, label %bb.nph
+
+bb.nph: ; preds = %entry
+ %umax = select i1 %0, i64 1, i64 %n ; <i64> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %i.03 = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i64> [#uses=3]
+ trunc i64 %i.03 to i32 ; <i32>:1 [#uses=1]
+ tail call void @bar( i32 %1 ) nounwind
+ uitofp i64 %i.03 to double ; <double>:2 [#uses=1]
+ tail call void @foo( double %2 ) nounwind
+ %indvar.next = add i64 %i.03, 1 ; <i64> [#uses=2]
+ %exitcond = icmp eq i64 %indvar.next, %umax ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %bb
+
+return: ; preds = %bb, %entry
+ ret void
+}
+
+; Unable to eliminate cast due to potentional overflow.
+define void @foobar3() nounwind {
+entry:
+ tail call i32 (...)* @nn( ) nounwind ; <i32>:0 [#uses=1]
+ icmp eq i32 %0, 0 ; <i1>:1 [#uses=1]
+ br i1 %1, label %return, label %bb
+
+bb: ; preds = %bb, %entry
+ %i.03 = phi i32 [ 0, %entry ], [ %3, %bb ] ; <i32> [#uses=3]
+ tail call void @bar( i32 %i.03 ) nounwind
+ uitofp i32 %i.03 to double ; <double>:2 [#uses=1]
+ tail call void @foo( double %2 ) nounwind
+ add i32 %i.03, 1 ; <i32>:3 [#uses=2]
+ tail call i32 (...)* @nn( ) nounwind ; <i32>:4 [#uses=1]
+ icmp ugt i32 %4, %3 ; <i1>:5 [#uses=1]
+ br i1 %5, label %bb, label %return
+
+return: ; preds = %bb, %entry
+ ret void
+}
+
+; Unable to eliminate cast due to overflow.
+define void @foobar4() nounwind {
+entry:
+ br label %bb.nph
+
+bb.nph: ; preds = %entry
+ br label %bb
+
+bb: ; preds = %bb, %bb.nph
+ %i.03 = phi i8 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]
+ %tmp2 = sext i8 %i.03 to i32 ; <i32>:0 [#uses=1]
+ tail call void @bar( i32 %tmp2 ) nounwind
+ %tmp3 = uitofp i8 %i.03 to double ; <double>:1 [#uses=1]
+ tail call void @foo( double %tmp3 ) nounwind
+ %indvar.next = add i8 %i.03, 1 ; <i32> [#uses=2]
+ %tmp = sext i8 %indvar.next to i32
+ %exitcond = icmp eq i32 %tmp, 32767 ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %bb
+
+return: ; preds = %bb, %entry
+ ret void
+}
+
+declare void @bar(i32)
+
+declare void @foo(double)
+
+declare i32 @nn(...)
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll
new file mode 100644
index 0000000..1ee6b5c
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll
@@ -0,0 +1,48 @@
+; RUN: opt < %s -loop-reduce -S | grep phi | count 2
+; PR 2779
+@g_19 = common global i32 0 ; <i32*> [#uses=3]
+@"\01LC" = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+define i32 @func_8(i8 zeroext %p_9) nounwind {
+entry:
+ ret i32 1
+}
+
+define i32 @func_3(i8 signext %p_5) nounwind {
+entry:
+ ret i32 1
+}
+
+define void @func_1() nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %indvar = phi i16 [ 0, %entry ], [ %indvar.next, %bb ] ; <i16> [#uses=2]
+ %tmp = sub i16 0, %indvar ; <i16> [#uses=1]
+ %tmp27 = trunc i16 %tmp to i8 ; <i8> [#uses=1]
+ load i32* @g_19, align 4 ; <i32>:0 [#uses=2]
+ add i32 %0, 1 ; <i32>:1 [#uses=1]
+ store i32 %1, i32* @g_19, align 4
+ trunc i32 %0 to i8 ; <i8>:2 [#uses=1]
+ tail call i32 @func_8( i8 zeroext %2 ) nounwind ; <i32>:3 [#uses=0]
+ shl i8 %tmp27, 2 ; <i8>:4 [#uses=1]
+ add i8 %4, -112 ; <i8>:5 [#uses=1]
+ tail call i32 @func_3( i8 signext %5 ) nounwind ; <i32>:6 [#uses=0]
+ %indvar.next = add i16 %indvar, 1 ; <i16> [#uses=2]
+ %exitcond = icmp eq i16 %indvar.next, -28 ; <i1> [#uses=1]
+ br i1 %exitcond, label %return, label %bb
+
+return: ; preds = %bb
+ ret void
+}
+
+define i32 @main() nounwind {
+entry:
+ tail call void @func_1( ) nounwind
+ load i32* @g_19, align 4 ; <i32>:0 [#uses=1]
+ tail call i32 (i8*, ...)* @printf( i8* getelementptr ([4 x i8]* @"\01LC", i32 0, i32 0), i32 %0 ) nounwind ; <i32>:1 [#uses=0]
+ ret i32 0
+}
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2009-01-13-nonconstant-stride-outside-loop.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2009-01-13-nonconstant-stride-outside-loop.ll
new file mode 100644
index 0000000..b2cf818
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2009-01-13-nonconstant-stride-outside-loop.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -loop-reduce -S | grep phi | count 1
+; RUN: opt < %s -loop-reduce -S | grep mul | count 1
+; ModuleID = '<stdin>'
+; Make sure examining a fuller expression outside the loop doesn't cause us to create a second
+; IV of stride %3.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.5"
+ %struct.anon = type { %struct.obj*, %struct.obj* }
+ %struct.obj = type { i16, i16, { %struct.anon } }
+@heap_size = external global i32 ; <i32*> [#uses=1]
+@"\01LC85" = external constant [39 x i8] ; <[39 x i8]*> [#uses=1]
+
+declare i32 @sprintf(i8*, i8*, ...) nounwind
+
+define %struct.obj* @gc_status(%struct.obj* %args) nounwind {
+entry:
+ br label %bb1.i
+
+bb.i2: ; preds = %bb2.i3
+ %indvar.next24 = add i32 %m.0.i, 1 ; <i32> [#uses=1]
+ br label %bb1.i
+
+bb1.i: ; preds = %bb.i2, %entry
+ %m.0.i = phi i32 [ 0, %entry ], [ %indvar.next24, %bb.i2 ] ; <i32> [#uses=4]
+ %0 = icmp slt i32 %m.0.i, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb2.i3, label %nactive_heaps.exit
+
+bb2.i3: ; preds = %bb1.i
+ %1 = load %struct.obj** null, align 4 ; <%struct.obj*> [#uses=1]
+ %2 = icmp eq %struct.obj* %1, null ; <i1> [#uses=1]
+ br i1 %2, label %nactive_heaps.exit, label %bb.i2
+
+nactive_heaps.exit: ; preds = %bb2.i3, %bb1.i
+ %3 = load i32* @heap_size, align 4 ; <i32> [#uses=1]
+ %4 = mul i32 %3, %m.0.i ; <i32> [#uses=1]
+ %5 = sub i32 %4, 0 ; <i32> [#uses=1]
+ %6 = tail call i32 (i8*, i8*, ...)* @sprintf(i8* null, i8* getelementptr ([39 x i8]* @"\01LC85", i32 0, i32 0), i32 %m.0.i, i32 0, i32 %5, i32 0) nounwind ; <i32> [#uses=0]
+ ret %struct.obj* null
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2009-04-28-no-reduce-mul.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2009-04-28-no-reduce-mul.ll
new file mode 100644
index 0000000..002a878
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2009-04-28-no-reduce-mul.ll
@@ -0,0 +1,48 @@
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+
+; The multiply in bb2 must not be reduced to an add, as the sext causes the
+; %1 argument to become negative after a while.
+
+; CHECK: sext i8
+; CHECK: mul i32
+; CHECK: store i32
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+@table = common global [32 x [256 x i32]] zeroinitializer, align 32 ; <[32 x [256 x i32]]*> [#uses=2]
+
+define i32 @main() nounwind {
+bb4.thread:
+ br label %bb2
+
+bb2: ; preds = %bb4, %bb2, %bb4.thread
+ %i.0.reg2mem.0.ph = phi i32 [ 0, %bb4.thread ], [ %i.0.reg2mem.0.ph, %bb2 ], [ %indvar.next9, %bb4 ] ; <i32> [#uses=4]
+ %j.0.reg2mem.0 = phi i32 [ 0, %bb4.thread ], [ %indvar.next, %bb2 ], [ 0, %bb4 ] ; <i32> [#uses=3]
+ %0 = trunc i32 %j.0.reg2mem.0 to i8 ; <i8> [#uses=1]
+ %1 = sext i8 %0 to i32 ; <i32> [#uses=1]
+ %2 = mul i32 %1, %i.0.reg2mem.0.ph ; <i32> [#uses=1]
+ %3 = getelementptr [32 x [256 x i32]]* @table, i32 0, i32 %i.0.reg2mem.0.ph, i32 %j.0.reg2mem.0 ; <i32*> [#uses=1]
+ store i32 %2, i32* %3, align 4
+ %indvar.next = add i32 %j.0.reg2mem.0, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, 256 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb4, label %bb2
+
+bb4: ; preds = %bb2
+ %indvar.next9 = add i32 %i.0.reg2mem.0.ph, 1 ; <i32> [#uses=2]
+ %exitcond10 = icmp eq i32 %indvar.next9, 32 ; <i1> [#uses=1]
+ br i1 %exitcond10, label %bb5, label %bb2
+
+bb5: ; preds = %bb4
+ %4 = load i32* getelementptr ([32 x [256 x i32]]* @table, i32 0, i32 9, i32 132), align 16 ; <i32> [#uses=1]
+ %5 = icmp eq i32 %4, -1116 ; <i1> [#uses=1]
+ br i1 %5, label %bb7, label %bb6
+
+bb6: ; preds = %bb5
+ tail call void @abort() noreturn nounwind
+ unreachable
+
+bb7: ; preds = %bb5
+ ret i32 0
+}
+
+declare void @abort() noreturn nounwind
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-19-CritEdgeBreakCrash.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-19-CritEdgeBreakCrash.ll
new file mode 100644
index 0000000..b9bd7c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-19-CritEdgeBreakCrash.ll
@@ -0,0 +1,52 @@
+; ModuleID = '<stdin>'
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+; PR10386
+
+declare i1 @foo()
+declare i8* @bar(i8*,i8*,i8*,i8*)
+
+define void @f(i64* %a,i64* %b,i64* %c,i64* %d,i64* %e,i64* %f,i64* %g) nounwind uwtable {
+entry:
+ br label %b_throw.preheader
+
+D_BREAK_LBL: ; preds = %indirectgoto
+ call i1 @foo()
+ br label %indirectgoto
+
+H_CONST_LBL: ; preds = %indirectgoto
+ call i1 @foo()
+ br label %body_failed
+
+H_MPZ_LBL: ; preds = %indirectgoto
+ %boo3 = call i1 @foo()
+ br i1 %boo3, label %body_failed, label %while.cond.i
+
+while.cond.i: ; preds = %while.body.i15795, %if.then.i15791
+ %phi = phi i64 [ %tmp20916, %while.body.i15795 ], [ 0, %H_MPZ_LBL ]
+ %tmp20916 = add i64 %phi, 1
+ %incdec.ptr.i15793 = getelementptr i64* %pc.0.lcssa.i1610719352, i64 %tmp20916
+ %boo2 = call i1 @foo()
+ br i1 %boo2, label %indirectgoto, label %while.body.i15795
+
+while.body.i15795: ; preds = %while.cond.i
+ %tmp20.i = load i64* %incdec.ptr.i15793, align 8
+ %boo1 = call i1 @foo()
+ br i1 %boo1, label %while.cond.i, label %body_failed
+
+b_throw.preheader: ; preds = %body_failed, %entry
+ call i1 @foo()
+ br label %indirectgoto
+
+body_failed:
+ %pc.0.lcssa.i1610719364 = phi i64* [ %pc.0.lcssa.i1610719352, %indirectgoto ], [ %pc.0.lcssa.i1610719352, %H_MPZ_LBL ], [ %b, %H_CONST_LBL ], [ %pc.0.lcssa.i1610719352, %while.body.i15795 ]
+ call i1 @foo()
+ br label %b_throw.preheader
+
+indirectgoto:
+ %pc.0.lcssa.i1610719352 = phi i64* [ %pc.0.lcssa.i1610719352, %D_BREAK_LBL ], [ %a, %b_throw.preheader ], [ %d, %while.cond.i ]
+ %p = call i8* @bar(i8* blockaddress(@f, %D_BREAK_LBL), i8* blockaddress(@f, %H_CONST_LBL), i8* blockaddress(@f, %H_MPZ_LBL), i8* blockaddress(@f, %body_failed) )
+ indirectbr i8* %p, [label %D_BREAK_LBL, label %H_CONST_LBL, label %H_MPZ_LBL, label %body_failed]
+}
+
+; CHECK: %p = call i8* @bar(i8* blockaddress(@f, %D_BREAK_LBL), i8* blockaddress(@f, %H_CONST_LBL), i8* blockaddress(@f, %H_MPZ_LBL), i8* blockaddress(@f, %body_failed))
+; CHECK: indirectbr i8* %p, [label %D_BREAK_LBL, label %H_CONST_LBL, label %H_MPZ_LBL, label %body_failed]
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll
new file mode 100644
index 0000000..5d9ed64
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+;
+; Test LSR's OptimizeShadowIV. Handle a floating-point IV with a
+; nonzero initial value.
+; rdar://9786536
+
+; First, make sure LSR doesn't crash on an empty IVUsers list.
+; CHECK: @dummyIV
+; CHECK-NOT: phi
+; CHECK-NOT: sitofp
+; CHECK: br
+define void @dummyIV() nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
+ %conv = sitofp i32 %i.01 to double
+ %inc = add nsw i32 %i.01, 1
+ br i1 undef, label %loop, label %for.end
+
+for.end:
+ unreachable
+}
+
+; Now check that the computed double constant is correct.
+; CHECK: @doubleIV
+; CHECK: phi double [ -3.900000e+01, %entry ]
+; CHECK: br
+define void @doubleIV() nounwind {
+entry:
+ br label %loop
+
+loop:
+ %i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
+ %conv = sitofp i32 %i.01 to double
+ %div = fdiv double %conv, 4.000000e+01
+ %inc = add nsw i32 %i.01, 1
+ br i1 undef, label %loop, label %for.end
+
+for.end:
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll
new file mode 100644
index 0000000..a6996a8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll
@@ -0,0 +1,43 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+;
+; Test LSR's use of SplitCriticalEdge during phi rewriting.
+; Verify that identical edges are merged. rdar://problem/6453893
+
+target triple = "x86-apple-darwin"
+
+; CHECK: @test
+; CHECK: bb89:
+; CHECK: phi i8* [ %lsr.iv.next1, %bbA.bb89_crit_edge ], [ %lsr.iv.next1, %bbB.bb89_crit_edge ]{{$}}
+
+define i8* @test() {
+entry:
+ br label %loop
+
+loop:
+ %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
+ %next = add i32 %rec, 1
+ %tmp75 = getelementptr i8* null, i32 %next
+ br i1 false, label %loop, label %loopexit
+
+loopexit:
+ br i1 false, label %bbA, label %bbB
+
+bbA:
+ switch i32 0, label %bb89 [
+ i32 47, label %bb89
+ i32 58, label %bb89
+ ]
+
+bbB:
+ switch i8 0, label %bb89 [
+ i8 47, label %bb89
+ i8 58, label %bb89
+ ]
+
+bb89:
+ %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
+ br label %exit
+
+exit:
+ ret i8* %tmp75phi
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll
new file mode 100644
index 0000000..1ee9bb4
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll
@@ -0,0 +1,53 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+;
+; Test LSR's intelligence regarding phi reuse.
+; Verify that scaled GEPs are not reused. rdar://5064068
+
+target triple = "x86-apple-darwin"
+
+; CHECK: @test
+; multiplies are hoisted out of the loop
+; CHECK: while.body.lr.ph:
+; CHECK: mul i64
+; CHECK: mul i64
+; GEPs are ugly
+; CHECK: while.body:
+; CHECK: phi
+; CHECK: phi
+; CHECK: phi
+; CHECK: phi
+; CHECK-NOT: phi
+; CHECK: bitcast float* {{.*}} to i8*
+; CHECK: bitcast float* {{.*}} to i8*
+; CHECK: getelementptr i8*
+; CHECK: getelementptr i8*
+
+define float @test(float* nocapture %A, float* nocapture %B, i32 %N, i32 %IA, i32 %IB) nounwind uwtable readonly ssp {
+entry:
+ %cmp1 = icmp sgt i32 %N, 0
+ br i1 %cmp1, label %while.body.lr.ph, label %while.end
+
+while.body.lr.ph: ; preds = %entry
+ %idx.ext = sext i32 %IA to i64
+ %idx.ext2 = sext i32 %IB to i64
+ br label %while.body
+
+while.body: ; preds = %while.body.lr.ph, %while.body
+ %A.addr.05 = phi float* [ %A, %while.body.lr.ph ], [ %add.ptr, %while.body ]
+ %B.addr.04 = phi float* [ %B, %while.body.lr.ph ], [ %add.ptr3, %while.body ]
+ %N.addr.03 = phi i32 [ %N, %while.body.lr.ph ], [ %sub, %while.body ]
+ %Sum0.02 = phi float [ 0.000000e+00, %while.body.lr.ph ], [ %add, %while.body ]
+ %0 = load float* %A.addr.05, align 4
+ %1 = load float* %B.addr.04, align 4
+ %mul = fmul float %0, %1
+ %add = fadd float %Sum0.02, %mul
+ %add.ptr = getelementptr inbounds float* %A.addr.05, i64 %idx.ext
+ %add.ptr3 = getelementptr inbounds float* %B.addr.04, i64 %idx.ext2
+ %sub = add nsw i32 %N.addr.03, -1
+ %cmp = icmp sgt i32 %sub, 0
+ br i1 %cmp, label %while.body, label %while.end
+
+while.end: ; preds = %while.body, %entry
+ %Sum0.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %while.body ]
+ ret float %Sum0.0.lcssa
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-13-SCEVChain.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-13-SCEVChain.ll
new file mode 100644
index 0000000..4718529
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-13-SCEVChain.ll
@@ -0,0 +1,111 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+;
+; Test TransformForPostIncUse and LSR's expansion of expressions in
+; post-inc form to ensure the implementation can handle expressions
+; DAGs, not just trees.
+
+target triple = "x86_64-apple-darwin"
+
+; Verify that -loop-reduce runs without "hanging" and reuses post-inc
+; expansions.
+; CHECK: @test
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK: icmp
+; CHECK-NOT: icmp
+define void @test(i8* %base, i32 %a0) nounwind {
+entry:
+ br label %bb1
+bb1:
+ %n0 = sub i32 0, %a0
+ %t0 = icmp ugt i32 %n0, -4
+ %m0 = select i1 %t0, i32 %n0, i32 -4
+ %a1 = add i32 %m0, %a0
+ %n1 = sub i32 0, %a1
+ %t1 = icmp ugt i32 %n1, -4
+ %m1 = select i1 %t1, i32 %n1, i32 -4
+ %a2 = add i32 %m1, %a1
+ %n2 = sub i32 0, %a2
+ %t2 = icmp ugt i32 %n2, -4
+ %m2 = select i1 %t2, i32 %n2, i32 -4
+ %a3 = add i32 %m2, %a2
+ %n3 = sub i32 0, %a3
+ %t3 = icmp ugt i32 %n3, -4
+ %m3 = select i1 %t3, i32 %n3, i32 -4
+ %a4 = add i32 %m3, %a3
+ %n4 = sub i32 0, %a4
+ %t4 = icmp ugt i32 %n4, -4
+ %m4 = select i1 %t4, i32 %n4, i32 -4
+ %a5 = add i32 %m4, %a4
+ %n5 = sub i32 0, %a5
+ %t5 = icmp ugt i32 %n5, -4
+ %m5 = select i1 %t5, i32 %n5, i32 -4
+ %a6 = add i32 %m5, %a5
+ %n6 = sub i32 0, %a6
+ %t6 = icmp ugt i32 %n6, -4
+ %m6 = select i1 %t6, i32 %n6, i32 -4
+ %a7 = add i32 %m6, %a6
+ %n7 = sub i32 0, %a7
+ %t7 = icmp ugt i32 %n7, -4
+ %m7 = select i1 %t7, i32 %n7, i32 -4
+ %a8 = add i32 %m7, %a7
+ %n8 = sub i32 0, %a8
+ %t8 = icmp ugt i32 %n8, -4
+ %m8 = select i1 %t8, i32 %n8, i32 -4
+ %a9 = add i32 %m8, %a8
+ %n9 = sub i32 0, %a9
+ %t9 = icmp ugt i32 %n9, -4
+ %m9 = select i1 %t9, i32 %n9, i32 -4
+ %a10 = add i32 %m9, %a9
+ %n10 = sub i32 0, %a10
+ %t10 = icmp ugt i32 %n10, -4
+ %m10 = select i1 %t10, i32 %n10, i32 -4
+ %a11 = add i32 %m10, %a10
+ %n11 = sub i32 0, %a11
+ %t11 = icmp ugt i32 %n11, -4
+ %m11 = select i1 %t11, i32 %n11, i32 -4
+ %a12 = add i32 %m11, %a11
+ %n12 = sub i32 0, %a12
+ %t12 = icmp ugt i32 %n12, -4
+ %m12 = select i1 %t12, i32 %n12, i32 -4
+ %a13 = add i32 %m12, %a12
+ %n13 = sub i32 0, %a13
+ %t13 = icmp ugt i32 %n13, -4
+ %m13 = select i1 %t13, i32 %n13, i32 -4
+ %a14 = add i32 %m13, %a13
+ %n14 = sub i32 0, %a14
+ %t14 = icmp ugt i32 %n14, -4
+ %m14 = select i1 %t14, i32 %n14, i32 -4
+ %a15 = add i32 %m14, %a14
+ %n15 = sub i32 0, %a15
+ %t15 = icmp ugt i32 %n15, -4
+ %m15 = select i1 %t15, i32 %n15, i32 -4
+ %a16 = add i32 %m15, %a15
+ %gep = getelementptr i8* %base, i32 %a16
+ %ofs = add i32 %a16, 4
+ %limit = getelementptr i8* %base, i32 %ofs
+ br label %loop
+
+loop:
+ %iv = phi i8* [ %gep, %bb1 ], [ %inc, %loop ]
+ %inc = getelementptr inbounds i8* %iv, i64 1
+ %exitcond = icmp eq i8* %inc, %limit
+ br i1 %exitcond, label %loop, label %exit
+
+exit:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll
new file mode 100644
index 0000000..60cc7a5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/2011-10-14-IntPtr.ll
@@ -0,0 +1,27 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+;
+; Test SCEVExpander reusing a phi->gep->phi IV when SCEV "wrongly"
+; reports the expression as an IntegerTy.
+
+target triple = "x86_64-apple-darwin"
+
+; CHECK: @test
+; CHECK: phi
+; CHECK-NOT: phi
+define void @test(i32 %rowStride) ssp align 2 {
+entry:
+ %cond = select i1 undef, i32 %rowStride, i32 4
+ br label %for.end
+
+for.end.critedge: ; preds = %for.end
+ br label %for.end
+
+for.end: ; preds = %for.end.critedge, %entry
+ br i1 undef, label %for.body83, label %for.end.critedge
+
+for.body83: ; preds = %for.body83, %for.end
+ %ptr.0157 = phi i8* [ %add.ptr96, %for.body83 ], [ null, %for.end ]
+ store i8 undef, i8* %ptr.0157, align 1
+ %add.ptr96 = getelementptr inbounds i8* %ptr.0157, i32 %cond
+ br label %for.body83
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll
new file mode 100644
index 0000000..4032a59
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll
@@ -0,0 +1,130 @@
+; RUN: llc < %s -mtriple=i386-apple-darwin11
+
+define void @_ZN4llvm20SelectionDAGLowering14visitInlineAsmENS_8CallSiteE() nounwind ssp align 2 {
+entry:
+ br i1 undef, label %bb3.i, label %bb4.i
+
+bb3.i: ; preds = %entry
+ unreachable
+
+bb4.i: ; preds = %entry
+ br i1 undef, label %bb.i.i, label %_ZNK4llvm8CallSite14getCalledValueEv.exit
+
+bb.i.i: ; preds = %bb4.i
+ unreachable
+
+_ZNK4llvm8CallSite14getCalledValueEv.exit: ; preds = %bb4.i
+ br i1 undef, label %_ZN4llvm4castINS_9InlineAsmEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit, label %bb6.i
+
+bb6.i: ; preds = %_ZNK4llvm8CallSite14getCalledValueEv.exit
+ unreachable
+
+_ZN4llvm4castINS_9InlineAsmEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit: ; preds = %_ZNK4llvm8CallSite14getCalledValueEv.exit
+ br i1 undef, label %_ZL25hasInlineAsmMemConstraintRSt6vectorIN4llvm9InlineAsm14ConstraintInfoESaIS2_EERKNS0_14TargetLoweringE.exit, label %bb.i
+
+bb.i: ; preds = %_ZN4llvm4castINS_9InlineAsmEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit
+ br label %_ZL25hasInlineAsmMemConstraintRSt6vectorIN4llvm9InlineAsm14ConstraintInfoESaIS2_EERKNS0_14TargetLoweringE.exit
+
+_ZL25hasInlineAsmMemConstraintRSt6vectorIN4llvm9InlineAsm14ConstraintInfoESaIS2_EERKNS0_14TargetLoweringE.exit: ; preds = %bb.i, %_ZN4llvm4castINS_9InlineAsmEPNS_5ValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS6_.exit
+ br i1 undef, label %bb50, label %bb27
+
+bb27: ; preds = %_ZL25hasInlineAsmMemConstraintRSt6vectorIN4llvm9InlineAsm14ConstraintInfoESaIS2_EERKNS0_14TargetLoweringE.exit
+ br i1 undef, label %bb1.i727, label %bb.i.i726
+
+bb.i.i726: ; preds = %bb27
+ unreachable
+
+bb1.i727: ; preds = %bb27
+ unreachable
+
+bb50: ; preds = %_ZL25hasInlineAsmMemConstraintRSt6vectorIN4llvm9InlineAsm14ConstraintInfoESaIS2_EERKNS0_14TargetLoweringE.exit
+ br label %bb107
+
+bb51: ; preds = %bb107
+ br i1 undef, label %bb105, label %bb106
+
+bb105: ; preds = %bb51
+ unreachable
+
+bb106: ; preds = %bb51
+ br label %bb107
+
+bb107: ; preds = %bb106, %bb50
+ br i1 undef, label %bb108, label %bb51
+
+bb108: ; preds = %bb107
+ br i1 undef, label %bb242, label %bb114
+
+bb114: ; preds = %bb108
+ br i1 undef, label %bb141, label %bb116
+
+bb116: ; preds = %bb114
+ br i1 undef, label %bb120, label %bb121
+
+bb120: ; preds = %bb116
+ unreachable
+
+bb121: ; preds = %bb116
+ unreachable
+
+bb141: ; preds = %bb114
+ br i1 undef, label %bb182, label %bb143
+
+bb143: ; preds = %bb141
+ br label %bb157
+
+bb144: ; preds = %bb.i.i.i843
+ switch i32 undef, label %bb155 [
+ i32 2, label %bb153
+ i32 6, label %bb153
+ i32 4, label %bb153
+ ]
+
+bb153: ; preds = %bb144, %bb144, %bb144
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br label %bb157
+
+bb155: ; preds = %bb144
+ unreachable
+
+bb157: ; preds = %bb153, %bb143
+ %indvar = phi i32 [ %indvar.next, %bb153 ], [ 0, %bb143 ] ; <i32> [#uses=2]
+ %0 = icmp eq i32 undef, %indvar ; <i1> [#uses=1]
+ switch i16 undef, label %bb6.i841 [
+ i16 9, label %_ZN4llvm4castINS_14ConstantSDNodeENS_7SDValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS5_.exit
+ i16 26, label %_ZN4llvm4castINS_14ConstantSDNodeENS_7SDValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS5_.exit
+ ]
+
+bb6.i841: ; preds = %bb157
+ unreachable
+
+_ZN4llvm4castINS_14ConstantSDNodeENS_7SDValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS5_.exit: ; preds = %bb157, %bb157
+ br i1 undef, label %bb.i.i.i843, label %bb1.i.i.i844
+
+bb.i.i.i843: ; preds = %_ZN4llvm4castINS_14ConstantSDNodeENS_7SDValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS5_.exit
+ br i1 %0, label %bb158, label %bb144
+
+bb1.i.i.i844: ; preds = %_ZN4llvm4castINS_14ConstantSDNodeENS_7SDValueEEENS_10cast_rettyIT_T0_E8ret_typeERKS5_.exit
+ unreachable
+
+bb158: ; preds = %bb.i.i.i843
+ br i1 undef, label %bb177, label %bb176
+
+bb176: ; preds = %bb158
+ unreachable
+
+bb177: ; preds = %bb158
+ br i1 undef, label %bb179, label %bb178
+
+bb178: ; preds = %bb177
+ unreachable
+
+bb179: ; preds = %bb177
+ unreachable
+
+bb182: ; preds = %bb141
+ unreachable
+
+bb242: ; preds = %bb108
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/X86/dg.exp b/src/LLVM/test/Transforms/LoopStrengthReduce/X86/dg.exp
new file mode 100644
index 0000000..7b7bd4e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/X86/dg.exp
@@ -0,0 +1,5 @@
+load_lib llvm.exp
+
+if { [llvm_supports_target X86] } {
+ RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]]
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/count-to-zero.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/count-to-zero.ll
new file mode 100644
index 0000000..feb79f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/count-to-zero.ll
@@ -0,0 +1,42 @@
+; RUN: opt < %s -loop-reduce -S | FileCheck %s
+; rdar://7382068
+
+define void @t(i32 %c) nounwind optsize {
+entry:
+ br label %bb6
+
+bb1: ; preds = %bb6
+ %tmp = icmp eq i32 %c_addr.1, 20 ; <i1> [#uses=1]
+ br i1 %tmp, label %bb2, label %bb3
+
+bb2: ; preds = %bb1
+ %tmp1 = tail call i32 @f20(i32 %c_addr.1) nounwind ; <i32> [#uses=1]
+ br label %bb7
+
+bb3: ; preds = %bb1
+ %tmp2 = icmp slt i32 %c_addr.1, 10 ; <i1> [#uses=1]
+ %tmp3 = add nsw i32 %c_addr.1, 1 ; <i32> [#uses=1]
+ %tmp4 = add i32 %c_addr.1, -1 ; <i32> [#uses=1]
+ %c_addr.1.be = select i1 %tmp2, i32 %tmp3, i32 %tmp4 ; <i32> [#uses=1]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+; CHECK: add i32 %lsr.iv, -1
+ br label %bb6
+
+bb6: ; preds = %bb3, %entry
+ %indvar = phi i32 [ %indvar.next, %bb3 ], [ 0, %entry ] ; <i32> [#uses=2]
+ %c_addr.1 = phi i32 [ %c_addr.1.be, %bb3 ], [ %c, %entry ] ; <i32> [#uses=7]
+ %tmp5 = icmp eq i32 %indvar, 9999 ; <i1> [#uses=1]
+; CHECK: icmp eq i32 %lsr.iv, 0
+ %tmp6 = icmp eq i32 %c_addr.1, 100 ; <i1> [#uses=1]
+ %or.cond = or i1 %tmp5, %tmp6 ; <i1> [#uses=1]
+ br i1 %or.cond, label %bb7, label %bb1
+
+bb7: ; preds = %bb6, %bb2
+ %c_addr.0 = phi i32 [ %tmp1, %bb2 ], [ %c_addr.1, %bb6 ] ; <i32> [#uses=1]
+ tail call void @bar(i32 %c_addr.0) nounwind
+ ret void
+}
+
+declare i32 @f20(i32)
+
+declare void @bar(i32)
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dead-phi.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/dead-phi.ll
new file mode 100644
index 0000000..07a942f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dead-phi.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -loop-reduce -S | grep phi | count 1
+
+define void @foo(i32 %n) {
+entry:
+ br label %loop
+
+loop:
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+
+ ; These three instructions form an isolated cycle and can be deleted.
+ %j = phi i32 [ 0, %entry ], [ %j.y, %loop ]
+ %j.x = add i32 %j, 1
+ %j.y = mul i32 %j.x, 2
+
+ %i.next = add i32 %i, 1
+ %c = icmp ne i32 %i.next, %n
+ br i1 %c, label %loop, label %exit
+
+exit:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dg.exp b/src/LLVM/test/Transforms/LoopStrengthReduce/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/different-type-ivs.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/different-type-ivs.ll
new file mode 100644
index 0000000..daa2d42
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/different-type-ivs.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -loop-reduce -disable-output
+; Test to make sure that loop-reduce never crashes on IV's
+; with different types but identical strides.
+
+define void @foo() {
+entry:
+ br label %no_exit
+no_exit: ; preds = %no_exit, %entry
+ %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %no_exit ] ; <i32> [#uses=3]
+ %indvar.upgrd.1 = trunc i32 %indvar to i16 ; <i16> [#uses=1]
+ %X.0.0 = mul i16 %indvar.upgrd.1, 1234 ; <i16> [#uses=1]
+ %tmp. = mul i32 %indvar, 1234 ; <i32> [#uses=1]
+ %tmp.5 = sext i16 %X.0.0 to i32 ; <i32> [#uses=1]
+ %tmp.3 = call i32 (...)* @bar( i32 %tmp.5, i32 %tmp. ) ; <i32> [#uses=0]
+ %tmp.0 = call i1 @pred( ) ; <i1> [#uses=1]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br i1 %tmp.0, label %return, label %no_exit
+return: ; preds = %no_exit
+ ret void
+}
+
+declare i1 @pred()
+
+declare i32 @bar(...)
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dont-hoist-simple-loop-constants.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/dont-hoist-simple-loop-constants.ll
new file mode 100644
index 0000000..3a34f17
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dont-hoist-simple-loop-constants.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: not grep {bitcast i32 1 to i32}
+; END.
+; The setlt wants to use a value that is incremented one more than the dominant
+; IV. Don't insert the 1 outside the loop, preventing folding it into the add.
+
+define void @test([700 x i32]* %nbeaux_.0__558, i32* %i_.16574) {
+then.0:
+ br label %no_exit.2
+no_exit.2: ; preds = %no_exit.2, %then.0
+ %indvar630 = phi i32 [ 0, %then.0 ], [ %indvar.next631, %no_exit.2 ] ; <i32> [#uses=4]
+ %gep.upgrd.1 = zext i32 %indvar630 to i64 ; <i64> [#uses=1]
+ %tmp.38 = getelementptr [700 x i32]* %nbeaux_.0__558, i32 0, i64 %gep.upgrd.1 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp.38
+ %inc.2 = add i32 %indvar630, 2 ; <i32> [#uses=2]
+ %tmp.34 = icmp slt i32 %inc.2, 701 ; <i1> [#uses=1]
+ %indvar.next631 = add i32 %indvar630, 1 ; <i32> [#uses=1]
+ br i1 %tmp.34, label %no_exit.2, label %loopexit.2.loopexit
+loopexit.2.loopexit: ; preds = %no_exit.2
+ store i32 %inc.2, i32* %i_.16574
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll
new file mode 100644
index 0000000..cc8dbc1
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll
@@ -0,0 +1,36 @@
+; Check that this test makes INDVAR and related stuff dead.
+; RUN: opt < %s -loop-reduce -S | grep phi | count 2
+
+declare i1 @pred()
+
+define void @test1({ i32, i32 }* %P) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=3]
+ %gep1 = getelementptr { i32, i32 }* %P, i32 %INDVAR, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %gep1
+ %gep2 = getelementptr { i32, i32 }* %P, i32 %INDVAR, i32 1 ; <i32*> [#uses=1]
+ store i32 0, i32* %gep2
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
+define void @test2([2 x i32]* %P) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=3]
+ %gep1 = getelementptr [2 x i32]* %P, i32 %INDVAR, i64 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %gep1
+ %gep2 = getelementptr [2 x i32]* %P, i32 %INDVAR, i64 1 ; <i32*> [#uses=1]
+ store i32 0, i32* %gep2
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll
new file mode 100644
index 0000000..8426715
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll
@@ -0,0 +1,22 @@
+; Don't reduce the byte access to P[i], at least not on targets that
+; support an efficient 'mem[r1+r2]' addressing mode.
+
+; RUN: opt < %s -loop-reduce -disable-output
+
+
+declare i1 @pred(i32)
+
+define void @test(i8* %PTR) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %STRRED = getelementptr i8* %PTR, i32 %INDVAR ; <i8*> [#uses=1]
+ store i8 0, i8* %STRRED
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=2]
+ ;; cannot eliminate indvar
+ %cond = call i1 @pred( i32 %INDVAR2 ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reverse.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reverse.ll
new file mode 100644
index 0000000..4c5db04
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/dont_reverse.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -loop-reduce -S \
+; RUN: | grep {icmp eq i2 %lsr.iv.next, %xmp4344}
+
+; Don't reverse the iteration if the rhs of the compare is defined
+; inside the loop.
+
+define void @Fill_Buffer(i2* %p) nounwind {
+entry:
+ br label %bb8
+
+bb8:
+ %indvar34 = phi i32 [ 0, %entry ], [ %indvar.next35, %bb8 ]
+ %indvar3451 = trunc i32 %indvar34 to i2
+ %xmp4344 = load i2* %p
+ %xmp104 = icmp eq i2 %indvar3451, %xmp4344
+ %indvar.next35 = add i32 %indvar34, 1
+ br i1 %xmp104, label %bb10, label %bb8
+
+bb10:
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/exit_compare_live_range.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/exit_compare_live_range.ll
new file mode 100644
index 0000000..0d76b87
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/exit_compare_live_range.ll
@@ -0,0 +1,21 @@
+; Make sure that the compare instruction occurs after the increment to avoid
+; having overlapping live ranges that result in copies. We want the setcc
+; instruction immediately before the conditional branch.
+;
+; RUN: opt -S -loop-reduce %s | FileCheck %s
+
+define void @foo(float* %D, i32 %E) {
+entry:
+ br label %no_exit
+no_exit: ; preds = %no_exit, %entry
+ %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %no_exit ] ; <i32> [#uses=1]
+ volatile store float 0.000000e+00, float* %D
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=2]
+; CHECK: icmp
+; CHECK-NEXT: br i1
+ %exitcond = icmp eq i32 %indvar.next, %E ; <i1> [#uses=1]
+ br i1 %exitcond, label %loopexit, label %no_exit
+loopexit: ; preds = %no_exit
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/hoist-parent-preheader.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/hoist-parent-preheader.ll
new file mode 100644
index 0000000..7982fbc
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/hoist-parent-preheader.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -loop-reduce -verify
+target triple = "x86_64-apple-darwin10"
+
+define void @myquicksort(i8* %a) nounwind ssp {
+entry:
+ br i1 undef, label %loop1, label %return
+
+loop1: ; preds = %bb13.loopexit, %entry
+ %indvar419 = phi i64 [ %indvar.next420, %loop2.exit ], [ 0, %entry ]
+ %tmp474 = shl i64 %indvar419, 2
+ %tmp484 = add i64 %tmp474, 4
+ br label %loop2
+
+loop2: ; preds = %loop1, %loop2.backedge
+ %indvar414 = phi i64 [ %indvar.next415, %loop2.backedge ], [ 0, %loop1 ]
+ %tmp473 = mul i64 %indvar414, -4
+ %tmp485 = add i64 %tmp484, %tmp473
+ %storemerge4 = getelementptr i8* %a, i64 %tmp485
+ %0 = icmp ugt i8* %storemerge4, %a
+ br i1 false, label %loop2.exit, label %loop2.backedge
+
+loop2.backedge: ; preds = %loop2
+ %indvar.next415 = add i64 %indvar414, 1
+ br label %loop2
+
+loop2.exit: ; preds = %loop2
+ %indvar.next420 = add i64 %indvar419, 1
+ br i1 undef, label %loop1, label %return
+
+return: ; preds = %loop2.exit, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first.ll
new file mode 100644
index 0000000..58dab64
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first.ll
@@ -0,0 +1,24 @@
+; Check that the index of 'P[outer]' is pulled out of the loop.
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: not grep {getelementptr.*%outer.*%INDVAR}
+
+target datalayout = "e-p:32:32:32-n8:16:32"
+declare i1 @pred()
+
+declare i32 @foo()
+
+define void @test([10000 x i32]* %P) {
+; <label>:0
+ %outer = call i32 @foo( ) ; <i32> [#uses=1]
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %STRRED = getelementptr [10000 x i32]* %P, i32 %outer, i32 %INDVAR ; <i32*> [#uses=1]
+ store i32 0, i32* %STRRED
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first_arg.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first_arg.ll
new file mode 100644
index 0000000..0a2d5f1
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/invariant_value_first_arg.ll
@@ -0,0 +1,21 @@
+; Check that the index of 'P[outer]' is pulled out of the loop.
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: not grep {getelementptr.*%outer.*%INDVAR}
+
+target datalayout = "e-p:32:32:32-n32"
+declare i1 @pred()
+
+define void @test([10000 x i32]* %P, i32 %outer) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %STRRED = getelementptr [10000 x i32]* %P, i32 %outer, i32 %INDVAR ; <i32*> [#uses=1]
+ store i32 0, i32* %STRRED
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/nested-reduce.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/nested-reduce.ll
new file mode 100644
index 0000000..694e531
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/nested-reduce.ll
@@ -0,0 +1,49 @@
+; RUN: opt < %s -loop-reduce -S | not grep mul
+
+; Make sure we don't get a multiply by 6 in this loop.
+
+define i32 @foo(i32 %A, i32 %B, i32 %C, i32 %D) {
+entry:
+ %tmp.5 = icmp sgt i32 %C, 0 ; <i1> [#uses=1]
+ %tmp.25 = and i32 %A, 1 ; <i32> [#uses=1]
+ br label %loopentry.1
+loopentry.1: ; preds = %loopexit.1, %entry
+ %indvar20 = phi i32 [ 0, %entry ], [ %indvar.next21, %loopexit.1 ] ; <i32> [#uses=2]
+ %k.1 = phi i32 [ 0, %entry ], [ %k.1.3, %loopexit.1 ] ; <i32> [#uses=2]
+ br i1 %tmp.5, label %no_exit.1.preheader, label %loopexit.1
+no_exit.1.preheader: ; preds = %loopentry.1
+ %i.0.0 = bitcast i32 %indvar20 to i32 ; <i32> [#uses=1]
+ %tmp.9 = mul i32 %i.0.0, 6 ; <i32> [#uses=1]
+ br label %no_exit.1.outer
+no_exit.1.outer: ; preds = %cond_true, %no_exit.1.preheader
+ %k.1.2.ph = phi i32 [ %k.1, %no_exit.1.preheader ], [ %k.09, %cond_true ] ; <i32> [#uses=2]
+ %j.1.2.ph = phi i32 [ 0, %no_exit.1.preheader ], [ %inc.1, %cond_true ] ; <i32> [#uses=1]
+ br label %no_exit.1
+no_exit.1: ; preds = %cond_continue, %no_exit.1.outer
+ %indvar.ui = phi i32 [ 0, %no_exit.1.outer ], [ %indvar.next, %cond_continue ] ; <i32> [#uses=2]
+ %indvar = bitcast i32 %indvar.ui to i32 ; <i32> [#uses=1]
+ %j.1.2 = add i32 %indvar, %j.1.2.ph ; <i32> [#uses=2]
+ %tmp.11 = add i32 %j.1.2, %tmp.9 ; <i32> [#uses=1]
+ %tmp.12 = trunc i32 %tmp.11 to i8 ; <i8> [#uses=1]
+ %shift.upgrd.1 = zext i8 %tmp.12 to i32 ; <i32> [#uses=1]
+ %tmp.13 = shl i32 %D, %shift.upgrd.1 ; <i32> [#uses=2]
+ %tmp.15 = icmp eq i32 %tmp.13, %B ; <i1> [#uses=1]
+ %inc.1 = add i32 %j.1.2, 1 ; <i32> [#uses=3]
+ br i1 %tmp.15, label %cond_true, label %cond_continue
+cond_true: ; preds = %no_exit.1
+ %tmp.26 = and i32 %tmp.25, %tmp.13 ; <i32> [#uses=1]
+ %k.09 = add i32 %tmp.26, %k.1.2.ph ; <i32> [#uses=2]
+ %tmp.517 = icmp slt i32 %inc.1, %C ; <i1> [#uses=1]
+ br i1 %tmp.517, label %no_exit.1.outer, label %loopexit.1
+cond_continue: ; preds = %no_exit.1
+ %tmp.519 = icmp slt i32 %inc.1, %C ; <i1> [#uses=1]
+ %indvar.next = add i32 %indvar.ui, 1 ; <i32> [#uses=1]
+ br i1 %tmp.519, label %no_exit.1, label %loopexit.1
+loopexit.1: ; preds = %cond_continue, %cond_true, %loopentry.1
+ %k.1.3 = phi i32 [ %k.1, %loopentry.1 ], [ %k.09, %cond_true ], [ %k.1.2.ph, %cond_continue ] ; <i32> [#uses=2]
+ %indvar.next21 = add i32 %indvar20, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next21, 4 ; <i1> [#uses=1]
+ br i1 %exitcond, label %loopexit.0, label %loopentry.1
+loopexit.0: ; preds = %loopexit.1
+ ret i32 %k.1.3
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/nonlinear-postinc.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/nonlinear-postinc.ll
new file mode 100644
index 0000000..1e63770
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/nonlinear-postinc.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -loop-reduce
+; PR6453
+
+target datalayout = "e-p:64:64:64"
+
+define void @_ZNK15PolynomialSpaceILi3EE13compute_indexEjRA3_j() nounwind {
+entry:
+ br label %bb6
+
+bb6:
+ %t4 = phi i32 [ 0, %entry ], [ %t3, %bb5 ]
+ %t16 = sub i32 undef, %t4
+ %t25 = sub i32 undef, %t4
+ %t26 = add i32 undef, %t25
+ br label %bb4
+
+bb4:
+ %t2 = phi i32 [ %t1, %bb3 ], [ 0, %bb6 ]
+ %t17 = mul i32 %t2, %t16
+ %t18 = zext i32 %t2 to i33
+ %t19 = add i32 %t2, -1
+ %t20 = zext i32 %t19 to i33
+ %t21 = mul i33 %t18, %t20
+ %t22 = lshr i33 %t21, 1
+ %t23 = trunc i33 %t22 to i32
+ %t24 = sub i32 %t17, %t23
+ %t27 = add i32 %t24, %t26
+ br i1 false, label %bb1, label %bb5
+
+bb1:
+ %t = icmp ugt i32 %t27, undef
+ br i1 %t, label %bb2, label %bb3
+
+bb3:
+ %t1 = add i32 %t2, 1
+ br label %bb4
+
+bb5:
+ %t3 = add i32 %t4, 1
+ br label %bb6
+
+bb2:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/ops_after_indvar.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/ops_after_indvar.ll
new file mode 100644
index 0000000..98e057b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/ops_after_indvar.ll
@@ -0,0 +1,26 @@
+; Check that this test makes INDVAR and related stuff dead, because P[indvar]
+; gets reduced, making INDVAR dead.
+
+; RUN: opt < %s -loop-reduce -S | not grep INDVAR
+
+target datalayout = "e-p:32:32:32-n32"
+
+declare i1 @pred()
+
+declare i32 @getidx()
+
+define void @test([10000 x i32]* %P) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %idx = call i32 @getidx( ) ; <i32> [#uses=1]
+ %STRRED = getelementptr [10000 x i32]* %P, i32 %INDVAR, i32 %idx ; <i32*> [#uses=1]
+ store i32 0, i32* %STRRED
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/phi_node_update_multiple_preds.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/phi_node_update_multiple_preds.ll
new file mode 100644
index 0000000..9e65eec
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/phi_node_update_multiple_preds.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -loop-reduce -disable-output
+; LSR should not crash on this.
+
+define fastcc void @loadloop() {
+entry:
+ switch i8 0, label %shortcirc_next [
+ i8 32, label %loopexit.2
+ i8 59, label %loopexit.2
+ ]
+shortcirc_next: ; preds = %no_exit.2, %entry
+ %indvar37 = phi i32 [ 0, %entry ], [ %indvar.next38, %no_exit.2 ] ; <i32> [#uses=3]
+ %gep.upgrd.1 = zext i32 %indvar37 to i64 ; <i64> [#uses=1]
+ %wp.2.4 = getelementptr i8* null, i64 %gep.upgrd.1 ; <i8*> [#uses=1]
+ br i1 false, label %loopexit.2, label %no_exit.2
+no_exit.2: ; preds = %shortcirc_next
+ %wp.2.4.rec = bitcast i32 %indvar37 to i32 ; <i32> [#uses=1]
+ %inc.1.rec = add i32 %wp.2.4.rec, 1 ; <i32> [#uses=1]
+ %inc.1 = getelementptr i8* null, i32 %inc.1.rec ; <i8*> [#uses=2]
+ %indvar.next38 = add i32 %indvar37, 1 ; <i32> [#uses=1]
+ switch i8 0, label %shortcirc_next [
+ i8 32, label %loopexit.2
+ i8 59, label %loopexit.2
+ ]
+loopexit.2: ; preds = %no_exit.2, %no_exit.2, %shortcirc_next, %entry, %entry
+ %wp.2.7 = phi i8* [ null, %entry ], [ null, %entry ], [ %wp.2.4, %shortcirc_next ], [ %inc.1, %no_exit.2 ], [ %inc.1, %no_exit.2 ] ; <i8*> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll
new file mode 100644
index 0000000..2760915
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/post-inc-icmpzero.ll
@@ -0,0 +1,91 @@
+; RUN: opt -loop-reduce -S < %s | FileCheck %s
+; PR9939
+
+; LSR should property handle the post-inc offset when folding the
+; non-IV operand of an icmp into the IV.
+
+; CHECK: %5 = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
+; CHECK: %6 = lshr i64 %5, 1
+; CHECK: %7 = mul i64 %6, 2
+; CHECK: br label %for.body
+; CHECK: for.body:
+; CHECK: %lsr.iv2 = phi i64 [ %lsr.iv.next, %for.body ], [ %7, %for.body.lr.ph ]
+; CHECK: %lsr.iv.next = add i64 %lsr.iv2, -2
+; CHECK: %lsr.iv.next3 = inttoptr i64 %lsr.iv.next to i16*
+; CHECK: %cmp27 = icmp eq i16* %lsr.iv.next3, null
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.Vector2 = type { i16*, [64 x i16], i32 }
+
+@.str = private unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
+
+define void @_Z15IntegerToStringjjR7Vector2(i32 %i, i32 %radix, %struct.Vector2* nocapture %result) nounwind noinline {
+entry:
+ %buffer = alloca [33 x i16], align 16
+ %add.ptr = getelementptr inbounds [33 x i16]* %buffer, i64 0, i64 33
+ br label %do.body
+
+do.body: ; preds = %do.body, %entry
+ %0 = phi i64 [ %indvar.next44, %do.body ], [ 0, %entry ]
+ %i.addr.0 = phi i32 [ %div, %do.body ], [ %i, %entry ]
+ %tmp51 = sub i64 32, %0
+ %incdec.ptr = getelementptr [33 x i16]* %buffer, i64 0, i64 %tmp51
+ %rem = urem i32 %i.addr.0, 10
+ %div = udiv i32 %i.addr.0, 10
+ %idxprom = zext i32 %rem to i64
+ %arrayidx = getelementptr inbounds [37 x i8]* @.str, i64 0, i64 %idxprom
+ %tmp5 = load i8* %arrayidx, align 1
+ %conv = sext i8 %tmp5 to i16
+ store i16 %conv, i16* %incdec.ptr, align 2
+ %1 = icmp ugt i32 %i.addr.0, 9
+ %indvar.next44 = add i64 %0, 1
+ br i1 %1, label %do.body, label %do.end
+
+do.end: ; preds = %do.body
+ %xap.0 = inttoptr i64 %0 to i1*
+ %cap.0 = ptrtoint i1* %xap.0 to i64
+ %sub.ptr.lhs.cast = ptrtoint i16* %add.ptr to i64
+ %sub.ptr.rhs.cast = ptrtoint i16* %incdec.ptr to i64
+ %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
+ %sub.ptr.div39 = lshr exact i64 %sub.ptr.sub, 1
+ %conv11 = trunc i64 %sub.ptr.div39 to i32
+ %mLength = getelementptr inbounds %struct.Vector2* %result, i64 0, i32 2
+ %idx.ext21 = bitcast i64 %sub.ptr.div39 to i64
+ %incdec.ptr.sum = add i64 %idx.ext21, -1
+ %cp.0.sum = sub i64 %incdec.ptr.sum, %0
+ %add.ptr22 = getelementptr [33 x i16]* %buffer, i64 1, i64 %cp.0.sum
+ %cmp2740 = icmp eq i64 %idx.ext21, 0
+ br i1 %cmp2740, label %for.end, label %for.body.lr.ph
+
+for.body.lr.ph: ; preds = %do.end
+ %tmp16 = load i32* %mLength, align 4
+ %mBegin = getelementptr inbounds %struct.Vector2* %result, i64 0, i32 0
+ %tmp14 = load i16** %mBegin, align 8
+ %tmp48 = zext i32 %tmp16 to i64
+ br label %for.body
+
+for.body: ; preds = %for.body, %for.body.lr.ph
+ %indvar = phi i64 [ 0, %for.body.lr.ph ], [ %indvar.next, %for.body ]
+ %tmp46 = add i64 %tmp51, %indvar
+ %p.042 = getelementptr [33 x i16]* %buffer, i64 0, i64 %tmp46
+ %tmp47 = sub i64 %indvar, %0
+ %incdec.ptr32 = getelementptr [33 x i16]* %buffer, i64 1, i64 %tmp47
+ %tmp49 = add i64 %tmp48, %indvar
+ %dst.041 = getelementptr i16* %tmp14, i64 %tmp49
+ %tmp29 = load i16* %p.042, align 2
+ store i16 %tmp29, i16* %dst.041, align 2
+ %cmp27 = icmp eq i16* %incdec.ptr32, %add.ptr22
+ %indvar.next = add i64 %indvar, 1
+ br i1 %cmp27, label %for.end.loopexit, label %for.body
+
+for.end.loopexit: ; preds = %for.body
+ br label %for.end
+
+for.end: ; preds = %for.end.loopexit, %do.end
+ %tmp38 = load i32* %mLength, align 4
+ %add = add i32 %tmp38, %conv11
+ store i32 %add, i32* %mLength, align 4
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/pr2537.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/pr2537.ll
new file mode 100644
index 0000000..46ad70e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/pr2537.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -loop-reduce -disable-output
+; PR 2537
+
+define void @a() {
+entry:
+ br label %dobody
+
+dobody: ; preds = %dobody, %entry
+ %y.0 = phi i128 [ 0, %entry ], [ %add, %dobody ]
+ %x.0 = phi i128 [ 0, %entry ], [ %add2, %dobody ]
+ %add = add i128 %y.0, shl (i128 1, i128 64)
+ %add2 = add i128 %x.0, shl (i128 1, i128 48)
+ call void @b( i128 %add )
+ %cmp = icmp ult i128 %add2, shl (i128 1, i128 64)
+ br i1 %cmp, label %dobody, label %afterdo
+
+afterdo: ; preds = %dobody
+ ret void
+}
+
+declare void @b(i128 %add)
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/pr2570.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/pr2570.ll
new file mode 100644
index 0000000..80efb9f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/pr2570.ll
@@ -0,0 +1,287 @@
+; RUN: opt < %s -loop-reduce -S | grep {phi\\>} | count 8
+; PR2570
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+@g_14 = internal global i32 1 ; <i32*> [#uses=1]
+@g_39 = internal global i16 -5 ; <i16*> [#uses=2]
+@g_43 = internal global i32 -6 ; <i32*> [#uses=3]
+@g_33 = internal global i32 -1269044541 ; <i32*> [#uses=1]
+@g_137 = internal global i32 8 ; <i32*> [#uses=1]
+@g_82 = internal global i32 -5 ; <i32*> [#uses=3]
+@g_91 = internal global i32 1 ; <i32*> [#uses=1]
+@g_197 = internal global i32 1 ; <i32*> [#uses=4]
+@g_207 = internal global i32 1 ; <i32*> [#uses=2]
+@g_222 = internal global i16 4165 ; <i16*> [#uses=1]
+@g_247 = internal global i8 -21 ; <i8*> [#uses=2]
+@g_260 = internal global i32 1 ; <i32*> [#uses=2]
+@g_221 = internal global i16 -17503 ; <i16*> [#uses=3]
+@g_267 = internal global i16 1 ; <i16*> [#uses=1]
+@llvm.used = appending global [1 x i8*] [ i8* bitcast (i32 (i32, i32, i16, i32, i8, i32)* @func_44 to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
+
+define i32 @func_44(i32 %p_45, i32 %p_46, i16 zeroext %p_48, i32 %p_49, i8 zeroext %p_50, i32 %p_52) nounwind {
+entry:
+ tail call i32 @func_116( i8 zeroext 2 ) nounwind ; <i32>:0 [#uses=0]
+ tail call i32 @func_63( i16 signext 2 ) nounwind ; <i32>:1 [#uses=1]
+ load i16* @g_39, align 2 ; <i16>:2 [#uses=1]
+ tail call i32 @func_63( i16 signext %2 ) nounwind ; <i32>:3 [#uses=1]
+ trunc i32 %3 to i16 ; <i16>:4 [#uses=1]
+ and i16 %4, 1 ; <i16>:5 [#uses=1]
+ trunc i32 %p_52 to i8 ; <i8>:6 [#uses=1]
+ trunc i32 %1 to i16 ; <i16>:7 [#uses=1]
+ tail call i32 @func_74( i16 zeroext %5, i8 zeroext %6, i16 zeroext %7, i16 zeroext 0 ) nounwind ; <i32>:8 [#uses=0]
+ tail call i32 @func_124( i32 544824386 ) nounwind ; <i32>:9 [#uses=0]
+ zext i8 %p_50 to i32 ; <i32>:10 [#uses=1]
+ load i32* @g_43, align 4 ; <i32>:11 [#uses=1]
+ icmp sle i32 %10, %11 ; <i1>:12 [#uses=1]
+ zext i1 %12 to i32 ; <i32>:13 [#uses=2]
+ load i8* @g_247, align 1 ; <i8>:14 [#uses=1]
+ trunc i32 %p_45 to i16 ; <i16>:15 [#uses=1]
+ zext i8 %14 to i16 ; <i16>:16 [#uses=1]
+ tail call i32 @func_74( i16 zeroext %15, i8 zeroext 0, i16 zeroext %16, i16 zeroext 23618 ) nounwind ; <i32>:17 [#uses=4]
+ icmp slt i32 %17, 0 ; <i1>:18 [#uses=1]
+ br i1 %18, label %bb162, label %bb152
+
+bb152: ; preds = %entry
+ lshr i32 2147483647, %13 ; <i32>:19 [#uses=1]
+ icmp slt i32 %19, %17 ; <i1>:20 [#uses=1]
+ select i1 %20, i32 0, i32 %13 ; <i32>:21 [#uses=1]
+ %.348 = shl i32 %17, %21 ; <i32> [#uses=1]
+ br label %bb162
+
+bb162: ; preds = %bb152, %entry
+ %.0346 = phi i32 [ %.348, %bb152 ], [ %17, %entry ] ; <i32> [#uses=1]
+ tail call i32 @func_124( i32 1 ) nounwind ; <i32>:22 [#uses=1]
+ mul i32 %22, %.0346 ; <i32>:23 [#uses=1]
+ icmp slt i32 %p_45, 0 ; <i1>:24 [#uses=1]
+ icmp ugt i32 %p_45, 31 ; <i1>:25 [#uses=1]
+ %or.cond = or i1 %24, %25 ; <i1> [#uses=1]
+ br i1 %or.cond, label %bb172, label %bb168
+
+bb168: ; preds = %bb162
+ lshr i32 2147483647, %p_45 ; <i32>:26 [#uses=1]
+ shl i32 1392859848, %p_45 ; <i32>:27 [#uses=1]
+ icmp slt i32 %26, 1392859848 ; <i1>:28 [#uses=1]
+ %.op355 = add i32 %27, 38978 ; <i32> [#uses=1]
+ %phitmp = select i1 %28, i32 1392898826, i32 %.op355 ; <i32> [#uses=1]
+ br label %bb172
+
+bb172: ; preds = %bb168, %bb162
+ %.0343 = phi i32 [ %phitmp, %bb168 ], [ 1392898826, %bb162 ] ; <i32> [#uses=2]
+ tail call i32 @func_84( i32 1, i16 zeroext 0, i16 zeroext 8 ) nounwind ; <i32>:29 [#uses=0]
+ icmp eq i32 %.0343, 0 ; <i1>:30 [#uses=1]
+ %.0341 = select i1 %30, i32 1, i32 %.0343 ; <i32> [#uses=1]
+ urem i32 %23, %.0341 ; <i32>:31 [#uses=1]
+ load i32* @g_137, align 4 ; <i32>:32 [#uses=4]
+ icmp slt i32 %32, 0 ; <i1>:33 [#uses=1]
+ br i1 %33, label %bb202, label %bb198
+
+bb198: ; preds = %bb172
+ %not. = icmp slt i32 %32, 1073741824 ; <i1> [#uses=1]
+ zext i1 %not. to i32 ; <i32>:34 [#uses=1]
+ %.351 = shl i32 %32, %34 ; <i32> [#uses=1]
+ br label %bb202
+
+bb202: ; preds = %bb198, %bb172
+ %.0335 = phi i32 [ %.351, %bb198 ], [ %32, %bb172 ] ; <i32> [#uses=1]
+ icmp ne i32 %31, %.0335 ; <i1>:35 [#uses=1]
+ zext i1 %35 to i32 ; <i32>:36 [#uses=1]
+ tail call i32 @func_128( i32 %36 ) nounwind ; <i32>:37 [#uses=0]
+ icmp eq i32 %p_45, 293685862 ; <i1>:38 [#uses=1]
+ br i1 %38, label %bb205, label %bb311
+
+bb205: ; preds = %bb202
+ icmp sgt i32 %p_46, 214 ; <i1>:39 [#uses=1]
+ zext i1 %39 to i32 ; <i32>:40 [#uses=2]
+ tail call i32 @func_128( i32 %40 ) nounwind ; <i32>:41 [#uses=0]
+ icmp sgt i32 %p_46, 65532 ; <i1>:42 [#uses=1]
+ zext i1 %42 to i16 ; <i16>:43 [#uses=1]
+ tail call i32 @func_74( i16 zeroext 23618, i8 zeroext -29, i16 zeroext %43, i16 zeroext 1 ) nounwind ; <i32>:44 [#uses=2]
+ tail call i32 @func_103( i16 zeroext -869 ) nounwind ; <i32>:45 [#uses=0]
+ udiv i32 %44, 34162 ; <i32>:46 [#uses=1]
+ icmp ult i32 %44, 34162 ; <i1>:47 [#uses=1]
+ %.0331 = select i1 %47, i32 1, i32 %46 ; <i32> [#uses=1]
+ urem i32 293685862, %.0331 ; <i32>:48 [#uses=1]
+ tail call i32 @func_112( i32 %p_52, i16 zeroext 1 ) nounwind ; <i32>:49 [#uses=0]
+ icmp eq i32 %p_52, 0 ; <i1>:50 [#uses=2]
+ br i1 %50, label %bb222, label %bb215
+
+bb215: ; preds = %bb205
+ zext i16 %p_48 to i32 ; <i32>:51 [#uses=1]
+ icmp eq i16 %p_48, 0 ; <i1>:52 [#uses=1]
+ %.0329 = select i1 %52, i32 1, i32 %51 ; <i32> [#uses=1]
+ udiv i32 -1, %.0329 ; <i32>:53 [#uses=1]
+ icmp eq i32 %53, 0 ; <i1>:54 [#uses=1]
+ br i1 %54, label %bb222, label %bb223
+
+bb222: ; preds = %bb215, %bb205
+ br label %bb223
+
+bb223: ; preds = %bb222, %bb215
+ %iftmp.437.0 = phi i32 [ 0, %bb222 ], [ 1, %bb215 ] ; <i32> [#uses=1]
+ load i32* @g_91, align 4 ; <i32>:55 [#uses=3]
+ tail call i32 @func_103( i16 zeroext 4 ) nounwind ; <i32>:56 [#uses=0]
+ tail call i32 @func_112( i32 0, i16 zeroext -31374 ) nounwind ; <i32>:57 [#uses=0]
+ load i32* @g_197, align 4 ; <i32>:58 [#uses=1]
+ tail call i32 @func_124( i32 28156 ) nounwind ; <i32>:59 [#uses=1]
+ load i32* @g_260, align 4 ; <i32>:60 [#uses=1]
+ load i32* @g_43, align 4 ; <i32>:61 [#uses=1]
+ xor i32 %61, %60 ; <i32>:62 [#uses=1]
+ mul i32 %62, %59 ; <i32>:63 [#uses=1]
+ trunc i32 %63 to i8 ; <i8>:64 [#uses=1]
+ trunc i32 %58 to i16 ; <i16>:65 [#uses=1]
+ tail call i32 @func_74( i16 zeroext 0, i8 zeroext %64, i16 zeroext %65, i16 zeroext 0 ) nounwind ; <i32>:66 [#uses=2]
+ icmp slt i32 %66, 0 ; <i1>:67 [#uses=1]
+ icmp slt i32 %55, 0 ; <i1>:68 [#uses=1]
+ icmp ugt i32 %55, 31 ; <i1>:69 [#uses=1]
+ or i1 %68, %69 ; <i1>:70 [#uses=1]
+ %or.cond352 = or i1 %70, %67 ; <i1> [#uses=1]
+ select i1 %or.cond352, i32 0, i32 %55 ; <i32>:71 [#uses=1]
+ %.353 = ashr i32 %66, %71 ; <i32> [#uses=2]
+ load i16* @g_221, align 2 ; <i16>:72 [#uses=1]
+ zext i16 %72 to i32 ; <i32>:73 [#uses=1]
+ icmp ugt i32 %.353, 31 ; <i1>:74 [#uses=1]
+ select i1 %74, i32 0, i32 %.353 ; <i32>:75 [#uses=1]
+ %.0323 = lshr i32 %73, %75 ; <i32> [#uses=1]
+ add i32 %.0323, %iftmp.437.0 ; <i32>:76 [#uses=1]
+ and i32 %48, 255 ; <i32>:77 [#uses=2]
+ add i32 %77, 2042556439 ; <i32>:78 [#uses=1]
+ load i32* @g_207, align 4 ; <i32>:79 [#uses=2]
+ icmp ugt i32 %79, 31 ; <i1>:80 [#uses=1]
+ select i1 %80, i32 0, i32 %79 ; <i32>:81 [#uses=1]
+ %.0320 = lshr i32 %77, %81 ; <i32> [#uses=1]
+ icmp ne i32 %78, %.0320 ; <i1>:82 [#uses=1]
+ zext i1 %82 to i8 ; <i8>:83 [#uses=1]
+ tail call i32 @func_25( i8 zeroext %83 ) nounwind ; <i32>:84 [#uses=1]
+ xor i32 %84, 1 ; <i32>:85 [#uses=1]
+ load i32* @g_197, align 4 ; <i32>:86 [#uses=1]
+ add i32 %86, 1 ; <i32>:87 [#uses=1]
+ add i32 %87, %85 ; <i32>:88 [#uses=1]
+ icmp ugt i32 %76, %88 ; <i1>:89 [#uses=1]
+ br i1 %89, label %bb241, label %bb311
+
+bb241: ; preds = %bb223
+ store i16 -9, i16* @g_221, align 2
+ udiv i32 %p_52, 1538244727 ; <i32>:90 [#uses=1]
+ load i32* @g_207, align 4 ; <i32>:91 [#uses=1]
+ sub i32 %91, %90 ; <i32>:92 [#uses=1]
+ load i32* @g_14, align 4 ; <i32>:93 [#uses=1]
+ trunc i32 %93 to i16 ; <i16>:94 [#uses=1]
+ trunc i32 %p_46 to i16 ; <i16>:95 [#uses=2]
+ sub i16 %94, %95 ; <i16>:96 [#uses=1]
+ load i32* @g_197, align 4 ; <i32>:97 [#uses=1]
+ trunc i32 %97 to i16 ; <i16>:98 [#uses=1]
+ tail call i32 @func_55( i32 -346178830, i16 zeroext %98, i16 zeroext %95 ) nounwind ; <i32>:99 [#uses=0]
+ zext i16 %p_48 to i32 ; <i32>:100 [#uses=1]
+ load i8* @g_247, align 1 ; <i8>:101 [#uses=1]
+ zext i8 %101 to i32 ; <i32>:102 [#uses=1]
+ sub i32 %100, %102 ; <i32>:103 [#uses=1]
+ tail call i32 @func_55( i32 %103, i16 zeroext -2972, i16 zeroext %96 ) nounwind ; <i32>:104 [#uses=0]
+ xor i32 %92, 2968 ; <i32>:105 [#uses=1]
+ load i32* @g_197, align 4 ; <i32>:106 [#uses=1]
+ icmp ugt i32 %105, %106 ; <i1>:107 [#uses=1]
+ zext i1 %107 to i32 ; <i32>:108 [#uses=1]
+ store i32 %108, i32* @g_33, align 4
+ br label %bb248
+
+bb248: ; preds = %bb284, %bb241
+ %p_49_addr.1.reg2mem.0 = phi i32 [ 0, %bb241 ], [ %134, %bb284 ] ; <i32> [#uses=2]
+ %p_48_addr.2.reg2mem.0 = phi i16 [ %p_48, %bb241 ], [ %p_48_addr.1, %bb284 ] ; <i16> [#uses=1]
+ %p_46_addr.1.reg2mem.0 = phi i32 [ %p_46, %bb241 ], [ %133, %bb284 ] ; <i32> [#uses=1]
+ %p_45_addr.1.reg2mem.0 = phi i32 [ %p_45, %bb241 ], [ %p_45_addr.0, %bb284 ] ; <i32> [#uses=2]
+ tail call i32 @func_63( i16 signext 1 ) nounwind ; <i32>:109 [#uses=1]
+ icmp eq i32 %109, 0 ; <i1>:110 [#uses=1]
+ br i1 %110, label %bb272.thread, label %bb255.thread
+
+bb272.thread: ; preds = %bb248
+ store i32 1, i32* @g_82
+ load i16* @g_267, align 2 ; <i16>:111 [#uses=1]
+ icmp eq i16 %111, 0 ; <i1>:112 [#uses=1]
+ br i1 %112, label %bb311.loopexit.split, label %bb268
+
+bb255.thread: ; preds = %bb248
+ load i32* @g_260, align 4 ; <i32>:113 [#uses=1]
+ sub i32 %113, %p_52 ; <i32>:114 [#uses=1]
+ and i32 %114, -20753 ; <i32>:115 [#uses=1]
+ icmp ne i32 %115, 0 ; <i1>:116 [#uses=1]
+ zext i1 %116 to i16 ; <i16>:117 [#uses=1]
+ store i16 %117, i16* @g_221, align 2
+ br label %bb284
+
+bb268: ; preds = %bb268, %bb272.thread
+ %indvar = phi i32 [ 0, %bb272.thread ], [ %g_82.tmp.0, %bb268 ] ; <i32> [#uses=2]
+ %p_46_addr.0.reg2mem.0 = phi i32 [ %p_46_addr.1.reg2mem.0, %bb272.thread ], [ %119, %bb268 ] ; <i32> [#uses=1]
+ %g_82.tmp.0 = add i32 %indvar, 1 ; <i32> [#uses=2]
+ trunc i32 %p_46_addr.0.reg2mem.0 to i16 ; <i16>:118 [#uses=1]
+ and i32 %g_82.tmp.0, 28156 ; <i32>:119 [#uses=1]
+ add i32 %indvar, 2 ; <i32>:120 [#uses=4]
+ icmp sgt i32 %120, -1 ; <i1>:121 [#uses=1]
+ br i1 %121, label %bb268, label %bb274.split
+
+bb274.split: ; preds = %bb268
+ store i32 %120, i32* @g_82
+ br i1 %50, label %bb279, label %bb276
+
+bb276: ; preds = %bb274.split
+ store i16 0, i16* @g_222, align 2
+ br label %bb284
+
+bb279: ; preds = %bb274.split
+ icmp eq i32 %120, 0 ; <i1>:122 [#uses=1]
+ %.0317 = select i1 %122, i32 1, i32 %120 ; <i32> [#uses=1]
+ udiv i32 -8, %.0317 ; <i32>:123 [#uses=1]
+ trunc i32 %123 to i16 ; <i16>:124 [#uses=1]
+ br label %bb284
+
+bb284: ; preds = %bb279, %bb276, %bb255.thread
+ %p_49_addr.0 = phi i32 [ %p_49_addr.1.reg2mem.0, %bb279 ], [ %p_49_addr.1.reg2mem.0, %bb276 ], [ 0, %bb255.thread ] ; <i32> [#uses=1]
+ %p_48_addr.1 = phi i16 [ %124, %bb279 ], [ %118, %bb276 ], [ %p_48_addr.2.reg2mem.0, %bb255.thread ] ; <i16> [#uses=1]
+ %p_45_addr.0 = phi i32 [ %p_45_addr.1.reg2mem.0, %bb279 ], [ %p_45_addr.1.reg2mem.0, %bb276 ], [ 8, %bb255.thread ] ; <i32> [#uses=3]
+ load i32* @g_43, align 4 ; <i32>:125 [#uses=1]
+ trunc i32 %125 to i8 ; <i8>:126 [#uses=1]
+ tail call i32 @func_116( i8 zeroext %126 ) nounwind ; <i32>:127 [#uses=0]
+ lshr i32 65255, %p_45_addr.0 ; <i32>:128 [#uses=1]
+ icmp ugt i32 %p_45_addr.0, 31 ; <i1>:129 [#uses=1]
+ %.op = lshr i32 %128, 31 ; <i32> [#uses=1]
+ %.op.op = xor i32 %.op, 1 ; <i32> [#uses=1]
+ %.354..lobit.not = select i1 %129, i32 1, i32 %.op.op ; <i32> [#uses=1]
+ load i16* @g_39, align 2 ; <i16>:130 [#uses=1]
+ zext i16 %130 to i32 ; <i32>:131 [#uses=1]
+ icmp slt i32 %.354..lobit.not, %131 ; <i1>:132 [#uses=1]
+ zext i1 %132 to i32 ; <i32>:133 [#uses=1]
+ add i32 %p_49_addr.0, 1 ; <i32>:134 [#uses=2]
+ icmp sgt i32 %134, -1 ; <i1>:135 [#uses=1]
+ br i1 %135, label %bb248, label %bb307
+
+bb307: ; preds = %bb284
+ tail call i32 @func_103( i16 zeroext 0 ) nounwind ; <i32>:136 [#uses=0]
+ ret i32 %40
+
+bb311.loopexit.split: ; preds = %bb272.thread
+ store i32 1, i32* @g_82
+ ret i32 1
+
+bb311: ; preds = %bb223, %bb202
+ %.0 = phi i32 [ 1, %bb202 ], [ 0, %bb223 ] ; <i32> [#uses=1]
+ ret i32 %.0
+}
+
+declare i32 @func_25(i8 zeroext ) nounwind
+
+declare i32 @func_55(i32, i16 zeroext , i16 zeroext ) nounwind
+
+declare i32 @func_63(i16 signext ) nounwind
+
+declare i32 @func_74(i16 zeroext , i8 zeroext , i16 zeroext , i16 zeroext ) nounwind
+
+declare i32 @func_84(i32, i16 zeroext , i16 zeroext ) nounwind
+
+declare i32 @func_103(i16 zeroext ) nounwind
+
+declare i32 @func_124(i32) nounwind
+
+declare i32 @func_128(i32) nounwind
+
+declare i32 @func_116(i8 zeroext ) nounwind
+
+declare i32 @func_112(i32, i16 zeroext ) nounwind
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/pr3086.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3086.ll
new file mode 100644
index 0000000..599633a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3086.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -loop-reduce
+; RUN: opt < %s -analyze -scalar-evolution
+; PR 3086
+
+ %struct.Cls = type { i32, i8, [2 x %struct.Cls*], [2 x %struct.Lit*] }
+ %struct.Lit = type { i8 }
+
+define fastcc i64 @collect_clauses() nounwind {
+entry:
+ br label %bb11
+
+bb5: ; preds = %bb9
+ %0 = load %struct.Lit** %storemerge, align 8 ; <%struct.Lit*> [#uses=0]
+ %indvar.next8 = add i64 %storemerge.rec, 1 ; <i64> [#uses=1]
+ br label %bb9
+
+bb9: ; preds = %bb22, %bb5
+ %storemerge.rec = phi i64 [ %indvar.next8, %bb5 ], [ 0, %bb22 ] ; <i64> [#uses=2]
+ %storemerge = getelementptr %struct.Lit** null, i64 %storemerge.rec ; <%struct.Lit**> [#uses=2]
+ %1 = icmp ugt %struct.Lit** null, %storemerge ; <i1> [#uses=1]
+ br i1 %1, label %bb5, label %bb22
+
+bb11: ; preds = %bb22, %entry
+ %2 = load %struct.Cls** null, align 8 ; <%struct.Cls*> [#uses=0]
+ br label %bb22
+
+bb22: ; preds = %bb11, %bb9
+ br i1 false, label %bb11, label %bb9
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/pr3399.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3399.ll
new file mode 100644
index 0000000..b809007
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3399.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -loop-reduce | llvm-dis
+; PR3399
+
+@g_53 = external global i32 ; <i32*> [#uses=1]
+
+define i32 @foo() nounwind {
+bb5.thread:
+ br label %bb
+
+bb: ; preds = %bb5, %bb5.thread
+ %indvar = phi i32 [ 0, %bb5.thread ], [ %indvar.next, %bb5 ] ; <i32> [#uses=2]
+ br i1 false, label %bb5, label %bb1
+
+bb1: ; preds = %bb
+ %l_2.0.reg2mem.0 = sub i32 0, %indvar ; <i32> [#uses=1]
+ %0 = volatile load i32* @g_53, align 4 ; <i32> [#uses=1]
+ %1 = trunc i32 %l_2.0.reg2mem.0 to i16 ; <i16> [#uses=1]
+ %2 = trunc i32 %0 to i16 ; <i16> [#uses=1]
+ %3 = mul i16 %2, %1 ; <i16> [#uses=1]
+ %4 = icmp eq i16 %3, 0 ; <i1> [#uses=1]
+ br i1 %4, label %bb7, label %bb2
+
+bb2: ; preds = %bb2, %bb1
+ br label %bb2
+
+bb5: ; preds = %bb
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br label %bb
+
+bb7: ; preds = %bb1
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/pr3571.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3571.ll
new file mode 100644
index 0000000..a23e4db
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/pr3571.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -loop-reduce | llvm-dis
+; PR3571
+
+target triple = "i386-pc-mingw32"
+define void @_ZNK18qdesigner_internal10TreeWidget12drawBranchesEP8QPainterRK5QRectRK11QModelIndex() nounwind {
+entry:
+ br label %_ZNK11QModelIndex7isValidEv.exit.i
+
+bb.i: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i
+ %indvar.next = add i32 %result.0.i, 1 ; <i32> [#uses=1]
+ br label %_ZNK11QModelIndex7isValidEv.exit.i
+
+_ZNK11QModelIndex7isValidEv.exit.i: ; preds = %bb.i, %entry
+ %result.0.i = phi i32 [ 0, %entry ], [ %indvar.next, %bb.i ] ; <i32> [#uses=2]
+ %0 = load i32** null, align 4 ; <%struct.QAbstractItemDelegate*> [#uses=0]
+ br i1 false, label %_ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit, label %bb.i
+
+_ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i
+ %1 = call i32 @_ZNK9QTreeView11indentationEv(i32* null) nounwind ; <i32> [#uses=1]
+ %2 = mul i32 %1, %result.0.i ; <i32> [#uses=1]
+ %3 = add i32 %2, -2 ; <i32> [#uses=1]
+ %4 = add i32 %3, 0 ; <i32> [#uses=1]
+ store i32 %4, i32* null, align 8
+ unreachable
+}
+
+declare i32 @_ZNK9QTreeView11indentationEv(i32*)
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
new file mode 100644
index 0000000..59f14fc
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -analyze -iv-users | grep {\{1,+,3,+,2\}<%loop> (post-inc with loop %loop)}
+
+; The value of %r is dependent on a polynomial iteration expression.
+
+define i64 @foo(i64 %n) {
+entry:
+ br label %loop
+
+loop:
+ %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %loop ]
+ %indvar.next = add i64 %indvar, 1
+ %c = icmp eq i64 %indvar.next, %n
+ br i1 %c, label %exit, label %loop
+
+exit:
+ %r = mul i64 %indvar.next, %indvar.next
+ ret i64 %r
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/related_indvars.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/related_indvars.ll
new file mode 100644
index 0000000..57f6f43
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/related_indvars.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -loop-reduce -S | grep phi | count 1
+
+; This should only result in one PHI node!
+
+; void foo(double *D, double *E, double F) {
+; while (D != E)
+; *D++ = F;
+; }
+
+define void @foo(double* %D, double* %E, double %F) nounwind {
+entry:
+ %tmp.24 = icmp eq double* %D, %E ; <i1> [#uses=1]
+ br i1 %tmp.24, label %return, label %no_exit
+no_exit: ; preds = %no_exit, %entry
+ %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %no_exit ] ; <i32> [#uses=2]
+ %D_addr.0.0.rec = bitcast i32 %indvar to i32 ; <i32> [#uses=2]
+ %D_addr.0.0 = getelementptr double* %D, i32 %D_addr.0.0.rec ; <double*> [#uses=1]
+ %inc.rec = add i32 %D_addr.0.0.rec, 1 ; <i32> [#uses=1]
+ %inc = getelementptr double* %D, i32 %inc.rec ; <double*> [#uses=1]
+ store double %F, double* %D_addr.0.0
+ %tmp.2 = icmp eq double* %inc, %E ; <i1> [#uses=1]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br i1 %tmp.2, label %return, label %no_exit
+return: ; preds = %no_exit, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/remove_indvar.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/remove_indvar.ll
new file mode 100644
index 0000000..7fb546f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/remove_indvar.ll
@@ -0,0 +1,21 @@
+; Check that this test makes INDVAR and related stuff dead.
+; RUN: opt < %s -loop-reduce -S | not grep INDVAR
+
+declare i1 @pred()
+
+define void @test(i32* %P) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %i = phi i32 [ 0, %0 ], [ %i.next, %Loop ]
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %STRRED = getelementptr i32* %P, i32 %INDVAR ; <i32*> [#uses=1]
+ store i32 0, i32* %STRRED
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ %i.next = add i32 %i, 1
+ %cond = call i1 @pred( ) ; <i1> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/share_code_in_preheader.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/share_code_in_preheader.ll
new file mode 100644
index 0000000..e5ca6bf
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/share_code_in_preheader.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -loop-reduce -S | grep mul | count 1
+; LSR should not make two copies of the Q*L expression in the preheader!
+
+define i8 @test(i8* %A, i8* %B, i32 %L, i32 %Q, i32 %N.s) {
+entry:
+ %tmp.6 = mul i32 %Q, %L ; <i32> [#uses=1]
+ %N = bitcast i32 %N.s to i32 ; <i32> [#uses=1]
+ br label %no_exit
+no_exit: ; preds = %no_exit, %entry
+ %indvar.ui = phi i32 [ 0, %entry ], [ %indvar.next, %no_exit ] ; <i32> [#uses=2]
+ %Sum.0.0 = phi i8 [ 0, %entry ], [ %tmp.21, %no_exit ] ; <i8> [#uses=1]
+ %indvar = bitcast i32 %indvar.ui to i32 ; <i32> [#uses=1]
+ %N_addr.0.0 = sub i32 %N.s, %indvar ; <i32> [#uses=1]
+ %tmp.8 = add i32 %N_addr.0.0, %tmp.6 ; <i32> [#uses=2]
+ %tmp.9 = getelementptr i8* %A, i32 %tmp.8 ; <i8*> [#uses=1]
+ %tmp.10 = load i8* %tmp.9 ; <i8> [#uses=1]
+ %tmp.17 = getelementptr i8* %B, i32 %tmp.8 ; <i8*> [#uses=1]
+ %tmp.18 = load i8* %tmp.17 ; <i8> [#uses=1]
+ %tmp.19 = sub i8 %tmp.10, %tmp.18 ; <i8> [#uses=1]
+ %tmp.21 = add i8 %tmp.19, %Sum.0.0 ; <i8> [#uses=2]
+ %indvar.next = add i32 %indvar.ui, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next, %N ; <i1> [#uses=1]
+ br i1 %exitcond, label %loopexit, label %no_exit
+loopexit: ; preds = %no_exit
+ ret i8 %tmp.21
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/share_ivs.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/share_ivs.ll
new file mode 100644
index 0000000..23a4b7e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/share_ivs.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -loop-reduce -S | grep phi | count 1
+
+; This testcase should have ONE stride 18 indvar, the other use should have a
+; loop invariant value (B) added to it inside of the loop, instead of having
+; a whole indvar based on B for it.
+
+declare i1 @cond(i32)
+
+define void @test(i32 %B) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %IV = phi i32 [ 0, %0 ], [ %IVn, %Loop ] ; <i32> [#uses=3]
+ %C = mul i32 %IV, 18 ; <i32> [#uses=1]
+ %D = mul i32 %IV, 18 ; <i32> [#uses=1]
+ %E = add i32 %D, %B ; <i32> [#uses=1]
+ %cnd = call i1 @cond( i32 %E ) ; <i1> [#uses=1]
+ call i1 @cond( i32 %C ) ; <i1>:1 [#uses=0]
+ %IVn = add i32 %IV, 1 ; <i32> [#uses=1]
+ br i1 %cnd, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/uglygep.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/uglygep.ll
new file mode 100644
index 0000000..8af5cf1
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/uglygep.ll
@@ -0,0 +1,66 @@
+; RUN: opt < %s -loop-reduce -S | not grep uglygep
+
+; LSR shouldn't consider %t8 to be an interesting user of %t6, and it
+; should be able to form pretty GEPs.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+define void @Z4() nounwind {
+bb:
+ br label %bb3
+
+bb1: ; preds = %bb3
+ br i1 undef, label %bb10, label %bb2
+
+bb2: ; preds = %bb1
+ %t = add i64 %t4, 1 ; <i64> [#uses=1]
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb
+ %t4 = phi i64 [ %t, %bb2 ], [ 0, %bb ] ; <i64> [#uses=3]
+ br label %bb1
+
+bb10: ; preds = %bb9
+ %t7 = icmp eq i64 %t4, 0 ; <i1> [#uses=1]
+ %t3 = add i64 %t4, 16 ; <i64> [#uses=1]
+ br label %bb14
+
+bb14: ; preds = %bb14, %bb10
+ %t2 = getelementptr inbounds i8* undef, i64 %t4 ; <i8*> [#uses=1]
+ store i8 undef, i8* %t2
+ %t6 = load float** undef
+ %t8 = bitcast float* %t6 to i8* ; <i8*> [#uses=1]
+ %t9 = getelementptr inbounds i8* %t8, i64 %t3 ; <i8*> [#uses=1]
+ store i8 undef, i8* %t9
+ br label %bb14
+}
+
+define fastcc void @TransformLine() nounwind {
+bb:
+ br label %loop0
+
+loop0: ; preds = %loop0, %bb
+ %i0 = phi i32 [ %i0.next, %loop0 ], [ 0, %bb ] ; <i32> [#uses=2]
+ %i0.next = add i32 %i0, 1 ; <i32> [#uses=1]
+ br i1 false, label %loop0, label %bb0
+
+bb0: ; preds = %loop0
+ br label %loop1
+
+loop1: ; preds = %bb5, %bb0
+ %i1 = phi i32 [ 0, %bb0 ], [ %i1.next, %bb5 ] ; <i32> [#uses=4]
+ %t0 = add i32 %i0, %i1 ; <i32> [#uses=1]
+ br i1 false, label %bb2, label %bb6
+
+bb2: ; preds = %loop1
+ br i1 true, label %bb6, label %bb5
+
+bb5: ; preds = %bb2
+ %i1.next = add i32 %i1, 1 ; <i32> [#uses=1]
+ br i1 true, label %bb6, label %loop1
+
+bb6: ; preds = %bb5, %bb2, %loop1
+ %p8 = phi i32 [ %t0, %bb5 ], [ undef, %loop1 ], [ undef, %bb2 ] ; <i32> [#uses=0]
+ %p9 = phi i32 [ undef, %bb5 ], [ %i1, %loop1 ], [ %i1, %bb2 ] ; <i32> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/use_postinc_value_outside_loop.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/use_postinc_value_outside_loop.ll
new file mode 100644
index 0000000..27ee2e0
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/use_postinc_value_outside_loop.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: grep {add i32 %indvar630.ui, 1}
+;
+; Make sure that the use of the IV outside of the loop (the store) uses the
+; post incremented value of the IV, not the preincremented value. This
+; prevents the loop from having to keep the post and pre-incremented value
+; around for the duration of the loop, adding a copy and an extra register
+; to the loop.
+
+declare i1 @pred(i32)
+
+define void @test([700 x i32]* %nbeaux_.0__558, i32* %i_.16574) {
+then.0:
+ br label %no_exit.2
+no_exit.2: ; preds = %no_exit.2, %then.0
+ %indvar630.ui = phi i32 [ 0, %then.0 ], [ %indvar.next631, %no_exit.2 ] ; <i32> [#uses=3]
+ %indvar630 = bitcast i32 %indvar630.ui to i32 ; <i32> [#uses=2]
+ %gep.upgrd.1 = zext i32 %indvar630.ui to i64 ; <i64> [#uses=1]
+ %tmp.38 = getelementptr [700 x i32]* %nbeaux_.0__558, i32 0, i64 %gep.upgrd.1 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp.38
+ %inc.2 = add i32 %indvar630, 2 ; <i32> [#uses=1]
+ %tmp.34 = call i1 @pred( i32 %indvar630 ) ; <i1> [#uses=1]
+ %indvar.next631 = add i32 %indvar630.ui, 1 ; <i32> [#uses=1]
+ br i1 %tmp.34, label %no_exit.2, label %loopexit.2.loopexit
+loopexit.2.loopexit: ; preds = %no_exit.2
+ store i32 %inc.2, i32* %i_.16574
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/var_stride_used_by_compare.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/var_stride_used_by_compare.ll
new file mode 100644
index 0000000..a4137e7
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/var_stride_used_by_compare.ll
@@ -0,0 +1,41 @@
+; Base should not be i*3, it should be i*2.
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: not grep {mul.*%i, 3}
+
+; Indvar should not start at zero:
+; RUN: opt < %s -loop-reduce -S | \
+; RUN: not grep {phi i32 .* 0}
+; END.
+
+; mul uint %i, 3
+
+target datalayout = "e-p:32:32-n32"
+target triple = "i686-apple-darwin8"
+@flags2 = external global [8193 x i8], align 32 ; <[8193 x i8]*> [#uses=1]
+
+define void @foo(i32 %k, i32 %i.s) {
+entry:
+ %i = bitcast i32 %i.s to i32 ; <i32> [#uses=2]
+ %k_addr.012 = shl i32 %i.s, 1 ; <i32> [#uses=1]
+ %tmp14 = icmp sgt i32 %k_addr.012, 8192 ; <i1> [#uses=1]
+ br i1 %tmp14, label %return, label %bb.preheader
+bb.preheader: ; preds = %entry
+ %tmp. = shl i32 %i, 1 ; <i32> [#uses=1]
+ br label %bb
+bb: ; preds = %bb, %bb.preheader
+ %indvar = phi i32 [ %indvar.next, %bb ], [ 0, %bb.preheader ] ; <i32> [#uses=2]
+ %tmp.15 = mul i32 %indvar, %i ; <i32> [#uses=1]
+ %tmp.16 = add i32 %tmp.15, %tmp. ; <i32> [#uses=2]
+ %k_addr.0.0 = bitcast i32 %tmp.16 to i32 ; <i32> [#uses=1]
+ %gep.upgrd.1 = zext i32 %tmp.16 to i64 ; <i64> [#uses=1]
+ %tmp = getelementptr [8193 x i8]* @flags2, i32 0, i64 %gep.upgrd.1 ; <i8*> [#uses=1]
+ store i8 0, i8* %tmp
+ %k_addr.0 = add i32 %k_addr.0.0, %i.s ; <i32> [#uses=1]
+ %tmp.upgrd.2 = icmp sgt i32 %k_addr.0, 8192 ; <i1> [#uses=1]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1]
+ br i1 %tmp.upgrd.2, label %return.loopexit, label %bb
+return.loopexit: ; preds = %bb
+ br label %return
+return: ; preds = %return.loopexit, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopStrengthReduce/variable_stride.ll b/src/LLVM/test/Transforms/LoopStrengthReduce/variable_stride.ll
new file mode 100644
index 0000000..0ba54e3
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopStrengthReduce/variable_stride.ll
@@ -0,0 +1,18 @@
+; Check that variable strides are reduced to adds instead of multiplies.
+; RUN: opt < %s -loop-reduce -S | not grep mul
+
+declare i1 @pred(i32)
+
+define void @test([10000 x i32]* %P, i32 %STRIDE) {
+; <label>:0
+ br label %Loop
+Loop: ; preds = %Loop, %0
+ %INDVAR = phi i32 [ 0, %0 ], [ %INDVAR2, %Loop ] ; <i32> [#uses=2]
+ %Idx = mul i32 %INDVAR, %STRIDE ; <i32> [#uses=1]
+ %cond = call i1 @pred( i32 %Idx ) ; <i1> [#uses=1]
+ %INDVAR2 = add i32 %INDVAR, 1 ; <i32> [#uses=1]
+ br i1 %cond, label %Loop, label %Out
+Out: ; preds = %Loop
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll b/src/LLVM/test/Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll
new file mode 100644
index 0000000..5a17039
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -loop-unroll -disable-output
+
+define i32 @main() {
+entry:
+ br label %no_exit
+no_exit: ; preds = %no_exit, %entry
+ %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %no_exit ] ; <i32> [#uses=1]
+ %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=2]
+ %exitcond = icmp ne i32 %indvar.next, -2147483648 ; <i1> [#uses=1]
+ br i1 %exitcond, label %no_exit, label %loopexit
+loopexit: ; preds = %no_exit
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2005-03-06-BadLoopInfoUpdate.ll b/src/LLVM/test/Transforms/LoopUnroll/2005-03-06-BadLoopInfoUpdate.ll
new file mode 100644
index 0000000..bde57c3
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2005-03-06-BadLoopInfoUpdate.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -loop-unroll -loop-simplify -disable-output
+
+define void @print_board() {
+entry:
+ br label %no_exit.1
+no_exit.1: ; preds = %cond_false.2, %entry
+ br label %no_exit.2
+no_exit.2: ; preds = %no_exit.2, %no_exit.1
+ %indvar1 = phi i32 [ 0, %no_exit.1 ], [ %indvar.next2, %no_exit.2 ] ; <i32> [#uses=1]
+ %indvar.next2 = add i32 %indvar1, 1 ; <i32> [#uses=2]
+ %exitcond3 = icmp ne i32 %indvar.next2, 7 ; <i1> [#uses=1]
+ br i1 %exitcond3, label %no_exit.2, label %loopexit.2
+loopexit.2: ; preds = %no_exit.2
+ br i1 false, label %cond_true.2, label %cond_false.2
+cond_true.2: ; preds = %loopexit.2
+ ret void
+cond_false.2: ; preds = %loopexit.2
+ br i1 false, label %no_exit.1, label %loopexit.1
+loopexit.1: ; preds = %cond_false.2
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2006-08-24-MultiBlockLoop.ll b/src/LLVM/test/Transforms/LoopUnroll/2006-08-24-MultiBlockLoop.ll
new file mode 100644
index 0000000..4a0329d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2006-08-24-MultiBlockLoop.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -loop-unroll -S | grep bb72.2
+
+define void @vorbis_encode_noisebias_setup() {
+entry:
+ br label %cond_true.outer
+cond_true.outer: ; preds = %bb72, %entry
+ %indvar1.ph = phi i32 [ 0, %entry ], [ %indvar.next2, %bb72 ] ; <i32> [#uses=1]
+ br label %bb72
+bb72: ; preds = %cond_true.outer
+ %indvar.next2 = add i32 %indvar1.ph, 1 ; <i32> [#uses=2]
+ %exitcond3 = icmp eq i32 %indvar.next2, 3 ; <i1> [#uses=1]
+ br i1 %exitcond3, label %cond_true138, label %cond_true.outer
+cond_true138: ; preds = %bb72
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2007-04-16-PhiUpdate.ll b/src/LLVM/test/Transforms/LoopUnroll/2007-04-16-PhiUpdate.ll
new file mode 100644
index 0000000..4ded9e6
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2007-04-16-PhiUpdate.ll
@@ -0,0 +1,17 @@
+; PR 1334
+; RUN: opt < %s -loop-unroll -disable-output
+
+define void @sal__math_float_manipulator_7__math__joint_array_dcv_ops__Omultiply__3([6 x float]* %agg.result) {
+entry:
+ %tmp282911 = zext i8 0 to i32 ; <i32> [#uses=1]
+ br label %cond_next
+cond_next: ; preds = %cond_next, %entry
+ %indvar = phi i8 [ 0, %entry ], [ %indvar.next, %cond_next ] ; <i8> [#uses=1]
+ %indvar.next = add i8 %indvar, 1 ; <i8> [#uses=2]
+ %exitcond = icmp eq i8 %indvar.next, 7 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb27, label %cond_next
+bb27: ; preds = %cond_next
+ %tmp282911.lcssa = phi i32 [ %tmp282911, %cond_next ] ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2007-05-05-UnrollMiscomp.ll b/src/LLVM/test/Transforms/LoopUnroll/2007-05-05-UnrollMiscomp.ll
new file mode 100644
index 0000000..70c2733
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2007-05-05-UnrollMiscomp.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -loop-unroll -S | not grep undef
+; PR1385
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-apple-darwin8"
+ %struct.__mpz_struct = type { i32, i32, i32* }
+
+
+define void @Foo(%struct.__mpz_struct* %base) {
+entry:
+ %want = alloca [1 x %struct.__mpz_struct], align 16 ; <[1 x %struct.__mpz_struct]*> [#uses=4]
+ %want1 = getelementptr [1 x %struct.__mpz_struct]* %want, i32 0, i32 0 ; <%struct.__mpz_struct*> [#uses=1]
+ call void @__gmpz_init( %struct.__mpz_struct* %want1 )
+ %want27 = getelementptr [1 x %struct.__mpz_struct]* %want, i32 0, i32 0 ; <%struct.__mpz_struct*> [#uses=1]
+ %want3 = getelementptr [1 x %struct.__mpz_struct]* %want, i32 0, i32 0 ; <%struct.__mpz_struct*> [#uses=1]
+ %want2 = getelementptr [1 x %struct.__mpz_struct]* %want, i32 0, i32 0 ; <%struct.__mpz_struct*> [#uses=2]
+ br label %bb
+
+bb: ; preds = %bb, %entry
+ %i.01.0 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; <i32> [#uses=1]
+ %want23.0 = phi %struct.__mpz_struct* [ %want27, %entry ], [ %want2, %bb ] ; <%struct.__mpz_struct*> [#uses=1]
+ call void @__gmpz_mul( %struct.__mpz_struct* %want23.0, %struct.__mpz_struct* %want3, %struct.__mpz_struct* %base )
+ %indvar.next = add i32 %i.01.0, 1 ; <i32> [#uses=2]
+ %exitcond = icmp ne i32 %indvar.next, 2 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb, label %bb10
+
+bb10: ; preds = %bb
+ %want2.lcssa = phi %struct.__mpz_struct* [ %want2, %bb ] ; <%struct.__mpz_struct*> [#uses=1]
+ call void @__gmpz_clear( %struct.__mpz_struct* %want2.lcssa )
+ ret void
+}
+
+declare void @__gmpz_init(%struct.__mpz_struct*)
+declare void @__gmpz_mul(%struct.__mpz_struct*, %struct.__mpz_struct*, %struct.__mpz_struct*)
+declare void @__gmpz_clear(%struct.__mpz_struct*)
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2007-05-09-UnknownTripCount.ll b/src/LLVM/test/Transforms/LoopUnroll/2007-05-09-UnknownTripCount.ll
new file mode 100644
index 0000000..c5f8c76
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2007-05-09-UnknownTripCount.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -loop-unroll -unroll-count=3 -S | grep bb72.2
+
+define void @foo(i32 %trips) {
+entry:
+ br label %cond_true.outer
+
+cond_true.outer:
+ %indvar1.ph = phi i32 [ 0, %entry ], [ %indvar.next2, %bb72 ]
+ br label %bb72
+
+bb72:
+ %indvar.next2 = add i32 %indvar1.ph, 1
+ %exitcond3 = icmp eq i32 %indvar.next2, %trips
+ br i1 %exitcond3, label %cond_true138, label %cond_true.outer
+
+cond_true138:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2007-11-05-Crash.ll b/src/LLVM/test/Transforms/LoopUnroll/2007-11-05-Crash.ll
new file mode 100644
index 0000000..1711f11
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2007-11-05-Crash.ll
@@ -0,0 +1,295 @@
+; RUN: opt < %s -disable-output -loop-unroll
+; PR1770
+; PR1947
+
+ %struct.cl_engine = type { i32, i16, i32, i8**, i8**, i8*, i8*, i8*, i8*, i8*, i8*, i8* }
+ %struct.cl_limits = type { i32, i32, i32, i32, i16, i64 }
+ %struct.cli_ac_alt = type { i8, i8*, i16, i16, %struct.cli_ac_alt* }
+ %struct.cli_ac_node = type { i8, i8, %struct.cli_ac_patt*, %struct.cli_ac_node**, %struct.cli_ac_node* }
+ %struct.cli_ac_patt = type { i16*, i16*, i16, i16, i8, i32, i32, i8*, i8*, i32, i16, i16, i16, i16, %struct.cli_ac_alt**, i8, i16, %struct.cli_ac_patt*, %struct.cli_ac_patt* }
+ %struct.cli_bm_patt = type { i8*, i32, i8*, i8*, i8, %struct.cli_bm_patt* }
+ %struct.cli_ctx = type { i8**, i64*, %struct.cli_matcher*, %struct.cl_engine*, %struct.cl_limits*, i32, i32, i32, i32, %struct.cli_dconf* }
+ %struct.cli_dconf = type { i32, i32, i32, i32, i32, i32, i32 }
+ %struct.cli_matcher = type { i16, i8, i32*, %struct.cli_bm_patt**, i32*, i32, i8, i8, %struct.cli_ac_node*, %struct.cli_ac_node**, %struct.cli_ac_patt**, i32, i32, i32 }
+
+declare i8* @calloc(i64, i64)
+
+define fastcc i32 @cli_scanpe(i32 %desc, %struct.cli_ctx* %ctx) {
+entry:
+ br i1 false, label %cond_next17, label %cond_true14
+
+cond_true14: ; preds = %entry
+ ret i32 0
+
+cond_next17: ; preds = %entry
+ br i1 false, label %LeafBlock, label %LeafBlock1250
+
+LeafBlock1250: ; preds = %cond_next17
+ ret i32 0
+
+LeafBlock: ; preds = %cond_next17
+ br i1 false, label %cond_next33, label %cond_true30
+
+cond_true30: ; preds = %LeafBlock
+ ret i32 0
+
+cond_next33: ; preds = %LeafBlock
+ br i1 false, label %cond_next90, label %cond_true42
+
+cond_true42: ; preds = %cond_next33
+ ret i32 0
+
+cond_next90: ; preds = %cond_next33
+ br i1 false, label %cond_next100, label %cond_true97
+
+cond_true97: ; preds = %cond_next90
+ ret i32 0
+
+cond_next100: ; preds = %cond_next90
+ br i1 false, label %cond_next109, label %cond_true106
+
+cond_true106: ; preds = %cond_next100
+ ret i32 0
+
+cond_next109: ; preds = %cond_next100
+ br i1 false, label %cond_false, label %cond_true118
+
+cond_true118: ; preds = %cond_next109
+ ret i32 0
+
+cond_false: ; preds = %cond_next109
+ br i1 false, label %NodeBlock1482, label %cond_true126
+
+cond_true126: ; preds = %cond_false
+ ret i32 0
+
+NodeBlock1482: ; preds = %cond_false
+ br i1 false, label %cond_next285, label %NodeBlock1480
+
+NodeBlock1480: ; preds = %NodeBlock1482
+ ret i32 0
+
+cond_next285: ; preds = %NodeBlock1482
+ br i1 false, label %cond_next320, label %cond_true294
+
+cond_true294: ; preds = %cond_next285
+ ret i32 0
+
+cond_next320: ; preds = %cond_next285
+ br i1 false, label %LeafBlock1491, label %LeafBlock1493
+
+LeafBlock1493: ; preds = %cond_next320
+ ret i32 0
+
+LeafBlock1491: ; preds = %cond_next320
+ br i1 false, label %cond_true400, label %cond_true378
+
+cond_true378: ; preds = %LeafBlock1491
+ ret i32 1
+
+cond_true400: ; preds = %LeafBlock1491
+ br i1 false, label %cond_next413, label %cond_true406
+
+cond_true406: ; preds = %cond_true400
+ ret i32 0
+
+cond_next413: ; preds = %cond_true400
+ br i1 false, label %cond_next429, label %cond_true424
+
+cond_true424: ; preds = %cond_next413
+ ret i32 0
+
+cond_next429: ; preds = %cond_next413
+ br i1 false, label %NodeBlock1557, label %NodeBlock1579
+
+NodeBlock1579: ; preds = %cond_next429
+ ret i32 0
+
+NodeBlock1557: ; preds = %cond_next429
+ br i1 false, label %LeafBlock1543, label %NodeBlock1555
+
+NodeBlock1555: ; preds = %NodeBlock1557
+ ret i32 0
+
+LeafBlock1543: ; preds = %NodeBlock1557
+ br i1 false, label %cond_next870, label %cond_next663
+
+cond_next663: ; preds = %LeafBlock1543
+ ret i32 0
+
+cond_next870: ; preds = %LeafBlock1543
+ br i1 false, label %cond_true1012, label %cond_true916
+
+cond_true916: ; preds = %cond_next870
+ ret i32 0
+
+cond_true1012: ; preds = %cond_next870
+ br i1 false, label %cond_next3849, label %cond_true2105
+
+cond_true2105: ; preds = %cond_true1012
+ ret i32 0
+
+cond_next3849: ; preds = %cond_true1012
+ br i1 false, label %cond_next4378, label %bb6559
+
+bb3862: ; preds = %cond_next4385
+ br i1 false, label %cond_false3904, label %cond_true3876
+
+cond_true3876: ; preds = %bb3862
+ ret i32 0
+
+cond_false3904: ; preds = %bb3862
+ br i1 false, label %cond_next4003, label %cond_true3935
+
+cond_true3935: ; preds = %cond_false3904
+ ret i32 0
+
+cond_next4003: ; preds = %cond_false3904
+ br i1 false, label %cond_next5160, label %cond_next4015
+
+cond_next4015: ; preds = %cond_next4003
+ ret i32 0
+
+cond_next4378: ; preds = %cond_next3849
+ br i1 false, label %cond_next4385, label %bb4393
+
+cond_next4385: ; preds = %cond_next4378
+ br i1 false, label %bb3862, label %bb4393
+
+bb4393: ; preds = %cond_next4385, %cond_next4378
+ ret i32 0
+
+cond_next5160: ; preds = %cond_next4003
+ br i1 false, label %bb5188, label %bb6559
+
+bb5188: ; preds = %cond_next5160
+ br i1 false, label %cond_next5285, label %cond_true5210
+
+cond_true5210: ; preds = %bb5188
+ ret i32 0
+
+cond_next5285: ; preds = %bb5188
+ br i1 false, label %cond_true5302, label %cond_true5330
+
+cond_true5302: ; preds = %cond_next5285
+ br i1 false, label %bb7405, label %bb7367
+
+cond_true5330: ; preds = %cond_next5285
+ ret i32 0
+
+bb6559: ; preds = %cond_next5160, %cond_next3849
+ ret i32 0
+
+bb7367: ; preds = %cond_true5302
+ ret i32 0
+
+bb7405: ; preds = %cond_true5302
+ br i1 false, label %cond_next8154, label %cond_true7410
+
+cond_true7410: ; preds = %bb7405
+ ret i32 0
+
+cond_next8154: ; preds = %bb7405
+ br i1 false, label %cond_true8235, label %bb9065
+
+cond_true8235: ; preds = %cond_next8154
+ br i1 false, label %bb8274, label %bb8245
+
+bb8245: ; preds = %cond_true8235
+ ret i32 0
+
+bb8274: ; preds = %cond_true8235
+ br i1 false, label %cond_next8358, label %cond_true8295
+
+cond_true8295: ; preds = %bb8274
+ ret i32 0
+
+cond_next8358: ; preds = %bb8274
+ br i1 false, label %cond_next.i509, label %cond_true8371
+
+cond_true8371: ; preds = %cond_next8358
+ ret i32 -123
+
+cond_next.i509: ; preds = %cond_next8358
+ br i1 false, label %bb36.i, label %bb33.i
+
+bb33.i: ; preds = %cond_next.i509
+ ret i32 0
+
+bb36.i: ; preds = %cond_next.i509
+ br i1 false, label %cond_next54.i, label %cond_true51.i
+
+cond_true51.i: ; preds = %bb36.i
+ ret i32 0
+
+cond_next54.i: ; preds = %bb36.i
+ %tmp10.i.i527 = call i8* @calloc( i64 0, i64 1 ) ; <i8*> [#uses=1]
+ br i1 false, label %cond_next11.i.i, label %bb132.i
+
+bb132.i: ; preds = %cond_next54.i
+ ret i32 0
+
+cond_next11.i.i: ; preds = %cond_next54.i
+ br i1 false, label %bb32.i.i545, label %cond_true1008.critedge.i
+
+bb32.i.i545: ; preds = %cond_next11.i.i
+ br i1 false, label %cond_next349.i, label %cond_true184.i
+
+cond_true184.i: ; preds = %bb32.i.i545
+ ret i32 0
+
+cond_next349.i: ; preds = %bb32.i.i545
+ br i1 false, label %cond_next535.i, label %cond_true1008.critedge1171.i
+
+cond_next535.i: ; preds = %cond_next349.i
+ br i1 false, label %cond_next569.i, label %cond_false574.i
+
+cond_next569.i: ; preds = %cond_next535.i
+ br i1 false, label %cond_next670.i, label %cond_true1008.critedge1185.i
+
+cond_false574.i: ; preds = %cond_next535.i
+ ret i32 0
+
+cond_next670.i: ; preds = %cond_next569.i
+ br i1 false, label %cond_true692.i, label %cond_next862.i
+
+cond_true692.i: ; preds = %cond_next670.i
+ br i1 false, label %cond_false742.i, label %cond_true718.i
+
+cond_true718.i: ; preds = %cond_true692.i
+ ret i32 0
+
+cond_false742.i: ; preds = %cond_true692.i
+ br i1 false, label %cond_true784.i, label %cond_next9079
+
+cond_true784.i: ; preds = %cond_next811.i, %cond_false742.i
+ %indvar1411.i.reg2mem.0 = phi i8 [ %indvar.next1412.i, %cond_next811.i ], [ 0, %cond_false742.i ] ; <i8> [#uses=1]
+ br i1 false, label %cond_true1008.critedge1190.i, label %cond_next811.i
+
+cond_next811.i: ; preds = %cond_true784.i
+ %indvar.next1412.i = add i8 %indvar1411.i.reg2mem.0, 1 ; <i8> [#uses=2]
+ %tmp781.i = icmp eq i8 %indvar.next1412.i, 3 ; <i1> [#uses=1]
+ br i1 %tmp781.i, label %cond_next9079, label %cond_true784.i
+
+cond_next862.i: ; preds = %cond_next670.i
+ ret i32 0
+
+cond_true1008.critedge.i: ; preds = %cond_next11.i.i
+ ret i32 0
+
+cond_true1008.critedge1171.i: ; preds = %cond_next349.i
+ ret i32 0
+
+cond_true1008.critedge1185.i: ; preds = %cond_next569.i
+ ret i32 0
+
+cond_true1008.critedge1190.i: ; preds = %cond_true784.i
+ %tmp621.i532.lcssa610 = phi i8* [ %tmp10.i.i527, %cond_true784.i ] ; <i8*> [#uses=0]
+ ret i32 0
+
+bb9065: ; preds = %cond_next8154
+ ret i32 0
+
+cond_next9079: ; preds = %cond_next811.i, %cond_false742.i
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2011-08-08-PhiUpdate.ll b/src/LLVM/test/Transforms/LoopUnroll/2011-08-08-PhiUpdate.ll
new file mode 100644
index 0000000..cd954c8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2011-08-08-PhiUpdate.ll
@@ -0,0 +1,103 @@
+; RUN: opt < %s -loop-unroll -S -unroll-count=4 | FileCheck %s
+; Test phi update after partial unroll.
+
+declare i1 @check() nounwind
+
+; CHECK: @test
+; CHECK: if.else:
+; CHECK: if.then.loopexit
+; CHECK: %sub5.lcssa = phi i32 [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ], [ %sub{{.*}}, %if.else{{.*}} ]
+; CHECK: if.else.3
+define void @test1(i32 %i, i32 %j) nounwind uwtable ssp {
+entry:
+ %cond1 = call zeroext i1 @check()
+ br i1 %cond1, label %if.then, label %if.else.lr.ph
+
+if.else.lr.ph: ; preds = %entry
+ br label %if.else
+
+if.else: ; preds = %if.else, %if.else.lr.ph
+ %sub = phi i32 [ %i, %if.else.lr.ph ], [ %sub5, %if.else ]
+ %sub5 = sub i32 %sub, %j
+ %cond2 = call zeroext i1 @check()
+ br i1 %cond2, label %if.then, label %if.else
+
+if.then: ; preds = %if.else, %entry
+ %i.tr = phi i32 [ %i, %entry ], [ %sub5, %if.else ]
+ ret void
+
+}
+
+; PR7318: assertion failure after doing a simple loop unroll
+;
+; CHECK: @test2
+; CHECK: bb1.bb2_crit_edge:
+; CHECK: %.lcssa = phi i32 [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ], [ %{{[2468]}}, %bb1{{.*}} ]
+; CHECK: bb1.3:
+define i32 @test2(i32* nocapture %p, i32 %n) nounwind readonly {
+entry:
+ %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb.nph, label %bb2
+
+bb.nph: ; preds = %entry
+ %tmp = zext i32 %n to i64 ; <i64> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb.nph, %bb1
+ %indvar = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i64> [#uses=2]
+ %s.01 = phi i32 [ 0, %bb.nph ], [ %2, %bb1 ] ; <i32> [#uses=1]
+ %scevgep = getelementptr i32* %p, i64 %indvar ; <i32*> [#uses=1]
+ %1 = load i32* %scevgep, align 1 ; <i32> [#uses=1]
+ %2 = add nsw i32 %1, %s.01 ; <i32> [#uses=2]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %indvar.next = add i64 %indvar, 1 ; <i64> [#uses=2]
+ %exitcond = icmp ne i64 %indvar.next, %tmp ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb, label %bb1.bb2_crit_edge
+
+bb1.bb2_crit_edge: ; preds = %bb1
+ %.lcssa = phi i32 [ %2, %bb1 ] ; <i32> [#uses=1]
+ br label %bb2
+
+bb2: ; preds = %bb1.bb2_crit_edge, %entry
+ %s.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ 0, %entry ] ; <i32> [#uses=1]
+ ret i32 %s.0.lcssa
+}
+
+; Check phi update for loop with an early-exit.
+;
+; CHECK: @test3
+; CHECK: return.loopexit:
+; CHECK: %tmp7.i.lcssa = phi i32 [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ], [ %tmp7.i{{.*}}, %land.lhs.true{{.*}} ]
+; CHECK: exit.3:
+define i32 @test3() nounwind uwtable ssp align 2 {
+entry:
+ %cond1 = call zeroext i1 @check()
+ br i1 %cond1, label %return, label %if.end
+
+if.end: ; preds = %entry
+ br label %do.body
+
+do.body: ; preds = %do.cond, %if.end
+ %cond2 = call zeroext i1 @check()
+ br i1 %cond2, label %exit, label %do.cond
+
+exit: ; preds = %do.body
+ %tmp7.i = load i32* undef, align 8
+ br i1 undef, label %do.cond, label %land.lhs.true
+
+land.lhs.true: ; preds = %exit
+ br i1 undef, label %return, label %do.cond
+
+do.cond: ; preds = %land.lhs.true, %exit, %do.body
+ %cond3 = call zeroext i1 @check()
+ br i1 %cond3, label %do.end, label %do.body
+
+do.end: ; preds = %do.cond
+ br label %return
+
+return: ; preds = %do.end, %land.lhs.true, %entry
+ %retval.0 = phi i32 [ 0, %do.end ], [ 0, %entry ], [ %tmp7.i, %land.lhs.true ]
+ ret i32 %retval.0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll b/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll
new file mode 100644
index 0000000..59551d5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll
@@ -0,0 +1,41 @@
+; RUN: opt -S < %s -loop-unroll -unroll-count=4 -enable-iv-rewrite=false | FileCheck %s
+;
+; Test induction variable simplify after loop unrolling. It should
+; expose nice opportunities for GVN.
+;
+; CHECK-NOT: while.body also ensures that loop unrolling (with SCEV)
+; removes unrolled loop exits given that 128 is a multiple of 4.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+
+; PR10534: LoopUnroll not keeping canonical induction variable...
+; CHECK: while.body:
+; CHECK-NOT: while.body.1:
+; CHECK: %shr.1 = lshr i32 %bit_addr.addr.01, 5
+; CHECK: %arrayidx.1 = getelementptr inbounds i32* %bitmap, i32 %shr.1
+; CHECK: %shr.2 = lshr i32 %bit_addr.addr.01, 5
+; CHECK: %arrayidx.2 = getelementptr inbounds i32* %bitmap, i32 %shr.2
+; CHECK: %shr.3 = lshr i32 %bit_addr.addr.01, 5
+; CHECK: %arrayidx.3 = getelementptr inbounds i32* %bitmap, i32 %shr.3
+define void @FlipBit(i32* nocapture %bitmap, i32 %bit_addr, i32 %nbits) nounwind {
+entry:
+ br label %while.body
+
+while.body:
+ %nbits.addr.02 = phi i32 [ 128, %entry ], [ %dec, %while.body ]
+ %bit_addr.addr.01 = phi i32 [ 0, %entry ], [ %inc, %while.body ]
+ %dec = add i32 %nbits.addr.02, -1
+ %shr = lshr i32 %bit_addr.addr.01, 5
+ %rem = and i32 %bit_addr.addr.01, 31
+ %shl = shl i32 1, %rem
+ %arrayidx = getelementptr inbounds i32* %bitmap, i32 %shr
+ %tmp6 = load i32* %arrayidx, align 4
+ %xor = xor i32 %tmp6, %shl
+ store i32 %xor, i32* %arrayidx, align 4
+ %inc = add i32 %bit_addr.addr.01, 1
+ %tobool = icmp eq i32 %dec, 0
+ br i1 %tobool, label %while.end, label %while.body
+
+while.end:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll b/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll
new file mode 100644
index 0000000..c1221f5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll
@@ -0,0 +1,62 @@
+; RUN: opt -S < %s -instcombine -inline -jump-threading -loop-unroll -unroll-count=4 | FileCheck %s
+;
+; This is a test case that required a number of setup passes because
+; it depends on block order.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.6.8"
+
+declare i1 @check() nounwind
+declare i32 @getval() nounwind
+
+; Check that the loop exit merges values from all the iterations. This
+; could be a tad fragile, but it's a good test.
+;
+; CHECK: @foo
+; CHECK: return:
+; CHECK: %retval.0 = phi i32 [ %tmp7.i, %land.lhs.true ], [ 0, %do.cond ], [ %tmp7.i.1, %land.lhs.true.1 ], [ 0, %do.cond.1 ], [ %tmp7.i.2, %land.lhs.true.2 ], [ 0, %do.cond.2 ], [ %tmp7.i.3, %land.lhs.true.3 ], [ 0, %do.cond.3 ]
+; CHECK-NOT: @bar
+; CHECK: bar.exit.3
+define i32 @foo() uwtable ssp align 2 {
+entry:
+ br i1 undef, label %return, label %if.end
+
+if.end: ; preds = %entry
+ %call2 = call i32 @getval()
+ br label %do.body
+
+do.body: ; preds = %do.cond, %if.end
+ %call6 = call i32 @bar()
+ %cmp = icmp ne i32 %call6, 0
+ br i1 %cmp, label %land.lhs.true, label %do.cond
+
+land.lhs.true: ; preds = %do.body
+ %call10 = call i32 @getval()
+ %cmp11 = icmp eq i32 0, %call10
+ br i1 %cmp11, label %return, label %do.cond
+
+do.cond: ; preds = %land.lhs.true, %do.body
+ %cmp18 = icmp sle i32 0, %call2
+ br i1 %cmp18, label %do.body, label %return
+
+return: ; preds = %do.cond, %land.lhs.true, %entry
+ %retval.0 = phi i32 [ 0, %entry ], [ %call6, %land.lhs.true ], [ 0, %do.cond ]
+ ret i32 %retval.0
+}
+
+define linkonce_odr i32 @bar() nounwind uwtable ssp align 2 {
+entry:
+ br i1 undef, label %land.lhs.true, label %cond.end
+
+land.lhs.true: ; preds = %entry
+ %cmp4 = call zeroext i1 @check()
+ br i1 %cmp4, label %cond.true, label %cond.end
+
+cond.true: ; preds = %land.lhs.true
+ %tmp7 = call i32 @getval()
+ br label %cond.end
+
+cond.end: ; preds = %cond.true, %land.lhs.true, %entry
+ %cond = phi i32 [ %tmp7, %cond.true ], [ 0, %land.lhs.true ], [ 0, %entry ]
+ ret i32 %cond
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/2011-10-01-NoopTrunc.ll b/src/LLVM/test/Transforms/LoopUnroll/2011-10-01-NoopTrunc.ll
new file mode 100644
index 0000000..7fb471e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/2011-10-01-NoopTrunc.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -S -loop-unroll -unroll-threshold=150 | FileCheck %s
+;
+; Verify that trunc i64 to i32 is considered free by loop unrolling
+; heuristics when i32 is a native type.
+; This should result in full unrolling this loop with size=7, TC=19.
+; If the trunc were not free we would have 8*19=152 > 150.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+; Check that for.body was unrolled 19 times.
+; CHECK: @test
+; CHECK: %0 = load
+; CHECK: %conv = sext i8 %0 to i32
+; CHECK: %add.1 = add nsw i32 %conv.1, %conv
+; CHECK: %add.18 = add nsw i32 %conv.18, %add.17
+; CHECK: ret i32 %add.18
+define i32 @test(i8* %arr) nounwind uwtable readnone {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+ %sum.02 = phi i32 [ 0, %entry ], [ %add, %for.body ]
+ %arrayidx = getelementptr inbounds i8* %arr, i64 %indvars.iv
+ %0 = load i8* %arrayidx, align 1
+ %conv = sext i8 %0 to i32
+ %add = add nsw i32 %conv, %sum.02
+ %indvars.iv.next = add i64 %indvars.iv, 1
+ %lftr.wideiv1 = trunc i64 %indvars.iv.next to i32
+ %exitcond2 = icmp eq i32 %lftr.wideiv1, 19
+ br i1 %exitcond2, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ %add.lcssa = phi i32 [ %add, %for.body ]
+ ret i32 %add.lcssa
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/basic.ll b/src/LLVM/test/Transforms/LoopUnroll/basic.ll
new file mode 100644
index 0000000..eeb3e9a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/basic.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -loop-unroll -S | FileCheck %s
+
+
+; This should not unroll since the address of the loop header is taken.
+
+; CHECK: @test1
+; CHECK: store i8* blockaddress(@test1, %l1), i8** %P
+; CHECK: l1:
+; CHECK-NEXT: phi i32
+; rdar://8287027
+define i32 @test1(i8** %P) nounwind ssp {
+entry:
+ store i8* blockaddress(@test1, %l1), i8** %P
+ br label %l1
+
+l1: ; preds = %l1, %entry
+ %x.0 = phi i32 [ 0, %entry ], [ %inc, %l1 ]
+ %inc = add nsw i32 %x.0, 1
+ %exitcond = icmp eq i32 %inc, 3
+ br i1 %exitcond, label %l2, label %l1
+
+l2: ; preds = %l1
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/dg.exp b/src/LLVM/test/Transforms/LoopUnroll/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopUnroll/pr10813.ll b/src/LLVM/test/Transforms/LoopUnroll/pr10813.ll
new file mode 100644
index 0000000..7daefc2
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/pr10813.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -loop-unroll -disable-output
+
+define void @"f_fu___REFUf[]REFUf[]Uf"() nounwind {
+allocas:
+ br i1 undef, label %cif_mask_all, label %cif_mixed_test_all
+
+cif_mask_all: ; preds = %allocas
+ unreachable
+
+cif_mixed_test_all: ; preds = %allocas
+ br label %pl_loop.i964
+
+pl_loop.i964: ; preds = %pl_loopend.i973, %cif_mixed_test_all
+ %0 = phi i32 [ %pl_nextlane.i971, %pl_loopend.i973 ], [ 0, %cif_mixed_test_all ]
+ br i1 undef, label %pl_dolane.i970, label %pl_loopend.i973
+
+pl_dolane.i970: ; preds = %pl_loop.i964
+ %storeval.i.i969 = extractelement <4 x i8> <i8 0, i8 1, i8 2, i8 3>, i32 %0
+ store i8 %storeval.i.i969, i8* undef, align 1
+ br label %pl_loopend.i973
+
+pl_loopend.i973: ; preds = %pl_dolane.i970, %pl_loop.i964
+ %pl_nextlane.i971 = add i32 %0, 1
+ %exitcond5 = icmp ne i32 %pl_nextlane.i971, 5
+ br i1 %exitcond5, label %pl_loop.i964, label %__scatter_base_offsets_i8.exit974
+
+__scatter_base_offsets_i8.exit974: ; preds = %pl_loopend.i973
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/scevunroll.ll b/src/LLVM/test/Transforms/LoopUnroll/scevunroll.ll
new file mode 100644
index 0000000..99b3a7d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/scevunroll.ll
@@ -0,0 +1,172 @@
+; RUN: opt < %s -S -indvars -loop-unroll -verify-loop-info | FileCheck %s
+;
+; Unit tests for loop unrolling using ScalarEvolution to compute trip counts.
+;
+; Indvars is run first to generate an "old" SCEV result. Some unit
+; tests may check that SCEV is properly invalidated between passes.
+
+; Completely unroll loops without a canonical IV.
+;
+; CHECK: @sansCanonical
+; CHECK-NOT: phi
+; CHECK-NOT: icmp
+; CHECK: ret
+define i32 @sansCanonical(i32* %base) nounwind {
+entry:
+ br label %while.body
+
+while.body:
+ %iv = phi i64 [ 10, %entry ], [ %iv.next, %while.body ]
+ %sum = phi i32 [ 0, %entry ], [ %sum.next, %while.body ]
+ %iv.next = add i64 %iv, -1
+ %adr = getelementptr inbounds i32* %base, i64 %iv.next
+ %tmp = load i32* %adr, align 8
+ %sum.next = add i32 %sum, %tmp
+ %iv.narrow = trunc i64 %iv.next to i32
+ %cmp.i65 = icmp sgt i32 %iv.narrow, 0
+ br i1 %cmp.i65, label %while.body, label %exit
+
+exit:
+ ret i32 %sum
+}
+
+; SCEV unrolling properly handles loops with multiple exits. In this
+; case, the computed trip count based on a canonical IV is *not* for a
+; latch block. Canonical unrolling incorrectly unrolls it, but SCEV
+; unrolling does not.
+;
+; CHECK: @earlyLoopTest
+; CHECK: tail:
+; CHECK-NOT: br
+; CHECK: br i1 %cmp2, label %loop, label %exit2
+define i64 @earlyLoopTest(i64* %base) nounwind {
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %inc, %tail ]
+ %s = phi i64 [ 0, %entry ], [ %s.next, %tail ]
+ %adr = getelementptr i64* %base, i64 %iv
+ %val = load i64* %adr
+ %s.next = add i64 %s, %val
+ %inc = add i64 %iv, 1
+ %cmp = icmp ne i64 %inc, 4
+ br i1 %cmp, label %tail, label %exit1
+
+tail:
+ %cmp2 = icmp ne i64 %val, 0
+ br i1 %cmp2, label %loop, label %exit2
+
+exit1:
+ ret i64 %s
+
+exit2:
+ ret i64 %s.next
+}
+
+; SCEV properly unrolls multi-exit loops.
+;
+; CHECK: @multiExit
+; CHECK: getelementptr i32* %base, i32 10
+; CHECK-NEXT: load i32*
+; CHECK: br i1 false, label %l2.10, label %exit1
+; CHECK: l2.10:
+; CHECK-NOT: br
+; CHECK: ret i32
+define i32 @multiExit(i32* %base) nounwind {
+entry:
+ br label %l1
+l1:
+ %iv1 = phi i32 [ 0, %entry ], [ %inc1, %l2 ]
+ %iv2 = phi i32 [ 0, %entry ], [ %inc2, %l2 ]
+ %inc1 = add i32 %iv1, 1
+ %inc2 = add i32 %iv2, 1
+ %adr = getelementptr i32* %base, i32 %iv1
+ %val = load i32* %adr
+ %cmp1 = icmp slt i32 %iv1, 5
+ br i1 %cmp1, label %l2, label %exit1
+l2:
+ %cmp2 = icmp slt i32 %iv2, 10
+ br i1 %cmp2, label %l1, label %exit2
+exit1:
+ ret i32 1
+exit2:
+ ret i32 %val
+}
+
+
+; SCEV should not unroll a multi-exit loops unless the latch block has
+; a known trip count, regardless of the early exit trip counts. The
+; LoopUnroll utility uses this assumption to optimize the latch
+; block's branch.
+;
+; CHECK: @multiExit
+; CHECK: l3:
+; CHECK-NOT: br
+; CHECK: br i1 %cmp3, label %l1, label %exit3
+define i32 @multiExitIncomplete(i32* %base) nounwind {
+entry:
+ br label %l1
+l1:
+ %iv1 = phi i32 [ 0, %entry ], [ %inc1, %l3 ]
+ %iv2 = phi i32 [ 0, %entry ], [ %inc2, %l3 ]
+ %inc1 = add i32 %iv1, 1
+ %inc2 = add i32 %iv2, 1
+ %adr = getelementptr i32* %base, i32 %iv1
+ %val = load i32* %adr
+ %cmp1 = icmp slt i32 %iv1, 5
+ br i1 %cmp1, label %l2, label %exit1
+l2:
+ %cmp2 = icmp slt i32 %iv2, 10
+ br i1 %cmp2, label %l3, label %exit2
+l3:
+ %cmp3 = icmp ne i32 %val, 0
+ br i1 %cmp3, label %l1, label %exit3
+
+exit1:
+ ret i32 1
+exit2:
+ ret i32 2
+exit3:
+ ret i32 3
+}
+
+; When loop unroll merges a loop exit with one of its parent loop's
+; exits, SCEV must forget its ExitNotTaken info.
+;
+; CHECK: @nestedUnroll
+; CHECK-NOT: br i1
+; CHECK: for.body87:
+define void @nestedUnroll() nounwind {
+entry:
+ br label %for.inc
+
+for.inc:
+ br i1 false, label %for.inc, label %for.body38.preheader
+
+for.body38.preheader:
+ br label %for.body38
+
+for.body38:
+ %i.113 = phi i32 [ %inc76, %for.inc74 ], [ 0, %for.body38.preheader ]
+ %mul48 = mul nsw i32 %i.113, 6
+ br label %for.body43
+
+for.body43:
+ %j.011 = phi i32 [ 0, %for.body38 ], [ %inc72, %for.body43 ]
+ %add49 = add nsw i32 %j.011, %mul48
+ %sh_prom50 = zext i32 %add49 to i64
+ %inc72 = add nsw i32 %j.011, 1
+ br i1 false, label %for.body43, label %for.inc74
+
+for.inc74:
+ %inc76 = add nsw i32 %i.113, 1
+ br i1 false, label %for.body38, label %for.body87.preheader
+
+for.body87.preheader:
+ br label %for.body87
+
+for.body87:
+ br label %for.body87
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnroll/shifted-tripcount.ll b/src/LLVM/test/Transforms/LoopUnroll/shifted-tripcount.ll
new file mode 100644
index 0000000..a118a46
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/shifted-tripcount.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -loop-unroll -unroll-count=2 -S | FileCheck %s
+
+; LoopUnroll should unroll this loop into one big basic block.
+
+; CHECK: for.body:
+; CHECK: %i.013 = phi i64 [ 0, %entry ], [ %tmp16.1, %for.body ]
+; CHECK: br i1 %exitcond.1, label %for.end, label %for.body
+
+define void @foo(double* nocapture %p, i64 %n) nounwind {
+entry:
+ %mul10 = shl i64 %n, 1 ; <i64> [#uses=2]
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.013 = phi i64 [ %tmp16, %for.body ], [ 0, %entry ] ; <i64> [#uses=2]
+ %arrayidx7 = getelementptr double* %p, i64 %i.013 ; <double*> [#uses=2]
+ %tmp16 = add i64 %i.013, 1 ; <i64> [#uses=3]
+ %arrayidx = getelementptr double* %p, i64 %tmp16 ; <double*> [#uses=1]
+ %tmp4 = load double* %arrayidx ; <double> [#uses=1]
+ %tmp8 = load double* %arrayidx7 ; <double> [#uses=1]
+ %mul9 = fmul double %tmp8, %tmp4 ; <double> [#uses=1]
+ store double %mul9, double* %arrayidx7
+ %exitcond = icmp eq i64 %tmp16, %mul10 ; <i1> [#uses=1]
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnroll/unloop.ll b/src/LLVM/test/Transforms/LoopUnroll/unloop.ll
new file mode 100644
index 0000000..217c8ce
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnroll/unloop.ll
@@ -0,0 +1,429 @@
+; RUN: opt < %s -S -loop-unroll -verify-loop-info | FileCheck %s
+;
+; Unit tests for LoopInfo::updateUnloop.
+
+declare i1 @check() nounwind
+
+; Ensure that tail->inner is removed and rely on verify-loopinfo to
+; check soundness.
+;
+; CHECK: @skiplevelexit
+; CHECK: tail:
+; CHECK-NOT: br
+; CHECK: ret void
+define void @skiplevelexit() nounwind {
+entry:
+ br label %outer
+
+outer:
+ br label %inner
+
+inner:
+ %iv = phi i32 [ 0, %outer ], [ %inc, %tail ]
+ %inc = add i32 %iv, 1
+ %wbucond = call zeroext i1 @check()
+ br i1 %wbucond, label %outer.backedge, label %tail
+
+tail:
+ br i1 false, label %inner, label %exit
+
+outer.backedge:
+ br label %outer
+
+exit:
+ ret void
+}
+
+; Remove the middle loop of a triply nested loop tree.
+; Ensure that only the middle loop is removed and rely on verify-loopinfo to
+; check soundness.
+;
+; CHECK: @unloopNested
+; Outer loop control.
+; CHECK: while.body:
+; CHECK: br i1 %cmp3, label %if.then, label %if.end
+; Inner loop control.
+; CHECK: while.end14.i:
+; CHECK: br i1 %call15.i, label %if.end.i, label %exit
+; Middle loop control should no longer reach %while.cond.
+; Now it is the outer loop backedge.
+; CHECK: exit:
+; CHECK: br label %while.cond.outer
+define void @unloopNested() {
+entry:
+ br label %while.cond.outer
+
+while.cond.outer:
+ br label %while.cond
+
+while.cond:
+ %cmp = call zeroext i1 @check()
+ br i1 %cmp, label %while.body, label %while.end
+
+while.body:
+ %cmp3 = call zeroext i1 @check()
+ br i1 %cmp3, label %if.then, label %if.end
+
+if.then:
+ br label %return
+
+if.end:
+ %cmp.i48 = call zeroext i1 @check()
+ br i1 %cmp.i48, label %if.then.i, label %if.else20.i
+
+if.then.i:
+ %cmp8.i = call zeroext i1 @check()
+ br i1 %cmp8.i, label %merge, label %if.else.i
+
+if.else.i:
+ br label %merge
+
+if.else20.i:
+ %cmp25.i = call zeroext i1 @check()
+ br i1 %cmp25.i, label %merge, label %if.else28.i
+
+if.else28.i:
+ br label %merge
+
+merge:
+ br label %while.cond2.i
+
+while.cond2.i:
+ %cmp.i = call zeroext i1 @check()
+ br i1 %cmp.i, label %while.cond2.backedge.i, label %while.end.i
+
+while.cond2.backedge.i:
+ br label %while.cond2.i
+
+while.end.i:
+ %cmp1114.i = call zeroext i1 @check()
+ br i1 %cmp1114.i, label %while.body12.lr.ph.i, label %while.end14.i
+
+while.body12.lr.ph.i:
+ br label %while.end14.i
+
+while.end14.i:
+ %call15.i = call zeroext i1 @check()
+ br i1 %call15.i, label %if.end.i, label %exit
+
+if.end.i:
+ br label %while.cond2.backedge.i
+
+exit:
+ br i1 false, label %while.cond, label %if.else
+
+if.else:
+ br label %while.cond.outer
+
+while.end:
+ br label %return
+
+return:
+ ret void
+}
+
+; Remove the middle loop of a deeply nested loop tree.
+; Ensure that only the middle loop is removed and rely on verify-loopinfo to
+; check soundness.
+;
+; CHECK: @unloopDeepNested
+; Inner-inner loop control.
+; CHECK: while.cond.us.i:
+; CHECK: br i1 %cmp.us.i, label %next_data.exit, label %while.body.us.i
+; CHECK: if.then.us.i:
+; CHECK: br label %while.cond.us.i
+; Inner loop tail.
+; CHECK: if.else.i:
+; CHECK: br label %while.cond.outer.i
+; Middle loop control (removed).
+; CHECK: valid_data.exit:
+; CHECK-NOT: br
+; CHECK: %cmp = call zeroext i1 @check()
+; Outer loop control.
+; CHECK: copy_data.exit:
+; CHECK: br i1 %cmp38, label %if.then39, label %while.cond.outer
+; Outer-outer loop tail.
+; CHECK: while.cond.outer.outer.backedge:
+; CHECK: br label %while.cond.outer.outer
+define void @unloopDeepNested() nounwind {
+for.cond8.preheader.i:
+ %cmp113.i = call zeroext i1 @check()
+ br i1 %cmp113.i, label %make_data.exit, label %for.body13.lr.ph.i
+
+for.body13.lr.ph.i:
+ br label %make_data.exit
+
+make_data.exit:
+ br label %while.cond.outer.outer
+
+while.cond.outer.outer:
+ br label %while.cond.outer
+
+while.cond.outer:
+ br label %while.cond
+
+while.cond:
+ br label %while.cond.outer.i
+
+while.cond.outer.i:
+ %tmp192.ph.i = call zeroext i1 @check()
+ br i1 %tmp192.ph.i, label %while.cond.outer.split.us.i, label %while.body.loopexit
+
+while.cond.outer.split.us.i:
+ br label %while.cond.us.i
+
+while.cond.us.i:
+ %cmp.us.i = call zeroext i1 @check()
+ br i1 %cmp.us.i, label %next_data.exit, label %while.body.us.i
+
+while.body.us.i:
+ %cmp7.us.i = call zeroext i1 @check()
+ br i1 %cmp7.us.i, label %if.then.us.i, label %if.else.i
+
+if.then.us.i:
+ br label %while.cond.us.i
+
+if.else.i:
+ br label %while.cond.outer.i
+
+next_data.exit:
+ %tmp192.ph.i.lcssa28 = call zeroext i1 @check()
+ br i1 %tmp192.ph.i.lcssa28, label %while.end, label %while.body
+
+while.body.loopexit:
+ br label %while.body
+
+while.body:
+ br label %while.cond.i
+
+while.cond.i:
+ %cmp.i = call zeroext i1 @check()
+ br i1 %cmp.i, label %valid_data.exit, label %while.body.i
+
+while.body.i:
+ %cmp7.i = call zeroext i1 @check()
+ br i1 %cmp7.i, label %valid_data.exit, label %if.end.i
+
+if.end.i:
+ br label %while.cond.i
+
+valid_data.exit:
+ br i1 true, label %if.then, label %while.cond
+
+if.then:
+ %cmp = call zeroext i1 @check()
+ br i1 %cmp, label %if.then12, label %if.end
+
+if.then12:
+ br label %if.end
+
+if.end:
+ %tobool3.i = call zeroext i1 @check()
+ br i1 %tobool3.i, label %copy_data.exit, label %while.body.lr.ph.i
+
+while.body.lr.ph.i:
+ br label %copy_data.exit
+
+copy_data.exit:
+ %cmp38 = call zeroext i1 @check()
+ br i1 %cmp38, label %if.then39, label %while.cond.outer
+
+if.then39:
+ %cmp5.i = call zeroext i1 @check()
+ br i1 %cmp5.i, label %while.cond.outer.outer.backedge, label %for.cond8.preheader.i8.thread
+
+for.cond8.preheader.i8.thread:
+ br label %while.cond.outer.outer.backedge
+
+while.cond.outer.outer.backedge:
+ br label %while.cond.outer.outer
+
+while.end:
+ ret void
+}
+
+; Remove a nested loop with irreducible control flow.
+; Ensure that only the middle loop is removed and rely on verify-loopinfo to
+; check soundness.
+;
+; CHECK: @unloopIrreducible
+; Irreducible loop.
+; CHECK: for.inc117:
+; CHECK: br label %for.cond103t
+; Nested loop (removed).
+; CHECK: for.inc159:
+; CHECK: br label %for.inc163
+define void @unloopIrreducible() nounwind {
+
+entry:
+ br label %for.body
+
+for.body:
+ %cmp2113 = call zeroext i1 @check()
+ br i1 %cmp2113, label %for.body22.lr.ph, label %for.inc163
+
+for.body22.lr.ph:
+ br label %for.body22
+
+for.body22:
+ br label %for.body33
+
+for.body33:
+ br label %for.end
+
+for.end:
+ %cmp424 = call zeroext i1 @check()
+ br i1 %cmp424, label %for.body43.lr.ph, label %for.end93
+
+for.body43.lr.ph:
+ br label %for.end93
+
+for.end93:
+ %cmp96 = call zeroext i1 @check()
+ br i1 %cmp96, label %if.then97, label %for.cond103
+
+if.then97:
+ br label %for.cond103t
+
+for.cond103t:
+ br label %for.cond103
+
+for.cond103:
+ %cmp105 = call zeroext i1 @check()
+ br i1 %cmp105, label %for.body106, label %for.end120
+
+for.body106:
+ %cmp108 = call zeroext i1 @check()
+ br i1 %cmp108, label %if.then109, label %for.inc117
+
+if.then109:
+ br label %for.inc117
+
+for.inc117:
+ br label %for.cond103t
+
+for.end120:
+ br label %for.inc159
+
+for.inc159:
+ br i1 false, label %for.body22, label %for.cond15.for.inc163_crit_edge
+
+for.cond15.for.inc163_crit_edge:
+ br label %for.inc163
+
+for.inc163:
+ %cmp12 = call zeroext i1 @check()
+ br i1 %cmp12, label %for.body, label %for.end166
+
+for.end166:
+ ret void
+
+}
+
+; Remove a loop whose exit branches into a sibling loop.
+; Ensure that only the loop is removed and rely on verify-loopinfo to
+; check soundness.
+;
+; CHECK: @unloopCriticalEdge
+; CHECK: while.cond.outer.i.loopexit.split:
+; CHECK: br label %while.body
+; CHECK: while.body:
+; CHECK: br label %for.end78
+define void @unloopCriticalEdge() nounwind {
+entry:
+ br label %for.cond31
+
+for.cond31:
+ br i1 undef, label %for.body35, label %for.end94
+
+for.body35:
+ br label %while.cond.i.preheader
+
+while.cond.i.preheader:
+ br i1 undef, label %while.cond.i.preheader.split, label %while.cond.outer.i.loopexit.split
+
+while.cond.i.preheader.split:
+ br label %while.cond.i
+
+while.cond.i:
+ br i1 true, label %while.cond.i, label %while.cond.outer.i.loopexit
+
+while.cond.outer.i.loopexit:
+ br label %while.cond.outer.i.loopexit.split
+
+while.cond.outer.i.loopexit.split:
+ br i1 false, label %while.cond.i.preheader, label %Func2.exit
+
+Func2.exit:
+ br label %while.body
+
+while.body:
+ br i1 false, label %while.body, label %while.end
+
+while.end:
+ br label %for.end78
+
+for.end78:
+ br i1 undef, label %Proc2.exit, label %for.cond.i.preheader
+
+for.cond.i.preheader:
+ br label %for.cond.i
+
+for.cond.i:
+ br label %for.cond.i
+
+Proc2.exit:
+ br label %for.cond31
+
+for.end94:
+ ret void
+}
+
+; Test UnloopUpdater::removeBlocksFromAncestors.
+;
+; Check that the loop backedge is removed from the middle loop 1699,
+; but not the inner loop 1676.
+; CHECK: while.body1694:
+; CHECK: br label %while.cond1676
+; CHECK: while.end1699:
+; CHECK: br label %sw.default1711
+define void @removeSubloopBlocks() nounwind {
+entry:
+ br label %tryagain.outer
+
+tryagain.outer: ; preds = %sw.bb304, %entry
+ br label %tryagain
+
+tryagain: ; preds = %while.end1699, %tryagain.outer
+ br i1 undef, label %sw.bb1669, label %sw.bb304
+
+sw.bb304: ; preds = %tryagain
+ br i1 undef, label %return, label %tryagain.outer
+
+sw.bb1669: ; preds = %tryagain
+ br i1 undef, label %sw.default1711, label %while.cond1676
+
+while.cond1676: ; preds = %while.body1694, %sw.bb1669
+ br i1 undef, label %while.end1699, label %while.body1694
+
+while.body1694: ; preds = %while.cond1676
+ br label %while.cond1676
+
+while.end1699: ; preds = %while.cond1676
+ br i1 false, label %tryagain, label %sw.default1711
+
+sw.default1711: ; preds = %while.end1699, %sw.bb1669, %tryagain
+ br label %defchar
+
+defchar: ; preds = %sw.default1711, %sw.bb376
+ br i1 undef, label %if.end2413, label %if.then2368
+
+if.then2368: ; preds = %defchar
+ unreachable
+
+if.end2413: ; preds = %defchar
+ unreachable
+
+return: ; preds = %sw.bb304
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2006-06-13-SingleEntryPHI.ll b/src/LLVM/test/Transforms/LoopUnswitch/2006-06-13-SingleEntryPHI.ll
new file mode 100644
index 0000000..3d16e8f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2006-06-13-SingleEntryPHI.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+
+ %struct.BLEND_MAP = type { i16, i16, i16, i32, %struct.BLEND_MAP_ENTRY* }
+ %struct.BLEND_MAP_ENTRY = type { float, i8, { [5 x float], [4 x i8] } }
+ %struct.TPATTERN = type { i16, i16, i16, i32, float, float, float, %struct.WARP*, %struct.TPATTERN*, %struct.BLEND_MAP*, { %struct.anon, [4 x i8] } }
+ %struct.TURB = type { i16, %struct.WARP*, [3 x double], i32, float, float }
+ %struct.WARP = type { i16, %struct.WARP* }
+ %struct.anon = type { float, [3 x double] }
+
+define void @Parse_Pattern() {
+entry:
+ br label %bb1096.outer20
+bb671: ; preds = %cond_true1099
+ br label %bb1096.outer23
+bb1096.outer20.loopexit: ; preds = %cond_true1099
+ %Local_Turb.0.ph24.lcssa = phi %struct.TURB* [ %Local_Turb.0.ph24, %cond_true1099 ] ; <%struct.TURB*> [#uses=1]
+ br label %bb1096.outer20
+bb1096.outer20: ; preds = %bb1096.outer20.loopexit, %entry
+ %Local_Turb.0.ph22 = phi %struct.TURB* [ undef, %entry ], [ %Local_Turb.0.ph24.lcssa, %bb1096.outer20.loopexit ] ; <%struct.TURB*> [#uses=1]
+ %tmp1098 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br label %bb1096.outer23
+bb1096.outer23: ; preds = %bb1096.outer20, %bb671
+ %Local_Turb.0.ph24 = phi %struct.TURB* [ %Local_Turb.0.ph22, %bb1096.outer20 ], [ null, %bb671 ] ; <%struct.TURB*> [#uses=2]
+ br label %bb1096
+bb1096: ; preds = %cond_true1099, %bb1096.outer23
+ br i1 %tmp1098, label %cond_true1099, label %bb1102
+cond_true1099: ; preds = %bb1096
+ switch i32 0, label %bb1096.outer20.loopexit [
+ i32 161, label %bb671
+ i32 359, label %bb1096
+ ]
+bb1102: ; preds = %bb1096
+ %Local_Turb.0.ph24.lcssa1 = phi %struct.TURB* [ %Local_Turb.0.ph24, %bb1096 ] ; <%struct.TURB*> [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2006-06-27-DeadSwitchCase.ll b/src/LLVM/test/Transforms/LoopUnswitch/2006-06-27-DeadSwitchCase.ll
new file mode 100644
index 0000000..a9b0356
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2006-06-27-DeadSwitchCase.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+
+define void @init_caller_save() {
+entry:
+ br label %cond_true78
+cond_next20: ; preds = %cond_true64
+ br label %bb31
+bb31: ; preds = %cond_true64, %cond_true64, %cond_next20
+ %iftmp.29.1 = phi i32 [ 0, %cond_next20 ], [ 0, %cond_true64 ], [ 0, %cond_true64 ] ; <i32> [#uses=0]
+ br label %bb54
+bb54: ; preds = %cond_true78, %bb31
+ br i1 false, label %bb75, label %cond_true64
+cond_true64: ; preds = %bb54
+ switch i32 %i.0.0, label %cond_next20 [
+ i32 17, label %bb31
+ i32 18, label %bb31
+ ]
+bb75: ; preds = %bb54
+ %tmp74.0 = add i32 %i.0.0, 1 ; <i32> [#uses=1]
+ br label %cond_true78
+cond_true78: ; preds = %bb75, %entry
+ %i.0.0 = phi i32 [ 0, %entry ], [ %tmp74.0, %bb75 ] ; <i32> [#uses=2]
+ br label %bb54
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-Unreachable.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-Unreachable.ll
new file mode 100644
index 0000000..aa8e1da
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-Unreachable.ll
@@ -0,0 +1,28 @@
+; PR1333
+; RUN: opt < %s -loop-unswitch -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-pc-linux-gnu"
+ %struct.ada__streams__root_stream_type = type { %struct.ada__tags__dispatch_table* }
+ %struct.ada__tags__dispatch_table = type { [1 x i8*] }
+ %struct.quotes__T173s = type { i8, %struct.quotes__T173s__T174s, [2 x [1 x double]], [2 x i16], i64, i8 }
+ %struct.quotes__T173s__T174s = type { i8, i8, i8, i16, i16, [2 x [1 x double]] }
+
+define void @quotes__write_quote() {
+entry:
+ %tmp606.i = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br label %bb
+bb: ; preds = %cond_next73, %bb, %entry
+ br i1 false, label %bb51, label %bb
+bb51: ; preds = %cond_next73, %bb
+ br i1 %tmp606.i, label %quotes__bid_ask_depth_offset_matrices__get_price.exit, label %cond_true.i
+cond_true.i: ; preds = %bb51
+ unreachable
+quotes__bid_ask_depth_offset_matrices__get_price.exit: ; preds = %bb51
+ br i1 false, label %cond_next73, label %cond_true72
+cond_true72: ; preds = %quotes__bid_ask_depth_offset_matrices__get_price.exit
+ unreachable
+cond_next73: ; preds = %quotes__bid_ask_depth_offset_matrices__get_price.exit
+ br i1 false, label %bb, label %bb51
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-tl.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-tl.ll
new file mode 100644
index 0000000..9e1af94
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-05-09-tl.ll
@@ -0,0 +1,95 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+; PR1333
+
+define void @pp_cxx_expression() {
+entry:
+ %tmp6 = lshr i32 0, 24 ; <i32> [#uses=1]
+ br label %tailrecurse
+
+tailrecurse: ; preds = %tailrecurse, %tailrecurse, %entry
+ switch i32 %tmp6, label %bb96 [
+ i32 24, label %bb10
+ i32 25, label %bb10
+ i32 28, label %bb10
+ i32 29, label %bb48
+ i32 31, label %bb48
+ i32 32, label %bb48
+ i32 33, label %bb48
+ i32 34, label %bb48
+ i32 36, label %bb15
+ i32 51, label %bb89
+ i32 52, label %bb89
+ i32 54, label %bb83
+ i32 57, label %bb59
+ i32 63, label %bb80
+ i32 64, label %bb80
+ i32 68, label %bb80
+ i32 169, label %bb75
+ i32 170, label %bb19
+ i32 171, label %bb63
+ i32 172, label %bb63
+ i32 173, label %bb67
+ i32 174, label %bb67
+ i32 175, label %bb19
+ i32 176, label %bb75
+ i32 178, label %bb59
+ i32 179, label %bb89
+ i32 180, label %bb59
+ i32 182, label %bb48
+ i32 183, label %bb48
+ i32 184, label %bb48
+ i32 185, label %bb48
+ i32 186, label %bb48
+ i32 195, label %bb48
+ i32 196, label %bb59
+ i32 197, label %bb89
+ i32 198, label %bb70
+ i32 199, label %bb59
+ i32 200, label %bb59
+ i32 201, label %bb59
+ i32 202, label %bb59
+ i32 203, label %bb75
+ i32 204, label %bb59
+ i32 205, label %tailrecurse
+ i32 210, label %tailrecurse
+ ]
+
+bb10: ; preds = %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb15: ; preds = %tailrecurse
+ ret void
+
+bb19: ; preds = %tailrecurse, %tailrecurse
+ ret void
+
+bb48: ; preds = %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb59: ; preds = %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb63: ; preds = %tailrecurse, %tailrecurse
+ ret void
+
+bb67: ; preds = %tailrecurse, %tailrecurse
+ ret void
+
+bb70: ; preds = %tailrecurse
+ ret void
+
+bb75: ; preds = %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb80: ; preds = %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb83: ; preds = %tailrecurse
+ ret void
+
+bb89: ; preds = %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse
+ ret void
+
+bb96: ; preds = %tailrecurse
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-07-12-ExitDomInfo.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-12-ExitDomInfo.ll
new file mode 100644
index 0000000..bf5a61b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-12-ExitDomInfo.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -loop-unswitch -instcombine -disable-output
+
+@str3 = external constant [3 x i8] ; <[3 x i8]*> [#uses=1]
+
+define i32 @stringSearch_Clib(i32 %count) {
+entry:
+ %ttmp25 = icmp sgt i32 %count, 0 ; <i1> [#uses=1]
+ br i1 %ttmp25, label %bb36.preheader, label %bb44
+
+bb36.preheader: ; preds = %entry
+ %ttmp33 = icmp slt i32 0, 250 ; <i1> [#uses=1]
+ br label %bb36.outer
+
+bb36.outer: ; preds = %bb41, %bb36.preheader
+ br i1 %ttmp33, label %bb.nph, label %bb41
+
+bb.nph: ; preds = %bb36.outer
+ %ttmp8 = icmp eq i8* null, null ; <i1> [#uses=1]
+ %ttmp6 = icmp eq i8* null, null ; <i1> [#uses=1]
+ %tmp31 = call i32 @strcspn( i8* null, i8* getelementptr ([3 x i8]* @str3, i64 0, i64 0) ) ; <i32> [#uses=1]
+ br i1 %ttmp8, label %cond_next, label %cond_true
+
+cond_true: ; preds = %bb.nph
+ ret i32 0
+
+cond_next: ; preds = %bb.nph
+ br i1 %ttmp6, label %cond_next28, label %cond_true20
+
+cond_true20: ; preds = %cond_next
+ ret i32 0
+
+cond_next28: ; preds = %cond_next
+ %tmp33 = add i32 %tmp31, 0 ; <i32> [#uses=1]
+ br label %bb41
+
+bb41: ; preds = %cond_next28, %bb36.outer
+ %c.2.lcssa = phi i32 [ 0, %bb36.outer ], [ %tmp33, %cond_next28 ] ; <i32> [#uses=1]
+ br i1 false, label %bb36.outer, label %bb44
+
+bb44: ; preds = %bb41, %entry
+ %c.01.1 = phi i32 [ 0, %entry ], [ %c.2.lcssa, %bb41 ] ; <i32> [#uses=1]
+ ret i32 %c.01.1
+}
+
+declare i32 @strcspn(i8*, i8*)
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-07-13-DomInfo.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-13-DomInfo.ll
new file mode 100644
index 0000000..5ae335b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-13-DomInfo.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %tmp1785365 = icmp ult i32 0, 100 ; <i1> [#uses=1]
+ br label %bb
+
+bb: ; preds = %cond_true, %entry
+ br i1 false, label %cond_true, label %cond_next
+
+cond_true: ; preds = %bb
+ br i1 %tmp1785365, label %bb, label %bb1788
+
+cond_next: ; preds = %bb
+ %iftmp.1.0 = select i1 false, i32 0, i32 0 ; <i32> [#uses=1]
+ br i1 false, label %cond_true47, label %cond_next74
+
+cond_true47: ; preds = %cond_next
+ %tmp53 = urem i32 %iftmp.1.0, 0 ; <i32> [#uses=0]
+ ret i32 0
+
+cond_next74: ; preds = %cond_next
+ ret i32 0
+
+bb1788: ; preds = %cond_true
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-07-18-DomInfo.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-18-DomInfo.ll
new file mode 100644
index 0000000..dfca154
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-07-18-DomInfo.ll
@@ -0,0 +1,66 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+; PR1559
+
+target triple = "i686-pc-linux-gnu"
+ %struct.re_pattern_buffer = type { i8*, i32, i32, i32, i8*, i8*, i32, i8 }
+
+define fastcc i32 @byte_regex_compile(i8* %pattern, i32 %size, i32 %syntax, %struct.re_pattern_buffer* %bufp) {
+entry:
+ br i1 false, label %bb147, label %cond_next123
+
+cond_next123: ; preds = %entry
+ ret i32 0
+
+bb147: ; preds = %entry
+ switch i32 0, label %normal_char [
+ i32 91, label %bb1734
+ i32 92, label %bb5700
+ ]
+
+bb1734: ; preds = %bb147
+ br label %bb1855.outer.outer
+
+cond_true1831: ; preds = %bb1855.outer
+ br i1 %tmp1837, label %cond_next1844, label %cond_true1840
+
+cond_true1840: ; preds = %cond_true1831
+ ret i32 0
+
+cond_next1844: ; preds = %cond_true1831
+ br i1 false, label %bb1855.outer, label %cond_true1849
+
+cond_true1849: ; preds = %cond_next1844
+ br label %bb1855.outer.outer
+
+bb1855.outer.outer: ; preds = %cond_true1849, %bb1734
+ %b.10.ph.ph = phi i8* [ null, %cond_true1849 ], [ null, %bb1734 ] ; <i8*> [#uses=1]
+ br label %bb1855.outer
+
+bb1855.outer: ; preds = %bb1855.outer.outer, %cond_next1844
+ %b.10.ph = phi i8* [ null, %cond_next1844 ], [ %b.10.ph.ph, %bb1855.outer.outer ] ; <i8*> [#uses=1]
+ %tmp1837 = icmp eq i8* null, null ; <i1> [#uses=2]
+ br i1 false, label %cond_true1831, label %cond_next1915
+
+cond_next1915: ; preds = %cond_next1961, %bb1855.outer
+ store i8* null, i8** null
+ br i1 %tmp1837, label %cond_next1929, label %cond_true1923
+
+cond_true1923: ; preds = %cond_next1915
+ ret i32 0
+
+cond_next1929: ; preds = %cond_next1915
+ br i1 false, label %cond_next1961, label %cond_next2009
+
+cond_next1961: ; preds = %cond_next1929
+ %tmp1992 = getelementptr i8* %b.10.ph, i32 0 ; <i8*> [#uses=0]
+ br label %cond_next1915
+
+cond_next2009: ; preds = %cond_next1929
+ ret i32 0
+
+bb5700: ; preds = %bb147
+ ret i32 0
+
+normal_char: ; preds = %bb147
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-Dom.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-Dom.ll
new file mode 100644
index 0000000..fc92579
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-Dom.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -licm -loop-unswitch -disable-output
+; PR 1589
+
+ %struct.QBasicAtomic = type { i32 }
+
+define void @_ZNK5QDate9addMonthsEi(%struct.QBasicAtomic* sret %agg.result, %struct.QBasicAtomic* %this, i32 %nmonths) {
+entry:
+ br label %cond_true90
+
+bb16: ; preds = %cond_true90
+ br i1 false, label %bb93, label %cond_true90
+
+bb45: ; preds = %cond_true90
+ br i1 false, label %bb53, label %bb58
+
+bb53: ; preds = %bb45
+ br i1 false, label %bb93, label %cond_true90
+
+bb58: ; preds = %bb45
+ store i32 0, i32* null, align 4
+ br i1 false, label %cond_true90, label %bb93
+
+cond_true90: ; preds = %bb58, %bb53, %bb16, %entry
+ %nmonths_addr.016.1 = phi i32 [ %nmonths, %entry ], [ 0, %bb16 ], [ 0, %bb53 ], [ %nmonths_addr.016.1, %bb58 ] ; <i32> [#uses=2]
+ %tmp14 = icmp slt i32 %nmonths_addr.016.1, -11 ; <i1> [#uses=1]
+ br i1 %tmp14, label %bb16, label %bb45
+
+bb93: ; preds = %bb58, %bb53, %bb16
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-LCSSA.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-LCSSA.ll
new file mode 100644
index 0000000..f83acaa
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-08-01-LCSSA.ll
@@ -0,0 +1,55 @@
+; RUN: opt < %s -loop-unswitch -instcombine -disable-output
+ %struct.ClassDef = type { %struct.QByteArray, %struct.QByteArray, %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", i8, i8, %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", %"struct.QList<ArgumentDef>", %"struct.QMap<QByteArray,QByteArray>", %"struct.QList<ArgumentDef>", %"struct.QMap<QByteArray,QByteArray>", i32, i32 }
+ %struct.FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct.FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i32, i32, [40 x i8] }
+ %struct.Generator = type { %struct.FILE*, %struct.ClassDef*, %"struct.QList<ArgumentDef>", %struct.QByteArray, %"struct.QList<ArgumentDef>" }
+ %struct.QBasicAtomic = type { i32 }
+ %struct.QByteArray = type { %"struct.QByteArray::Data"* }
+ %"struct.QByteArray::Data" = type { %struct.QBasicAtomic, i32, i32, i8*, [1 x i8] }
+ %"struct.QList<ArgumentDef>" = type { %"struct.QList<ArgumentDef>::._19" }
+ %"struct.QList<ArgumentDef>::._19" = type { %struct.QListData }
+ %struct.QListData = type { %"struct.QListData::Data"* }
+ %"struct.QListData::Data" = type { %struct.QBasicAtomic, i32, i32, i32, i8, [1 x i8*] }
+ %"struct.QMap<QByteArray,QByteArray>" = type { %"struct.QMap<QByteArray,QByteArray>::._56" }
+ %"struct.QMap<QByteArray,QByteArray>::._56" = type { %struct.QMapData* }
+ %struct.QMapData = type { %struct.QMapData*, [12 x %struct.QMapData*], %struct.QBasicAtomic, i32, i32, i32, i8 }
+ %struct._IO_marker = type { %struct._IO_marker*, %struct.FILE*, i32 }
+@.str9 = external constant [1 x i8] ; <[1 x i8]*> [#uses=1]
+
+declare i32 @strcmp(i8*, i8*)
+
+define i32 @_ZN9Generator6strregEPKc(%struct.Generator* %this, i8* %s) {
+entry:
+ %s_addr.0 = select i1 false, i8* getelementptr ([1 x i8]* @.str9, i32 0, i32 0), i8* %s ; <i8*> [#uses=2]
+ %tmp122 = icmp eq i8* %s_addr.0, null ; <i1> [#uses=1]
+ br label %bb184
+
+bb55: ; preds = %bb184
+ ret i32 0
+
+bb88: ; preds = %bb184
+ br i1 %tmp122, label %bb154, label %bb128
+
+bb128: ; preds = %bb88
+ %tmp138 = call i32 @strcmp( i8* null, i8* %s_addr.0 ) ; <i32> [#uses=1]
+ %iftmp.37.0.in4 = icmp eq i32 %tmp138, 0 ; <i1> [#uses=1]
+ br i1 %iftmp.37.0.in4, label %bb250, label %bb166
+
+bb154: ; preds = %bb88
+ br i1 false, label %bb250, label %bb166
+
+bb166: ; preds = %bb154, %bb128
+ %tmp175 = add i32 %idx.0, 1 ; <i32> [#uses=1]
+ %tmp177 = add i32 %tmp175, 0 ; <i32> [#uses=1]
+ %tmp181 = add i32 %tmp177, 0 ; <i32> [#uses=1]
+ %tmp183 = add i32 %i33.0, 1 ; <i32> [#uses=1]
+ br label %bb184
+
+bb184: ; preds = %bb166, %entry
+ %i33.0 = phi i32 [ 0, %entry ], [ %tmp183, %bb166 ] ; <i32> [#uses=2]
+ %idx.0 = phi i32 [ 0, %entry ], [ %tmp181, %bb166 ] ; <i32> [#uses=2]
+ %tmp49 = icmp slt i32 %i33.0, 0 ; <i1> [#uses=1]
+ br i1 %tmp49, label %bb88, label %bb55
+
+bb250: ; preds = %bb154, %bb128
+ ret i32 %idx.0
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2007-10-04-DomFrontier.ll b/src/LLVM/test/Transforms/LoopUnswitch/2007-10-04-DomFrontier.ll
new file mode 100644
index 0000000..efbb761
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2007-10-04-DomFrontier.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -licm -loop-unroll -disable-output
+
+@resonant = external global i32 ; <i32*> [#uses=2]
+
+define void @weightadj() {
+entry:
+ br label %bb
+
+bb: ; preds = %bb158, %entry
+ store i32 0, i32* @resonant, align 4
+ br i1 false, label %g.exit, label %bb158
+
+g.exit: ; preds = %bb68, %bb
+ br i1 false, label %bb68, label %cond_true
+
+cond_true: ; preds = %g.exit
+ store i32 1, i32* @resonant, align 4
+ br label %bb68
+
+bb68: ; preds = %cond_true, %g.exit
+ %tmp71 = icmp slt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp71, label %g.exit, label %bb158
+
+bb158: ; preds = %bb68, %bb
+ br i1 false, label %bb, label %return
+
+return: ; preds = %bb158
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2008-06-02-DomInfo.ll b/src/LLVM/test/Transforms/LoopUnswitch/2008-06-02-DomInfo.ll
new file mode 100644
index 0000000..906c2c5
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2008-06-02-DomInfo.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -loop-unswitch -instcombine -gvn -disable-output
+; PR2372
+target triple = "i386-pc-linux-gnu"
+
+define i32 @func_3(i16 signext %p_5, i16 signext %p_6) nounwind {
+entry:
+ %tmp3 = icmp eq i16 %p_5, 0 ; <i1> [#uses=1]
+ %tmp1314 = sext i16 %p_6 to i32 ; <i32> [#uses=1]
+ %tmp28 = icmp ugt i32 %tmp1314, 3 ; <i1> [#uses=1]
+ %bothcond = or i1 %tmp28, false ; <i1> [#uses=1]
+ br label %bb
+bb: ; preds = %bb54, %entry
+ br i1 %tmp3, label %bb54, label %bb5
+bb5: ; preds = %bb
+ br i1 %bothcond, label %bb54, label %bb31
+bb31: ; preds = %bb5
+ br label %bb54
+bb54: ; preds = %bb31, %bb5, %bb
+ br i1 false, label %bb64, label %bb
+bb64: ; preds = %bb54
+ %tmp6566 = sext i16 %p_6 to i32 ; <i32> [#uses=1]
+ %tmp68 = tail call i32 (...)* @func_18( i32 1, i32 %tmp6566, i32 1 ) nounwind ; <i32> [#uses=0]
+ ret i32 undef
+}
+
+declare i32 @func_18(...)
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2008-06-17-DomFrontier.ll b/src/LLVM/test/Transforms/LoopUnswitch/2008-06-17-DomFrontier.ll
new file mode 100644
index 0000000..f74054a
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2008-06-17-DomFrontier.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -licm -loop-unswitch -disable-output
+@g_56 = external global i16 ; <i16*> [#uses=2]
+
+define i32 @func_67(i32 %p_68, i8 signext %p_69, i8 signext %p_71) nounwind {
+entry:
+ br label %bb
+bb: ; preds = %bb44, %entry
+ br label %bb3
+bb3: ; preds = %bb36, %bb
+ %bothcond = or i1 false, false ; <i1> [#uses=1]
+ br i1 %bothcond, label %bb29, label %bb19
+bb19: ; preds = %bb3
+ br i1 false, label %bb36, label %bb29
+bb29: ; preds = %bb19, %bb3
+ ret i32 0
+bb36: ; preds = %bb19
+ store i16 0, i16* @g_56, align 2
+ br i1 false, label %bb44, label %bb3
+bb44: ; preds = %bb44, %bb36
+ %tmp46 = load i16* @g_56, align 2 ; <i16> [#uses=0]
+ br i1 false, label %bb, label %bb44
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2008-11-03-Invariant.ll b/src/LLVM/test/Transforms/LoopUnswitch/2008-11-03-Invariant.ll
new file mode 100644
index 0000000..20f2c2b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2008-11-03-Invariant.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -loop-unswitch -stats -disable-output |& grep "1 loop-unswitch - Number of branches unswitched" | count 1
+; PR 3170
+define i32 @a(i32 %x, i32 %y) nounwind {
+entry:
+ %0 = icmp ult i32 0, %y ; <i1> [#uses=1]
+ br i1 %0, label %bb.nph, label %bb4
+
+bb.nph: ; preds = %entry
+ %1 = icmp eq i32 %x, 0 ; <i1> [#uses=1]
+ br label %bb
+
+bb: ; preds = %bb.nph, %bb3
+ %i.01 = phi i32 [ %3, %bb3 ], [ 0, %bb.nph ] ; <i32> [#uses=1]
+ br i1 %1, label %bb2, label %bb1
+
+bb1: ; preds = %bb
+ %2 = tail call i32 (...)* @b() nounwind ; <i32> [#uses=0]
+ br label %bb2
+
+bb2: ; preds = %bb, %bb1
+ %3 = add i32 %i.01, 1 ; <i32> [#uses=2]
+ br label %bb3
+
+bb3: ; preds = %bb2
+ %i.0 = phi i32 [ %3, %bb2 ] ; <i32> [#uses=1]
+ %4 = icmp ult i32 %i.0, %y ; <i1> [#uses=1]
+ br i1 %4, label %bb, label %bb3.bb4_crit_edge
+
+bb3.bb4_crit_edge: ; preds = %bb3
+ br label %bb4
+
+bb4: ; preds = %bb3.bb4_crit_edge, %entry
+ ret i32 0
+}
+
+declare i32 @b(...)
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2010-11-18-LCSSA.ll b/src/LLVM/test/Transforms/LoopUnswitch/2010-11-18-LCSSA.ll
new file mode 100644
index 0000000..a976d18
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2010-11-18-LCSSA.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -loop-unswitch
+; PR8622
+@g_38 = external global i32, align 4
+
+define void @func_67(i32 %p_68.coerce) nounwind {
+entry:
+ br i1 true, label %for.end12, label %bb.nph
+
+bb.nph: ; preds = %entry
+ %g_38.promoted = load i32* @g_38
+ br label %for.body
+
+for.body: ; preds = %for.cond, %bb.nph
+ %tobool.i = icmp eq i32 %p_68.coerce, 1
+ %xor4.i = xor i32 %p_68.coerce, 1
+ %call1 = select i1 %tobool.i, i32 0, i32 %xor4.i
+ br label %for.cond
+
+for.cond: ; preds = %for.body
+ br i1 true, label %for.cond.for.end12_crit_edge, label %for.body
+
+for.cond.for.end12_crit_edge: ; preds = %for.cond
+ store i32 %call1, i32* @g_38
+ br label %for.end12
+
+for.end12: ; preds = %for.cond.for.end12_crit_edge, %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2011-06-02-CritSwitch.ll b/src/LLVM/test/Transforms/LoopUnswitch/2011-06-02-CritSwitch.ll
new file mode 100644
index 0000000..61c54dd
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2011-06-02-CritSwitch.ll
@@ -0,0 +1,28 @@
+; RUN: opt -loop-unswitch -disable-output
+; PR10031
+
+define i32 @test(i32 %command) {
+entry:
+ br label %tailrecurse
+
+tailrecurse: ; preds = %if.then14, %tailrecurse, %entry
+ br i1 undef, label %if.then, label %tailrecurse
+
+if.then: ; preds = %tailrecurse
+ switch i32 %command, label %sw.bb [
+ i32 2, label %land.lhs.true
+ i32 0, label %land.lhs.true
+ ]
+
+land.lhs.true: ; preds = %if.then, %if.then
+ br i1 undef, label %sw.bb, label %if.then14
+
+if.then14: ; preds = %land.lhs.true
+ switch i32 %command, label %tailrecurse [
+ i32 0, label %sw.bb
+ i32 1, label %sw.bb
+ ]
+
+sw.bb: ; preds = %if.then14
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/2011-09-26-EHCrash.ll b/src/LLVM/test/Transforms/LoopUnswitch/2011-09-26-EHCrash.ll
new file mode 100644
index 0000000..0e3103d
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/2011-09-26-EHCrash.ll
@@ -0,0 +1,67 @@
+; RUN: opt < %s -scalarrepl-ssa -loop-unswitch -disable-output
+; PR11016
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.2"
+
+%class.MyContainer.1.3.19.29 = type { [6 x %class.MyMemVarClass.0.2.18.28*] }
+%class.MyMemVarClass.0.2.18.28 = type { i32 }
+
+define void @_ZN11MyContainer1fEi(%class.MyContainer.1.3.19.29* %this, i32 %doit) uwtable ssp align 2 {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %inc1 = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
+ %conv = sext i32 %inc1 to i64
+ %cmp = icmp ult i64 %conv, 6
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %tobool = icmp ne i32 %doit, 0
+ br i1 %tobool, label %for.inc, label %if.then
+
+if.then: ; preds = %for.body
+ %idxprom = sext i32 %inc1 to i64
+ %array_ = getelementptr inbounds %class.MyContainer.1.3.19.29* %this, i32 0, i32 0
+ %arrayidx = getelementptr inbounds [6 x %class.MyMemVarClass.0.2.18.28*]* %array_, i32 0, i64 %idxprom
+ %tmp4 = load %class.MyMemVarClass.0.2.18.28** %arrayidx, align 8, !tbaa !0
+ %isnull = icmp eq %class.MyMemVarClass.0.2.18.28* %tmp4, null
+ br i1 %isnull, label %for.inc, label %delete.notnull
+
+delete.notnull: ; preds = %if.then
+ invoke void @_ZN13MyMemVarClassD1Ev(%class.MyMemVarClass.0.2.18.28* %tmp4)
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %delete.notnull
+ %0 = bitcast %class.MyMemVarClass.0.2.18.28* %tmp4 to i8*
+ call void @_ZdlPv(i8* %0) nounwind
+ br label %for.inc
+
+lpad: ; preds = %delete.notnull
+ %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ %2 = extractvalue { i8*, i32 } %1, 0
+ %3 = extractvalue { i8*, i32 } %1, 1
+ %4 = bitcast %class.MyMemVarClass.0.2.18.28* %tmp4 to i8*
+ call void @_ZdlPv(i8* %4) nounwind
+ %lpad.val = insertvalue { i8*, i32 } undef, i8* %2, 0
+ %lpad.val7 = insertvalue { i8*, i32 } %lpad.val, i32 %3, 1
+ resume { i8*, i32 } %lpad.val7
+
+for.inc: ; preds = %invoke.cont, %if.then, %for.body
+ %inc = add nsw i32 %inc1, 1
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
+
+declare void @_ZN13MyMemVarClassD1Ev(%class.MyMemVarClass.0.2.18.28*)
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @_ZdlPv(i8*) nounwind
+
+!0 = metadata !{metadata !"any pointer", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/basictest.ll b/src/LLVM/test/Transforms/LoopUnswitch/basictest.ll
new file mode 100644
index 0000000..48b847f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/basictest.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+
+define i32 @test(i32* %A, i1 %C) {
+entry:
+ br label %no_exit
+no_exit: ; preds = %no_exit.backedge, %entry
+ %i.0.0 = phi i32 [ 0, %entry ], [ %i.0.0.be, %no_exit.backedge ] ; <i32> [#uses=3]
+ %gep.upgrd.1 = zext i32 %i.0.0 to i64 ; <i64> [#uses=1]
+ %tmp.7 = getelementptr i32* %A, i64 %gep.upgrd.1 ; <i32*> [#uses=4]
+ %tmp.13 = load i32* %tmp.7 ; <i32> [#uses=2]
+ %tmp.14 = add i32 %tmp.13, 1 ; <i32> [#uses=1]
+ store i32 %tmp.14, i32* %tmp.7
+ br i1 %C, label %then, label %endif
+then: ; preds = %no_exit
+ %tmp.29 = load i32* %tmp.7 ; <i32> [#uses=1]
+ %tmp.30 = add i32 %tmp.29, 2 ; <i32> [#uses=1]
+ store i32 %tmp.30, i32* %tmp.7
+ %inc9 = add i32 %i.0.0, 1 ; <i32> [#uses=2]
+ %tmp.112 = icmp ult i32 %inc9, 100000 ; <i1> [#uses=1]
+ br i1 %tmp.112, label %no_exit.backedge, label %return
+no_exit.backedge: ; preds = %endif, %then
+ %i.0.0.be = phi i32 [ %inc9, %then ], [ %inc, %endif ] ; <i32> [#uses=1]
+ br label %no_exit
+endif: ; preds = %no_exit
+ %inc = add i32 %i.0.0, 1 ; <i32> [#uses=2]
+ %tmp.1 = icmp ult i32 %inc, 100000 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %no_exit.backedge, label %return
+return: ; preds = %endif, %then
+ ret i32 %tmp.13
+}
+
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/crash.ll b/src/LLVM/test/Transforms/LoopUnswitch/crash.ll
new file mode 100644
index 0000000..2d49b0f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/crash.ll
@@ -0,0 +1,66 @@
+; RUN: opt < %s -loop-unswitch -disable-output
+
+define void @test1(i32* %S2) {
+entry:
+ br i1 false, label %list_Length.exit, label %cond_true.i
+cond_true.i: ; preds = %entry
+ ret void
+list_Length.exit: ; preds = %entry
+ br i1 false, label %list_Length.exit9, label %cond_true.i5
+cond_true.i5: ; preds = %list_Length.exit
+ ret void
+list_Length.exit9: ; preds = %list_Length.exit
+ br i1 false, label %bb78, label %return
+bb44: ; preds = %bb78, %cond_next68
+ br i1 %tmp49.not, label %bb62, label %bb62.loopexit
+bb62.loopexit: ; preds = %bb44
+ br label %bb62
+bb62: ; preds = %bb62.loopexit, %bb44
+ br i1 false, label %return.loopexit, label %cond_next68
+cond_next68: ; preds = %bb62
+ br i1 false, label %return.loopexit, label %bb44
+bb78: ; preds = %list_Length.exit9
+ %tmp49.not = icmp eq i32* %S2, null ; <i1> [#uses=1]
+ br label %bb44
+return.loopexit: ; preds = %cond_next68, %bb62
+ %retval.0.ph = phi i32 [ 1, %cond_next68 ], [ 0, %bb62 ] ; <i32> [#uses=1]
+ br label %return
+return: ; preds = %return.loopexit, %list_Length.exit9
+ %retval.0 = phi i32 [ 0, %list_Length.exit9 ], [ %retval.0.ph, %return.loopexit ] ; <i32> [#uses=0]
+ ret void
+}
+
+define void @test2(i32 %x1, i32 %y1, i32 %z1, i32 %r1) nounwind {
+entry:
+ br label %bb.nph
+
+bb.nph: ; preds = %entry
+ %and.i13521 = and <4 x i1> undef, undef ; <<4 x i1>> [#uses=1]
+ br label %for.body
+
+for.body: ; preds = %for.body, %bb.nph
+ %or.i = select <4 x i1> %and.i13521, <4 x i32> undef, <4 x i32> undef ; <<4 x i32>> [#uses=0]
+ br i1 false, label %for.body, label %for.end
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
+
+; PR6879
+define i32* @test3(i32** %p_45, i16 zeroext %p_46, i64 %p_47, i64 %p_48, i16 signext %p_49) nounwind {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.cond4, %entry
+ br i1 false, label %for.cond4, label %for.end88
+
+for.cond4: ; preds = %for.cond
+ %conv46 = trunc i32 0 to i8 ; <i8> [#uses=2]
+ %cmp60 = icmp sgt i8 %conv46, 124 ; <i1> [#uses=1]
+ %or.cond = and i1 undef, %cmp60 ; <i1> [#uses=1]
+ %cond = select i1 %or.cond, i8 %conv46, i8 undef ; <i8> [#uses=0]
+ br label %for.cond
+
+for.end88: ; preds = %for.cond
+ ret i32* undef
+}
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/dg.exp b/src/LLVM/test/Transforms/LoopUnswitch/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/infinite-loop.ll b/src/LLVM/test/Transforms/LoopUnswitch/infinite-loop.ll
new file mode 100644
index 0000000..73391ca
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/infinite-loop.ll
@@ -0,0 +1,53 @@
+; RUN: opt -loop-unswitch -disable-output -stats -info-output-file - < %s | FileCheck --check-prefix=STATS %s
+; RUN: opt -loop-unswitch -simplifycfg -S < %s | FileCheck %s
+; PR5373
+
+; Loop unswitching shouldn't trivially unswitch the true case of condition %a
+; in the code here because it leads to an infinite loop. While this doesn't
+; contain any instructions with side effects, it's still a kind of side effect.
+; It can trivially unswitch on the false cas of condition %a though.
+
+; STATS: 2 loop-unswitch - Number of branches unswitched
+; STATS: 1 loop-unswitch - Number of unswitches that are trivial
+
+; CHECK: @func_16
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %a, label %entry.split, label %abort0.split
+
+; CHECK: entry.split:
+; CHECK-NEXT: br i1 %b, label %cond.end.us, label %abort1
+
+; CHECK: cond.end.us:
+; CHECK-NEXT: br label %cond.end.us
+
+; CHECK: abort0.split:
+; CHECK-NEXT: call void @end0() noreturn nounwind
+; CHECK-NEXT: unreachable
+
+; CHECK: abort1:
+; CHECK-NEXT: call void @end1() noreturn nounwind
+; CHECK-NEXT: unreachable
+
+; CHECK: }
+
+define void @func_16(i1 %a, i1 %b) nounwind {
+entry:
+ br label %for.body
+
+for.body:
+ br i1 %a, label %cond.end, label %abort0
+
+cond.end:
+ br i1 %b, label %for.body, label %abort1
+
+abort0:
+ call void @end0() noreturn nounwind
+ unreachable
+
+abort1:
+ call void @end1() noreturn nounwind
+ unreachable
+}
+
+declare void @end0() noreturn
+declare void @end1() noreturn
diff --git a/src/LLVM/test/Transforms/LoopUnswitch/preserve-analyses.ll b/src/LLVM/test/Transforms/LoopUnswitch/preserve-analyses.ll
new file mode 100644
index 0000000..668f8ec
--- /dev/null
+++ b/src/LLVM/test/Transforms/LoopUnswitch/preserve-analyses.ll
@@ -0,0 +1,129 @@
+; RUN: opt -loop-unswitch -verify-loop-info -verify-dom-info %s -disable-output
+
+; Loop unswitch should be able to unswitch these loops and
+; preserve LCSSA and LoopSimplify forms.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:64"
+target triple = "armv6-apple-darwin9"
+
+@delim1 = external global i32 ; <i32*> [#uses=1]
+@delim2 = external global i32 ; <i32*> [#uses=1]
+
+define i32 @ineqn(i8* %s, i8* %p) nounwind readonly {
+entry:
+ %0 = load i32* @delim1, align 4 ; <i32> [#uses=1]
+ %1 = load i32* @delim2, align 4 ; <i32> [#uses=1]
+ br label %bb8.outer
+
+bb: ; preds = %bb8
+ %2 = icmp eq i8* %p_addr.0, %s ; <i1> [#uses=1]
+ br i1 %2, label %bb10, label %bb2
+
+bb2: ; preds = %bb
+ %3 = getelementptr inbounds i8* %p_addr.0, i32 1 ; <i8*> [#uses=3]
+ switch i32 %ineq.0.ph, label %bb8.backedge [
+ i32 0, label %bb3
+ i32 1, label %bb6
+ ]
+
+bb8.backedge: ; preds = %bb6, %bb5, %bb2
+ br label %bb8
+
+bb3: ; preds = %bb2
+ %4 = icmp eq i32 %8, %0 ; <i1> [#uses=1]
+ br i1 %4, label %bb8.outer.loopexit, label %bb5
+
+bb5: ; preds = %bb3
+ br i1 %6, label %bb6, label %bb8.backedge
+
+bb6: ; preds = %bb5, %bb2
+ %5 = icmp eq i32 %8, %1 ; <i1> [#uses=1]
+ br i1 %5, label %bb7, label %bb8.backedge
+
+bb7: ; preds = %bb6
+ %.lcssa1 = phi i8* [ %3, %bb6 ] ; <i8*> [#uses=1]
+ br label %bb8.outer.backedge
+
+bb8.outer.backedge: ; preds = %bb8.outer.loopexit, %bb7
+ %.lcssa2 = phi i8* [ %.lcssa1, %bb7 ], [ %.lcssa, %bb8.outer.loopexit ] ; <i8*> [#uses=1]
+ %ineq.0.ph.be = phi i32 [ 0, %bb7 ], [ 1, %bb8.outer.loopexit ] ; <i32> [#uses=1]
+ br label %bb8.outer
+
+bb8.outer.loopexit: ; preds = %bb3
+ %.lcssa = phi i8* [ %3, %bb3 ] ; <i8*> [#uses=1]
+ br label %bb8.outer.backedge
+
+bb8.outer: ; preds = %bb8.outer.backedge, %entry
+ %ineq.0.ph = phi i32 [ 0, %entry ], [ %ineq.0.ph.be, %bb8.outer.backedge ] ; <i32> [#uses=3]
+ %p_addr.0.ph = phi i8* [ %p, %entry ], [ %.lcssa2, %bb8.outer.backedge ] ; <i8*> [#uses=1]
+ %6 = icmp eq i32 %ineq.0.ph, 1 ; <i1> [#uses=1]
+ br label %bb8
+
+bb8: ; preds = %bb8.outer, %bb8.backedge
+ %p_addr.0 = phi i8* [ %p_addr.0.ph, %bb8.outer ], [ %3, %bb8.backedge ] ; <i8*> [#uses=3]
+ %7 = load i8* %p_addr.0, align 1 ; <i8> [#uses=2]
+ %8 = sext i8 %7 to i32 ; <i32> [#uses=2]
+ %9 = icmp eq i8 %7, 0 ; <i1> [#uses=1]
+ br i1 %9, label %bb10, label %bb
+
+bb10: ; preds = %bb8, %bb
+ %.0 = phi i32 [ %ineq.0.ph, %bb ], [ 0, %bb8 ] ; <i32> [#uses=1]
+ ret i32 %.0
+}
+
+; This is a simplified form of ineqn from above. It triggers some
+; different cases in the loop-unswitch code.
+
+define void @simplified_ineqn() nounwind readonly {
+entry:
+ br label %bb8.outer
+
+bb8.outer: ; preds = %bb6, %bb2, %entry
+ %x = phi i32 [ 0, %entry ], [ 0, %bb6 ], [ 1, %bb2 ] ; <i32> [#uses=1]
+ br i1 undef, label %return, label %bb2
+
+bb2: ; preds = %bb
+ switch i32 %x, label %bb6 [
+ i32 0, label %bb8.outer
+ ]
+
+bb6: ; preds = %bb2
+ br i1 undef, label %bb8.outer, label %bb2
+
+return: ; preds = %bb8, %bb
+ ret void
+}
+
+; This function requires special handling to preserve LCSSA form.
+; PR4934
+
+define void @pnp_check_irq() nounwind noredzone {
+entry:
+ %conv56 = trunc i64 undef to i32 ; <i32> [#uses=1]
+ br label %while.cond.i
+
+while.cond.i: ; preds = %while.cond.i.backedge, %entry
+ %call.i25 = call i8* @pci_get_device() nounwind noredzone ; <i8*> [#uses=2]
+ br i1 undef, label %if.then65, label %while.body.i
+
+while.body.i: ; preds = %while.cond.i
+ br i1 undef, label %if.then31.i.i, label %while.cond.i.backedge
+
+while.cond.i.backedge: ; preds = %if.then31.i.i, %while.body.i
+ br label %while.cond.i
+
+if.then31.i.i: ; preds = %while.body.i
+ switch i32 %conv56, label %while.cond.i.backedge [
+ i32 14, label %if.then42.i.i
+ i32 15, label %if.then42.i.i
+ ]
+
+if.then42.i.i: ; preds = %if.then31.i.i, %if.then31.i.i
+ %call.i25.lcssa48 = phi i8* [ %call.i25, %if.then31.i.i ], [ %call.i25, %if.then31.i.i ] ; <i8*> [#uses=0]
+ unreachable
+
+if.then65: ; preds = %while.cond.i
+ unreachable
+}
+
+declare i8* @pci_get_device() noredzone
diff --git a/src/LLVM/test/Transforms/LowerAtomic/atomic-load.ll b/src/LLVM/test/Transforms/LowerAtomic/atomic-load.ll
new file mode 100644
index 0000000..bc04e88
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerAtomic/atomic-load.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -loweratomic -S | FileCheck %s
+
+define i8 @add() {
+; CHECK: @add
+ %i = alloca i8
+ %j = atomicrmw add i8* %i, i8 42 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: add
+; CHECK-NEXT: store
+ ret i8 %j
+; CHECK: ret i8 [[INST]]
+}
+
+define i8 @nand() {
+; CHECK: @nand
+ %i = alloca i8
+ %j = atomicrmw nand i8* %i, i8 42 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: and
+; CHECK-NEXT: xor
+; CHECK-NEXT: store
+ ret i8 %j
+; CHECK: ret i8 [[INST]]
+}
+
+define i8 @min() {
+; CHECK: @min
+ %i = alloca i8
+ %j = atomicrmw min i8* %i, i8 42 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: icmp
+; CHECK-NEXT: select
+; CHECK-NEXT: store
+ ret i8 %j
+; CHECK: ret i8 [[INST]]
+}
diff --git a/src/LLVM/test/Transforms/LowerAtomic/atomic-swap.ll b/src/LLVM/test/Transforms/LowerAtomic/atomic-swap.ll
new file mode 100644
index 0000000..5e2f034
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerAtomic/atomic-swap.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -loweratomic -S | FileCheck %s
+
+define i8 @cmpswap() {
+; CHECK: @cmpswap
+ %i = alloca i8
+ %j = cmpxchg i8* %i, i8 0, i8 42 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: icmp
+; CHECK-NEXT: select
+; CHECK-NEXT: store
+ ret i8 %j
+; CHECK: ret i8 [[INST]]
+}
+
+define i8 @swap() {
+; CHECK: @swap
+ %i = alloca i8
+ %j = atomicrmw xchg i8* %i, i8 42 monotonic
+; CHECK: [[INST:%[a-z0-9]+]] = load
+; CHECK-NEXT: store
+ ret i8 %j
+; CHECK: ret i8 [[INST]]
+}
diff --git a/src/LLVM/test/Transforms/LowerAtomic/barrier.ll b/src/LLVM/test/Transforms/LowerAtomic/barrier.ll
new file mode 100644
index 0000000..814d7af
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerAtomic/barrier.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -loweratomic -S | FileCheck %s
+
+define void @barrier() {
+; CHECK: @barrier
+ fence seq_cst
+; CHECK-NEXT: ret
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/LowerAtomic/dg.exp b/src/LLVM/test/Transforms/LowerAtomic/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerAtomic/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LowerExpectIntrinsic/basic.ll b/src/LLVM/test/Transforms/LowerExpectIntrinsic/basic.ll
new file mode 100644
index 0000000..c00127e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerExpectIntrinsic/basic.ll
@@ -0,0 +1,251 @@
+; RUN: opt -lower-expect -strip-dead-prototypes -S -o - < %s | FileCheck %s
+
+; CHECK: @test1
+define i32 @test1(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %cmp = icmp sgt i32 %tmp, 1
+ %conv = zext i1 %cmp to i32
+ %conv1 = sext i32 %conv to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
+ %tobool = icmp ne i64 %expval, 0
+; CHECK: !prof !0
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+declare i64 @llvm.expect.i64(i64, i64) nounwind readnone
+
+declare i32 @f(...)
+
+; CHECK: @test2
+define i32 @test2(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %conv = sext i32 %tmp to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
+ %tobool = icmp ne i64 %expval, 0
+; CHECK: !prof !0
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test3
+define i32 @test3(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %tobool = icmp ne i32 %tmp, 0
+ %lnot = xor i1 %tobool, true
+ %lnot.ext = zext i1 %lnot to i32
+ %conv = sext i32 %lnot.ext to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
+ %tobool1 = icmp ne i64 %expval, 0
+; CHECK: !prof !0
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool1, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test4
+define i32 @test4(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %tobool = icmp ne i32 %tmp, 0
+ %lnot = xor i1 %tobool, true
+ %lnot1 = xor i1 %lnot, true
+ %lnot.ext = zext i1 %lnot1 to i32
+ %conv = sext i32 %lnot.ext to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
+ %tobool2 = icmp ne i64 %expval, 0
+; CHECK: !prof !0
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool2, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test5
+define i32 @test5(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %cmp = icmp slt i32 %tmp, 0
+ %conv = zext i1 %cmp to i32
+ %conv1 = sext i32 %conv to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 0)
+ %tobool = icmp ne i64 %expval, 0
+; CHECK: !prof !1
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test6
+define i32 @test6(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %conv = sext i32 %tmp to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
+; CHECK: !prof !2
+; CHECK-NOT: @llvm.expect
+ switch i64 %expval, label %sw.epilog [
+ i64 1, label %sw.bb
+ i64 2, label %sw.bb
+ ]
+
+sw.bb: ; preds = %entry, %entry
+ store i32 0, i32* %retval
+ br label %return
+
+sw.epilog: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %sw.epilog, %sw.bb
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test7
+define i32 @test7(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %conv = sext i32 %tmp to i64
+ %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
+; CHECK: !prof !3
+; CHECK-NOT: @llvm.expect
+ switch i64 %expval, label %sw.epilog [
+ i64 2, label %sw.bb
+ i64 3, label %sw.bb
+ ]
+
+sw.bb: ; preds = %entry, %entry
+ %tmp1 = load i32* %x.addr, align 4
+ store i32 %tmp1, i32* %retval
+ br label %return
+
+sw.epilog: ; preds = %entry
+ store i32 0, i32* %retval
+ br label %return
+
+return: ; preds = %sw.epilog, %sw.bb
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+; CHECK: @test8
+define i32 @test8(i32 %x) nounwind uwtable ssp {
+entry:
+ %retval = alloca i32, align 4
+ %x.addr = alloca i32, align 4
+ store i32 %x, i32* %x.addr, align 4
+ %tmp = load i32* %x.addr, align 4
+ %cmp = icmp sgt i32 %tmp, 1
+ %conv = zext i1 %cmp to i32
+ %expval = call i32 @llvm.expect.i32(i32 %conv, i32 1)
+ %tobool = icmp ne i32 %expval, 0
+; CHECK: !prof !0
+; CHECK-NOT: @llvm.expect
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %call = call i32 (...)* @f()
+ store i32 %call, i32* %retval
+ br label %return
+
+if.end: ; preds = %entry
+ store i32 1, i32* %retval
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %0 = load i32* %retval
+ ret i32 %0
+}
+
+declare i32 @llvm.expect.i32(i32, i32) nounwind readnone
+
+; CHECK: !0 = metadata !{metadata !"branch_weights", i32 64, i32 4}
+; CHECK: !1 = metadata !{metadata !"branch_weights", i32 4, i32 64}
+; CHECK: !2 = metadata !{metadata !"branch_weights", i32 4, i32 64, i32 4}
+; CHECK: !3 = metadata !{metadata !"branch_weights", i32 64, i32 4, i32 4}
diff --git a/src/LLVM/test/Transforms/LowerExpectIntrinsic/dg.exp b/src/LLVM/test/Transforms/LowerExpectIntrinsic/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerExpectIntrinsic/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LowerInvoke/2003-12-10-Crash.ll b/src/LLVM/test/Transforms/LowerInvoke/2003-12-10-Crash.ll
new file mode 100644
index 0000000..35181ec
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/2003-12-10-Crash.ll
@@ -0,0 +1,22 @@
+; This testcase was reduced from Shootout-C++/reversefile.cpp by bugpoint
+
+; RUN: opt < %s -lowerinvoke -disable-output
+
+declare void @baz()
+
+declare void @bar()
+
+define void @foo() {
+then:
+ invoke void @baz( )
+ to label %invoke_cont.0 unwind label %try_catch
+invoke_cont.0: ; preds = %then
+ invoke void @bar( )
+ to label %try_exit unwind label %try_catch
+try_catch: ; preds = %invoke_cont.0, %then
+ %__tmp.0 = phi i32* [ null, %invoke_cont.0 ], [ null, %then ] ; <i32*> [#uses=0]
+ ret void
+try_exit: ; preds = %invoke_cont.0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LowerInvoke/2004-02-29-PHICrash.ll b/src/LLVM/test/Transforms/LowerInvoke/2004-02-29-PHICrash.ll
new file mode 100644
index 0000000..836c05e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/2004-02-29-PHICrash.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -lowerinvoke -enable-correct-eh-support -disable-output
+
+define void @_ZNKSt11__use_cacheISt16__numpunct_cacheIcEEclERKSt6locale() {
+entry:
+ br i1 false, label %then, label %UnifiedReturnBlock
+then: ; preds = %entry
+ invoke void @_Znwj( )
+ to label %UnifiedReturnBlock unwind label %UnifiedReturnBlock
+UnifiedReturnBlock: ; preds = %then, %then, %entry
+ %UnifiedRetVal = phi i32* [ null, %entry ], [ null, %then ], [ null, %then ] ; <i32*> [#uses=0]
+ ret void
+}
+
+declare void @_Znwj()
+
diff --git a/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll b/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll
new file mode 100644
index 0000000..8bd1cfd
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -lowerinvoke -enable-correct-eh-support -disable-output
+
+declare void @ll_listnext__listiterPtr()
+
+define void @WorkTask.fn() {
+block0:
+ invoke void @ll_listnext__listiterPtr( )
+ to label %block9 unwind label %block8_exception_handling
+block8_exception_handling: ; preds = %block0
+ ret void
+block9: ; preds = %block0
+ %w_2690 = phi { i32, i32 }* [ null, %block0 ] ; <{ i32, i32 }*> [#uses=1]
+ %tmp.129 = getelementptr { i32, i32 }* %w_2690, i32 0, i32 1 ; <i32*> [#uses=1]
+ %v2769 = load i32* %tmp.129 ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll b/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll
new file mode 100644
index 0000000..f8d67c8
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -lowerinvoke -enable-correct-eh-support -disable-output
+
+declare fastcc i32 @ll_listnext__listiterPtr()
+
+define fastcc i32 @WorkTask.fn() {
+block0:
+ %v2679 = invoke fastcc i32 @ll_listnext__listiterPtr( )
+ to label %block9 unwind label %block8_exception_handling ; <i32> [#uses=1]
+block8_exception_handling: ; preds = %block0
+ ret i32 0
+block9: ; preds = %block0
+ %i_2689 = phi i32 [ %v2679, %block0 ] ; <i32> [#uses=1]
+ ret i32 %i_2689
+}
+
diff --git a/src/LLVM/test/Transforms/LowerInvoke/2008-02-14-CritEdgePhiCrash.ll b/src/LLVM/test/Transforms/LowerInvoke/2008-02-14-CritEdgePhiCrash.ll
new file mode 100644
index 0000000..b46ccfb
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/2008-02-14-CritEdgePhiCrash.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -lowerinvoke -enable-correct-eh-support -disable-output
+; PR2029
+define i32 @main(i32 %argc, i8** %argv) {
+bb470:
+ invoke i32 @main(i32 0, i8** null) to label %invcont474 unwind label
+%lpad902
+
+invcont474: ; preds = %bb470
+ ret i32 0
+
+lpad902: ; preds = %bb470
+ %tmp471.lcssa = phi i8* [ null, %bb470 ] ; <i8*>
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/LowerInvoke/basictest.ll b/src/LLVM/test/Transforms/LowerInvoke/basictest.ll
new file mode 100644
index 0000000..3956264
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/basictest.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -lowerinvoke -disable-output -enable-correct-eh-support
+
+
+define i32 @foo() {
+ invoke i32 @foo( )
+ to label %Ok unwind label %Crap ; <i32>:1 [#uses=0]
+Ok: ; preds = %0
+ invoke i32 @foo( )
+ to label %Ok2 unwind label %Crap ; <i32>:2 [#uses=0]
+Ok2: ; preds = %Ok
+ ret i32 2
+Crap: ; preds = %Ok, %0
+ ret i32 1
+}
+
+define i32 @bar(i32 %blah) {
+ br label %doit
+doit: ; preds = %0
+ ;; Value live across an unwind edge.
+ %B2 = add i32 %blah, 1 ; <i32> [#uses=1]
+ invoke i32 @foo( )
+ to label %Ok unwind label %Crap ; <i32>:1 [#uses=0]
+Ok: ; preds = %doit
+ invoke i32 @foo( )
+ to label %Ok2 unwind label %Crap ; <i32>:2 [#uses=0]
+Ok2: ; preds = %Ok
+ ret i32 2
+Crap: ; preds = %Ok, %doit
+ ret i32 %B2
+}
diff --git a/src/LLVM/test/Transforms/LowerInvoke/dg.exp b/src/LLVM/test/Transforms/LowerInvoke/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerInvoke/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LowerSwitch/2003-05-01-PHIProblem.ll b/src/LLVM/test/Transforms/LowerSwitch/2003-05-01-PHIProblem.ll
new file mode 100644
index 0000000..578f48e
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerSwitch/2003-05-01-PHIProblem.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -lowerswitch
+
+define void @child(i32 %ct.1) {
+entry:
+ switch i32 0, label %return [
+ i32 3, label %UnifiedExitNode
+ i32 0, label %return
+ ]
+return: ; preds = %entry, %entry
+ %result.0 = phi i32* [ null, %entry ], [ null, %entry ] ; <i32*> [#uses=0]
+ br label %UnifiedExitNode
+UnifiedExitNode: ; preds = %return, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LowerSwitch/2003-08-23-EmptySwitch.ll b/src/LLVM/test/Transforms/LowerSwitch/2003-08-23-EmptySwitch.ll
new file mode 100644
index 0000000..93a8327
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerSwitch/2003-08-23-EmptySwitch.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -lowerswitch
+
+define void @test() {
+ switch i32 0, label %Next [
+ ]
+Next: ; preds = %0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/LowerSwitch/2004-03-13-SwitchIsDefaultCrash.ll b/src/LLVM/test/Transforms/LowerSwitch/2004-03-13-SwitchIsDefaultCrash.ll
new file mode 100644
index 0000000..da1d277
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerSwitch/2004-03-13-SwitchIsDefaultCrash.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -lowerswitch -disable-output
+
+define void @solve() {
+entry:
+ %targetBlock = call i16 @solve_code( ) ; <i16> [#uses=1]
+ br label %codeReplTail
+then.1: ; preds = %codeReplTail
+ ret void
+loopexit.0: ; preds = %codeReplTail
+ ret void
+codeReplTail: ; preds = %codeReplTail, %entry
+ switch i16 %targetBlock, label %codeReplTail [
+ i16 0, label %loopexit.0
+ i16 1, label %then.1
+ ]
+}
+
+declare i16 @solve_code()
+
diff --git a/src/LLVM/test/Transforms/LowerSwitch/dg.exp b/src/LLVM/test/Transforms/LowerSwitch/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerSwitch/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/LowerSwitch/feature.ll b/src/LLVM/test/Transforms/LowerSwitch/feature.ll
new file mode 100644
index 0000000..30ac70f
--- /dev/null
+++ b/src/LLVM/test/Transforms/LowerSwitch/feature.ll
@@ -0,0 +1,51 @@
+; RUN: opt < %s -lowerswitch -S > %t
+; RUN: grep slt %t | count 10
+; RUN: grep ule %t | count 3
+; RUN: grep eq %t | count 9
+
+define i32 @main(i32 %tmp158) {
+entry:
+ switch i32 %tmp158, label %bb336 [
+ i32 -2, label %bb338
+ i32 -3, label %bb338
+ i32 -4, label %bb338
+ i32 -5, label %bb338
+ i32 -6, label %bb338
+ i32 0, label %bb338
+ i32 1, label %bb338
+ i32 2, label %bb338
+ i32 3, label %bb338
+ i32 4, label %bb338
+ i32 5, label %bb338
+ i32 6, label %bb338
+ i32 7, label %bb
+ i32 8, label %bb338
+ i32 9, label %bb322
+ i32 10, label %bb324
+ i32 11, label %bb326
+ i32 12, label %bb328
+ i32 13, label %bb330
+ i32 14, label %bb332
+ i32 15, label %bb334
+ ]
+bb:
+ ret i32 2
+bb322:
+ ret i32 3
+bb324:
+ ret i32 4
+bb326:
+ ret i32 5
+bb328:
+ ret i32 6
+bb330:
+ ret i32 7
+bb332:
+ ret i32 8
+bb334:
+ ret i32 9
+bb336:
+ ret i32 10
+bb338:
+ ret i32 11
+}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll b/src/LLVM/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll
new file mode 100644
index 0000000..f3d99da
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll
@@ -0,0 +1,11 @@
+; Uninitialized values are not handled correctly.
+;
+; RUN: opt < %s -mem2reg -disable-output
+;
+
+define i32 @test() {
+ ; To be promoted
+ %X = alloca i32 ; <i32*> [#uses=1]
+ %Y = load i32* %X ; <i32> [#uses=1]
+ ret i32 %Y
+}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll b/src/LLVM/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll
new file mode 100644
index 0000000..5a92ad0
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2002-05-01-ShouldNotPromoteThisAlloca.ll
@@ -0,0 +1,12 @@
+; This input caused the mem2reg pass to die because it was trying to promote
+; the %r alloca, even though it is invalid to do so in this case!
+;
+; RUN: opt < %s -mem2reg
+
+define void @test() {
+ %r = alloca i32 ; <i32*> [#uses=2]
+ store i32 4, i32* %r
+ store i32* %r, i32** null
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll b/src/LLVM/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll
new file mode 100644
index 0000000..1cf60b5
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2003-04-10-DFNotFound.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -mem2reg
+
+define void @_Z3barv() {
+ %result = alloca i32 ; <i32*> [#uses=1]
+ ret void
+ ; No predecessors!
+ store i32 0, i32* %result
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll b/src/LLVM/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll
new file mode 100644
index 0000000..55ea11a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2003-04-18-DeadBlockProblem.ll
@@ -0,0 +1,16 @@
+; This testcases makes sure that mem2reg can handle unreachable blocks.
+; RUN: opt < %s -mem2reg
+
+define i32 @test() {
+ %X = alloca i32 ; <i32*> [#uses=2]
+ store i32 6, i32* %X
+ br label %Loop
+Loop: ; preds = %EndOfLoop, %0
+ store i32 5, i32* %X
+ br label %EndOfLoop
+Unreachable: ; No predecessors!
+ br label %EndOfLoop
+EndOfLoop: ; preds = %Unreachable, %Loop
+ br label %Loop
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll b/src/LLVM/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll
new file mode 100644
index 0000000..bb260c1
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2003-04-24-MultipleIdenticalSuccessors.ll
@@ -0,0 +1,16 @@
+; Mem2reg used to only add one incoming value to a PHI node, even if it had
+; multiple incoming edges from a block.
+;
+; RUN: opt < %s -mem2reg -disable-output
+
+define i32 @test(i1 %c1, i1 %c2) {
+ %X = alloca i32 ; <i32*> [#uses=2]
+ br i1 %c1, label %Exit, label %B2
+B2: ; preds = %0
+ store i32 2, i32* %X
+ br i1 %c2, label %Exit, label %Exit
+Exit: ; preds = %B2, %B2, %0
+ %Y = load i32* %X ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll b/src/LLVM/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll
new file mode 100644
index 0000000..66e7008
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2003-06-26-IterativePromote.ll
@@ -0,0 +1,16 @@
+; Promoting some values allows promotion of other values.
+; RUN: opt < %s -mem2reg -S | not grep alloca
+
+define i32 @test2() {
+ %result = alloca i32 ; <i32*> [#uses=2]
+ %a = alloca i32 ; <i32*> [#uses=2]
+ %p = alloca i32* ; <i32**> [#uses=2]
+ store i32 0, i32* %a
+ store i32* %a, i32** %p
+ %tmp.0 = load i32** %p ; <i32*> [#uses=1]
+ %tmp.1 = load i32* %tmp.0 ; <i32> [#uses=1]
+ store i32 %tmp.1, i32* %result
+ %tmp.2 = load i32* %result ; <i32> [#uses=1]
+ ret i32 %tmp.2
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll b/src/LLVM/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll
new file mode 100644
index 0000000..fd0750a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2003-10-05-DeadPHIInsertion.ll
@@ -0,0 +1,22 @@
+; Mem2reg should not insert dead PHI nodes! The naive algorithm inserts a PHI
+; node in L3, even though there is no load of %A in anything dominated by L3.
+
+; RUN: opt < %s -mem2reg -S | not grep phi
+
+define void @test(i32 %B, i1 %C) {
+ %A = alloca i32 ; <i32*> [#uses=4]
+ store i32 %B, i32* %A
+ br i1 %C, label %L1, label %L2
+L1: ; preds = %0
+ store i32 %B, i32* %A
+ %D = load i32* %A ; <i32> [#uses=1]
+ call void @test( i32 %D, i1 false )
+ br label %L3
+L2: ; preds = %0
+ %E = load i32* %A ; <i32> [#uses=1]
+ call void @test( i32 %E, i1 true )
+ br label %L3
+L3: ; preds = %L2, %L1
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll b/src/LLVM/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll
new file mode 100644
index 0000000..ffe603e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2005-06-30-ReadBeforeWrite.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -mem2reg -instcombine -S | grep store
+; PR590
+
+
+define void @zero(i8* %p, i32 %n) {
+entry:
+ %p_addr = alloca i8* ; <i8**> [#uses=2]
+ %n_addr = alloca i32 ; <i32*> [#uses=2]
+ %i = alloca i32 ; <i32*> [#uses=6]
+ %out = alloca i32 ; <i32*> [#uses=2]
+ %undef = alloca i32 ; <i32*> [#uses=2]
+ store i8* %p, i8** %p_addr
+ store i32 %n, i32* %n_addr
+ store i32 0, i32* %i
+ br label %loopentry
+loopentry: ; preds = %endif, %entry
+ %tmp.0 = load i32* %n_addr ; <i32> [#uses=1]
+ %tmp.1 = add i32 %tmp.0, 1 ; <i32> [#uses=1]
+ %tmp.2 = load i32* %i ; <i32> [#uses=1]
+ %tmp.3 = icmp sgt i32 %tmp.1, %tmp.2 ; <i1> [#uses=2]
+ %tmp.4 = zext i1 %tmp.3 to i32 ; <i32> [#uses=0]
+ br i1 %tmp.3, label %no_exit, label %return
+no_exit: ; preds = %loopentry
+ %tmp.5 = load i32* %undef ; <i32> [#uses=1]
+ store i32 %tmp.5, i32* %out
+ store i32 0, i32* %undef
+ %tmp.6 = load i32* %i ; <i32> [#uses=1]
+ %tmp.7 = icmp sgt i32 %tmp.6, 0 ; <i1> [#uses=2]
+ %tmp.8 = zext i1 %tmp.7 to i32 ; <i32> [#uses=0]
+ br i1 %tmp.7, label %then, label %endif
+then: ; preds = %no_exit
+ %tmp.9 = load i8** %p_addr ; <i8*> [#uses=1]
+ %tmp.10 = load i32* %i ; <i32> [#uses=1]
+ %tmp.11 = sub i32 %tmp.10, 1 ; <i32> [#uses=1]
+ %tmp.12 = getelementptr i8* %tmp.9, i32 %tmp.11 ; <i8*> [#uses=1]
+ %tmp.13 = load i32* %out ; <i32> [#uses=1]
+ %tmp.14 = trunc i32 %tmp.13 to i8 ; <i8> [#uses=1]
+ store i8 %tmp.14, i8* %tmp.12
+ br label %endif
+endif: ; preds = %then, %no_exit
+ %tmp.15 = load i32* %i ; <i32> [#uses=1]
+ %inc = add i32 %tmp.15, 1 ; <i32> [#uses=1]
+ store i32 %inc, i32* %i
+ br label %loopentry
+return: ; preds = %loopentry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2005-11-28-Crash.ll b/src/LLVM/test/Transforms/Mem2Reg/2005-11-28-Crash.ll
new file mode 100644
index 0000000..caa8ad9
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2005-11-28-Crash.ll
@@ -0,0 +1,62 @@
+; RUN: opt < %s -mem2reg -disable-output
+; PR670
+
+define void @printk(i32, ...) {
+entry:
+ %flags = alloca i32 ; <i32*> [#uses=2]
+ br i1 false, label %then.0, label %endif.0
+then.0: ; preds = %entry
+ br label %endif.0
+endif.0: ; preds = %then.0, %entry
+ store i32 0, i32* %flags
+ br label %loopentry
+loopentry: ; preds = %endif.3, %endif.0
+ br i1 false, label %no_exit, label %loopexit
+no_exit: ; preds = %loopentry
+ br i1 false, label %then.1, label %endif.1
+then.1: ; preds = %no_exit
+ br i1 false, label %shortcirc_done.0, label %shortcirc_next.0
+shortcirc_next.0: ; preds = %then.1
+ br label %shortcirc_done.0
+shortcirc_done.0: ; preds = %shortcirc_next.0, %then.1
+ br i1 false, label %shortcirc_done.1, label %shortcirc_next.1
+shortcirc_next.1: ; preds = %shortcirc_done.0
+ br label %shortcirc_done.1
+shortcirc_done.1: ; preds = %shortcirc_next.1, %shortcirc_done.0
+ br i1 false, label %shortcirc_done.2, label %shortcirc_next.2
+shortcirc_next.2: ; preds = %shortcirc_done.1
+ br label %shortcirc_done.2
+shortcirc_done.2: ; preds = %shortcirc_next.2, %shortcirc_done.1
+ br i1 false, label %then.2, label %endif.2
+then.2: ; preds = %shortcirc_done.2
+ br label %endif.2
+endif.2: ; preds = %then.2, %shortcirc_done.2
+ br label %endif.1
+endif.1: ; preds = %endif.2, %no_exit
+ br i1 false, label %then.3, label %endif.3
+then.3: ; preds = %endif.1
+ br label %endif.3
+endif.3: ; preds = %then.3, %endif.1
+ br label %loopentry
+loopexit: ; preds = %loopentry
+ br label %endif.4
+then.4: ; No predecessors!
+ %tmp.61 = load i32* %flags ; <i32> [#uses=0]
+ br label %out
+dead_block_after_goto: ; No predecessors!
+ br label %endif.4
+endif.4: ; preds = %dead_block_after_goto, %loopexit
+ br i1 false, label %then.5, label %else
+then.5: ; preds = %endif.4
+ br label %endif.5
+else: ; preds = %endif.4
+ br label %endif.5
+endif.5: ; preds = %else, %then.5
+ br label %out
+out: ; preds = %endif.5, %then.4
+ br label %return
+after_ret: ; No predecessors!
+ br label %return
+return: ; preds = %after_ret, %out
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll b/src/LLVM/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll
new file mode 100644
index 0000000..52a8375
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/2007-08-27-VolatileLoadsStores.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -std-compile-opts -S | grep volatile | count 3
+; PR1520
+; Don't promote volatile loads/stores. This is really needed to handle setjmp/lonjmp properly.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.__jmp_buf_tag = type { [6 x i32], i32, %struct.__sigset_t }
+ %struct.__sigset_t = type { [32 x i32] }
+@j = external global [1 x %struct.__jmp_buf_tag] ; <[1 x %struct.__jmp_buf_tag]*> [#uses=1]
+
+define i32 @f() {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %v = alloca i32, align 4 ; <i32*> [#uses=3]
+ %tmp = alloca i32, align 4 ; <i32*> [#uses=3]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ volatile store i32 0, i32* %v, align 4
+ %tmp1 = call i32 @_setjmp( %struct.__jmp_buf_tag* getelementptr ([1 x %struct.__jmp_buf_tag]* @j, i32 0, i32 0) ) ; <i32> [#uses=1]
+ %tmp2 = icmp ne i32 %tmp1, 0 ; <i1> [#uses=1]
+ %tmp23 = zext i1 %tmp2 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp23, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb, label %bb5
+
+bb: ; preds = %entry
+ %tmp4 = volatile load i32* %v, align 4 ; <i32> [#uses=1]
+ store i32 %tmp4, i32* %tmp, align 4
+ br label %bb6
+
+bb5: ; preds = %entry
+ volatile store i32 1, i32* %v, align 4
+ call void @g( )
+ store i32 0, i32* %tmp, align 4
+ br label %bb6
+
+bb6: ; preds = %bb5, %bb
+ %tmp7 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ store i32 %tmp7, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %bb6
+ %retval8 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval8
+}
+
+declare i32 @_setjmp(%struct.__jmp_buf_tag*) returns_twice
+
+declare void @g()
diff --git a/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo.ll b/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo.ll
new file mode 100644
index 0000000..2f1ccb4
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -mem2reg -S | FileCheck %s
+
+define double @testfunc(i32 %i, double %j) nounwind ssp {
+entry:
+ %i_addr = alloca i32 ; <i32*> [#uses=2]
+ %j_addr = alloca double ; <double*> [#uses=2]
+ %retval = alloca double ; <double*> [#uses=2]
+ %0 = alloca double ; <double*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.declare(metadata !{i32* %i_addr}, metadata !0), !dbg !8
+; CHECK: call void @llvm.dbg.value(metadata !{i32 %i}, i64 0, metadata !0)
+; CHECK: call void @llvm.dbg.value(metadata !{double %j}, i64 0, metadata !9)
+ store i32 %i, i32* %i_addr
+ call void @llvm.dbg.declare(metadata !{double* %j_addr}, metadata !9), !dbg !8
+ store double %j, double* %j_addr
+ %1 = load i32* %i_addr, align 4, !dbg !10 ; <i32> [#uses=1]
+ %2 = add nsw i32 %1, 1, !dbg !10 ; <i32> [#uses=1]
+ %3 = sitofp i32 %2 to double, !dbg !10 ; <double> [#uses=1]
+ %4 = load double* %j_addr, align 8, !dbg !10 ; <double> [#uses=1]
+ %5 = fadd double %3, %4, !dbg !10 ; <double> [#uses=1]
+ store double %5, double* %0, align 8, !dbg !10
+ %6 = load double* %0, align 8, !dbg !10 ; <double> [#uses=1]
+ store double %6, double* %retval, align 8, !dbg !10
+ br label %return, !dbg !10
+
+return: ; preds = %entry
+ %retval1 = load double* %retval, !dbg !10 ; <double> [#uses=1]
+ ret double %retval1, !dbg !10
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+!0 = metadata !{i32 524545, metadata !1, metadata !"i", metadata !2, i32 2, metadata !7} ; [ DW_TAG_arg_variable ]
+!1 = metadata !{i32 524334, i32 0, metadata !2, metadata !"testfunc", metadata !"testfunc", metadata !"testfunc", metadata !2, i32 2, metadata !4, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false} ; [ DW_TAG_subprogram ]
+!2 = metadata !{i32 524329, metadata !"testfunc.c", metadata !"/tmp", metadata !3} ; [ DW_TAG_file_type ]
+!3 = metadata !{i32 524305, i32 0, i32 1, metadata !"testfunc.c", metadata !"/tmp", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!4 = metadata !{i32 524309, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !5, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!5 = metadata !{metadata !6, metadata !7, metadata !6}
+!6 = metadata !{i32 524324, metadata !2, metadata !"double", metadata !2, i32 0, i64 64, i64 64, i64 0, i32 0, i32 4} ; [ DW_TAG_base_type ]
+!7 = metadata !{i32 524324, metadata !2, metadata !"int", metadata !2, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!8 = metadata !{i32 2, i32 0, metadata !1, null}
+!9 = metadata !{i32 524545, metadata !1, metadata !"j", metadata !2, i32 2, metadata !6} ; [ DW_TAG_arg_variable ]
+!10 = metadata !{i32 3, i32 0, metadata !11, null}
+!11 = metadata !{i32 524299, metadata !1, i32 2, i32 0} ; [ DW_TAG_lexical_block ]
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo2.ll b/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo2.ll
new file mode 100644
index 0000000..4cb621f
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/ConvertDebugInfo2.ll
@@ -0,0 +1,52 @@
+; RUN: opt -mem2reg < %s | llvm-dis | grep ".dbg " | count 7
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+declare void @foo(i32, i64, i8*)
+
+define void @baz(i32 %a) nounwind ssp {
+entry:
+ %x_addr.i = alloca i32 ; <i32*> [#uses=2]
+ %y_addr.i = alloca i64 ; <i64*> [#uses=2]
+ %z_addr.i = alloca i8* ; <i8**> [#uses=2]
+ %a_addr = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.declare(metadata !{i32* %a_addr}, metadata !0), !dbg !7
+ store i32 %a, i32* %a_addr
+ %0 = load i32* %a_addr, align 4, !dbg !8 ; <i32> [#uses=1]
+ call void @llvm.dbg.declare(metadata !{i32* %x_addr.i}, metadata !9) nounwind, !dbg !15
+ store i32 %0, i32* %x_addr.i
+ call void @llvm.dbg.declare(metadata !{i64* %y_addr.i}, metadata !16) nounwind, !dbg !15
+ store i64 55, i64* %y_addr.i
+ call void @llvm.dbg.declare(metadata !{i8** %z_addr.i}, metadata !17) nounwind, !dbg !15
+ store i8* bitcast (void (i32)* @baz to i8*), i8** %z_addr.i
+ %1 = load i32* %x_addr.i, align 4, !dbg !18 ; <i32> [#uses=1]
+ %2 = load i64* %y_addr.i, align 8, !dbg !18 ; <i64> [#uses=1]
+ %3 = load i8** %z_addr.i, align 8, !dbg !18 ; <i8*> [#uses=1]
+ call void @foo(i32 %1, i64 %2, i8* %3) nounwind, !dbg !18
+ br label %return, !dbg !19
+
+return: ; preds = %entry
+ ret void, !dbg !19
+}
+
+!0 = metadata !{i32 524545, metadata !1, metadata !"a", metadata !2, i32 8, metadata !6} ; [ DW_TAG_arg_variable ]
+!1 = metadata !{i32 524334, i32 0, metadata !2, metadata !"baz", metadata !"baz", metadata !"baz", metadata !2, i32 8, metadata !4, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false} ; [ DW_TAG_subprogram ]
+!2 = metadata !{i32 524329, metadata !"bar.c", metadata !"/tmp/", metadata !3} ; [ DW_TAG_file_type ]
+!3 = metadata !{i32 524305, i32 0, i32 1, metadata !"bar.c", metadata !"/tmp/", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!4 = metadata !{i32 524309, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !5, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!5 = metadata !{null, metadata !6}
+!6 = metadata !{i32 524324, metadata !2, metadata !"int", metadata !2, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!7 = metadata !{i32 8, i32 0, metadata !1, null}
+!8 = metadata !{i32 9, i32 0, metadata !1, null}
+!9 = metadata !{i32 524545, metadata !10, metadata !"x", metadata !2, i32 4, metadata !6} ; [ DW_TAG_arg_variable ]
+!10 = metadata !{i32 524334, i32 0, metadata !2, metadata !"bar", metadata !"bar", metadata !"bar", metadata !2, i32 4, metadata !11, i1 true, i1 true, i32 0, i32 0, null, i1 false, i1 false} ; [ DW_TAG_subprogram ]
+!11 = metadata !{i32 524309, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !12, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!12 = metadata !{null, metadata !6, metadata !13, metadata !14}
+!13 = metadata !{i32 524324, metadata !2, metadata !"long int", metadata !2, i32 0, i64 64, i64 64, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!14 = metadata !{i32 524303, metadata !2, metadata !"", metadata !2, i32 0, i64 64, i64 64, i64 0, i32 0, null} ; [ DW_TAG_pointer_type ]
+!15 = metadata !{i32 4, i32 0, metadata !10, metadata !8}
+!16 = metadata !{i32 524545, metadata !10, metadata !"y", metadata !2, i32 4, metadata !13} ; [ DW_TAG_arg_variable ]
+!17 = metadata !{i32 524545, metadata !10, metadata !"z", metadata !2, i32 4, metadata !14} ; [ DW_TAG_arg_variable ]
+!18 = metadata !{i32 5, i32 0, metadata !10, metadata !8}
+!19 = metadata !{i32 10, i32 0, metadata !1, null}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/PromoteMemToRegister.ll b/src/LLVM/test/Transforms/Mem2Reg/PromoteMemToRegister.ll
new file mode 100644
index 0000000..80d4fcc
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/PromoteMemToRegister.ll
@@ -0,0 +1,18 @@
+; Simple sanity check testcase. Both alloca's should be eliminated.
+; RUN: opt < %s -mem2reg -S | not grep alloca
+
+define double @testfunc(i32 %i, double %j) {
+ %I = alloca i32 ; <i32*> [#uses=4]
+ %J = alloca double ; <double*> [#uses=2]
+ store i32 %i, i32* %I
+ store double %j, double* %J
+ %t1 = load i32* %I ; <i32> [#uses=1]
+ %t2 = add i32 %t1, 1 ; <i32> [#uses=1]
+ store i32 %t2, i32* %I
+ %t3 = load i32* %I ; <i32> [#uses=1]
+ %t4 = sitofp i32 %t3 to double ; <double> [#uses=1]
+ %t5 = load double* %J ; <double> [#uses=1]
+ %t6 = fmul double %t4, %t5 ; <double> [#uses=1]
+ ret double %t6
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/UndefValuesMerge.ll b/src/LLVM/test/Transforms/Mem2Reg/UndefValuesMerge.ll
new file mode 100644
index 0000000..539a870
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/UndefValuesMerge.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -mem2reg -S | not grep phi
+
+define i32 @testfunc(i1 %C, i32 %i, i8 %j) {
+ %I = alloca i32 ; <i32*> [#uses=2]
+ br i1 %C, label %T, label %Cont
+T: ; preds = %0
+ store i32 %i, i32* %I
+ br label %Cont
+Cont: ; preds = %T, %0
+ %Y = load i32* %I ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/atomic.ll b/src/LLVM/test/Transforms/Mem2Reg/atomic.ll
new file mode 100644
index 0000000..982c413
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/atomic.ll
@@ -0,0 +1,12 @@
+; RUN: opt -mem2reg < %s -S | FileCheck %s
+
+; mem2reg is allowed with arbitrary atomic operations (although we only support
+; it for atomic load and store at the moment).
+define i32 @test1(i32 %x) {
+; CHECK: @test1
+; CHECK: ret i32 %x
+ %a = alloca i32
+ store atomic i32 %x, i32* %a seq_cst, align 4
+ %r = load atomic i32* %a seq_cst, align 4
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/Mem2Reg/crash.ll b/src/LLVM/test/Transforms/Mem2Reg/crash.ll
new file mode 100644
index 0000000..59e2c0b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/crash.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -mem2reg -S
+; PR5023
+
+declare i32 @test1f()
+
+define i32 @test1() {
+entry:
+ %whichFlag = alloca i32
+ %A = invoke i32 @test1f()
+ to label %invcont2 unwind label %lpad86
+
+invcont2:
+ store i32 %A, i32* %whichFlag
+ br label %bb15
+
+bb15:
+ %B = load i32* %whichFlag
+ ret i32 %B
+
+lpad86:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ br label %bb15
+
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+
+define i32 @test2() {
+entry:
+ %whichFlag = alloca i32
+ br label %bb15
+
+bb15:
+ %B = load i32* %whichFlag
+ ret i32 %B
+
+invcont2:
+ %C = load i32* %whichFlag
+ store i32 %C, i32* %whichFlag
+ br label %bb15
+}
+
diff --git a/src/LLVM/test/Transforms/Mem2Reg/dg.exp b/src/LLVM/test/Transforms/Mem2Reg/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/Mem2Reg/ignore-lifetime.ll b/src/LLVM/test/Transforms/Mem2Reg/ignore-lifetime.ll
new file mode 100644
index 0000000..5e4f9bf
--- /dev/null
+++ b/src/LLVM/test/Transforms/Mem2Reg/ignore-lifetime.ll
@@ -0,0 +1,26 @@
+; RUN: opt -mem2reg -S -o - < %s | FileCheck %s
+
+declare void @llvm.lifetime.start(i64 %size, i8* nocapture %ptr)
+declare void @llvm.lifetime.end(i64 %size, i8* nocapture %ptr)
+
+define void @test1() {
+; CHECK: test1
+; CHECK-NOT: alloca
+ %A = alloca i32
+ %B = bitcast i32* %A to i8*
+ call void @llvm.lifetime.start(i64 2, i8* %B)
+ store i32 1, i32* %A
+ call void @llvm.lifetime.end(i64 2, i8* %B)
+ ret void
+}
+
+define void @test2() {
+; CHECK: test2
+; CHECK-NOT: alloca
+ %A = alloca {i8, i16}
+ %B = getelementptr {i8, i16}* %A, i32 0, i32 0
+ call void @llvm.lifetime.start(i64 2, i8* %B)
+ store {i8, i16} zeroinitializer, {i8, i16}* %A
+ call void @llvm.lifetime.end(i64 2, i8* %B)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/2008-02-24-MultipleUseofSRet.ll b/src/LLVM/test/Transforms/MemCpyOpt/2008-02-24-MultipleUseofSRet.ll
new file mode 100644
index 0000000..b95ad91
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/2008-02-24-MultipleUseofSRet.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -basicaa -memcpyopt -dse -S | grep {call.*initialize} | not grep memtmp
+; PR2077
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+%0 = type { x86_fp80, x86_fp80 }
+
+define internal fastcc void @initialize(%0* noalias sret %agg.result) nounwind {
+entry:
+ %agg.result.03 = getelementptr %0* %agg.result, i32 0, i32 0
+ store x86_fp80 0xK00000000000000000000, x86_fp80* %agg.result.03
+ %agg.result.15 = getelementptr %0* %agg.result, i32 0, i32 1
+ store x86_fp80 0xK00000000000000000000, x86_fp80* %agg.result.15
+ ret void
+}
+
+declare fastcc x86_fp80 @passed_uninitialized(%0*) nounwind
+
+define fastcc void @badly_optimized() nounwind {
+entry:
+ %z = alloca %0
+ %tmp = alloca %0
+ %memtmp = alloca %0, align 8
+ call fastcc void @initialize(%0* noalias sret %memtmp)
+ %tmp1 = bitcast %0* %tmp to i8*
+ %memtmp2 = bitcast %0* %memtmp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp1, i8* %memtmp2, i32 24, i32 8, i1 false)
+ %z3 = bitcast %0* %z to i8*
+ %tmp4 = bitcast %0* %tmp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %z3, i8* %tmp4, i32 24, i32 8, i1 false)
+ %tmp5 = call fastcc x86_fp80 @passed_uninitialized(%0* %z)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/2008-03-13-ReturnSlotBitcast.ll b/src/LLVM/test/Transforms/MemCpyOpt/2008-03-13-ReturnSlotBitcast.ll
new file mode 100644
index 0000000..24cf576
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/2008-03-13-ReturnSlotBitcast.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -basicaa -memcpyopt -S | not grep {call.*memcpy.}
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+%a = type { i32 }
+%b = type { float }
+
+declare void @g(%a*)
+
+define float @f() {
+entry:
+ %a_var = alloca %a
+ %b_var = alloca %b
+ call void @g(%a* %a_var)
+ %a_i8 = bitcast %a* %a_var to i8*
+ %b_i8 = bitcast %b* %b_var to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b_i8, i8* %a_i8, i32 4, i32 4, i1 false)
+ %tmp1 = getelementptr %b* %b_var, i32 0, i32 0
+ %tmp2 = load float* %tmp1
+ ret float %tmp2
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/2011-06-02-CallSlotOverwritten.ll b/src/LLVM/test/Transforms/MemCpyOpt/2011-06-02-CallSlotOverwritten.ll
new file mode 100644
index 0000000..132966e
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/2011-06-02-CallSlotOverwritten.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -basicaa -memcpyopt -S | FileCheck %s
+; PR10067
+; Make sure the call+copy isn't optimized in such a way that
+; %ret ends up with the wrong value.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin10"
+
+%struct1 = type { i32, i32 }
+%struct2 = type { %struct1, i8* }
+
+declare void @bar(%struct1* nocapture sret %agg.result) nounwind
+
+define i32 @foo() nounwind {
+ %x = alloca %struct1, align 8
+ %y = alloca %struct2, align 8
+ call void @bar(%struct1* sret %x) nounwind
+; CHECK: call void @bar(%struct1* sret %x)
+
+ %gepn1 = getelementptr inbounds %struct2* %y, i32 0, i32 0, i32 0
+ store i32 0, i32* %gepn1, align 8
+ %gepn2 = getelementptr inbounds %struct2* %y, i32 0, i32 0, i32 1
+ store i32 0, i32* %gepn2, align 4
+
+ %bit1 = bitcast %struct1* %x to i64*
+ %bit2 = bitcast %struct2* %y to i64*
+ %load = load i64* %bit1, align 8
+ store i64 %load, i64* %bit2, align 8
+
+; CHECK: %load = load i64* %bit1, align 8
+; CHECK: store i64 %load, i64* %bit2, align 8
+
+ %gep1 = getelementptr %struct2* %y, i32 0, i32 0, i32 0
+ %ret = load i32* %gep1
+ ret i32 %ret
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/align.ll b/src/LLVM/test/Transforms/MemCpyOpt/align.ll
new file mode 100644
index 0000000..b1f900d
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/align.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -S -memcpyopt | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+; The resulting memset is only 4-byte aligned, despite containing
+; a 16-byte aligned store in the middle.
+
+; CHECK: call void @llvm.memset.p0i8.i64(i8* {{.*}}, i8 0, i64 16, i32 4, i1 false)
+
+define void @foo(i32* %p) {
+ %a0 = getelementptr i32* %p, i64 0
+ store i32 0, i32* %a0, align 4
+ %a1 = getelementptr i32* %p, i64 1
+ store i32 0, i32* %a1, align 16
+ %a2 = getelementptr i32* %p, i64 2
+ store i32 0, i32* %a2, align 4
+ %a3 = getelementptr i32* %p, i64 3
+ store i32 0, i32* %a3, align 4
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/atomic.ll b/src/LLVM/test/Transforms/MemCpyOpt/atomic.ll
new file mode 100644
index 0000000..f351e67
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/atomic.ll
@@ -0,0 +1,41 @@
+; RUN: opt -basicaa -memcpyopt -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+@x = global i32 0
+
+declare void @otherf(i32*)
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+
+; memcpyopt should not touch atomic ops
+define void @test1() nounwind uwtable ssp {
+; CHECK: test1
+; CHECK: store atomic
+ %x = alloca [101 x i32], align 16
+ %bc = bitcast [101 x i32]* %x to i8*
+ call void @llvm.memset.p0i8.i64(i8* %bc, i8 0, i64 400, i32 16, i1 false)
+ %gep1 = getelementptr inbounds [101 x i32]* %x, i32 0, i32 100
+ store atomic i32 0, i32* %gep1 unordered, align 4
+ %gep2 = getelementptr inbounds [101 x i32]* %x, i32 0, i32 0
+ call void @otherf(i32* %gep2)
+ ret void
+}
+
+; memcpyopt across unordered store
+define void @test2() nounwind uwtable ssp {
+; CHECK: test2
+; CHECK: call
+; CHECK-NEXT: store atomic
+; CHECK-NEXT: call
+ %old = alloca i32
+ %new = alloca i32
+ call void @otherf(i32* nocapture %old)
+ store atomic i32 0, i32* @x unordered, align 4
+ %v = load i32* %old
+ store i32 %v, i32* %new
+ call void @otherf(i32* nocapture %new)
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/crash.ll b/src/LLVM/test/Transforms/MemCpyOpt/crash.ll
new file mode 100644
index 0000000..cc3a6b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/crash.ll
@@ -0,0 +1,58 @@
+; RUN: opt < %s -basicaa -memcpyopt -disable-output
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "armv7-eabi"
+
+%struct.qw = type { [4 x float] }
+%struct.bar = type { %struct.qw, %struct.qw, %struct.qw, %struct.qw, %struct.qw, float, float}
+
+; PR4882
+define void @test1(%struct.bar* %this) {
+entry:
+ %0 = getelementptr inbounds %struct.bar* %this, i32 0, i32 0, i32 0, i32 0
+ store float 0.000000e+00, float* %0, align 4
+ %1 = getelementptr inbounds %struct.bar* %this, i32 0, i32 0, i32 0, i32 1
+ store float 0.000000e+00, float* %1, align 4
+ %2 = getelementptr inbounds %struct.bar* %this, i32 0, i32 0, i32 0, i32 2
+ store float 0.000000e+00, float* %2, align 4
+ %3 = getelementptr inbounds %struct.bar* %this, i32 0, i32 0, i32 0, i32 3
+ store float 0.000000e+00, float* %3, align 4
+ %4 = getelementptr inbounds %struct.bar* %this, i32 0, i32 1, i32 0, i32 0
+ store float 0.000000e+00, float* %4, align 4
+ %5 = getelementptr inbounds %struct.bar* %this, i32 0, i32 1, i32 0, i32 1
+ store float 0.000000e+00, float* %5, align 4
+ %6 = getelementptr inbounds %struct.bar* %this, i32 0, i32 1, i32 0, i32 2
+ store float 0.000000e+00, float* %6, align 4
+ %7 = getelementptr inbounds %struct.bar* %this, i32 0, i32 1, i32 0, i32 3
+ store float 0.000000e+00, float* %7, align 4
+ %8 = getelementptr inbounds %struct.bar* %this, i32 0, i32 3, i32 0, i32 1
+ store float 0.000000e+00, float* %8, align 4
+ %9 = getelementptr inbounds %struct.bar* %this, i32 0, i32 3, i32 0, i32 2
+ store float 0.000000e+00, float* %9, align 4
+ %10 = getelementptr inbounds %struct.bar* %this, i32 0, i32 3, i32 0, i32 3
+ store float 0.000000e+00, float* %10, align 4
+ %11 = getelementptr inbounds %struct.bar* %this, i32 0, i32 4, i32 0, i32 0
+ store float 0.000000e+00, float* %11, align 4
+ %12 = getelementptr inbounds %struct.bar* %this, i32 0, i32 4, i32 0, i32 1
+ store float 0.000000e+00, float* %12, align 4
+ %13 = getelementptr inbounds %struct.bar* %this, i32 0, i32 4, i32 0, i32 2
+ store float 0.000000e+00, float* %13, align 4
+ %14 = getelementptr inbounds %struct.bar* %this, i32 0, i32 4, i32 0, i32 3
+ store float 0.000000e+00, float* %14, align 4
+ %15 = getelementptr inbounds %struct.bar* %this, i32 0, i32 5
+ store float 0.000000e+00, float* %15, align 4
+ unreachable
+}
+
+; PR8753
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32,
+i1) nounwind
+
+define void @test2(i32 %cmd) nounwind {
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* undef, i64 20, i32 1, i1
+false) nounwind
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* null, i8* undef, i64 20, i32 1, i1
+false) nounwind
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/dg.exp b/src/LLVM/test/Transforms/MemCpyOpt/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/form-memset.ll b/src/LLVM/test/Transforms/MemCpyOpt/form-memset.ll
new file mode 100644
index 0000000..1ac97e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/form-memset.ll
@@ -0,0 +1,222 @@
+; RUN: opt < %s -memcpyopt -S | FileCheck %s
+
+; All the stores in this example should be merged into a single memset.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+define void @test1(i8 signext %c) nounwind {
+entry:
+ %x = alloca [19 x i8] ; <[19 x i8]*> [#uses=20]
+ %tmp = getelementptr [19 x i8]* %x, i32 0, i32 0 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp, align 1
+ %tmp5 = getelementptr [19 x i8]* %x, i32 0, i32 1 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp5, align 1
+ %tmp9 = getelementptr [19 x i8]* %x, i32 0, i32 2 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp9, align 1
+ %tmp13 = getelementptr [19 x i8]* %x, i32 0, i32 3 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp13, align 1
+ %tmp17 = getelementptr [19 x i8]* %x, i32 0, i32 4 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp17, align 1
+ %tmp21 = getelementptr [19 x i8]* %x, i32 0, i32 5 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp21, align 1
+ %tmp25 = getelementptr [19 x i8]* %x, i32 0, i32 6 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp25, align 1
+ %tmp29 = getelementptr [19 x i8]* %x, i32 0, i32 7 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp29, align 1
+ %tmp33 = getelementptr [19 x i8]* %x, i32 0, i32 8 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp33, align 1
+ %tmp37 = getelementptr [19 x i8]* %x, i32 0, i32 9 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp37, align 1
+ %tmp41 = getelementptr [19 x i8]* %x, i32 0, i32 10 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp41, align 1
+ %tmp45 = getelementptr [19 x i8]* %x, i32 0, i32 11 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp45, align 1
+ %tmp49 = getelementptr [19 x i8]* %x, i32 0, i32 12 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp49, align 1
+ %tmp53 = getelementptr [19 x i8]* %x, i32 0, i32 13 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp53, align 1
+ %tmp57 = getelementptr [19 x i8]* %x, i32 0, i32 14 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp57, align 1
+ %tmp61 = getelementptr [19 x i8]* %x, i32 0, i32 15 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp61, align 1
+ %tmp65 = getelementptr [19 x i8]* %x, i32 0, i32 16 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp65, align 1
+ %tmp69 = getelementptr [19 x i8]* %x, i32 0, i32 17 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp69, align 1
+ %tmp73 = getelementptr [19 x i8]* %x, i32 0, i32 18 ; <i8*> [#uses=1]
+ store i8 %c, i8* %tmp73, align 1
+ %tmp76 = call i32 (...)* @bar( [19 x i8]* %x ) nounwind
+ ret void
+; CHECK: @test1
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64
+; CHECK-NOT: store
+; CHECK: ret
+}
+
+declare i32 @bar(...)
+
+
+ %struct.MV = type { i16, i16 }
+
+define void @test2() nounwind {
+entry:
+ %ref_idx = alloca [8 x i8] ; <[8 x i8]*> [#uses=8]
+ %left_mvd = alloca [8 x %struct.MV] ; <[8 x %struct.MV]*> [#uses=17]
+ %up_mvd = alloca [8 x %struct.MV] ; <[8 x %struct.MV]*> [#uses=17]
+ %tmp20 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 7 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp20, align 1
+ %tmp23 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 6 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp23, align 1
+ %tmp26 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 5 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp26, align 1
+ %tmp29 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 4 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp29, align 1
+ %tmp32 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 3 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp32, align 1
+ %tmp35 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 2 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp35, align 1
+ %tmp38 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 1 ; <i8*> [#uses=1]
+ store i8 -1, i8* %tmp38, align 1
+ %tmp41 = getelementptr [8 x i8]* %ref_idx, i32 0, i32 0 ; <i8*> [#uses=2]
+ store i8 -1, i8* %tmp41, align 1
+ %tmp43 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 7, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp43, align 2
+ %tmp46 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 7, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp46, align 2
+ %tmp57 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 6, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp57, align 2
+ %tmp60 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 6, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp60, align 2
+ %tmp71 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 5, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp71, align 2
+ %tmp74 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 5, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp74, align 2
+ %tmp85 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 4, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp85, align 2
+ %tmp88 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 4, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp88, align 2
+ %tmp99 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 3, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp99, align 2
+ %tmp102 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 3, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp102, align 2
+ %tmp113 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 2, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp113, align 2
+ %tmp116 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 2, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp116, align 2
+ %tmp127 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 1, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp127, align 2
+ %tmp130 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 1, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp130, align 2
+ %tmp141 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 0, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp141, align 8
+ %tmp144 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 0, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp144, align 2
+ %tmp148 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 7, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp148, align 2
+ %tmp151 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 7, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp151, align 2
+ %tmp162 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 6, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp162, align 2
+ %tmp165 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 6, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp165, align 2
+ %tmp176 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 5, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp176, align 2
+ %tmp179 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 5, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp179, align 2
+ %tmp190 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 4, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp190, align 2
+ %tmp193 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 4, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp193, align 2
+ %tmp204 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 3, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp204, align 2
+ %tmp207 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 3, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp207, align 2
+ %tmp218 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 2, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp218, align 2
+ %tmp221 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 2, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp221, align 2
+ %tmp232 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 1, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp232, align 2
+ %tmp235 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 1, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp235, align 2
+ %tmp246 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 0, i32 0 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp246, align 8
+ %tmp249 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 0, i32 1 ; <i16*> [#uses=1]
+ store i16 0, i16* %tmp249, align 2
+ %up_mvd252 = getelementptr [8 x %struct.MV]* %up_mvd, i32 0, i32 0 ; <%struct.MV*> [#uses=1]
+ %left_mvd253 = getelementptr [8 x %struct.MV]* %left_mvd, i32 0, i32 0 ; <%struct.MV*> [#uses=1]
+ call void @foo( %struct.MV* %up_mvd252, %struct.MV* %left_mvd253, i8* %tmp41 ) nounwind
+ ret void
+
+; CHECK: @test2
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %tmp41, i8 -1, i64 8, i32 1, i1 false)
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 32, i32 8, i1 false)
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 32, i32 8, i1 false)
+; CHECK-NOT: store
+; CHECK: ret
+}
+
+declare void @foo(%struct.MV*, %struct.MV*, i8*)
+
+
+; Store followed by memset.
+define void @test3(i32* nocapture %P) nounwind ssp {
+entry:
+ %arrayidx = getelementptr inbounds i32* %P, i64 1
+ store i32 0, i32* %arrayidx, align 4
+ %add.ptr = getelementptr inbounds i32* %P, i64 2
+ %0 = bitcast i32* %add.ptr to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i32 1, i1 false)
+ ret void
+; CHECK: @test3
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 15, i32 4, i1 false)
+}
+
+; store followed by memset, different offset scenario
+define void @test4(i32* nocapture %P) nounwind ssp {
+entry:
+ store i32 0, i32* %P, align 4
+ %add.ptr = getelementptr inbounds i32* %P, i64 1
+ %0 = bitcast i32* %add.ptr to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i32 1, i1 false)
+ ret void
+; CHECK: @test4
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 15, i32 4, i1 false)
+}
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+
+; Memset followed by store.
+define void @test5(i32* nocapture %P) nounwind ssp {
+entry:
+ %add.ptr = getelementptr inbounds i32* %P, i64 2
+ %0 = bitcast i32* %add.ptr to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i32 1, i1 false)
+ %arrayidx = getelementptr inbounds i32* %P, i64 1
+ store i32 0, i32* %arrayidx, align 4
+ ret void
+; CHECK: @test5
+; CHECK-NOT: store
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 15, i32 4, i1 false)
+}
+
+;; Memset followed by memset.
+define void @test6(i32* nocapture %P) nounwind ssp {
+entry:
+ %0 = bitcast i32* %P to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 12, i32 1, i1 false)
+ %add.ptr = getelementptr inbounds i32* %P, i64 3
+ %1 = bitcast i32* %add.ptr to i8*
+ tail call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 12, i32 1, i1 false)
+ ret void
+; CHECK: @test6
+; CHECK: call void @llvm.memset.p0i8.i64(i8* %2, i8 0, i64 24, i32 1, i1 false)
+}
+
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/loadstore-sret.ll b/src/LLVM/test/Transforms/MemCpyOpt/loadstore-sret.ll
new file mode 100644
index 0000000..67e7137
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/loadstore-sret.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S < %s -basicaa -memcpyopt | FileCheck %s
+; <rdar://problem/8536696>
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+%"class.std::auto_ptr" = type { i32* }
+
+; CHECK: @_Z3foov
+define void @_Z3foov(%"class.std::auto_ptr"* noalias nocapture sret %agg.result) ssp {
+_ZNSt8auto_ptrIiED1Ev.exit:
+ %temp.lvalue = alloca %"class.std::auto_ptr", align 8
+; CHECK: call void @_Z3barv(%"class.std::auto_ptr"* sret %agg.result)
+ call void @_Z3barv(%"class.std::auto_ptr"* sret %temp.lvalue)
+ %tmp.i.i = getelementptr inbounds %"class.std::auto_ptr"* %temp.lvalue, i64 0, i32 0
+; CHECK-NOT: load
+ %tmp2.i.i = load i32** %tmp.i.i, align 8
+ %tmp.i.i4 = getelementptr inbounds %"class.std::auto_ptr"* %agg.result, i64 0, i32 0
+; CHECK-NOT: store
+ store i32* %tmp2.i.i, i32** %tmp.i.i4, align 8
+; CHECK: ret void
+ ret void
+}
+
+declare void @_Z3barv(%"class.std::auto_ptr"* sret)
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/memcpy-to-memset.ll b/src/LLVM/test/Transforms/MemCpyOpt/memcpy-to-memset.ll
new file mode 100644
index 0000000..b18d176
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/memcpy-to-memset.ll
@@ -0,0 +1,19 @@
+; RUN: opt -memcpyopt -S < %s | FileCheck %s
+
+@cst = internal constant [3 x i32] [i32 -1, i32 -1, i32 -1], align 4
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+declare void @foo(i32*) nounwind
+
+define void @test1() nounwind {
+ %arr = alloca [3 x i32], align 4
+ %arr_i8 = bitcast [3 x i32]* %arr to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %arr_i8, i8* bitcast ([3 x i32]* @cst to i8*), i64 12, i32 4, i1 false)
+ %arraydecay = getelementptr inbounds [3 x i32]* %arr, i64 0, i64 0
+ call void @foo(i32* %arraydecay) nounwind
+ ret void
+; CHECK: @test1
+; CHECK: call void @llvm.memset
+; CHECK-NOT: call void @llvm.memcpy
+; CHECK: ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/memcpy.ll b/src/LLVM/test/Transforms/MemCpyOpt/memcpy.ll
new file mode 100644
index 0000000..71d4d4e
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/memcpy.ll
@@ -0,0 +1,132 @@
+; RUN: opt < %s -basicaa -memcpyopt -dse -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin9"
+
+%0 = type { x86_fp80, x86_fp80 }
+%1 = type { i32, i32 }
+
+define void @test1(%0* sret %agg.result, x86_fp80 %z.0, x86_fp80 %z.1) nounwind {
+entry:
+ %tmp2 = alloca %0
+ %memtmp = alloca %0, align 16
+ %tmp5 = fsub x86_fp80 0xK80000000000000000000, %z.1
+ call void @ccoshl(%0* sret %memtmp, x86_fp80 %tmp5, x86_fp80 %z.0) nounwind
+ %tmp219 = bitcast %0* %tmp2 to i8*
+ %memtmp20 = bitcast %0* %memtmp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp219, i8* %memtmp20, i32 32, i32 16, i1 false)
+ %agg.result21 = bitcast %0* %agg.result to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result21, i8* %tmp219, i32 32, i32 16, i1 false)
+ ret void
+
+; Check that one of the memcpy's are removed.
+;; FIXME: PR 8643 We should be able to eliminate the last memcpy here.
+
+; CHECK: @test1
+; CHECK: call void @ccoshl
+; CHECK: call void @llvm.memcpy
+; CHECK-NOT: llvm.memcpy
+; CHECK: ret void
+}
+
+declare void @ccoshl(%0* sret , x86_fp80, x86_fp80) nounwind
+
+
+; The intermediate alloca and one of the memcpy's should be eliminated, the
+; other should be related with a memmove.
+define void @test2(i8* %P, i8* %Q) nounwind {
+ %memtmp = alloca %0, align 16
+ %R = bitcast %0* %memtmp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %R, i8* %P, i32 32, i32 16, i1 false)
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %Q, i8* %R, i32 32, i32 16, i1 false)
+ ret void
+
+; CHECK: @test2
+; CHECK-NEXT: call void @llvm.memmove{{.*}}(i8* %Q, i8* %P
+; CHECK-NEXT: ret void
+}
+
+
+
+
+@x = external global %0
+
+define void @test3(%0* noalias sret %agg.result) nounwind {
+ %x.0 = alloca %0
+ %x.01 = bitcast %0* %x.0 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %x.01, i8* bitcast (%0* @x to i8*), i32 32, i32 16, i1 false)
+ %agg.result2 = bitcast %0* %agg.result to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result2, i8* %x.01, i32 32, i32 16, i1 false)
+ ret void
+; CHECK: @test3
+; CHECK-NEXT: %agg.result2 = bitcast
+; CHECK-NEXT: call void @llvm.memcpy
+; CHECK-NEXT: ret void
+}
+
+
+; PR8644
+define void @test4(i8 *%P) {
+ %A = alloca %1
+ %a = bitcast %1* %A to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %P, i64 8, i32 4, i1 false)
+ call void @test4a(i8* byval align 1 %a)
+ ret void
+; CHECK: @test4
+; CHECK-NEXT: call void @test4a(
+}
+
+declare void @test4a(i8* byval align 1)
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+%struct.S = type { i128, [4 x i8]}
+
+@sS = external global %struct.S, align 16
+
+declare void @test5a(%struct.S* byval align 16) nounwind ssp
+
+
+; rdar://8713376 - This memcpy can't be eliminated.
+define i32 @test5(i32 %x) nounwind ssp {
+entry:
+ %y = alloca %struct.S, align 16
+ %tmp = bitcast %struct.S* %y to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* bitcast (%struct.S* @sS to i8*), i64 32, i32 16, i1 false)
+ %a = getelementptr %struct.S* %y, i64 0, i32 1, i64 0
+ store i8 4, i8* %a
+ call void @test5a(%struct.S* byval align 16 %y)
+ ret i32 0
+ ; CHECK: @test5(
+ ; CHECK: store i8 4
+ ; CHECK: call void @test5a(%struct.S* byval align 16 %y)
+}
+
+;; Noop memcpy should be zapped.
+define void @test6(i8 *%P) {
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %P, i64 8, i32 4, i1 false)
+ ret void
+; CHECK: @test6
+; CHECK-NEXT: ret void
+}
+
+
+; PR9794 - Should forward memcpy into byval argument even though the memcpy
+; isn't itself 8 byte aligned.
+%struct.p = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
+
+define i32 @test7(%struct.p* nocapture byval align 8 %q) nounwind ssp {
+entry:
+ %agg.tmp = alloca %struct.p, align 4
+ %tmp = bitcast %struct.p* %agg.tmp to i8*
+ %tmp1 = bitcast %struct.p* %q to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* %tmp1, i64 48, i32 4, i1 false)
+ %call = call i32 @g(%struct.p* byval align 8 %agg.tmp) nounwind
+ ret i32 %call
+; CHECK: @test7
+; CHECK: call i32 @g(%struct.p* byval align 8 %q) nounwind
+}
+
+declare i32 @g(%struct.p* byval align 8)
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/memmove.ll b/src/LLVM/test/Transforms/MemCpyOpt/memmove.ll
new file mode 100644
index 0000000..7f1667a
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/memmove.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -basicaa -memcpyopt -S | FileCheck %s
+; These memmoves should get optimized to memcpys.
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin9.0"
+
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+define i8* @test1(i8* nocapture %src) nounwind {
+entry:
+; CHECK: @test1
+; CHECK: call void @llvm.memcpy
+
+ %malloccall = tail call i8* @malloc(i32 trunc (i64 mul nuw (i64 ptrtoint (i8* getelementptr (i8* null, i32 1) to i64), i64 13) to i32))
+ %call3 = bitcast i8* %malloccall to [13 x i8]*
+ %call3.sub = getelementptr inbounds [13 x i8]* %call3, i64 0, i64 0
+ tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %call3.sub, i8* %src, i64 13, i32 1, i1 false)
+ ret i8* %call3.sub
+}
+declare noalias i8* @malloc(i32)
+
+
+define void @test2(i8* %P) nounwind {
+entry:
+; CHECK: @test2
+; CHECK: call void @llvm.memcpy
+ %add.ptr = getelementptr i8* %P, i64 16
+ tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %add.ptr, i64 16, i32 1, i1 false)
+ ret void
+}
+
+; This cannot be optimize because the src/dst really do overlap.
+define void @test3(i8* %P) nounwind {
+entry:
+; CHECK: @test3
+; CHECK: call void @llvm.memmove
+ %add.ptr = getelementptr i8* %P, i64 16
+ tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %add.ptr, i64 17, i32 1, i1 false)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/smaller.ll b/src/LLVM/test/Transforms/MemCpyOpt/smaller.ll
new file mode 100644
index 0000000..1d35582
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/smaller.ll
@@ -0,0 +1,28 @@
+; RUN: opt -memcpyopt -S < %s | FileCheck %s
+; rdar://8875553
+
+; Memcpyopt shouldn't optimize the second memcpy using the first
+; because the first has a smaller size.
+
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp, i8* getelementptr inbounds (%struct.s* @cell, i32 0, i32 0, i32 0), i32 16, i32 4, i1 false)
+
+target datalayout = "e-p:32:32:32"
+
+%struct.s = type { [11 x i8], i32 }
+
+@.str = private constant [11 x i8] c"0123456789\00"
+@cell = external global %struct.s
+
+declare void @check(%struct.s* byval %p) nounwind
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+define void @foo() nounwind {
+entry:
+ %agg.tmp = alloca %struct.s, align 4
+ store i32 99, i32* getelementptr inbounds (%struct.s* @cell, i32 0, i32 1), align 4
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* getelementptr inbounds (%struct.s* @cell, i32 0, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0), i32 11, i32 1, i1 false)
+ %tmp = getelementptr inbounds %struct.s* %agg.tmp, i32 0, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp, i8* getelementptr inbounds (%struct.s* @cell, i32 0, i32 0, i32 0), i32 16, i32 4, i1 false)
+ call void @check(%struct.s* byval %agg.tmp)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/MemCpyOpt/sret.ll b/src/LLVM/test/Transforms/MemCpyOpt/sret.ll
new file mode 100644
index 0000000..8eac7da
--- /dev/null
+++ b/src/LLVM/test/Transforms/MemCpyOpt/sret.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -basicaa -memcpyopt -S | not grep {call.*memcpy}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin9"
+
+%0 = type { x86_fp80, x86_fp80 }
+
+define void @ccosl(%0* noalias sret %agg.result, %0* byval align 8 %z) nounwind {
+entry:
+ %iz = alloca %0
+ %memtmp = alloca %0, align 16
+ %tmp1 = getelementptr %0* %z, i32 0, i32 1
+ %tmp2 = load x86_fp80* %tmp1, align 16
+ %tmp3 = fsub x86_fp80 0xK80000000000000000000, %tmp2
+ %tmp4 = getelementptr %0* %iz, i32 0, i32 1
+ %real = getelementptr %0* %iz, i32 0, i32 0
+ %tmp7 = getelementptr %0* %z, i32 0, i32 0
+ %tmp8 = load x86_fp80* %tmp7, align 16
+ store x86_fp80 %tmp3, x86_fp80* %real, align 16
+ store x86_fp80 %tmp8, x86_fp80* %tmp4, align 16
+ call void @ccoshl(%0* noalias sret %memtmp, %0* byval align 8 %iz) nounwind
+ %memtmp14 = bitcast %0* %memtmp to i8*
+ %agg.result15 = bitcast %0* %agg.result to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result15, i8* %memtmp14, i32 32, i32 16, i1 false)
+ ret void
+}
+
+declare void @ccoshl(%0* noalias sret, %0* byval) nounwind
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/MergeFunc/2011-02-08-RemoveEqual.ll b/src/LLVM/test/Transforms/MergeFunc/2011-02-08-RemoveEqual.ll
new file mode 100644
index 0000000..201903e
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/2011-02-08-RemoveEqual.ll
@@ -0,0 +1,276 @@
+; RUN: opt -mergefunc %s -disable-output
+; This used to crash.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+%"struct.kc::impl_Ccode_option" = type { %"struct.kc::impl_abstract_phylum" }
+%"struct.kc::impl_CexpressionDQ" = type { %"struct.kc::impl_Ccode_option", %"struct.kc::impl_Ccode_option"*, %"struct.kc::impl_CexpressionDQ"* }
+%"struct.kc::impl_Ctext" = type { %"struct.kc::impl_Ccode_option", i32, %"struct.kc::impl_casestring__Str"*, %"struct.kc::impl_Ctext_elem"*, %"struct.kc::impl_Ctext"* }
+%"struct.kc::impl_Ctext_elem" = type { %"struct.kc::impl_abstract_phylum", i32, %"struct.kc::impl_casestring__Str"* }
+%"struct.kc::impl_ID" = type { %"struct.kc::impl_abstract_phylum", %"struct.kc::impl_Ccode_option"*, %"struct.kc::impl_casestring__Str"*, i32, %"struct.kc::impl_casestring__Str"* }
+%"struct.kc::impl_abstract_phylum" = type { i32 (...)** }
+%"struct.kc::impl_ac_abstract_declarator_AcAbsdeclDirdecl" = type { %"struct.kc::impl_Ccode_option", %"struct.kc::impl_Ccode_option"*, %"struct.kc::impl_Ccode_option"* }
+%"struct.kc::impl_casestring__Str" = type { %"struct.kc::impl_abstract_phylum", i8* }
+%"struct.kc::impl_elem_patternrepresentation" = type { %"struct.kc::impl_abstract_phylum", i32, %"struct.kc::impl_casestring__Str"*, %"struct.kc::impl_ID"* }
+%"struct.kc::impl_fileline" = type { %"struct.kc::impl_abstract_phylum", %"struct.kc::impl_casestring__Str"*, i32 }
+%"struct.kc::impl_fileline_FileLine" = type { %"struct.kc::impl_fileline" }
+%"struct.kc::impl_outmostpatterns" = type { %"struct.kc::impl_Ccode_option", %"struct.kc::impl_elem_patternrepresentation"*, %"struct.kc::impl_outmostpatterns"* }
+%"struct.kc::impl_withcaseinfo_Withcaseinfo" = type { %"struct.kc::impl_Ccode_option", %"struct.kc::impl_outmostpatterns"*, %"struct.kc::impl_outmostpatterns"*, %"struct.kc::impl_Ctext"* }
+
+@_ZTVN2kc13impl_filelineE = external constant [13 x i32 (...)*], align 32
+@.str = external constant [1 x i8], align 1
+@_ZTVN2kc22impl_fileline_FileLineE = external constant [13 x i32 (...)*], align 32
+
+define void @_ZN2kc22impl_fileline_FileLineC2EPNS_20impl_casestring__StrEi(%"struct.kc::impl_fileline_FileLine"* %this, %"struct.kc::impl_casestring__Str"* %_file, i32 %_line) align 2 {
+entry:
+ %this_addr = alloca %"struct.kc::impl_fileline_FileLine"*, align 4
+ %_file_addr = alloca %"struct.kc::impl_casestring__Str"*, align 4
+ %_line_addr = alloca i32, align 4
+ %save_filt.150 = alloca i32
+ %save_eptr.149 = alloca i8*
+ %iftmp.99 = alloca %"struct.kc::impl_casestring__Str"*
+ %eh_exception = alloca i8*
+ %eh_selector = alloca i32
+ %"alloca point" = bitcast i32 0 to i32
+ store %"struct.kc::impl_fileline_FileLine"* %this, %"struct.kc::impl_fileline_FileLine"** %this_addr
+ store %"struct.kc::impl_casestring__Str"* %_file, %"struct.kc::impl_casestring__Str"** %_file_addr
+ store i32 %_line, i32* %_line_addr
+ %0 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %1 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %0, i32 0, i32 0
+ call void @_ZN2kc13impl_filelineC2Ev() nounwind
+ %2 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %3 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %2, i32 0, i32 0
+ %4 = getelementptr inbounds %"struct.kc::impl_fileline"* %3, i32 0, i32 0
+ %5 = getelementptr inbounds %"struct.kc::impl_abstract_phylum"* %4, i32 0, i32 0
+ store i32 (...)** getelementptr inbounds ([13 x i32 (...)*]* @_ZTVN2kc22impl_fileline_FileLineE, i32 0, i32 2), i32 (...)*** %5, align 4
+ %6 = load %"struct.kc::impl_casestring__Str"** %_file_addr, align 4
+ %7 = icmp eq %"struct.kc::impl_casestring__Str"* %6, null
+ br i1 %7, label %bb, label %bb1
+
+bb: ; preds = %entry
+ %8 = invoke %"struct.kc::impl_casestring__Str"* @_ZN2kc12mkcasestringEPKci()
+ to label %invcont unwind label %lpad
+
+invcont: ; preds = %bb
+ store %"struct.kc::impl_casestring__Str"* %8, %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ br label %bb2
+
+bb1: ; preds = %entry
+ %9 = load %"struct.kc::impl_casestring__Str"** %_file_addr, align 4
+ store %"struct.kc::impl_casestring__Str"* %9, %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ br label %bb2
+
+bb2: ; preds = %bb1, %invcont
+ %10 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %11 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %10, i32 0, i32 0
+ %12 = getelementptr inbounds %"struct.kc::impl_fileline"* %11, i32 0, i32 1
+ %13 = load %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ store %"struct.kc::impl_casestring__Str"* %13, %"struct.kc::impl_casestring__Str"** %12, align 4
+ %14 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %15 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %14, i32 0, i32 0
+ %16 = getelementptr inbounds %"struct.kc::impl_fileline"* %15, i32 0, i32 2
+ %17 = load i32* %_line_addr, align 4
+ store i32 %17, i32* %16, align 4
+ ret void
+
+lpad: ; preds = %bb
+ %eh_ptr = call i8* @llvm.eh.exception()
+ store i8* %eh_ptr, i8** %eh_exception
+ %eh_ptr4 = load i8** %eh_exception
+ %eh_select5 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %eh_ptr4, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0)
+ store i32 %eh_select5, i32* %eh_selector
+ %eh_select = load i32* %eh_selector
+ store i32 %eh_select, i32* %save_filt.150, align 4
+ %eh_value = load i8** %eh_exception
+ store i8* %eh_value, i8** %save_eptr.149, align 4
+ %18 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %19 = bitcast %"struct.kc::impl_fileline_FileLine"* %18 to %"struct.kc::impl_fileline"*
+ call void @_ZN2kc13impl_filelineD2Ev(%"struct.kc::impl_fileline"* %19) nounwind
+ %20 = load i8** %save_eptr.149, align 4
+ store i8* %20, i8** %eh_exception, align 4
+ %21 = load i32* %save_filt.150, align 4
+ store i32 %21, i32* %eh_selector, align 4
+ %eh_ptr6 = load i8** %eh_exception
+ call void @_Unwind_Resume_or_Rethrow()
+ unreachable
+}
+
+declare void @_ZN2kc13impl_filelineC2Ev() nounwind align 2
+
+define void @_ZN2kc13impl_filelineD1Ev(%"struct.kc::impl_fileline"* %this) nounwind align 2 {
+entry:
+ %this_addr = alloca %"struct.kc::impl_fileline"*, align 4
+ %"alloca point" = bitcast i32 0 to i32
+ store %"struct.kc::impl_fileline"* %this, %"struct.kc::impl_fileline"** %this_addr
+ %0 = load %"struct.kc::impl_fileline"** %this_addr, align 4
+ %1 = getelementptr inbounds %"struct.kc::impl_fileline"* %0, i32 0, i32 0
+ %2 = getelementptr inbounds %"struct.kc::impl_abstract_phylum"* %1, i32 0, i32 0
+ store i32 (...)** getelementptr inbounds ([13 x i32 (...)*]* @_ZTVN2kc13impl_filelineE, i32 0, i32 2), i32 (...)*** %2, align 4
+ %3 = trunc i32 0 to i8
+ %toBool = icmp ne i8 %3, 0
+ br i1 %toBool, label %bb1, label %return
+
+bb1: ; preds = %entry
+ %4 = load %"struct.kc::impl_fileline"** %this_addr, align 4
+ %5 = bitcast %"struct.kc::impl_fileline"* %4 to i8*
+ call void @_ZdlPv() nounwind
+ br label %return
+
+return: ; preds = %bb1, %entry
+ ret void
+}
+
+declare void @_ZdlPv() nounwind
+
+define void @_ZN2kc13impl_filelineD2Ev(%"struct.kc::impl_fileline"* %this) nounwind align 2 {
+entry:
+ %this_addr = alloca %"struct.kc::impl_fileline"*, align 4
+ %"alloca point" = bitcast i32 0 to i32
+ store %"struct.kc::impl_fileline"* %this, %"struct.kc::impl_fileline"** %this_addr
+ %0 = load %"struct.kc::impl_fileline"** %this_addr, align 4
+ %1 = getelementptr inbounds %"struct.kc::impl_fileline"* %0, i32 0, i32 0
+ %2 = getelementptr inbounds %"struct.kc::impl_abstract_phylum"* %1, i32 0, i32 0
+ store i32 (...)** getelementptr inbounds ([13 x i32 (...)*]* @_ZTVN2kc13impl_filelineE, i32 0, i32 2), i32 (...)*** %2, align 4
+ %3 = trunc i32 0 to i8
+ %toBool = icmp ne i8 %3, 0
+ br i1 %toBool, label %bb1, label %return
+
+bb1: ; preds = %entry
+ %4 = load %"struct.kc::impl_fileline"** %this_addr, align 4
+ %5 = bitcast %"struct.kc::impl_fileline"* %4 to i8*
+ call void @_ZdlPv() nounwind
+ br label %return
+
+return: ; preds = %bb1, %entry
+ ret void
+}
+
+define void @_ZN2kc22impl_fileline_FileLineC1EPNS_20impl_casestring__StrEi(%"struct.kc::impl_fileline_FileLine"* %this, %"struct.kc::impl_casestring__Str"* %_file, i32 %_line) align 2 {
+entry:
+ %this_addr = alloca %"struct.kc::impl_fileline_FileLine"*, align 4
+ %_file_addr = alloca %"struct.kc::impl_casestring__Str"*, align 4
+ %_line_addr = alloca i32, align 4
+ %save_filt.148 = alloca i32
+ %save_eptr.147 = alloca i8*
+ %iftmp.99 = alloca %"struct.kc::impl_casestring__Str"*
+ %eh_exception = alloca i8*
+ %eh_selector = alloca i32
+ %"alloca point" = bitcast i32 0 to i32
+ store %"struct.kc::impl_fileline_FileLine"* %this, %"struct.kc::impl_fileline_FileLine"** %this_addr
+ store %"struct.kc::impl_casestring__Str"* %_file, %"struct.kc::impl_casestring__Str"** %_file_addr
+ store i32 %_line, i32* %_line_addr
+ %0 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %1 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %0, i32 0, i32 0
+ call void @_ZN2kc13impl_filelineC2Ev() nounwind
+ %2 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %3 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %2, i32 0, i32 0
+ %4 = getelementptr inbounds %"struct.kc::impl_fileline"* %3, i32 0, i32 0
+ %5 = getelementptr inbounds %"struct.kc::impl_abstract_phylum"* %4, i32 0, i32 0
+ store i32 (...)** getelementptr inbounds ([13 x i32 (...)*]* @_ZTVN2kc22impl_fileline_FileLineE, i32 0, i32 2), i32 (...)*** %5, align 4
+ %6 = load %"struct.kc::impl_casestring__Str"** %_file_addr, align 4
+ %7 = icmp eq %"struct.kc::impl_casestring__Str"* %6, null
+ br i1 %7, label %bb, label %bb1
+
+bb: ; preds = %entry
+ %8 = invoke %"struct.kc::impl_casestring__Str"* @_ZN2kc12mkcasestringEPKci()
+ to label %invcont unwind label %lpad
+
+invcont: ; preds = %bb
+ store %"struct.kc::impl_casestring__Str"* %8, %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ br label %bb2
+
+bb1: ; preds = %entry
+ %9 = load %"struct.kc::impl_casestring__Str"** %_file_addr, align 4
+ store %"struct.kc::impl_casestring__Str"* %9, %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ br label %bb2
+
+bb2: ; preds = %bb1, %invcont
+ %10 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %11 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %10, i32 0, i32 0
+ %12 = getelementptr inbounds %"struct.kc::impl_fileline"* %11, i32 0, i32 1
+ %13 = load %"struct.kc::impl_casestring__Str"** %iftmp.99, align 4
+ store %"struct.kc::impl_casestring__Str"* %13, %"struct.kc::impl_casestring__Str"** %12, align 4
+ %14 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %15 = getelementptr inbounds %"struct.kc::impl_fileline_FileLine"* %14, i32 0, i32 0
+ %16 = getelementptr inbounds %"struct.kc::impl_fileline"* %15, i32 0, i32 2
+ %17 = load i32* %_line_addr, align 4
+ store i32 %17, i32* %16, align 4
+ ret void
+
+lpad: ; preds = %bb
+ %eh_ptr = call i8* @llvm.eh.exception()
+ store i8* %eh_ptr, i8** %eh_exception
+ %eh_ptr4 = load i8** %eh_exception
+ %eh_select5 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %eh_ptr4, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0)
+ store i32 %eh_select5, i32* %eh_selector
+ %eh_select = load i32* %eh_selector
+ store i32 %eh_select, i32* %save_filt.148, align 4
+ %eh_value = load i8** %eh_exception
+ store i8* %eh_value, i8** %save_eptr.147, align 4
+ %18 = load %"struct.kc::impl_fileline_FileLine"** %this_addr, align 4
+ %19 = bitcast %"struct.kc::impl_fileline_FileLine"* %18 to %"struct.kc::impl_fileline"*
+ call void @_ZN2kc13impl_filelineD2Ev(%"struct.kc::impl_fileline"* %19) nounwind
+ %20 = load i8** %save_eptr.147, align 4
+ store i8* %20, i8** %eh_exception, align 4
+ %21 = load i32* %save_filt.148, align 4
+ store i32 %21, i32* %eh_selector, align 4
+ %eh_ptr6 = load i8** %eh_exception
+ call void @_Unwind_Resume_or_Rethrow()
+ unreachable
+}
+
+declare i8* @llvm.eh.exception() nounwind readonly
+
+declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @_Unwind_Resume_or_Rethrow()
+
+define void @_ZN2kc21printer_functor_classC2Ev(%"struct.kc::impl_abstract_phylum"* %this) nounwind align 2 {
+entry:
+ unreachable
+}
+
+define %"struct.kc::impl_Ccode_option"* @_ZN2kc11phylum_castIPNS_17impl_withcaseinfoES1_EET_PT0_(%"struct.kc::impl_Ccode_option"* %t) nounwind {
+entry:
+ ret %"struct.kc::impl_Ccode_option"* null
+}
+
+define %"struct.kc::impl_abstract_phylum"* @_ZNK2kc43impl_ac_direct_declarator_AcDirectDeclProto9subphylumEi(%"struct.kc::impl_ac_abstract_declarator_AcAbsdeclDirdecl"* %this, i32 %no) nounwind align 2 {
+entry:
+ ret %"struct.kc::impl_abstract_phylum"* undef
+}
+
+define void @_ZN2kc30impl_withcaseinfo_WithcaseinfoD0Ev(%"struct.kc::impl_withcaseinfo_Withcaseinfo"* %this) nounwind align 2 {
+entry:
+ unreachable
+}
+
+define void @_ZN2kc30impl_withcaseinfo_WithcaseinfoC1EPNS_26impl_patternrepresentationES2_PNS_10impl_CtextE(%"struct.kc::impl_withcaseinfo_Withcaseinfo"* %this, %"struct.kc::impl_outmostpatterns"* %_patternrepresentation_1, %"struct.kc::impl_outmostpatterns"* %_patternrepresentation_2, %"struct.kc::impl_Ctext"* %_Ctext_1) nounwind align 2 {
+entry:
+ unreachable
+}
+
+define void @_ZN2kc21impl_rewriteviewsinfoC2EPNS_20impl_rewriteviewinfoEPS0_(%"struct.kc::impl_CexpressionDQ"* %this, %"struct.kc::impl_Ccode_option"* %p1, %"struct.kc::impl_CexpressionDQ"* %p2) nounwind align 2 {
+entry:
+ unreachable
+}
+
+define %"struct.kc::impl_Ctext_elem"* @_ZN2kc11phylum_castIPNS_9impl_termENS_20impl_abstract_phylumEEET_PT0_(%"struct.kc::impl_abstract_phylum"* %t) nounwind {
+entry:
+ unreachable
+}
+
+define void @_ZN2kc27impl_ac_parameter_type_listD2Ev(%"struct.kc::impl_Ccode_option"* %this) nounwind align 2 {
+entry:
+ ret void
+}
+
+define void @_ZN2kc21impl_ac_operator_nameD2Ev(%"struct.kc::impl_Ctext_elem"* %this) nounwind align 2 {
+entry:
+ ret void
+}
+
+declare %"struct.kc::impl_casestring__Str"* @_ZN2kc12mkcasestringEPKci()
diff --git a/src/LLVM/test/Transforms/MergeFunc/dg.exp b/src/LLVM/test/Transforms/MergeFunc/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/MergeFunc/fold-weak.ll b/src/LLVM/test/Transforms/MergeFunc/fold-weak.ll
new file mode 100644
index 0000000..23e4d33
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/fold-weak.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -mergefunc -S > %t
+; RUN: grep {define weak} %t | count 2
+; RUN: grep {call} %t | count 2
+; XFAIL: *
+
+; This test is off for a bit as we change this particular sort of folding to
+; only apply on ELF systems and not Mach-O systems.
+
+define weak i32 @sum(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ ret i32 %sum
+}
+
+define weak i32 @add(i32 %x, i32 %y) {
+ %sum = add i32 %x, %y
+ ret i32 %sum
+}
diff --git a/src/LLVM/test/Transforms/MergeFunc/phi-speculation1.ll b/src/LLVM/test/Transforms/MergeFunc/phi-speculation1.ll
new file mode 100644
index 0000000..7b2a2fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/phi-speculation1.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -mergefunc -stats -disable-output |& not grep {functions merged}
+
+define i32 @foo1(i32 %x) {
+entry:
+ %A = add i32 %x, 1
+ %B = call i32 @foo1(i32 %A)
+ br label %loop
+loop:
+ %C = phi i32 [%B, %entry], [%D, %loop]
+ %D = add i32 %x, 2
+ %E = icmp ugt i32 %D, 10000
+ br i1 %E, label %loopexit, label %loop
+loopexit:
+ ret i32 %D
+}
+
+define i32 @foo2(i32 %x) {
+entry:
+ %0 = add i32 %x, 1
+ %1 = call i32 @foo2(i32 %0)
+ br label %loop
+loop:
+ %2 = phi i32 [%1, %entry], [%3, %loop]
+ %3 = add i32 %2, 2
+ %4 = icmp ugt i32 %3, 10000
+ br i1 %4, label %loopexit, label %loop
+loopexit:
+ ret i32 %3
+}
diff --git a/src/LLVM/test/Transforms/MergeFunc/phi-speculation2.ll b/src/LLVM/test/Transforms/MergeFunc/phi-speculation2.ll
new file mode 100644
index 0000000..f080191
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/phi-speculation2.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -mergefunc -stats -disable-output |& grep {functions merged}
+
+define i32 @foo1(i32 %x) {
+entry:
+ %A = add i32 %x, 1
+ %B = call i32 @foo1(i32 %A)
+ br label %loop
+loop:
+ %C = phi i32 [%B, %entry], [%D, %loop]
+ %D = add i32 %C, 2
+ %E = icmp ugt i32 %D, 10000
+ br i1 %E, label %loopexit, label %loop
+loopexit:
+ ret i32 %D
+}
+
+define i32 @foo2(i32 %x) {
+entry:
+ %0 = add i32 %x, 1
+ %1 = call i32 @foo2(i32 %0)
+ br label %loop
+loop:
+ %2 = phi i32 [%1, %entry], [%3, %loop]
+ %3 = add i32 %2, 2
+ %4 = icmp ugt i32 %3, 10000
+ br i1 %4, label %loopexit, label %loop
+loopexit:
+ ret i32 %3
+}
diff --git a/src/LLVM/test/Transforms/MergeFunc/vector.ll b/src/LLVM/test/Transforms/MergeFunc/vector.ll
new file mode 100644
index 0000000..6954fce
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/vector.ll
@@ -0,0 +1,76 @@
+; RUN: opt -mergefunc -stats -disable-output < %s |& grep {functions merged}
+
+; This test is checks whether we can merge
+; vector<intptr_t>::push_back(0)
+; and
+; vector<void *>::push_back(0)
+; .
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+%0 = type { i32, void ()* }
+%1 = type { i64, i1 }
+%"class.std::vector" = type { [24 x i8] }
+
+@vi = global %"class.std::vector" zeroinitializer, align 8
+@__dso_handle = external unnamed_addr global i8*
+@vp = global %"class.std::vector" zeroinitializer, align 8
+@llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @_GLOBAL__I_a }]
+
+define linkonce_odr void @_ZNSt6vectorIlSaIlEED1Ev(%"class.std::vector"* nocapture %this) unnamed_addr align 2 {
+entry:
+ %tmp2.i.i = bitcast %"class.std::vector"* %this to i64**
+ %tmp3.i.i = load i64** %tmp2.i.i, align 8, !tbaa !0
+ %tobool.i.i.i = icmp eq i64* %tmp3.i.i, null
+ br i1 %tobool.i.i.i, label %_ZNSt6vectorIlSaIlEED2Ev.exit, label %if.then.i.i.i
+
+if.then.i.i.i: ; preds = %entry
+ %0 = bitcast i64* %tmp3.i.i to i8*
+ tail call void @_ZdlPv(i8* %0) nounwind
+ ret void
+
+_ZNSt6vectorIlSaIlEED2Ev.exit: ; preds = %entry
+ ret void
+}
+
+declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
+
+define linkonce_odr void @_ZNSt6vectorIPvSaIS0_EED1Ev(%"class.std::vector"* nocapture %this) unnamed_addr align 2 {
+entry:
+ %tmp2.i.i = bitcast %"class.std::vector"* %this to i8***
+ %tmp3.i.i = load i8*** %tmp2.i.i, align 8, !tbaa !0
+ %tobool.i.i.i = icmp eq i8** %tmp3.i.i, null
+ br i1 %tobool.i.i.i, label %_ZNSt6vectorIPvSaIS0_EED2Ev.exit, label %if.then.i.i.i
+
+if.then.i.i.i: ; preds = %entry
+ %0 = bitcast i8** %tmp3.i.i to i8*
+ tail call void @_ZdlPv(i8* %0) nounwind
+ ret void
+
+_ZNSt6vectorIPvSaIS0_EED2Ev.exit: ; preds = %entry
+ ret void
+}
+
+declare void @_Z1fv()
+
+declare void @_ZNSt6vectorIPvSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_(%"class.std::vector"* nocapture %this, i8** %__position.coerce, i8** nocapture %__x) align 2
+
+declare void @_ZdlPv(i8*) nounwind
+
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+declare void @_ZSt17__throw_bad_allocv() noreturn
+
+declare noalias i8* @_Znwm(i64)
+
+declare void @_ZNSt6vectorIlSaIlEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPlS1_EERKl(%"class.std::vector"* nocapture %this, i64* %__position.coerce, i64* nocapture %__x) align 2
+
+declare void @_GLOBAL__I_a()
+
+declare %1 @llvm.uadd.with.overflow.i64(i64, i64) nounwind readnone
+
+!0 = metadata !{metadata !"any pointer", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
+!3 = metadata !{metadata !"long", metadata !1}
diff --git a/src/LLVM/test/Transforms/MergeFunc/vectors-and-arrays.ll b/src/LLVM/test/Transforms/MergeFunc/vectors-and-arrays.ll
new file mode 100644
index 0000000..dc64a08
--- /dev/null
+++ b/src/LLVM/test/Transforms/MergeFunc/vectors-and-arrays.ll
@@ -0,0 +1,18 @@
+; RUN: opt -mergefunc < %s -disable-output -stats | not grep merged
+; This used to crash with an assert.
+
+define <2 x i8> @v1(<2 x i8> %x) {
+ ret <2 x i8> %x
+}
+
+define <4 x i8> @v2(<4 x i8> %x) {
+ ret <4 x i8> %x
+}
+
+define [2 x i8] @a1([2 x i8] %x) {
+ ret [2 x i8] %x
+}
+
+define [4 x i8] @a2([4 x i8] %x) {
+ ret [4 x i8] %x
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/basic.ll b/src/LLVM/test/Transforms/ObjCARC/basic.ll
new file mode 100644
index 0000000..575cf42
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/basic.ll
@@ -0,0 +1,2004 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+declare i8* @objc_autorelease(i8*)
+declare void @objc_autoreleasePoolPop(i8*)
+declare void @objc_autoreleasePoolPush()
+declare i8* @objc_retainBlock(i8*)
+
+declare i8* @objc_retainedObject(i8*)
+declare i8* @objc_unretainedObject(i8*)
+declare i8* @objc_unretainedPointer(i8*)
+
+declare void @use_pointer(i8*)
+declare void @callee()
+declare void @callee_fnptr(void ()*)
+declare void @invokee()
+declare i8* @returner()
+
+declare void @llvm.dbg.value(metadata, i64, metadata)
+
+declare i8* @objc_msgSend(i8*, i8*, ...)
+
+; Simple retain+release pair deletion, with some intervening control
+; flow and harmless instructions.
+
+; CHECK: define void @test0(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test0(i32* %x, i1 %p) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ br i1 %p, label %t, label %f
+
+t:
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %return
+
+f:
+ store i32 7, i32* %x
+ br label %return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; Like test0 but the release isn't always executed when the retain is,
+; so the optimization is not safe.
+
+; TODO: Make the objc_release's argument be %0.
+
+; CHECK: define void @test1(
+; CHECK: @objc_retain(i8* %a)
+; CHECK: @objc_release
+; CHECK: }
+define void @test1(i32* %x, i1 %p, i1 %q) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ br i1 %p, label %t, label %f
+
+t:
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %return
+
+f:
+ store i32 7, i32* %x
+ call void @callee()
+ br i1 %q, label %return, label %alt_return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+
+alt_return:
+ ret void
+}
+
+; Like test0 but the pointer is passed to an intervening call,
+; so the optimization is not safe.
+
+; CHECK: define void @test2(
+; CHECK: @objc_retain(i8* %a)
+; CHECK: @objc_release
+; CHECK: }
+define void @test2(i32* %x, i1 %p) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ br i1 %p, label %t, label %f
+
+t:
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %return
+
+f:
+ store i32 7, i32* %x
+ call void @use_pointer(i8* %0)
+ %d = bitcast i32* %x to float*
+ store float 3.0, float* %d
+ br label %return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; Like test0 but the release is in a loop,
+; so the optimization is not safe.
+
+; TODO: For now, assume this can't happen.
+
+; CHECK: define void @test3(
+; TODO: @objc_retain(i8* %a)
+; TODO: @objc_release
+; CHECK: }
+define void @test3(i32* %x, i1* %q) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ %j = volatile load i1* %q
+ br i1 %j, label %loop, label %return
+
+return:
+ ret void
+}
+
+; TODO: For now, assume this can't happen.
+
+; Like test0 but the retain is in a loop,
+; so the optimization is not safe.
+
+; CHECK: define void @test4(
+; TODO: @objc_retain(i8* %a)
+; TODO: @objc_release
+; CHECK: }
+define void @test4(i32* %x, i1* %q) nounwind {
+entry:
+ br label %loop
+
+loop:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ %j = volatile load i1* %q
+ br i1 %j, label %loop, label %return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; Like test0 but the pointer is conditionally passed to an intervening call,
+; so the optimization is not safe.
+
+; CHECK: define void @test5(
+; CHECK: @objc_retain(i8*
+; CHECK: @objc_release
+; CHECK: }
+define void @test5(i32* %x, i1 %q, i8* %y) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ %s = select i1 %q, i8* %y, i8* %0
+ call void @use_pointer(i8* %s)
+ store i32 7, i32* %x
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; retain+release pair deletion, where the release happens on two different
+; flow paths.
+
+; CHECK: define void @test6(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test6(i32* %x, i1 %p) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ br i1 %p, label %t, label %f
+
+t:
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ %ct = bitcast i32* %x to i8*
+ call void @objc_release(i8* %ct) nounwind
+ br label %return
+
+f:
+ store i32 7, i32* %x
+ call void @callee()
+ %cf = bitcast i32* %x to i8*
+ call void @objc_release(i8* %cf) nounwind
+ br label %return
+
+return:
+ ret void
+}
+
+; retain+release pair deletion, where the retain happens on two different
+; flow paths.
+
+; CHECK: define void @test7(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test7(i32* %x, i1 %p) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ br i1 %p, label %t, label %f
+
+t:
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %return
+
+f:
+ %1 = call i8* @objc_retain(i8* %a) nounwind
+ store i32 7, i32* %x
+ call void @callee()
+ br label %return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; Like test7, but there's a retain/retainBlock mismatch. Don't delete!
+
+; CHECK: define void @test7b
+; CHECK: t:
+; CHECK: call i8* @objc_retainBlock
+; CHECK: f:
+; CHECK: call i8* @objc_retain
+; CHECK: return:
+; CHECK: call void @objc_release
+; CHECK: }
+define void @test7b(i32* %x, i1 %p) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ br i1 %p, label %t, label %f
+
+t:
+ %0 = call i8* @objc_retainBlock(i8* %a) nounwind
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %return
+
+f:
+ %1 = call i8* @objc_retain(i8* %a) nounwind
+ store i32 7, i32* %x
+ call void @callee()
+ br label %return
+
+return:
+ %c = bitcast i32* %x to i8*
+ call void @objc_release(i8* %c) nounwind
+ ret void
+}
+
+; retain+release pair deletion, where the retain and release both happen on
+; different flow paths. Wild!
+
+; CHECK: define void @test8(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test8(i32* %x, i1 %p, i1 %q) nounwind {
+entry:
+ %a = bitcast i32* %x to i8*
+ br i1 %p, label %t, label %f
+
+t:
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ store i8 3, i8* %a
+ %b = bitcast i32* %x to float*
+ store float 2.0, float* %b
+ br label %mid
+
+f:
+ %1 = call i8* @objc_retain(i8* %a) nounwind
+ store i32 7, i32* %x
+ br label %mid
+
+mid:
+ br i1 %q, label %u, label %g
+
+u:
+ call void @callee()
+ %cu = bitcast i32* %x to i8*
+ call void @objc_release(i8* %cu) nounwind
+ br label %return
+
+g:
+ %cg = bitcast i32* %x to i8*
+ call void @objc_release(i8* %cg) nounwind
+ br label %return
+
+return:
+ ret void
+}
+
+; Trivial retain+release pair deletion.
+
+; CHECK: define void @test9(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test9(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %0) nounwind
+ ret void
+}
+
+; Retain+release pair, but on an unknown pointer relationship. Don't delete!
+
+; CHECK: define void @test9b
+; CHECK: @objc_retain(i8* %x)
+; CHECK: @objc_release(i8* %s)
+; CHECK: }
+define void @test9b(i8* %x, i1 %j, i8* %p) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ %s = select i1 %j, i8* %x, i8* %p
+ call void @objc_release(i8* %s) nounwind
+ ret void
+}
+
+; Trivial retain+release pair with intervening calls - don't delete!
+
+; CHECK: define void @test10(
+; CHECK: @objc_retain(i8* %x)
+; CHECK: @callee
+; CHECK: @use_pointer
+; CHECK: @objc_release
+; CHECK: }
+define void @test10(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call void @callee()
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %0) nounwind
+ ret void
+}
+
+; Trivial retain+autoreleaserelease pair. Don't delete!
+; Also, add a tail keyword, since objc_retain can never be passed
+; a stack argument.
+
+; CHECK: define void @test11(
+; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK: tail call i8* @objc_autorelease(i8* %0) nounwind
+; CHECK: }
+define void @test11(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_autorelease(i8* %0) nounwind
+ call void @use_pointer(i8* %x)
+ ret void
+}
+
+; Same as test11 but with no use_pointer call. Delete the pair!
+
+; CHECK: define void @test11a(
+; CHECK: entry:
+; CHECK-NEXT: ret void
+; CHECK: }
+define void @test11a(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_autorelease(i8* %0) nounwind
+ ret void
+}
+
+; Same as test11 but the value is returned. Do an RV optimization.
+
+; CHECK: define i8* @test11b(
+; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+; CHECK: }
+define i8* @test11b(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_autorelease(i8* %0) nounwind
+ ret i8* %x
+}
+
+; Trivial retain,release pair with intervening call, but it's dominated
+; by another retain - delete!
+
+; CHECK: define void @test12(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_retain(i8* %x)
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test12(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Trivial retain,autorelease pair. Don't delete!
+
+; CHECK: define void @test13(
+; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK: @use_pointer(i8* %x)
+; CHECK: tail call i8* @objc_autorelease(i8* %x) nounwind
+; CHECK: }
+define void @test13(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call i8* @objc_autorelease(i8* %x) nounwind
+ ret void
+}
+
+; Delete the retain+release pair.
+
+; CHECK: define void @test13b
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_retain(i8* %x)
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: ret void
+define void @test13b(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Don't delete the retain+release pair because there's an
+; autoreleasePoolPop in the way.
+
+; CHECK: define void @test13c
+; CHECK: @objc_retain(i8* %x)
+; CHECK: @objc_autoreleasePoolPop
+; CHECK: @objc_retain(i8* %x)
+; CHECK: @use_pointer
+; CHECK: @objc_release
+; CHECK: }
+define void @test13c(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_autoreleasePoolPop(i8* undef)
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Like test13c, but there's an autoreleasePoolPush in the way, but that
+; doesn't matter.
+
+; CHECK: define void @test13d
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_retain(i8* %x)
+; CHECK-NEXT: @objc_autoreleasePoolPush
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: ret void
+define void @test13d(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_autoreleasePoolPush()
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Trivial retain,release pair with intervening call, but it's post-dominated
+; by another release - delete!
+
+; CHECK: define void @test14(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @objc_release
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test14(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Trivial retain,autorelease pair with intervening call, but it's post-dominated
+; by another release. Don't delete anything.
+
+; CHECK: define void @test15(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_retain(i8* %x)
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @objc_autorelease(i8* %x)
+; CHECK-NEXT: @objc_release
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test15(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call i8* @objc_autorelease(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Trivial retain,autorelease pair, post-dominated
+; by another release. Delete the retain and release.
+
+; CHECK: define void @test15b
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_autorelease
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test15b(i8* %x, i64 %n) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call i8* @objc_autorelease(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Retain+release pairs in diamonds, all dominated by a retain.
+
+; CHECK: define void @test16(
+; CHECK: @objc_retain(i8* %x)
+; CHECK-NOT: @objc
+; CHECK: }
+define void @test16(i1 %a, i1 %b, i8* %x) {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ br i1 %a, label %red, label %orange
+
+red:
+ call i8* @objc_retain(i8* %x) nounwind
+ br label %yellow
+
+orange:
+ call i8* @objc_retain(i8* %x) nounwind
+ br label %yellow
+
+yellow:
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ br i1 %b, label %green, label %blue
+
+green:
+ call void @objc_release(i8* %x) nounwind
+ br label %purple
+
+blue:
+ call void @objc_release(i8* %x) nounwind
+ br label %purple
+
+purple:
+ ret void
+}
+
+; Retain+release pairs in diamonds, all post-dominated by a release.
+
+; CHECK: define void @test17(
+; CHECK-NOT: @objc_
+; CHECK: purple:
+; CHECK: @objc_release
+; CHECK: }
+define void @test17(i1 %a, i1 %b, i8* %x) {
+entry:
+ br i1 %a, label %red, label %orange
+
+red:
+ call i8* @objc_retain(i8* %x) nounwind
+ br label %yellow
+
+orange:
+ call i8* @objc_retain(i8* %x) nounwind
+ br label %yellow
+
+yellow:
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ br i1 %b, label %green, label %blue
+
+green:
+ call void @objc_release(i8* %x) nounwind
+ br label %purple
+
+blue:
+ call void @objc_release(i8* %x) nounwind
+ br label %purple
+
+purple:
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Delete no-ops.
+
+; CHECK: define void @test18(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test18() {
+ call i8* @objc_retain(i8* null)
+ call void @objc_release(i8* null)
+ call i8* @objc_autorelease(i8* null)
+ ret void
+}
+
+; Delete no-ops where undef can be assumed to be null.
+
+; CHECK: define void @test18b
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test18b() {
+ call i8* @objc_retain(i8* undef)
+ call void @objc_release(i8* undef)
+ call i8* @objc_autorelease(i8* undef)
+ ret void
+}
+
+; Replace uses of arguments with uses of return values, to reduce
+; register pressure.
+
+; CHECK: define void @test19(i32* %y) {
+; CHECK: %z = bitcast i32* %y to i8*
+; CHECK: %0 = bitcast i32* %y to i8*
+; CHECK: %1 = tail call i8* @objc_retain(i8* %0)
+; CHECK: call void @use_pointer(i8* %z)
+; CHECK: call void @use_pointer(i8* %z)
+; CHECK: %2 = bitcast i32* %y to i8*
+; CHECK: call void @objc_release(i8* %2)
+; CHECK: ret void
+; CHECK: }
+define void @test19(i32* %y) {
+entry:
+ %x = bitcast i32* %y to i8*
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ %z = bitcast i32* %y to i8*
+ call void @use_pointer(i8* %z)
+ call void @use_pointer(i8* %z)
+ call void @objc_release(i8* %x)
+ ret void
+}
+
+; Bitcast insertion
+
+; CHECK: define void @test20(
+; CHECK: %tmp1 = tail call i8* @objc_retain(i8* %tmp) nounwind
+; CHECK-NEXT: invoke
+define void @test20(double* %self) {
+if.then12:
+ %tmp = bitcast double* %self to i8*
+ %tmp1 = call i8* @objc_retain(i8* %tmp) nounwind
+ invoke void @invokee()
+ to label %invoke.cont23 unwind label %lpad20
+
+invoke.cont23: ; preds = %if.then12
+ invoke void @invokee()
+ to label %if.end unwind label %lpad20
+
+lpad20: ; preds = %invoke.cont23, %if.then12
+ %tmp502 = phi double* [ undef, %invoke.cont23 ], [ %self, %if.then12 ]
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+
+if.end: ; preds = %invoke.cont23
+ ret void
+}
+
+; Delete a redundant retain,autorelease when forwaring a call result
+; directly to a return value.
+
+; CHECK: define i8* @test21(
+; CHECK: call i8* @returner()
+; CHECK-NEXT: ret i8* %call
+define i8* @test21() {
+entry:
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retain(i8* %call) nounwind
+ %1 = call i8* @objc_autorelease(i8* %0) nounwind
+ ret i8* %1
+}
+
+; Move an objc call up through a phi that has null operands.
+
+; CHECK: define void @test22(
+; CHECK: B:
+; CHECK: %1 = bitcast double* %p to i8*
+; CHECK: call void @objc_release(i8* %1)
+; CHECK: br label %C
+; CHECK: C: ; preds = %B, %A
+; CHECK-NOT: @objc_release
+; CHECK: }
+define void @test22(double* %p, i1 %a) {
+ br i1 %a, label %A, label %B
+A:
+ br label %C
+B:
+ br label %C
+C:
+ %h = phi double* [ null, %A ], [ %p, %B ]
+ %c = bitcast double* %h to i8*
+ call void @objc_release(i8* %c)
+ ret void
+}
+
+; Optimize objc_retainBlock.
+
+; CHECK: define void @test23(
+; CHECK-NOT: @objc_
+; CHECK: }
+%block0 = type { i64, i64, i8*, i8* }
+%block1 = type { i8**, i32, i32, i32 (%struct.__block_literal_1*)*, %block0* }
+%struct.__block_descriptor = type { i64, i64 }
+%struct.__block_literal_1 = type { i8**, i32, i32, i8**, %struct.__block_descriptor* }
+@__block_holder_tmp_1 = external constant %block1
+define void @test23() {
+entry:
+ %0 = call i8* @objc_retainBlock(i8* bitcast (%block1* @__block_holder_tmp_1 to i8*)) nounwind
+ call void @bar(i32 ()* bitcast (%block1* @__block_holder_tmp_1 to i32 ()*))
+ call void @bar(i32 ()* bitcast (%block1* @__block_holder_tmp_1 to i32 ()*))
+ call void @objc_release(i8* bitcast (%block1* @__block_holder_tmp_1 to i8*)) nounwind
+ ret void
+}
+
+; Don't optimize objc_retainBlock.
+
+; CHECK: define void @test23b
+; CHECK: @objc_retainBlock
+; CHECK: @objc_release
+; CHECK: }
+define void @test23b(i8* %p) {
+entry:
+ %0 = call i8* @objc_retainBlock(i8* %p) nounwind
+ call void @callee()
+ call void @use_pointer(i8* %p)
+ call void @objc_release(i8* %p) nounwind
+ ret void
+}
+
+; Any call can decrement a retain count.
+
+; CHECK: define void @test24(
+; CHECK: @objc_retain(i8* %a)
+; CHECK: @objc_release
+; CHECK: }
+define void @test24(i8* %r, i8* %a) {
+ call i8* @objc_retain(i8* %a)
+ call void @use_pointer(i8* %r)
+ %q = load i8* %a
+ call void @objc_release(i8* %a)
+ ret void
+}
+
+; Don't move a retain/release pair if the release can be moved
+; but the retain can't be moved to balance it.
+
+; CHECK: define void @test25(
+; CHECK: entry:
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: true:
+; CHECK: done:
+; CHECK: call void @objc_release(i8* %p)
+; CHECK: }
+define void @test25(i8* %p, i1 %x) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ call void @callee()
+ br i1 %x, label %true, label %done
+
+true:
+ store i8 0, i8* %p
+ br label %done
+
+done:
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't move a retain/release pair if the retain can be moved
+; but the release can't be moved to balance it.
+
+; CHECK: define void @test26(
+; CHECK: entry:
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: true:
+; CHECK: done:
+; CHECK: call void @objc_release(i8* %p)
+; CHECK: }
+define void @test26(i8* %p, i1 %x) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ br label %done
+
+done:
+ store i8 0, i8* %p
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't sink the retain,release into the loop.
+
+; CHECK: define void @test27(
+; CHECK: entry:
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: loop:
+; CHECK-NOT: @objc_
+; CHECK: done:
+; CHECK: call void @objc_release
+; CHECK: }
+define void @test27(i8* %p, i1 %x, i1 %y) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %loop, label %done
+
+loop:
+ call void @callee()
+ store i8 0, i8* %p
+ br i1 %y, label %done, label %loop
+
+done:
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Trivial code motion case: Triangle.
+
+; CHECK: define void @test28(
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test28(i8* %p, i1 %x) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br label %done
+
+done:
+ call void @objc_release(i8* %p), !clang.imprecise_release !0
+ ret void
+}
+
+; Trivial code motion case: Triangle, but no metadata. Don't move past
+; unrelated memory references!
+
+; CHECK: define void @test28b
+; CHECK: call i8* @objc_retain(
+; CHECK: true:
+; CHECK-NOT: @objc_
+; CHECK: call void @callee()
+; CHECK-NOT: @objc_
+; CHECK: store
+; CHECK-NOT: @objc_
+; CHECK: done:
+; CHECK: @objc_release
+; CHECK: }
+define void @test28b(i8* %p, i1 %x, i8* noalias %t) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br label %done
+
+done:
+ store i8 0, i8* %t
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Trivial code motion case: Triangle, with metadata. Do move past
+; unrelated memory references! And preserve the metadata.
+
+; CHECK: define void @test28c
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release(i8* %p) nounwind, !clang.imprecise_release
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test28c(i8* %p, i1 %x, i8* noalias %t) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br label %done
+
+done:
+ store i8 0, i8* %t
+ call void @objc_release(i8* %p), !clang.imprecise_release !0
+ ret void
+}
+
+; Like test28. but with two releases.
+
+; CHECK: define void @test29(
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release
+; CHECK-NOT: @objc_release
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: ohno:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test29(i8* %p, i1 %x, i1 %y) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br i1 %y, label %done, label %ohno
+
+done:
+ call void @objc_release(i8* %p)
+ ret void
+
+ohno:
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Basic case with the use and call in a diamond
+; with an extra release.
+
+; CHECK: define void @test30(
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release
+; CHECK-NOT: @objc_release
+; CHECK: false:
+; CHECK-NOT: @objc_
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: ohno:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test30(i8* %p, i1 %x, i1 %y, i1 %z) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %false
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br i1 %y, label %done, label %ohno
+
+false:
+ br i1 %z, label %done, label %ohno
+
+done:
+ call void @objc_release(i8* %p)
+ ret void
+
+ohno:
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Basic case with a mergeable release.
+
+; CHECK: define void @test31(
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release
+; CHECK-NOT: @objc_release
+; CHECK: true:
+; CHECK-NOT: @objc_release
+; CHECK: false:
+; CHECK-NOT: @objc_release
+; CHECK: ret void
+; CHECK-NOT: @objc_release
+; CHECK: }
+define void @test31(i8* %p, i1 %x) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ call void @callee()
+ store i8 0, i8* %p
+ br i1 %x, label %true, label %false
+true:
+ call void @objc_release(i8* %p)
+ ret void
+false:
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't consider bitcasts or getelementptrs direct uses.
+
+; CHECK: define void @test32(
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: store
+; CHECK: call void @objc_release
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test32(i8* %p, i1 %x) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ store i8 0, i8* %p
+ br label %done
+
+done:
+ %g = bitcast i8* %p to i8*
+ %h = getelementptr i8* %g, i64 0
+ call void @objc_release(i8* %g)
+ ret void
+}
+
+; Do consider icmps to be direct uses.
+
+; CHECK: define void @test33(
+; CHECK-NOT: @objc_
+; CHECK: true:
+; CHECK: call i8* @objc_retain(
+; CHECK: call void @callee()
+; CHECK: icmp
+; CHECK: call void @objc_release
+; CHECK: done:
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test33(i8* %p, i1 %x, i8* %y) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ %v = icmp eq i8* %p, %y
+ br label %done
+
+done:
+ %g = bitcast i8* %p to i8*
+ %h = getelementptr i8* %g, i64 0
+ call void @objc_release(i8* %g)
+ ret void
+}
+
+; Delete retain,release if there's just a possible dec.
+
+; CHECK: define void @test34(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test34(i8* %p, i1 %x, i8* %y) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ call void @callee()
+ br label %done
+
+done:
+ %g = bitcast i8* %p to i8*
+ %h = getelementptr i8* %g, i64 0
+ call void @objc_release(i8* %g)
+ ret void
+}
+
+; Delete retain,release if there's just a use.
+
+; CHECK: define void @test35(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test35(i8* %p, i1 %x, i8* %y) {
+entry:
+ %f0 = call i8* @objc_retain(i8* %p)
+ br i1 %x, label %true, label %done
+
+true:
+ %v = icmp eq i8* %p, %y
+ br label %done
+
+done:
+ %g = bitcast i8* %p to i8*
+ %h = getelementptr i8* %g, i64 0
+ call void @objc_release(i8* %g)
+ ret void
+}
+
+; Delete a retain,release if there's no actual use.
+
+; CHECK: define void @test36(
+; CHECK-NOT: @objc_
+; CHECK: call void @callee()
+; CHECK-NOT: @objc_
+; CHECK: call void @callee()
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test36(i8* %p) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ call void @callee()
+ call void @callee()
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Like test36, but with metadata.
+
+; CHECK: define void @test37(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test37(i8* %p) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ call void @callee()
+ call void @callee()
+ call void @objc_release(i8* %p), !clang.imprecise_release !0
+ ret void
+}
+
+; Be aggressive about analyzing phis to eliminate possible uses.
+
+; CHECK: define void @test38(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test38(i8* %p, i1 %u, i1 %m, i8* %z, i8* %y, i8* %x, i8* %w) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ br i1 %u, label %true, label %false
+true:
+ br i1 %m, label %a, label %b
+false:
+ br i1 %m, label %c, label %d
+a:
+ br label %e
+b:
+ br label %e
+c:
+ br label %f
+d:
+ br label %f
+e:
+ %j = phi i8* [ %z, %a ], [ %y, %b ]
+ br label %g
+f:
+ %k = phi i8* [ %w, %c ], [ %x, %d ]
+ br label %g
+g:
+ %h = phi i8* [ %j, %e ], [ %k, %f ]
+ call void @use_pointer(i8* %h)
+ call void @objc_release(i8* %p), !clang.imprecise_release !0
+ ret void
+}
+
+; Delete retain,release pairs around loops.
+
+; CHECK: define void @test39(
+; CHECK_NOT: @objc_
+; CHECK: }
+define void @test39(i8* %p) {
+entry:
+ %0 = call i8* @objc_retain(i8* %p)
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ br i1 undef, label %loop, label %exit
+
+exit: ; preds = %loop
+ call void @objc_release(i8* %0), !clang.imprecise_release !0
+ ret void
+}
+
+; Delete retain,release pairs around loops containing uses.
+
+; CHECK: define void @test39b(
+; CHECK_NOT: @objc_
+; CHECK: }
+define void @test39b(i8* %p) {
+entry:
+ %0 = call i8* @objc_retain(i8* %p)
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ store i8 0, i8* %0
+ br i1 undef, label %loop, label %exit
+
+exit: ; preds = %loop
+ call void @objc_release(i8* %0), !clang.imprecise_release !0
+ ret void
+}
+
+; Delete retain,release pairs around loops containing potential decrements.
+
+; CHECK: define void @test39c(
+; CHECK_NOT: @objc_
+; CHECK: }
+define void @test39c(i8* %p) {
+entry:
+ %0 = call i8* @objc_retain(i8* %p)
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ call void @use_pointer(i8* %0)
+ br i1 undef, label %loop, label %exit
+
+exit: ; preds = %loop
+ call void @objc_release(i8* %0), !clang.imprecise_release !0
+ ret void
+}
+
+; Delete retain,release pairs around loops even if
+; the successors are in a different order.
+
+; CHECK: define void @test40(
+; CHECK_NOT: @objc_
+; CHECK: }
+define void @test40(i8* %p) {
+entry:
+ %0 = call i8* @objc_retain(i8* %p)
+ br label %loop
+
+loop: ; preds = %loop, %entry
+ call void @use_pointer(i8* %0)
+ br i1 undef, label %exit, label %loop
+
+exit: ; preds = %loop
+ call void @objc_release(i8* %0), !clang.imprecise_release !0
+ ret void
+}
+
+; Do the known-incremented retain+release elimination even if the pointer
+; is also autoreleased.
+
+; CHECK: define void @test42(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test42(i8* %p) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ call i8* @objc_autorelease(i8* %p)
+ call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't the known-incremented retain+release elimination if the pointer is
+; autoreleased and there's an autoreleasePoolPop.
+
+; CHECK: define void @test43(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: call i8* @objc_retain
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: call void @objc_autoreleasePoolPop(i8* undef)
+; CHECK-NEXT: call void @objc_release
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test43(i8* %p) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ call i8* @objc_autorelease(i8* %p)
+ call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @objc_autoreleasePoolPop(i8* undef)
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Do the known-incremented retain+release elimination if the pointer is
+; autoreleased and there's an autoreleasePoolPush.
+
+; CHECK: define void @test43b
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: call void @objc_autoreleasePoolPush()
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test43b(i8* %p) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ call i8* @objc_autorelease(i8* %p)
+ call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @use_pointer(i8* %p)
+ call void @objc_autoreleasePoolPush()
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Do retain+release elimination for non-provenance pointers.
+
+; CHECK: define void @test44(
+; CHECK-NOT: objc_
+; CHECK: }
+define void @test44(i8** %pp) {
+ %p = load i8** %pp
+ %q = call i8* @objc_retain(i8* %p)
+ call void @objc_release(i8* %q)
+ ret void
+}
+
+; Don't delete retain+release with an unknown-provenance
+; may-alias objc_release between them.
+
+; CHECK: define void @test45(
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: call void @objc_release(i8* %q)
+; CHECK: call void @use_pointer(i8* %p)
+; CHECK: call void @objc_release(i8* %p)
+define void @test45(i8** %pp, i8** %qq) {
+ %p = load i8** %pp
+ %q = load i8** %qq
+ call i8* @objc_retain(i8* %p)
+ call void @objc_release(i8* %q)
+ call void @use_pointer(i8* %p)
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't delete retain and autorelease here.
+
+; CHECK: define void @test46(
+; CHECK: tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK: true:
+; CHECK: tail call i8* @objc_autorelease(i8* %p) nounwind
+define void @test46(i8* %p, i1 %a) {
+entry:
+ call i8* @objc_retain(i8* %p)
+ br i1 %a, label %true, label %false
+
+true:
+ call i8* @objc_autorelease(i8* %p)
+ call void @use_pointer(i8* %p)
+ ret void
+
+false:
+ ret void
+}
+
+; Delete no-op cast calls.
+
+; CHECK: define i8* @test47(
+; CHECK-NOT: call
+; CHECK: ret i8* %p
+define i8* @test47(i8* %p) nounwind {
+ %x = call i8* @objc_retainedObject(i8* %p)
+ ret i8* %x
+}
+
+; Delete no-op cast calls.
+
+; CHECK: define i8* @test48(
+; CHECK-NOT: call
+; CHECK: ret i8* %p
+define i8* @test48(i8* %p) nounwind {
+ %x = call i8* @objc_unretainedObject(i8* %p)
+ ret i8* %x
+}
+
+; Delete no-op cast calls.
+
+; CHECK: define i8* @test49(
+; CHECK-NOT: call
+; CHECK: ret i8* %p
+define i8* @test49(i8* %p) nounwind {
+ %x = call i8* @objc_unretainedPointer(i8* %p)
+ ret i8* %x
+}
+
+; Do delete retain+release with intervening stores of the
+; address value;
+
+; CHECK: define void @test50(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test50(i8* %p, i8** %pp) {
+ call i8* @objc_retain(i8* %p)
+ call void @callee()
+ store i8* %p, i8** %pp
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't delete retain+release with intervening stores through the
+; address value.
+
+; CHECK: define void @test51(
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: call void @objc_release(i8* %p)
+define void @test51(i8* %p) {
+ call i8* @objc_retain(i8* %p)
+ call void @callee()
+ store i8 0, i8* %p
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Don't delete retain+release with intervening use of a pointer of
+; unknown provenance.
+
+; CHECK: define void @test52(
+; CHECK: call i8* @objc_retain
+; CHECK: call void @callee()
+; CHECK: call void @use_pointer(i8* %z)
+; CHECK: call void @objc_release
+define void @test52(i8** %zz, i8** %pp) {
+ %p = load i8** %pp
+ %1 = call i8* @objc_retain(i8* %p)
+ call void @callee()
+ %z = load i8** %zz
+ call void @use_pointer(i8* %z)
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Like test52, but the pointer has function type, so it's assumed to
+; be not reference counted.
+
+; CHECK: define void @test53(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test53(void ()** %zz, i8** %pp) {
+ %p = load i8** %pp
+ %1 = call i8* @objc_retain(i8* %p)
+ call void @callee()
+ %z = load void ()** %zz
+ call void @callee_fnptr(void ()* %z)
+ call void @objc_release(i8* %p)
+ ret void
+}
+
+; Convert autorelease to release if the value is unused.
+
+; CHECK: define void @test54(
+; CHECK: call i8* @returner()
+; CHECK-NEXT: call void @objc_release(i8* %t) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: ret void
+define void @test54() {
+ %t = call i8* @returner()
+ call i8* @objc_autorelease(i8* %t)
+ ret void
+}
+
+; Nested retain+release pairs. Delete them both.
+
+; CHECK: define void @test55(
+; CHECK-NOT: @objc
+; CHECK: }
+define void @test55(i8* %x) {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ %1 = call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Nested retain+release pairs where the inner pair depends
+; on the outer pair to be removed, and then the outer pair
+; can be partially eliminated. Plus an extra outer pair to
+; eliminate, for fun.
+
+; CHECK: define void @test56(
+; CHECK-NOT: @objc
+; CHECK: if.then:
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NEXT: tail call void @use_pointer(i8* %x)
+; CHECK-NEXT: tail call void @use_pointer(i8* %x)
+; CHECK-NEXT: tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: br label %if.end
+; CHECK-NOT: @objc
+; CHECK: }
+define void @test56(i8* %x, i32 %n) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %x) nounwind
+ %1 = tail call i8* @objc_retain(i8* %0) nounwind
+ %tobool = icmp eq i32 %n, 0
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ %2 = tail call i8* @objc_retain(i8* %1) nounwind
+ tail call void @use_pointer(i8* %2)
+ tail call void @use_pointer(i8* %2)
+ tail call void @objc_release(i8* %2) nounwind, !clang.imprecise_release !0
+ br label %if.end
+
+if.end: ; preds = %entry, %if.then
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ tail call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; When there are adjacent retain+release pairs, the first one is
+; known unnecessary because the presence of the second one means that
+; the first one won't be deleting the object.
+
+; CHECK: define void @test57(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test57(i8* %x) nounwind {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; An adjacent retain+release pair is sufficient even if it will be
+; removed itself.
+
+; CHECK: define void @test58(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test58(i8* %x) nounwind {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Don't delete the second retain+release pair in an adjacent set.
+
+; CHECK: define void @test59(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test59(i8* %x) nounwind {
+entry:
+ %a = call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ %b = call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Constant pointers to objects don't need reference counting.
+
+@constptr = external constant i8*
+@something = external global i8*
+
+; CHECK: define void @test60(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test60() {
+ %t = load i8** @constptr
+ %s = load i8** @something
+ call i8* @objc_retain(i8* %s)
+ call void @callee()
+ call void @use_pointer(i8* %t)
+ call void @objc_release(i8* %s)
+ ret void
+}
+
+; Constant pointers to objects don't need to be considered related to other
+; pointers.
+
+; CHECK: define void @test61(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test61() {
+ %t = load i8** @constptr
+ call i8* @objc_retain(i8* %t)
+ call void @callee()
+ call void @use_pointer(i8* %t)
+ call void @objc_release(i8* %t)
+ ret void
+}
+
+declare void @bar(i32 ()*)
+
+; A few real-world testcases.
+
+@.str4 = private unnamed_addr constant [33 x i8] c"-[A z] = { %f, %f, { %f, %f } }\0A\00"
+@"OBJC_IVAR_$_A.myZ" = global i64 20, section "__DATA, __objc_const", align 8
+declare i32 @printf(i8* nocapture, ...) nounwind
+declare i32 @puts(i8* nocapture) nounwind
+@str = internal constant [16 x i8] c"-[ Top0 _getX ]\00"
+
+; CHECK: @"\01-[A z]"
+; CHECK-NOT: @objc_
+; CHECK: }
+
+define {<2 x float>, <2 x float>} @"\01-[A z]"({}* %self, i8* nocapture %_cmd) nounwind {
+invoke.cont:
+ %0 = bitcast {}* %self to i8*
+ %1 = tail call i8* @objc_retain(i8* %0) nounwind
+ tail call void @llvm.dbg.value(metadata !{{}* %self}, i64 0, metadata !0)
+ tail call void @llvm.dbg.value(metadata !{{}* %self}, i64 0, metadata !0)
+ %ivar = load i64* @"OBJC_IVAR_$_A.myZ", align 8
+ %add.ptr = getelementptr i8* %0, i64 %ivar
+ %tmp1 = bitcast i8* %add.ptr to float*
+ %tmp2 = load float* %tmp1, align 4
+ %conv = fpext float %tmp2 to double
+ %add.ptr.sum = add i64 %ivar, 4
+ %tmp6 = getelementptr inbounds i8* %0, i64 %add.ptr.sum
+ %2 = bitcast i8* %tmp6 to float*
+ %tmp7 = load float* %2, align 4
+ %conv8 = fpext float %tmp7 to double
+ %add.ptr.sum36 = add i64 %ivar, 8
+ %tmp12 = getelementptr inbounds i8* %0, i64 %add.ptr.sum36
+ %arrayidx = bitcast i8* %tmp12 to float*
+ %tmp13 = load float* %arrayidx, align 4
+ %conv14 = fpext float %tmp13 to double
+ %tmp12.sum = add i64 %ivar, 12
+ %arrayidx19 = getelementptr inbounds i8* %0, i64 %tmp12.sum
+ %3 = bitcast i8* %arrayidx19 to float*
+ %tmp20 = load float* %3, align 4
+ %conv21 = fpext float %tmp20 to double
+ %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([33 x i8]* @.str4, i64 0, i64 0), double %conv, double %conv8, double %conv14, double %conv21)
+ %ivar23 = load i64* @"OBJC_IVAR_$_A.myZ", align 8
+ %add.ptr24 = getelementptr i8* %0, i64 %ivar23
+ %4 = bitcast i8* %add.ptr24 to i128*
+ %srcval = load i128* %4, align 4
+ tail call void @objc_release(i8* %0) nounwind
+ %tmp29 = trunc i128 %srcval to i64
+ %tmp30 = bitcast i64 %tmp29 to <2 x float>
+ %tmp31 = insertvalue {<2 x float>, <2 x float>} undef, <2 x float> %tmp30, 0
+ %tmp32 = lshr i128 %srcval, 64
+ %tmp33 = trunc i128 %tmp32 to i64
+ %tmp34 = bitcast i64 %tmp33 to <2 x float>
+ %tmp35 = insertvalue {<2 x float>, <2 x float>} %tmp31, <2 x float> %tmp34, 1
+ ret {<2 x float>, <2 x float>} %tmp35
+}
+
+; CHECK: @"\01-[Top0 _getX]"
+; CHECK-NOT: @objc_
+; CHECK: }
+
+define i32 @"\01-[Top0 _getX]"({}* %self, i8* nocapture %_cmd) nounwind {
+invoke.cont:
+ %0 = bitcast {}* %self to i8*
+ %1 = tail call i8* @objc_retain(i8* %0) nounwind
+ %puts = tail call i32 @puts(i8* getelementptr inbounds ([16 x i8]* @str, i64 0, i64 0))
+ tail call void @objc_release(i8* %0) nounwind
+ ret i32 0
+}
+
+@"\01L_OBJC_METH_VAR_NAME_" = internal global [5 x i8] c"frob\00", section "__TEXT,__cstring,cstring_literals", align 1@"\01L_OBJC_SELECTOR_REFERENCES_" = internal global i8* getelementptr inbounds ([5 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i64 0, i64 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"
+@llvm.used = appending global [3 x i8*] [i8* getelementptr inbounds ([5 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i32 0, i32 0), i8* bitcast (i8** @"\01L_OBJC_SELECTOR_REFERENCES_" to i8*), i8* bitcast ([2 x i32]* @"\01L_OBJC_IMAGE_INFO" to i8*)], section "llvm.metadata"
+
+; A simple loop. Eliminate the retain and release inside of it!
+
+; CHECK: define void @loop
+; CHECK: for.body:
+; CHECK-NOT: @objc_
+; CHECK: @objc_msgSend
+; CHECK-NOT: @objc_
+; CHECK: for.end:
+define void @loop(i8* %x, i64 %n) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %x) nounwind
+ %cmp9 = icmp sgt i64 %n, 0
+ br i1 %cmp9, label %for.body, label %for.end
+
+for.body: ; preds = %entry, %for.body
+ %i.010 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
+ %1 = tail call i8* @objc_retain(i8* %x) nounwind
+ %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call = tail call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %1, i8* %tmp5)
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ %inc = add nsw i64 %i.010, 1
+ %exitcond = icmp eq i64 %inc, %n
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; ObjCARCOpt can delete the retain,release on self.
+
+; CHECK: define void @TextEditTest
+; CHECK-NOT: call i8* @objc_retain(i8* %tmp7)
+; CHECK: }
+
+%0 = type { i8* (i8*, %struct._message_ref_t*, ...)*, i8* }
+%1 = type opaque
+%2 = type opaque
+%3 = type opaque
+%4 = type opaque
+%5 = type opaque
+%struct.NSConstantString = type { i32*, i32, i8*, i64 }
+%struct._NSRange = type { i64, i64 }
+%struct.__CFString = type opaque
+%struct.__method_list_t = type { i32, i32, [0 x %struct._objc_method] }
+%struct._class_ro_t = type { i32, i32, i32, i8*, i8*, %struct.__method_list_t*, %struct._objc_protocol_list*, %struct._ivar_list_t*, i8*, %struct._prop_list_t* }
+%struct._class_t = type { %struct._class_t*, %struct._class_t*, %struct._objc_cache*, i8* (i8*, i8*)**, %struct._class_ro_t* }
+%struct._ivar_list_t = type { i32, i32, [0 x %struct._ivar_t] }
+%struct._ivar_t = type { i64*, i8*, i8*, i32, i32 }
+%struct._message_ref_t = type { i8*, i8* }
+%struct._objc_cache = type opaque
+%struct._objc_method = type { i8*, i8*, i8* }
+%struct._objc_protocol_list = type { i64, [0 x %struct._protocol_t*] }
+%struct._prop_list_t = type { i32, i32, [0 x %struct._message_ref_t] }
+%struct._protocol_t = type { i8*, i8*, %struct._objc_protocol_list*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct._prop_list_t*, i32, i32 }
+
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_17" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@kUTTypePlainText = external constant %struct.__CFString*
+@"\01L_OBJC_SELECTOR_REFERENCES_19" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_21" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_23" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_25" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_26" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_28" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_29" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_31" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_33" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_35" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_37" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_38" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_40" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_42" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@_unnamed_cfstring_44 = external hidden constant %struct.NSConstantString, section "__DATA,__cfstring"
+@"\01L_OBJC_SELECTOR_REFERENCES_46" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_48" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01l_objc_msgSend_fixup_isEqual_" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_50" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@NSCocoaErrorDomain = external constant %1*
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_51" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@NSFilePathErrorKey = external constant %1*
+@"\01L_OBJC_SELECTOR_REFERENCES_53" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_55" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_56" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_58" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_60" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+
+declare %1* @truncatedString(%1*, i64)
+define void @TextEditTest(%2* %self, %3* %pboard) {
+entry:
+ %err = alloca %4*, align 8
+ %tmp7 = bitcast %2* %self to i8*
+ %tmp8 = call i8* @objc_retain(i8* %tmp7) nounwind
+ store %4* null, %4** %err, align 8
+ %tmp1 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_17", align 8
+ %tmp2 = load %struct.__CFString** @kUTTypePlainText, align 8
+ %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_19", align 8
+ %tmp4 = bitcast %struct._class_t* %tmp1 to i8*
+ %call5 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp4, i8* %tmp3, %struct.__CFString* %tmp2)
+ %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_21", align 8
+ %tmp6 = bitcast %3* %pboard to i8*
+ %call76 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp6, i8* %tmp5, i8* %call5)
+ %tmp9 = call i8* @objc_retain(i8* %call76) nounwind
+ %tobool = icmp eq i8* %tmp9, null
+ br i1 %tobool, label %end, label %land.lhs.true
+
+land.lhs.true: ; preds = %entry
+ %tmp11 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_23", align 8
+ %call137 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp6, i8* %tmp11, i8* %tmp9)
+ %tmp = bitcast i8* %call137 to %1*
+ %tmp10 = call i8* @objc_retain(i8* %call137) nounwind
+ call void @objc_release(i8* null) nounwind
+ %tmp12 = call i8* @objc_retain(i8* %call137) nounwind
+ call void @objc_release(i8* null) nounwind
+ %tobool16 = icmp eq i8* %call137, null
+ br i1 %tobool16, label %end, label %if.then
+
+if.then: ; preds = %land.lhs.true
+ %tmp19 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_25", align 8
+ %call21 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %call137, i8* %tmp19)
+ %tobool22 = icmp eq i8 %call21, 0
+ br i1 %tobool22, label %if.then44, label %land.lhs.true23
+
+land.lhs.true23: ; preds = %if.then
+ %tmp24 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_26", align 8
+ %tmp26 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_28", align 8
+ %tmp27 = bitcast %struct._class_t* %tmp24 to i8*
+ %call2822 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp27, i8* %tmp26, i8* %call137)
+ %tmp13 = bitcast i8* %call2822 to %5*
+ %tmp14 = call i8* @objc_retain(i8* %call2822) nounwind
+ call void @objc_release(i8* null) nounwind
+ %tobool30 = icmp eq i8* %call2822, null
+ br i1 %tobool30, label %if.then44, label %if.end
+
+if.end: ; preds = %land.lhs.true23
+ %tmp32 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_29", align 8
+ %tmp33 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_31", align 8
+ %tmp34 = bitcast %struct._class_t* %tmp32 to i8*
+ %call35 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp34, i8* %tmp33)
+ %tmp37 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_33", align 8
+ %call3923 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call35, i8* %tmp37, i8* %call2822, i32 signext 1, %4** %err)
+ %cmp = icmp eq i8* %call3923, null
+ br i1 %cmp, label %if.then44, label %end
+
+if.then44: ; preds = %if.end, %land.lhs.true23, %if.then
+ %url.025 = phi %5* [ %tmp13, %if.end ], [ %tmp13, %land.lhs.true23 ], [ null, %if.then ]
+ %tmp49 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_35", align 8
+ %call51 = call %struct._NSRange bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %struct._NSRange (i8*, i8*, i64, i64)*)(i8* %call137, i8* %tmp49, i64 0, i64 0)
+ %call513 = extractvalue %struct._NSRange %call51, 0
+ %call514 = extractvalue %struct._NSRange %call51, 1
+ %tmp52 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_37", align 8
+ %call548 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call137, i8* %tmp52, i64 %call513, i64 %call514)
+ %tmp55 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_38", align 8
+ %tmp56 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_40", align 8
+ %tmp57 = bitcast %struct._class_t* %tmp55 to i8*
+ %call58 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp57, i8* %tmp56)
+ %tmp59 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_42", align 8
+ %call6110 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call548, i8* %tmp59, i8* %call58)
+ %tmp15 = call i8* @objc_retain(i8* %call6110) nounwind
+ call void @objc_release(i8* %call137) nounwind
+ %tmp64 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_46", align 8
+ %call66 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*, %1*)*)(i8* %call6110, i8* %tmp64, %1* bitcast (%struct.NSConstantString* @_unnamed_cfstring_44 to %1*))
+ %tobool67 = icmp eq i8 %call66, 0
+ br i1 %tobool67, label %if.end74, label %if.then68
+
+if.then68: ; preds = %if.then44
+ %tmp70 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_48", align 8
+ %call7220 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call6110, i8* %tmp70)
+ %tmp16 = call i8* @objc_retain(i8* %call7220) nounwind
+ call void @objc_release(i8* %call6110) nounwind
+ br label %if.end74
+
+if.end74: ; preds = %if.then68, %if.then44
+ %filename.0.in = phi i8* [ %call7220, %if.then68 ], [ %call6110, %if.then44 ]
+ %filename.0 = bitcast i8* %filename.0.in to %1*
+ %tmp17 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_isEqual_" to i8**), align 16
+ %tmp18 = bitcast i8* %tmp17 to i8 (i8*, %struct._message_ref_t*, i8*, ...)*
+ %call78 = call signext i8 (i8*, %struct._message_ref_t*, i8*, ...)* %tmp18(i8* %call137, %struct._message_ref_t* bitcast (%0* @"\01l_objc_msgSend_fixup_isEqual_" to %struct._message_ref_t*), i8* %filename.0.in)
+ %tobool79 = icmp eq i8 %call78, 0
+ br i1 %tobool79, label %land.lhs.true80, label %if.then109
+
+land.lhs.true80: ; preds = %if.end74
+ %tmp82 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_25", align 8
+ %call84 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %filename.0.in, i8* %tmp82)
+ %tobool86 = icmp eq i8 %call84, 0
+ br i1 %tobool86, label %if.then109, label %if.end106
+
+if.end106: ; preds = %land.lhs.true80
+ %tmp88 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_26", align 8
+ %tmp90 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_28", align 8
+ %tmp91 = bitcast %struct._class_t* %tmp88 to i8*
+ %call9218 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp91, i8* %tmp90, i8* %filename.0.in)
+ %tmp20 = bitcast i8* %call9218 to %5*
+ %tmp21 = call i8* @objc_retain(i8* %call9218) nounwind
+ %tmp22 = bitcast %5* %url.025 to i8*
+ call void @objc_release(i8* %tmp22) nounwind
+ %tmp94 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_29", align 8
+ %tmp95 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_31", align 8
+ %tmp96 = bitcast %struct._class_t* %tmp94 to i8*
+ %call97 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp96, i8* %tmp95)
+ %tmp99 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_33", align 8
+ %call10119 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call97, i8* %tmp99, i8* %call9218, i32 signext 1, %4** %err)
+ %phitmp = icmp eq i8* %call10119, null
+ br i1 %phitmp, label %if.then109, label %end
+
+if.then109: ; preds = %if.end106, %land.lhs.true80, %if.end74
+ %url.129 = phi %5* [ %tmp20, %if.end106 ], [ %url.025, %if.end74 ], [ %url.025, %land.lhs.true80 ]
+ %tmp110 = load %4** %err, align 8
+ %tobool111 = icmp eq %4* %tmp110, null
+ br i1 %tobool111, label %if.then112, label %if.end125
+
+if.then112: ; preds = %if.then109
+ %tmp113 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_50", align 8
+ %tmp114 = load %1** @NSCocoaErrorDomain, align 8
+ %tmp115 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_51", align 8
+ %call117 = call %1* @truncatedString(%1* %filename.0, i64 1034)
+ %tmp118 = load %1** @NSFilePathErrorKey, align 8
+ %tmp119 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_53", align 8
+ %tmp120 = bitcast %struct._class_t* %tmp115 to i8*
+ %call12113 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp120, i8* %tmp119, %1* %call117, %1* %tmp118, i8* null)
+ %tmp122 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_55", align 8
+ %tmp123 = bitcast %struct._class_t* %tmp113 to i8*
+ %call12414 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp123, i8* %tmp122, %1* %tmp114, i64 258, i8* %call12113)
+ %tmp23 = call i8* @objc_retain(i8* %call12414) nounwind
+ %tmp25 = call i8* @objc_autorelease(i8* %tmp23) nounwind
+ %tmp28 = bitcast i8* %tmp25 to %4*
+ store %4* %tmp28, %4** %err, align 8
+ br label %if.end125
+
+if.end125: ; preds = %if.then112, %if.then109
+ %tmp127 = phi %4* [ %tmp110, %if.then109 ], [ %tmp28, %if.then112 ]
+ %tmp126 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_56", align 8
+ %tmp128 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_58", align 8
+ %tmp129 = bitcast %struct._class_t* %tmp126 to i8*
+ %call13015 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp129, i8* %tmp128, %4* %tmp127)
+ %tmp131 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_60", align 8
+ %call13317 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call13015, i8* %tmp131)
+ br label %end
+
+end: ; preds = %if.end125, %if.end106, %if.end, %land.lhs.true, %entry
+ %filename.2 = phi %1* [ %filename.0, %if.end106 ], [ %filename.0, %if.end125 ], [ %tmp, %land.lhs.true ], [ null, %entry ], [ %tmp, %if.end ]
+ %origFilename.0 = phi %1* [ %tmp, %if.end106 ], [ %tmp, %if.end125 ], [ %tmp, %land.lhs.true ], [ null, %entry ], [ %tmp, %if.end ]
+ %url.2 = phi %5* [ %tmp20, %if.end106 ], [ %url.129, %if.end125 ], [ null, %land.lhs.true ], [ null, %entry ], [ %tmp13, %if.end ]
+ call void @objc_release(i8* %tmp9) nounwind, !clang.imprecise_release !0
+ %tmp29 = bitcast %5* %url.2 to i8*
+ call void @objc_release(i8* %tmp29) nounwind, !clang.imprecise_release !0
+ %tmp30 = bitcast %1* %origFilename.0 to i8*
+ call void @objc_release(i8* %tmp30) nounwind, !clang.imprecise_release !0
+ %tmp31 = bitcast %1* %filename.2 to i8*
+ call void @objc_release(i8* %tmp31) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %tmp7) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+!0 = metadata !{}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/ObjCARC/cfg-hazards.ll b/src/LLVM/test/Transforms/ObjCARC/cfg-hazards.ll
new file mode 100644
index 0000000..1519423
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/cfg-hazards.ll
@@ -0,0 +1,397 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+; rdar://9503416
+
+; Detect loop boundaries and don't move retains and releases
+; across them.
+
+declare void @use_pointer(i8*)
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+declare void @callee()
+
+; CHECK: define void @test0(
+; CHECK: call i8* @objc_retain(
+; CHECK: for.body:
+; CHECK-NOT: @objc
+; CHECK: for.end:
+; CHECK: call void @objc_release(
+; CHECK: }
+define void @test0(i8* %digits) {
+entry:
+ %tmp1 = call i8* @objc_retain(i8* %digits) nounwind
+ call void @use_pointer(i8* %digits)
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
+ call void @use_pointer(i8* %digits)
+ %inc = add i64 %upcDigitIndex.01, 1
+ %cmp = icmp ult i64 %inc, 12
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test1(
+; CHECK: call i8* @objc_retain(
+; CHECK: for.body:
+; CHECK-NOT: @objc
+; CHECK: for.end:
+; CHECK: void @objc_release(
+; CHECK: }
+define void @test1(i8* %digits) {
+entry:
+ %tmp1 = call i8* @objc_retain(i8* %digits) nounwind
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
+ call void @use_pointer(i8* %digits)
+ call void @use_pointer(i8* %digits)
+ %inc = add i64 %upcDigitIndex.01, 1
+ %cmp = icmp ult i64 %inc, 12
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test2(
+; CHECK: call i8* @objc_retain(
+; CHECK: for.body:
+; CHECK-NOT: @objc
+; CHECK: for.end:
+; CHECK: void @objc_release(
+; CHECK: }
+define void @test2(i8* %digits) {
+entry:
+ %tmp1 = call i8* @objc_retain(i8* %digits) nounwind
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
+ call void @use_pointer(i8* %digits)
+ %inc = add i64 %upcDigitIndex.01, 1
+ %cmp = icmp ult i64 %inc, 12
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ call void @use_pointer(i8* %digits)
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete nested retain+release pairs around loops.
+
+; CHECK: define void @test3(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test3(i8* %a) nounwind {
+entry:
+ %outer = call i8* @objc_retain(i8* %a) nounwind
+ %inner = call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ call void @callee()
+ store i8 0, i8* %a
+ br i1 undef, label %loop, label %exit
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test4(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test4(i8* %a) nounwind {
+entry:
+ %outer = call i8* @objc_retain(i8* %a) nounwind
+ %inner = call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br label %more
+
+more:
+ call void @callee()
+ call void @callee()
+ store i8 0, i8* %a
+ br i1 undef, label %loop, label %exit
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test5(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @use_pointer(i8* %a)
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test5(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ call void @callee()
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @use_pointer(i8* %a)
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test6(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @use_pointer(i8* %a)
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test6(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @use_pointer(i8* %a)
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test7(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test7(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ call void @callee()
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test8(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test8(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test9(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test9(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test10(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test10(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test11(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test11(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Don't delete anything if they're not balanced.
+
+; CHECK: define void @test12(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %outer = tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: %inner = tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a) nounwind
+; CHECK-NEXT: call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test12(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ ret void
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/contract-marker.ll b/src/LLVM/test/Transforms/ObjCARC/contract-marker.ll
new file mode 100644
index 0000000..01d978a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/contract-marker.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -objc-arc-contract < %s | FileCheck %s
+
+; CHECK: %call = tail call i32* @qux()
+; CHECK-NEXT: %tcall = bitcast i32* %call to i8*
+; CHECK-NEXT: call void asm sideeffect "mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue", ""()
+; CHECK-NEXT: %0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tcall) nounwind
+
+define void @foo() {
+entry:
+ %call = tail call i32* @qux()
+ %tcall = bitcast i32* %call to i8*
+ %0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tcall) nounwind
+ tail call void @bar(i8* %0)
+ ret void
+}
+
+declare i32* @qux()
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare void @bar(i8*)
+
+!clang.arc.retainAutoreleasedReturnValueMarker = !{!0}
+
+!0 = metadata !{metadata !"mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue"}
diff --git a/src/LLVM/test/Transforms/ObjCARC/contract-storestrong-ivar.ll b/src/LLVM/test/Transforms/ObjCARC/contract-storestrong-ivar.ll
new file mode 100644
index 0000000..4ad78e7
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/contract-storestrong-ivar.ll
@@ -0,0 +1,31 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+
+; CHECK: call void @objc_storeStrong(i8**
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.0"
+
+%0 = type opaque
+%1 = type opaque
+
+@"OBJC_IVAR_$_Controller.preferencesController" = external global i64, section "__DATA, __objc_const", align 8
+
+declare i8* @objc_retain(i8*)
+
+declare void @objc_release(i8*)
+
+define hidden void @y(%0* nocapture %self, %1* %preferencesController) nounwind {
+entry:
+ %ivar = load i64* @"OBJC_IVAR_$_Controller.preferencesController", align 8
+ %tmp = bitcast %0* %self to i8*
+ %add.ptr = getelementptr inbounds i8* %tmp, i64 %ivar
+ %tmp1 = bitcast i8* %add.ptr to %1**
+ %tmp2 = load %1** %tmp1, align 8
+ %tmp3 = bitcast %1* %preferencesController to i8*
+ %tmp4 = tail call i8* @objc_retain(i8* %tmp3) nounwind
+ %tmp5 = bitcast %1* %tmp2 to i8*
+ tail call void @objc_release(i8* %tmp5) nounwind
+ %tmp6 = bitcast i8* %tmp4 to %1*
+ store %1* %tmp6, %1** %tmp1, align 8
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/contract-storestrong.ll b/src/LLVM/test/Transforms/ObjCARC/contract-storestrong.ll
new file mode 100644
index 0000000..25c93f4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/contract-storestrong.ll
@@ -0,0 +1,59 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+
+@x = external global i8*
+
+; CHECK: define void @test0(
+; CHECK: entry:
+; CHECK-NEXT: call void @objc_storeStrong(i8** @x, i8* %p) nounwind
+; CHECK-NEXT: ret void
+define void @test0(i8* %p) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %p) nounwind
+ %tmp = load i8** @x, align 8
+ store i8* %0, i8** @x, align 8
+ tail call void @objc_release(i8* %tmp) nounwind
+ ret void
+}
+
+; Don't do this if the load is volatile.
+
+; CHECK: define void @test1(i8* %p) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK-NEXT: %tmp = load volatile i8** @x, align 8
+; CHECK-NEXT: store i8* %0, i8** @x, align 8
+; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test1(i8* %p) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %p) nounwind
+ %tmp = volatile load i8** @x, align 8
+ store i8* %0, i8** @x, align 8
+ tail call void @objc_release(i8* %tmp) nounwind
+ ret void
+}
+
+; Don't do this if the store is volatile.
+
+; CHECK: define void @test2(i8* %p) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK-NEXT: %tmp = load i8** @x, align 8
+; CHECK-NEXT: store volatile i8* %0, i8** @x, align 8
+; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test2(i8* %p) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %p) nounwind
+ %tmp = load i8** @x, align 8
+ volatile store i8* %0, i8** @x, align 8
+ tail call void @objc_release(i8* %tmp) nounwind
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/contract-testcases.ll b/src/LLVM/test/Transforms/ObjCARC/contract-testcases.ll
new file mode 100644
index 0000000..69fa837
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/contract-testcases.ll
@@ -0,0 +1,63 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+; rdar://9511608
+
+%0 = type opaque
+%1 = type opaque
+%2 = type { i64, i64 }
+%3 = type { i8*, i8* }
+%4 = type opaque
+
+declare %0* @"\01-[NSAttributedString(Terminal) pathAtIndex:effectiveRange:]"(%1*, i8* nocapture, i64, %2*) optsize
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare i8* @objc_msgSend_fixup(i8*, %3*, ...)
+declare void @objc_release(i8*)
+declare %2 @NSUnionRange(i64, i64, i64, i64) optsize
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_autorelease(i8*)
+declare i8* @objc_msgSend() nonlazybind
+
+; Don't get in trouble on bugpointed code.
+
+; CHECK: define void @test0(
+define void @test0() {
+bb:
+ %tmp = bitcast %4* undef to i8*
+ %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tmp) nounwind
+ br label %bb3
+
+bb3: ; preds = %bb2
+ br i1 undef, label %bb6, label %bb4
+
+bb4: ; preds = %bb3
+ switch i64 undef, label %bb5 [
+ i64 9223372036854775807, label %bb6
+ i64 0, label %bb6
+ ]
+
+bb5: ; preds = %bb4
+ br label %bb6
+
+bb6: ; preds = %bb5, %bb4, %bb4, %bb3
+ %tmp7 = phi %4* [ undef, %bb5 ], [ undef, %bb4 ], [ undef, %bb3 ], [ undef, %bb4 ]
+ unreachable
+}
+
+; When rewriting operands for a phi which has multiple operands
+; for the same block, use the exactly same value in each block.
+
+; CHECK: define void @test1(
+; CHECK: %0 = bitcast i8* %tmp3 to %0*
+; CHECK: br i1 undef, label %bb7, label %bb7
+; CHECK: bb7:
+; CHECK: %tmp8 = phi %0* [ %0, %bb ], [ %0, %bb ]
+define void @test1() {
+bb:
+ %tmp = tail call %0* bitcast (i8* ()* @objc_msgSend to %0* ()*)()
+ %tmp2 = bitcast %0* %tmp to i8*
+ %tmp3 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tmp2) nounwind
+ br i1 undef, label %bb7, label %bb7
+
+bb7: ; preds = %bb6, %bb6, %bb5
+ %tmp8 = phi %0* [ %tmp, %bb ], [ %tmp, %bb ]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/contract.ll b/src/LLVM/test/Transforms/ObjCARC/contract.ll
new file mode 100644
index 0000000..04ae3ca
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/contract.ll
@@ -0,0 +1,145 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+declare i8* @objc_autorelease(i8*)
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+
+declare void @use_pointer(i8*)
+declare i8* @returner()
+
+; CHECK: define void @test0
+; CHECK: call void @use_pointer(i8* %0)
+; CHECK: }
+define void @test0(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ ret void
+}
+
+; CHECK: define void @test1
+; CHECK: call void @use_pointer(i8* %0)
+; CHECK: }
+define void @test1(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_autorelease(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ ret void
+}
+
+; Merge objc_retain and objc_autorelease into objc_retainAutorelease.
+
+; CHECK: define void @test2(
+; CHECK: tail call i8* @objc_retainAutorelease(i8* %x) nounwind
+; CHECK: }
+define void @test2(i8* %x) nounwind {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %x) nounwind
+ tail call i8* @objc_autorelease(i8* %0) nounwind
+ call void @use_pointer(i8* %x)
+ ret void
+}
+
+; Same as test2 but the value is returned. Do an RV optimization.
+
+; CHECK: define i8* @test2b(
+; CHECK: tail call i8* @objc_retainAutoreleaseReturnValue(i8* %x) nounwind
+; CHECK: }
+define i8* @test2b(i8* %x) nounwind {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %x) nounwind
+ tail call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+ ret i8* %x
+}
+
+; Merge a retain,autorelease pair around a call.
+
+; CHECK: define void @test3(
+; CHECK: tail call i8* @objc_retainAutorelease(i8* %x) nounwind
+; CHECK: @use_pointer(i8* %0)
+; CHECK: }
+define void @test3(i8* %x, i64 %n) {
+entry:
+ tail call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ tail call i8* @objc_autorelease(i8* %x) nounwind
+ ret void
+}
+
+; Trivial retain,autorelease pair with intervening call, but it's post-dominated
+; by another release. The retain and autorelease can be merged.
+
+; CHECK: define void @test4(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: @objc_retainAutorelease(i8* %x) nounwind
+; CHECK-NEXT: @use_pointer
+; CHECK-NEXT: @objc_release
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test4(i8* %x, i64 %n) {
+entry:
+ tail call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ tail call i8* @objc_autorelease(i8* %x) nounwind
+ tail call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Don't merge retain and autorelease if they're not control-equivalent.
+
+; CHECK: define void @test5(
+; CHECK: tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK: true:
+; CHECK: tail call i8* @objc_autorelease(i8* %0) nounwind
+; CHECK: }
+define void @test5(i8* %p, i1 %a) {
+entry:
+ tail call i8* @objc_retain(i8* %p) nounwind
+ br i1 %a, label %true, label %false
+
+true:
+ tail call i8* @objc_autorelease(i8* %p) nounwind
+ call void @use_pointer(i8* %p)
+ ret void
+
+false:
+ ret void
+}
+
+; Don't eliminate objc_retainAutoreleasedReturnValue by merging it into
+; an objc_autorelease.
+; TODO? Merge objc_retainAutoreleasedReturnValue and objc_autorelease into
+; objc_retainAutoreleasedReturnValueAutorelease and merge
+; objc_retainAutoreleasedReturnValue and objc_autoreleaseReturnValue
+; into objc_retainAutoreleasedReturnValueAutoreleaseReturnValue?
+; Those entrypoints don't exist yet though.
+
+; CHECK: define i8* @test6(
+; CHECK: call i8* @objc_retainAutoreleasedReturnValue(i8* %p) nounwind
+; CHECK: %t = tail call i8* @objc_autoreleaseReturnValue(i8* %1) nounwind
+; CHECK: }
+define i8* @test6() {
+ %p = call i8* @returner()
+ tail call i8* @objc_retainAutoreleasedReturnValue(i8* %p) nounwind
+ %t = tail call i8* @objc_autoreleaseReturnValue(i8* %p) nounwind
+ call void @use_pointer(i8* %t)
+ ret i8* %t
+}
+
+; Don't spoil the RV optimization.
+
+; CHECK: define i8* @test7(i8* %p)
+; CHECK: tail call i8* @objc_retain(i8* %p)
+; CHECK: call void @use_pointer(i8* %1)
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %1)
+; CHECK: ret i8* %2
+define i8* @test7(i8* %p) {
+ %1 = tail call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ %2 = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+ ret i8* %p
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/dg.exp b/src/LLVM/test/Transforms/ObjCARC/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/ObjCARC/empty-block.ll b/src/LLVM/test/Transforms/ObjCARC/empty-block.ll
new file mode 100644
index 0000000..ca55413
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/empty-block.ll
@@ -0,0 +1,59 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+; rdar://10210274
+
+%0 = type opaque
+
+declare i8* @objc_retain(i8*)
+
+declare void @objc_release(i8*)
+
+declare i8* @objc_autoreleaseReturnValue(i8*)
+
+; Don't delete the autorelease.
+
+; CHECK: define %0* @test0(
+; CHECK: @objc_retain
+; CHECK: .lr.ph:
+; CHECK-NOT: @objc_r
+; CHECK: @objc_autoreleaseReturnValue
+; CHECK-NOT: @objc_
+; CHECK: }
+define %0* @test0(%0* %buffer) nounwind {
+ %1 = bitcast %0* %buffer to i8*
+ %2 = tail call i8* @objc_retain(i8* %1) nounwind
+ br i1 undef, label %.lr.ph, label %._crit_edge
+
+.lr.ph: ; preds = %.lr.ph, %0
+ br i1 false, label %.lr.ph, label %._crit_edge
+
+._crit_edge: ; preds = %.lr.ph, %0
+ %3 = tail call i8* @objc_retain(i8* %1) nounwind
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ %4 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) nounwind
+ ret %0* %buffer
+}
+
+; Do delete the autorelease, even with the retain in a different block.
+
+; CHECK: define %0* @test1(
+; CHECK-NOT: @objc
+; CHECK: }
+define %0* @test1() nounwind {
+ %buffer = call %0* @foo()
+ %1 = bitcast %0* %buffer to i8*
+ %2 = tail call i8* @objc_retain(i8* %1) nounwind
+ br i1 undef, label %.lr.ph, label %._crit_edge
+
+.lr.ph: ; preds = %.lr.ph, %0
+ br i1 false, label %.lr.ph, label %._crit_edge
+
+._crit_edge: ; preds = %.lr.ph, %0
+ %3 = tail call i8* @objc_retain(i8* %1) nounwind
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ %4 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) nounwind
+ ret %0* %buffer
+}
+
+declare %0* @foo()
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/expand.ll b/src/LLVM/test/Transforms/ObjCARC/expand.ll
new file mode 100644
index 0000000..5388673
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/expand.ll
@@ -0,0 +1,28 @@
+; RUN: opt -objc-arc-expand -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+declare i8* @objc_retain(i8*)
+declare i8* @objc_autorelease(i8*)
+
+declare void @use_pointer(i8*)
+
+; CHECK: define void @test0
+; CHECK: call void @use_pointer(i8* %x)
+; CHECK: }
+define void @test0(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %0)
+ ret void
+}
+
+; CHECK: define void @test1
+; CHECK: call void @use_pointer(i8* %x)
+; CHECK: }
+define void @test1(i8* %x) nounwind {
+entry:
+ %0 = call i8* @objc_autorelease(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/gvn.ll b/src/LLVM/test/Transforms/ObjCARC/gvn.ll
new file mode 100644
index 0000000..6917b02
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/gvn.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -basicaa -objc-arc -gvn < %s | FileCheck %s
+
+@x = common global i8* null, align 8
+
+declare i8* @objc_retain(i8*)
+
+; GVN should be able to eliminate this redundant load, with ARC-specific
+; alias analysis.
+
+; CHECK: @foo
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %s = load i8** @x
+; CHECK-NOT: load
+; CHECK: ret i8* %s
+define i8* @foo(i32 %n) nounwind {
+entry:
+ %s = load i8** @x
+ %0 = tail call i8* @objc_retain(i8* %s) nounwind
+ %t = load i8** @x
+ ret i8* %s
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/invoke.ll b/src/LLVM/test/Transforms/ObjCARC/invoke.ll
new file mode 100644
index 0000000..cf971e4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/invoke.ll
@@ -0,0 +1,73 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+declare i8* @objc_msgSend(i8*, i8*, ...)
+declare void @use_pointer(i8*)
+declare void @callee()
+
+; ARCOpt shouldn't try to move the releases to the block containing the invoke.
+
+; CHECK: define void @test0(
+; CHECK: invoke.cont:
+; CHECK: call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+; CHECK: ret void
+; CHECK: lpad:
+; CHECK: call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+; CHECK: ret void
+define void @test0(i8* %zipFile) {
+entry:
+ call i8* @objc_retain(i8* %zipFile) nounwind
+ call void @use_pointer(i8* %zipFile)
+ invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %zipFile)
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+ ret void
+
+lpad: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; ARCOpt should move the release before the callee calls.
+
+; CHECK: define void @test1(
+; CHECK: invoke.cont:
+; CHECK: call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+; CHECK: call void @callee()
+; CHECK: br label %done
+; CHECK: lpad:
+; CHECK: call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+; CHECK: call void @callee()
+; CHECK: br label %done
+; CHECK: done:
+; CHECK-NEXT: ret void
+define void @test1(i8* %zipFile) {
+entry:
+ call i8* @objc_retain(i8* %zipFile) nounwind
+ call void @use_pointer(i8* %zipFile)
+ invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %zipFile)
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ call void @callee()
+ br label %done
+
+lpad: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @callee()
+ br label %done
+
+done:
+ call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/move-and-form-retain-autorelease.ll b/src/LLVM/test/Transforms/ObjCARC/move-and-form-retain-autorelease.ll
new file mode 100644
index 0000000..170d0a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/move-and-form-retain-autorelease.ll
@@ -0,0 +1,221 @@
+; RUN: opt -S -objc-arc-contract < %s | FileCheck %s
+
+; The optimizer should be able to move the autorelease past a control triangle
+; and various scary looking things and fold it into an objc_retainAutorelease.
+
+; CHECK: bb57:
+; CHECK: tail call i8* @objc_retainAutorelease(i8* %tmp71x) nounwind
+; CHECK: bb99:
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.0"
+
+%0 = type { i8* (i8*, %1*, ...)*, i8* }
+%1 = type { i8*, i8* }
+%2 = type { %2*, %2*, %3*, i8* (i8*, i8*)**, %4* }
+%3 = type opaque
+%4 = type { i32, i32, i32, i8*, i8*, %5*, %7*, %10*, i8*, %9* }
+%5 = type { i32, i32, [0 x %6] }
+%6 = type { i8*, i8*, i8* }
+%7 = type { i64, [0 x %8*] }
+%8 = type { i8*, i8*, %7*, %5*, %5*, %5*, %5*, %9*, i32, i32 }
+%9 = type { i32, i32, [0 x %1] }
+%10 = type { i32, i32, [0 x %11] }
+%11 = type { i64*, i8*, i8*, i32, i32 }
+%12 = type { i32*, i32, i8*, i64 }
+%13 = type opaque
+%14 = type opaque
+%15 = type opaque
+%16 = type opaque
+%17 = type opaque
+%18 = type opaque
+%19 = type opaque
+%20 = type opaque
+%21 = type opaque
+%22 = type opaque
+%23 = type opaque
+%24 = type opaque
+%25 = type opaque
+
+@"\01l_objc_msgSend_fixup_alloc" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
+@"\01L_OBJC_SELECTOR_REFERENCES_8" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_3725" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_40" = external hidden global %2*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_4227" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_4631" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_70" = external hidden global %2*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_148" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_159" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_188" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_328" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01l_objc_msgSend_fixup_objectAtIndex_" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
+@_unnamed_cfstring_386 = external hidden constant %12, section "__DATA,__cfstring"
+@"\01l_objc_msgSend_fixup_count" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
+@"\01L_OBJC_SELECTOR_REFERENCES_389" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_391" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_393" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@NSPrintHeaderAndFooter = external constant %13*
+@"\01L_OBJC_SELECTOR_REFERENCES_395" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_396" = external hidden global %2*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_398" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_400" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_402" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_404" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_406" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_408" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_CLASSLIST_REFERENCES_$_409" = external hidden global %2*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
+@"\01L_OBJC_SELECTOR_REFERENCES_411" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_413" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_415" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+
+declare i8* @objc_msgSend(i8*, i8*, ...)
+
+declare i8* @objc_retain(i8*)
+
+declare void @objc_release(i8*)
+
+declare i8* @objc_autorelease(i8*)
+
+declare i8* @objc_explicit_autorelease(i8*)
+
+define hidden %14* @foo(%15* %arg, %16* %arg2) {
+bb:
+ %tmp = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_3725", align 8
+ %tmp4 = bitcast %15* %arg to i8*
+ %tmp5 = tail call %18* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %18* (i8*, i8*)*)(i8* %tmp4, i8* %tmp)
+ %tmp6 = bitcast %18* %tmp5 to i8*
+ %tmp7 = tail call i8* @objc_retain(i8* %tmp6) nounwind
+ %tmp8 = load %2** @"\01L_OBJC_CLASSLIST_REFERENCES_$_40", align 8
+ %tmp9 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_4227", align 8
+ %tmp10 = bitcast %2* %tmp8 to i8*
+ %tmp11 = tail call %19* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %19* (i8*, i8*)*)(i8* %tmp10, i8* %tmp9)
+ %tmp12 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_4631", align 8
+ %tmp13 = bitcast %19* %tmp11 to i8*
+ %tmp14 = tail call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*, %13*)*)(i8* %tmp13, i8* %tmp12, %13* bitcast (%12* @_unnamed_cfstring_386 to %13*))
+ %tmp15 = bitcast %16* %arg2 to i8*
+ %tmp16 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_count" to i8**), align 16
+ %tmp17 = bitcast i8* %tmp16 to i64 (i8*, %1*)*
+ %tmp18 = tail call i64 %tmp17(i8* %tmp15, %1* bitcast (%0* @"\01l_objc_msgSend_fixup_count" to %1*))
+ %tmp19 = icmp eq i64 %tmp18, 0
+ br i1 %tmp19, label %bb22, label %bb20
+
+bb20: ; preds = %bb
+ %tmp21 = icmp eq i8 %tmp14, 0
+ br label %bb25
+
+bb22: ; preds = %bb
+ %tmp23 = bitcast i8* %tmp7 to %18*
+ %tmp24 = icmp eq i8 %tmp14, 0
+ br i1 %tmp24, label %bb46, label %bb25
+
+bb25: ; preds = %bb22, %bb20
+ %tmp26 = phi i1 [ %tmp21, %bb20 ], [ false, %bb22 ]
+ %tmp27 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_188", align 8
+ %tmp28 = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %tmp7, i8* %tmp27)
+ %tmp29 = tail call i8* @objc_explicit_autorelease(i8* %tmp28) nounwind
+ %tmp30 = bitcast i8* %tmp29 to %18*
+ tail call void @objc_release(i8* %tmp7) nounwind
+ %tmp31 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_389", align 8
+ %tmp32 = tail call %20* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %20* (i8*, i8*)*)(i8* %tmp29, i8* %tmp31)
+ %tmp33 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_391", align 8
+ %tmp34 = bitcast %20* %tmp32 to i8*
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %16*)*)(i8* %tmp34, i8* %tmp33, %16* %arg2)
+ br i1 %tmp26, label %bb46, label %bb35
+
+bb35: ; preds = %bb25
+ %tmp36 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_389", align 8
+ %tmp37 = tail call %20* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %20* (i8*, i8*)*)(i8* %tmp29, i8* %tmp36)
+ %tmp38 = load %2** @"\01L_OBJC_CLASSLIST_REFERENCES_$_70", align 8
+ %tmp39 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_393", align 8
+ %tmp40 = bitcast %2* %tmp38 to i8*
+ %tmp41 = tail call %21* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %21* (i8*, i8*, i8)*)(i8* %tmp40, i8* %tmp39, i8 signext 1)
+ %tmp42 = bitcast %21* %tmp41 to i8*
+ %tmp43 = load %13** @NSPrintHeaderAndFooter, align 8
+ %tmp44 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_159", align 8
+ %tmp45 = bitcast %20* %tmp37 to i8*
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*, %13*)*)(i8* %tmp45, i8* %tmp44, i8* %tmp42, %13* %tmp43)
+ br label %bb46
+
+bb46: ; preds = %bb35, %bb25, %bb22
+ %tmp47 = phi %18* [ %tmp30, %bb35 ], [ %tmp30, %bb25 ], [ %tmp23, %bb22 ]
+ %tmp48 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
+ %tmp49 = tail call %22* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %22* (i8*, i8*)*)(i8* %tmp4, i8* %tmp48)
+ %tmp50 = bitcast %22* %tmp49 to i8*
+ %tmp51 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_count" to i8**), align 16
+ %tmp52 = bitcast i8* %tmp51 to i64 (i8*, %1*)*
+ %tmp53 = tail call i64 %tmp52(i8* %tmp50, %1* bitcast (%0* @"\01l_objc_msgSend_fixup_count" to %1*))
+ %tmp54 = icmp eq i64 %tmp53, 0
+ br i1 %tmp54, label %bb55, label %bb57
+
+bb55: ; preds = %bb46
+ %tmp56 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_395", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*)*)(i8* %tmp4, i8* %tmp56)
+ br label %bb57
+
+bb57: ; preds = %bb55, %bb46
+ %tmp58 = load %2** @"\01L_OBJC_CLASSLIST_REFERENCES_$_396", align 8
+ %tmp59 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
+ %tmp60 = tail call %22* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %22* (i8*, i8*)*)(i8* %tmp4, i8* %tmp59)
+ %tmp61 = bitcast %22* %tmp60 to i8*
+ %tmp62 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_objectAtIndex_" to i8**), align 16
+ %tmp63 = bitcast i8* %tmp62 to i8* (i8*, %1*, i64)*
+ %tmp64 = tail call i8* %tmp63(i8* %tmp61, %1* bitcast (%0* @"\01l_objc_msgSend_fixup_objectAtIndex_" to %1*), i64 0)
+ %tmp65 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_398", align 8
+ %tmp66 = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %tmp64, i8* %tmp65)
+ %tmp67 = bitcast i8* %tmp66 to %23*
+ %tmp68 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_400", align 8
+ %tmp69 = bitcast %2* %tmp58 to i8*
+ %tmp70 = tail call %14* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %14* (i8*, i8*, %23*, %18*)*)(i8* %tmp69, i8* %tmp68, %23* %tmp67, %18* %tmp47)
+ %tmp71 = bitcast %14* %tmp70 to i8*
+ ; hack to prevent the optimize from using objc_retainAutoreleasedReturnValue.
+ %tmp71x = getelementptr i8* %tmp71, i64 1
+ %tmp72 = tail call i8* @objc_retain(i8* %tmp71x) nounwind
+ %tmp73 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_402", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8)*)(i8* %tmp72, i8* %tmp73, i8 signext 1)
+ %tmp74 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_404", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8)*)(i8* %tmp72, i8* %tmp74, i8 signext 1)
+ %tmp75 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
+ %tmp76 = tail call %22* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %22* (i8*, i8*)*)(i8* %tmp4, i8* %tmp75)
+ %tmp77 = bitcast %22* %tmp76 to i8*
+ %tmp78 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_objectAtIndex_" to i8**), align 16
+ %tmp79 = bitcast i8* %tmp78 to i8* (i8*, %1*, i64)*
+ %tmp80 = tail call i8* %tmp79(i8* %tmp77, %1* bitcast (%0* @"\01l_objc_msgSend_fixup_objectAtIndex_" to %1*), i64 0)
+ %tmp81 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_406", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i64)*)(i8* %tmp80, i8* %tmp81, i64 9223372036854775807)
+ %tmp82 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_408", align 8
+ %tmp83 = tail call %24* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %24* (i8*, i8*)*)(i8* %tmp72, i8* %tmp82)
+ %tmp84 = bitcast %24* %tmp83 to i8*
+ %tmp85 = tail call i8* @objc_retain(i8* %tmp84) nounwind
+ %tmp86 = load %2** @"\01L_OBJC_CLASSLIST_REFERENCES_$_409", align 8
+ %tmp87 = bitcast %2* %tmp86 to i8*
+ %tmp88 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_alloc" to i8**), align 16
+ %tmp89 = bitcast i8* %tmp88 to i8* (i8*, %1*)*
+ %tmp90 = tail call i8* %tmp89(i8* %tmp87, %1* bitcast (%0* @"\01l_objc_msgSend_fixup_alloc" to %1*))
+ %tmp91 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_8", align 8
+ %tmp92 = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %tmp90, i8* %tmp91)
+ %tmp93 = tail call i8* @objc_explicit_autorelease(i8* %tmp92) nounwind
+ %tmp94 = bitcast i8* %tmp93 to %25*
+ %tmp95 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_411", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %25*)*)(i8* %tmp85, i8* %tmp95, %25* %tmp94)
+ tail call void @objc_release(i8* %tmp93) nounwind
+ %tmp96 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_148", align 8
+ %tmp97 = tail call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %tmp4, i8* %tmp96)
+ %tmp98 = icmp eq i8 %tmp97, 0
+ br i1 %tmp98, label %bb99, label %bb104
+
+bb99: ; preds = %bb57
+ %tmp100 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_413", align 8
+ %tmp101 = tail call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*)*)(i8* %tmp85, i8* %tmp100)
+ %tmp102 = or i64 %tmp101, 12
+ %tmp103 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_415", align 8
+ tail call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i64)*)(i8* %tmp85, i8* %tmp103, i64 %tmp102)
+ br label %bb104
+
+bb104: ; preds = %bb99, %bb57
+ %tmp105 = tail call i8* @objc_autorelease(i8* %tmp72) nounwind
+ %tmp106 = bitcast i8* %tmp105 to %14*
+ tail call void @objc_release(i8* %tmp85) nounwind
+ %tmp107 = bitcast %18* %tmp47 to i8*
+ tail call void @objc_release(i8* %tmp107) nounwind
+ ret %14* %tmp106
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/move-and-merge-autorelease.ll b/src/LLVM/test/Transforms/ObjCARC/move-and-merge-autorelease.ll
new file mode 100644
index 0000000..8462c70
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/move-and-merge-autorelease.ll
@@ -0,0 +1,108 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+
+; The optimizer should be able to move the autorelease past two phi nodes
+; and fold it with the release in bb65.
+
+; CHECK: bb65:
+; CHECK: call i8* @objc_retainAutorelease
+; CHECK: br label %bb76
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.0"
+
+%0 = type opaque
+%1 = type opaque
+%2 = type opaque
+%3 = type opaque
+%4 = type opaque
+%5 = type opaque
+
+@"\01L_OBJC_SELECTOR_REFERENCES_11" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_421455" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_598" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_620" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_622" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_624" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@"\01L_OBJC_SELECTOR_REFERENCES_626" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+
+declare i8* @objc_msgSend(i8*, i8*, ...)
+
+declare i8* @objc_retain(i8*)
+
+declare void @objc_release(i8*)
+
+declare i8* @objc_autorelease(i8*)
+
+define hidden %0* @foo(%1* %arg, %3* %arg3) {
+bb:
+ %tmp16 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_620", align 8
+ %tmp17 = bitcast %3* %arg3 to i8*
+ %tmp18 = call %4* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %4* (i8*, i8*)*)(i8* %tmp17, i8* %tmp16)
+ %tmp19 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_622", align 8
+ %tmp20 = bitcast %4* %tmp18 to i8*
+ %tmp21 = call %5* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %5* (i8*, i8*)*)(i8* %tmp20, i8* %tmp19)
+ %tmp22 = bitcast %5* %tmp21 to i8*
+ %tmp23 = call i8* @objc_retain(i8* %tmp22) nounwind
+ %tmp24 = bitcast i8* %tmp23 to %5*
+ %tmp26 = icmp eq i8* %tmp23, null
+ br i1 %tmp26, label %bb81, label %bb27
+
+bb27: ; preds = %bb
+ %tmp29 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_11", align 8
+ %tmp30 = bitcast %1* %arg to i8*
+ %tmp31 = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %tmp30, i8* %tmp29)
+ %tmp34 = call i8* @objc_retain(i8* %tmp31) nounwind
+ %tmp37 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_421455", align 8
+ %tmp39 = call %0* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %0* (i8*, i8*)*)(i8* %tmp34, i8* %tmp37)
+ %tmp40 = bitcast %0* %tmp39 to i8*
+ %tmp41 = call i8* @objc_retain(i8* %tmp40) nounwind
+ %tmp42 = bitcast i8* %tmp41 to %0*
+ %tmp44 = icmp eq i8* %tmp41, null
+ br i1 %tmp44, label %bb45, label %bb55
+
+bb45: ; preds = %bb27
+ %tmp47 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_624", align 8
+ %tmp49 = call %0* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %0* (i8*, i8*)*)(i8* %tmp34, i8* %tmp47)
+ %tmp51 = bitcast %0* %tmp49 to i8*
+ %tmp52 = call i8* @objc_retain(i8* %tmp51) nounwind
+ call void @objc_release(i8* %tmp41) nounwind
+ br label %bb55
+
+bb55: ; preds = %bb27, %bb45
+ %tmp13.0 = phi %0* [ %tmp42, %bb27 ], [ %tmp49, %bb45 ]
+ %tmp57 = icmp eq %0* %tmp13.0, null
+ br i1 %tmp57, label %bb76, label %bb58
+
+bb58: ; preds = %bb55
+ %tmp60 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_598", align 8
+ %tmp61 = bitcast %0* %tmp13.0 to i8*
+ %tmp62 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %tmp61, i8* %tmp60)
+ %tmp64 = icmp eq i8 %tmp62, 0
+ br i1 %tmp64, label %bb76, label %bb65
+
+bb65: ; preds = %bb58
+ %tmp68 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_626", align 8
+ %tmp69 = bitcast %0* %tmp13.0 to i8*
+ %tmp70 = call %0* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %0* (i8*, i8*, %5*)*)(i8* %tmp69, i8* %tmp68, %5* %tmp24)
+ %tmp72 = bitcast %0* %tmp70 to i8*
+ %tmp73 = call i8* @objc_retain(i8* %tmp72) nounwind
+ br label %bb76
+
+bb76: ; preds = %bb58, %bb55, %bb65
+ %tmp10.0 = phi %0* [ %tmp70, %bb65 ], [ null, %bb58 ], [ null, %bb55 ]
+ %tmp78 = bitcast %0* %tmp13.0 to i8*
+ call void @objc_release(i8* %tmp78) nounwind
+ call void @objc_release(i8* %tmp34) nounwind
+ br label %bb81
+
+bb81: ; preds = %bb, %bb76
+ %tmp10.1 = phi %0* [ %tmp10.0, %bb76 ], [ null, %bb ]
+ %tmp83 = bitcast %0* %tmp10.1 to i8*
+ %tmp84 = call i8* @objc_retain(i8* %tmp83) nounwind
+ %tmp88 = bitcast i8* %tmp87 to %0*
+ call void @objc_release(i8* %tmp23) nounwind
+ %tmp87 = call i8* @objc_autorelease(i8* %tmp84) nounwind
+ %tmp92 = bitcast %0* %tmp10.1 to i8*
+ call void @objc_release(i8* %tmp92) nounwind
+ ret %0* %tmp88
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/nested.ll b/src/LLVM/test/Transforms/ObjCARC/nested.ll
new file mode 100644
index 0000000..9eada8a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/nested.ll
@@ -0,0 +1,620 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+%struct.__objcFastEnumerationState = type { i64, i8**, i64*, [5 x i64] }
+
+@"\01L_OBJC_METH_VAR_NAME_" = internal global [43 x i8] c"countByEnumeratingWithState:objects:count:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
+@"\01L_OBJC_SELECTOR_REFERENCES_" = internal global i8* getelementptr inbounds ([43 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i64 0, i64 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@g = common global i8* null, align 8
+@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"
+
+declare void @callee()
+declare i8* @returner()
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare i8* @objc_retain(i8*)
+declare void @objc_enumerationMutation(i8*)
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind
+declare void @use(i8*)
+declare void @objc_release(i8*)
+
+!0 = metadata !{}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test0(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test0(i8* %a) nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call, %forcoll.loopinit ], [ %call6, %forcoll.refetch ]
+ %tmp7 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp7, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr3 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr3, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call6 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp5, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call6, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test2(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test2() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test4(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test4() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %tmp = load i8** @g, align 8
+ %0 = call i8* @objc_retain(i8* %tmp) nounwind
+ %tmp2 = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp2, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp4 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp4, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call, %forcoll.loopinit ], [ %call8, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp7 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call8 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp7, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call8, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test5(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test5() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test6(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test6() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @callee()
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test7(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test7() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @callee()
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test8(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test8() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.next ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ %tobool = icmp eq i8* %3, null
+ br i1 %tobool, label %forcoll.next, label %if.then
+
+if.then:
+ call void @callee()
+ br label %forcoll.next
+
+forcoll.next:
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test9(
+; CHECK: call i8* @objc_retain
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test9() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %call1 = call i8* @returner()
+ %1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call1) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %2 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call4 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp3, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call4, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call4, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ %phitmp, %forcoll.notmutated.forcoll.loopbody_crit_edge ], [ 1, %forcoll.loopbody.outer ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %3 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %3, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %2)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %exitcond = icmp eq i64 %forcoll.index, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.notmutated.forcoll.loopbody_crit_edge
+
+forcoll.notmutated.forcoll.loopbody_crit_edge:
+ %phitmp = add i64 %forcoll.index, 1
+ br label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %4 = icmp eq i64 %call7, 0
+ br i1 %4, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %2) nounwind
+ call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test10(
+; CHECK: call i8* @objc_retain
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test10() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %call1 = call i8* @returner()
+ %1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call1) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %2 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call4 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp3, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call4, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call4, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ %phitmp, %forcoll.notmutated.forcoll.loopbody_crit_edge ], [ 1, %forcoll.loopbody.outer ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %3 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %3, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %2)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %exitcond = icmp eq i64 %forcoll.index, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.notmutated.forcoll.loopbody_crit_edge
+
+forcoll.notmutated.forcoll.loopbody_crit_edge:
+ %phitmp = add i64 %forcoll.index, 1
+ br label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %4 = icmp eq i64 %call7, 0
+ br i1 %4, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %2) nounwind
+ call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/post-inlining.ll b/src/LLVM/test/Transforms/ObjCARC/post-inlining.ll
new file mode 100644
index 0000000..ad69ccd
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/post-inlining.ll
@@ -0,0 +1,48 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+
+declare void @use_pointer(i8*)
+declare i8* @returner()
+declare i8* @objc_retain(i8*)
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+
+; Clean up residue left behind after inlining.
+
+; CHECK: define void @test0(
+; CHECK: entry:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test0(i8* %call.i) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %call.i) nounwind
+ %1 = tail call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+ ret void
+}
+
+; Same as test0, but with slightly different use arrangements.
+
+; CHECK: define void @test1(
+; CHECK: entry:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test1(i8* %call.i) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %call.i) nounwind
+ %1 = tail call i8* @objc_autoreleaseReturnValue(i8* %call.i) nounwind
+ ret void
+}
+
+; Delete a retainRV+autoreleaseRV even if the pointer is used.
+
+; CHECK: define void @test24(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test24(i8* %p) {
+entry:
+ call i8* @objc_autoreleaseReturnValue(i8* %p) nounwind
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p) nounwind
+ call void @use_pointer(i8* %p)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/retain-block-alloca.ll b/src/LLVM/test/Transforms/ObjCARC/retain-block-alloca.ll
new file mode 100644
index 0000000..468da91
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/retain-block-alloca.ll
@@ -0,0 +1,54 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+; rdar://10209613
+
+; CHECK: define void @test
+; CHECK: %3 = call i8* @objc_retainBlock(i8* %2) nounwind
+; CHECK: @objc_msgSend
+; CHECK-NEXT: @objc_release(i8* %3)
+
+%0 = type opaque
+%struct.__block_descriptor = type { i64, i64 }
+
+@_NSConcreteStackBlock = external global i8*
+@__block_descriptor_tmp = external hidden constant { i64, i64, i8*, i8*, i8*, i8* }
+@"\01L_OBJC_SELECTOR_REFERENCES_" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+
+define void @test(%0* %array) uwtable {
+entry:
+ %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>, align 8
+ %0 = bitcast %0* %array to i8*
+ %1 = tail call i8* @objc_retain(i8* %0) nounwind
+ %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 0
+ store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
+ %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 1
+ store i32 1107296256, i32* %block.flags, align 8
+ %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 2
+ store i32 0, i32* %block.reserved, align 4
+ %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 3
+ store i8* bitcast (void (i8*)* @__test_block_invoke_0 to i8*), i8** %block.invoke, align 8
+ %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 4
+ store %struct.__block_descriptor* bitcast ({ i64, i64, i8*, i8*, i8*, i8* }* @__block_descriptor_tmp to %struct.__block_descriptor*), %struct.__block_descriptor** %block.descriptor, align 8
+ %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 5
+ store %0* %array, %0** %block.captured, align 8
+ %2 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block to i8*
+ %3 = call i8* @objc_retainBlock(i8* %2) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* %0, i8* %tmp2, i8* %3)
+ call void @objc_release(i8* %3) nounwind
+ %strongdestroy = load %0** %block.captured, align 8
+ %4 = bitcast %0* %strongdestroy to i8*
+ call void @objc_release(i8* %4) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+declare i8* @objc_retain(i8*)
+
+declare void @__test_block_invoke_0(i8* nocapture) uwtable
+
+declare i8* @objc_retainBlock(i8*)
+
+declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind
+
+declare void @objc_release(i8*)
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/retain-block-side-effects.ll b/src/LLVM/test/Transforms/ObjCARC/retain-block-side-effects.ll
new file mode 100644
index 0000000..e84d48f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/retain-block-side-effects.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -objc-arc-aa -basicaa -gvn < %s | FileCheck %s
+; rdar://10050579
+
+; objc_retainBlock stores into %repeater so the load from after the
+; call isn't forwardable from the store before the call.
+
+; CHECK: %tmp16 = call i8* @objc_retainBlock(i8* %tmp15) nounwind
+; CHECK: %tmp17 = bitcast i8* %tmp16 to void ()*
+; CHECK: %tmp18 = load %struct.__block_byref_repeater** %byref.forwarding, align 8
+; CHECK: %repeater12 = getelementptr inbounds %struct.__block_byref_repeater* %tmp18, i64 0, i32 6
+; CHECK: store void ()* %tmp17, void ()** %repeater12, align 8
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+%0 = type opaque
+%struct.__block_byref_repeater = type { i8*, %struct.__block_byref_repeater*, i32, i32, i8*, i8*, void ()* }
+%struct.__block_descriptor = type { i64, i64 }
+
+define void @foo() noreturn {
+entry:
+ %repeater = alloca %struct.__block_byref_repeater, align 8
+ %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>, align 8
+ %byref.forwarding = getelementptr inbounds %struct.__block_byref_repeater* %repeater, i64 0, i32 1
+ %tmp10 = getelementptr inbounds %struct.__block_byref_repeater* %repeater, i64 0, i32 6
+ store void ()* null, void ()** %tmp10, align 8
+ %block.captured11 = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>* %block, i64 0, i32 6
+ %tmp14 = bitcast %struct.__block_byref_repeater* %repeater to i8*
+ store i8* %tmp14, i8** %block.captured11, align 8
+ %tmp15 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>* %block to i8*
+ %tmp16 = call i8* @objc_retainBlock(i8* %tmp15) nounwind
+ %tmp17 = bitcast i8* %tmp16 to void ()*
+ %tmp18 = load %struct.__block_byref_repeater** %byref.forwarding, align 8
+ %repeater12 = getelementptr inbounds %struct.__block_byref_repeater* %tmp18, i64 0, i32 6
+ %tmp13 = load void ()** %repeater12, align 8
+ store void ()* %tmp17, void ()** %repeater12, align 8
+ ret void
+}
+
+declare i8* @objc_retainBlock(i8*)
diff --git a/src/LLVM/test/Transforms/ObjCARC/retain-not-declared.ll b/src/LLVM/test/Transforms/ObjCARC/retain-not-declared.ll
new file mode 100644
index 0000000..41bde01
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/retain-not-declared.ll
@@ -0,0 +1,67 @@
+; RUN: opt -S -objc-arc -objc-arc-contract < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+declare i8* @objc_unretainedObject(i8*)
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_msgSend(i8*, i8*, ...)
+declare void @objc_release(i8*)
+
+; Test that the optimizer can create an objc_retainAutoreleaseReturnValue
+; declaration even if no objc_retain declaration exists.
+; rdar://9401303
+
+; CHECK: define i8* @test0(i8* %p) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = tail call i8* @objc_retainAutoreleaseReturnValue(i8* %p) nounwind
+; CHECK-NEXT: ret i8* %0
+; CHECK-NEXT: }
+
+define i8* @test0(i8* %p) {
+entry:
+ %call = tail call i8* @objc_unretainedObject(i8* %p)
+ %0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %1 = tail call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+ ret i8* %1
+}
+
+; Properly create the @objc_retain declaration when it doesn't already exist.
+; rdar://9825114
+
+; CHECK: @test1(
+; CHECK: @objc_retain(
+; CHECK: @objc_retain(
+; CHECK: @objc_release(
+; CHECK: @objc_release(
+; CHECK: }
+define void @test1(i8* %call88) nounwind {
+entry:
+ %tmp1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call88) nounwind
+ %call94 = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*)*)(i8* %tmp1)
+ to label %invoke.cont93 unwind label %lpad91
+
+invoke.cont93: ; preds = %entry
+ %tmp2 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call94) nounwind
+ call void @objc_release(i8* %tmp1) nounwind
+ invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %tmp2)
+ to label %invoke.cont102 unwind label %lpad100
+
+invoke.cont102: ; preds = %invoke.cont93
+ call void @objc_release(i8* %tmp2) nounwind, !clang.imprecise_release !0
+ unreachable
+
+lpad91: ; preds = %entry
+ %exn91 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+
+lpad100: ; preds = %invoke.cont93
+ %exn100 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @objc_release(i8* %tmp2) nounwind, !clang.imprecise_release !0
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/rle-s2l.ll b/src/LLVM/test/Transforms/ObjCARC/rle-s2l.ll
new file mode 100644
index 0000000..8f8d5c0
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/rle-s2l.ll
@@ -0,0 +1,135 @@
+; RUN: opt -S -basicaa -objc-arc < %s | FileCheck %s
+
+declare i8* @objc_loadWeak(i8**)
+declare i8* @objc_loadWeakRetained(i8**)
+declare i8* @objc_storeWeak(i8**, i8*)
+declare i8* @objc_initWeak(i8**, i8*)
+declare void @use_pointer(i8*)
+declare void @callee()
+
+; Basic redundant @objc_loadWeak elimination.
+
+; CHECK: define void @test0(i8** %p) {
+; CHECK-NEXT: %y = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %y)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test0(i8** %p) {
+ %x = call i8* @objc_loadWeak(i8** %p)
+ %y = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; DCE the @objc_loadWeak.
+
+; CHECK: define void @test1(i8** %p) {
+; CHECK-NEXT: %y = call i8* @objc_loadWeakRetained(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %y)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test1(i8** %p) {
+ %x = call i8* @objc_loadWeak(i8** %p)
+ %y = call i8* @objc_loadWeakRetained(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; Basic redundant @objc_loadWeakRetained elimination.
+
+; CHECK: define void @test2(i8** %p) {
+; CHECK-NEXT: %x = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: store i8 3, i8* %x
+; CHECK-NEXT: %1 = tail call i8* @objc_retain(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test2(i8** %p) {
+ %x = call i8* @objc_loadWeak(i8** %p)
+ store i8 3, i8* %x
+ %y = call i8* @objc_loadWeakRetained(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; Basic redundant @objc_loadWeakRetained elimination, this time
+; with a readonly call instead of a store.
+
+; CHECK: define void @test3(i8** %p) {
+; CHECK-NEXT: %x = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %x) readonly
+; CHECK-NEXT: %1 = tail call i8* @objc_retain(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test3(i8** %p) {
+ %x = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %x) readonly
+ %y = call i8* @objc_loadWeakRetained(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; A regular call blocks redundant weak load elimination.
+
+; CHECK: define void @test4(i8** %p) {
+; CHECK-NEXT: %x = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %x) readonly
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: %y = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %y)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test4(i8** %p) {
+ %x = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %x) readonly
+ call void @callee()
+ %y = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; Store to load forwarding.
+
+; CHECK: define void @test5(i8** %p, i8* %n) {
+; CHECK-NEXT: %1 = call i8* @objc_storeWeak(i8** %p, i8* %n)
+; CHECK-NEXT: call void @use_pointer(i8* %n)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test5(i8** %p, i8* %n) {
+ call i8* @objc_storeWeak(i8** %p, i8* %n)
+ %y = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; Store to load forwarding with objc_initWeak.
+
+; CHECK: define void @test6(i8** %p, i8* %n) {
+; CHECK-NEXT: %1 = call i8* @objc_initWeak(i8** %p, i8* %n)
+; CHECK-NEXT: call void @use_pointer(i8* %n)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test6(i8** %p, i8* %n) {
+ call i8* @objc_initWeak(i8** %p, i8* %n)
+ %y = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
+
+; Don't forward if there's a may-alias store in the way.
+
+; CHECK: define void @test7(i8** %p, i8* %n, i8** %q, i8* %m) {
+; CHECK-NEXT: call i8* @objc_initWeak(i8** %p, i8* %n)
+; CHECK-NEXT: call i8* @objc_storeWeak(i8** %q, i8* %m)
+; CHECK-NEXT: %y = call i8* @objc_loadWeak(i8** %p)
+; CHECK-NEXT: call void @use_pointer(i8* %y)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test7(i8** %p, i8* %n, i8** %q, i8* %m) {
+ call i8* @objc_initWeak(i8** %p, i8* %n)
+ call i8* @objc_storeWeak(i8** %q, i8* %m)
+ %y = call i8* @objc_loadWeak(i8** %p)
+ call void @use_pointer(i8* %y)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/rv.ll b/src/LLVM/test/Transforms/ObjCARC/rv.ll
new file mode 100644
index 0000000..9353a19
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/rv.ll
@@ -0,0 +1,342 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64"
+
+declare i8* @objc_retain(i8*)
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare void @objc_release(i8*)
+declare i8* @objc_autorelease(i8*)
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_retainAutoreleaseReturnValue(i8*)
+declare void @objc_autoreleasePoolPop(i8*)
+declare void @objc_autoreleasePoolPush()
+declare i8* @objc_retainBlock(i8*)
+
+declare i8* @objc_retainedObject(i8*)
+declare i8* @objc_unretainedObject(i8*)
+declare i8* @objc_unretainedPointer(i8*)
+
+declare void @use_pointer(i8*)
+declare void @callee()
+declare void @callee_fnptr(void ()*)
+declare void @invokee()
+declare i8* @returner()
+
+; Test that retain+release elimination is suppressed when the
+; retain is an objc_retainAutoreleasedReturnValue, since it's
+; better to do the RV optimization.
+
+; CHECK: define void @test0(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %x = call i8* @returner
+; CHECK-NEXT: %0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %x) nounwind
+; CHECK: t:
+; CHECK-NOT: @objc_
+; CHECK: return:
+; CHECK-NEXT: call void @objc_release(i8* %x)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test0(i1 %p) nounwind {
+entry:
+ %x = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %x)
+ br i1 %p, label %t, label %return
+
+t:
+ call void @use_pointer(i8* %x)
+ store i8 0, i8* %x
+ br label %return
+
+return:
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Delete no-ops.
+
+; CHECK: define void @test2
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test2() {
+ call i8* @objc_retainAutoreleasedReturnValue(i8* null)
+ call i8* @objc_autoreleaseReturnValue(i8* null)
+ ; call i8* @objc_retainAutoreleaseReturnValue(i8* null) ; TODO
+ ret void
+}
+
+; Delete a redundant retainRV,autoreleaseRV when forwaring a call result
+; directly to a return value.
+
+; CHECK: define i8* @test3
+; CHECK: call i8* @returner()
+; CHECK-NEXT: ret i8* %call
+define i8* @test3() {
+entry:
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %1 = call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+ ret i8* %1
+}
+
+; Delete a redundant retain,autoreleaseRV when forwaring a call result
+; directly to a return value.
+
+; CHECK: define i8* @test4
+; CHECK: call i8* @returner()
+; CHECK-NEXT: ret i8* %call
+define i8* @test4() {
+entry:
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retain(i8* %call) nounwind
+ %1 = call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
+ ret i8* %1
+}
+
+; Delete a redundant fused retain+autoreleaseRV when forwaring a call result
+; directly to a return value.
+
+; TODO
+; HECK: define i8* @test5
+; HECK: call i8* @returner()
+; HECK-NEXT: ret i8* %call
+;define i8* @test5() {
+;entry:
+; %call = call i8* @returner()
+; %0 = call i8* @objc_retainAutoreleaseReturnValue(i8* %call) nounwind
+; ret i8* %0
+;}
+
+; Don't eliminate objc_retainAutoreleasedReturnValue by merging it into
+; an objc_autorelease.
+; TODO? Merge objc_retainAutoreleasedReturnValue and objc_autorelease into
+; objc_retainAutoreleasedReturnValueAutorelease and merge
+; objc_retainAutoreleasedReturnValue and objc_autoreleaseReturnValue
+; into objc_retainAutoreleasedReturnValueAutoreleaseReturnValue?
+; Those entrypoints don't exist yet though.
+
+; CHECK: define i8* @test7(
+; CHECK: call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+; CHECK: %t = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+define i8* @test7() {
+ %p = call i8* @returner()
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ %t = call i8* @objc_autoreleaseReturnValue(i8* %p)
+ call void @use_pointer(i8* %t)
+ ret i8* %t
+}
+
+; CHECK: define i8* @test7b(
+; CHECK: call i8* @objc_retain(i8* %p)
+; CHECK: %t = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+define i8* @test7b() {
+ %p = call i8* @returner()
+ call void @use_pointer(i8* %p)
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ %t = call i8* @objc_autoreleaseReturnValue(i8* %p)
+ ret i8* %t
+}
+
+; Turn objc_retain into objc_retainAutoreleasedReturnValue if its operand
+; is a return value.
+
+; CHECK: define void @test8()
+; CHECK: tail call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+define void @test8() {
+ %p = call i8* @returner()
+ call i8* @objc_retain(i8* %p)
+ ret void
+}
+
+; Don't apply the RV optimization to autorelease if there's no retain.
+
+; CHECK: define i8* @test9(i8* %p)
+; CHECK: tail call i8* @objc_autorelease(i8* %p)
+define i8* @test9(i8* %p) {
+ call i8* @objc_autorelease(i8* %p)
+ ret i8* %p
+}
+
+; Apply the RV optimization.
+
+; CHECK: define i8* @test10(i8* %p)
+; CHECK: tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %p) nounwind
+; CHECK-NEXT: ret i8* %p
+define i8* @test10(i8* %p) {
+ %1 = call i8* @objc_retain(i8* %p)
+ %2 = call i8* @objc_autorelease(i8* %p)
+ ret i8* %p
+}
+
+; Don't do the autoreleaseRV optimization because @use_pointer
+; could undo the retain.
+
+; CHECK: define i8* @test11(i8* %p)
+; CHECK: tail call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: call void @use_pointer(i8* %p)
+; CHECK: tail call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: ret i8* %p
+define i8* @test11(i8* %p) {
+ %1 = call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ %2 = call i8* @objc_autorelease(i8* %p)
+ ret i8* %p
+}
+
+; Don't spoil the RV optimization.
+
+; CHECK: define i8* @test12(i8* %p)
+; CHECK: tail call i8* @objc_retain(i8* %p)
+; CHECK: call void @use_pointer(i8* %p)
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+; CHECK: ret i8* %p
+define i8* @test12(i8* %p) {
+ %1 = call i8* @objc_retain(i8* %p)
+ call void @use_pointer(i8* %p)
+ %2 = call i8* @objc_autoreleaseReturnValue(i8* %p)
+ ret i8* %p
+}
+
+; Don't zap the objc_retainAutoreleasedReturnValue.
+
+; CHECK: define i8* @test13(
+; CHECK: tail call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+; CHECK: tail call i8* @objc_autorelease(i8* %p)
+; CHECK: ret i8* %p
+define i8* @test13() {
+ %p = call i8* @returner()
+ %1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ call void @callee()
+ %2 = call i8* @objc_autorelease(i8* %p)
+ ret i8* %p
+}
+
+; Convert objc_retainAutoreleasedReturnValue to objc_retain if its
+; argument is not a return value.
+
+; CHECK: define void @test14(
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %p) nounwind
+; CHECK-NEXT: ret void
+define void @test14(i8* %p) {
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ ret void
+}
+
+; Don't convert objc_retainAutoreleasedReturnValue to objc_retain if its
+; argument is a return value.
+
+; CHECK: define void @test15(
+; CHECK-NEXT: %y = call i8* @returner()
+; CHECK-NEXT: tail call i8* @objc_retainAutoreleasedReturnValue(i8* %y) nounwind
+; CHECK-NEXT: ret void
+define void @test15() {
+ %y = call i8* @returner()
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %y)
+ ret void
+}
+
+; Convert objc_retain to objc_retainAutoreleasedReturnValue if its
+; argument is a return value.
+
+; CHECK: define void @test16(
+; CHECK-NEXT: %y = call i8* @returner()
+; CHECK-NEXT: tail call i8* @objc_retainAutoreleasedReturnValue(i8* %y) nounwind
+; CHECK-NEXT: ret void
+define void @test16() {
+ %y = call i8* @returner()
+ call i8* @objc_retain(i8* %y)
+ ret void
+}
+
+; Don't convert objc_retain to objc_retainAutoreleasedReturnValue if its
+; argument is not a return value.
+
+; CHECK: define void @test17(
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %y) nounwind
+; CHECK-NEXT: ret void
+define void @test17(i8* %y) {
+ call i8* @objc_retain(i8* %y)
+ ret void
+}
+
+; Don't Convert objc_retain to objc_retainAutoreleasedReturnValue if it
+; isn't next to the call providing its return value.
+
+; CHECK: define void @test18(
+; CHECK-NEXT: %y = call i8* @returner()
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %y) nounwind
+; CHECK-NEXT: ret void
+define void @test18() {
+ %y = call i8* @returner()
+ call void @callee()
+ call i8* @objc_retain(i8* %y)
+ ret void
+}
+
+; Delete autoreleaseRV+retainRV pairs.
+
+; CHECK: define i8* @test19(i8* %p) {
+; CHECK-NEXT: ret i8* %p
+define i8* @test19(i8* %p) {
+ call i8* @objc_autoreleaseReturnValue(i8* %p)
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ ret i8* %p
+}
+
+; Like test19 but with plain autorelease.
+
+; CHECK: define i8* @test20(i8* %p) {
+; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: ret i8* %p
+define i8* @test20(i8* %p) {
+ call i8* @objc_autorelease(i8* %p)
+ call i8* @objc_retainAutoreleasedReturnValue(i8* %p)
+ ret i8* %p
+}
+
+; Like test19 but with plain retain.
+
+; CHECK: define i8* @test21(i8* %p) {
+; CHECK-NEXT: call i8* @objc_autoreleaseReturnValue(i8* %p)
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: ret i8* %p
+define i8* @test21(i8* %p) {
+ call i8* @objc_autoreleaseReturnValue(i8* %p)
+ call i8* @objc_retain(i8* %p)
+ ret i8* %p
+}
+
+; Like test19 but with plain retain and autorelease.
+
+; CHECK: define i8* @test22(i8* %p) {
+; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
+; CHECK-NEXT: call i8* @objc_retain(i8* %p)
+; CHECK-NEXT: ret i8* %p
+define i8* @test22(i8* %p) {
+ call i8* @objc_autorelease(i8* %p)
+ call i8* @objc_retain(i8* %p)
+ ret i8* %p
+}
+
+; Convert autoreleaseRV to autorelease.
+
+; CHECK: define void @test23(
+; CHECK: tail call i8* @objc_autorelease(i8* %p) nounwind
+define void @test23(i8* %p) {
+ store i8 0, i8* %p
+ call i8* @objc_autoreleaseReturnValue(i8* %p)
+ ret void
+}
+
+; Don't convert autoreleaseRV to autorelease if the result is returned,
+; even through a bitcast.
+
+; CHECK: define {}* @test24(
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+define {}* @test24(i8* %p) {
+ %t = call i8* @objc_autoreleaseReturnValue(i8* %p)
+ %s = bitcast i8* %p to {}*
+ ret {}* %s
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/weak-contract.ll b/src/LLVM/test/Transforms/ObjCARC/weak-contract.ll
new file mode 100644
index 0000000..ca69c70
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/weak-contract.ll
@@ -0,0 +1,14 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+
+declare i8* @objc_initWeak(i8**, i8*)
+
+; Convert objc_initWeak(p, null) to *p = null.
+
+; CHECK: define i8* @test0(i8** %p) {
+; CHECK-NEXT: store i8* null, i8** %p
+; CHECK-NEXT: ret i8* null
+; CHECK-NEXT: }
+define i8* @test0(i8** %p) {
+ %t = call i8* @objc_initWeak(i8** %p, i8* null)
+ ret i8* %t
+}
diff --git a/src/LLVM/test/Transforms/ObjCARC/weak-copies.ll b/src/LLVM/test/Transforms/ObjCARC/weak-copies.ll
new file mode 100644
index 0000000..e1a94bb
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/weak-copies.ll
@@ -0,0 +1,87 @@
+; RUN: opt -S -basicaa -objc-arc < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.0"
+
+%0 = type { i64, i64, i8*, i8*, i8*, i8* }
+%1 = type <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>
+%struct.__block_descriptor = type { i64, i64 }
+
+@_NSConcreteStackBlock = external global i8*
+@.str = private unnamed_addr constant [6 x i8] c"v8@?0\00"
+@"\01L_OBJC_CLASS_NAME_" = internal global [3 x i8] c"\01@\00", section "__TEXT,__objc_classname,cstring_literals", align 1
+@__block_descriptor_tmp = internal constant %0 { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_ to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_ to i8*), i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8]* @"\01L_OBJC_CLASS_NAME_", i32 0, i32 0) }
+@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"
+@llvm.used = appending global [2 x i8*] [i8* getelementptr inbounds ([3 x i8]* @"\01L_OBJC_CLASS_NAME_", i32 0, i32 0), i8* bitcast ([2 x i32]* @"\01L_OBJC_IMAGE_INFO" to i8*)], section "llvm.metadata"
+
+; Eliminate unnecessary weak pointer copies.
+
+; CHECK: define void @foo() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %call = call i8* @bar()
+; CHECK-NEXT: call void @use(i8* %call) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @foo() {
+entry:
+ %w = alloca i8*, align 8
+ %x = alloca i8*, align 8
+ %call = call i8* @bar()
+ %0 = call i8* @objc_initWeak(i8** %w, i8* %call) nounwind
+ %1 = call i8* @objc_loadWeak(i8** %w) nounwind
+ %2 = call i8* @objc_initWeak(i8** %x, i8* %1) nounwind
+ %3 = call i8* @objc_loadWeak(i8** %x) nounwind
+ call void @use(i8* %3) nounwind
+ call void @objc_destroyWeak(i8** %x) nounwind
+ call void @objc_destroyWeak(i8** %w) nounwind
+ ret void
+}
+
+; Eliminate unnecessary weak pointer copies in a block initialization.
+
+; CHECK: define void @qux(i8* %me) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %block = alloca %1, align 8
+; CHECK-NOT: alloca
+; CHECK: }
+define void @qux(i8* %me) nounwind {
+entry:
+ %w = alloca i8*, align 8
+ %block = alloca %1, align 8
+ %0 = call i8* @objc_retain(i8* %me) nounwind
+ %1 = call i8* @objc_initWeak(i8** %w, i8* %0) nounwind
+ %block.isa = getelementptr inbounds %1* %block, i64 0, i32 0
+ store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
+ %block.flags = getelementptr inbounds %1* %block, i64 0, i32 1
+ store i32 1107296256, i32* %block.flags, align 8
+ %block.reserved = getelementptr inbounds %1* %block, i64 0, i32 2
+ store i32 0, i32* %block.reserved, align 4
+ %block.invoke = getelementptr inbounds %1* %block, i64 0, i32 3
+ store i8* bitcast (void (i8*)* @__qux_block_invoke_0 to i8*), i8** %block.invoke, align 8
+ %block.descriptor = getelementptr inbounds %1* %block, i64 0, i32 4
+ store %struct.__block_descriptor* bitcast (%0* @__block_descriptor_tmp to %struct.__block_descriptor*), %struct.__block_descriptor** %block.descriptor, align 8
+ %block.captured = getelementptr inbounds %1* %block, i64 0, i32 5
+ %2 = call i8* @objc_loadWeak(i8** %w) nounwind
+ %3 = call i8* @objc_initWeak(i8** %block.captured, i8* %2) nounwind
+ %4 = bitcast %1* %block to void ()*
+ call void @use_block(void ()* %4) nounwind
+ call void @objc_destroyWeak(i8** %block.captured) nounwind
+ call void @objc_destroyWeak(i8** %w) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+declare i8* @objc_retain(i8*)
+declare void @use_block(void ()*) nounwind
+declare void @__qux_block_invoke_0(i8* %.block_descriptor) nounwind
+declare void @__copy_helper_block_(i8*, i8*) nounwind
+declare void @objc_copyWeak(i8**, i8**)
+declare void @__destroy_helper_block_(i8*) nounwind
+declare void @objc_release(i8*)
+declare i8* @bar()
+declare i8* @objc_initWeak(i8**, i8*)
+declare i8* @objc_loadWeak(i8**)
+declare void @use(i8*) nounwind
+declare void @objc_destroyWeak(i8**)
+
+!0 = metadata !{}
diff --git a/src/LLVM/test/Transforms/ObjCARC/weak.ll b/src/LLVM/test/Transforms/ObjCARC/weak.ll
new file mode 100644
index 0000000..85a290c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ObjCARC/weak.ll
@@ -0,0 +1,57 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+declare i8* @objc_initWeak(i8**, i8*)
+declare i8* @objc_storeWeak(i8**, i8*)
+declare i8* @objc_loadWeak(i8**)
+declare void @objc_destroyWeak(i8**)
+declare i8* @objc_loadWeakRetained(i8**)
+declare void @objc_moveWeak(i8**, i8**)
+declare void @objc_copyWeak(i8**, i8**)
+
+; If the pointer-to-weak-pointer is null, it's undefined behavior.
+
+; CHECK: define void @test0(
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: store i8* undef, i8** null
+; CHECK: ret void
+define void @test0(i8* %p, i8** %q) {
+entry:
+ call i8* @objc_storeWeak(i8** null, i8* %p)
+ call i8* @objc_storeWeak(i8** undef, i8* %p)
+ call i8* @objc_loadWeakRetained(i8** null)
+ call i8* @objc_loadWeakRetained(i8** undef)
+ call i8* @objc_loadWeak(i8** null)
+ call i8* @objc_loadWeak(i8** undef)
+ call i8* @objc_initWeak(i8** null, i8* %p)
+ call i8* @objc_initWeak(i8** undef, i8* %p)
+ call void @objc_destroyWeak(i8** null)
+ call void @objc_destroyWeak(i8** undef)
+
+ call void @objc_copyWeak(i8** null, i8** %q)
+ call void @objc_copyWeak(i8** undef, i8** %q)
+ call void @objc_copyWeak(i8** %q, i8** null)
+ call void @objc_copyWeak(i8** %q, i8** undef)
+
+ call void @objc_moveWeak(i8** null, i8** %q)
+ call void @objc_moveWeak(i8** undef, i8** %q)
+ call void @objc_moveWeak(i8** %q, i8** null)
+ call void @objc_moveWeak(i8** %q, i8** undef)
+
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/PhaseOrdering/2010-03-22-empty-baseclass.ll b/src/LLVM/test/Transforms/PhaseOrdering/2010-03-22-empty-baseclass.ll
new file mode 100644
index 0000000..8859da8
--- /dev/null
+++ b/src/LLVM/test/Transforms/PhaseOrdering/2010-03-22-empty-baseclass.ll
@@ -0,0 +1,162 @@
+; RUN: opt -O2 %s -S -o - | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.1"
+
+%"struct.boost::compressed_pair<empty_t,int>" = type { %"struct.boost::details::compressed_pair_imp<empty_t,int,1>" }
+%"struct.boost::details::compressed_pair_imp<empty_t,int,1>" = type { i32 }
+%struct.empty_base_t = type <{ i8 }>
+%struct.empty_t = type <{ i8 }>
+
+@.str = private constant [25 x i8] c"x.second() was clobbered\00", align 1 ; <[25 x i8]*> [#uses=1]
+
+define i32 @main(i32 %argc, i8** %argv) ssp {
+entry:
+ %argc_addr = alloca i32, align 4 ; <i32*> [#uses=1]
+ %argv_addr = alloca i8**, align 8 ; <i8***> [#uses=1]
+ %retval = alloca i32 ; <i32*> [#uses=2]
+ %0 = alloca i32 ; <i32*> [#uses=2]
+ %retval.1 = alloca i8 ; <i8*> [#uses=2]
+ %1 = alloca %struct.empty_base_t ; <%struct.empty_base_t*> [#uses=1]
+ %2 = alloca %struct.empty_base_t* ; <%struct.empty_base_t**> [#uses=1]
+ %x = alloca %"struct.boost::compressed_pair<empty_t,int>" ; <%"struct.boost::compressed_pair<empty_t,int>"*> [#uses=3]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 %argc, i32* %argc_addr
+ store i8** %argv, i8*** %argv_addr
+ %3 = call i32* @_ZN5boost15compressed_pairI7empty_tiE6secondEv(%"struct.boost::compressed_pair<empty_t,int>"* %x) ssp ; <i32*> [#uses=1]
+ store i32 -3, i32* %3, align 4
+ %4 = call %struct.empty_base_t* @_ZN5boost15compressed_pairI7empty_tiE5firstEv(%"struct.boost::compressed_pair<empty_t,int>"* %x) ssp ; <%struct.empty_base_t*> [#uses=1]
+ store %struct.empty_base_t* %4, %struct.empty_base_t** %2, align 8
+ call void @_ZN7empty_tC1Ev(%struct.empty_base_t* %1) nounwind
+ %5 = call i32* @_ZN5boost15compressed_pairI7empty_tiE6secondEv(%"struct.boost::compressed_pair<empty_t,int>"* %x) ssp ; <i32*> [#uses=1]
+ %6 = load i32* %5, align 4 ; <i32> [#uses=1]
+ %7 = icmp ne i32 %6, -3 ; <i1> [#uses=1]
+ %8 = zext i1 %7 to i8 ; <i8> [#uses=1]
+ store i8 %8, i8* %retval.1, align 1
+ %9 = load i8* %retval.1, align 1 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %9, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %bb, label %bb1
+
+bb: ; preds = %entry
+ %10 = call i32 @puts(i8* getelementptr inbounds ([25 x i8]* @.str, i64 0, i64 0)) ; <i32> [#uses=0]
+ call void @abort() noreturn
+ unreachable
+
+bb1: ; preds = %entry
+ store i32 0, i32* %0, align 4
+ %11 = load i32* %0, align 4 ; <i32> [#uses=1]
+ store i32 %11, i32* %retval, align 4
+ br label %return
+
+; CHECK-NOT: x.second() was clobbered
+; CHECK: ret i32
+return: ; preds = %bb1
+ %retval2 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval2
+}
+
+define linkonce_odr void @_ZN12empty_base_tC2Ev(%struct.empty_base_t* %this) nounwind ssp align 2 {
+entry:
+ %this_addr = alloca %struct.empty_base_t*, align 8 ; <%struct.empty_base_t**> [#uses=1]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %struct.empty_base_t* %this, %struct.empty_base_t** %this_addr
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define linkonce_odr void @_ZN7empty_tC1Ev(%struct.empty_base_t* %this) nounwind ssp align 2 {
+entry:
+ %this_addr = alloca %struct.empty_base_t*, align 8 ; <%struct.empty_base_t**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %struct.empty_base_t* %this, %struct.empty_base_t** %this_addr
+ %0 = load %struct.empty_base_t** %this_addr, align 8 ; <%struct.empty_base_t*> [#uses=1]
+ call void @_ZN12empty_base_tC2Ev(%struct.empty_base_t* %0) nounwind
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+define linkonce_odr i32* @_ZN5boost7details19compressed_pair_impI7empty_tiLi1EE6secondEv(%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %this) nounwind ssp align 2 {
+entry:
+ %this_addr = alloca %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*, align 8 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"**> [#uses=2]
+ %retval = alloca i32* ; <i32**> [#uses=2]
+ %0 = alloca i32* ; <i32**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %this, %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"** %this_addr
+ %1 = load %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"** %this_addr, align 8 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*> [#uses=1]
+ %2 = getelementptr inbounds %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %1, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32* %2, i32** %0, align 8
+ %3 = load i32** %0, align 8 ; <i32*> [#uses=1]
+ store i32* %3, i32** %retval, align 8
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32** %retval ; <i32*> [#uses=1]
+ ret i32* %retval1
+}
+
+define linkonce_odr i32* @_ZN5boost15compressed_pairI7empty_tiE6secondEv(%"struct.boost::compressed_pair<empty_t,int>"* %this) ssp align 2 {
+entry:
+ %this_addr = alloca %"struct.boost::compressed_pair<empty_t,int>"*, align 8 ; <%"struct.boost::compressed_pair<empty_t,int>"**> [#uses=2]
+ %retval = alloca i32* ; <i32**> [#uses=2]
+ %0 = alloca i32* ; <i32**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %"struct.boost::compressed_pair<empty_t,int>"* %this, %"struct.boost::compressed_pair<empty_t,int>"** %this_addr
+ %1 = load %"struct.boost::compressed_pair<empty_t,int>"** %this_addr, align 8 ; <%"struct.boost::compressed_pair<empty_t,int>"*> [#uses=1]
+ %2 = getelementptr inbounds %"struct.boost::compressed_pair<empty_t,int>"* %1, i32 0, i32 0 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*> [#uses=1]
+ %3 = call i32* @_ZN5boost7details19compressed_pair_impI7empty_tiLi1EE6secondEv(%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %2) nounwind ; <i32*> [#uses=1]
+ store i32* %3, i32** %0, align 8
+ %4 = load i32** %0, align 8 ; <i32*> [#uses=1]
+ store i32* %4, i32** %retval, align 8
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32** %retval ; <i32*> [#uses=1]
+ ret i32* %retval1
+}
+
+define linkonce_odr %struct.empty_base_t* @_ZN5boost7details19compressed_pair_impI7empty_tiLi1EE5firstEv(%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %this) nounwind ssp align 2 {
+entry:
+ %this_addr = alloca %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*, align 8 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"**> [#uses=2]
+ %retval = alloca %struct.empty_base_t* ; <%struct.empty_base_t**> [#uses=2]
+ %0 = alloca %struct.empty_base_t* ; <%struct.empty_base_t**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %this, %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"** %this_addr
+ %1 = load %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"** %this_addr, align 8 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*> [#uses=1]
+ %2 = bitcast %"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %1 to %struct.empty_base_t* ; <%struct.empty_base_t*> [#uses=1]
+ store %struct.empty_base_t* %2, %struct.empty_base_t** %0, align 8
+ %3 = load %struct.empty_base_t** %0, align 8 ; <%struct.empty_base_t*> [#uses=1]
+ store %struct.empty_base_t* %3, %struct.empty_base_t** %retval, align 8
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load %struct.empty_base_t** %retval ; <%struct.empty_base_t*> [#uses=1]
+ ret %struct.empty_base_t* %retval1
+}
+
+define linkonce_odr %struct.empty_base_t* @_ZN5boost15compressed_pairI7empty_tiE5firstEv(%"struct.boost::compressed_pair<empty_t,int>"* %this) ssp align 2 {
+entry:
+ %this_addr = alloca %"struct.boost::compressed_pair<empty_t,int>"*, align 8 ; <%"struct.boost::compressed_pair<empty_t,int>"**> [#uses=2]
+ %retval = alloca %struct.empty_base_t* ; <%struct.empty_base_t**> [#uses=2]
+ %0 = alloca %struct.empty_base_t* ; <%struct.empty_base_t**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %"struct.boost::compressed_pair<empty_t,int>"* %this, %"struct.boost::compressed_pair<empty_t,int>"** %this_addr
+ %1 = load %"struct.boost::compressed_pair<empty_t,int>"** %this_addr, align 8 ; <%"struct.boost::compressed_pair<empty_t,int>"*> [#uses=1]
+ %2 = getelementptr inbounds %"struct.boost::compressed_pair<empty_t,int>"* %1, i32 0, i32 0 ; <%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"*> [#uses=1]
+ %3 = call %struct.empty_base_t* @_ZN5boost7details19compressed_pair_impI7empty_tiLi1EE5firstEv(%"struct.boost::details::compressed_pair_imp<empty_t,int,1>"* %2) nounwind ; <%struct.empty_base_t*> [#uses=1]
+ store %struct.empty_base_t* %3, %struct.empty_base_t** %0, align 8
+ %4 = load %struct.empty_base_t** %0, align 8 ; <%struct.empty_base_t*> [#uses=1]
+ store %struct.empty_base_t* %4, %struct.empty_base_t** %retval, align 8
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load %struct.empty_base_t** %retval ; <%struct.empty_base_t*> [#uses=1]
+ ret %struct.empty_base_t* %retval1
+}
+
+declare i32 @puts(i8*)
+
+declare void @abort() noreturn
diff --git a/src/LLVM/test/Transforms/PhaseOrdering/basic.ll b/src/LLVM/test/Transforms/PhaseOrdering/basic.ll
new file mode 100644
index 0000000..e5b2ba4
--- /dev/null
+++ b/src/LLVM/test/Transforms/PhaseOrdering/basic.ll
@@ -0,0 +1,118 @@
+; RUN: opt -O3 -S %s | FileCheck %s
+; XFAIL: *
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.6.7"
+
+declare i8* @malloc(i64)
+declare void @free(i8*)
+
+
+; PR2338
+define void @test1() nounwind ssp {
+ %retval = alloca i32, align 4
+ %i = alloca i8*, align 8
+ %call = call i8* @malloc(i64 1)
+ store i8* %call, i8** %i, align 8
+ %tmp = load i8** %i, align 8
+ store i8 1, i8* %tmp
+ %tmp1 = load i8** %i, align 8
+ call void @free(i8* %tmp1)
+ ret void
+
+; CHECK: @test1
+; CHECK-NEXT: ret void
+}
+
+
+; PR6627 - This whole nasty sequence should be flattened down to a single
+; 32-bit comparison.
+define void @test2(i8* %arrayidx) nounwind ssp {
+entry:
+ %xx = bitcast i8* %arrayidx to i32*
+ %x1 = load i32* %xx, align 4
+ %tmp = trunc i32 %x1 to i8
+ %conv = zext i8 %tmp to i32
+ %cmp = icmp eq i32 %conv, 127
+ br i1 %cmp, label %land.lhs.true, label %if.end
+
+land.lhs.true: ; preds = %entry
+ %arrayidx4 = getelementptr inbounds i8* %arrayidx, i64 1
+ %tmp5 = load i8* %arrayidx4, align 1
+ %conv6 = zext i8 %tmp5 to i32
+ %cmp7 = icmp eq i32 %conv6, 69
+ br i1 %cmp7, label %land.lhs.true9, label %if.end
+
+land.lhs.true9: ; preds = %land.lhs.true
+ %arrayidx12 = getelementptr inbounds i8* %arrayidx, i64 2
+ %tmp13 = load i8* %arrayidx12, align 1
+ %conv14 = zext i8 %tmp13 to i32
+ %cmp15 = icmp eq i32 %conv14, 76
+ br i1 %cmp15, label %land.lhs.true17, label %if.end
+
+land.lhs.true17: ; preds = %land.lhs.true9
+ %arrayidx20 = getelementptr inbounds i8* %arrayidx, i64 3
+ %tmp21 = load i8* %arrayidx20, align 1
+ %conv22 = zext i8 %tmp21 to i32
+ %cmp23 = icmp eq i32 %conv22, 70
+ br i1 %cmp23, label %if.then, label %if.end
+
+if.then: ; preds = %land.lhs.true17
+ %call25 = call i32 (...)* @doo()
+ br label %if.end
+
+if.end:
+ ret void
+
+; CHECK: @test2
+; CHECK: %x1 = load i32* %xx, align 4
+; CHECK-NEXT: icmp eq i32 %x1, 1179403647
+; CHECK-NEXT: br i1 {{.*}}, label %if.then, label %if.end
+}
+
+declare i32 @doo(...)
+
+; PR6627 - This should all be flattened down to one compare. This is the same
+; as test2, except that the initial load is done as an i8 instead of i32, thus
+; requiring widening.
+define void @test2a(i8* %arrayidx) nounwind ssp {
+entry:
+ %x1 = load i8* %arrayidx, align 4
+ %conv = zext i8 %x1 to i32
+ %cmp = icmp eq i32 %conv, 127
+ br i1 %cmp, label %land.lhs.true, label %if.end
+
+land.lhs.true: ; preds = %entry
+ %arrayidx4 = getelementptr inbounds i8* %arrayidx, i64 1
+ %tmp5 = load i8* %arrayidx4, align 1
+ %conv6 = zext i8 %tmp5 to i32
+ %cmp7 = icmp eq i32 %conv6, 69
+ br i1 %cmp7, label %land.lhs.true9, label %if.end
+
+land.lhs.true9: ; preds = %land.lhs.true
+ %arrayidx12 = getelementptr inbounds i8* %arrayidx, i64 2
+ %tmp13 = load i8* %arrayidx12, align 1
+ %conv14 = zext i8 %tmp13 to i32
+ %cmp15 = icmp eq i32 %conv14, 76
+ br i1 %cmp15, label %land.lhs.true17, label %if.end
+
+land.lhs.true17: ; preds = %land.lhs.true9
+ %arrayidx20 = getelementptr inbounds i8* %arrayidx, i64 3
+ %tmp21 = load i8* %arrayidx20, align 1
+ %conv22 = zext i8 %tmp21 to i32
+ %cmp23 = icmp eq i32 %conv22, 70
+ br i1 %cmp23, label %if.then, label %if.end
+
+if.then: ; preds = %land.lhs.true17
+ %call25 = call i32 (...)* @doo()
+ br label %if.end
+
+if.end:
+ ret void
+
+; CHECK: @test2a
+; CHECK: %x1 = load i32* {{.*}}, align 4
+; CHECK-NEXT: icmp eq i32 %x1, 1179403647
+; CHECK-NEXT: br i1 {{.*}}, label %if.then, label %if.end
+}
+
diff --git a/src/LLVM/test/Transforms/PhaseOrdering/dg.exp b/src/LLVM/test/Transforms/PhaseOrdering/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/PhaseOrdering/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/PruneEH/2003-09-14-ExternalCall.ll b/src/LLVM/test/Transforms/PruneEH/2003-09-14-ExternalCall.ll
new file mode 100644
index 0000000..8c4e8ef
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/2003-09-14-ExternalCall.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -prune-eh -S | grep invoke
+
+declare void @External()
+
+define void @foo() {
+ invoke void @External( )
+ to label %Cont unwind label %Cont
+Cont: ; preds = %0, %0
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/PruneEH/2003-11-21-PHIUpdate.ll b/src/LLVM/test/Transforms/PruneEH/2003-11-21-PHIUpdate.ll
new file mode 100644
index 0000000..58d04e6
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/2003-11-21-PHIUpdate.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -prune-eh -disable-output
+
+define internal void @callee() {
+ ret void
+}
+
+define i32 @caller() {
+; <label>:0
+ invoke void @callee( )
+ to label %E unwind label %E
+E: ; preds = %0, %0
+ %X = phi i32 [ 0, %0 ], [ 0, %0 ] ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/PruneEH/2008-06-02-Weak.ll b/src/LLVM/test/Transforms/PruneEH/2008-06-02-Weak.ll
new file mode 100644
index 0000000..fb97ae8
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/2008-06-02-Weak.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -prune-eh -S | not grep nounwind
+
+define weak void @f() {
+entry:
+ ret void
+}
+
+define void @g() {
+entry:
+ call void @f()
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/PruneEH/dg.exp b/src/LLVM/test/Transforms/PruneEH/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/PruneEH/recursivetest.ll b/src/LLVM/test/Transforms/PruneEH/recursivetest.ll
new file mode 100644
index 0000000..7683b88
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/recursivetest.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -prune-eh -S | not grep invoke
+
+define internal i32 @foo() {
+ invoke i32 @foo( )
+ to label %Normal unwind label %Except ; <i32>:1 [#uses=0]
+Normal: ; preds = %0
+ ret i32 12
+Except: ; preds = %0
+ ret i32 123
+}
+
+define i32 @caller() {
+ invoke i32 @foo( )
+ to label %Normal unwind label %Except ; <i32>:1 [#uses=0]
+Normal: ; preds = %0
+ ret i32 0
+Except: ; preds = %0
+ ret i32 1
+}
+
diff --git a/src/LLVM/test/Transforms/PruneEH/simplenoreturntest.ll b/src/LLVM/test/Transforms/PruneEH/simplenoreturntest.ll
new file mode 100644
index 0000000..999f84d
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/simplenoreturntest.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -prune-eh -S | not grep {ret i32}
+
+declare void @noreturn() noreturn
+
+define i32 @caller() {
+ call void @noreturn( )
+ ret i32 17
+}
+
+define i32 @caller2() {
+ %T = call i32 @caller( ) ; <i32> [#uses=1]
+ ret i32 %T
+}
diff --git a/src/LLVM/test/Transforms/PruneEH/simpletest.ll b/src/LLVM/test/Transforms/PruneEH/simpletest.ll
new file mode 100644
index 0000000..77c429d
--- /dev/null
+++ b/src/LLVM/test/Transforms/PruneEH/simpletest.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -prune-eh -S | not grep invoke
+
+declare void @nounwind() nounwind
+
+define internal void @foo() {
+ call void @nounwind()
+ ret void
+}
+
+define i32 @caller() {
+ invoke void @foo( )
+ to label %Normal unwind label %Except
+
+Normal: ; preds = %0
+ ret i32 0
+
+Except: ; preds = %0
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll b/src/LLVM/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll
new file mode 100644
index 0000000..7226178
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -reassociate -instcombine -constprop -dce -S | not grep add
+
+define i32 @test(i32 %A) {
+ %X = add i32 %A, 1 ; <i32> [#uses=1]
+ %Y = add i32 %A, 1 ; <i32> [#uses=1]
+ %r = sub i32 %X, %Y ; <i32> [#uses=1]
+ ret i32 %r
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2002-05-15-MissedTree.ll b/src/LLVM/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
new file mode 100644
index 0000000..471f51a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -reassociate -instcombine -constprop -die -S | not grep 5
+
+define i32 @test(i32 %A, i32 %B) {
+ %W = add i32 %B, -5 ; <i32> [#uses=1]
+ %Y = add i32 %A, 5 ; <i32> [#uses=1]
+ %Z = add i32 %W, %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll b/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
new file mode 100644
index 0000000..62647c2
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
@@ -0,0 +1,12 @@
+; With sub reassociation, constant folding can eliminate all of the constants.
+;
+; RUN: opt < %s -reassociate -constprop -instcombine -dce -S | not grep add
+
+define i32 @test(i32 %A, i32 %B) {
+ %W = add i32 5, %B ; <i32> [#uses=1]
+ %X = add i32 -7, %A ; <i32> [#uses=1]
+ %Y = sub i32 %X, %W ; <i32> [#uses=1]
+ %Z = add i32 %Y, 12 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll b/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll
new file mode 100644
index 0000000..2da3ecc
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll
@@ -0,0 +1,13 @@
+; With sub reassociation, constant folding can eliminate the two 12 constants.
+;
+; RUN: opt < %s -reassociate -constprop -dce -S | not grep 12
+
+define i32 @test(i32 %A, i32 %B, i32 %C, i32 %D) {
+ %M = add i32 %A, 12 ; <i32> [#uses=1]
+ %N = add i32 %M, %B ; <i32> [#uses=1]
+ %O = add i32 %N, %C ; <i32> [#uses=1]
+ %P = sub i32 %D, %O ; <i32> [#uses=1]
+ %Q = add i32 %P, 12 ; <i32> [#uses=1]
+ ret i32 %Q
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll b/src/LLVM/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll
new file mode 100644
index 0000000..67d90a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll
@@ -0,0 +1,10 @@
+; The reassociate pass is not preserving dominance properties correctly
+;
+; RUN: opt < %s -reassociate
+
+define i32 @compute_dist(i32 %i, i32 %j) {
+ %reg119 = sub i32 %j, %i ; <i32> [#uses=1]
+ ret i32 %reg119
+}
+
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll b/src/LLVM/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll
new file mode 100644
index 0000000..88ecfa3
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -reassociate -disable-output
+
+define i32 @test(i32 %A.1, i32 %B.1, i32 %C.1, i32 %D.1) {
+ %tmp.16 = and i32 %A.1, %B.1 ; <i32> [#uses=1]
+ %tmp.18 = and i32 %tmp.16, %C.1 ; <i32> [#uses=1]
+ %tmp.20 = and i32 %tmp.18, %D.1 ; <i32> [#uses=1]
+ ret i32 %tmp.20
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2005-08-24-Crash.ll b/src/LLVM/test/Transforms/Reassociate/2005-08-24-Crash.ll
new file mode 100644
index 0000000..c350dc3
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2005-08-24-Crash.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -reassociate -disable-output
+
+define void @test(i32 %a, i32 %b, i32 %c, i32 %d) {
+ %tmp.2 = xor i32 %a, %b ; <i32> [#uses=1]
+ %tmp.5 = xor i32 %c, %d ; <i32> [#uses=1]
+ %tmp.6 = xor i32 %tmp.2, %tmp.5 ; <i32> [#uses=1]
+ %tmp.9 = xor i32 %c, %a ; <i32> [#uses=1]
+ %tmp.12 = xor i32 %b, %d ; <i32> [#uses=1]
+ %tmp.13 = xor i32 %tmp.9, %tmp.12 ; <i32> [#uses=1]
+ %tmp.16 = xor i32 %tmp.6, %tmp.13 ; <i32> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll b/src/LLVM/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll
new file mode 100644
index 0000000..8680bef
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -reassociate -instcombine -S |\
+; RUN: grep {ret i32 0}
+
+define i32 @f(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {
+ %tmp.2 = add i32 %a4, %a3 ; <i32> [#uses=1]
+ %tmp.4 = add i32 %tmp.2, %a2 ; <i32> [#uses=1]
+ %tmp.6 = add i32 %tmp.4, %a1 ; <i32> [#uses=1]
+ %tmp.8 = add i32 %tmp.6, %a0 ; <i32> [#uses=1]
+ %tmp.11 = add i32 %a3, %a2 ; <i32> [#uses=1]
+ %tmp.13 = add i32 %tmp.11, %a1 ; <i32> [#uses=1]
+ %tmp.15 = add i32 %tmp.13, %a0 ; <i32> [#uses=1]
+ %tmp.18 = add i32 %a2, %a1 ; <i32> [#uses=1]
+ %tmp.20 = add i32 %tmp.18, %a0 ; <i32> [#uses=1]
+ %tmp.23 = add i32 %a1, %a0 ; <i32> [#uses=1]
+ %tmp.26 = sub i32 %tmp.8, %tmp.15 ; <i32> [#uses=1]
+ %tmp.28 = add i32 %tmp.26, %tmp.20 ; <i32> [#uses=1]
+ %tmp.30 = sub i32 %tmp.28, %tmp.23 ; <i32> [#uses=1]
+ %tmp.32 = sub i32 %tmp.30, %a4 ; <i32> [#uses=1]
+ %tmp.34 = sub i32 %tmp.32, %a2 ; <i32> [#uses=2]
+ %T = mul i32 %tmp.34, %tmp.34 ; <i32> [#uses=1]
+ ret i32 %T
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll b/src/LLVM/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll
new file mode 100644
index 0000000..d20cf6e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -reassociate -disable-output
+
+define void @foo() {
+ %tmp162 = fsub <4 x float> zeroinitializer, zeroinitializer ; <<4 x float>> [#uses=1]
+ %tmp164 = fmul <4 x float> zeroinitializer, %tmp162 ; <<4 x float>> [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll b/src/LLVM/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll
new file mode 100644
index 0000000..003fbb1
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -reassociate
+; PR9039
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-gnu-linux"
+
+define void @exp_averages_intraday__deviation() {
+entry:
+ %0 = load i32* undef, align 4
+ %1 = shl i32 %0, 2
+ %2 = add nsw i32 undef, %1
+ %3 = add nsw i32 %2, undef
+ %4 = mul nsw i32 %0, 12
+ %5 = add nsw i32 %3, %4
+ %6 = add nsw i32 %5, %4
+ %7 = add nsw i32 %6, undef
+ br i1 false, label %"4", label %"12"
+
+"4": ; preds = %entry
+ br i1 undef, label %"5", label %"8"
+
+"5": ; preds = %"4"
+ unreachable
+
+"8": ; preds = %"4"
+ %8 = getelementptr inbounds i8* undef, i32 %6
+ br i1 undef, label %"13", label %"12"
+
+"12": ; preds = %"8", %entry
+ ret void
+
+"13": ; preds = %"8"
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/basictest.ll b/src/LLVM/test/Transforms/Reassociate/basictest.ll
new file mode 100644
index 0000000..c8f8a5e
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/basictest.ll
@@ -0,0 +1,216 @@
+; With reassociation, constant folding can eliminate the 12 and -12 constants.
+;
+; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s
+
+define i32 @test1(i32 %arg) {
+ %tmp1 = sub i32 -12, %arg
+ %tmp2 = add i32 %tmp1, 12
+ ret i32 %tmp2
+; CHECK: @test1
+; CHECK-NEXT: sub i32 0, %arg
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test2(i32 %reg109, i32 %reg1111) {
+ %reg115 = add i32 %reg109, -30 ; <i32> [#uses=1]
+ %reg116 = add i32 %reg115, %reg1111 ; <i32> [#uses=1]
+ %reg117 = add i32 %reg116, 30 ; <i32> [#uses=1]
+ ret i32 %reg117
+; CHECK: @test2
+; CHECK-NEXT: add i32 %reg1111, %reg109
+; CHECK-NEXT: ret i32
+}
+
+@e = external global i32 ; <i32*> [#uses=3]
+@a = external global i32 ; <i32*> [#uses=3]
+@b = external global i32 ; <i32*> [#uses=3]
+@c = external global i32 ; <i32*> [#uses=3]
+@f = external global i32 ; <i32*> [#uses=3]
+
+define void @test3() {
+ %A = load i32* @a ; <i32> [#uses=2]
+ %B = load i32* @b ; <i32> [#uses=2]
+ %C = load i32* @c ; <i32> [#uses=2]
+ %t1 = add i32 %A, %B ; <i32> [#uses=1]
+ %t2 = add i32 %t1, %C ; <i32> [#uses=1]
+ %t3 = add i32 %C, %A ; <i32> [#uses=1]
+ %t4 = add i32 %t3, %B ; <i32> [#uses=1]
+ ; e = (a+b)+c;
+ store i32 %t2, i32* @e
+ ; f = (a+c)+b
+ store i32 %t4, i32* @f
+ ret void
+; CHECK: @test3
+; CHECK: add i32
+; CHECK: add i32
+; CHECK-NOT: add i32
+; CHECK: ret void
+}
+
+define void @test4() {
+ %A = load i32* @a ; <i32> [#uses=2]
+ %B = load i32* @b ; <i32> [#uses=2]
+ %C = load i32* @c ; <i32> [#uses=2]
+ %t1 = add i32 %A, %B ; <i32> [#uses=1]
+ %t2 = add i32 %t1, %C ; <i32> [#uses=1]
+ %t3 = add i32 %C, %A ; <i32> [#uses=1]
+ %t4 = add i32 %t3, %B ; <i32> [#uses=1]
+ ; e = c+(a+b)
+ store i32 %t2, i32* @e
+ ; f = (c+a)+b
+ store i32 %t4, i32* @f
+ ret void
+; CHECK: @test4
+; CHECK: add i32
+; CHECK: add i32
+; CHECK-NOT: add i32
+; CHECK: ret void
+}
+
+define void @test5() {
+ %A = load i32* @a ; <i32> [#uses=2]
+ %B = load i32* @b ; <i32> [#uses=2]
+ %C = load i32* @c ; <i32> [#uses=2]
+ %t1 = add i32 %B, %A ; <i32> [#uses=1]
+ %t2 = add i32 %t1, %C ; <i32> [#uses=1]
+ %t3 = add i32 %C, %A ; <i32> [#uses=1]
+ %t4 = add i32 %t3, %B ; <i32> [#uses=1]
+ ; e = c+(b+a)
+ store i32 %t2, i32* @e
+ ; f = (c+a)+b
+ store i32 %t4, i32* @f
+ ret void
+; CHECK: @test5
+; CHECK: add i32
+; CHECK: add i32
+; CHECK-NOT: add i32
+; CHECK: ret void
+}
+
+define i32 @test6() {
+ %tmp.0 = load i32* @a
+ %tmp.1 = load i32* @b
+ ; (a+b)
+ %tmp.2 = add i32 %tmp.0, %tmp.1
+ %tmp.4 = load i32* @c
+ ; (a+b)+c
+ %tmp.5 = add i32 %tmp.2, %tmp.4
+ ; (a+c)
+ %tmp.8 = add i32 %tmp.0, %tmp.4
+ ; (a+c)+b
+ %tmp.11 = add i32 %tmp.8, %tmp.1
+ ; X ^ X = 0
+ %RV = xor i32 %tmp.5, %tmp.11
+ ret i32 %RV
+; CHECK: @test6
+; CHECK: ret i32 0
+}
+
+; This should be one add and two multiplies.
+define i32 @test7(i32 %A, i32 %B, i32 %C) {
+ ; A*A*B + A*C*A
+ %aa = mul i32 %A, %A
+ %aab = mul i32 %aa, %B
+ %ac = mul i32 %A, %C
+ %aac = mul i32 %ac, %A
+ %r = add i32 %aab, %aac
+ ret i32 %r
+; CHECK: @test7
+; CHECK-NEXT: add i32 %C, %B
+; CHECK-NEXT: mul i32
+; CHECK-NEXT: mul i32
+; CHECK-NEXT: ret i32
+}
+
+
+define i32 @test8(i32 %X, i32 %Y, i32 %Z) {
+ %A = sub i32 0, %X
+ %B = mul i32 %A, %Y
+ ; (-X)*Y + Z -> Z-X*Y
+ %C = add i32 %B, %Z
+ ret i32 %C
+; CHECK: @test8
+; CHECK-NEXT: %A = mul i32 %Y, %X
+; CHECK-NEXT: %C = sub i32 %Z, %A
+; CHECK-NEXT: ret i32 %C
+}
+
+
+; PR5458
+define i32 @test9(i32 %X) {
+ %Y = mul i32 %X, 47
+ %Z = add i32 %Y, %Y
+ ret i32 %Z
+; CHECK: @test9
+; CHECK-NEXT: mul i32 %X, 94
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test10(i32 %X) {
+ %Y = add i32 %X ,%X
+ %Z = add i32 %Y, %X
+ ret i32 %Z
+; CHECK: @test10
+; CHECK-NEXT: mul i32 %X, 3
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test11(i32 %W) {
+ %X = mul i32 %W, 127
+ %Y = add i32 %X ,%X
+ %Z = add i32 %Y, %X
+ ret i32 %Z
+; CHECK: @test11
+; CHECK-NEXT: mul i32 %W, 381
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test12(i32 %X) {
+ %A = sub i32 1, %X
+ %B = sub i32 2, %X
+ %C = sub i32 3, %X
+
+ %Y = add i32 %A ,%B
+ %Z = add i32 %Y, %C
+ ret i32 %Z
+; CHECK: @test12
+; CHECK-NEXT: mul i32 %X, -3
+; CHECK-NEXT: add i32{{.*}}, 6
+; CHECK-NEXT: ret i32
+}
+
+define i32 @test13(i32 %X1, i32 %X2, i32 %X3) {
+ %A = sub i32 0, %X1
+ %B = mul i32 %A, %X2 ; -X1*X2
+ %C = mul i32 %X1, %X3 ; X1*X3
+ %D = add i32 %B, %C ; -X1*X2 + X1*X3 -> X1*(X3-X2)
+ ret i32 %D
+; CHECK: @test13
+; CHECK-NEXT: sub i32 %X3, %X2
+; CHECK-NEXT: mul i32 {{.*}}, %X1
+; CHECK-NEXT: ret i32
+}
+
+; PR5359
+define i32 @test14(i32 %X1, i32 %X2) {
+ %B = mul i32 %X1, 47 ; X1*47
+ %C = mul i32 %X2, -47 ; X2*-47
+ %D = add i32 %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
+ ret i32 %D
+; CHECK: @test14
+; CHECK-NEXT: sub i32 %X1, %X2
+; CHECK-NEXT: mul i32 {{.*}}, 47
+; CHECK-NEXT: ret i32
+}
+
+; Do not reassociate expressions of type i1
+define i32 @test15(i32 %X1, i32 %X2, i32 %X3) {
+ %A = icmp ne i32 %X1, 0
+ %B = icmp slt i32 %X2, %X3
+ %C = and i1 %A, %B
+ %D = select i1 %C, i32 %X1, i32 0
+ ret i32 %D
+; CHECK: @test15
+; CHECK: and i1 %A, %B
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/crash.ll b/src/LLVM/test/Transforms/Reassociate/crash.ll
new file mode 100644
index 0000000..7a81942
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/crash.ll
@@ -0,0 +1,69 @@
+; RUN: opt -reassociate -disable-output %s
+
+
+; rdar://7507855
+define fastcc i32 @test1() nounwind {
+entry:
+ %cond = select i1 undef, i32 1, i32 -1 ; <i32> [#uses=2]
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ %sub889 = sub i32 undef, undef ; <i32> [#uses=1]
+ %sub891 = sub i32 %sub889, %cond ; <i32> [#uses=0]
+ %add896 = sub i32 0, %cond ; <i32> [#uses=0]
+ ret i32 undef
+}
+
+; PR5981
+define i32 @test2() nounwind ssp {
+entry:
+ %0 = load i32* undef, align 4
+ %1 = mul nsw i32 undef, %0
+ %2 = mul nsw i32 undef, %0
+ %3 = add nsw i32 undef, %1
+ %4 = add nsw i32 %3, %2
+ %5 = add nsw i32 %4, 4
+ %6 = shl i32 %0, 3
+ %7 = add nsw i32 %5, %6
+ br label %bb4.i9
+
+bb4.i9:
+ %8 = add nsw i32 undef, %1
+ ret i32 0
+}
+
+
+define i32 @test3(i32 %Arg, i32 %x1, i32 %x2, i32 %x3) {
+ %A = mul i32 %x1, %Arg
+ %B = mul i32 %Arg, %x2 ;; Part of add operation being factored, also used by C
+ %C = mul i32 %x3, %B
+
+ %D = add i32 %A, %B
+ %E = add i32 %D, %C
+ ret i32 %E
+}
+
+
+; rdar://9096268
+define void @x66303361ae3f602889d1b7d0f86e5455(i8* %arg) nounwind {
+_:
+ br label %_33
+
+_33: ; preds = %_33, %_
+ %tmp348 = load i8* %arg, align 1
+ %tmp349 = lshr i8 %tmp348, 7
+ %tmp350 = or i8 %tmp349, 42
+ %tmp351 = add i8 %tmp350, -42
+ %tmp352 = zext i8 %tmp351 to i32
+ %tmp358 = add i32 %tmp352, -501049439
+ %tmp359 = mul i32 %tmp358, %tmp358
+ %tmp360 = mul i32 %tmp352, %tmp352
+ %tmp361 = sub i32 %tmp359, %tmp360
+ %tmp362 = mul i32 %tmp361, -920056735
+ %tmp363 = add i32 %tmp362, 501049439
+ %tmp364 = add i32 %tmp362, -2000262972
+ %tmp365 = sub i32 %tmp363, %tmp364
+ %tmp366 = sub i32 -501049439, %tmp362
+ %tmp367 = add i32 %tmp365, %tmp366
+ br label %_33
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/dg.exp b/src/LLVM/test/Transforms/Reassociate/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/Reassociate/inverses.ll b/src/LLVM/test/Transforms/Reassociate/inverses.ll
new file mode 100644
index 0000000..7ddb8d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/inverses.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -reassociate -die -S | FileCheck %s
+
+define i32 @test1(i32 %a, i32 %b) {
+ %tmp.2 = and i32 %b, %a
+ %tmp.4 = xor i32 %a, -1
+ ; (A&B)&~A == 0
+ %tmp.5 = and i32 %tmp.2, %tmp.4
+ ret i32 %tmp.5
+; CHECK: @test1
+; CHECK: ret i32 0
+}
+
+define i32 @test2(i32 %a, i32 %b) {
+ %tmp.1 = and i32 %a, 1234
+ %tmp.2 = and i32 %b, %tmp.1
+ %tmp.4 = xor i32 %a, -1
+ ; A&~A == 0
+ %tmp.5 = and i32 %tmp.2, %tmp.4
+ ret i32 %tmp.5
+; CHECK: @test2
+; CHECK: ret i32 0
+}
+
+define i32 @test3(i32 %b, i32 %a) {
+ %tmp.1 = add i32 %a, 1234
+ %tmp.2 = add i32 %b, %tmp.1
+ %tmp.4 = sub i32 0, %a
+ ; (b+(a+1234))+-a -> b+1234
+ %tmp.5 = add i32 %tmp.2, %tmp.4
+ ret i32 %tmp.5
+; CHECK: @test3
+; CHECK: %tmp.5 = add i32 %b, 1234
+; CHECK: ret i32 %tmp.5
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/looptest.ll b/src/LLVM/test/Transforms/Reassociate/looptest.ll
new file mode 100644
index 0000000..4ec0c18
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/looptest.ll
@@ -0,0 +1,50 @@
+; This testcase comes from this C fragment:
+;
+; void test(unsigned Num, int *Array) {
+; unsigned i, j, k;
+;
+; for (i = 0; i != Num; ++i)
+; for (j = 0; j != Num; ++j)
+; for (k = 0; k != Num; ++k)
+; printf("%d\n", i+k+j); /* Reassociate to (i+j)+k */
+;}
+;
+; In this case, we want to reassociate the specified expr so that i+j can be
+; hoisted out of the inner most loop.
+;
+; RUN: opt < %s -reassociate -S | grep 115 | not grep 117
+; END.
+@.LC0 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+declare i32 @printf(i8*, ...)
+
+define void @test(i32 %Num, i32* %Array) {
+bb0:
+ %cond221 = icmp eq i32 0, %Num ; <i1> [#uses=3]
+ br i1 %cond221, label %bb7, label %bb2
+bb2: ; preds = %bb6, %bb0
+ %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; <i32> [#uses=2]
+ br i1 %cond221, label %bb6, label %bb3
+bb3: ; preds = %bb5, %bb2
+ %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; <i32> [#uses=2]
+ br i1 %cond221, label %bb5, label %bb4
+bb4: ; preds = %bb4, %bb3
+ %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; <i32> [#uses=2]
+ %reg113 = add i32 %reg115, %reg117 ; <i32> [#uses=1]
+ %reg114 = add i32 %reg113, %reg116 ; <i32> [#uses=1]
+ %cast227 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0 ; <i8*> [#uses=1]
+ call i32 (i8*, ...)* @printf( i8* %cast227, i32 %reg114 ) ; <i32>:0 [#uses=0]
+ %reg118 = add i32 %reg117, 1 ; <i32> [#uses=2]
+ %cond224 = icmp ne i32 %reg118, %Num ; <i1> [#uses=1]
+ br i1 %cond224, label %bb4, label %bb5
+bb5: ; preds = %bb4, %bb3
+ %reg119 = add i32 %reg116, 1 ; <i32> [#uses=2]
+ %cond225 = icmp ne i32 %reg119, %Num ; <i1> [#uses=1]
+ br i1 %cond225, label %bb3, label %bb6
+bb6: ; preds = %bb5, %bb2
+ %reg120 = add i32 %reg115, 1 ; <i32> [#uses=2]
+ %cond226 = icmp ne i32 %reg120, %Num ; <i1> [#uses=1]
+ br i1 %cond226, label %bb2, label %bb7
+bb7: ; preds = %bb6, %bb0
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/mulfactor.ll b/src/LLVM/test/Transforms/Reassociate/mulfactor.ll
new file mode 100644
index 0000000..2ce5644
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/mulfactor.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -reassociate -instcombine -S | grep mul | count 2
+
+; This should have exactly 2 multiplies when we're done.
+
+define i32 @f(i32 %a, i32 %b) {
+ %tmp.2 = mul i32 %a, %a ; <i32> [#uses=1]
+ %tmp.5 = shl i32 %a, 1 ; <i32> [#uses=1]
+ %tmp.6 = mul i32 %tmp.5, %b ; <i32> [#uses=1]
+ %tmp.10 = mul i32 %b, %b ; <i32> [#uses=1]
+ %tmp.7 = add i32 %tmp.6, %tmp.2 ; <i32> [#uses=1]
+ %tmp.11 = add i32 %tmp.7, %tmp.10 ; <i32> [#uses=1]
+ ret i32 %tmp.11
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/mulfactor2.ll b/src/LLVM/test/Transforms/Reassociate/mulfactor2.ll
new file mode 100644
index 0000000..dd6a282
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/mulfactor2.ll
@@ -0,0 +1,15 @@
+; This should turn into one multiply and one add.
+
+; RUN: opt < %s -instcombine -reassociate -instcombine -S > %t
+; RUN: grep mul %t | count 1
+; RUN: grep add %t | count 1
+
+define i32 @main(i32 %t) {
+ %tmp.3 = mul i32 %t, 12 ; <i32> [#uses=1]
+ %tmp.4 = add i32 %tmp.3, 5 ; <i32> [#uses=1]
+ %tmp.6 = mul i32 %t, 6 ; <i32> [#uses=1]
+ %tmp.8 = mul i32 %tmp.4, 3 ; <i32> [#uses=1]
+ %tmp.9 = add i32 %tmp.8, %tmp.6 ; <i32> [#uses=1]
+ ret i32 %tmp.9
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/negation.ll b/src/LLVM/test/Transforms/Reassociate/negation.ll
new file mode 100644
index 0000000..e1e434a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/negation.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -reassociate -instcombine -S | not grep sub
+
+; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
+
+define i32 @test1(i32 %a, i32 %b, i32 %z) {
+ %c = sub i32 0, %z ; <i32> [#uses=1]
+ %d = mul i32 %a, %b ; <i32> [#uses=1]
+ %e = mul i32 %c, %d ; <i32> [#uses=1]
+ %f = mul i32 %e, 12345 ; <i32> [#uses=1]
+ %g = sub i32 0, %f ; <i32> [#uses=1]
+ ret i32 %g
+}
+
+define i32 @test2(i32 %a, i32 %b, i32 %z) {
+ %d = mul i32 %z, 40 ; <i32> [#uses=1]
+ %c = sub i32 0, %d ; <i32> [#uses=1]
+ %e = mul i32 %a, %c ; <i32> [#uses=1]
+ %f = sub i32 0, %e ; <i32> [#uses=1]
+ ret i32 %f
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/optional-flags.ll b/src/LLVM/test/Transforms/Reassociate/optional-flags.ll
new file mode 100644
index 0000000..40f7d5b
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/optional-flags.ll
@@ -0,0 +1,29 @@
+; RUN: opt -S -reassociate < %s | FileCheck %s
+; rdar://8944681
+
+; Reassociate should clear optional flags like nsw when reassociating.
+
+; CHECK: @test0
+; CHECK: %y = add i64 %b, %a
+; CHECK: %z = add i64 %y, %c
+define i64 @test0(i64 %a, i64 %b, i64 %c) {
+ %y = add nsw i64 %c, %b
+ %z = add i64 %y, %a
+ ret i64 %z
+}
+
+; CHECK: @test1
+; CHECK: %y = add i64 %b, %a
+; CHECK: %z = add i64 %y, %c
+define i64 @test1(i64 %a, i64 %b, i64 %c) {
+ %y = add i64 %c, %b
+ %z = add nsw i64 %y, %a
+ ret i64 %z
+}
+
+; PR9215
+; CHECK: %s = add nsw i32 %y, %x
+define i32 @test2(i32 %x, i32 %y) {
+ %s = add nsw i32 %x, %y
+ ret i32 %s
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/otherops.ll b/src/LLVM/test/Transforms/Reassociate/otherops.ll
new file mode 100644
index 0000000..be54344
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/otherops.ll
@@ -0,0 +1,28 @@
+; Reassociation should apply to Add, Mul, And, Or, & Xor
+;
+; RUN: opt < %s -reassociate -constprop -instcombine -die -S | not grep 12
+
+define i32 @test_mul(i32 %arg) {
+ %tmp1 = mul i32 12, %arg ; <i32> [#uses=1]
+ %tmp2 = mul i32 %tmp1, 12 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @test_and(i32 %arg) {
+ %tmp1 = and i32 14, %arg ; <i32> [#uses=1]
+ %tmp2 = and i32 %tmp1, 14 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @test_or(i32 %arg) {
+ %tmp1 = or i32 14, %arg ; <i32> [#uses=1]
+ %tmp2 = or i32 %tmp1, 14 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
+define i32 @test_xor(i32 %arg) {
+ %tmp1 = xor i32 12, %arg ; <i32> [#uses=1]
+ %tmp2 = xor i32 %tmp1, 12 ; <i32> [#uses=1]
+ ret i32 %tmp2
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/secondary.ll b/src/LLVM/test/Transforms/Reassociate/secondary.ll
new file mode 100644
index 0000000..a52000a
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/secondary.ll
@@ -0,0 +1,24 @@
+; RUN: opt -S -reassociate < %s | FileCheck %s
+; rdar://9167457
+
+; Reassociate shouldn't break this testcase involving a secondary
+; reassociation.
+
+; CHECK: define
+; CHECK-NOT: undef
+; CHECK: %factor = mul i32 %tmp3, -2
+; CHECK-NOT: undef
+; CHECK: }
+
+define void @x0f2f640ab6718391b59ce96d9fdeda54(i32 %arg, i32 %arg1, i32 %arg2, i32* %.out) nounwind {
+_:
+ %tmp = sub i32 %arg, %arg1
+ %tmp3 = mul i32 %tmp, -1268345047
+ %tmp4 = add i32 %tmp3, 2014710503
+ %tmp5 = add i32 %tmp3, -1048397418
+ %tmp6 = sub i32 %tmp4, %tmp5
+ %tmp7 = sub i32 -2014710503, %tmp3
+ %tmp8 = add i32 %tmp6, %tmp7
+ store i32 %tmp8, i32* %.out
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/Reassociate/shift-factor.ll b/src/LLVM/test/Transforms/Reassociate/shift-factor.ll
new file mode 100644
index 0000000..8497028
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/shift-factor.ll
@@ -0,0 +1,12 @@
+; There should be exactly one shift and one add left.
+; RUN: opt < %s -reassociate -instcombine -S > %t
+; RUN: grep shl %t | count 1
+; RUN: grep add %t | count 1
+
+define i32 @test(i32 %X, i32 %Y) {
+ %tmp.2 = shl i32 %X, 1 ; <i32> [#uses=1]
+ %tmp.6 = shl i32 %Y, 1 ; <i32> [#uses=1]
+ %tmp.4 = add i32 %tmp.6, %tmp.2 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/shifttest.ll b/src/LLVM/test/Transforms/Reassociate/shifttest.ll
new file mode 100644
index 0000000..82b0832
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/shifttest.ll
@@ -0,0 +1,12 @@
+; With shl->mul reassociation, we can see that this is (shl A, 9) * A
+;
+; RUN: opt < %s -reassociate -instcombine -S |\
+; RUN: grep {shl .*, 9}
+
+define i32 @test(i32 %A, i32 %B) {
+ %X = shl i32 %A, 5 ; <i32> [#uses=1]
+ %Y = shl i32 %A, 4 ; <i32> [#uses=1]
+ %Z = mul i32 %Y, %X ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/subtest.ll b/src/LLVM/test/Transforms/Reassociate/subtest.ll
new file mode 100644
index 0000000..ab1849c
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/subtest.ll
@@ -0,0 +1,11 @@
+; With sub reassociation, constant folding can eliminate the 12 and -12 constants.
+;
+; RUN: opt < %s -reassociate -instcombine -S | not grep 12
+
+define i32 @test(i32 %A, i32 %B) {
+ %X = add i32 -12, %A ; <i32> [#uses=1]
+ %Y = sub i32 %X, %B ; <i32> [#uses=1]
+ %Z = add i32 %Y, 12 ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/Reassociate/subtest2.ll b/src/LLVM/test/Transforms/Reassociate/subtest2.ll
new file mode 100644
index 0000000..0513c5f
--- /dev/null
+++ b/src/LLVM/test/Transforms/Reassociate/subtest2.ll
@@ -0,0 +1,13 @@
+; With sub reassociation, constant folding can eliminate the uses of %a.
+;
+; RUN: opt < %s -reassociate -instcombine -S | grep %a | count 1
+; PR2047
+
+define i32 @test(i32 %a, i32 %b, i32 %c) nounwind {
+entry:
+ %tmp3 = sub i32 %a, %b ; <i32> [#uses=1]
+ %tmp5 = sub i32 %tmp3, %c ; <i32> [#uses=1]
+ %tmp7 = sub i32 %tmp5, %a ; <i32> [#uses=1]
+ ret i32 %tmp7
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2002-05-02-MissSecondInst.ll b/src/LLVM/test/Transforms/SCCP/2002-05-02-MissSecondInst.ll
new file mode 100644
index 0000000..be6a8cf
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2002-05-02-MissSecondInst.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -sccp -S | not grep sub
+
+define void @test3(i32, i32) {
+ add i32 0, 0 ; <i32>:3 [#uses=0]
+ sub i32 0, 4 ; <i32>:4 [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2002-05-20-MissedIncomingValue.ll b/src/LLVM/test/Transforms/SCCP/2002-05-20-MissedIncomingValue.ll
new file mode 100644
index 0000000..f521055
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2002-05-20-MissedIncomingValue.ll
@@ -0,0 +1,19 @@
+; This test shows a case where SCCP is incorrectly eliminating the PHI node
+; because it thinks it has a constant 0 value, when it really doesn't.
+
+; RUN: opt < %s -sccp -S | grep phi
+
+define i32 @test(i32 %A, i1 %c) {
+bb1:
+ br label %BB2
+BB2: ; preds = %BB4, %bb1
+ %V = phi i32 [ 0, %bb1 ], [ %A, %BB4 ] ; <i32> [#uses=1]
+ br label %BB3
+BB3: ; preds = %BB2
+ br i1 %c, label %BB4, label %BB5
+BB4: ; preds = %BB3
+ br label %BB2
+BB5: ; preds = %BB3
+ ret i32 %V
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2002-05-21-InvalidSimplify.ll b/src/LLVM/test/Transforms/SCCP/2002-05-21-InvalidSimplify.ll
new file mode 100644
index 0000000..698b6c9
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2002-05-21-InvalidSimplify.ll
@@ -0,0 +1,33 @@
+; This test shows SCCP "proving" that the loop (from bb6 to 14) loops infinitely
+; this is in fact NOT the case, so the return should still be alive in the code
+; after sccp and CFG simplification have been performed.
+;
+; RUN: opt < %s -sccp -simplifycfg -S | \
+; RUN: grep ret
+
+define void @old_main() {
+bb3:
+ br label %bb6
+bb6: ; preds = %bb14, %bb3
+ %reg403 = phi i32 [ %reg155, %bb14 ], [ 0, %bb3 ] ; <i32> [#uses=1]
+ %reg155 = add i32 %reg403, 1 ; <i32> [#uses=2]
+ br label %bb11
+bb11: ; preds = %bb11, %bb6
+ %reg407 = phi i32 [ %reg408, %bb11 ], [ 0, %bb6 ] ; <i32> [#uses=2]
+ %reg408 = add i32 %reg407, 1 ; <i32> [#uses=1]
+ %cond550 = icmp sle i32 %reg407, 1 ; <i1> [#uses=1]
+ br i1 %cond550, label %bb11, label %bb12
+bb12: ; preds = %bb11
+ br label %bb13
+bb13: ; preds = %bb13, %bb12
+ %reg409 = phi i32 [ %reg410, %bb13 ], [ 0, %bb12 ] ; <i32> [#uses=1]
+ %reg410 = add i32 %reg409, 1 ; <i32> [#uses=2]
+ %cond552 = icmp sle i32 %reg410, 2 ; <i1> [#uses=1]
+ br i1 %cond552, label %bb13, label %bb14
+bb14: ; preds = %bb13
+ %cond553 = icmp sle i32 %reg155, 31 ; <i1> [#uses=1]
+ br i1 %cond553, label %bb6, label %bb15
+bb15: ; preds = %bb14
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2002-08-30-GetElementPtrTest.ll b/src/LLVM/test/Transforms/SCCP/2002-08-30-GetElementPtrTest.ll
new file mode 100644
index 0000000..88bb205
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2002-08-30-GetElementPtrTest.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -sccp -S | not grep %X
+
+@G = external global [40 x i32] ; <[40 x i32]*> [#uses=1]
+
+define i32* @test() {
+ %X = getelementptr [40 x i32]* @G, i64 0, i64 0 ; <i32*> [#uses=1]
+ ret i32* %X
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2003-06-24-OverdefinedPHIValue.ll b/src/LLVM/test/Transforms/SCCP/2003-06-24-OverdefinedPHIValue.ll
new file mode 100644
index 0000000..850b28c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2003-06-24-OverdefinedPHIValue.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -sccp -simplifycfg -S | \
+; RUN: not grep then:
+
+define void @cprop_test11(i32* %data.1) {
+entry:
+ %tmp.1 = load i32* %data.1 ; <i32> [#uses=3]
+ %tmp.41 = icmp sgt i32 %tmp.1, 1 ; <i1> [#uses=1]
+ br i1 %tmp.41, label %no_exit, label %loopexit
+no_exit: ; preds = %endif, %then, %entry
+ %j.0 = phi i32 [ %j.0, %endif ], [ %i.0, %then ], [ 1, %entry ] ; <i32> [#uses=3]
+ %i.0 = phi i32 [ %inc, %endif ], [ %inc1, %then ], [ 1, %entry ] ; <i32> [#uses=4]
+ %tmp.8.not = icmp ne i32 %j.0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.8.not, label %endif, label %then
+then: ; preds = %no_exit
+ %inc1 = add i32 %i.0, 1 ; <i32> [#uses=3]
+ %tmp.42 = icmp slt i32 %inc1, %tmp.1 ; <i1> [#uses=1]
+ br i1 %tmp.42, label %no_exit, label %loopexit
+endif: ; preds = %no_exit
+ %inc = add i32 %i.0, 1 ; <i32> [#uses=3]
+ %tmp.4 = icmp slt i32 %inc, %tmp.1 ; <i1> [#uses=1]
+ br i1 %tmp.4, label %no_exit, label %loopexit
+loopexit: ; preds = %endif, %then, %entry
+ %j.1 = phi i32 [ 1, %entry ], [ %j.0, %endif ], [ %i.0, %then ] ; <i32> [#uses=1]
+ %i.1 = phi i32 [ 1, %entry ], [ %inc, %endif ], [ %inc1, %then ] ; <i32> [#uses=1]
+ %tmp.17 = getelementptr i32* %data.1, i64 1 ; <i32*> [#uses=1]
+ store i32 %j.1, i32* %tmp.17
+ %tmp.23 = getelementptr i32* %data.1, i64 2 ; <i32*> [#uses=1]
+ store i32 %i.1, i32* %tmp.23
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SCCP/2003-08-26-InvokeHandling.ll b/src/LLVM/test/Transforms/SCCP/2003-08-26-InvokeHandling.ll
new file mode 100644
index 0000000..73724d8
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2003-08-26-InvokeHandling.ll
@@ -0,0 +1,23 @@
+; The PHI cannot be eliminated from this testcase, SCCP is mishandling invoke's!
+; RUN: opt < %s -sccp -S | grep phi
+
+declare void @foo()
+
+define i32 @test(i1 %cond) {
+Entry:
+ br i1 %cond, label %Inv, label %Cont
+Inv: ; preds = %Entry
+ invoke void @foo( )
+ to label %Ok unwind label %LPad
+Ok: ; preds = %Inv
+ br label %Cont
+LPad:
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ br label %Cont
+Cont: ; preds = %Ok, %Inv, %Entry
+ %X = phi i32 [ 0, %Entry ], [ 1, %Ok ], [ 0, %LPad ] ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SCCP/2004-11-16-DeadInvoke.ll b/src/LLVM/test/Transforms/SCCP/2004-11-16-DeadInvoke.ll
new file mode 100644
index 0000000..9b84ad6
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2004-11-16-DeadInvoke.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -sccp -disable-output
+
+declare i32 @foo()
+
+define void @caller() {
+ br i1 true, label %T, label %F
+F: ; preds = %0
+ %X = invoke i32 @foo( )
+ to label %T unwind label %LP ; <i32> [#uses=0]
+LP:
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ br label %T
+T:
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SCCP/2004-12-10-UndefBranchBug.ll b/src/LLVM/test/Transforms/SCCP/2004-12-10-UndefBranchBug.ll
new file mode 100644
index 0000000..dafb68e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2004-12-10-UndefBranchBug.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -sccp -S | grep {ret i32 1}
+
+; This function definitely returns 1, even if we don't know the direction
+; of the branch.
+
+define i32 @foo() {
+ br i1 undef, label %T, label %T
+T: ; preds = %0, %0
+ %X = add i32 0, 1 ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2006-10-23-IPSCCP-Crash.ll b/src/LLVM/test/Transforms/SCCP/2006-10-23-IPSCCP-Crash.ll
new file mode 100644
index 0000000..a2d36fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2006-10-23-IPSCCP-Crash.ll
@@ -0,0 +1,103 @@
+; RUN: opt < %s -sccp -disable-output
+; END.
+target datalayout = "E-p:32:32"
+target triple = "powerpc-apple-darwin8.7.0"
+ %struct.pat_list = type { i32, %struct.pat_list* }
+@JUMP = external global i32 ; <i32*> [#uses=1]
+@old_D_pat = external global [16 x i8] ; <[16 x i8]*> [#uses=0]
+
+define void @asearch1(i32 %D) {
+entry:
+ %tmp80 = icmp ult i32 0, %D ; <i1> [#uses=1]
+ br i1 %tmp80, label %bb647.preheader, label %cond_true81.preheader
+cond_true81.preheader: ; preds = %entry
+ ret void
+bb647.preheader: ; preds = %entry
+ %tmp3.i = call i32 @read( ) ; <i32> [#uses=1]
+ %tmp6.i = add i32 %tmp3.i, 0 ; <i32> [#uses=1]
+ %tmp653 = icmp sgt i32 %tmp6.i, 0 ; <i1> [#uses=1]
+ br i1 %tmp653, label %cond_true654, label %UnifiedReturnBlock
+cond_true612: ; preds = %cond_true654
+ ret void
+cond_next624: ; preds = %cond_true654
+ ret void
+cond_true654: ; preds = %bb647.preheader
+ br i1 undef, label %cond_true612, label %cond_next624
+UnifiedReturnBlock: ; preds = %bb647.preheader
+ ret void
+}
+
+define void @bitap(i32 %D) {
+entry:
+ %tmp29 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp29, label %cond_next50, label %cond_next37
+cond_next37: ; preds = %entry
+ ret void
+cond_next50: ; preds = %entry
+ %tmp52 = icmp sgt i32 %D, 0 ; <i1> [#uses=1]
+ br i1 %tmp52, label %cond_true53, label %cond_next71
+cond_true53: ; preds = %cond_next50
+ %tmp54 = load i32* @JUMP ; <i32> [#uses=1]
+ %tmp55 = icmp eq i32 %tmp54, 1 ; <i1> [#uses=1]
+ br i1 %tmp55, label %cond_true56, label %cond_next63
+cond_true56: ; preds = %cond_true53
+ %tmp57 = bitcast i32 %D to i32 ; <i32> [#uses=1]
+ call void @asearch1( i32 %tmp57 )
+ ret void
+cond_next63: ; preds = %cond_true53
+ ret void
+cond_next71: ; preds = %cond_next50
+ ret void
+}
+
+declare i32 @read()
+
+define void @initial_value() {
+entry:
+ ret void
+}
+
+define void @main() {
+entry:
+ br label %cond_next252
+cond_next208: ; preds = %cond_true260
+ %tmp229 = call i32 @atoi( ) ; <i32> [#uses=1]
+ br label %cond_next252
+bb217: ; preds = %cond_true260
+ ret void
+cond_next252: ; preds = %cond_next208, %entry
+ %D.0.0 = phi i32 [ 0, %entry ], [ %tmp229, %cond_next208 ] ; <i32> [#uses=1]
+ %tmp254 = getelementptr i8** null, i32 1 ; <i8**> [#uses=1]
+ %tmp256 = load i8** %tmp254 ; <i8*> [#uses=1]
+ %tmp258 = load i8* %tmp256 ; <i8> [#uses=1]
+ %tmp259 = icmp eq i8 %tmp258, 45 ; <i1> [#uses=1]
+ br i1 %tmp259, label %cond_true260, label %bb263
+cond_true260: ; preds = %cond_next252
+ %tmp205818 = icmp sgt i8 0, -1 ; <i1> [#uses=1]
+ br i1 %tmp205818, label %cond_next208, label %bb217
+bb263: ; preds = %cond_next252
+ %tmp265 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp265, label %cond_next276, label %cond_true266
+cond_true266: ; preds = %bb263
+ ret void
+cond_next276: ; preds = %bb263
+ %tmp278 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp278, label %cond_next298, label %cond_true279
+cond_true279: ; preds = %cond_next276
+ ret void
+cond_next298: ; preds = %cond_next276
+ call void @bitap( i32 %D.0.0 )
+ ret void
+}
+
+declare i32 @atoi()
+
+define void @subset_pset() {
+entry:
+ ret void
+}
+
+define void @strcmp() {
+entry:
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SCCP/2006-12-04-PackedType.ll b/src/LLVM/test/Transforms/SCCP/2006-12-04-PackedType.ll
new file mode 100644
index 0000000..6027e4c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2006-12-04-PackedType.ll
@@ -0,0 +1,140 @@
+; Test VectorType handling by SCCP.
+; SCCP ignores VectorTypes until PR 1034 is fixed
+;
+; RUN: opt < %s -sccp
+; END.
+
+target datalayout = "E-p:32:32"
+target triple = "powerpc-apple-darwin8"
+ %struct.GLDAlphaTest = type { float, i16, i8, i8 }
+ %struct.GLDArrayRange = type { i8, i8, i8, i8 }
+ %struct.GLDBlendMode = type { i16, i16, i16, i16, %struct.GLTColor4, i16, i16, i8, i8, i8, i8 }
+ %struct.GLDBufferRec = type opaque
+ %struct.GLDBufferstate = type { %struct.GLTDimensions, %struct.GLTDimensions, %struct.GLTFixedColor4, %struct.GLTFixedColor4, i8, i8, i8, i8, [2 x %struct.GLSBuffer], [4 x %struct.GLSBuffer], %struct.GLSBuffer, %struct.GLSBuffer, %struct.GLSBuffer, [4 x %struct.GLSBuffer*], %struct.GLSBuffer*, %struct.GLSBuffer*, %struct.GLSBuffer*, i8, i8 }
+ %struct.GLDClearColor = type { double, %struct.GLTColor4, %struct.GLTColor4, float, i32 }
+ %struct.GLDClipPlane = type { i32, [6 x %struct.GLTColor4] }
+ %struct.GLDColorBuffer = type { i16, i16, [4 x i16] }
+ %struct.GLDColorMatrix = type { [16 x float]*, %struct.GLDImagingColorScale }
+ %struct.GLDContextRec = type { float, float, float, float, float, float, float, float, %struct.GLTColor4, %struct.GLTColor4, %struct.GLVMFPContext, %struct.GLDTextureMachine, %struct.GLGProcessor, %struct._GLVMConstants*, void (%struct.GLDContextRec*, i32, i32, %struct.GLVMFragmentAttribRec*, %struct.GLVMFragmentAttribRec*, i32)*, %struct._GLVMFunction*, void (%struct.GLDContextRec*, %struct.GLDVertex*)*, void (%struct.GLDContextRec*, %struct.GLDVertex*, %struct.GLDVertex*)*, void (%struct.GLDContextRec*, %struct.GLDVertex*, %struct.GLDVertex*, %struct.GLDVertex*)*, %struct._GLVMFunction*, %struct._GLVMFunction*, %struct._GLVMFunction*, i32, i32, i32, float, float, float, i32, %struct.GLSDrawable, %struct.GLDFramebufferAttachment, %struct.GLDFormat, %struct.GLDBufferstate, %struct.GLDSharedRec*, %struct.GLDState*, %struct.GLDPluginState*, %struct.GLTDimensions, %struct.GLTColor4*, %struct.GLTColor4*, %struct.GLVMFragmentAttribRec*, %struct.GLVMFragmentAttribRec*, %struct.GLVMFragmentAttribRec*, %struct.GLDPipelineProgramRec*, %struct.GLDStateProgramRec, %struct.GLVMTextures, { [4 x i8*], i8*, i8* }, [64 x float], %struct.GLDStippleData, i16, i8, i8, i32, %struct.GLDFramebufferRec*, i8, %struct.GLDQueryRec*, %struct.GLDQueryRec* }
+ %struct.GLDConvolution = type { %struct.GLTColor4, %struct.GLDImagingColorScale, i16, i16, float*, i32, i32 }
+ %struct.GLDDepthTest = type { i16, i16, i8, i8, i8, i8, double, double }
+ %struct.GLDFogMode = type { %struct.GLTColor4, float, float, float, float, float, i16, i16, i16, i8, i8 }
+ %struct.GLDFormat = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, i32, i32 }
+ %struct.GLDFramebufferAttachment = type { i32, i32, i32, i32, i32, i32 }
+ %struct.GLDFramebufferData = type { [6 x %struct.GLDFramebufferAttachment], [4 x i16], i16, i16, i16, i16, i32 }
+ %struct.GLDFramebufferRec = type { %struct.GLDFramebufferData*, %struct.GLDPluginFramebufferData*, %struct.GLDPixelFormat }
+ %struct.GLDHintMode = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16 }
+ %struct.GLDHistogram = type { %struct.GLTFixedColor4*, i32, i16, i8, i8 }
+ %struct.GLDImagingColorScale = type { { float, float }, { float, float }, { float, float }, { float, float } }
+ %struct.GLDImagingSubset = type { %struct.GLDConvolution, %struct.GLDConvolution, %struct.GLDConvolution, %struct.GLDColorMatrix, %struct.GLDMinmax, %struct.GLDHistogram, %struct.GLDImagingColorScale, %struct.GLDImagingColorScale, %struct.GLDImagingColorScale, %struct.GLDImagingColorScale, i32 }
+ %struct.GLDLight = type { %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTCoord3, float, float, float, float, float, %struct.GLTCoord3, float, float, float, float, float }
+ %struct.GLDLightModel = type { %struct.GLTColor4, [8 x %struct.GLDLight], [2 x %struct.GLDMaterial], i32, i16, i16, i16, i8, i8, i8, i8, i8, i8 }
+ %struct.GLDLightProduct = type { %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4 }
+ %struct.GLDLineMode = type { float, i32, i16, i16, i8, i8, i8, i8 }
+ %struct.GLDLogicOp = type { i16, i8, i8 }
+ %struct.GLDMaskMode = type { i32, [3 x i32], i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.GLDMaterial = type { %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, float, float, float, float, [8 x %struct.GLDLightProduct], %struct.GLTColor4, [6 x i32], [2 x i32] }
+ %struct.GLDMinmax = type { %struct.GLDMinmaxTable*, i16, i8, i8 }
+ %struct.GLDMinmaxTable = type { %struct.GLTColor4, %struct.GLTColor4 }
+ %struct.GLDMipmaplevel = type { [4 x i32], [4 x float], [4 x i32], [4 x i32], [4 x float], [4 x i32], [3 x i32], i32, float*, float*, float*, i32, i32, i8*, i16, i16, i16, i16 }
+ %struct.GLDMultisample = type { float, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.GLDPipelineProgramData = type { i16, i16, i32, %struct._PPStreamToken*, i64, %struct.GLDShaderSourceData*, %struct.GLTColor4*, i32 }
+ %struct.GLDPipelineProgramRec = type { %struct.GLDPipelineProgramData*, %struct._PPStreamToken*, %struct._PPStreamToken*, %struct._GLVMFunction*, i32, i32, i32 }
+ %struct.GLDPipelineProgramState = type { i8, i8, i8, i8, %struct.GLTColor4* }
+ %struct.GLDPixelFormat = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.GLDPixelMap = type { i32*, float*, float*, float*, float*, float*, float*, float*, float*, i32*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
+ %struct.GLDPixelMode = type { float, float, %struct.GLDPixelStore, %struct.GLDPixelTransfer, %struct.GLDPixelMap, %struct.GLDImagingSubset, i32, i32 }
+ %struct.GLDPixelPack = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8 }
+ %struct.GLDPixelStore = type { %struct.GLDPixelPack, %struct.GLDPixelPack }
+ %struct.GLDPixelTransfer = type { float, float, float, float, float, float, float, float, float, float, i32, i32, float, float, float, float, float, float, float, float, float, float, float, float }
+ %struct.GLDPluginFramebufferData = type { [6 x %struct.GLDTextureRec*], i32, i32 }
+ %struct.GLDPluginProgramData = type { [3 x %struct.GLDPipelineProgramRec*], %struct.GLDBufferRec**, i32 }
+ %struct.GLDPluginState = type { [16 x [5 x %struct.GLDTextureRec*]], [3 x %struct.GLDTextureRec*], [16 x %struct.GLDTextureRec*], [3 x %struct.GLDPipelineProgramRec*], %struct.GLDProgramRec*, %struct.GLDVertexArrayRec*, [16 x %struct.GLDBufferRec*], %struct.GLDFramebufferRec*, %struct.GLDFramebufferRec* }
+ %struct.GLDPointMode = type { float, float, float, float, %struct.GLTCoord3, float, i8, i8, i8, i8, i16, i16, i32, i16, i16 }
+ %struct.GLDPolygonMode = type { [128 x i8], float, float, i16, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8 }
+ %struct.GLDProgramData = type { i32, [16 x i32], i32, i32, i32, i32 }
+ %struct.GLDProgramRec = type { %struct.GLDProgramData*, %struct.GLDPluginProgramData*, i32 }
+ %struct.GLDQueryRec = type { i32, i32, %struct.GLDQueryRec* }
+ %struct.GLDRect = type { i32, i32, i32, i32, i32, i32 }
+ %struct.GLDRegisterCombiners = type { i8, i8, i8, i8, i32, [2 x %struct.GLTColor4], [8 x %struct.GLDRegisterCombinersPerStageState], %struct.GLDRegisterCombinersFinalStageState }
+ %struct.GLDRegisterCombinersFinalStageState = type { i8, i8, i8, i8, [7 x %struct.GLDRegisterCombinersPerVariableState] }
+ %struct.GLDRegisterCombinersPerPortionState = type { [4 x %struct.GLDRegisterCombinersPerVariableState], i8, i8, i8, i8, i16, i16, i16, i16, i16, i16 }
+ %struct.GLDRegisterCombinersPerStageState = type { [2 x %struct.GLDRegisterCombinersPerPortionState], [2 x %struct.GLTColor4] }
+ %struct.GLDRegisterCombinersPerVariableState = type { i16, i16, i16, i16 }
+ %struct.GLDScissorTest = type { %struct.GLTFixedColor4, i8, i8, i8, i8 }
+ %struct.GLDShaderSourceData = type { i32, i32, i8*, i32*, i32, i32, i8*, i32*, i8* }
+ %struct.GLDSharedRec = type opaque
+ %struct.GLDState = type { i16, i16, i32, i32, i32, [256 x %struct.GLTColor4], [128 x %struct.GLTColor4], %struct.GLDViewport, %struct.GLDTransform, %struct.GLDLightModel, i32*, i32, i32, i32, %struct.GLDAlphaTest, %struct.GLDBlendMode, %struct.GLDClearColor, %struct.GLDColorBuffer, %struct.GLDDepthTest, %struct.GLDArrayRange, %struct.GLDFogMode, %struct.GLDHintMode, %struct.GLDLineMode, %struct.GLDLogicOp, %struct.GLDMaskMode, %struct.GLDPixelMode, %struct.GLDPointMode, %struct.GLDPolygonMode, %struct.GLDScissorTest, i32, %struct.GLDStencilTest, [16 x %struct.GLDTextureMode], %struct.GLDArrayRange, [8 x %struct.GLDTextureCoordGen], %struct.GLDClipPlane, %struct.GLDMultisample, %struct.GLDRegisterCombiners, %struct.GLDArrayRange, %struct.GLDArrayRange, [3 x %struct.GLDPipelineProgramState], %struct.GLDTransformFeedback }
+ %struct.GLDStateProgramRec = type { %struct.GLDPipelineProgramData*, %struct.GLDPipelineProgramRec* }
+ %struct.GLDStencilTest = type { [3 x { i32, i32, i16, i16, i16, i16 }], i32, [4 x i8] }
+ %struct.GLDStippleData = type { i32, i16, i16, [32 x [32 x i8]] }
+ %struct.GLDTextureCoordGen = type { { i16, i16, %struct.GLTColor4, %struct.GLTColor4 }, { i16, i16, %struct.GLTColor4, %struct.GLTColor4 }, { i16, i16, %struct.GLTColor4, %struct.GLTColor4 }, { i16, i16, %struct.GLTColor4, %struct.GLTColor4 }, i8, i8, i8, i8 }
+ %struct.GLDTextureGeomState = type { i16, i16, i16, i16, i16, i8, i8, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, [6 x i16], [6 x i16] }
+ %struct.GLDTextureLevel = type { i32, i32, i16, i16, i16, i8, i8, i16, i16, i16, i16, i8* }
+ %struct.GLDTextureMachine = type { [8 x %struct.GLDTextureRec*], %struct.GLDTextureRec*, i8, i8, i8, i8 }
+ %struct.GLDTextureMode = type { %struct.GLTColor4, i32, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, float, float, float, i16, i16, i16, i16, i16, i16, [4 x i16], i8, i8, i8, i8, [3 x float], [4 x float], float, float }
+ %struct.GLDTextureParamState = type { i16, i16, i16, i16, i16, i16, %struct.GLTColor4, float, float, float, float, i16, i16, i16, i16, float, i16, i8, i8, i32, i8* }
+ %struct.GLDTextureRec = type { %struct.GLDTextureState*, i32, [2 x float], float, i32, float, float, float, float, float, float, %struct.GLDMipmaplevel*, %struct.GLDMipmaplevel*, i32, i32, i32, i32, i32, i32, %struct.GLDTextureParamState, i32, [2 x %struct._PPStreamToken] }
+ %struct.GLDTextureState = type { i16, i16, i16, float, i32, i16, %struct.GLISWRSurface*, i8, i8, i8, i8, %struct.GLDTextureParamState, %struct.GLDTextureGeomState, %struct.GLDTextureLevel, [6 x [15 x %struct.GLDTextureLevel]] }
+ %struct.GLDTransform = type { [24 x [16 x float]], [24 x [16 x float]], [16 x float], float, float, float, float, i32, float, i16, i16, i8, i8, i8, i8 }
+ %struct.GLDTransformFeedback = type { i8, i8, i8, [16 x i32], [16 x i32] }
+ %struct.GLDVertex = type { %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTColor4, %struct.GLTCoord3, float, %struct.GLTColor4, float, float, float, i8, i8, i8, i8, [4 x float], [2 x %struct.GLDMaterial*], i32, i32, [8 x %struct.GLTColor4] }
+ %struct.GLDVertexArrayRec = type opaque
+ %struct.GLDViewport = type { float, float, float, float, float, float, float, float, double, double, i32, i32, i32, i32, float, float, float, float }
+ %struct.GLGColorTable = type { i32, i32, i32, i8* }
+ %struct.GLGOperation = type { i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, float, %struct.GLGColorTable, %struct.GLGColorTable, %struct.GLGColorTable }
+ %struct.GLGProcessor = type { void (%struct.GLDPixelMode*, %struct.GLGOperation*, %struct._GLGFunctionKey*)*, %struct._GLVMFunction*, %struct._GLGFunctionKey* }
+ %struct.GLISWRSurface = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i8*, [4 x i8*], i32 }
+ %struct.GLIWindow = type { i32, i32, i32 }
+ %struct.GLSBuffer = type { i8* }
+ %struct.GLSDrawable = type { %struct.GLSWindowRec* }
+ %struct.GLSWindowRec = type { %struct.GLTDimensions, %struct.GLTDimensions, i32, i32, %struct.GLSDrawable, [2 x i8*], i8*, i8*, i8*, [4 x i8*], i32, i32, i32, i32, [4 x i32], i16, i16, i16, %struct.GLIWindow, i32, i32, i8*, i8* }
+ %struct.GLTColor4 = type { float, float, float, float }
+ %struct.GLTCoord3 = type { float, float, float }
+ %struct.GLTDimensions = type { i32, i32 }
+ %struct.GLTFixedColor4 = type { i32, i32, i32, i32 }
+ %struct.GLVMFPContext = type { float, i32, i32, i32 }
+ %struct.GLVMFragmentAttribRec = type { <4 x float>, <4 x float>, <4 x float>, <4 x float>, [8 x <4 x float>] }
+ %struct.GLVMTextures = type { [8 x %struct.GLDTextureRec*] }
+ %struct._GLGFunctionKey = type opaque
+ %struct._GLVMConstants = type opaque
+ %struct._GLVMFunction = type opaque
+ %struct._PPStreamToken = type { { i16, i8, i8, i32 } }
+
+define void @gldLLVMVecPointRender(%struct.GLDContextRec* %ctx) {
+entry:
+ %tmp.uip = getelementptr %struct.GLDContextRec* %ctx, i32 0, i32 22 ; <i32*> [#uses=1]
+ %tmp = load i32* %tmp.uip ; <i32> [#uses=3]
+ %tmp91 = lshr i32 %tmp, 5 ; <i32> [#uses=1]
+ %tmp92 = trunc i32 %tmp91 to i1 ; <i1> [#uses=1]
+ br i1 %tmp92, label %cond_true93, label %cond_next116
+cond_true93: ; preds = %entry
+ %tmp.upgrd.1 = getelementptr %struct.GLDContextRec* %ctx, i32 0, i32 31, i32 14 ; <i32*> [#uses=1]
+ %tmp95 = load i32* %tmp.upgrd.1 ; <i32> [#uses=1]
+ %tmp95.upgrd.2 = sitofp i32 %tmp95 to float ; <float> [#uses=1]
+ %tmp108 = fmul float undef, %tmp95.upgrd.2 ; <float> [#uses=1]
+ br label %cond_next116
+cond_next116: ; preds = %cond_true93, %entry
+ %point_size.2 = phi float [ %tmp108, %cond_true93 ], [ undef, %entry ] ; <float> [#uses=2]
+ %tmp457 = fcmp olt float %point_size.2, 1.000000e+00 ; <i1> [#uses=1]
+ %tmp460 = lshr i32 %tmp, 6 ; <i32> [#uses=1]
+ %tmp461 = trunc i32 %tmp460 to i1 ; <i1> [#uses=1]
+ br i1 %tmp457, label %cond_true458, label %cond_next484
+cond_true458: ; preds = %cond_next116
+ br i1 %tmp461, label %cond_true462, label %cond_next487
+cond_true462: ; preds = %cond_true458
+ %tmp26 = bitcast i32 %tmp to i32 ; <i32> [#uses=1]
+ %tmp465 = and i32 %tmp26, 128 ; <i32> [#uses=1]
+ %tmp466 = icmp eq i32 %tmp465, 0 ; <i1> [#uses=1]
+ br i1 %tmp466, label %cond_true467, label %cond_next487
+cond_true467: ; preds = %cond_true462
+ ret void
+cond_next484: ; preds = %cond_next116
+ %tmp486 = fmul float %point_size.2, 5.000000e-01 ; <float> [#uses=1]
+ br label %cond_next487
+cond_next487: ; preds = %cond_next484, %cond_true462, %cond_true458
+ %radius.0 = phi float [ %tmp486, %cond_next484 ], [ 5.000000e-01, %cond_true458 ], [ 5.000000e-01, %cond_true462 ] ; <float> [#uses=2]
+ %tmp494 = insertelement <4 x float> zeroinitializer, float %radius.0, i32 2 ; <<4 x float>> [#uses=1]
+ %tmp495 = insertelement <4 x float> %tmp494, float %radius.0, i32 3 ; <<4 x float>> [#uses=0]
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SCCP/2006-12-19-UndefBug.ll b/src/LLVM/test/Transforms/SCCP/2006-12-19-UndefBug.ll
new file mode 100644
index 0000000..0648bb7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2006-12-19-UndefBug.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -sccp -S | \
+; RUN: grep {ret i1 false}
+
+define i1 @foo() {
+ %X = and i1 false, undef ; <i1> [#uses=1]
+ ret i1 %X
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/2007-05-16-InvokeCrash.ll b/src/LLVM/test/Transforms/SCCP/2007-05-16-InvokeCrash.ll
new file mode 100644
index 0000000..280c548
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2007-05-16-InvokeCrash.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -sccp -disable-output
+; PR1431
+
+define void @_ada_bench() {
+entry:
+ br label %cond_next
+cond_next: ; preds = %cond_next, %entry
+ %indvar46 = phi i32 [ 0, %entry ], [ %indvar.next47, %cond_next ] ; <i32> [#uses=1]
+ %indvar.next47 = add i32 %indvar46, 1 ; <i32> [#uses=2]
+ %exitcond48 = icmp eq i32 %indvar.next47, 10000 ; <i1> [#uses=1]
+ br i1 %exitcond48, label %cond_next40, label %cond_next
+cond_next40: ; preds = %cond_next40, %cond_next
+ %indvar43 = phi i32 [ %indvar.next44, %cond_next40 ], [ 0, %cond_next ] ; <i32> [#uses=1]
+ %indvar.next44 = add i32 %indvar43, 1 ; <i32> [#uses=2]
+ %exitcond45 = icmp eq i32 %indvar.next44, 10000 ; <i1> [#uses=1]
+ br i1 %exitcond45, label %cond_next53, label %cond_next40
+cond_next53: ; preds = %cond_next53, %cond_next40
+ %indvar41 = phi i32 [ %indvar.next42, %cond_next53 ], [ 0, %cond_next40 ] ; <i32> [#uses=1]
+ %indvar.next42 = add i32 %indvar41, 1 ; <i32> [#uses=2]
+ %exitcond = icmp eq i32 %indvar.next42, 10000 ; <i1> [#uses=1]
+ br i1 %exitcond, label %bb67, label %cond_next53
+bb67: ; preds = %cond_next53
+ %tmp112 = invoke double @sin( double 5.000000e-01 )
+ to label %bb114 unwind label %cleanup ; <double> [#uses=0]
+bb114: ; preds = %bb67
+ %tmp147 = invoke double @log( double 5.000000e-01 )
+ to label %bb149 unwind label %cleanup ; <double> [#uses=0]
+bb149: ; preds = %bb114
+ %tmp175 = invoke double @sqrt( double 5.000000e-01 )
+ to label %bb177 unwind label %cleanup ; <double> [#uses=0]
+bb177: ; preds = %bb149
+ unreachable
+cleanup: ; preds = %bb149, %bb114, %bb67
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ resume { i8*, i32 } %val
+}
+
+declare double @sin(double)
+
+declare double @log(double)
+
+declare double @sqrt(double)
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SCCP/2008-01-27-UndefCorrelate.ll b/src/LLVM/test/Transforms/SCCP/2008-01-27-UndefCorrelate.ll
new file mode 100644
index 0000000..aa613dc
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2008-01-27-UndefCorrelate.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -sccp -S | grep undef | count 1
+; PR1938
+
+define i32 @main() {
+entry:
+ br label %bb
+
+bb:
+ %indvar = phi i32 [ 0, %entry ], [ %k, %bb.backedge ]
+ %k = add i32 %indvar, 1
+ br i1 undef, label %cond_true, label %cond_false
+
+cond_true:
+ %tmp97 = icmp slt i32 %k, 10
+ br i1 %tmp97, label %bb.backedge, label %bb12
+
+bb.backedge:
+ br label %bb
+
+cond_false:
+ %tmp9 = icmp slt i32 %k, 10
+ br i1 %tmp9, label %bb.backedge, label %bb12
+
+bb12:
+ %tmp14 = icmp eq i32 %k, 10
+ br i1 %tmp14, label %cond_next18, label %cond_true17
+
+cond_true17:
+ tail call void @abort( )
+ unreachable
+
+cond_next18:
+ ret i32 0
+}
+
+declare void @abort()
diff --git a/src/LLVM/test/Transforms/SCCP/2008-04-22-multiple-ret-sccp.ll b/src/LLVM/test/Transforms/SCCP/2008-04-22-multiple-ret-sccp.ll
new file mode 100644
index 0000000..a40455c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2008-04-22-multiple-ret-sccp.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -sccp -S | grep {ret i32 %Z}
+; rdar://5778210
+
+declare {i32, i32} @bar(i32 %A)
+
+define i32 @foo() {
+ %X = call {i32, i32} @bar(i32 17)
+ %Y = extractvalue {i32, i32} %X, 0
+ %Z = add i32 %Y, %Y
+ ret i32 %Z
+}
diff --git a/src/LLVM/test/Transforms/SCCP/2008-05-23-UndefCallFold.ll b/src/LLVM/test/Transforms/SCCP/2008-05-23-UndefCallFold.ll
new file mode 100644
index 0000000..cd6cf97
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2008-05-23-UndefCallFold.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -sccp -S | not grep {ret i32 undef}
+; PR2358
+target datalayout =
+"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-pc-linux-gnu"
+
+define i32 @x(i32 %b) {
+entry:
+ %val = call i32 @llvm.cttz.i32(i32 undef)
+ ret i32 %val
+}
+
+declare i32 @llvm.cttz.i32(i32)
+
diff --git a/src/LLVM/test/Transforms/SCCP/2009-01-14-IPSCCP-Invoke.ll b/src/LLVM/test/Transforms/SCCP/2009-01-14-IPSCCP-Invoke.ll
new file mode 100644
index 0000000..7546bf5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2009-01-14-IPSCCP-Invoke.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -ipsccp -S | grep {ret i32 42}
+; RUN: opt < %s -ipsccp -S | grep {ret i32 undef}
+; PR3325
+
+define i32 @main() {
+ %tmp1 = invoke i32 @f()
+ to label %UnifiedReturnBlock unwind label %lpad
+
+lpad:
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ unreachable
+
+UnifiedReturnBlock:
+ ret i32 %tmp1
+}
+
+define internal i32 @f() {
+ ret i32 42
+}
+
+declare i8* @__cxa_begin_catch(i8*) nounwind
+
+declare i8* @llvm.eh.exception() nounwind
+
+declare i32 @llvm.eh.selector.i32(i8*, i8*, ...) nounwind
+
+declare void @__cxa_end_catch()
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SCCP/2009-05-27-VectorOperandZero.ll b/src/LLVM/test/Transforms/SCCP/2009-05-27-VectorOperandZero.ll
new file mode 100644
index 0000000..7aced66
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/2009-05-27-VectorOperandZero.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -sccp -disable-output
+; PR4277
+
+define i32 @main() nounwind {
+entry:
+ %0 = tail call signext i8 (...)* @sin() nounwind
+ ret i32 0
+}
+
+declare signext i8 @sin(...)
diff --git a/src/LLVM/test/Transforms/SCCP/apint-array.ll b/src/LLVM/test/Transforms/SCCP/apint-array.ll
new file mode 100644
index 0000000..90af939
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-array.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -sccp -S | grep {ret i101 12}
+
+@Y = constant [6 x i101] [ i101 12, i101 123456789000000, i101 -12,i101
+-123456789000000, i101 0,i101 9123456789000000]
+
+define i101 @array()
+{
+Head:
+ %A = getelementptr [6 x i101]* @Y, i32 0, i32 1
+
+ %B = load i101* %A
+ %C = icmp sge i101 %B, 1
+ br i1 %C, label %True, label %False
+True:
+ %D = and i101 %B, 1
+ %E = trunc i101 %D to i32
+ %F = getelementptr [6 x i101]* @Y, i32 0, i32 %E
+ %G = load i101* %F
+ br label %False
+False:
+ %H = phi i101 [%G, %True], [-1, %Head]
+ ret i101 %H
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-basictest.ll b/src/LLVM/test/Transforms/SCCP/apint-basictest.ll
new file mode 100644
index 0000000..8514c0b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-basictest.ll
@@ -0,0 +1,16 @@
+; This is a basic sanity check for constant propagation. The add instruction
+; should be eliminated.
+
+; RUN: opt < %s -sccp -S | not grep add
+
+define i128 @test(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1:
+ %Val = add i128 0, 1
+ br label %BB3
+BB2:
+ br label %BB3
+BB3:
+ %Ret = phi i128 [%Val, %BB1], [2, %BB2]
+ ret i128 %Ret
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-basictest2.ll b/src/LLVM/test/Transforms/SCCP/apint-basictest2.ll
new file mode 100644
index 0000000..591b670
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-basictest2.ll
@@ -0,0 +1,17 @@
+; This is a basic sanity check for constant propagation. The add instruction
+; and phi instruction should be eliminated.
+
+; RUN: opt < %s -sccp -S | not grep phi
+; RUN: opt < %s -sccp -S | not grep add
+
+define i128 @test(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1:
+ %Val = add i128 0, 1
+ br label %BB3
+BB2:
+ br label %BB3
+BB3:
+ %Ret = phi i128 [%Val, %BB1], [1, %BB2]
+ ret i128 %Ret
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-basictest3.ll b/src/LLVM/test/Transforms/SCCP/apint-basictest3.ll
new file mode 100644
index 0000000..011c595
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-basictest3.ll
@@ -0,0 +1,23 @@
+; This is a basic sanity check for constant propagation. It tests the basic
+; arithmatic operations.
+
+
+; RUN: opt < %s -sccp -S | not grep mul
+; RUN: opt < %s -sccp -S | not grep umod
+
+define i128 @test(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1:
+ %t1 = add i128 0, 1
+ %t2 = sub i128 0, %t1
+ %t3 = mul i128 %t2, -1
+ br label %BB3
+BB2:
+ %f1 = udiv i128 -1, 1
+ %f2 = add i128 %f1, 1
+ %f3 = urem i128 %f2, 2121
+ br label %BB3
+BB3:
+ %Ret = phi i128 [%t3, %BB1], [%f3, %BB2]
+ ret i128 %Ret
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-basictest4.ll b/src/LLVM/test/Transforms/SCCP/apint-basictest4.ll
new file mode 100644
index 0000000..9de3219
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-basictest4.ll
@@ -0,0 +1,25 @@
+; This is a basic sanity check for constant propagation. It tests the basic
+; logic operations.
+
+
+; RUN: opt < %s -sccp -S | not grep and
+; RUN: opt < %s -sccp -S | not grep trunc
+; RUN: opt < %s -sccp -S | grep {ret i100 -1}
+
+define i100 @test(i133 %A) {
+ %B = and i133 0, %A
+ %C = icmp sgt i133 %B, 0
+ br i1 %C, label %BB1, label %BB2
+BB1:
+ %t3 = xor i133 %B, -1
+ %t4 = trunc i133 %t3 to i100
+ br label %BB3
+BB2:
+ %f1 = or i133 -1, %A
+ %f2 = lshr i133 %f1, 33
+ %f3 = trunc i133 %f2 to i100
+ br label %BB3
+BB3:
+ %Ret = phi i100 [%t4, %BB1], [%f3, %BB2]
+ ret i100 %Ret
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-bigarray.ll b/src/LLVM/test/Transforms/SCCP/apint-bigarray.ll
new file mode 100644
index 0000000..f61abfc
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-bigarray.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -sccp -S | not grep %X
+
+@G = global [1000000 x i10000] zeroinitializer
+
+define internal i10000* @test(i10000 %Arg) {
+ %X = getelementptr [1000000 x i10000]* @G, i32 0, i32 999
+ store i10000 %Arg, i10000* %X
+ ret i10000* %X
+}
+
+define i10000 @caller()
+{
+ %Y = call i10000* @test(i10000 -1)
+ %Z = load i10000* %Y
+ ret i10000 %Z
+}
+
+define i10000 @caller2()
+{
+ %Y = call i10000* @test(i10000 1)
+ %Z = load i10000* %Y
+ ret i10000 %Z
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-bigint.ll b/src/LLVM/test/Transforms/SCCP/apint-bigint.ll
new file mode 100644
index 0000000..394ec49
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-bigint.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -sccp -S | not grep xor
+
+define i11129 @test1() {
+ %B = shl i11129 1, 11128
+ %C = sub i11129 %B, 1
+ %D = xor i11129 %B, %C
+
+ ret i11129 %D
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-bigint2.ll b/src/LLVM/test/Transforms/SCCP/apint-bigint2.ll
new file mode 100644
index 0000000..1ada65d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-bigint2.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -sccp -S | not grep load
+
+@Y = constant [6 x i101] [ i101 12, i101 123456789000000, i101 -12,
+ i101 -123456789000000, i101 0,i101 9123456789000000]
+
+define i101 @array()
+{
+Head:
+ %A = getelementptr [6 x i101]* @Y, i32 0, i32 1
+ %B = load i101* %A
+ %D = and i101 %B, 1
+ %DD = or i101 %D, 1
+ %E = trunc i101 %DD to i32
+ %F = getelementptr [6 x i101]* @Y, i32 0, i32 %E
+ %G = load i101* %F
+
+ ret i101 %G
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-ipsccp1.ll b/src/LLVM/test/Transforms/SCCP/apint-ipsccp1.ll
new file mode 100644
index 0000000..f14f488
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-ipsccp1.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -ipsccp -S | grep -v {ret i512 undef} | \
+; RUN: grep {ret i8 2}
+
+define internal i512 @test(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1:
+ %Val = add i512 0, 1
+ br label %BB3
+BB2:
+ br label %BB3
+BB3:
+ %Ret = phi i512 [%Val, %BB1], [2, %BB2]
+ ret i512 %Ret
+}
+
+define i8 @caller()
+{
+ %t1 = and i2 2, 1
+ %t11 = trunc i2 %t1 to i1
+ %t2 = call i512 @test(i1 %t11)
+ %t3 = trunc i512 %t2 to i8
+ ret i8 %t3
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/apint-ipsccp2.ll b/src/LLVM/test/Transforms/SCCP/apint-ipsccp2.ll
new file mode 100644
index 0000000..1a4fff5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-ipsccp2.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -ipsccp -S | grep -v {ret i101 0} | \
+; RUN: grep -v {ret i101 undef} | not grep ret
+
+
+define internal i101 @bar(i101 %A) {
+ %x = icmp eq i101 %A, 0
+ br i1 %x, label %T, label %F
+T:
+ %B = call i101 @bar(i101 0)
+ ret i101 0
+F: ; unreachable
+ %C = call i101 @bar(i101 1)
+ ret i101 %C
+}
+
+define i101 @foo() {
+ %X = call i101 @bar(i101 0)
+ ret i101 %X
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-ipsccp3.ll b/src/LLVM/test/Transforms/SCCP/apint-ipsccp3.ll
new file mode 100644
index 0000000..ef0f4fd
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-ipsccp3.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -ipsccp -S | not grep global
+
+@G = internal global i66 undef
+
+
+
+define void @foo() {
+ %X = load i66* @G
+ store i66 %X, i66* @G
+ ret void
+}
+
+define i66 @bar() {
+ %V = load i66* @G
+ %C = icmp eq i66 %V, 17
+ br i1 %C, label %T, label %F
+T:
+ store i66 17, i66* @G
+ ret i66 %V
+F:
+ store i66 123, i66* @G
+ ret i66 0
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-ipsccp4.ll b/src/LLVM/test/Transforms/SCCP/apint-ipsccp4.ll
new file mode 100644
index 0000000..bc8618f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-ipsccp4.ll
@@ -0,0 +1,49 @@
+; This test makes sure that these instructions are properly constant propagated.
+
+; RUN: opt < %s -ipsccp -S | not grep load
+; RUN: opt < %s -ipsccp -S | not grep add
+; RUN: opt < %s -ipsccp -S | not grep phi
+
+
+@Y = constant [2 x { i212, float }] [ { i212, float } { i212 12, float 1.0 },
+ { i212, float } { i212 37, float 2.0 } ]
+
+define internal float @test2() {
+ %A = getelementptr [2 x { i212, float}]* @Y, i32 0, i32 1, i32 1
+ %B = load float* %A
+ ret float %B
+}
+
+define internal float @test3() {
+ %A = getelementptr [2 x { i212, float}]* @Y, i32 0, i32 0, i32 1
+ %B = load float* %A
+ ret float %B
+}
+
+define internal float @test()
+{
+ %A = call float @test2()
+ %B = call float @test3()
+
+ %E = fdiv float %B, %A
+ ret float %E
+}
+
+define float @All()
+{
+ %A = call float @test()
+ %B = fcmp oge float %A, 1.0
+ br i1 %B, label %T, label %F
+T:
+ %C = fadd float %A, 1.0
+ br label %exit
+F:
+ %D = fadd float %A, 2.0
+ br label %exit
+exit:
+ %E = phi float [%C, %T], [%D, %F]
+ ret float %E
+}
+
+
+
diff --git a/src/LLVM/test/Transforms/SCCP/apint-load.ll b/src/LLVM/test/Transforms/SCCP/apint-load.ll
new file mode 100644
index 0000000..662bf27
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-load.ll
@@ -0,0 +1,36 @@
+; This test makes sure that these instructions are properly constant propagated.
+
+; RUN: opt < %s -ipsccp -S | not grep load
+; RUN: opt < %s -ipsccp -S | not grep fdiv
+
+@X = constant i212 42
+@Y = constant [2 x { i212, float }] [ { i212, float } { i212 12, float 1.0 },
+ { i212, float } { i212 37, float 0x3FF3B2FEC0000000 } ]
+define i212 @test1() {
+ %B = load i212* @X
+ ret i212 %B
+}
+
+define internal float @test2() {
+ %A = getelementptr [2 x { i212, float}]* @Y, i32 0, i32 1, i32 1
+ %B = load float* %A
+ ret float %B
+}
+
+define internal i212 @test3() {
+ %A = getelementptr [2 x { i212, float}]* @Y, i32 0, i32 0, i32 0
+ %B = load i212* %A
+ ret i212 %B
+}
+
+define float @All()
+{
+ %A = call float @test2()
+ %B = call i212 @test3()
+ %C = mul i212 %B, -1234567
+ %D = sitofp i212 %C to float
+ %E = fdiv float %A, %D
+ ret float %E
+}
+
+
diff --git a/src/LLVM/test/Transforms/SCCP/apint-phi.ll b/src/LLVM/test/Transforms/SCCP/apint-phi.ll
new file mode 100644
index 0000000..56f1610
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-phi.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -sccp -S | not grep phi
+
+define i999 @test(i999%A, i1 %c) {
+bb1:
+ br label %BB2
+BB2:
+ %V = phi i999 [2, %bb1], [%A, %BB4]
+ br label %BB3
+
+BB3:
+ %E = trunc i999 %V to i1
+ %F = and i1 %E, %c
+ br i1 %F, label %BB4, label %BB5
+BB4:
+ br label %BB2
+
+BB5:
+ ret i999 %V
+}
diff --git a/src/LLVM/test/Transforms/SCCP/apint-select.ll b/src/LLVM/test/Transforms/SCCP/apint-select.ll
new file mode 100644
index 0000000..9597c22
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/apint-select.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -sccp -S | not grep select
+
+@A = constant i32 10
+
+define i712 @test1() {
+ %P = getelementptr i32* @A, i32 0
+ %B = ptrtoint i32* %P to i64
+ %BB = and i64 %B, undef
+ %C = icmp sge i64 %BB, 0
+ %X = select i1 %C, i712 0, i712 1
+ ret i712 %X
+}
+
+
+
+define i712 @test2(i1 %C) {
+ %X = select i1 %C, i712 0, i712 undef
+ ret i712 %X
+}
+
+
diff --git a/src/LLVM/test/Transforms/SCCP/atomic-load-store.ll b/src/LLVM/test/Transforms/SCCP/atomic-load-store.ll
new file mode 100644
index 0000000..09061f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/atomic-load-store.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -ipsccp -S | FileCheck %s
+
+; This transformation is safe for atomic loads and stores; check that it works.
+
+@G = internal global i32 17
+@C = internal constant i32 222
+
+define i32 @test1() {
+ %V = load atomic i32* @G seq_cst, align 4
+ %C = icmp eq i32 %V, 17
+ br i1 %C, label %T, label %F
+T:
+ store atomic i32 17, i32* @G seq_cst, align 4
+ ret i32 %V
+F:
+ store atomic i32 123, i32* @G seq_cst, align 4
+ ret i32 0
+}
+; CHECK: define i32 @test1
+; CHECK-NOT: store
+; CHECK: ret i32 17
+
+define i32 @test2() {
+ %V = load atomic i32* @C seq_cst, align 4
+ ret i32 %V
+}
+
+; CHECK: define i32 @test2
+; CHECK-NOT: load
+; CHECK: ret i32 222
diff --git a/src/LLVM/test/Transforms/SCCP/calltest.ll b/src/LLVM/test/Transforms/SCCP/calltest.ll
new file mode 100644
index 0000000..dcadc9a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/calltest.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | not grep br
+
+; No matter how hard you try, sqrt(1.0) is always 1.0. This allows the
+; optimizer to delete this loop.
+
+declare double @sqrt(double)
+
+define double @test(i32 %param) {
+entry:
+ br label %Loop
+Loop: ; preds = %Loop, %entry
+ %I2 = phi i32 [ 0, %entry ], [ %I3, %Loop ] ; <i32> [#uses=1]
+ %V = phi double [ 1.000000e+00, %entry ], [ %V2, %Loop ] ; <double> [#uses=2]
+ %V2 = call double @sqrt( double %V ) ; <double> [#uses=1]
+ %I3 = add i32 %I2, 1 ; <i32> [#uses=2]
+ %tmp.7 = icmp ne i32 %I3, %param ; <i1> [#uses=1]
+ br i1 %tmp.7, label %Loop, label %Exit
+Exit: ; preds = %Loop
+ ret double %V
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/crash.ll b/src/LLVM/test/Transforms/SCCP/crash.ll
new file mode 100644
index 0000000..2f6da1d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/crash.ll
@@ -0,0 +1,29 @@
+; RUN: opt %s -sccp -S
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+
+define void @test1(i8 %arg) {
+entry:
+ br i1 undef, label %return, label %bb
+
+bb:
+ br label %bb34
+
+bb23:
+ %c = icmp eq i8 %arg, undef
+ br i1 %c, label %bb34, label %bb23
+
+bb34:
+ %Kind.1 = phi i32 [ undef, %bb ], [ %ins174, %bb23 ]
+ %mask173 = or i32 %Kind.1, 7
+ %ins174 = and i32 %mask173, -249
+ br label %bb23
+
+return:
+ ret void
+}
+
+define i32 @test2([4 x i32] %A) {
+ %B = extractvalue [4 x i32] %A, 1
+ ret i32 %B
+}
diff --git a/src/LLVM/test/Transforms/SCCP/dg.exp b/src/LLVM/test/Transforms/SCCP/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/SCCP/ipsccp-addr-taken.ll b/src/LLVM/test/Transforms/SCCP/ipsccp-addr-taken.ll
new file mode 100644
index 0000000..c6572fa
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/ipsccp-addr-taken.ll
@@ -0,0 +1,28 @@
+; RUN: opt %s -ipsccp -S | FileCheck %s
+; PR7876
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define internal i32 @foo() nounwind noinline ssp {
+entry:
+ ret i32 0
+; CHECK: @foo
+; CHECK: entry:
+; CHECK: ret i32 0
+}
+
+declare i32 @bar()
+
+define internal i32 @test(i32 %c) nounwind noinline ssp {
+bb:
+ %tmp1 = icmp ne i32 %c, 0 ; <i1> [#uses=1]
+ %tmp2 = select i1 %tmp1, i32 ()* @foo, i32 ()* @bar ; <i32 ()*> [#uses=1]
+ %tmp3 = tail call i32 %tmp2() nounwind ; <i32> [#uses=1]
+ ret i32 %tmp3
+}
+
+define i32 @main() nounwind ssp {
+bb:
+ %tmp = tail call i32 @test(i32 1) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/SCCP/ipsccp-basic.ll b/src/LLVM/test/Transforms/SCCP/ipsccp-basic.ll
new file mode 100644
index 0000000..4ae2032
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/ipsccp-basic.ll
@@ -0,0 +1,229 @@
+; RUN: opt < %s -ipsccp -S | FileCheck %s
+
+;;======================== test1
+
+define internal i32 @test1a(i32 %A) {
+ %X = add i32 1, 2
+ ret i32 %A
+}
+; CHECK: define internal i32 @test1a
+; CHECK: ret i32 undef
+
+define i32 @test1b() {
+ %X = call i32 @test1a( i32 17 )
+ ret i32 %X
+
+; CHECK: define i32 @test1b
+; CHECK: ret i32 17
+}
+
+
+
+;;======================== test2
+
+define internal i32 @test2a(i32 %A) {
+ %C = icmp eq i32 %A, 0
+ br i1 %C, label %T, label %F
+T:
+ %B = call i32 @test2a( i32 0 )
+ ret i32 0
+F:
+ %C.upgrd.1 = call i32 @test2a(i32 1)
+ ret i32 %C.upgrd.1
+}
+; CHECK: define internal i32 @test2a
+; CHECK-NEXT: br label %T
+; CHECK: ret i32 undef
+
+
+define i32 @test2b() {
+ %X = call i32 @test2a(i32 0)
+ ret i32 %X
+}
+; CHECK: define i32 @test2b
+; CHECK-NEXT: %X = call i32 @test2a(i32 0)
+; CHECK-NEXT: ret i32 0
+
+
+;;======================== test3
+
+@G = internal global i32 undef
+
+define void @test3a() {
+ %X = load i32* @G
+ store i32 %X, i32* @G
+ ret void
+}
+; CHECK: define void @test3a
+; CHECK-NEXT: ret void
+
+
+define i32 @test3b() {
+ %V = load i32* @G
+ %C = icmp eq i32 %V, 17
+ br i1 %C, label %T, label %F
+T:
+ store i32 17, i32* @G
+ ret i32 %V
+F:
+ store i32 123, i32* @G
+ ret i32 0
+}
+; CHECK: define i32 @test3b
+; CHECK-NOT: store
+; CHECK: ret i32 0
+
+
+;;======================== test4
+
+define internal {i64,i64} @test4a() {
+ %a = insertvalue {i64,i64} undef, i64 4, 1
+ %b = insertvalue {i64,i64} %a, i64 5, 0
+ ret {i64,i64} %b
+}
+
+define i64 @test4b() {
+ %a = invoke {i64,i64} @test4a()
+ to label %A unwind label %B
+A:
+ %b = extractvalue {i64,i64} %a, 0
+ %c = call i64 @test4c(i64 %b)
+ ret i64 %c
+B:
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ ret i64 0
+}
+; CHECK: define i64 @test4b()
+; CHECK: %c = call i64 @test4c(i64 5)
+; CHECK-NEXT: ret i64 5
+
+
+define internal i64 @test4c(i64 %a) {
+ ret i64 %a
+}
+; CHECK: define internal i64 @test4c
+; CHECK: ret i64 undef
+
+
+
+;;======================== test5
+
+; PR4313
+define internal {i64,i64} @test5a() {
+ %a = insertvalue {i64,i64} undef, i64 4, 1
+ %b = insertvalue {i64,i64} %a, i64 5, 0
+ ret {i64,i64} %b
+}
+
+define i64 @test5b() {
+ %a = invoke {i64,i64} @test5a()
+ to label %A unwind label %B
+A:
+ %c = call i64 @test5c({i64,i64} %a)
+ ret i64 %c
+B:
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ ret i64 0
+}
+
+; CHECK: define i64 @test5b()
+; CHECK: A:
+; CHECK-NEXT: %c = call i64 @test5c({ i64, i64 } %a)
+; CHECK-NEXT: ret i64 5
+
+define internal i64 @test5c({i64,i64} %a) {
+ %b = extractvalue {i64,i64} %a, 0
+ ret i64 %b
+}
+
+
+;;======================== test6
+
+define i64 @test6a() {
+ ret i64 0
+}
+
+define i64 @test6b() {
+ %a = call i64 @test6a()
+ ret i64 %a
+}
+; CHECK: define i64 @test6b
+; CHECK: ret i64 0
+
+;;======================== test7
+
+
+%T = type {i32,i32}
+
+define internal %T @test7a(i32 %A) {
+ %X = add i32 1, %A
+ %mrv0 = insertvalue %T undef, i32 %X, 0
+ %mrv1 = insertvalue %T %mrv0, i32 %A, 1
+ ret %T %mrv1
+; CHECK: @test7a
+; CHECK-NEXT: %mrv0 = insertvalue %T undef, i32 18, 0
+; CHECK-NEXT: %mrv1 = insertvalue %T %mrv0, i32 17, 1
+}
+
+define i32 @test7b() {
+ %X = call %T @test7a(i32 17)
+ %Y = extractvalue %T %X, 0
+ %Z = add i32 %Y, %Y
+ ret i32 %Z
+; CHECK: define i32 @test7b
+; CHECK-NEXT: call %T @test7a(i32 17)
+; CHECK-NEXT: ret i32 36
+}
+
+;;======================== test8
+
+
+define internal {} @test8a(i32 %A, i32* %P) {
+ store i32 %A, i32* %P
+ ret {} {}
+; CHECK: @test8a
+; CHECK-NEXT: store i32 5,
+; CHECK-NEXT: ret
+}
+
+define void @test8b(i32* %P) {
+ %X = call {} @test8a(i32 5, i32* %P)
+ ret void
+; CHECK: define void @test8b
+; CHECK-NEXT: call {} @test8a
+; CHECK-NEXT: ret void
+}
+
+;;======================== test9
+
+@test9g = internal global { } zeroinitializer
+
+define void @test9() {
+entry:
+ %local_foo = alloca { }
+ load { }* @test9g
+ store { } %0, { }* %local_foo
+ ret void
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+;;======================== test10
+
+define i32 @test10a() nounwind {
+entry:
+ %call = call i32 @test10b(i32 undef)
+ ret i32 %call
+; CHECK: define i32 @test10a
+; CHECK: ret i32 0
+}
+
+define internal i32 @test10b(i32 %x) nounwind {
+entry:
+ %r = and i32 %x, 1
+ ret i32 %r
+; CHECK: define internal i32 @test10b
+; CHECK: ret i32 undef
+}
diff --git a/src/LLVM/test/Transforms/SCCP/loadtest.ll b/src/LLVM/test/Transforms/SCCP/loadtest.ll
new file mode 100644
index 0000000..6f89cad
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/loadtest.ll
@@ -0,0 +1,33 @@
+; This test makes sure that these instructions are properly constant propagated.
+
+target datalayout = "e-p:32:32"
+
+; RUN: opt < %s -sccp -S | not grep load
+
+
+@X = constant i32 42 ; <i32*> [#uses=1]
+@Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
+
+define i32 @test1() {
+ %B = load i32* @X ; <i32> [#uses=1]
+ ret i32 %B
+}
+
+define float @test2() {
+ %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1 ; <float*> [#uses=1]
+ %B = load float* %A ; <float> [#uses=1]
+ ret float %B
+}
+
+define i32 @test3() {
+ %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0 ; <i32*> [#uses=1]
+ %B = load i32* %A
+ ret i32 %B
+}
+
+define i8 @test4() {
+ %A = bitcast i32* @X to i8*
+ %B = load i8* %A
+ ret i8 %B
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/logical-nuke.ll b/src/LLVM/test/Transforms/SCCP/logical-nuke.ll
new file mode 100644
index 0000000..bf0c01e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/logical-nuke.ll
@@ -0,0 +1,9 @@
+; RUN: opt < %s -sccp -S | grep {ret i32 0}
+
+; Test that SCCP has basic knowledge of when and/or nuke overdefined values.
+
+define i32 @test(i32 %X) {
+ %Y = and i32 %X, 0 ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/phitest.ll b/src/LLVM/test/Transforms/SCCP/phitest.ll
new file mode 100644
index 0000000..70ab88b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/phitest.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -sccp -dce -simplifycfg -S | not grep br
+
+define i32 @test(i32 %param) {
+entry:
+ %tmp.1 = icmp ne i32 %param, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %endif.0, label %else
+else: ; preds = %entry
+ br label %endif.0
+endif.0: ; preds = %else, %entry
+ %a.0 = phi i32 [ 2, %else ], [ 3, %entry ] ; <i32> [#uses=1]
+ %b.0 = phi i32 [ 3, %else ], [ 2, %entry ] ; <i32> [#uses=1]
+ %tmp.5 = add i32 %a.0, %b.0 ; <i32> [#uses=1]
+ %tmp.7 = icmp ne i32 %tmp.5, 5 ; <i1> [#uses=1]
+ br i1 %tmp.7, label %UnifiedReturnBlock, label %endif.1
+endif.1: ; preds = %endif.0
+ ret i32 0
+UnifiedReturnBlock: ; preds = %endif.0
+ ret i32 2
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/retvalue-undef.ll b/src/LLVM/test/Transforms/SCCP/retvalue-undef.ll
new file mode 100644
index 0000000..389561f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/retvalue-undef.ll
@@ -0,0 +1,32 @@
+; RUN: opt -ipsccp -S %s | FileCheck %s
+; PR6414
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define internal i32 ()* @f() {
+ ret i32 ()* @g
+}
+
+define internal i32 @g() {
+ ret i32 8
+}
+
+; CHECK: internal i32 @g()
+; CHECK-NEXT: ret i32 8
+
+define internal void @outer_mod() {
+ %1 = call i32 ()* ()* @f() ; <i32 ()*> [#uses=1]
+ %2 = call i32 %1() ; <i32> [#uses=0]
+ ret void
+}
+
+define internal void @module_init() {
+ call void @register_outer_mod(void ()* @outer_mod)
+ ret void
+}
+
+declare void @register_outer_mod(void ()*)
+
+define i32 @main() {
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SCCP/sccptest.ll b/src/LLVM/test/Transforms/SCCP/sccptest.ll
new file mode 100644
index 0000000..2e8eadf
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/sccptest.ll
@@ -0,0 +1,58 @@
+; RUN: opt < %s -sccp -S | FileCheck %s
+
+; This is a basic sanity check for constant propagation. The add instruction
+; should be eliminated.
+
+define i32 @test1(i1 %B) {
+ br i1 %B, label %BB1, label %BB2
+BB1: ; preds = %0
+ %Val = add i32 0, 0 ; <i32> [#uses=1]
+ br label %BB3
+BB2: ; preds = %0
+ br label %BB3
+BB3: ; preds = %BB2, %BB1
+ %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ] ; <i32> [#uses=1]
+ ret i32 %Ret
+
+; CHECK: @test1
+; CHECK: %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
+}
+
+; This is the test case taken from appel's book that illustrates a hard case
+; that SCCP gets right.
+;
+define i32 @test2(i32 %i0, i32 %j0) {
+; CHECK: @test2
+BB1:
+ br label %BB2
+BB2:
+ %j2 = phi i32 [ %j4, %BB7 ], [ 1, %BB1 ]
+ %k2 = phi i32 [ %k4, %BB7 ], [ 0, %BB1 ]
+ %kcond = icmp slt i32 %k2, 100
+ br i1 %kcond, label %BB3, label %BB4
+BB3:
+ %jcond = icmp slt i32 %j2, 20
+ br i1 %jcond, label %BB5, label %BB6
+; CHECK: BB3:
+; CHECK-NEXT: br i1 true, label %BB5, label %BB6
+BB4:
+ ret i32 %j2
+; CHECK: BB4:
+; CHECK-NEXT: ret i32 1
+BB5:
+ %k3 = add i32 %k2, 1
+ br label %BB7
+BB6:
+ %k5 = add i32 %k2, 1
+ br label %BB7
+; CHECK: BB6:
+; CHECK-NEXT: br label %BB7
+BB7:
+ %j4 = phi i32 [ 1, %BB5 ], [ %k2, %BB6 ]
+ %k4 = phi i32 [ %k3, %BB5 ], [ %k5, %BB6 ]
+ br label %BB2
+; CHECK: BB7:
+; CHECK-NEXT: %k4 = phi i32 [ %k3, %BB5 ], [ undef, %BB6 ]
+; CHECK-NEXT: br label %BB2
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/select.ll b/src/LLVM/test/Transforms/SCCP/select.ll
new file mode 100644
index 0000000..1cd5a8b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/select.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -sccp -S | not grep select
+
+define i32 @test1(i1 %C) {
+ %X = select i1 %C, i32 0, i32 0 ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+define i32 @test2(i1 %C) {
+ %X = select i1 %C, i32 0, i32 undef ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/SCCP/switch.ll b/src/LLVM/test/Transforms/SCCP/switch.ll
new file mode 100644
index 0000000..9f93423
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/switch.ll
@@ -0,0 +1,13 @@
+; RUN: opt -S -sccp < %s | FileCheck %s
+
+; Make sure we always consider the default edge executable for a switch
+; with no cases.
+declare void @foo()
+define void @test1() {
+; CHECK: define void @test1
+; CHECK: call void @foo()
+ switch i32 undef, label %d []
+d:
+ call void @foo()
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SCCP/undef-resolve.ll b/src/LLVM/test/Transforms/SCCP/undef-resolve.ll
new file mode 100644
index 0000000..a3dddb7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SCCP/undef-resolve.ll
@@ -0,0 +1,172 @@
+; RUN: opt %s -sccp -S | FileCheck %s
+
+
+; PR6940
+define double @test1() {
+ %t = sitofp i32 undef to double
+ ret double %t
+; CHECK: @test1
+; CHECK: ret double 0.0
+}
+
+
+; rdar://7832370
+; Check that lots of stuff doesn't get turned into undef.
+define i32 @test2() nounwind readnone ssp {
+; CHECK: @test2
+init:
+ br label %control.outer.outer
+
+control.outer.loopexit.us-lcssa: ; preds = %control
+ br label %control.outer.loopexit
+
+control.outer.loopexit: ; preds = %control.outer.loopexit.us-lcssa.us, %control.outer.loopexit.us-lcssa
+ br label %control.outer.outer.backedge
+
+control.outer.outer: ; preds = %control.outer.outer.backedge, %init
+ %switchCond.0.ph.ph = phi i32 [ 2, %init ], [ 3, %control.outer.outer.backedge ] ; <i32> [#uses=2]
+ %i.0.ph.ph = phi i32 [ undef, %init ], [ %i.0.ph.ph.be, %control.outer.outer.backedge ] ; <i32> [#uses=1]
+ %tmp4 = icmp eq i32 %i.0.ph.ph, 0 ; <i1> [#uses=1]
+ br i1 %tmp4, label %control.outer.outer.split.us, label %control.outer.outer.control.outer.outer.split_crit_edge
+
+control.outer.outer.control.outer.outer.split_crit_edge: ; preds = %control.outer.outer
+ br label %control.outer
+
+control.outer.outer.split.us: ; preds = %control.outer.outer
+ br label %control.outer.us
+
+control.outer.us: ; preds = %bb3.us, %control.outer.outer.split.us
+ %A.0.ph.us = phi i32 [ %switchCond.0.us, %bb3.us ], [ 4, %control.outer.outer.split.us ] ; <i32> [#uses=2]
+ %switchCond.0.ph.us = phi i32 [ %A.0.ph.us, %bb3.us ], [ %switchCond.0.ph.ph, %control.outer.outer.split.us ] ; <i32> [#uses=1]
+ br label %control.us
+
+bb3.us: ; preds = %control.us
+ br label %control.outer.us
+
+bb0.us: ; preds = %control.us
+ br label %control.us
+
+; CHECK: control.us: ; preds = %bb0.us, %control.outer.us
+; CHECK-NEXT: %switchCond.0.us = phi i32
+; CHECK-NEXT: switch i32 %switchCond.0.us
+control.us: ; preds = %bb0.us, %control.outer.us
+ %switchCond.0.us = phi i32 [ %A.0.ph.us, %bb0.us ], [ %switchCond.0.ph.us, %control.outer.us ] ; <i32> [#uses=2]
+ switch i32 %switchCond.0.us, label %control.outer.loopexit.us-lcssa.us [
+ i32 0, label %bb0.us
+ i32 1, label %bb1.us-lcssa.us
+ i32 3, label %bb3.us
+ i32 4, label %bb4.us-lcssa.us
+ ]
+
+control.outer.loopexit.us-lcssa.us: ; preds = %control.us
+ br label %control.outer.loopexit
+
+bb1.us-lcssa.us: ; preds = %control.us
+ br label %bb1
+
+bb4.us-lcssa.us: ; preds = %control.us
+ br label %bb4
+
+control.outer: ; preds = %bb3, %control.outer.outer.control.outer.outer.split_crit_edge
+ %A.0.ph = phi i32 [ %nextId17, %bb3 ], [ 4, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
+ %switchCond.0.ph = phi i32 [ 0, %bb3 ], [ %switchCond.0.ph.ph, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
+ br label %control
+
+control: ; preds = %bb0, %control.outer
+ %switchCond.0 = phi i32 [ %A.0.ph, %bb0 ], [ %switchCond.0.ph, %control.outer ] ; <i32> [#uses=2]
+ switch i32 %switchCond.0, label %control.outer.loopexit.us-lcssa [
+ i32 0, label %bb0
+ i32 1, label %bb1.us-lcssa
+ i32 3, label %bb3
+ i32 4, label %bb4.us-lcssa
+ ]
+
+bb4.us-lcssa: ; preds = %control
+ br label %bb4
+
+bb4: ; preds = %bb4.us-lcssa, %bb4.us-lcssa.us
+ br label %control.outer.outer.backedge
+
+control.outer.outer.backedge: ; preds = %bb4, %control.outer.loopexit
+ %i.0.ph.ph.be = phi i32 [ 1, %bb4 ], [ 0, %control.outer.loopexit ] ; <i32> [#uses=1]
+ br label %control.outer.outer
+
+bb3: ; preds = %control
+ %nextId17 = add i32 %switchCond.0, -2 ; <i32> [#uses=1]
+ br label %control.outer
+
+bb0: ; preds = %control
+ br label %control
+
+bb1.us-lcssa: ; preds = %control
+ br label %bb1
+
+bb1: ; preds = %bb1.us-lcssa, %bb1.us-lcssa.us
+ ret i32 0
+}
+
+; Make sure SCCP honors the xor "idiom"
+; rdar://9956541
+define i32 @test3() {
+ %t = xor i32 undef, undef
+ ret i32 %t
+; CHECK: @test3
+; CHECK: ret i32 0
+}
+
+; Be conservative with FP ops
+define double @test4(double %x) {
+ %t = fadd double %x, undef
+ ret double %t
+; CHECK: @test4
+; CHECK: fadd double %x, undef
+}
+
+; Make sure casts produce a possible value
+define i32 @test5() {
+ %t = sext i8 undef to i32
+ ret i32 %t
+; CHECK: @test5
+; CHECK: ret i32 0
+}
+
+; Make sure ashr produces a possible value
+define i32 @test6() {
+ %t = ashr i32 undef, 31
+ ret i32 %t
+; CHECK: @test6
+; CHECK: ret i32 -1
+}
+
+; Make sure lshr produces a possible value
+define i32 @test7() {
+ %t = lshr i32 undef, 31
+ ret i32 %t
+; CHECK: @test7
+; CHECK: ret i32 0
+}
+
+; icmp eq with undef simplifies to undef
+define i1 @test8() {
+ %t = icmp eq i32 undef, -1
+ ret i1 %t
+; CHECK: @test8
+; CHECK: ret i1 undef
+}
+
+; Make sure we don't conclude that relational comparisons simplify to undef
+define i1 @test9() {
+ %t = icmp ugt i32 undef, -1
+ ret i1 %t
+; CHECK: @test9
+; CHECK: icmp ugt
+}
+
+; Make sure we handle extractvalue
+define i64 @test10() {
+entry:
+ %e = extractvalue { i64, i64 } undef, 1
+ ret i64 %e
+; CHECK: @test10
+; CHECK: ret i64 undef
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2003-05-29-ArrayFail.ll b/src/LLVM/test/Transforms/ScalarRepl/2003-05-29-ArrayFail.ll
new file mode 100644
index 0000000..64e2b05
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2003-05-29-ArrayFail.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -scalarrepl -instcombine -S | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+; Test that an array is not incorrectly deconstructed.
+
+define i32 @test() nounwind {
+ %X = alloca [4 x i32] ; <[4 x i32]*> [#uses=1]
+ %Y = getelementptr [4 x i32]* %X, i64 0, i64 0 ; <i32*> [#uses=1]
+ ; Must preserve arrayness!
+ %Z = getelementptr i32* %Y, i64 1 ; <i32*> [#uses=1]
+ %A = load i32* %Z ; <i32> [#uses=1]
+ ret i32 %A
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2003-09-12-IncorrectPromote.ll b/src/LLVM/test/Transforms/ScalarRepl/2003-09-12-IncorrectPromote.ll
new file mode 100644
index 0000000..7f17c05
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2003-09-12-IncorrectPromote.ll
@@ -0,0 +1,13 @@
+; Scalar replacement was incorrectly promoting this alloca!!
+;
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: sed {s/;.*//g} | grep {\\\[}
+
+define i8* @test() {
+ %A = alloca [30 x i8] ; <[30 x i8]*> [#uses=1]
+ %B = getelementptr [30 x i8]* %A, i64 0, i64 0 ; <i8*> [#uses=2]
+ %C = getelementptr i8* %B, i64 1 ; <i8*> [#uses=1]
+ store i8 0, i8* %B
+ ret i8* %C
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2003-10-29-ArrayProblem.ll b/src/LLVM/test/Transforms/ScalarRepl/2003-10-29-ArrayProblem.ll
new file mode 100644
index 0000000..7753f9f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2003-10-29-ArrayProblem.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -scalarrepl -S | grep {alloca %%T}
+
+%T = type { [80 x i8], i32, i32 }
+declare i32 @.callback_1(i8*)
+
+declare void @.iter_2(i32 (i8*)*, i8*)
+
+define i32 @main() {
+ %d = alloca %T ; <{ [80 x i8], i32, i32 }*> [#uses=2]
+ %tmp.0 = getelementptr %T* %d, i64 0, i32 2 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp.0
+ %tmp.1 = getelementptr %T* %d, i64 0, i32 0, i64 0 ; <i8*> [#uses=1]
+ call void @.iter_2( i32 (i8*)* @.callback_1, i8* %tmp.1 )
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2006-11-07-InvalidArrayPromote.ll b/src/LLVM/test/Transforms/ScalarRepl/2006-11-07-InvalidArrayPromote.ll
new file mode 100644
index 0000000..e027f24
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2006-11-07-InvalidArrayPromote.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @func(<4 x float> %v0, <4 x float> %v1) nounwind {
+ %vsiidx = alloca [2 x <4 x i32>], align 16 ; <[2 x <4 x i32>]*> [#uses=3]
+ %tmp = call <4 x i32> @llvm.x86.sse2.cvttps2dq( <4 x float> %v0 ) ; <<4 x i32>> [#uses=2]
+ %tmp.upgrd.1 = bitcast <4 x i32> %tmp to <2 x i64> ; <<2 x i64>> [#uses=0]
+ %tmp.upgrd.2 = getelementptr [2 x <4 x i32>]* %vsiidx, i32 0, i32 0 ; <<4 x i32>*> [#uses=1]
+ store <4 x i32> %tmp, <4 x i32>* %tmp.upgrd.2
+ %tmp10 = call <4 x i32> @llvm.x86.sse2.cvttps2dq( <4 x float> %v1 ) ; <<4 x i32>> [#uses=2]
+ %tmp10.upgrd.3 = bitcast <4 x i32> %tmp10 to <2 x i64> ; <<2 x i64>> [#uses=0]
+ %tmp14 = getelementptr [2 x <4 x i32>]* %vsiidx, i32 0, i32 1 ; <<4 x i32>*> [#uses=1]
+ store <4 x i32> %tmp10, <4 x i32>* %tmp14
+ %tmp15 = getelementptr [2 x <4 x i32>]* %vsiidx, i32 0, i32 0, i32 4 ; <i32*> [#uses=1]
+ %tmp.upgrd.4 = load i32* %tmp15 ; <i32> [#uses=1]
+ ret i32 %tmp.upgrd.4
+}
+
+declare <4 x i32> @llvm.x86.sse2.cvttps2dq(<4 x float>)
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2007-05-29-MemcpyPreserve.ll b/src/LLVM/test/Transforms/ScalarRepl/2007-05-29-MemcpyPreserve.ll
new file mode 100644
index 0000000..cfdf669
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2007-05-29-MemcpyPreserve.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -scalarrepl -S | grep memcpy
+; PR1421
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-apple-darwin8"
+
+%struct.LongestMember = type { i8, i32 }
+%struct.MyString = type { i32 }
+%struct.UnionType = type { %struct.LongestMember }
+
+define void @_Z4testP9UnionTypePS0_(%struct.UnionType* %p, %struct.UnionType** %pointerToUnion) {
+entry:
+ %tmp = alloca %struct.UnionType, align 8
+ %tmp2 = getelementptr %struct.UnionType* %tmp, i32 0, i32 0, i32 0
+ %tmp13 = getelementptr %struct.UnionType* %p, i32 0, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp2, i8* %tmp13, i32 8, i32 0, i1 false)
+ %tmp5 = load %struct.UnionType** %pointerToUnion
+ %tmp56 = getelementptr %struct.UnionType* %tmp5, i32 0, i32 0, i32 0
+ %tmp7 = getelementptr %struct.UnionType* %tmp, i32 0, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp56, i8* %tmp7, i32 8, i32 0, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2007-11-03-bigendian_apint.ll b/src/LLVM/test/Transforms/ScalarRepl/2007-11-03-bigendian_apint.ll
new file mode 100644
index 0000000..48abffe
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2007-11-03-bigendian_apint.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -scalarrepl -S | not grep shr
+
+%struct.S = type { i16 }
+
+define zeroext i1 @f(i16 signext %b) {
+entry:
+ %b_addr = alloca i16 ; <i16*> [#uses=2]
+ %retval = alloca i32 ; <i32*> [#uses=2]
+ %s = alloca %struct.S ; <%struct.S*> [#uses=2]
+ %tmp = alloca i32 ; <i32*> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i16 %b, i16* %b_addr
+ %tmp1 = getelementptr %struct.S* %s, i32 0, i32 0 ; <i16*> [#uses=1]
+ %tmp2 = load i16* %b_addr, align 2 ; <i16> [#uses=1]
+ store i16 %tmp2, i16* %tmp1, align 2
+ %tmp3 = getelementptr %struct.S* %s, i32 0, i32 0 ; <i16*> [#uses=1]
+ %tmp34 = bitcast i16* %tmp3 to [2 x i1]* ; <[2 x i1]*> [#uses=1]
+ %tmp5 = getelementptr [2 x i1]* %tmp34, i32 0, i32 1 ; <i1*> [#uses=1]
+ %tmp6 = load i1* %tmp5, align 1 ; <i1> [#uses=1]
+ %tmp67 = zext i1 %tmp6 to i32 ; <i32> [#uses=1]
+ store i32 %tmp67, i32* %tmp, align 4
+ %tmp8 = load i32* %tmp, align 4 ; <i32> [#uses=1]
+ store i32 %tmp8, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %entry
+ %retval9 = load i32* %retval ; <i32> [#uses=1]
+ %retval910 = trunc i32 %retval9 to i1 ; <i1> [#uses=1]
+ ret i1 %retval910
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-01-29-PromoteBug.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-01-29-PromoteBug.ll
new file mode 100644
index 0000000..8bc4ff0
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-01-29-PromoteBug.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -scalarrepl -instcombine -S | grep {ret i8 17}
+; rdar://5707076
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.1.0"
+ %struct.T = type <{ i8, [3 x i8] }>
+
+define i8 @f() {
+entry:
+ %s = alloca [1 x %struct.T], align 4 ; <[1 x %struct.T]*> [#uses=2]
+ %T3 = bitcast [1 x %struct.T]* %s to i32*
+ store i32 -61184, i32* %T3
+
+ %tmp16 = getelementptr [1 x %struct.T]* %s, i32 0, i32 0 ; <%struct.T*> [#uses=1]
+ %tmp17 = getelementptr %struct.T* %tmp16, i32 0, i32 1 ; <[3 x i8]*> [#uses=1]
+ %tmp1718 = bitcast [3 x i8]* %tmp17 to i32* ; <i32*> [#uses=1]
+ %tmp19 = load i32* %tmp1718, align 4 ; <i32> [#uses=1]
+ %mask = and i32 %tmp19, 16777215 ; <i32> [#uses=2]
+ %mask2324 = trunc i32 %mask to i8 ; <i8> [#uses=1]
+ ret i8 %mask2324
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-02-28-SubElementExtractCrash.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-02-28-SubElementExtractCrash.ll
new file mode 100644
index 0000000..7f8ef83
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-02-28-SubElementExtractCrash.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+ %struct..0anon = type { <1 x i64> }
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %c = alloca %struct..0anon ; <%struct..0anon*> [#uses=2]
+ %tmp2 = getelementptr %struct..0anon* %c, i32 0, i32 0 ; <<1 x i64>*> [#uses=1]
+ store <1 x i64> zeroinitializer, <1 x i64>* %tmp2, align 8
+ %tmp7 = getelementptr %struct..0anon* %c, i32 0, i32 0 ; <<1 x i64>*> [#uses=1]
+ %tmp78 = bitcast <1 x i64>* %tmp7 to [2 x i32]* ; <[2 x i32]*> [#uses=1]
+ %tmp9 = getelementptr [2 x i32]* %tmp78, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp10 = load i32* %tmp9, align 4 ; <i32> [#uses=0]
+ unreachable
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-06-05-loadstore-agg.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-06-05-loadstore-agg.ll
new file mode 100644
index 0000000..ce70a1b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-06-05-loadstore-agg.ll
@@ -0,0 +1,33 @@
+; This test shows an alloca of a struct and an array that can be reduced to
+; multiple variables easily. However, the alloca is used by a store
+; instruction, which was not possible before aggregrates were first class
+; values. This checks of scalarrepl splits up the struct and array properly.
+
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @foo() {
+ %target = alloca { i32, i32 } ; <{ i32, i32 }*> [#uses=1]
+ ; Build a first class struct to store
+ %res1 = insertvalue { i32, i32 } undef, i32 1, 0 ; <{ i32, i32 }> [#uses=1]
+ %res2 = insertvalue { i32, i32 } %res1, i32 2, 1 ; <{ i32, i32 }> [#uses=1]
+ ; And store it
+ store { i32, i32 } %res2, { i32, i32 }* %target
+ ; Actually use %target, so it doesn't get removed altogether
+ %ptr = getelementptr { i32, i32 }* %target, i32 0, i32 0
+ %val = load i32* %ptr
+ ret i32 %val
+}
+
+define i32 @bar() {
+ %target = alloca [ 2 x i32 ] ; <{ i32, i32 }*> [#uses=1]
+ ; Build a first class array to store
+ %res1 = insertvalue [ 2 x i32 ] undef, i32 1, 0 ; <{ i32, i32 }> [#uses=1]
+ %res2 = insertvalue [ 2 x i32 ] %res1, i32 2, 1 ; <{ i32, i32 }> [#uses=1]
+ ; And store it
+ store [ 2 x i32 ] %res2, [ 2 x i32 ]* %target
+ ; Actually use %target, so it doesn't get removed altogether
+ %ptr = getelementptr [ 2 x i32 ]* %target, i32 0, i32 0
+ %val = load i32* %ptr
+ ret i32 %val
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-06-22-LargeArray.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-06-22-LargeArray.ll
new file mode 100644
index 0000000..71ba601
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-06-22-LargeArray.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -scalarrepl -S | grep {call.*mem}
+; PR2369
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+define void @memtest1(i8* %dst, i8* %src) nounwind {
+entry:
+ %temp = alloca [200 x i8]
+ %temp1 = bitcast [200 x i8]* %temp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %temp1, i8* %src, i32 200, i32 1, i1 false)
+ %temp3 = bitcast [200 x i8]* %temp to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %temp3, i32 200, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-08-22-out-of-range-array-promote.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-08-22-out-of-range-array-promote.ll
new file mode 100644
index 0000000..7cccb19
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-08-22-out-of-range-array-promote.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -scalarrepl -S | grep {s = alloca .struct.x}
+; PR2423
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+%struct.x = type { [1 x i32], i32, i32 }
+
+define i32 @b() nounwind {
+entry:
+ %s = alloca %struct.x
+ %r = alloca %struct.x
+ %0 = call i32 @a(%struct.x* %s) nounwind
+ %r1 = bitcast %struct.x* %r to i8*
+ %s2 = bitcast %struct.x* %s to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %r1, i8* %s2, i32 12, i32 8, i1 false)
+ %1 = getelementptr %struct.x* %r, i32 0, i32 0, i32 1
+ %2 = load i32* %1, align 4
+ ret i32 %2
+}
+
+declare i32 @a(%struct.x*)
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2008-09-22-vector-gep.ll b/src/LLVM/test/Transforms/ScalarRepl/2008-09-22-vector-gep.ll
new file mode 100644
index 0000000..e7a58f1
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2008-09-22-vector-gep.ll
@@ -0,0 +1,25 @@
+; This test checks to see if scalarrepl also works when a gep with all zeroes is
+; used instead of a bitcast to prepare a memmove pointer argument. Previously,
+; this would not work when there was a vector involved in the struct, preventing
+; scalarrepl from removing the alloca below.
+
+; RUN: opt < %s -scalarrepl -S > %t
+; RUN: cat %t | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+%struct.two = type <{ < 2 x i8 >, i16 }>
+
+define void @main(%struct.two* %D, i16 %V) {
+entry:
+ %S = alloca %struct.two
+ %S.2 = getelementptr %struct.two* %S, i32 0, i32 1
+ store i16 %V, i16* %S.2
+ ; This gep is effectively a bitcast to i8*, but is sometimes generated
+ ; because the type of the first element in %struct.two is i8.
+ %tmpS = getelementptr %struct.two* %S, i32 0, i32 0, i32 0
+ %tmpD = bitcast %struct.two* %D to i8*
+ call void @llvm.memmove.p0i8.p0i8.i32(i8* %tmpD, i8* %tmpS, i32 4, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2009-02-02-ScalarPromoteOutOfRange.ll b/src/LLVM/test/Transforms/ScalarRepl/2009-02-02-ScalarPromoteOutOfRange.ll
new file mode 100644
index 0000000..9c0f203
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2009-02-02-ScalarPromoteOutOfRange.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -scalarrepl -instcombine -S | grep {ret i32 %x}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+%pair = type { [1 x i32], i32 }
+
+define i32 @f(i32 %x, i32 %y) {
+ %instance = alloca %pair
+ %first = getelementptr %pair* %instance, i32 0, i32 0
+ %cast = bitcast [1 x i32]* %first to i32*
+ store i32 %x, i32* %cast
+ %second = getelementptr %pair* %instance, i32 0, i32 1
+ store i32 %y, i32* %second
+ %v = load i32* %cast
+ ret i32 %v
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2009-02-05-LoadFCA.ll b/src/LLVM/test/Transforms/ScalarRepl/2009-02-05-LoadFCA.ll
new file mode 100644
index 0000000..f8ab875
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2009-02-05-LoadFCA.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -scalarrepl -instcombine -inline -instcombine -S | grep {ret i32 42}
+; PR3489
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "x86_64-apple-darwin10.0"
+ %struct.anon = type <{ i32, i32, i32 }>
+
+define i32 @f({ i64, i64 }) nounwind {
+entry:
+ %tmp = alloca { i64, i64 }, align 8 ; <{ i64, i64 }*> [#uses=2]
+ store { i64, i64 } %0, { i64, i64 }* %tmp
+ %1 = bitcast { i64, i64 }* %tmp to %struct.anon* ; <%struct.anon*> [#uses=1]
+ %2 = load %struct.anon* %1, align 8 ; <%struct.anon> [#uses=1]
+ %tmp3 = extractvalue %struct.anon %2, 0
+ ret i32 %tmp3
+}
+
+define i32 @g() {
+ %a = call i32 @f({i64,i64} { i64 42, i64 1123123123123123 })
+ ret i32 %a
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2009-03-04-MemCpyAlign.ll b/src/LLVM/test/Transforms/ScalarRepl/2009-03-04-MemCpyAlign.ll
new file mode 100644
index 0000000..3218d59
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2009-03-04-MemCpyAlign.ll
@@ -0,0 +1,19 @@
+; The store into %p should end up with a known alignment of 1, since the memcpy
+; is only known to access it with 1-byte alignment.
+; RUN: opt < %s -scalarrepl -S | grep {store i16 1, .*, align 1}
+; PR3720
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+ %struct.st = type { i16 }
+
+define void @f(i8* %p) nounwind {
+entry:
+ %s = alloca %struct.st, align 4 ; <%struct.st*> [#uses=2]
+ %0 = getelementptr %struct.st* %s, i32 0, i32 0 ; <i16*> [#uses=1]
+ store i16 1, i16* %0, align 4
+ %s1 = bitcast %struct.st* %s to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %p, i8* %s1, i32 2, i32 1, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2009-03-05-Aggre2Scalar-dbg.ll b/src/LLVM/test/Transforms/ScalarRepl/2009-03-05-Aggre2Scalar-dbg.ll
new file mode 100644
index 0000000..d71bcb9
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2009-03-05-Aggre2Scalar-dbg.ll
@@ -0,0 +1,184 @@
+; RUN: opt < %s -scalarrepl -disable-output -stats |& grep "Number of aggregates converted to scalar"
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin9.6"
+ %0 = type { } ; type %0
+ %1 = type { i8*, i32, i32, i16, i16, %2, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %2, %3*, i32, [3 x i8], [1 x i8], %2, i32, i64 } ; type %1
+ %2 = type { i8*, i32 } ; type %2
+ %3 = type opaque ; type %3
+ %4 = type { i32 } ; type %4
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.basictype.type = type { i32, %0*, i8*, %0*, i32, i64, i64, i64, i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, %0*, i32, i8*, i8*, i8*, i1, i1, i8*, i32 }
+ %llvm.dbg.composite.type = type { i32, %0*, i8*, %0*, i32, i64, i64, i64, i32, %0*, %0*, i32 }
+ %llvm.dbg.derivedtype.type = type { i32, %0*, i8*, %0*, i32, i64, i64, i64, i32, %0* }
+ %llvm.dbg.subprogram.type = type { i32, %0*, %0*, i8*, i8*, i8*, %0*, i32, %0*, i1, i1 }
+ %llvm.dbg.subrange.type = type { i32, i64, i64 }
+ %llvm.dbg.variable.type = type { i32, %0*, i8*, %0*, i32, %0* }
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+internal constant [8 x i8] c"PR491.c\00", section "llvm.metadata" ; <[8 x i8]*>:0 [#uses=1]
+internal constant [77 x i8] c"/Volumes/Nanpura/mainline/llvm/projects/llvm-test/SingleSource/Regression/C/\00", section "llvm.metadata" ; <[77 x i8]*>:1 [#uses=1]
+internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5641) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*>:2 [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, %0* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to %0*), i32 1, i8* getelementptr ([8 x i8]* @0, i32 0, i32 0), i8* getelementptr ([77 x i8]* @1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @2, i32 0, i32 0), i1 true, i1 false, i8* null, i32 0 }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+internal constant [4 x i8] c"int\00", section "llvm.metadata" ; <[4 x i8]*>:3 [#uses=1]
+@llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type { i32 458788, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([4 x i8]* @3, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+internal constant [5 x i8] c"char\00", section "llvm.metadata" ; <[5 x i8]*>:4 [#uses=1]
+@llvm.dbg.basictype5 = internal constant %llvm.dbg.basictype.type { i32 458788, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([5 x i8]* @4, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 8, i64 8, i64 0, i32 0, i32 6 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@llvm.dbg.derivedtype = internal constant %llvm.dbg.derivedtype.type { i32 458790, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 8, i64 8, i64 0, i32 0, %0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype5 to %0*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.derivedtype6 = internal constant %llvm.dbg.derivedtype.type { i32 458767, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 32, i64 32, i64 0, i32 0, %0* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype to %0*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+internal constant [13 x i8] c"unsigned int\00", section "llvm.metadata" ; <[13 x i8]*>:5 [#uses=1]
+@llvm.dbg.basictype8 = internal constant %llvm.dbg.basictype.type { i32 458788, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([13 x i8]* @5, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 7 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@llvm.dbg.array = internal constant [3 x %0*] [%0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to %0*), %0* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype6 to %0*), %0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype8 to %0*)], section "llvm.metadata" ; <[3 x %0*]*> [#uses=1]
+@llvm.dbg.composite = internal constant %llvm.dbg.composite.type { i32 458773, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 0, i64 0, i64 0, i32 0, %0* null, %0* bitcast ([3 x %0*]* @llvm.dbg.array to %0*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+internal constant [12 x i8] c"assert_fail\00", section "llvm.metadata" ; <[12 x i8]*>:6 [#uses=1]
+@llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 458798, %0* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to %0*), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([12 x i8]* @6, i32 0, i32 0), i8* getelementptr ([12 x i8]* @6, i32 0, i32 0), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 4, %0* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite to %0*), i1 true, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=0]
+internal constant [2 x i8] c"l\00", section "llvm.metadata" ; <[2 x i8]*>:7 [#uses=1]
+@__stderrp = external global %1* ; <%1**> [#uses=4]
+internal constant [35 x i8] c"assertion failed in line %u: '%s'\0A\00", section "__TEXT,__cstring,cstring_literals" ; <[35 x i8]*>:8 [#uses=1]
+@llvm.dbg.array13 = internal constant [2 x %0*] [%0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to %0*), %0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to %0*)], section "llvm.metadata" ; <[2 x %0*]*> [#uses=1]
+@llvm.dbg.composite14 = internal constant %llvm.dbg.composite.type { i32 458773, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 0, i64 0, i64 0, i32 0, %0* null, %0* bitcast ([2 x %0*]* @llvm.dbg.array13 to %0*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+internal constant [5 x i8] c"test\00", section "llvm.metadata" ; <[5 x i8]*>:9 [#uses=1]
+@llvm.dbg.subprogram16 = internal constant %llvm.dbg.subprogram.type { i32 458798, %0* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to %0*), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([5 x i8]* @9, i32 0, i32 0), i8* getelementptr ([5 x i8]* @9, i32 0, i32 0), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 10, %0* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite14 to %0*), i1 false, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+internal constant [9 x i8] c"long int\00", section "llvm.metadata" ; <[9 x i8]*>:10 [#uses=1]
+@llvm.dbg.basictype21 = internal constant %llvm.dbg.basictype.type { i32 458788, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([9 x i8]* @10, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@llvm.dbg.derivedtype22 = internal constant %llvm.dbg.derivedtype.type { i32 458765, %0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*), i8* getelementptr ([2 x i8]* @7, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 20, i64 32, i64 32, i64 0, i32 0, %0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype21 to %0*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.subrange = internal constant %llvm.dbg.subrange.type { i32 458785, i64 0, i64 3 }, section "llvm.metadata" ; <%llvm.dbg.subrange.type*> [#uses=1]
+@llvm.dbg.array23 = internal constant [1 x %0*] [%0* bitcast (%llvm.dbg.subrange.type* @llvm.dbg.subrange to %0*)], section "llvm.metadata" ; <[1 x %0*]*> [#uses=1]
+internal constant [14 x i8] c"unsigned char\00", section "llvm.metadata" ; <[14 x i8]*>:11 [#uses=1]
+@llvm.dbg.basictype25 = internal constant %llvm.dbg.basictype.type { i32 458788, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([14 x i8]* @11, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 8, i64 8, i64 0, i32 0, i32 8 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@llvm.dbg.composite26 = internal constant %llvm.dbg.composite.type { i32 458753, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 32, i64 8, i64 0, i32 0, %0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype25 to %0*), %0* bitcast ([1 x %0*]* @llvm.dbg.array23 to %0*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+internal constant [2 x i8] c"c\00", section "llvm.metadata" ; <[2 x i8]*>:12 [#uses=1]
+@llvm.dbg.derivedtype28 = internal constant %llvm.dbg.derivedtype.type { i32 458765, %0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*), i8* getelementptr ([2 x i8]* @12, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 20, i64 32, i64 8, i64 0, i32 0, %0* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite26 to %0*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.array29 = internal constant [2 x %0*] [%0* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype22 to %0*), %0* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype28 to %0*)], section "llvm.metadata" ; <[2 x %0*]*> [#uses=1]
+@llvm.dbg.composite30 = internal constant %llvm.dbg.composite.type { i32 458775, %0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 20, i64 32, i64 32, i64 0, i32 0, %0* null, %0* bitcast ([2 x %0*]* @llvm.dbg.array29 to %0*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+internal constant [2 x i8] c"u\00", section "llvm.metadata" ; <[2 x i8]*>:13 [#uses=1]
+@llvm.dbg.variable32 = internal constant %llvm.dbg.variable.type { i32 459008, %0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*), i8* getelementptr ([2 x i8]* @13, i32 0, i32 0), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 20, %0* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite30 to %0*) }, section "llvm.metadata" ; <%llvm.dbg.variable.type*> [#uses=1]
+internal constant [11 x i8] c"u.l == 128\00", section "__TEXT,__cstring,cstring_literals" ; <[11 x i8]*>:14 [#uses=1]
+internal constant [8 x i8] c"u.l < 0\00", section "__TEXT,__cstring,cstring_literals" ; <[8 x i8]*>:15 [#uses=1]
+@llvm.dbg.array35 = internal constant [1 x %0*] [%0* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to %0*)], section "llvm.metadata" ; <[1 x %0*]*> [#uses=1]
+@llvm.dbg.composite36 = internal constant %llvm.dbg.composite.type { i32 458773, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 0, i64 0, i64 0, i64 0, i32 0, %0* null, %0* bitcast ([1 x %0*]* @llvm.dbg.array35 to %0*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+internal constant [5 x i8] c"main\00", section "llvm.metadata" ; <[5 x i8]*>:16 [#uses=1]
+@llvm.dbg.subprogram38 = internal constant %llvm.dbg.subprogram.type { i32 458798, %0* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to %0*), %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i8* getelementptr ([5 x i8]* @16, i32 0, i32 0), i8* getelementptr ([5 x i8]* @16, i32 0, i32 0), i8* null, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*), i32 28, %0* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite36 to %0*), i1 false, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+
+declare void @llvm.dbg.func.start(%0*) nounwind readnone
+
+declare void @llvm.dbg.declare(%0*, %0*) nounwind readnone
+
+declare void @llvm.dbg.stoppoint(i32, i32, %0*) nounwind readnone
+
+declare i32 @fprintf(%1* nocapture, i8* nocapture, ...) nounwind
+
+declare void @llvm.dbg.region.end(%0*) nounwind readnone
+
+define i32 @test(i32) nounwind {
+; <label>:1
+ %2 = alloca %4, align 8 ; <%4*> [#uses=7]
+ call void @llvm.dbg.func.start(%0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*))
+ %3 = bitcast %4* %2 to %0* ; <%0*> [#uses=1]
+ call void @llvm.dbg.declare(%0* %3, %0* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable32 to %0*))
+ call void @llvm.dbg.stoppoint(i32 21, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %4 = getelementptr %4* %2, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %4, align 8
+ %5 = bitcast %4* %2 to i8* ; <i8*> [#uses=1]
+ store i8 -128, i8* %5, align 8
+ call void @llvm.dbg.stoppoint(i32 22, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %6 = getelementptr %4* %2, i32 0, i32 0 ; <i32*> [#uses=1]
+ %7 = load i32* %6, align 8 ; <i32> [#uses=1]
+ %8 = icmp eq i32 %7, 128 ; <i1> [#uses=1]
+ br i1 %8, label %12, label %9
+
+; <label>:9 ; preds = %1
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %10 = load %1** @__stderrp, align 4 ; <%1*> [#uses=1]
+ %11 = call i32 (%1*, i8*, ...)* @fprintf(%1* %10, i8* getelementptr ([35 x i8]* @8, i32 0, i32 0), i32 22, i8* getelementptr ([11 x i8]* @14, i32 0, i32 0)) nounwind ; <i32> [#uses=0]
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ br label %12
+
+; <label>:12 ; preds = %9, %1
+ %.0 = phi i32 [ 0, %9 ], [ 1, %1 ] ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 22, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %13 = and i32 %.0, %0 ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 23, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %14 = getelementptr %4* %2, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %14, align 8
+ %15 = bitcast %4* %2 to [4 x i8]* ; <[4 x i8]*> [#uses=1]
+ %16 = getelementptr [4 x i8]* %15, i32 0, i32 3 ; <i8*> [#uses=1]
+ store i8 -128, i8* %16, align 1
+ call void @llvm.dbg.stoppoint(i32 24, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %17 = getelementptr %4* %2, i32 0, i32 0 ; <i32*> [#uses=1]
+ %18 = load i32* %17, align 8 ; <i32> [#uses=1]
+ %19 = icmp slt i32 %18, 0 ; <i1> [#uses=1]
+ br i1 %19, label %23, label %20
+
+; <label>:20 ; preds = %12
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %21 = load %1** @__stderrp, align 4 ; <%1*> [#uses=1]
+ %22 = call i32 (%1*, i8*, ...)* @fprintf(%1* %21, i8* getelementptr ([35 x i8]* @8, i32 0, i32 0), i32 24, i8* getelementptr ([8 x i8]* @15, i32 0, i32 0)) nounwind ; <i32> [#uses=0]
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ br label %23
+
+; <label>:23 ; preds = %20, %12
+ %.01 = phi i32 [ 0, %20 ], [ 1, %12 ] ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 24, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %24 = and i32 %.01, %13 ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 25, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ call void @llvm.dbg.region.end(%0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to %0*))
+ ret i32 %24
+}
+
+define i32 @main() nounwind {
+; <label>:0
+ %1 = alloca %4, align 8 ; <%4*> [#uses=7]
+ call void @llvm.dbg.func.start(%0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram38 to %0*))
+ call void @llvm.dbg.stoppoint(i32 29, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ %2 = bitcast %4* %1 to %0* ; <%0*> [#uses=1]
+ call void @llvm.dbg.declare(%0* %2, %0* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable32 to %0*)) nounwind
+ call void @llvm.dbg.stoppoint(i32 21, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %3 = getelementptr %4* %1, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %3, align 8
+ %4 = bitcast %4* %1 to i8* ; <i8*> [#uses=1]
+ store i8 -128, i8* %4, align 8
+ call void @llvm.dbg.stoppoint(i32 22, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %5 = getelementptr %4* %1, i32 0, i32 0 ; <i32*> [#uses=1]
+ %6 = load i32* %5, align 8 ; <i32> [#uses=1]
+ %7 = icmp eq i32 %6, 128 ; <i1> [#uses=1]
+ br i1 %7, label %11, label %8
+
+; <label>:8 ; preds = %0
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %9 = load %1** @__stderrp, align 4 ; <%1*> [#uses=1]
+ %10 = call i32 (%1*, i8*, ...)* @fprintf(%1* %9, i8* getelementptr ([35 x i8]* @8, i32 0, i32 0), i32 22, i8* getelementptr ([11 x i8]* @14, i32 0, i32 0)) nounwind ; <i32> [#uses=0]
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ br label %11
+
+; <label>:11 ; preds = %8, %0
+ %.0.i = phi i32 [ 0, %8 ], [ 1, %0 ] ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 23, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %12 = getelementptr %4* %1, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 0, i32* %12, align 8
+ %13 = bitcast %4* %1 to [4 x i8]* ; <[4 x i8]*> [#uses=1]
+ %14 = getelementptr [4 x i8]* %13, i32 0, i32 3 ; <i8*> [#uses=1]
+ store i8 -128, i8* %14, align 1
+ call void @llvm.dbg.stoppoint(i32 24, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %15 = getelementptr %4* %1, i32 0, i32 0 ; <i32*> [#uses=1]
+ %16 = load i32* %15, align 8 ; <i32> [#uses=1]
+ %17 = icmp slt i32 %16, 0 ; <i1> [#uses=1]
+ br i1 %17, label %test.exit, label %18
+
+; <label>:18 ; preds = %11
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %19 = load %1** @__stderrp, align 4 ; <%1*> [#uses=1]
+ %20 = call i32 (%1*, i8*, ...)* @fprintf(%1* %19, i8* getelementptr ([35 x i8]* @8, i32 0, i32 0), i32 24, i8* getelementptr ([8 x i8]* @15, i32 0, i32 0)) nounwind ; <i32> [#uses=0]
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ br label %test.exit
+
+test.exit: ; preds = %18, %11
+ %.01.i = phi i32 [ 0, %18 ], [ 1, %11 ] ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 24, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %21 = and i32 %.01.i, %.0.i ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 25, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*)) nounwind
+ %tmp = xor i32 %21, 1 ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 29, i32 0, %0* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to %0*))
+ call void @llvm.dbg.region.end(%0* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram38 to %0*))
+ ret i32 %tmp
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2009-12-11-NeonTypes.ll b/src/LLVM/test/Transforms/ScalarRepl/2009-12-11-NeonTypes.ll
new file mode 100644
index 0000000..1993e4f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2009-12-11-NeonTypes.ll
@@ -0,0 +1,90 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; Radar 7441282
+
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"
+target triple = "thumbv7-apple-darwin10"
+
+%struct.__neon_int16x8x2_t = type { <8 x i16>, <8 x i16> }
+%struct.int16x8_t = type { <8 x i16> }
+%struct.int16x8x2_t = type { [2 x %struct.int16x8_t] }
+%union..0anon = type { %struct.int16x8x2_t }
+
+define void @test(<8 x i16> %tmp.0, %struct.int16x8x2_t* %dst) nounwind {
+; CHECK: @test
+; CHECK-NOT: alloca
+; CHECK: "alloca point"
+; CHECK: store <8 x i16>
+; CHECK: store <8 x i16>
+
+entry:
+ %tmp_addr = alloca %struct.int16x8_t
+ %dst_addr = alloca %struct.int16x8x2_t*
+ %__rv = alloca %union..0anon
+ %__bx = alloca %struct.int16x8_t
+ %__ax = alloca %struct.int16x8_t
+ %tmp2 = alloca %struct.int16x8x2_t
+ %0 = alloca %struct.int16x8x2_t
+ %"alloca point" = bitcast i32 0 to i32
+ %1 = getelementptr inbounds %struct.int16x8_t* %tmp_addr, i32 0, i32 0
+ store <8 x i16> %tmp.0, <8 x i16>* %1
+ store %struct.int16x8x2_t* %dst, %struct.int16x8x2_t** %dst_addr
+ %2 = getelementptr inbounds %struct.int16x8_t* %__ax, i32 0, i32 0
+ %3 = getelementptr inbounds %struct.int16x8_t* %tmp_addr, i32 0, i32 0
+ %4 = load <8 x i16>* %3, align 16
+ store <8 x i16> %4, <8 x i16>* %2, align 16
+ %5 = getelementptr inbounds %struct.int16x8_t* %__bx, i32 0, i32 0
+ %6 = getelementptr inbounds %struct.int16x8_t* %tmp_addr, i32 0, i32 0
+ %7 = load <8 x i16>* %6, align 16
+ store <8 x i16> %7, <8 x i16>* %5, align 16
+ %8 = getelementptr inbounds %struct.int16x8_t* %__ax, i32 0, i32 0
+ %9 = load <8 x i16>* %8, align 16
+ %10 = getelementptr inbounds %struct.int16x8_t* %__bx, i32 0, i32 0
+ %11 = load <8 x i16>* %10, align 16
+ %12 = getelementptr inbounds %union..0anon* %__rv, i32 0, i32 0
+ %13 = bitcast %struct.int16x8x2_t* %12 to %struct.__neon_int16x8x2_t*
+ %14 = shufflevector <8 x i16> %9, <8 x i16> %11, <8 x i32> <i32 0, i32 8, i32 2, i32 10, i32 4, i32 12, i32 6, i32 14>
+ %15 = getelementptr inbounds %struct.__neon_int16x8x2_t* %13, i32 0, i32 0
+ store <8 x i16> %14, <8 x i16>* %15
+ %16 = shufflevector <8 x i16> %9, <8 x i16> %11, <8 x i32> <i32 1, i32 9, i32 3, i32 11, i32 5, i32 13, i32 7, i32 15>
+ %17 = getelementptr inbounds %struct.__neon_int16x8x2_t* %13, i32 0, i32 1
+ store <8 x i16> %16, <8 x i16>* %17
+ %18 = getelementptr inbounds %union..0anon* %__rv, i32 0, i32 0
+ %19 = bitcast %struct.int16x8x2_t* %0 to i8*
+ %20 = bitcast %struct.int16x8x2_t* %18 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %19, i8* %20, i32 32, i32 16, i1 false)
+ %tmp21 = bitcast %struct.int16x8x2_t* %tmp2 to i8*
+ %21 = bitcast %struct.int16x8x2_t* %0 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp21, i8* %21, i32 32, i32 16, i1 false)
+ %22 = load %struct.int16x8x2_t** %dst_addr, align 4
+ %23 = bitcast %struct.int16x8x2_t* %22 to i8*
+ %tmp22 = bitcast %struct.int16x8x2_t* %tmp2 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %23, i8* %tmp22, i32 32, i32 16, i1 false)
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+
+; Radar 7466574
+%struct._NSRange = type { i64 }
+
+define void @test_memcpy_self() nounwind {
+entry:
+ %range = alloca %struct._NSRange
+ br i1 undef, label %cond.true, label %cond.false
+
+cond.true: ; preds = %entry
+ %tmp3 = bitcast %struct._NSRange* %range to i8*
+ %tmp4 = bitcast %struct._NSRange* %range to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp3, i8* %tmp4, i32 8, i32 8, i1 false)
+ ret void
+
+cond.false: ; preds = %entry
+ ret void
+
+; CHECK: @test_memcpy_self
+; CHECK-NOT: alloca
+; CHECK: br i1
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2010-01-18-SelfCopy.ll b/src/LLVM/test/Transforms/ScalarRepl/2010-01-18-SelfCopy.ll
new file mode 100644
index 0000000..52df6d5
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2010-01-18-SelfCopy.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; Radar 7552893
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+
+%struct.test = type { [3 x double] }
+
+define void @test_memcpy_self() nounwind {
+; CHECK: @test_memcpy_self
+; CHECK-NOT: alloca
+; CHECK: ret void
+ %1 = alloca %struct.test
+ %2 = bitcast %struct.test* %1 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %2, i8* %2, i32 24, i32 4, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2011-05-06-CapturedAlloca.ll b/src/LLVM/test/Transforms/ScalarRepl/2011-05-06-CapturedAlloca.ll
new file mode 100644
index 0000000..816cb60
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2011-05-06-CapturedAlloca.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR9820
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+@func_1.l_10 = internal unnamed_addr constant [4 x i32] [i32 1, i32 0, i32 0, i32 0], align 16
+
+define i32* @noop(i32* %p_29) nounwind readnone {
+entry:
+ ret i32* %p_29
+}
+
+define i32 @main() nounwind {
+entry:
+ %l_10 = alloca [4 x i32], align 16
+ %tmp = bitcast [4 x i32]* %l_10 to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* bitcast ([4 x i32]* @func_1.l_10 to i8*), i64 16, i32 16, i1 false)
+; CHECK: call void @llvm.memcpy
+ %arrayidx = getelementptr inbounds [4 x i32]* %l_10, i64 0, i64 0
+ %call = call i32* @noop(i32* %arrayidx)
+ store i32 0, i32* %call
+ ret i32 0
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2011-06-08-VectorExtractValue.ll b/src/LLVM/test/Transforms/ScalarRepl/2011-06-08-VectorExtractValue.ll
new file mode 100644
index 0000000..98fa1c6
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2011-06-08-VectorExtractValue.ll
@@ -0,0 +1,64 @@
+; RUN: opt < %s -S -scalarrepl | FileCheck %s
+; RUN: opt < %s -S -scalarrepl-ssa | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.7.0"
+
+%0 = type { <2 x float>, float }
+%struct.PointC3 = type { %struct.array }
+%struct.Point_3 = type { %struct.PointC3 }
+%struct.array = type { [3 x float], [4 x i8] }
+
+; CHECK: main
+; CHECK-NOT: alloca
+; CHECK: %[[A:[a-z0-9]*]] = and i128
+; CHECK: %[[B:[a-z0-9]*]] = trunc i128 %[[A]] to i32
+
+define void @main() uwtable ssp {
+entry:
+ %ref.tmp2 = alloca %0, align 16
+ %tmpcast = bitcast %0* %ref.tmp2 to %struct.Point_3*
+ %0 = getelementptr %0* %ref.tmp2, i64 0, i32 0
+ store <2 x float> zeroinitializer, <2 x float>* %0, align 16
+ %1 = getelementptr inbounds %struct.Point_3* %tmpcast, i64 0, i32 0
+ %base.i.i.i = getelementptr inbounds %struct.PointC3* %1, i64 0, i32 0
+ %arrayidx.i.i.i.i = getelementptr inbounds %struct.array* %base.i.i.i, i64 0, i32 0, i64 0
+ %tmp5.i.i = load float* %arrayidx.i.i.i.i, align 4
+ ret void
+}
+
+; CHECK: test1
+; CHECK-NOT: alloca
+; CHECK: %[[A:[a-z0-9]*]] = and i128
+; CHECK: %[[B:[a-z0-9]*]] = trunc i128 %[[A]] to i32
+
+define void @test1() uwtable ssp {
+entry:
+ %ref.tmp2 = alloca {<2 x float>, float}, align 16
+ %tmpcast = bitcast {<2 x float>, float}* %ref.tmp2 to float*
+ %0 = getelementptr {<2 x float>, float}* %ref.tmp2, i64 0, i32 0
+ store <2 x float> zeroinitializer, <2 x float>* %0, align 16
+ %tmp5.i.i = load float* %tmpcast, align 4
+ ret void
+}
+
+; CHECK: test2
+; CHECK-NOT: alloca
+; CHECK: and i128
+; CHECK: or i128
+; CHECK: trunc i128
+; CHECK-NOT: insertelement
+; CHECK-NOT: extractelement
+
+define float @test2() uwtable ssp {
+entry:
+ %ref.tmp2 = alloca {<2 x float>, float}, align 16
+ %tmpcast = bitcast {<2 x float>, float}* %ref.tmp2 to float*
+ %tmpcast2 = getelementptr {<2 x float>, float}* %ref.tmp2, i64 0, i32 1
+ %0 = getelementptr {<2 x float>, float}* %ref.tmp2, i64 0, i32 0
+ store <2 x float> zeroinitializer, <2 x float>* %0, align 16
+ store float 1.0, float* %tmpcast2, align 4
+ %r1 = load float* %tmpcast, align 4
+ %r2 = load float* %tmpcast2, align 4
+ %r = fadd float %r1, %r2
+ ret float %r
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2011-06-17-VectorPartialMemset.ll b/src/LLVM/test/Transforms/ScalarRepl/2011-06-17-VectorPartialMemset.ll
new file mode 100644
index 0000000..f8530d6
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2011-06-17-VectorPartialMemset.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:64-v128:32:128-a0:0:32-n32"
+target triple = "thumbv7-apple-darwin10"
+
+; CHECK: f
+; CHECK-NOT: alloca
+; CHECK: %[[A:[a-z0-9]*]] = and i128 undef, -16777216
+; CHECK: %[[B:[a-z0-9]*]] = bitcast i128 %[[A]] to <4 x float>
+; CHECK: %[[C:[a-z0-9]*]] = extractelement <4 x float> %[[B]], i32 0
+; CHECK: ret float %[[C]]
+
+define float @f() nounwind ssp {
+entry:
+ %a = alloca <4 x float>, align 16
+ %p = bitcast <4 x float>* %a to i8*
+ call void @llvm.memset.p0i8.i32(i8* %p, i8 0, i32 3, i32 16, i1 false)
+ %vec = load <4 x float>* %a, align 8
+ %val = extractelement <4 x float> %vec, i32 0
+ ret float %val
+}
+
+; CHECK: g
+; CHECK-NOT: alloca
+; CHECK: and i128
+
+define void @g() nounwind ssp {
+entry:
+ %a = alloca { <4 x float> }, align 16
+ %p = bitcast { <4 x float> }* %a to i8*
+ call void @llvm.memset.p0i8.i32(i8* %p, i8 0, i32 16, i32 16, i1 false)
+ %q = bitcast { <4 x float> }* %a to [2 x <2 x float>]*
+ %arrayidx = getelementptr inbounds [2 x <2 x float>]* %q, i32 0, i32 0
+ store <2 x float> undef, <2 x float>* %arrayidx, align 8
+ ret void
+}
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2011-09-22-PHISpeculateInvoke.ll b/src/LLVM/test/Transforms/ScalarRepl/2011-09-22-PHISpeculateInvoke.ll
new file mode 100644
index 0000000..f98f3e8
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2011-09-22-PHISpeculateInvoke.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; PR10987
+
+; Make sure scalarrepl doesn't move a load across an invoke which could
+; modify the loaded value.
+; (The PHI could theoretically be transformed by splitting the critical
+; edge, but scalarrepl doesn't modify the CFG, at least at the moment.)
+
+declare void @extern_fn(i32*)
+declare i32 @extern_fn2(i32)
+declare i32 @__gcc_personality_v0(i32, i64, i8*, i8*)
+
+define void @odd_fn(i1) noinline {
+ %retptr1 = alloca i32
+ %retptr2 = alloca i32
+ br i1 %0, label %then, label %else
+
+then: ; preds = %2
+ invoke void @extern_fn(i32* %retptr1)
+ to label %join unwind label %unwind
+
+else: ; preds = %2
+ store i32 3, i32* %retptr2
+ br label %join
+
+join: ; preds = %then, %else
+ %storemerge.in = phi i32* [ %retptr2, %else ], [ %retptr1, %then ]
+ %storemerge = load i32* %storemerge.in
+ %x3 = call i32 @extern_fn2(i32 %storemerge)
+ ret void
+
+unwind: ; preds = %then
+ %info = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gcc_personality_v0
+ cleanup
+ call void @extern_fn(i32* null)
+ unreachable
+}
+
+; CHECK: define void @odd_fn
+; CHECK: %storemerge.in = phi i32* [ %retptr2, %else ], [ %retptr1, %then ]
diff --git a/src/LLVM/test/Transforms/ScalarRepl/2011-10-11-VectorMemset.ll b/src/LLVM/test/Transforms/ScalarRepl/2011-10-11-VectorMemset.ll
new file mode 100644
index 0000000..9e31231
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/2011-10-11-VectorMemset.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -S -scalarrepl | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.1"
+
+; CHECK: test
+; CHECK-NOT: alloca
+
+define void @test() nounwind {
+entry:
+ %a156286 = alloca [4 x <4 x float>], align 16
+ br i1 undef, label %cif_done, label %for_test158.preheader
+
+for_test158.preheader: ; preds = %entry
+ %a156286305 = bitcast [4 x <4 x float>]* %a156286 to i8*
+ call void @llvm.memset.p0i8.i64(i8* %a156286305, i8 -1, i64 64, i32 16, i1 false)
+ unreachable
+
+cif_done: ; preds = %entry
+ ret void
+}
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/AggregatePromote.ll b/src/LLVM/test/Transforms/ScalarRepl/AggregatePromote.ll
new file mode 100644
index 0000000..bc0b2c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/AggregatePromote.ll
@@ -0,0 +1,51 @@
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep alloca
+
+target datalayout = "E-p:32:32"
+target triple = "powerpc-apple-darwin8.0.0"
+
+define i64 @test1(i64 %X) {
+ %A = alloca i64 ; <i64*> [#uses=3]
+ store i64 %X, i64* %A
+ %B = bitcast i64* %A to i32* ; <i32*> [#uses=1]
+ %C = bitcast i32* %B to i8* ; <i8*> [#uses=1]
+ store i8 0, i8* %C
+ %Y = load i64* %A ; <i64> [#uses=1]
+ ret i64 %Y
+}
+
+define i8 @test2(i64 %X) {
+ %X_addr = alloca i64 ; <i64*> [#uses=2]
+ store i64 %X, i64* %X_addr
+ %tmp.0 = bitcast i64* %X_addr to i32* ; <i32*> [#uses=1]
+ %tmp.1 = getelementptr i32* %tmp.0, i32 1 ; <i32*> [#uses=1]
+ %tmp.2 = bitcast i32* %tmp.1 to i8* ; <i8*> [#uses=1]
+ %tmp.3 = getelementptr i8* %tmp.2, i32 3 ; <i8*> [#uses=1]
+ %tmp.2.upgrd.1 = load i8* %tmp.3 ; <i8> [#uses=1]
+ ret i8 %tmp.2.upgrd.1
+}
+
+define i16 @crafty(i64 %X) {
+ %a = alloca { i64 } ; <{ i64 }*> [#uses=2]
+ %tmp.0 = getelementptr { i64 }* %a, i32 0, i32 0 ; <i64*> [#uses=1]
+ store i64 %X, i64* %tmp.0
+ %tmp.3 = bitcast { i64 }* %a to [4 x i16]* ; <[4 x i16]*> [#uses=2]
+ %tmp.4 = getelementptr [4 x i16]* %tmp.3, i32 0, i32 3 ; <i16*> [#uses=1]
+ %tmp.5 = load i16* %tmp.4 ; <i16> [#uses=1]
+ %tmp.8 = getelementptr [4 x i16]* %tmp.3, i32 0, i32 2 ; <i16*> [#uses=1]
+ %tmp.9 = load i16* %tmp.8 ; <i16> [#uses=1]
+ %tmp.10 = or i16 %tmp.9, %tmp.5 ; <i16> [#uses=1]
+ ret i16 %tmp.10
+}
+
+define i16 @crafty2(i64 %X) {
+ %a = alloca i64 ; <i64*> [#uses=2]
+ store i64 %X, i64* %a
+ %tmp.3 = bitcast i64* %a to [4 x i16]* ; <[4 x i16]*> [#uses=2]
+ %tmp.4 = getelementptr [4 x i16]* %tmp.3, i32 0, i32 3 ; <i16*> [#uses=1]
+ %tmp.5 = load i16* %tmp.4 ; <i16> [#uses=1]
+ %tmp.8 = getelementptr [4 x i16]* %tmp.3, i32 0, i32 2 ; <i16*> [#uses=1]
+ %tmp.9 = load i16* %tmp.8 ; <i16> [#uses=1]
+ %tmp.10 = or i16 %tmp.9, %tmp.5 ; <i16> [#uses=1]
+ ret i16 %tmp.10
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/DifferingTypes.ll b/src/LLVM/test/Transforms/ScalarRepl/DifferingTypes.ll
new file mode 100644
index 0000000..e0aa78f
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/DifferingTypes.ll
@@ -0,0 +1,16 @@
+; This is a feature test. Hopefully one day this will be implemented. The
+; generated code should perform the appropriate masking operations required
+; depending on the endianness of the target...
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @testfunc(i32 %i, i8 %j) {
+ %I = alloca i32 ; <i32*> [#uses=3]
+ store i32 %i, i32* %I
+ %P = bitcast i32* %I to i8* ; <i8*> [#uses=1]
+ store i8 %j, i8* %P
+ %t = load i32* %I ; <i32> [#uses=1]
+ ret i32 %t
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/address-space.ll b/src/LLVM/test/Transforms/ScalarRepl/address-space.ll
new file mode 100644
index 0000000..318d4e7
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/address-space.ll
@@ -0,0 +1,35 @@
+; RUN: opt -S -scalarrepl < %s | FileCheck %s
+; PR7437 - Make sure SROA preserves address space of memcpy when
+; hacking on it.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10"
+
+%struct.anon = type { [1 x float] }
+
+; CHECK: define void @Test(
+; CHECK: load float addrspace(2)*
+; CHECK-NEXT: fsub float
+; CHECK: store float {{.*}}, float addrspace(2)*
+define void @Test(%struct.anon addrspace(2)* %pPtr) nounwind {
+entry:
+ %s = alloca %struct.anon, align 4 ; <%struct.anon*> [#uses=3]
+ %arrayidx = getelementptr inbounds %struct.anon addrspace(2)* %pPtr, i64 0 ; <%struct.anon addrspace(2)*> [#uses=1]
+ %tmp1 = bitcast %struct.anon* %s to i8* ; <i8*> [#uses=1]
+ %tmp2 = bitcast %struct.anon addrspace(2)* %arrayidx to i8 addrspace(2)* ; <i8 addrspace(2)*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p2i8.i64(i8* %tmp1, i8 addrspace(2)* %tmp2, i64 4, i32 4, i1 false)
+ %tmp3 = getelementptr inbounds %struct.anon* %s, i32 0, i32 0 ; <[1 x float]*> [#uses=1]
+ %arrayidx4 = getelementptr inbounds [1 x float]* %tmp3, i32 0, i64 0 ; <float*> [#uses=2]
+ %tmp5 = load float* %arrayidx4 ; <float> [#uses=1]
+ %sub = fsub float %tmp5, 5.000000e+00 ; <float> [#uses=1]
+ store float %sub, float* %arrayidx4
+ %arrayidx7 = getelementptr inbounds %struct.anon addrspace(2)* %pPtr, i64 0 ; <%struct.anon addrspace(2)*> [#uses=1]
+ %tmp8 = bitcast %struct.anon addrspace(2)* %arrayidx7 to i8 addrspace(2)* ; <i8 addrspace(2)*> [#uses=1]
+ %tmp9 = bitcast %struct.anon* %s to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p2i8.p0i8.i64(i8 addrspace(2)* %tmp8, i8* %tmp9, i64 4, i32 4, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p2i8.i64(i8* nocapture, i8 addrspace(2)* nocapture, i64, i32, i1) nounwind
+
+declare void @llvm.memcpy.p2i8.p0i8.i64(i8 addrspace(2)* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/arraytest.ll b/src/LLVM/test/Transforms/ScalarRepl/arraytest.ll
new file mode 100644
index 0000000..75fffef
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/arraytest.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -scalarrepl -mem2reg -S | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @test() {
+ %X = alloca [4 x i32] ; <[4 x i32]*> [#uses=1]
+ %Y = getelementptr [4 x i32]* %X, i64 0, i64 0 ; <i32*> [#uses=2]
+ store i32 0, i32* %Y
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/badarray.ll b/src/LLVM/test/Transforms/ScalarRepl/badarray.ll
new file mode 100644
index 0000000..e9feeb8
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/badarray.ll
@@ -0,0 +1,57 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+
+; PR3466
+; Off end of array, don't transform.
+define i32 @test1() {
+; CHECK: @test1
+; CHECK-NOT: = alloca
+ %X = alloca [4 x i32]
+ %Y = getelementptr [4 x i32]* %X, i64 0, i64 6 ; <i32*> [#uses=2]
+ store i32 0, i32* %Y
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+
+; Off end of array, don't transform.
+define i32 @test2() nounwind {
+entry:
+; CHECK: @test2
+; CHECK-NOT: = alloca
+ %yx2.i = alloca float, align 4 ; <float*> [#uses=1]
+ %yx26.i = bitcast float* %yx2.i to i64* ; <i64*> [#uses=1]
+ %0 = load i64* %yx26.i, align 8 ; <i64> [#uses=0]
+ unreachable
+}
+
+%base = type { i32, [0 x i8] }
+%padded = type { %base, [1 x i32] }
+
+; PR5436
+define void @test3() {
+entry:
+; CHECK: @test3
+; CHECK-NOT: = alloca
+; CHECK: store i64
+ %var_1 = alloca %padded, align 8 ; <%padded*> [#uses=3]
+ %0 = getelementptr inbounds %padded* %var_1, i32 0, i32 0 ; <%base*> [#uses=2]
+
+ %p2 = getelementptr inbounds %base* %0, i32 0, i32 1, i32 0 ; <i8*> [#uses=1]
+ store i8 72, i8* %p2, align 1
+
+ ; 72 -> a[0].
+
+ %callret = call %padded *@test3f() ; <i32> [#uses=2]
+ %callretcast = bitcast %padded* %callret to i8* ; <i8*> [#uses=1]
+ %var_11 = bitcast %padded* %var_1 to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %callretcast, i8* %var_11, i32 8, i32 4, i1 false)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+declare %padded* @test3f()
diff --git a/src/LLVM/test/Transforms/ScalarRepl/basictest.ll b/src/LLVM/test/Transforms/ScalarRepl/basictest.ll
new file mode 100644
index 0000000..2c2fee9
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/basictest.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @test1() {
+ %X = alloca { i32, float } ; <{ i32, float }*> [#uses=1]
+ %Y = getelementptr { i32, float }* %X, i64 0, i32 0 ; <i32*> [#uses=2]
+ store i32 0, i32* %Y
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+; CHECK: @test1
+; CHECK-NOT: alloca
+; CHECK: ret i32 0
+}
+
+; PR8980
+define i64 @test2(i64 %X) {
+ %A = alloca [8 x i8]
+ %B = bitcast [8 x i8]* %A to i64*
+
+ store i64 %X, i64* %B
+ br label %L2
+
+L2:
+ %Z = load i64* %B ; <i32> [#uses=1]
+ ret i64 %Z
+; CHECK: @test2
+; CHECK-NOT: alloca
+; CHECK: ret i64 %X
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/bitfield-sroa.ll b/src/LLVM/test/Transforms/ScalarRepl/bitfield-sroa.ll
new file mode 100644
index 0000000..3728658
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/bitfield-sroa.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+; rdar://6532315
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+%t = type { { i32, i16, i8, i8 } }
+
+define i8 @foo(i64 %A) {
+ %ALL = alloca %t, align 8
+ %tmp59172 = bitcast %t* %ALL to i64*
+ store i64 %A, i64* %tmp59172, align 8
+ %C = getelementptr %t* %ALL, i32 0, i32 0, i32 1
+ %D = bitcast i16* %C to i32*
+ %E = load i32* %D, align 4
+ %F = bitcast %t* %ALL to i8*
+ %G = load i8* %F, align 8
+ ret i8 %G
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/copy-aggregate.ll b/src/LLVM/test/Transforms/ScalarRepl/copy-aggregate.ll
new file mode 100644
index 0000000..51ba810
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/copy-aggregate.ll
@@ -0,0 +1,107 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; PR3290
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+;; Store of integer to whole alloca struct.
+define i32 @test1(i64 %V) nounwind {
+; CHECK: test1
+; CHECK-NOT: alloca
+ %X = alloca {{i32, i32}}
+ %Y = bitcast {{i32,i32}}* %X to i64*
+ store i64 %V, i64* %Y
+
+ %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0
+ %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1
+ %a = load i32* %A
+ %b = load i32* %B
+ %c = add i32 %a, %b
+ ret i32 %c
+}
+
+;; Store of integer to whole struct/array alloca.
+define float @test2(i128 %V) nounwind {
+; CHECK: test2
+; CHECK-NOT: alloca
+ %X = alloca {[4 x float]}
+ %Y = bitcast {[4 x float]}* %X to i128*
+ store i128 %V, i128* %Y
+
+ %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0
+ %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3
+ %a = load float* %A
+ %b = load float* %B
+ %c = fadd float %a, %b
+ ret float %c
+}
+
+;; Load of whole alloca struct as integer
+define i64 @test3(i32 %a, i32 %b) nounwind {
+; CHECK: test3
+; CHECK-NOT: alloca
+ %X = alloca {{i32, i32}}
+
+ %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0
+ %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1
+ store i32 %a, i32* %A
+ store i32 %b, i32* %B
+
+ %Y = bitcast {{i32,i32}}* %X to i64*
+ %Z = load i64* %Y
+ ret i64 %Z
+}
+
+;; load of integer from whole struct/array alloca.
+define i128 @test4(float %a, float %b) nounwind {
+; CHECK: test4
+; CHECK-NOT: alloca
+ %X = alloca {[4 x float]}
+ %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0
+ %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3
+ store float %a, float* %A
+ store float %b, float* %B
+
+ %Y = bitcast {[4 x float]}* %X to i128*
+ %V = load i128* %Y
+ ret i128 %V
+}
+
+;; If the elements of a struct or array alloca contain padding, SROA can still
+;; split up the alloca as long as there is no padding between the elements.
+%padded = type { i16, i8 }
+define void @test5([4 x %padded]* %p, [4 x %padded]* %q) {
+entry:
+; CHECK: test5
+; CHECK-NOT: i128
+ %var = alloca [4 x %padded], align 4
+ %vari8 = bitcast [4 x %padded]* %var to i8*
+ %pi8 = bitcast [4 x %padded]* %p to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %vari8, i8* %pi8, i32 16, i32 4, i1 false)
+ %qi8 = bitcast [4 x %padded]* %q to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %qi8, i8* %vari8, i32 16, i32 4, i1 false)
+ ret void
+}
+
+;; Check that an array alloca can be split up when it is also accessed with
+;; a load or store as a homogeneous structure with the same element type and
+;; number of elements as the array.
+%homogeneous = type { <8 x i16>, <8 x i16>, <8 x i16> }
+%wrapped_array = type { [3 x <8 x i16>] }
+define void @test6(i8* %p, %wrapped_array* %arr) {
+entry:
+; CHECK: test6
+; CHECK: store <8 x i16>
+; CHECK: store <8 x i16>
+; CHECK: store <8 x i16>
+ %var = alloca %wrapped_array, align 16
+ %res = call %homogeneous @test6callee(i8* %p)
+ %varcast = bitcast %wrapped_array* %var to %homogeneous*
+ store %homogeneous %res, %homogeneous* %varcast
+ %tmp1 = bitcast %wrapped_array* %arr to i8*
+ %tmp2 = bitcast %wrapped_array* %var to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp1, i8* %tmp2, i32 48, i32 16, i1 false)
+ ret void
+}
+
+declare %homogeneous @test6callee(i8* nocapture) nounwind
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/crash.ll b/src/LLVM/test/Transforms/ScalarRepl/crash.ll
new file mode 100644
index 0000000..cd4dc32
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/crash.ll
@@ -0,0 +1,264 @@
+; RUN: opt -scalarrepl %s -disable-output
+; RUN: opt -scalarrepl-ssa %s -disable-output
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+; PR9017
+define void @test1() nounwind readnone ssp {
+entry:
+ %l_72 = alloca i32*, align 8
+ unreachable
+
+for.cond: ; preds = %for.cond
+ %tmp1.i = load i32** %l_72, align 8
+ store i32* %tmp1.i, i32** %l_72, align 8
+ br label %for.cond
+
+if.end: ; No predecessors!
+ ret void
+}
+
+
+define void @test2() {
+ %E = alloca { { i32, float, double, i64 }, { i32, float, double, i64 } } ; <{ { i32, float, double, i64 }, { i32, float, double, i64 } }*> [#uses=1]
+ %tmp.151 = getelementptr { { i32, float, double, i64 }, { i32, float, double, i64 } }* %E, i64 0, i32 1, i32 3 ; <i64*> [#uses=0]
+ ret void
+}
+
+define i32 @test3() {
+ %X = alloca { [4 x i32] } ; <{ [4 x i32] }*> [#uses=1]
+ %Y = getelementptr { [4 x i32] }* %X, i64 0, i32 0, i64 2 ; <i32*> [#uses=2]
+ store i32 4, i32* %Y
+ %Z = load i32* %Y ; <i32> [#uses=1]
+ ret i32 %Z
+}
+
+
+%struct.rtx_def = type { [2 x i8], i32, [1 x %union.rtunion_def] }
+%union.rtunion_def = type { i32 }
+
+define void @test4() {
+entry:
+ %c_addr.i = alloca i8 ; <i8*> [#uses=1]
+ switch i32 0, label %return [
+ i32 36, label %label.7
+ i32 34, label %label.7
+ i32 41, label %label.5
+ ]
+label.5: ; preds = %entry
+ ret void
+label.7: ; preds = %entry, %entry
+ br i1 false, label %then.4, label %switchexit.0
+then.4: ; preds = %label.7
+ %tmp.0.i = bitcast i8* %c_addr.i to i32* ; <i32*> [#uses=1]
+ store i32 44, i32* %tmp.0.i
+ ret void
+switchexit.0: ; preds = %label.7
+ ret void
+return: ; preds = %entry
+ ret void
+}
+
+
+define void @test5() {
+entry:
+ %source_ptr = alloca i8*, align 4 ; <i8**> [#uses=2]
+ br i1 false, label %bb1357, label %cond_next583
+cond_next583: ; preds = %entry
+ ret void
+bb1357: ; preds = %entry
+ br i1 false, label %bb1365, label %bb27055
+bb1365: ; preds = %bb1357
+ switch i32 0, label %cond_next10377 [
+ i32 0, label %bb4679
+ i32 1, label %bb4679
+ i32 2, label %bb4679
+ i32 3, label %bb4679
+ i32 4, label %bb5115
+ i32 5, label %bb6651
+ i32 6, label %bb7147
+ i32 7, label %bb8683
+ i32 8, label %bb9131
+ i32 9, label %bb9875
+ i32 10, label %bb4679
+ i32 11, label %bb4859
+ i32 12, label %bb4679
+ i32 16, label %bb10249
+ ]
+bb4679: ; preds = %bb1365, %bb1365, %bb1365, %bb1365, %bb1365, %bb1365
+ ret void
+bb4859: ; preds = %bb1365
+ ret void
+bb5115: ; preds = %bb1365
+ ret void
+bb6651: ; preds = %bb1365
+ ret void
+bb7147: ; preds = %bb1365
+ ret void
+bb8683: ; preds = %bb1365
+ ret void
+bb9131: ; preds = %bb1365
+ ret void
+bb9875: ; preds = %bb1365
+ %source_ptr9884 = bitcast i8** %source_ptr to i8** ; <i8**> [#uses=1]
+ %tmp9885 = load i8** %source_ptr9884 ; <i8*> [#uses=0]
+ ret void
+bb10249: ; preds = %bb1365
+ %source_ptr10257 = bitcast i8** %source_ptr to i16** ; <i16**> [#uses=1]
+ %tmp10258 = load i16** %source_ptr10257 ; <i16*> [#uses=0]
+ ret void
+cond_next10377: ; preds = %bb1365
+ ret void
+bb27055: ; preds = %bb1357
+ ret void
+}
+
+
+ %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>" = type { %"struct.__gnu_cxx::bitmap_allocator<char>::_Alloc_block"* }
+ %"struct.__gnu_cxx::bitmap_allocator<char>" = type { i8 }
+ %"struct.__gnu_cxx::bitmap_allocator<char>::_Alloc_block" = type { [8 x i8] }
+
+; PR1045
+define void @test6() {
+entry:
+ %this_addr.i = alloca %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"* ; <%"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"**> [#uses=3]
+ %tmp = alloca %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>", align 4 ; <%"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"*> [#uses=1]
+ store %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"* %tmp, %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"** %this_addr.i
+ %tmp.i = load %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"** %this_addr.i ; <%"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"*> [#uses=1]
+ %tmp.i.upgrd.1 = bitcast %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"* %tmp.i to %"struct.__gnu_cxx::bitmap_allocator<char>"* ; <%"struct.__gnu_cxx::bitmap_allocator<char>"*> [#uses=0]
+ %tmp1.i = load %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"** %this_addr.i ; <%"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"*> [#uses=1]
+ %tmp.i.upgrd.2 = getelementptr %"struct.__gnu_cxx::balloc::_Inclusive_between<__gnu_cxx::bitmap_allocator<char>::_Alloc_block*>"* %tmp1.i, i32 0, i32 0 ; <%"struct.__gnu_cxx::bitmap_allocator<char>::_Alloc_block"**> [#uses=0]
+ unreachable
+}
+
+ %struct.CGPoint = type { float, float }
+ %struct.aal_big_range_t = type { i32, i32 } %struct.aal_callback_t = type { i8* (i8*, i32)*, void (i8*, i8*)* } %struct.aal_edge_pool_t = type { %struct.aal_edge_pool_t*, i32, i32, [0 x %struct.aal_edge_t] } %struct.aal_edge_t = type { %struct.CGPoint, %struct.CGPoint, i32 }
+ %struct.aal_range_t = type { i16, i16 }
+ %struct.aal_span_pool_t = type { %struct.aal_span_pool_t*, [341 x %struct.aal_span_t] }
+ %struct.aal_span_t = type { %struct.aal_span_t*, %struct.aal_big_range_t }
+ %struct.aal_spanarray_t = type { [2 x %struct.aal_range_t] }
+ %struct.aal_spanbucket_t = type { i16, [2 x i8], %struct.anon }
+ %struct.aal_state_t = type { %struct.CGPoint, %struct.CGPoint, %struct.CGPoint, i32, float, float, float, float, %struct.CGPoint, %struct.CGPoint, float, float, float, float, i32, i32, i32, i32, float, float, i8*, i32, i32, %struct.aal_edge_pool_t*, %struct.aal_edge_pool_t*, i8*, %struct.aal_callback_t*, i32, %struct.aal_span_t*, %struct.aal_span_t*, %struct.aal_span_t*, %struct.aal_span_pool_t*, i8, float, i8, i32 }
+ %struct.anon = type { %struct.aal_spanarray_t }
+
+
+
+define fastcc void @test7() {
+entry:
+ %SB = alloca %struct.aal_spanbucket_t, align 4 ; <%struct.aal_spanbucket_t*> [#uses=2]
+ br i1 false, label %cond_true, label %cond_next79
+
+cond_true: ; preds = %entry
+ br i1 false, label %cond_next, label %cond_next114.i
+
+cond_next114.i: ; preds = %cond_true
+ ret void
+
+cond_next: ; preds = %cond_true
+ %SB19 = bitcast %struct.aal_spanbucket_t* %SB to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %SB19, i8* null, i32 12, i32 0, i1 false)
+ br i1 false, label %cond_next34, label %cond_next79
+
+cond_next34: ; preds = %cond_next
+ %i.2.reload22 = load i32* null ; <i32> [#uses=1]
+ %tmp51 = getelementptr %struct.aal_spanbucket_t* %SB, i32 0, i32 2, i32 0, i32 0, i32 %i.2.reload22, i32 1
+ ; <i16*> [#uses=0]
+ ret void
+
+cond_next79: ; preds = %cond_next, %entry
+ ret void
+}
+
+
+ %struct.c37304a__vrec = type { i8, %struct.c37304a__vrec___disc___XVN }
+ %struct.c37304a__vrec___disc___XVN = type {
+%struct.c37304a__vrec___disc___XVN___O }
+ %struct.c37304a__vrec___disc___XVN___O = type { }
+
+; PR3304
+define void @test8() {
+entry:
+ %v = alloca %struct.c37304a__vrec
+ %0 = getelementptr %struct.c37304a__vrec* %v, i32 0, i32 0
+ store i8 8, i8* %0, align 1
+ unreachable
+}
+
+
+
+; rdar://6808691 - ZeroLengthMemSet
+ %0 = type <{ i32, i16, i8, i8, i64, i64, i16, [0 x i16] }>
+
+define i32 @test9() {
+entry:
+ %.compoundliteral = alloca %0
+ %tmp228 = getelementptr %0* %.compoundliteral, i32 0, i32 7
+ %tmp229 = bitcast [0 x i16]* %tmp228 to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp229, i8 0, i64 0, i32 2, i1 false)
+ unreachable
+}
+
+declare void @llvm.memset.i64(i8* nocapture, i8, i64, i32) nounwind
+
+
+; PR4146 - i1 handling
+%wrapper = type { i1 }
+define void @test10() {
+entry:
+ %w = alloca %wrapper, align 8 ; <%wrapper*> [#uses=1]
+ %0 = getelementptr %wrapper* %w, i64 0, i32 0 ; <i1*>
+ store i1 true, i1* %0
+ ret void
+}
+
+
+ %struct.singlebool = type <{ i8 }>
+; PR4286
+define zeroext i8 @test11() nounwind {
+entry:
+ %a = alloca %struct.singlebool, align 1 ; <%struct.singlebool*> [#uses=2]
+ %storetmp.i = bitcast %struct.singlebool* %a to i1* ; <i1*> [#uses=1]
+ store i1 true, i1* %storetmp.i
+ %tmp = getelementptr %struct.singlebool* %a, i64 0, i32 0 ; <i8*> [#uses=1]
+ %tmp1 = load i8* %tmp ; <i8> [#uses=1]
+ ret i8 %tmp1
+}
+
+
+ %struct.Item = type { [4 x i16], %struct.rule* }
+ %struct.rule = type { [4 x i16], i32, i32, i32, %struct.nonterminal*, %struct.pattern*, i8 }
+ %struct.nonterminal = type { i8*, i32, i32, i32, %struct.plankMap*, %struct.rule* }
+ %struct.plankMap = type { %struct.list*, i32, %struct.stateMap* }
+ %struct.list = type { i8*, %struct.list* }
+ %struct.stateMap = type { i8*, %struct.plank*, i32, i16* }
+ %struct.plank = type { i8*, %struct.list*, i32 }
+ %struct.pattern = type { %struct.nonterminal*, %struct.operator*, [2 x %struct.nonterminal*] }
+ %struct.operator = type { i8*, i8, i32, i32, i32, i32, %struct.table* }
+ %struct.table = type { %struct.operator*, %struct.list*, i16*, [2 x %struct.dimension*], %struct.item_set** }
+ %struct.dimension = type { i16*, %struct.Index_Map, %struct.mapping*, i32, %struct.plankMap* }
+ %struct.Index_Map = type { i32, %struct.item_set** }
+ %struct.item_set = type { i32, i32, %struct.operator*, [2 x %struct.item_set*], %struct.item_set*, i16*, %struct.Item*, %struct.Item* }
+ %struct.mapping = type { %struct.list**, i32, i32, i32, %struct.item_set** }
+
+; VLAs.
+define void @test12() {
+bb4.i:
+ %malloccall = tail call i8* @malloc(i32 0)
+ %0 = bitcast i8* %malloccall to [0 x %struct.Item]*
+ %.sub.i.c.i = getelementptr [0 x %struct.Item]* %0, i32 0, i32 0 ; <%struct.Item*> [#uses=0]
+ unreachable
+}
+declare noalias i8* @malloc(i32)
+
+; PR8680
+define void @test13() nounwind {
+entry:
+ %memtmp = alloca i32, align 4
+ %0 = bitcast i32* %memtmp to void ()*
+ call void %0() nounwind
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/debuginfo-preserved.ll b/src/LLVM/test/Transforms/ScalarRepl/debuginfo-preserved.ll
new file mode 100644
index 0000000..c149134
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/debuginfo-preserved.ll
@@ -0,0 +1,61 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; RUN: opt < %s -scalarrepl-ssa -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-macosx10.6.0"
+
+; CHECK: f
+; CHECK-NOT: llvm.dbg.declare
+; CHECK: llvm.dbg.value
+; CHECK: llvm.dbg.value
+; CHECK: llvm.dbg.value
+; CHECK: llvm.dbg.value
+; CHECK: llvm.dbg.value
+
+define i32 @f(i32 %a, i32 %b) nounwind ssp {
+entry:
+ %a.addr = alloca i32, align 4
+ %b.addr = alloca i32, align 4
+ %c = alloca i32, align 4
+ store i32 %a, i32* %a.addr, align 4
+ call void @llvm.dbg.declare(metadata !{i32* %a.addr}, metadata !6), !dbg !7
+ store i32 %b, i32* %b.addr, align 4
+ call void @llvm.dbg.declare(metadata !{i32* %b.addr}, metadata !8), !dbg !9
+ call void @llvm.dbg.declare(metadata !{i32* %c}, metadata !10), !dbg !12
+ %tmp = load i32* %a.addr, align 4, !dbg !13
+ store i32 %tmp, i32* %c, align 4, !dbg !13
+ %tmp1 = load i32* %a.addr, align 4, !dbg !14
+ %tmp2 = load i32* %b.addr, align 4, !dbg !14
+ %add = add nsw i32 %tmp1, %tmp2, !dbg !14
+ store i32 %add, i32* %a.addr, align 4, !dbg !14
+ %tmp3 = load i32* %c, align 4, !dbg !15
+ %tmp4 = load i32* %b.addr, align 4, !dbg !15
+ %sub = sub nsw i32 %tmp3, %tmp4, !dbg !15
+ store i32 %sub, i32* %b.addr, align 4, !dbg !15
+ %tmp5 = load i32* %a.addr, align 4, !dbg !16
+ %tmp6 = load i32* %b.addr, align 4, !dbg !16
+ %add7 = add nsw i32 %tmp5, %tmp6, !dbg !16
+ ret i32 %add7, !dbg !16
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+!llvm.dbg.cu = !{!0}
+!llvm.dbg.sp = !{!1}
+
+!0 = metadata !{i32 589841, i32 0, i32 12, metadata !"/d/j/debug-test.c", metadata !"/Volumes/Data/b", metadata !"clang version 3.0 (trunk 131941)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!1 = metadata !{i32 589870, i32 0, metadata !2, metadata !"f", metadata !"f", metadata !"", metadata !2, i32 1, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, i32 (i32, i32)* @f, null, null} ; [ DW_TAG_subprogram ]
+!2 = metadata !{i32 589865, metadata !"/d/j/debug-test.c", metadata !"/Volumes/Data/b", metadata !0} ; [ DW_TAG_file_type ]
+!3 = metadata !{i32 589845, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{metadata !5}
+!5 = metadata !{i32 589860, metadata !0, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!6 = metadata !{i32 590081, metadata !1, metadata !"a", metadata !2, i32 16777217, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!7 = metadata !{i32 1, i32 11, metadata !1, null}
+!8 = metadata !{i32 590081, metadata !1, metadata !"b", metadata !2, i32 33554433, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!9 = metadata !{i32 1, i32 18, metadata !1, null}
+!10 = metadata !{i32 590080, metadata !11, metadata !"c", metadata !2, i32 2, metadata !5, i32 0} ; [ DW_TAG_auto_variable ]
+!11 = metadata !{i32 589835, metadata !1, i32 1, i32 21, metadata !2, i32 0} ; [ DW_TAG_lexical_block ]
+!12 = metadata !{i32 2, i32 9, metadata !11, null}
+!13 = metadata !{i32 2, i32 14, metadata !11, null}
+!14 = metadata !{i32 3, i32 5, metadata !11, null}
+!15 = metadata !{i32 4, i32 5, metadata !11, null}
+!16 = metadata !{i32 5, i32 5, metadata !11, null}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/debuginfo.ll b/src/LLVM/test/Transforms/ScalarRepl/debuginfo.ll
new file mode 100644
index 0000000..ae2c6cc
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/debuginfo.ll
@@ -0,0 +1,107 @@
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+; RUN: opt < %s -scalarrepl-ssa -S | not grep alloca
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+ %llvm.dbg.composite.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }*, { }* }
+ %llvm.dbg.derivedtype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }* }
+ %llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 }
+ %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }* }
+ %struct.Sphere = type { %struct.Vec }
+ %struct.Vec = type { i32, i32, i32 }
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@.str = internal constant [6 x i8] c"r.cpp\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str1 = internal constant [5 x i8] c"/tmp\00", section "llvm.metadata" ; <[5 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 4, i8* getelementptr ([6 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([5 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+@.str3 = internal constant [4 x i8] c"Vec\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str4 = internal constant [4 x i8] c"int\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type { i32 458788, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@.str5 = internal constant [2 x i8] c"x\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.derivedtype = internal constant %llvm.dbg.derivedtype.type { i32 458765, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([2 x i8]* @.str5, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@.str6 = internal constant [2 x i8] c"y\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.derivedtype7 = internal constant %llvm.dbg.derivedtype.type { i32 458765, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([2 x i8]* @.str6, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, i64 32, i64 32, i64 32, i32 0, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@.str8 = internal constant [2 x i8] c"z\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.derivedtype9 = internal constant %llvm.dbg.derivedtype.type { i32 458765, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([2 x i8]* @.str8, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, i64 32, i64 32, i64 64, i32 0, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.derivedtype10 = internal constant %llvm.dbg.derivedtype.type { i32 458767, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.derivedtype11 = internal constant %llvm.dbg.derivedtype.type { i32 458790, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 96, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.derivedtype12 = internal constant %llvm.dbg.derivedtype.type { i32 458768, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype11 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.array = internal constant [3 x { }*] [ { }* null, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype10 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype12 to { }*) ], section "llvm.metadata" ; <[3 x { }*]*> [#uses=1]
+@llvm.dbg.composite13 = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([3 x { }*]* @llvm.dbg.array to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 2, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite13 to { }*), i1 false, i1 false }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@llvm.dbg.array14 = internal constant [5 x { }*] [ { }* null, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype10 to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) ], section "llvm.metadata" ; <[5 x { }*]*> [#uses=1]
+@llvm.dbg.composite15 = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([5 x { }*]* @llvm.dbg.array14 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.subprogram16 = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 5, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite15 to { }*), i1 false, i1 false }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@llvm.dbg.array17 = internal constant [5 x { }*] [ { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype7 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype9 to { }*), { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*), { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram16 to { }*) ], section "llvm.metadata" ; <[5 x { }*]*> [#uses=1]
+@llvm.dbg.composite18 = internal constant %llvm.dbg.composite.type { i32 458771, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 2, i64 96, i64 32, i64 0, i32 0, { }* null, { }* bitcast ([5 x { }*]* @llvm.dbg.array17 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.derivedtype19 = internal constant %llvm.dbg.derivedtype.type { i32 458767, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.array20 = internal constant [5 x { }*] [ { }* null, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype19 to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) ], section "llvm.metadata" ; <[5 x { }*]*> [#uses=1]
+@llvm.dbg.composite = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([5 x { }*]* @llvm.dbg.array20 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@.str21 = internal constant [13 x i8] c"__comp_ctor \00", section "llvm.metadata" ; <[13 x i8]*> [#uses=1]
+@.str22 = internal constant [14 x i8] c"_ZN3VecC1Eiii\00", section "llvm.metadata" ; <[14 x i8]*> [#uses=1]
+@llvm.dbg.array32 = internal constant [3 x { }*] [ { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype12 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype12 to { }*) ], section "llvm.metadata" ; <[3 x { }*]*> [#uses=1]
+@llvm.dbg.composite33 = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([3 x { }*]* @llvm.dbg.array32 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@.str34 = internal constant [10 x i8] c"operator-\00", section "llvm.metadata" ; <[10 x i8]*> [#uses=1]
+@.str35 = internal constant [14 x i8] c"_ZmiRK3VecS1_\00", section "llvm.metadata" ; <[14 x i8]*> [#uses=1]
+@.str41 = internal constant [7 x i8] c"Sphere\00", section "llvm.metadata" ; <[7 x i8]*> [#uses=1]
+@.str43 = internal constant [7 x i8] c"center\00", section "llvm.metadata" ; <[7 x i8]*> [#uses=1]
+@llvm.dbg.derivedtype44 = internal constant %llvm.dbg.derivedtype.type { i32 458765, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([7 x i8]* @.str43, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 14, i64 96, i64 32, i64 0, i32 1, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.derivedtype45 = internal constant %llvm.dbg.derivedtype.type { i32 458767, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite52 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.array46 = internal constant [3 x { }*] [ { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype45 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype12 to { }*) ], section "llvm.metadata" ; <[3 x { }*]*> [#uses=1]
+@llvm.dbg.composite47 = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([3 x { }*]* @llvm.dbg.array46 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@.str48 = internal constant [11 x i8] c"ray_sphere\00", section "llvm.metadata" ; <[11 x i8]*> [#uses=1]
+@.str49 = internal constant [30 x i8] c"_ZN6Sphere10ray_sphereERK3Vec\00", section "llvm.metadata" ; <[30 x i8]*> [#uses=1]
+@llvm.dbg.subprogram50 = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([11 x i8]* @.str48, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str48, i32 0, i32 0), i8* getelementptr ([30 x i8]* @.str49, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 16, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite47 to { }*), i1 false, i1 false }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@llvm.dbg.array51 = internal constant [2 x { }*] [ { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype44 to { }*), { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram50 to { }*) ], section "llvm.metadata" ; <[2 x { }*]*> [#uses=1]
+@llvm.dbg.composite52 = internal constant %llvm.dbg.composite.type { i32 458771, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([7 x i8]* @.str41, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 12, i64 96, i64 32, i64 0, i32 0, { }* null, { }* bitcast ([2 x { }*]* @llvm.dbg.array51 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.derivedtype53 = internal constant %llvm.dbg.derivedtype.type { i32 458767, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite52 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@llvm.dbg.array54 = internal constant [3 x { }*] [ { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype53 to { }*), { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype12 to { }*) ], section "llvm.metadata" ; <[3 x { }*]*> [#uses=1]
+@llvm.dbg.composite55 = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([3 x { }*]* @llvm.dbg.array54 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.subprogram56 = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([11 x i8]* @.str48, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str48, i32 0, i32 0), i8* getelementptr ([30 x i8]* @.str49, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 16, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite55 to { }*), i1 false, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@.str61 = internal constant [2 x i8] c"v\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.variable62 = internal constant %llvm.dbg.variable.type { i32 459008, { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram56 to { }*), i8* getelementptr ([2 x i8]* @.str61, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 17, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite18 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.variable.type*> [#uses=1]
+
+declare void @llvm.dbg.func.start({ }*) nounwind
+
+declare void @llvm.dbg.declare({ }*, { }*) nounwind
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+declare void @llvm.dbg.region.end({ }*) nounwind
+
+define i32 @_ZN6Sphere10ray_sphereERK3Vec(%struct.Sphere* %this, %struct.Vec* %Orig) nounwind {
+entry:
+ %v = alloca %struct.Vec, align 8 ; <%struct.Vec*> [#uses=4]
+ call void @llvm.dbg.func.start({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram56 to { }*))
+ %0 = bitcast %struct.Vec* %v to { }* ; <{ }*> [#uses=1]
+ call void @llvm.dbg.declare({ }* %0, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable62 to { }*))
+ %1 = getelementptr %struct.Sphere* %this, i32 0, i32 0, i32 2 ; <i32*> [#uses=1]
+ %2 = load i32* %1, align 4 ; <i32> [#uses=1]
+ %3 = getelementptr %struct.Vec* %Orig, i32 0, i32 2 ; <i32*> [#uses=1]
+ %4 = load i32* %3, align 4 ; <i32> [#uses=1]
+ %5 = sub i32 %2, %4 ; <i32> [#uses=1]
+ %6 = getelementptr %struct.Sphere* %this, i32 0, i32 0, i32 1 ; <i32*> [#uses=1]
+ %7 = load i32* %6, align 4 ; <i32> [#uses=1]
+ %8 = getelementptr %struct.Vec* %Orig, i32 0, i32 1 ; <i32*> [#uses=1]
+ %9 = load i32* %8, align 4 ; <i32> [#uses=1]
+ %10 = sub i32 %7, %9 ; <i32> [#uses=1]
+ %11 = getelementptr %struct.Sphere* %this, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
+ %12 = load i32* %11, align 4 ; <i32> [#uses=1]
+ %13 = getelementptr %struct.Vec* %Orig, i32 0, i32 0 ; <i32*> [#uses=1]
+ %14 = load i32* %13, align 4 ; <i32> [#uses=1]
+ %15 = sub i32 %12, %14 ; <i32> [#uses=1]
+ %16 = getelementptr %struct.Vec* %v, i32 0, i32 0 ; <i32*> [#uses=2]
+ store i32 %15, i32* %16, align 8
+ %17 = getelementptr %struct.Vec* %v, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 %10, i32* %17, align 4
+ %18 = getelementptr %struct.Vec* %v, i32 0, i32 2 ; <i32*> [#uses=1]
+ store i32 %5, i32* %18, align 8
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*)) nounwind
+ call void @llvm.dbg.stoppoint(i32 9, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*)) nounwind
+ %19 = load i32* %16, align 8 ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 18, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ call void @llvm.dbg.region.end({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram56 to { }*))
+ ret i32 %19
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/dg.exp b/src/LLVM/test/Transforms/ScalarRepl/dg.exp
new file mode 100644
index 0000000..1a4e1b1
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]]
diff --git a/src/LLVM/test/Transforms/ScalarRepl/inline-vector.ll b/src/LLVM/test/Transforms/ScalarRepl/inline-vector.ll
new file mode 100644
index 0000000..2f51cc7
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/inline-vector.ll
@@ -0,0 +1,53 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+; RUN: opt < %s -scalarrepl-ssa -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"
+target triple = "thumbv7-apple-darwin10.0.0"
+
+%struct.Vector4 = type { float, float, float, float }
+@f.vector = internal constant %struct.Vector4 { float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 }, align 16
+
+; CHECK: define void @f
+; CHECK-NOT: alloca
+; CHECK: phi <4 x float>
+
+define void @f() nounwind ssp {
+entry:
+ %i = alloca i32, align 4
+ %vector = alloca %struct.Vector4, align 16
+ %agg.tmp = alloca %struct.Vector4, align 16
+ %tmp = bitcast %struct.Vector4* %vector to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp, i8* bitcast (%struct.Vector4* @f.vector to i8*), i32 16, i32 16, i1 false)
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ %storemerge = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ store i32 %storemerge, i32* %i, align 4
+ %cmp = icmp slt i32 %storemerge, 1000000
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %tmp2 = bitcast %struct.Vector4* %agg.tmp to i8*
+ %tmp3 = bitcast %struct.Vector4* %vector to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp2, i8* %tmp3, i32 16, i32 16, i1 false)
+ %0 = bitcast %struct.Vector4* %agg.tmp to [2 x i64]*
+ %1 = load [2 x i64]* %0, align 16
+ %tmp2.i = extractvalue [2 x i64] %1, 0
+ %tmp3.i = zext i64 %tmp2.i to i128
+ %tmp10.i = bitcast i128 %tmp3.i to <4 x float>
+ %sub.i.i = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %tmp10.i
+ %2 = bitcast %struct.Vector4* %vector to <4 x float>*
+ store <4 x float> %sub.i.i, <4 x float>* %2, align 16
+ %tmp4 = load i32* %i, align 4
+ %inc = add nsw i32 %tmp4, 1
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ %x = getelementptr inbounds %struct.Vector4* %vector, i32 0, i32 0
+ %tmp5 = load float* %x, align 16
+ %conv = fpext float %tmp5 to double
+ %call = call i32 (...)* @printf(double %conv) nounwind
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+declare i32 @printf(...)
diff --git a/src/LLVM/test/Transforms/ScalarRepl/lifetime.ll b/src/LLVM/test/Transforms/ScalarRepl/lifetime.ll
new file mode 100644
index 0000000..3f558a1
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/lifetime.ll
@@ -0,0 +1,139 @@
+; RUN: opt -scalarrepl -S < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @llvm.lifetime.start(i64, i8*)
+declare void @llvm.lifetime.end(i64, i8*)
+
+%t1 = type {i32, i32, i32}
+
+define void @test1() {
+; CHECK: @test1
+ %A = alloca %t1
+ %A1 = getelementptr %t1* %A, i32 0, i32 0
+ %A2 = getelementptr %t1* %A, i32 0, i32 1
+ %A3 = getelementptr %t1* %A, i32 0, i32 2
+ %B = bitcast i32* %A1 to i8*
+ store i32 0, i32* %A1
+ call void @llvm.lifetime.start(i64 -1, i8* %B)
+ ret void
+; CHECK-NEXT: ret void
+}
+
+define void @test2() {
+; CHECK: @test2
+ %A = alloca %t1
+ %A1 = getelementptr %t1* %A, i32 0, i32 0
+ %A2 = getelementptr %t1* %A, i32 0, i32 1
+ %A3 = getelementptr %t1* %A, i32 0, i32 2
+ %B = bitcast i32* %A2 to i8*
+ store i32 0, i32* %A2
+ call void @llvm.lifetime.start(i64 -1, i8* %B)
+ %C = load i32* %A2
+ ret void
+; CHECK: ret void
+}
+
+define void @test3() {
+; CHECK: @test3
+ %A = alloca %t1
+ %A1 = getelementptr %t1* %A, i32 0, i32 0
+ %A2 = getelementptr %t1* %A, i32 0, i32 1
+ %A3 = getelementptr %t1* %A, i32 0, i32 2
+ %B = bitcast i32* %A2 to i8*
+ store i32 0, i32* %A2
+ call void @llvm.lifetime.start(i64 6, i8* %B)
+ %C = load i32* %A2
+ ret void
+; CHECK-NEXT: ret void
+}
+
+define void @test4() {
+; CHECK: @test4
+ %A = alloca %t1
+ %A1 = getelementptr %t1* %A, i32 0, i32 0
+ %A2 = getelementptr %t1* %A, i32 0, i32 1
+ %A3 = getelementptr %t1* %A, i32 0, i32 2
+ %B = bitcast i32* %A2 to i8*
+ store i32 0, i32* %A2
+ call void @llvm.lifetime.start(i64 1, i8* %B)
+ %C = load i32* %A2
+ ret void
+; CHECK-NEXT: ret void
+}
+
+%t2 = type {i32, [4 x i8], i32}
+
+define void @test5() {
+; CHECK: @test5
+ %A = alloca %t2
+; CHECK: alloca{{.*}}i8
+; CHECK: alloca{{.*}}i8
+; CHECK: alloca{{.*}}i8
+
+ %A21 = getelementptr %t2* %A, i32 0, i32 1, i32 0
+ %A22 = getelementptr %t2* %A, i32 0, i32 1, i32 1
+ %A23 = getelementptr %t2* %A, i32 0, i32 1, i32 2
+ %A24 = getelementptr %t2* %A, i32 0, i32 1, i32 3
+; CHECK-NOT: store i8 1
+ store i8 1, i8* %A21
+ store i8 2, i8* %A22
+ store i8 3, i8* %A23
+ store i8 4, i8* %A24
+
+ %A1 = getelementptr %t2* %A, i32 0, i32 0
+ %A2 = getelementptr %t2* %A, i32 0, i32 1, i32 1
+ %A3 = getelementptr %t2* %A, i32 0, i32 2
+ store i8 0, i8* %A2
+ call void @llvm.lifetime.start(i64 5, i8* %A2)
+; CHECK: llvm.lifetime{{.*}}i64 1
+; CHECK: llvm.lifetime{{.*}}i64 1
+; CHECK: llvm.lifetime{{.*}}i64 1
+ %C = load i8* %A2
+ ret void
+}
+
+%t3 = type {[4 x i16], [4 x i8]}
+
+define void @test6() {
+; CHECK: @test6
+ %A = alloca %t3
+; CHECK: alloca i8
+; CHECK: alloca i8
+; CHECK: alloca i8
+
+ %A11 = getelementptr %t3* %A, i32 0, i32 0, i32 0
+ %A12 = getelementptr %t3* %A, i32 0, i32 0, i32 1
+ %A13 = getelementptr %t3* %A, i32 0, i32 0, i32 2
+ %A14 = getelementptr %t3* %A, i32 0, i32 0, i32 3
+ store i16 11, i16* %A11
+ store i16 12, i16* %A12
+ store i16 13, i16* %A13
+ store i16 14, i16* %A14
+; CHECK-NOT: store i16 11
+; CHECK-NOT: store i16 12
+; CHECK-NOT: store i16 13
+; CHECK-NOT: store i16 14
+
+ %A21 = getelementptr %t3* %A, i32 0, i32 1, i32 0
+ %A22 = getelementptr %t3* %A, i32 0, i32 1, i32 1
+ %A23 = getelementptr %t3* %A, i32 0, i32 1, i32 2
+ %A24 = getelementptr %t3* %A, i32 0, i32 1, i32 3
+ store i8 21, i8* %A21
+ store i8 22, i8* %A22
+ store i8 23, i8* %A23
+ store i8 24, i8* %A24
+; CHECK: store i8 21
+; CHECK: store i8 22
+; CHECK: store i8 23
+; CHECK-NOT: store i8 24
+
+ %B = bitcast i16* %A13 to i8*
+ call void @llvm.lifetime.start(i64 7, i8* %B)
+; CHECK: lifetime.start{{.*}}i64 1
+; CHECK: lifetime.start{{.*}}i64 1
+; CHECK: lifetime.start{{.*}}i64 1
+
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/load-store-aggregate.ll b/src/LLVM/test/Transforms/ScalarRepl/load-store-aggregate.ll
new file mode 100644
index 0000000..c5008ac
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/load-store-aggregate.ll
@@ -0,0 +1,31 @@
+; This testcase shows that scalarrepl is able to replace struct alloca's which
+; are directly loaded from or stored to (using the first class aggregates
+; feature).
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+; RUN: opt < %s -scalarrepl -S > %t
+; RUN: cat %t | not grep alloca
+
+%struct.foo = type { i32, i32 }
+
+define i32 @test(%struct.foo* %P) {
+entry:
+ %L = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
+ %V = load %struct.foo* %P
+ store %struct.foo %V, %struct.foo* %L
+
+ %tmp4 = getelementptr %struct.foo* %L, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %tmp4 ; <i32> [#uses=1]
+ ret i32 %tmp5
+}
+
+define %struct.foo @test2(i32 %A, i32 %B) {
+entry:
+ %L = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
+ %L.0 = getelementptr %struct.foo* %L, i32 0, i32 0
+ store i32 %A, i32* %L.0
+ %L.1 = getelementptr %struct.foo* %L, i32 0, i32 1
+ store i32 %B, i32* %L.1
+ %V = load %struct.foo* %L
+ ret %struct.foo %V
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/memcpy-align.ll b/src/LLVM/test/Transforms/ScalarRepl/memcpy-align.ll
new file mode 100644
index 0000000..a7af208
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/memcpy-align.ll
@@ -0,0 +1,32 @@
+; RUN: opt %s -scalarrepl -S | FileCheck %s
+; PR6832
+target datalayout =
+"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32"
+target triple = "arm-u-u"
+
+%0 = type { %struct.anon, %struct.anon }
+%struct.anon = type { [4 x i8] }
+
+@c = external global %0 ; <%0*> [#uses=1]
+
+define void @good() nounwind {
+entry:
+ %x0 = alloca %struct.anon, align 4 ; <%struct.anon*> [#uses=2]
+ %tmp = bitcast %struct.anon* %x0 to i8* ; <i8*> [#uses=1]
+ call void @llvm.memset.p0i8.i32(i8* %tmp, i8 0, i32 4, i32 4, i1 false)
+ %tmp1 = bitcast %struct.anon* %x0 to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* getelementptr inbounds (%0* @c, i32
+0, i32 0, i32 0, i32 0), i8* %tmp1, i32 4, i32 4, i1 false)
+ ret void
+
+; CHECK: store i8 0, i8*{{.*}}, align 4
+; CHECK: store i8 0, i8*{{.*}}, align 1
+; CHECK: store i8 0, i8*{{.*}}, align 2
+; CHECK: store i8 0, i8*{{.*}}, align 1
+}
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32,
+i1) nounwind
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/memcpy-from-global.ll b/src/LLVM/test/Transforms/ScalarRepl/memcpy-from-global.ll
new file mode 100644
index 0000000..81f7b6a
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/memcpy-from-global.ll
@@ -0,0 +1,110 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+@C.0.1248 = internal constant [128 x float] [ float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 ], align 32 ; <[128 x float]*> [#uses=1]
+
+define float @test1(i32 %hash, float %x, float %y, float %z, float %w) {
+entry:
+ %lookupTable = alloca [128 x float], align 16 ; <[128 x float]*> [#uses=5]
+ %lookupTable1 = bitcast [128 x float]* %lookupTable to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.i32( i8* %lookupTable1, i8* bitcast ([128 x float]* @C.0.1248 to i8*), i32 512, i32 16 )
+
+; CHECK: @test1
+; CHECK-NOT: alloca
+; CHECK-NOT: call{{.*}}@llvm.memcpy
+; CHECK: %lookupTable1 = bitcast [128 x float]* @C.0.1248 to i8*
+; CHECK-NOT: call{{.*}}@llvm.memcpy
+
+ %tmp3 = shl i32 %hash, 2 ; <i32> [#uses=1]
+ %tmp5 = and i32 %tmp3, 124 ; <i32> [#uses=4]
+ %tmp753 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp5 ; <float*> [#uses=1]
+ %tmp9 = load float* %tmp753 ; <float> [#uses=1]
+ %tmp11 = fmul float %tmp9, %x ; <float> [#uses=1]
+ %tmp13 = fadd float %tmp11, 0.000000e+00 ; <float> [#uses=1]
+ %tmp17.sum52 = or i32 %tmp5, 1 ; <i32> [#uses=1]
+ %tmp1851 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp17.sum52 ; <float*> [#uses=1]
+ %tmp19 = load float* %tmp1851 ; <float> [#uses=1]
+ %tmp21 = fmul float %tmp19, %y ; <float> [#uses=1]
+ %tmp23 = fadd float %tmp21, %tmp13 ; <float> [#uses=1]
+ %tmp27.sum50 = or i32 %tmp5, 2 ; <i32> [#uses=1]
+ %tmp2849 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp27.sum50 ; <float*> [#uses=1]
+ %tmp29 = load float* %tmp2849 ; <float> [#uses=1]
+ %tmp31 = fmul float %tmp29, %z ; <float> [#uses=1]
+ %tmp33 = fadd float %tmp31, %tmp23 ; <float> [#uses=1]
+ %tmp37.sum48 = or i32 %tmp5, 3 ; <i32> [#uses=1]
+ %tmp3847 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp37.sum48 ; <float*> [#uses=1]
+ %tmp39 = load float* %tmp3847 ; <float> [#uses=1]
+ %tmp41 = fmul float %tmp39, %w ; <float> [#uses=1]
+ %tmp43 = fadd float %tmp41, %tmp33 ; <float> [#uses=1]
+ ret float %tmp43
+}
+
+declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
+
+
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+%T = type { i8, [123 x i8] }
+
+@G = constant %T {i8 1, [123 x i8] zeroinitializer }
+
+define void @test2() {
+ %A = alloca %T
+ %B = alloca %T
+ %a = bitcast %T* %A to i8*
+ %b = bitcast %T* %B to i8*
+
+; CHECK: @test2
+
+; %A alloca is deleted
+; CHECK-NEXT: %B = alloca %T
+
+; use @G instead of %A
+; CHECK-NEXT: %a = bitcast %T* @G to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
+ call void @bar(i8* %b)
+ ret void
+}
+
+declare void @bar(i8*)
+
+
+;; Should be able to eliminate the alloca.
+define void @test3() {
+ %A = alloca %T
+ %a = bitcast %T* %A to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
+ call void @bar(i8* %a) readonly
+; CHECK: @test3
+; CHECK-NEXT: %a = bitcast %T* @G to i8*
+; CHECK-NEXT: call void @bar(i8* %a)
+ ret void
+}
+
+define void @test4() {
+ %A = alloca %T
+ %a = bitcast %T* %A to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
+ call void @baz(i8* byval %a)
+; CHECK: @test4
+; CHECK-NEXT: %a = bitcast %T* @G to i8*
+; CHECK-NEXT: call void @baz(i8* byval %a)
+ ret void
+}
+
+declare void @llvm.lifetime.start(i64, i8*)
+define void @test5() {
+ %A = alloca %T
+ %a = bitcast %T* %A to i8*
+ call void @llvm.lifetime.start(i64 -1, i8* %a)
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
+ call void @baz(i8* byval %a)
+; CHECK: @test5
+; CHECK-NEXT: %a = bitcast %T* @G to i8*
+; CHECK-NEXT: call void @baz(i8* byval %a)
+ ret void
+}
+
+
+declare void @baz(i8* byval)
diff --git a/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate-byte-leader.ll b/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate-byte-leader.ll
new file mode 100644
index 0000000..873d18c
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate-byte-leader.ll
@@ -0,0 +1,23 @@
+; PR1226
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep {call void @llvm.memcpy.i32}
+; RUN: opt < %s -scalarrepl -S | grep getelementptr
+; END.
+
+target datalayout = "E-p:32:32"
+target triple = "powerpc-apple-darwin8.8.0"
+ %struct.foo = type { i8, i8 }
+
+
+define i32 @test1(%struct.foo* %P) {
+entry:
+ %L = alloca %struct.foo, align 2 ; <%struct.foo*> [#uses=1]
+ %L2 = getelementptr %struct.foo* %L, i32 0, i32 0 ; <i8*> [#uses=2]
+ %tmp13 = getelementptr %struct.foo* %P, i32 0, i32 0 ; <i8*> [#uses=1]
+ call void @llvm.memcpy.i32( i8* %L2, i8* %tmp13, i32 2, i32 1 )
+ %tmp5 = load i8* %L2 ; <i8> [#uses=1]
+ %tmp56 = sext i8 %tmp5 to i32 ; <i32> [#uses=1]
+ ret i32 %tmp56
+}
+
+declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
diff --git a/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate.ll b/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate.ll
new file mode 100644
index 0000000..f4b4a68
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/memset-aggregate.ll
@@ -0,0 +1,67 @@
+; PR1226
+; RUN: opt < %s -scalarrepl -S | grep {ret i32 16843009}
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+; RUN: opt < %s -scalarrepl -instcombine -S | grep {ret i16 514}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "i686-apple-darwin8"
+ %struct.bar = type { %struct.foo, i64, double }
+ %struct.foo = type { i32, i32 }
+
+
+define i32 @test1(%struct.foo* %P) {
+entry:
+ %L = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
+ %L2 = bitcast %struct.foo* %L to i8* ; <i8*> [#uses=1]
+ %tmp13 = bitcast %struct.foo* %P to i8* ; <i8*> [#uses=1]
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %L2, i8* %tmp13, i32 8, i32 4, i1 false)
+ %tmp4 = getelementptr %struct.foo* %L, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %tmp4 ; <i32> [#uses=1]
+ ret i32 %tmp5
+}
+
+
+define i32 @test2() {
+entry:
+ %L = alloca [4 x %struct.foo], align 16 ; <[4 x %struct.foo]*> [#uses=2]
+ %L12 = bitcast [4 x %struct.foo]* %L to i8* ; <i8*> [#uses=1]
+ call void @llvm.memset.p0i8.i32(i8* %L12, i8 0, i32 32, i32 16, i1 false)
+ %tmp4 = getelementptr [4 x %struct.foo]* %L, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %tmp4 ; <i32> [#uses=1]
+ ret i32 %tmp5
+}
+
+
+define i32 @test3() {
+entry:
+ %B = alloca %struct.bar, align 16 ; <%struct.bar*> [#uses=4]
+ %B1 = bitcast %struct.bar* %B to i8* ; <i8*> [#uses=1]
+ call void @llvm.memset.p0i8.i32(i8* %B1, i8 1, i32 24, i32 16, i1 false)
+ %tmp3 = getelementptr %struct.bar* %B, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp3
+ %tmp4 = getelementptr %struct.bar* %B, i32 0, i32 2 ; <double*> [#uses=1]
+ store double 1.000000e+01, double* %tmp4
+ %tmp6 = getelementptr %struct.bar* %B, i32 0, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp7 = load i32* %tmp6 ; <i32> [#uses=1]
+ ret i32 %tmp7
+}
+
+
+ %struct.f = type { i32, i32, i32, i32, i32, i32 }
+
+define i16 @test4() nounwind {
+entry:
+ %A = alloca %struct.f, align 8 ; <%struct.f*> [#uses=3]
+ %0 = getelementptr %struct.f* %A, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %0, align 8
+ %1 = getelementptr %struct.f* %A, i32 0, i32 1 ; <i32*> [#uses=1]
+ %2 = bitcast i32* %1 to i8* ; <i8*> [#uses=1]
+ call void @llvm.memset.p0i8.i32(i8* %2, i8 2, i32 12, i32 4, i1 false)
+ %3 = getelementptr %struct.f* %A, i32 0, i32 2 ; <i32*> [#uses=1]
+ %4 = load i32* %3, align 8 ; <i32> [#uses=1]
+ %retval12 = trunc i32 %4 to i16 ; <i16> [#uses=1]
+ ret i16 %retval12
+}
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
\ No newline at end of file
diff --git a/src/LLVM/test/Transforms/ScalarRepl/nonzero-first-index.ll b/src/LLVM/test/Transforms/ScalarRepl/nonzero-first-index.ll
new file mode 100644
index 0000000..60f414b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/nonzero-first-index.ll
@@ -0,0 +1,53 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+%nested = type { i32, [4 x i32] }
+
+; Check that a GEP with a non-zero first index does not prevent SROA as long
+; as the resulting offset corresponds to an element in the alloca.
+define i32 @test1() {
+; CHECK: @test1
+; CHECK-NOT: = i160
+; CHECK: ret i32 undef
+ %A = alloca %nested
+ %B = getelementptr %nested* %A, i32 0, i32 1, i32 0
+ %C = getelementptr i32* %B, i32 2
+ %D = load i32* %C
+ ret i32 %D
+}
+
+; But, if the offset is out of range, then it should not be transformed.
+define i32 @test2() {
+; CHECK: @test2
+; CHECK: i160
+ %A = alloca %nested
+ %B = getelementptr %nested* %A, i32 0, i32 1, i32 0
+ %C = getelementptr i32* %B, i32 4
+ %D = load i32* %C
+ ret i32 %D
+}
+
+; Try it with a bitcast and single GEP....
+define i32 @test3() {
+; CHECK: @test3
+; CHECK-NOT: = i160
+; CHECK: ret i32 undef
+ %A = alloca %nested
+ %B = bitcast %nested* %A to i32*
+ %C = getelementptr i32* %B, i32 2
+ %D = load i32* %C
+ ret i32 %D
+}
+
+; ...and again make sure that out-of-range accesses are not transformed.
+define i32 @test4() {
+; CHECK: @test4
+; CHECK: i160
+ %A = alloca %nested
+ %B = bitcast %nested* %A to i32*
+ %C = getelementptr i32* %B, i32 -1
+ %D = load i32* %C
+ ret i32 %D
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/not-a-vector.ll b/src/LLVM/test/Transforms/ScalarRepl/not-a-vector.ll
new file mode 100644
index 0000000..f873456
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/not-a-vector.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -scalarrepl -S | not grep alloca
+; RUN: opt < %s -scalarrepl -S | not grep {7 x double}
+; RUN: opt < %s -scalarrepl -instcombine -S | grep {ret double %B}
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define double @test(double %A, double %B) {
+ %ARR = alloca [7 x i64]
+ %C = bitcast [7 x i64]* %ARR to double*
+ store double %A, double* %C
+
+ %D = getelementptr [7 x i64]* %ARR, i32 0, i32 4
+ %E = bitcast i64* %D to double*
+ store double %B, double* %E
+
+ %F = getelementptr double* %C, i32 4
+ %G = load double* %F
+ ret double %G
+}
+
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/only-memcpy-uses.ll b/src/LLVM/test/Transforms/ScalarRepl/only-memcpy-uses.ll
new file mode 100644
index 0000000..cfb88bd
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/only-memcpy-uses.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+%struct.S = type { [12 x i32] }
+
+; CHECK: @bar4
+define void @bar4(%struct.S* byval %s) nounwind ssp {
+entry:
+; CHECK: alloca
+; CHECK-NOT: load
+; CHECK: memcpy
+ %t = alloca %struct.S, align 4
+ %agg.tmp = alloca %struct.S, align 4
+ %tmp = bitcast %struct.S* %t to i8*
+ %tmp1 = bitcast %struct.S* %s to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* %tmp1, i64 48, i32 4, i1 false)
+ %tmp2 = bitcast %struct.S* %agg.tmp to i8*
+ %tmp3 = bitcast %struct.S* %t to i8*
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp2, i8* %tmp3, i64 48, i32 4, i1 false)
+ %call = call i32 (...)* @bazz(%struct.S* byval %agg.tmp)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+declare i32 @bazz(...)
diff --git a/src/LLVM/test/Transforms/ScalarRepl/phi-select.ll b/src/LLVM/test/Transforms/ScalarRepl/phi-select.ll
new file mode 100644
index 0000000..ffe0b1d
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/phi-select.ll
@@ -0,0 +1,153 @@
+; RUN: opt %s -scalarrepl -S | FileCheck %s
+; Test promotion of allocas that have phis and select users.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.2"
+
+%struct.X = type { i32 }
+%PairTy = type {i32, i32}
+
+; CHECK: @test1
+; CHECK: %a.0 = alloca i32
+; CHECK: %b.0 = alloca i32
+define i32 @test1(i32 %x) nounwind readnone ssp {
+entry:
+ %a = alloca %struct.X, align 8 ; <%struct.X*> [#uses=2]
+ %b = alloca %struct.X, align 8 ; <%struct.X*> [#uses=2]
+ %0 = getelementptr inbounds %struct.X* %a, i64 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %0, align 8
+ %1 = getelementptr inbounds %struct.X* %b, i64 0, i32 0 ; <i32*> [#uses=1]
+ store i32 2, i32* %1, align 8
+ %2 = icmp eq i32 %x, 0 ; <i1> [#uses=1]
+ %p.0 = select i1 %2, %struct.X* %b, %struct.X* %a ; <%struct.X*> [#uses=1]
+ %3 = getelementptr inbounds %struct.X* %p.0, i64 0, i32 0 ; <i32*> [#uses=1]
+ %4 = load i32* %3, align 8 ; <i32> [#uses=1]
+ ret i32 %4
+}
+
+; CHECK: @test2
+; CHECK: %X.ld = phi i32 [ 1, %entry ], [ 2, %T ]
+; CHECK-NEXT: ret i32 %X.ld
+define i32 @test2(i1 %c) {
+entry:
+ %A = alloca {i32, i32}
+ %B = getelementptr {i32, i32}* %A, i32 0, i32 0
+ store i32 1, i32* %B
+ br i1 %c, label %T, label %F
+T:
+ %C = getelementptr {i32, i32}* %A, i32 0, i32 1
+ store i32 2, i32* %C
+ br label %F
+F:
+ %X = phi i32* [%B, %entry], [%C, %T]
+ %Q = load i32* %X
+ ret i32 %Q
+}
+
+; CHECK: @test3
+; CHECK-NEXT: %Q = select i1 %c, i32 1, i32 2
+; CHECK-NEXT: ret i32 %Q
+; rdar://8904039
+define i32 @test3(i1 %c) {
+ %A = alloca {i32, i32}
+ %B = getelementptr {i32, i32}* %A, i32 0, i32 0
+ store i32 1, i32* %B
+ %C = getelementptr {i32, i32}* %A, i32 0, i32 1
+ store i32 2, i32* %C
+
+ %X = select i1 %c, i32* %B, i32* %C
+ %Q = load i32* %X
+ ret i32 %Q
+}
+
+;; We can't scalarize this, a use of the select is not an element access.
+define i64 @test4(i1 %c) {
+entry:
+ %A = alloca %PairTy
+ ; CHECK: @test4
+ ; CHECK: %A = alloca %PairTy
+ %B = getelementptr %PairTy* %A, i32 0, i32 0
+ store i32 1, i32* %B
+ %C = getelementptr %PairTy* %A, i32 0, i32 1
+ store i32 2, i32* %B
+
+ %X = select i1 %c, i32* %B, i32* %C
+ %Y = bitcast i32* %X to i64*
+ %Q = load i64* %Y
+ ret i64 %Q
+}
+
+
+;;
+;; Tests for promoting allocas used by selects.
+;; rdar://7339113
+;;
+
+define i32 @test5(i32 *%P) nounwind readnone ssp {
+entry:
+ %b = alloca i32, align 8
+ store i32 2, i32* %b, align 8
+
+ ;; Select on constant condition should be folded.
+ %p.0 = select i1 false, i32* %b, i32* %P
+ store i32 123, i32* %p.0
+
+ %r = load i32* %b, align 8
+ ret i32 %r
+
+; CHECK: @test5
+; CHECK: store i32 123, i32* %P
+; CHECK: ret i32 2
+}
+
+define i32 @test6(i32 %x, i1 %c) nounwind readnone ssp {
+ %a = alloca i32, align 8
+ %b = alloca i32, align 8
+ store i32 1, i32* %a, align 8
+ store i32 2, i32* %b, align 8
+ %p.0 = select i1 %c, i32* %b, i32* %a
+ %r = load i32* %p.0, align 8
+ ret i32 %r
+; CHECK: @test6
+; CHECK-NEXT: %r = select i1 %c, i32 2, i32 1
+; CHECK-NEXT: ret i32 %r
+}
+
+; Verify that the loads happen where the loads are, not where the select is.
+define i32 @test7(i32 %x, i1 %c) nounwind readnone ssp {
+ %a = alloca i32, align 8
+ %b = alloca i32, align 8
+ store i32 1, i32* %a
+ store i32 2, i32* %b
+ %p.0 = select i1 %c, i32* %b, i32* %a
+
+ store i32 0, i32* %a
+
+ %r = load i32* %p.0, align 8
+ ret i32 %r
+; CHECK: @test7
+; CHECK-NOT: alloca i32
+; CHECK: %r = select i1 %c, i32 2, i32 0
+; CHECK: ret i32 %r
+}
+
+;; Promote allocs that are PHI'd together by moving the loads.
+define i32 @test8(i32 %x) nounwind readnone ssp {
+; CHECK: @test8
+; CHECK-NOT: load i32
+; CHECK-NOT: store i32
+; CHECK: %p.0.ld = phi i32 [ 2, %entry ], [ 1, %T ]
+; CHECK-NEXT: ret i32 %p.0.ld
+entry:
+ %a = alloca i32, align 8
+ %b = alloca i32, align 8
+ store i32 1, i32* %a, align 8
+ store i32 2, i32* %b, align 8
+ %c = icmp eq i32 %x, 0
+ br i1 %c, label %T, label %Cont
+T:
+ br label %Cont
+Cont:
+ %p.0 = phi i32* [%b, %entry],[%a, %T]
+ %r = load i32* %p.0, align 8
+ ret i32 %r
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/phinodepromote.ll b/src/LLVM/test/Transforms/ScalarRepl/phinodepromote.ll
new file mode 100644
index 0000000..cc515ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/phinodepromote.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -simplifycfg -instcombine -mem2reg -S | not grep alloca
+;
+; This tests to see if mem2reg can promote alloca instructions whose addresses
+; are used by PHI nodes that are immediately loaded. The LLVM C++ front-end
+; often generates code that looks like this (when it codegen's ?: exprs as
+; lvalues), so handling this simple extension is quite useful.
+;
+; This testcase is what the following program looks like when it reaches
+; instcombine:
+;
+; template<typename T>
+; const T& max(const T& a1, const T& a2) { return a1 < a2 ? a1 : a2; }
+; int main() { return max(0, 1); }
+;
+; This test checks to make sure the combination of instcombine and mem2reg
+; perform the transformation.
+
+define i32 @main() {
+entry:
+ %mem_tmp.0 = alloca i32 ; <i32*> [#uses=3]
+ %mem_tmp.1 = alloca i32 ; <i32*> [#uses=3]
+ store i32 0, i32* %mem_tmp.0
+ store i32 1, i32* %mem_tmp.1
+ %tmp.1.i = load i32* %mem_tmp.1 ; <i32> [#uses=1]
+ %tmp.3.i = load i32* %mem_tmp.0 ; <i32> [#uses=1]
+ %tmp.4.i = icmp sle i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
+ br i1 %tmp.4.i, label %cond_true.i, label %cond_continue.i
+cond_true.i: ; preds = %entry
+ br label %cond_continue.i
+cond_continue.i: ; preds = %cond_true.i, %entry
+ %mem_tmp.i.0 = phi i32* [ %mem_tmp.1, %cond_true.i ], [ %mem_tmp.0, %entry ] ; <i32*> [#uses=1]
+ %tmp.3 = load i32* %mem_tmp.i.0 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/select_promote.ll b/src/LLVM/test/Transforms/ScalarRepl/select_promote.ll
new file mode 100644
index 0000000..26c29f4
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/select_promote.ll
@@ -0,0 +1,18 @@
+; Test promotion of loads that use the result of a select instruction. This
+; should be simplified by the instcombine pass.
+
+; RUN: opt < %s -instcombine -mem2reg -S | not grep alloca
+
+define i32 @main() {
+ %mem_tmp.0 = alloca i32 ; <i32*> [#uses=3]
+ %mem_tmp.1 = alloca i32 ; <i32*> [#uses=3]
+ store i32 0, i32* %mem_tmp.0
+ store i32 1, i32* %mem_tmp.1
+ %tmp.1.i = load i32* %mem_tmp.1 ; <i32> [#uses=1]
+ %tmp.3.i = load i32* %mem_tmp.0 ; <i32> [#uses=1]
+ %tmp.4.i = icmp sle i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
+ %mem_tmp.i.0 = select i1 %tmp.4.i, i32* %mem_tmp.1, i32* %mem_tmp.0 ; <i32*> [#uses=1]
+ %tmp.3 = load i32* %mem_tmp.i.0 ; <i32> [#uses=1]
+ ret i32 %tmp.3
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/sroa-fca.ll b/src/LLVM/test/Transforms/ScalarRepl/sroa-fca.ll
new file mode 100644
index 0000000..2df3b9b
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/sroa-fca.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -scalarrepl | llvm-dis
+; Make sure that SROA "scalar conversion" can handle first class aggregates.
+
+define i64 @test({i32, i32} %A) {
+ %X = alloca i64
+ %Y = bitcast i64* %X to {i32,i32}*
+ store {i32,i32} %A, {i32,i32}* %Y
+
+ %Q = load i64* %X
+ ret i64 %Q
+}
+
+define {i32,i32} @test2(i64 %A) {
+ %X = alloca i64
+ %Y = bitcast i64* %X to {i32,i32}*
+ store i64 %A, i64* %X
+
+ %Q = load {i32,i32}* %Y
+ ret {i32,i32} %Q
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/sroa_two.ll b/src/LLVM/test/Transforms/ScalarRepl/sroa_two.ll
new file mode 100644
index 0000000..514a47e
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/sroa_two.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -scalarrepl | llvm-dis
+
+define i32 @test(i32 %X) {
+ %Arr = alloca [2 x i32] ; <[2 x i32]*> [#uses=3]
+ %tmp.0 = getelementptr [2 x i32]* %Arr, i32 0, i32 0 ; <i32*> [#uses=1]
+ store i32 1, i32* %tmp.0
+ %tmp.1 = getelementptr [2 x i32]* %Arr, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 2, i32* %tmp.1
+ %tmp.3 = getelementptr [2 x i32]* %Arr, i32 0, i32 %X ; <i32*> [#uses=1]
+ %tmp.4 = load i32* %tmp.3 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/union-fp-int.ll b/src/LLVM/test/Transforms/ScalarRepl/union-fp-int.ll
new file mode 100644
index 0000000..5343b57
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/union-fp-int.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep alloca
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: grep {bitcast.*float.*i32}
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define i32 @test(float %X) {
+ %X_addr = alloca float ; <float*> [#uses=2]
+ store float %X, float* %X_addr
+ %X_addr.upgrd.1 = bitcast float* %X_addr to i32* ; <i32*> [#uses=1]
+ %tmp = load i32* %X_addr.upgrd.1 ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/union-packed.ll b/src/LLVM/test/Transforms/ScalarRepl/union-packed.ll
new file mode 100644
index 0000000..53e9963
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/union-packed.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep alloca
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: grep bitcast
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define <4 x i32> @test(<4 x float> %X) {
+ %X_addr = alloca <4 x float> ; <<4 x float>*> [#uses=2]
+ store <4 x float> %X, <4 x float>* %X_addr
+ %X_addr.upgrd.1 = bitcast <4 x float>* %X_addr to <4 x i32>* ; <<4 x i32>*> [#uses=1]
+ %tmp = load <4 x i32>* %X_addr.upgrd.1 ; <<4 x i32>> [#uses=1]
+ ret <4 x i32> %tmp
+}
+
diff --git a/src/LLVM/test/Transforms/ScalarRepl/union-pointer.ll b/src/LLVM/test/Transforms/ScalarRepl/union-pointer.ll
new file mode 100644
index 0000000..8005871
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/union-pointer.ll
@@ -0,0 +1,41 @@
+; PR892
+; RUN: opt < %s -scalarrepl -S | \
+; RUN: not grep alloca
+; RUN: opt < %s -scalarrepl -S | grep {ret i8}
+
+target datalayout = "e-p:32:32-n8:16:32"
+target triple = "i686-apple-darwin8.7.2"
+ %struct.Val = type { i32*, i32 }
+
+define i8* @test(i16* %X) {
+ %X_addr = alloca i16* ; <i16**> [#uses=2]
+ store i16* %X, i16** %X_addr
+ %X_addr.upgrd.1 = bitcast i16** %X_addr to i8** ; <i8**> [#uses=1]
+ %tmp = load i8** %X_addr.upgrd.1 ; <i8*> [#uses=1]
+ ret i8* %tmp
+}
+
+define void @test2(i64 %Op.0) {
+ %tmp = alloca %struct.Val, align 8 ; <%struct.Val*> [#uses=3]
+ %tmp1 = alloca %struct.Val, align 8 ; <%struct.Val*> [#uses=3]
+ %tmp.upgrd.2 = call i64 @_Z3foov( ) ; <i64> [#uses=1]
+ %tmp1.upgrd.3 = bitcast %struct.Val* %tmp1 to i64* ; <i64*> [#uses=1]
+ store i64 %tmp.upgrd.2, i64* %tmp1.upgrd.3
+ %tmp.upgrd.4 = getelementptr %struct.Val* %tmp, i32 0, i32 0 ; <i32**> [#uses=1]
+ %tmp2 = getelementptr %struct.Val* %tmp1, i32 0, i32 0 ; <i32**> [#uses=1]
+ %tmp.upgrd.5 = load i32** %tmp2 ; <i32*> [#uses=1]
+ store i32* %tmp.upgrd.5, i32** %tmp.upgrd.4
+ %tmp3 = getelementptr %struct.Val* %tmp, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp4 = getelementptr %struct.Val* %tmp1, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp.upgrd.6 = load i32* %tmp4 ; <i32> [#uses=1]
+ store i32 %tmp.upgrd.6, i32* %tmp3
+ %tmp7 = bitcast %struct.Val* %tmp to { i64 }* ; <{ i64 }*> [#uses=1]
+ %tmp8 = getelementptr { i64 }* %tmp7, i32 0, i32 0 ; <i64*> [#uses=1]
+ %tmp9 = load i64* %tmp8 ; <i64> [#uses=1]
+ call void @_Z3bar3ValS_( i64 %Op.0, i64 %tmp9 )
+ ret void
+}
+
+declare i64 @_Z3foov()
+
+declare void @_Z3bar3ValS_(i64, i64)
diff --git a/src/LLVM/test/Transforms/ScalarRepl/vector_memcpy.ll b/src/LLVM/test/Transforms/ScalarRepl/vector_memcpy.ll
new file mode 100644
index 0000000..decbd30
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/vector_memcpy.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -scalarrepl -S > %t
+; RUN: grep {ret <16 x float> %A} %t
+; RUN: grep {ret <16 x float> zeroinitializer} %t
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+
+define <16 x float> @foo(<16 x float> %A) nounwind {
+ %tmp = alloca <16 x float>, align 16
+ %tmp2 = alloca <16 x float>, align 16
+ store <16 x float> %A, <16 x float>* %tmp
+ %s = bitcast <16 x float>* %tmp to i8*
+ %s2 = bitcast <16 x float>* %tmp2 to i8*
+ call void @llvm.memcpy.i64(i8* %s2, i8* %s, i64 64, i32 16)
+
+ %R = load <16 x float>* %tmp2
+ ret <16 x float> %R
+}
+
+define <16 x float> @foo2(<16 x float> %A) nounwind {
+ %tmp2 = alloca <16 x float>, align 16
+
+ %s2 = bitcast <16 x float>* %tmp2 to i8*
+ call void @llvm.memset.i64(i8* %s2, i8 0, i64 64, i32 16)
+
+ %R = load <16 x float>* %tmp2
+ ret <16 x float> %R
+}
+
+
+declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
+declare void @llvm.memset.i64(i8* nocapture, i8, i64, i32) nounwind
diff --git a/src/LLVM/test/Transforms/ScalarRepl/vector_promote.ll b/src/LLVM/test/Transforms/ScalarRepl/vector_promote.ll
new file mode 100644
index 0000000..88efcd5
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/vector_promote.ll
@@ -0,0 +1,113 @@
+; RUN: opt < %s -scalarrepl -S | FileCheck %s
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+define void @test1(<4 x float>* %F, float %f) {
+entry:
+ %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
+ %tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
+ %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp3, <4 x float>* %G
+ %G.upgrd.1 = getelementptr <4 x float>* %G, i32 0, i32 0 ; <float*> [#uses=1]
+ store float %f, float* %G.upgrd.1
+ %tmp4 = load <4 x float>* %G ; <<4 x float>> [#uses=2]
+ %tmp6 = fadd <4 x float> %tmp4, %tmp4 ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp6, <4 x float>* %F
+ ret void
+; CHECK: @test1
+; CHECK-NOT: alloca
+; CHECK: %tmp = load <4 x float>* %F
+; CHECK: fadd <4 x float> %tmp, %tmp
+; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 0
+}
+
+define void @test2(<4 x float>* %F, float %f) {
+entry:
+ %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
+ %tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
+ %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp3, <4 x float>* %G
+ %tmp.upgrd.2 = getelementptr <4 x float>* %G, i32 0, i32 2 ; <float*> [#uses=1]
+ store float %f, float* %tmp.upgrd.2
+ %tmp4 = load <4 x float>* %G ; <<4 x float>> [#uses=2]
+ %tmp6 = fadd <4 x float> %tmp4, %tmp4 ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp6, <4 x float>* %F
+ ret void
+; CHECK: @test2
+; CHECK-NOT: alloca
+; CHECK: %tmp = load <4 x float>* %F
+; CHECK: fadd <4 x float> %tmp, %tmp
+; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 2
+}
+
+define void @test3(<4 x float>* %F, float* %f) {
+entry:
+ %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
+ %tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
+ %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp3, <4 x float>* %G
+ %tmp.upgrd.3 = getelementptr <4 x float>* %G, i32 0, i32 2 ; <float*> [#uses=1]
+ %tmp.upgrd.4 = load float* %tmp.upgrd.3 ; <float> [#uses=1]
+ store float %tmp.upgrd.4, float* %f
+ ret void
+; CHECK: @test3
+; CHECK-NOT: alloca
+; CHECK: %tmp = load <4 x float>* %F
+; CHECK: fadd <4 x float> %tmp, %tmp
+; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 2
+}
+
+define void @test4(<4 x float>* %F, float* %f) {
+entry:
+ %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
+ %tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
+ %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
+ store <4 x float> %tmp3, <4 x float>* %G
+ %G.upgrd.5 = getelementptr <4 x float>* %G, i32 0, i32 0 ; <float*> [#uses=1]
+ %tmp.upgrd.6 = load float* %G.upgrd.5 ; <float> [#uses=1]
+ store float %tmp.upgrd.6, float* %f
+ ret void
+; CHECK: @test4
+; CHECK-NOT: alloca
+; CHECK: %tmp = load <4 x float>* %F
+; CHECK: fadd <4 x float> %tmp, %tmp
+; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 0
+}
+
+define i32 @test5(float %X) { ;; should turn into bitcast.
+ %X_addr = alloca [4 x float]
+ %X1 = getelementptr [4 x float]* %X_addr, i32 0, i32 2
+ store float %X, float* %X1
+ %a = bitcast float* %X1 to i32*
+ %tmp = load i32* %a
+ ret i32 %tmp
+; CHECK: @test5
+; CHECK-NEXT: bitcast float %X to i32
+; CHECK-NEXT: ret i32
+}
+
+define i64 @test6(<2 x float> %X) {
+ %X_addr = alloca <2 x float>
+ store <2 x float> %X, <2 x float>* %X_addr
+ %P = bitcast <2 x float>* %X_addr to i64*
+ %tmp = load i64* %P
+ ret i64 %tmp
+; CHECK: @test6
+; CHECK: bitcast <2 x float> %X to i64
+; CHECK: ret i64
+}
+
+%struct.test7 = type { [6 x i32] }
+
+define void @test7() {
+entry:
+ %memtmp = alloca %struct.test7, align 16
+ %0 = bitcast %struct.test7* %memtmp to <4 x i32>*
+ store <4 x i32> zeroinitializer, <4 x i32>* %0, align 16
+ %1 = getelementptr inbounds %struct.test7* %memtmp, i64 0, i32 0, i64 5
+ store i32 0, i32* %1, align 4
+ ret void
+; CHECK: @test7
+; CHECK-NOT: alloca
+; CHECK: and i192
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/vectors-with-mismatched-elements.ll b/src/LLVM/test/Transforms/ScalarRepl/vectors-with-mismatched-elements.ll
new file mode 100644
index 0000000..c3fbdf5
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/vectors-with-mismatched-elements.ll
@@ -0,0 +1,27 @@
+; RUN: opt -scalarrepl -S < %s | FileCheck %s
+; rdar://9786827
+
+; SROA should be able to handle the mixed types and eliminate the allocas here.
+
+; TODO: Currently it does this by falling back to integer "bags of bits".
+; With enough cleverness, it should be possible to convert between <3 x i32>
+; and <2 x i64> by using a combination of a bitcast and a shuffle.
+
+; CHECK: {
+; CHECK-NOT: alloca
+; CHECK: }
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin11.0.0"
+
+define <2 x i64> @foo() nounwind {
+entry:
+ %retval = alloca <3 x i32>, align 16
+ %z = alloca <4 x i32>, align 16
+ %tmp = load <4 x i32>* %z
+ %tmp1 = shufflevector <4 x i32> %tmp, <4 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
+ store <3 x i32> %tmp1, <3 x i32>* %retval
+ %0 = bitcast <3 x i32>* %retval to <2 x i64>*
+ %1 = load <2 x i64>* %0, align 1
+ ret <2 x i64> %1
+}
diff --git a/src/LLVM/test/Transforms/ScalarRepl/volatile.ll b/src/LLVM/test/Transforms/ScalarRepl/volatile.ll
new file mode 100644
index 0000000..ab276b0
--- /dev/null
+++ b/src/LLVM/test/Transforms/ScalarRepl/volatile.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -scalarrepl -S | grep {load volatile}
+; RUN: opt < %s -scalarrepl -S | grep {store volatile}
+
+define i32 @voltest(i32 %T) {
+ %A = alloca {i32, i32}
+ %B = getelementptr {i32,i32}* %A, i32 0, i32 0
+ volatile store i32 %T, i32* %B
+
+ %C = getelementptr {i32,i32}* %A, i32 0, i32 1
+ %X = volatile load i32* %C
+ ret i32 %X
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll b/src/LLVM/test/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll
new file mode 100644
index 0000000..d950ae1
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll
@@ -0,0 +1,22 @@
+; Basic block #2 should not be merged into BB #3!
+;
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: grep {br label}
+;
+
+declare void @foo()
+
+define void @cprop_test12(i32* %data) {
+bb0:
+ %reg108 = load i32* %data ; <i32> [#uses=2]
+ %cond218 = icmp ne i32 %reg108, 5 ; <i1> [#uses=1]
+ br i1 %cond218, label %bb3, label %bb2
+bb2: ; preds = %bb0
+ call void @foo( )
+ br label %bb3
+bb3: ; preds = %bb2, %bb0
+ %reg117 = phi i32 [ 110, %bb2 ], [ %reg108, %bb0 ] ; <i32> [#uses=1]
+ store i32 %reg117, i32* %data
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2002-05-21-PHIElimination.ll b/src/LLVM/test/Transforms/SimplifyCFG/2002-05-21-PHIElimination.ll
new file mode 100644
index 0000000..a677ff3
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2002-05-21-PHIElimination.ll
@@ -0,0 +1,19 @@
+; CFG Simplification is making a loop dead, then changing the add into:
+;
+; %V1 = add int %V1, 1
+;
+; Which is not valid SSA
+;
+; RUN: opt < %s -simplifycfg | llvm-dis
+
+define void @test() {
+; <label>:0
+ br i1 true, label %end, label %Loop
+Loop: ; preds = %Loop, %0
+ %V = phi i32 [ 0, %0 ], [ %V1, %Loop ] ; <i32> [#uses=1]
+ %V1 = add i32 %V, 1 ; <i32> [#uses=1]
+ br label %Loop
+end: ; preds = %0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2002-06-24-PHINode.ll b/src/LLVM/test/Transforms/SimplifyCFG/2002-06-24-PHINode.ll
new file mode 100644
index 0000000..1187657
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2002-06-24-PHINode.ll
@@ -0,0 +1,14 @@
+; -simplifycfg is not folding blocks if there is a PHI node involved. This
+; should be fixed eventually
+
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define i32 @main(i32 %argc) {
+; <label>:0
+ br label %InlinedFunctionReturnNode
+InlinedFunctionReturnNode: ; preds = %0
+ %X = phi i32 [ 7, %0 ] ; <i32> [#uses=1]
+ %Y = add i32 %X, %argc ; <i32> [#uses=1]
+ ret i32 %Y
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2002-09-24-PHIAssertion.ll b/src/LLVM/test/Transforms/SimplifyCFG/2002-09-24-PHIAssertion.ll
new file mode 100644
index 0000000..94f08da
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2002-09-24-PHIAssertion.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -simplifycfg
+
+define i32 @test(i32 %A, i32 %B, i1 %cond) {
+J:
+ %C = add i32 %A, 12 ; <i32> [#uses=3]
+ br i1 %cond, label %L, label %L
+L: ; preds = %J, %J
+ %Q = phi i32 [ %C, %J ], [ %C, %J ] ; <i32> [#uses=1]
+ %D = add i32 %C, %B ; <i32> [#uses=1]
+ %E = add i32 %Q, %D ; <i32> [#uses=1]
+ ret i32 %E
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-03-07-DominateProblem.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-03-07-DominateProblem.ll
new file mode 100644
index 0000000..69f8521
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-03-07-DominateProblem.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -simplifycfg -disable-output
+
+define void @test(i32* %ldo, i1 %c, i1 %d) {
+bb9:
+ br i1 %c, label %bb11, label %bb10
+bb10: ; preds = %bb9
+ br label %bb11
+bb11: ; preds = %bb10, %bb9
+ %reg330 = phi i32* [ null, %bb10 ], [ %ldo, %bb9 ] ; <i32*> [#uses=1]
+ br label %bb20
+bb20: ; preds = %bb20, %bb11
+ store i32* %reg330, i32** null
+ br i1 %d, label %bb20, label %done
+done: ; preds = %bb20
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-InvokeCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-InvokeCrash.ll
new file mode 100644
index 0000000..c2e6679
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-InvokeCrash.ll
@@ -0,0 +1,16 @@
+; Do not remove the invoke!
+;
+; RUN: opt < %s -simplifycfg -disable-output
+
+define i32 @test() {
+ %A = invoke i32 @test( )
+ to label %Ret unwind label %Ret2 ; <i32> [#uses=1]
+Ret: ; preds = %0
+ ret i32 %A
+Ret2: ; preds = %0
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ ret i32 undef
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-MishandleInvoke.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-MishandleInvoke.ll
new file mode 100644
index 0000000..b583e39
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-05-MishandleInvoke.ll
@@ -0,0 +1,15 @@
+; Do not remove the invoke!
+;
+; RUN: opt < %s -simplifycfg -S | grep invoke
+
+define i32 @test() {
+ invoke i32 @test( )
+ to label %Ret unwind label %Ret ; <i32>:1 [#uses=0]
+Ret: ; preds = %0, %0
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ %A = add i32 0, 1 ; <i32> [#uses=1]
+ ret i32 %A
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFold.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFold.ll
new file mode 100644
index 0000000..f178e07
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFold.ll
@@ -0,0 +1,22 @@
+; This test checks to make sure that 'br X, Dest, Dest' is folded into
+; 'br Dest'
+
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {br i1 %c2}
+
+declare void @noop()
+
+define i32 @test(i1 %c1, i1 %c2) {
+ call void @noop( )
+ br i1 %c1, label %A, label %Y
+A: ; preds = %0
+ call void @noop( )
+ br i1 %c2, label %X, label %X
+X: ; preds = %Y, %A, %A
+ call void @noop( )
+ ret i32 0
+Y: ; preds = %0
+ call void @noop( )
+ br label %X
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFoldOrdering.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFoldOrdering.ll
new file mode 100644
index 0000000..719a9a9
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-BranchFoldOrdering.ll
@@ -0,0 +1,26 @@
+; This test checks to make sure that 'br X, Dest, Dest' is folded into
+; 'br Dest'. This can only happen after the 'Z' block is eliminated. This is
+; due to the fact that the SimplifyCFG function does not use
+; the ConstantFoldTerminator function.
+
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {br i1 %c2}
+
+declare void @noop()
+
+define i32 @test(i1 %c1, i1 %c2) {
+ call void @noop( )
+ br i1 %c1, label %A, label %Y
+A: ; preds = %0
+ call void @noop( )
+ br i1 %c2, label %Z, label %X
+Z: ; preds = %A
+ br label %X
+X: ; preds = %Y, %Z, %A
+ call void @noop( )
+ ret i32 0
+Y: ; preds = %0
+ call void @noop( )
+ br label %X
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch-dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch-dbg.ll
new file mode 100644
index 0000000..af59ba0
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch-dbg.ll
@@ -0,0 +1,58 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep switch
+
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata"
+
+@.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+; Test folding all to same dest
+define i32 @test3(i1 %C) {
+ br i1 %C, label %Start, label %TheDest
+Start: ; preds = %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ switch i32 3, label %TheDest [
+ i32 0, label %TheDest
+ i32 1, label %TheDest
+ i32 2, label %TheDest
+ i32 5, label %TheDest
+ ]
+TheDest: ; preds = %Start, %Start, %Start, %Start, %Start, %0
+ ret i32 1234
+}
+
+; Test folding switch -> branch
+define i32 @test4(i32 %C) {
+ switch i32 %C, label %L1 [
+ i32 0, label %L2
+ ]
+L1: ; preds = %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret i32 0
+L2: ; preds = %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret i32 1
+}
+
+; Can fold into a cond branch!
+define i32 @test5(i32 %C) {
+ switch i32 %C, label %L1 [
+ i32 0, label %L2
+ i32 123, label %L1
+ ]
+L1: ; preds = %0, %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret i32 0
+L2: ; preds = %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret i32 1
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch.ll b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch.ll
new file mode 100644
index 0000000..aa0bc2f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2003-08-17-FoldSwitch.ll
@@ -0,0 +1,80 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep switch
+
+; Test normal folding
+define i32 @test1() {
+ switch i32 5, label %Default [
+ i32 0, label %Foo
+ i32 1, label %Bar
+ i32 2, label %Baz
+ i32 5, label %TheDest
+ ]
+Default: ; preds = %0
+ ret i32 -1
+Foo: ; preds = %0
+ ret i32 -2
+Bar: ; preds = %0
+ ret i32 -3
+Baz: ; preds = %0
+ ret i32 -4
+TheDest: ; preds = %0
+ ret i32 1234
+}
+
+; Test folding to default dest
+define i32 @test2() {
+ switch i32 3, label %Default [
+ i32 0, label %Foo
+ i32 1, label %Bar
+ i32 2, label %Baz
+ i32 5, label %TheDest
+ ]
+Default: ; preds = %0
+ ret i32 1234
+Foo: ; preds = %0
+ ret i32 -2
+Bar: ; preds = %0
+ ret i32 -5
+Baz: ; preds = %0
+ ret i32 -6
+TheDest: ; preds = %0
+ ret i32 -8
+}
+
+; Test folding all to same dest
+define i32 @test3(i1 %C) {
+ br i1 %C, label %Start, label %TheDest
+Start: ; preds = %0
+ switch i32 3, label %TheDest [
+ i32 0, label %TheDest
+ i32 1, label %TheDest
+ i32 2, label %TheDest
+ i32 5, label %TheDest
+ ]
+TheDest: ; preds = %Start, %Start, %Start, %Start, %Start, %0
+ ret i32 1234
+}
+
+; Test folding switch -> branch
+define i32 @test4(i32 %C) {
+ switch i32 %C, label %L1 [
+ i32 0, label %L2
+ ]
+L1: ; preds = %0
+ ret i32 0
+L2: ; preds = %0
+ ret i32 1
+}
+
+; Can fold into a cond branch!
+define i32 @test5(i32 %C) {
+ switch i32 %C, label %L1 [
+ i32 0, label %L2
+ i32 123, label %L1
+ ]
+L1: ; preds = %0, %0
+ ret i32 0
+L2: ; preds = %0
+ ret i32 1
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2004-12-10-SimplifyCFGCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2004-12-10-SimplifyCFGCrash.ll
new file mode 100644
index 0000000..9ea5527
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2004-12-10-SimplifyCFGCrash.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -simplifycfg -disable-output
+
+define void @symhash_add() {
+entry:
+ br i1 undef, label %then.0, label %UnifiedReturnBlock
+then.0: ; preds = %entry
+ br i1 undef, label %loopentry.2, label %loopentry.1.preheader
+loopentry.1.preheader: ; preds = %then.0
+ br label %loopentry.1.outer
+loopentry.1.outer: ; preds = %loopexit.1, %loopentry.1.preheader
+ br label %loopentry.1
+loopentry.1: ; preds = %endif.1, %then.4, %then.3, %then.1, %loopentry.1.outer
+ br i1 undef, label %loopexit.1, label %no_exit.1
+no_exit.1: ; preds = %loopentry.1
+ br i1 undef, label %then.1, label %else.0
+then.1: ; preds = %no_exit.1
+ br label %loopentry.1
+else.0: ; preds = %no_exit.1
+ br i1 undef, label %then.2, label %else.1
+then.2: ; preds = %else.0
+ br i1 undef, label %then.3, label %endif.1
+then.3: ; preds = %then.2
+ br label %loopentry.1
+else.1: ; preds = %else.0
+ br i1 undef, label %endif.1, label %then.4
+then.4: ; preds = %else.1
+ br label %loopentry.1
+endif.1: ; preds = %else.1, %then.2
+ br label %loopentry.1
+loopexit.1: ; preds = %loopentry.1
+ br i1 undef, label %loopentry.1.outer, label %loopentry.2
+loopentry.2: ; preds = %no_exit.2, %loopexit.1, %then.0
+ br i1 undef, label %loopexit.2, label %no_exit.2
+no_exit.2: ; preds = %loopentry.2
+ br label %loopentry.2
+loopexit.2: ; preds = %loopentry.2
+ ret void
+UnifiedReturnBlock: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2005-06-16-PHICrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2005-06-16-PHICrash.ll
new file mode 100644
index 0000000..ccfd38c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2005-06-16-PHICrash.ll
@@ -0,0 +1,95 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; PR584
+@g_38098584 = external global i32 ; <i32*> [#uses=1]
+@g_60187400 = external global i32 ; <i32*> [#uses=1]
+@g_59182229 = external global i32 ; <i32*> [#uses=2]
+
+define i32 @_Z13func_26556482h(i8 %l_88173906) {
+entry:
+ %tmp.1 = bitcast i8 %l_88173906 to i8 ; <i8> [#uses=2]
+ %tmp.3 = icmp eq i8 %l_88173906, 0 ; <i1> [#uses=1]
+ br i1 %tmp.3, label %else.0, label %then.0
+then.0: ; preds = %entry
+ %tmp.5 = icmp eq i8 %l_88173906, 0 ; <i1> [#uses=1]
+ br i1 %tmp.5, label %else.1, label %then.1
+then.1: ; preds = %then.0
+ br label %return
+else.1: ; preds = %then.0
+ br label %loopentry.0
+loopentry.0: ; preds = %no_exit.0, %else.1
+ %i.0.1 = phi i32 [ 0, %else.1 ], [ %inc.0, %no_exit.0 ] ; <i32> [#uses=2]
+ %tmp.9 = icmp sgt i32 %i.0.1, 99 ; <i1> [#uses=1]
+ br i1 %tmp.9, label %endif.0, label %no_exit.0
+no_exit.0: ; preds = %loopentry.0
+ %inc.0 = add i32 %i.0.1, 1 ; <i32> [#uses=1]
+ br label %loopentry.0
+else.0: ; preds = %entry
+ %tmp.12 = sext i8 %tmp.1 to i32 ; <i32> [#uses=1]
+ br label %return
+endif.0: ; preds = %loopentry.0
+ %tmp.14 = sext i8 %tmp.1 to i32 ; <i32> [#uses=1]
+ %tmp.16 = zext i8 %l_88173906 to i32 ; <i32> [#uses=1]
+ %tmp.17 = icmp sgt i32 %tmp.14, %tmp.16 ; <i1> [#uses=1]
+ %tmp.19 = load i32* @g_59182229 ; <i32> [#uses=2]
+ br i1 %tmp.17, label %cond_true, label %cond_false
+cond_true: ; preds = %endif.0
+ %tmp.20 = icmp ne i32 %tmp.19, 1 ; <i1> [#uses=1]
+ br label %cond_continue
+cond_false: ; preds = %endif.0
+ %tmp.22 = icmp ne i32 %tmp.19, 0 ; <i1> [#uses=1]
+ br label %cond_continue
+cond_continue: ; preds = %cond_false, %cond_true
+ %mem_tmp.0 = phi i1 [ %tmp.20, %cond_true ], [ %tmp.22, %cond_false ] ; <i1> [#uses=1]
+ br i1 %mem_tmp.0, label %then.2, label %else.2
+then.2: ; preds = %cond_continue
+ %tmp.25 = zext i8 %l_88173906 to i32 ; <i32> [#uses=1]
+ br label %return
+else.2: ; preds = %cond_continue
+ br label %loopentry.1
+loopentry.1: ; preds = %endif.3, %else.2
+ %i.1.1 = phi i32 [ 0, %else.2 ], [ %inc.3, %endif.3 ] ; <i32> [#uses=2]
+ %i.3.2 = phi i32 [ undef, %else.2 ], [ %i.3.0, %endif.3 ] ; <i32> [#uses=2]
+ %l_88173906_addr.1 = phi i8 [ %l_88173906, %else.2 ], [ %l_88173906_addr.0, %endif.3 ] ; <i8> [#uses=3]
+ %tmp.29 = icmp sgt i32 %i.1.1, 99 ; <i1> [#uses=1]
+ br i1 %tmp.29, label %endif.2, label %no_exit.1
+no_exit.1: ; preds = %loopentry.1
+ %tmp.30 = load i32* @g_38098584 ; <i32> [#uses=1]
+ %tmp.31 = icmp eq i32 %tmp.30, 0 ; <i1> [#uses=1]
+ br i1 %tmp.31, label %else.3, label %then.3
+then.3: ; preds = %no_exit.1
+ br label %endif.3
+else.3: ; preds = %no_exit.1
+ br i1 false, label %else.4, label %then.4
+then.4: ; preds = %else.3
+ br label %endif.3
+else.4: ; preds = %else.3
+ br i1 false, label %else.5, label %then.5
+then.5: ; preds = %else.4
+ store i32 -1004318825, i32* @g_59182229
+ br label %return
+else.5: ; preds = %else.4
+ br label %loopentry.3
+loopentry.3: ; preds = %then.7, %else.5
+ %i.3.3 = phi i32 [ 0, %else.5 ], [ %inc.2, %then.7 ] ; <i32> [#uses=3]
+ %tmp.55 = icmp sgt i32 %i.3.3, 99 ; <i1> [#uses=1]
+ br i1 %tmp.55, label %endif.3, label %no_exit.3
+no_exit.3: ; preds = %loopentry.3
+ %tmp.57 = icmp eq i8 %l_88173906_addr.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp.57, label %else.7, label %then.7
+then.7: ; preds = %no_exit.3
+ store i32 16239, i32* @g_60187400
+ %inc.2 = add i32 %i.3.3, 1 ; <i32> [#uses=1]
+ br label %loopentry.3
+else.7: ; preds = %no_exit.3
+ br label %return
+endif.3: ; preds = %loopentry.3, %then.4, %then.3
+ %i.3.0 = phi i32 [ %i.3.2, %then.3 ], [ %i.3.2, %then.4 ], [ %i.3.3, %loopentry.3 ] ; <i32> [#uses=1]
+ %l_88173906_addr.0 = phi i8 [ 100, %then.3 ], [ %l_88173906_addr.1, %then.4 ], [ %l_88173906_addr.1, %loopentry.3 ] ; <i8> [#uses=1]
+ %inc.3 = add i32 %i.1.1, 1 ; <i32> [#uses=1]
+ br label %loopentry.1
+endif.2: ; preds = %loopentry.1
+ br label %return
+return: ; preds = %endif.2, %else.7, %then.5, %then.2, %else.0, %then.1
+ %result.0 = phi i32 [ 1624650671, %then.1 ], [ %tmp.25, %then.2 ], [ 3379, %then.5 ], [ 52410, %else.7 ], [ -1526438411, %endif.2 ], [ %tmp.12, %else.0 ] ; <i32> [#uses=1]
+ ret i32 %result.0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll b/src/LLVM/test/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
new file mode 100644
index 0000000..ceeddbb
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; END.
+
+define void @main() {
+entry:
+ %tmp.14.i19 = icmp eq i32 0, 2 ; <i1> [#uses=1]
+ br i1 %tmp.14.i19, label %endif.1.i20, label %read_min.exit
+endif.1.i20: ; preds = %entry
+ %tmp.9.i.i = icmp eq i8* null, null ; <i1> [#uses=1]
+ br i1 %tmp.9.i.i, label %then.i12.i, label %then.i.i
+then.i.i: ; preds = %endif.1.i20
+ ret void
+then.i12.i: ; preds = %endif.1.i20
+ %tmp.9.i4.i = icmp eq i8* null, null ; <i1> [#uses=1]
+ br i1 %tmp.9.i4.i, label %endif.2.i33, label %then.i5.i
+then.i5.i: ; preds = %then.i12.i
+ ret void
+endif.2.i33: ; preds = %then.i12.i
+ br i1 false, label %loopexit.0.i40, label %no_exit.0.i35
+no_exit.0.i35: ; preds = %no_exit.0.i35, %endif.2.i33
+ %tmp.130.i = icmp slt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.130.i, label %loopexit.0.i40.loopexit, label %no_exit.0.i35
+loopexit.0.i40.loopexit: ; preds = %no_exit.0.i35
+ br label %loopexit.0.i40
+loopexit.0.i40: ; preds = %loopexit.0.i40.loopexit, %endif.2.i33
+ %tmp.341.i = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.341.i, label %loopentry.1.i, label %read_min.exit
+loopentry.1.i: ; preds = %loopexit.0.i40
+ %tmp.347.i = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.347.i, label %no_exit.1.i41, label %loopexit.2.i44
+no_exit.1.i41: ; preds = %endif.5.i, %loopentry.1.i
+ %indvar.i42 = phi i32 [ %indvar.next.i, %endif.5.i ], [ 0, %loopentry.1.i ] ; <i32> [#uses=1]
+ %tmp.355.i = icmp eq i32 0, 3 ; <i1> [#uses=1]
+ br i1 %tmp.355.i, label %endif.5.i, label %read_min.exit
+endif.5.i: ; preds = %no_exit.1.i41
+ %tmp.34773.i = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+ %indvar.next.i = add i32 %indvar.i42, 1 ; <i32> [#uses=1]
+ br i1 %tmp.34773.i, label %no_exit.1.i41, label %loopexit.1.i.loopexit
+loopexit.1.i.loopexit: ; preds = %endif.5.i
+ ret void
+loopexit.2.i44: ; preds = %loopentry.1.i
+ ret void
+read_min.exit: ; preds = %no_exit.1.i41, %loopexit.0.i40, %entry
+ %tmp.23 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.23, label %endif.1, label %then.1
+then.1: ; preds = %read_min.exit
+ br i1 false, label %endif.0.i, label %then.0.i
+then.0.i: ; preds = %then.1
+ br i1 false, label %endif.1.i, label %then.1.i
+endif.0.i: ; preds = %then.1
+ br i1 false, label %endif.1.i, label %then.1.i
+then.1.i: ; preds = %endif.0.i, %then.0.i
+ br i1 false, label %getfree.exit, label %then.2.i
+endif.1.i: ; preds = %endif.0.i, %then.0.i
+ br i1 false, label %getfree.exit, label %then.2.i
+then.2.i: ; preds = %endif.1.i, %then.1.i
+ ret void
+getfree.exit: ; preds = %endif.1.i, %then.1.i
+ ret void
+endif.1: ; preds = %read_min.exit
+ %tmp.27.i = getelementptr i32* null, i32 0 ; <i32*> [#uses=0]
+ br i1 false, label %loopexit.0.i15, label %no_exit.0.i14
+no_exit.0.i14: ; preds = %endif.1
+ ret void
+loopexit.0.i15: ; preds = %endif.1
+ br i1 false, label %primal_start_artificial.exit, label %no_exit.1.i16
+no_exit.1.i16: ; preds = %no_exit.1.i16, %loopexit.0.i15
+ br i1 false, label %primal_start_artificial.exit, label %no_exit.1.i16
+primal_start_artificial.exit: ; preds = %no_exit.1.i16, %loopexit.0.i15
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2005-10-02-InvokeSimplify.ll b/src/LLVM/test/Transforms/SimplifyCFG/2005-10-02-InvokeSimplify.ll
new file mode 100644
index 0000000..7cc8ded
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2005-10-02-InvokeSimplify.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -simplifycfg -disable-output
+
+define i1 @foo() {
+ %X = invoke i1 @foo( )
+ to label %N unwind label %F ; <i1> [#uses=1]
+F: ; preds = %0
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ catch i8* null
+ ret i1 false
+N: ; preds = %0
+ br i1 %X, label %A, label %B
+A: ; preds = %N
+ ret i1 true
+B: ; preds = %N
+ ret i1 true
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2005-12-03-IncorrectPHIFold.ll b/src/LLVM/test/Transforms/SimplifyCFG/2005-12-03-IncorrectPHIFold.ll
new file mode 100644
index 0000000..badedee
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2005-12-03-IncorrectPHIFold.ll
@@ -0,0 +1,124 @@
+; Make sure this doesn't turn into an infinite loop
+
+; RUN: opt < %s -simplifycfg -constprop -simplifycfg |\
+; RUN: llvm-dis | grep bb86
+; END.
+
+%struct.anon = type { i32, i32, i32, i32, [1024 x i8] }
+@_zero_ = external global %struct.anon* ; <%struct.anon**> [#uses=2]
+@_one_ = external global %struct.anon* ; <%struct.anon**> [#uses=4]
+@str = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=0]
+
+declare i32 @bc_compare(%struct.anon*, %struct.anon*)
+
+declare void @free_num(%struct.anon**)
+
+declare %struct.anon* @copy_num(%struct.anon*)
+
+declare void @init_num(%struct.anon**)
+
+declare %struct.anon* @new_num(i32, i32)
+
+declare void @int2num(%struct.anon**, i32)
+
+declare void @bc_multiply(%struct.anon*, %struct.anon*, %struct.anon**, i32)
+
+declare void @bc_raise(%struct.anon*, %struct.anon*, %struct.anon**, i32)
+
+declare i32 @bc_divide(%struct.anon*, %struct.anon*, %struct.anon**, i32)
+
+declare void @bc_add(%struct.anon*, %struct.anon*, %struct.anon**)
+
+declare i32 @_do_compare(%struct.anon*, %struct.anon*, i32, i32)
+
+declare i32 @printf(i8*, ...)
+
+define i32 @bc_sqrt(%struct.anon** %num, i32 %scale) {
+entry:
+ %guess = alloca %struct.anon* ; <%struct.anon**> [#uses=7]
+ %guess1 = alloca %struct.anon* ; <%struct.anon**> [#uses=7]
+ %point5 = alloca %struct.anon* ; <%struct.anon**> [#uses=3]
+ %tmp = load %struct.anon** %num ; <%struct.anon*> [#uses=1]
+ %tmp1 = load %struct.anon** @_zero_ ; <%struct.anon*> [#uses=1]
+ %tmp.upgrd.1 = call i32 @bc_compare( %struct.anon* %tmp, %struct.anon* %tmp1 ) ; <i32> [#uses=2]
+ %tmp.upgrd.2 = icmp slt i32 %tmp.upgrd.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp.upgrd.2, label %cond_true, label %cond_false
+cond_true: ; preds = %entry
+ ret i32 0
+cond_false: ; preds = %entry
+ %tmp5 = icmp eq i32 %tmp.upgrd.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp5, label %cond_true6, label %cond_next13
+cond_true6: ; preds = %cond_false
+ call void @free_num( %struct.anon** %num )
+ %tmp8 = load %struct.anon** @_zero_ ; <%struct.anon*> [#uses=1]
+ %tmp9 = call %struct.anon* @copy_num( %struct.anon* %tmp8 ) ; <%struct.anon*> [#uses=1]
+ store %struct.anon* %tmp9, %struct.anon** %num
+ ret i32 1
+cond_next13: ; preds = %cond_false
+ %tmp15 = load %struct.anon** %num ; <%struct.anon*> [#uses=1]
+ %tmp16 = load %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
+ %tmp17 = call i32 @bc_compare( %struct.anon* %tmp15, %struct.anon* %tmp16 ) ; <i32> [#uses=2]
+ %tmp19 = icmp eq i32 %tmp17, 0 ; <i1> [#uses=1]
+ br i1 %tmp19, label %cond_true20, label %cond_next27
+cond_true20: ; preds = %cond_next13
+ call void @free_num( %struct.anon** %num )
+ %tmp22 = load %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
+ %tmp23 = call %struct.anon* @copy_num( %struct.anon* %tmp22 ) ; <%struct.anon*> [#uses=1]
+ store %struct.anon* %tmp23, %struct.anon** %num
+ ret i32 1
+cond_next27: ; preds = %cond_next13
+ %tmp29 = load %struct.anon** %num ; <%struct.anon*> [#uses=1]
+ %tmp30 = getelementptr %struct.anon* %tmp29, i32 0, i32 2 ; <i32*> [#uses=1]
+ %tmp31 = load i32* %tmp30 ; <i32> [#uses=2]
+ %tmp33 = icmp sge i32 %tmp31, %scale ; <i1> [#uses=1]
+ %max = select i1 %tmp33, i32 %tmp31, i32 %scale ; <i32> [#uses=4]
+ %tmp35 = add i32 %max, 2 ; <i32> [#uses=0]
+ call void @init_num( %struct.anon** %guess )
+ call void @init_num( %struct.anon** %guess1 )
+ %tmp36 = call %struct.anon* @new_num( i32 1, i32 1 ) ; <%struct.anon*> [#uses=2]
+ store %struct.anon* %tmp36, %struct.anon** %point5
+ %tmp.upgrd.3 = getelementptr %struct.anon* %tmp36, i32 0, i32 4, i32 1 ; <i8*> [#uses=1]
+ store i8 5, i8* %tmp.upgrd.3
+ %tmp39 = icmp slt i32 %tmp17, 0 ; <i1> [#uses=1]
+ br i1 %tmp39, label %cond_true40, label %cond_false43
+cond_true40: ; preds = %cond_next27
+ %tmp41 = load %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
+ %tmp42 = call %struct.anon* @copy_num( %struct.anon* %tmp41 ) ; <%struct.anon*> [#uses=1]
+ store %struct.anon* %tmp42, %struct.anon** %guess
+ br label %bb80.outer
+cond_false43: ; preds = %cond_next27
+ call void @int2num( %struct.anon** %guess, i32 10 )
+ %tmp45 = load %struct.anon** %num ; <%struct.anon*> [#uses=1]
+ %tmp46 = getelementptr %struct.anon* %tmp45, i32 0, i32 1 ; <i32*> [#uses=1]
+ %tmp47 = load i32* %tmp46 ; <i32> [#uses=1]
+ call void @int2num( %struct.anon** %guess1, i32 %tmp47 )
+ %tmp48 = load %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
+ %tmp49 = load %struct.anon** %point5 ; <%struct.anon*> [#uses=1]
+ call void @bc_multiply( %struct.anon* %tmp48, %struct.anon* %tmp49, %struct.anon** %guess1, i32 %max )
+ %tmp51 = load %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
+ %tmp52 = getelementptr %struct.anon* %tmp51, i32 0, i32 2 ; <i32*> [#uses=1]
+ store i32 0, i32* %tmp52
+ %tmp53 = load %struct.anon** %guess ; <%struct.anon*> [#uses=1]
+ %tmp54 = load %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
+ call void @bc_raise( %struct.anon* %tmp53, %struct.anon* %tmp54, %struct.anon** %guess, i32 %max )
+ br label %bb80.outer
+bb80.outer: ; preds = %cond_true83, %cond_false43, %cond_true40
+ %done.1.ph = phi i32 [ 1, %cond_true83 ], [ 0, %cond_true40 ], [ 0, %cond_false43 ] ; <i32> [#uses=1]
+ br label %bb80
+bb80: ; preds = %cond_true83, %bb80.outer
+ %tmp82 = icmp eq i32 %done.1.ph, 0 ; <i1> [#uses=1]
+ br i1 %tmp82, label %cond_true83, label %bb86
+cond_true83: ; preds = %bb80
+ %tmp71 = call i32 @_do_compare( %struct.anon* null, %struct.anon* null, i32 0, i32 1 ) ; <i32> [#uses=1]
+ %tmp76 = icmp eq i32 %tmp71, 0 ; <i1> [#uses=1]
+ br i1 %tmp76, label %bb80.outer, label %bb80
+bb86: ; preds = %bb80
+ call void @free_num( %struct.anon** %num )
+ %tmp88 = load %struct.anon** %guess ; <%struct.anon*> [#uses=1]
+ %tmp89 = load %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
+ %tmp92 = call i32 @bc_divide( %struct.anon* %tmp88, %struct.anon* %tmp89, %struct.anon** %num, i32 %max ) ; <i32> [#uses=0]
+ call void @free_num( %struct.anon** %guess )
+ call void @free_num( %struct.anon** %guess1 )
+ call void @free_num( %struct.anon** %point5 )
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-02-17-InfiniteUnroll.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-02-17-InfiniteUnroll.ll
new file mode 100644
index 0000000..67faac7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-02-17-InfiniteUnroll.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -simplifycfg -disable-output
+
+define void @polnel_() {
+entry:
+ %tmp595 = icmp slt i32 0, 0 ; <i1> [#uses=4]
+ br i1 %tmp595, label %bb148.critedge, label %cond_true40
+bb36: ; preds = %bb43
+ br i1 %tmp595, label %bb43, label %cond_true40
+cond_true40: ; preds = %bb46, %cond_true40, %bb36, %entry
+ %tmp397 = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp397, label %bb43, label %cond_true40
+bb43: ; preds = %cond_true40, %bb36
+ br i1 false, label %bb53, label %bb36
+bb46: ; preds = %bb53
+ br i1 %tmp595, label %bb53, label %cond_true40
+bb53: ; preds = %bb46, %bb43
+ br i1 false, label %bb102, label %bb46
+bb92.preheader: ; preds = %bb102
+ ret void
+bb102: ; preds = %bb53
+ br i1 %tmp595, label %bb148, label %bb92.preheader
+bb148.critedge: ; preds = %entry
+ ret void
+bb148: ; preds = %bb102
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-06-12-InfLoop.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-06-12-InfLoop.ll
new file mode 100644
index 0000000..a48154a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-06-12-InfLoop.ll
@@ -0,0 +1,413 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; END.
+
+define void @main(i32 %c) {
+entry:
+ %tmp.9 = icmp eq i32 %c, 2 ; <i1> [#uses=1]
+ br i1 %tmp.9, label %endif.0, label %then.0
+then.0: ; preds = %entry
+ ret void
+endif.0: ; preds = %entry
+ br i1 false, label %then.1, label %endif.1
+then.1: ; preds = %endif.0
+ ret void
+endif.1: ; preds = %endif.0
+ br i1 false, label %then.2, label %endif.2
+then.2: ; preds = %endif.1
+ ret void
+endif.2: ; preds = %endif.1
+ br i1 false, label %then.3, label %loopentry.0
+then.3: ; preds = %endif.2
+ ret void
+loopentry.0: ; preds = %endif.2
+ br i1 false, label %no_exit.0.preheader, label %loopexit.0
+no_exit.0.preheader: ; preds = %loopentry.0
+ br label %no_exit.0
+no_exit.0: ; preds = %endif.4, %no_exit.0.preheader
+ br i1 false, label %then.4, label %endif.4
+then.4: ; preds = %no_exit.0
+ ret void
+endif.4: ; preds = %no_exit.0
+ br i1 false, label %no_exit.0, label %loopexit.0.loopexit
+loopexit.0.loopexit: ; preds = %endif.4
+ br label %loopexit.0
+loopexit.0: ; preds = %loopexit.0.loopexit, %loopentry.0
+ br i1 false, label %then.5, label %loopentry.1
+then.5: ; preds = %loopexit.0
+ ret void
+loopentry.1: ; preds = %loopexit.0
+ %tmp.143 = icmp sgt i32 0, 0 ; <i1> [#uses=4]
+ br i1 %tmp.143, label %no_exit.1.preheader, label %loopexit.1
+no_exit.1.preheader: ; preds = %loopentry.1
+ br label %no_exit.1
+no_exit.1: ; preds = %endif.6, %no_exit.1.preheader
+ br i1 false, label %then.6, label %shortcirc_next.3
+shortcirc_next.3: ; preds = %no_exit.1
+ br i1 false, label %then.6, label %shortcirc_next.4
+shortcirc_next.4: ; preds = %shortcirc_next.3
+ br i1 false, label %then.6, label %endif.6
+then.6: ; preds = %shortcirc_next.4, %shortcirc_next.3, %no_exit.1
+ ret void
+endif.6: ; preds = %shortcirc_next.4
+ br i1 false, label %no_exit.1, label %loopexit.1.loopexit
+loopexit.1.loopexit: ; preds = %endif.6
+ br label %loopexit.1
+loopexit.1: ; preds = %loopexit.1.loopexit, %loopentry.1
+ br i1 false, label %then.i, label %loopentry.0.i
+then.i: ; preds = %loopexit.1
+ ret void
+loopentry.0.i: ; preds = %loopexit.1
+ br i1 %tmp.143, label %no_exit.0.i.preheader, label %readvector.exit
+no_exit.0.i.preheader: ; preds = %loopentry.0.i
+ br label %no_exit.0.i
+no_exit.0.i: ; preds = %loopexit.1.i, %no_exit.0.i.preheader
+ br i1 false, label %no_exit.1.i.preheader, label %loopexit.1.i
+no_exit.1.i.preheader: ; preds = %no_exit.0.i
+ br label %no_exit.1.i
+no_exit.1.i: ; preds = %loopexit.2.i, %no_exit.1.i.preheader
+ br i1 false, label %no_exit.2.i.preheader, label %loopexit.2.i
+no_exit.2.i.preheader: ; preds = %no_exit.1.i
+ br label %no_exit.2.i
+no_exit.2.i: ; preds = %no_exit.2.i, %no_exit.2.i.preheader
+ br i1 false, label %no_exit.2.i, label %loopexit.2.i.loopexit
+loopexit.2.i.loopexit: ; preds = %no_exit.2.i
+ br label %loopexit.2.i
+loopexit.2.i: ; preds = %loopexit.2.i.loopexit, %no_exit.1.i
+ br i1 false, label %no_exit.1.i, label %loopexit.1.i.loopexit
+loopexit.1.i.loopexit: ; preds = %loopexit.2.i
+ br label %loopexit.1.i
+loopexit.1.i: ; preds = %loopexit.1.i.loopexit, %no_exit.0.i
+ br i1 false, label %no_exit.0.i, label %readvector.exit.loopexit
+readvector.exit.loopexit: ; preds = %loopexit.1.i
+ br label %readvector.exit
+readvector.exit: ; preds = %readvector.exit.loopexit, %loopentry.0.i
+ br i1 %tmp.143, label %loopentry.1.preheader.i, label %loopexit.0.i
+loopentry.1.preheader.i: ; preds = %readvector.exit
+ br label %loopentry.1.outer.i
+loopentry.1.outer.i: ; preds = %loopexit.1.i110, %loopentry.1.preheader.i
+ br label %loopentry.1.i85
+loopentry.1.i85.loopexit: ; preds = %hamming.exit16.i
+ br label %loopentry.1.i85
+loopentry.1.i85: ; preds = %loopentry.1.i85.loopexit, %loopentry.1.outer.i
+ br i1 false, label %no_exit.1.preheader.i, label %loopexit.1.i110.loopexit1
+no_exit.1.preheader.i: ; preds = %loopentry.1.i85
+ br label %no_exit.1.i87
+no_exit.1.i87: ; preds = %then.1.i107, %no_exit.1.preheader.i
+ br i1 false, label %no_exit.i.i101.preheader, label %hamming.exit.i104
+no_exit.i.i101.preheader: ; preds = %no_exit.1.i87
+ br label %no_exit.i.i101
+no_exit.i.i101: ; preds = %no_exit.i.i101, %no_exit.i.i101.preheader
+ br i1 false, label %no_exit.i.i101, label %hamming.exit.i104.loopexit
+hamming.exit.i104.loopexit: ; preds = %no_exit.i.i101
+ br label %hamming.exit.i104
+hamming.exit.i104: ; preds = %hamming.exit.i104.loopexit, %no_exit.1.i87
+ br i1 false, label %no_exit.i15.i.preheader, label %hamming.exit16.i
+no_exit.i15.i.preheader: ; preds = %hamming.exit.i104
+ br label %no_exit.i15.i
+no_exit.i15.i: ; preds = %no_exit.i15.i, %no_exit.i15.i.preheader
+ br i1 false, label %no_exit.i15.i, label %hamming.exit16.i.loopexit
+hamming.exit16.i.loopexit: ; preds = %no_exit.i15.i
+ br label %hamming.exit16.i
+hamming.exit16.i: ; preds = %hamming.exit16.i.loopexit, %hamming.exit.i104
+ br i1 false, label %loopentry.1.i85.loopexit, label %then.1.i107
+then.1.i107: ; preds = %hamming.exit16.i
+ br i1 false, label %no_exit.1.i87, label %loopexit.1.i110.loopexit
+loopexit.1.i110.loopexit: ; preds = %then.1.i107
+ br label %loopexit.1.i110
+loopexit.1.i110.loopexit1: ; preds = %loopentry.1.i85
+ br label %loopexit.1.i110
+loopexit.1.i110: ; preds = %loopexit.1.i110.loopexit1, %loopexit.1.i110.loopexit
+ br i1 false, label %loopentry.1.outer.i, label %loopexit.0.i.loopexit
+loopexit.0.i.loopexit: ; preds = %loopexit.1.i110
+ br label %loopexit.0.i
+loopexit.0.i: ; preds = %loopexit.0.i.loopexit, %readvector.exit
+ br i1 false, label %UnifiedReturnBlock.i113, label %then.2.i112
+then.2.i112: ; preds = %loopexit.0.i
+ br label %checkham.exit
+UnifiedReturnBlock.i113: ; preds = %loopexit.0.i
+ br label %checkham.exit
+checkham.exit: ; preds = %UnifiedReturnBlock.i113, %then.2.i112
+ br i1 false, label %loopentry.1.i14.preheader, label %loopentry.3.i.preheader
+loopentry.1.i14.preheader: ; preds = %checkham.exit
+ br label %loopentry.1.i14
+loopentry.1.i14: ; preds = %loopexit.1.i18, %loopentry.1.i14.preheader
+ br i1 false, label %no_exit.1.i16.preheader, label %loopexit.1.i18
+no_exit.1.i16.preheader: ; preds = %loopentry.1.i14
+ br label %no_exit.1.i16
+no_exit.1.i16: ; preds = %no_exit.1.i16, %no_exit.1.i16.preheader
+ br i1 false, label %no_exit.1.i16, label %loopexit.1.i18.loopexit
+loopexit.1.i18.loopexit: ; preds = %no_exit.1.i16
+ br label %loopexit.1.i18
+loopexit.1.i18: ; preds = %loopexit.1.i18.loopexit, %loopentry.1.i14
+ br i1 false, label %loopentry.1.i14, label %loopentry.3.i.loopexit
+loopentry.3.i.loopexit: ; preds = %loopexit.1.i18
+ br label %loopentry.3.i.preheader
+loopentry.3.i.preheader: ; preds = %loopentry.3.i.loopexit, %checkham.exit
+ br label %loopentry.3.i
+loopentry.3.i: ; preds = %endif.1.i, %loopentry.3.i.preheader
+ br i1 false, label %loopentry.4.i.preheader, label %endif.1.i
+loopentry.4.i.preheader: ; preds = %loopentry.3.i
+ br label %loopentry.4.i
+loopentry.4.i: ; preds = %loopexit.4.i, %loopentry.4.i.preheader
+ br i1 false, label %no_exit.4.i.preheader, label %loopexit.4.i
+no_exit.4.i.preheader: ; preds = %loopentry.4.i
+ br label %no_exit.4.i
+no_exit.4.i: ; preds = %no_exit.4.i.backedge, %no_exit.4.i.preheader
+ br i1 false, label %endif.0.i, label %else.i
+else.i: ; preds = %no_exit.4.i
+ br i1 false, label %no_exit.4.i.backedge, label %loopexit.4.i.loopexit
+no_exit.4.i.backedge: ; preds = %endif.0.i, %else.i
+ br label %no_exit.4.i
+endif.0.i: ; preds = %no_exit.4.i
+ br i1 false, label %no_exit.4.i.backedge, label %loopexit.4.i.loopexit
+loopexit.4.i.loopexit: ; preds = %endif.0.i, %else.i
+ br label %loopexit.4.i
+loopexit.4.i: ; preds = %loopexit.4.i.loopexit, %loopentry.4.i
+ br i1 false, label %loopentry.4.i, label %endif.1.i.loopexit
+endif.1.i.loopexit: ; preds = %loopexit.4.i
+ br label %endif.1.i
+endif.1.i: ; preds = %endif.1.i.loopexit, %loopentry.3.i
+ %exitcond = icmp eq i32 0, 10 ; <i1> [#uses=1]
+ br i1 %exitcond, label %generateT.exit, label %loopentry.3.i
+generateT.exit: ; preds = %endif.1.i
+ br i1 false, label %then.0.i, label %loopentry.1.i30.preheader
+then.0.i: ; preds = %generateT.exit
+ ret void
+loopentry.1.i30.loopexit: ; preds = %loopexit.3.i
+ br label %loopentry.1.i30.backedge
+loopentry.1.i30.preheader: ; preds = %generateT.exit
+ br label %loopentry.1.i30
+loopentry.1.i30: ; preds = %loopentry.1.i30.backedge, %loopentry.1.i30.preheader
+ br i1 %tmp.143, label %no_exit.0.i31.preheader, label %loopentry.1.i30.backedge
+loopentry.1.i30.backedge: ; preds = %loopentry.1.i30, %loopentry.1.i30.loopexit
+ br label %loopentry.1.i30
+no_exit.0.i31.preheader: ; preds = %loopentry.1.i30
+ br label %no_exit.0.i31
+no_exit.0.i31: ; preds = %loopexit.3.i, %no_exit.0.i31.preheader
+ br i1 false, label %then.1.i, label %else.0.i
+then.1.i: ; preds = %no_exit.0.i31
+ br i1 undef, label %then.0.i29, label %loopentry.0.i31
+then.0.i29: ; preds = %then.1.i
+ unreachable
+loopentry.0.i31: ; preds = %then.1.i
+ br i1 false, label %no_exit.0.i38.preheader, label %loopentry.1.i.preheader
+no_exit.0.i38.preheader: ; preds = %loopentry.0.i31
+ br label %no_exit.0.i38
+no_exit.0.i38: ; preds = %no_exit.0.i38, %no_exit.0.i38.preheader
+ br i1 undef, label %no_exit.0.i38, label %loopentry.1.i.preheader.loopexit
+loopentry.1.i.preheader.loopexit: ; preds = %no_exit.0.i38
+ br label %loopentry.1.i.preheader
+loopentry.1.i.preheader: ; preds = %loopentry.1.i.preheader.loopexit, %loopentry.0.i31
+ br label %loopentry.1.i
+loopentry.1.i: ; preds = %endif.2.i, %loopentry.1.i.preheader
+ br i1 undef, label %loopentry.2.i39.preheader, label %loopexit.1.i79.loopexit2
+loopentry.2.i39.preheader: ; preds = %loopentry.1.i
+ br label %loopentry.2.i39
+loopentry.2.i39: ; preds = %loopexit.5.i77, %loopentry.2.i39.preheader
+ br i1 false, label %loopentry.3.i40.preheader, label %hamming.exit.i71
+loopentry.3.i40.preheader: ; preds = %loopentry.2.i39
+ br label %loopentry.3.i40
+loopentry.3.i40: ; preds = %loopexit.3.i51, %loopentry.3.i40.preheader
+ br i1 false, label %no_exit.3.preheader.i42, label %loopexit.3.i51
+no_exit.3.preheader.i42: ; preds = %loopentry.3.i40
+ br label %no_exit.3.i49
+no_exit.3.i49: ; preds = %no_exit.3.i49, %no_exit.3.preheader.i42
+ br i1 undef, label %no_exit.3.i49, label %loopexit.3.i51.loopexit
+loopexit.3.i51.loopexit: ; preds = %no_exit.3.i49
+ br label %loopexit.3.i51
+loopexit.3.i51: ; preds = %loopexit.3.i51.loopexit, %loopentry.3.i40
+ br i1 undef, label %loopentry.3.i40, label %loopentry.4.i52
+loopentry.4.i52: ; preds = %loopexit.3.i51
+ br i1 false, label %no_exit.4.i54.preheader, label %hamming.exit.i71
+no_exit.4.i54.preheader: ; preds = %loopentry.4.i52
+ br label %no_exit.4.i54
+no_exit.4.i54: ; preds = %no_exit.4.backedge.i, %no_exit.4.i54.preheader
+ br i1 undef, label %then.1.i55, label %endif.1.i56
+then.1.i55: ; preds = %no_exit.4.i54
+ br i1 undef, label %no_exit.4.backedge.i, label %loopexit.4.i57
+no_exit.4.backedge.i: ; preds = %endif.1.i56, %then.1.i55
+ br label %no_exit.4.i54
+endif.1.i56: ; preds = %no_exit.4.i54
+ br i1 undef, label %no_exit.4.backedge.i, label %loopexit.4.i57
+loopexit.4.i57: ; preds = %endif.1.i56, %then.1.i55
+ br i1 false, label %no_exit.i.i69.preheader, label %hamming.exit.i71
+no_exit.i.i69.preheader: ; preds = %loopexit.4.i57
+ br label %no_exit.i.i69
+no_exit.i.i69: ; preds = %no_exit.i.i69, %no_exit.i.i69.preheader
+ br i1 undef, label %no_exit.i.i69, label %hamming.exit.i71.loopexit
+hamming.exit.i71.loopexit: ; preds = %no_exit.i.i69
+ br label %hamming.exit.i71
+hamming.exit.i71: ; preds = %hamming.exit.i71.loopexit, %loopexit.4.i57, %loopentry.4.i52, %loopentry.2.i39
+ br i1 undef, label %endif.2.i, label %loopentry.5.i72
+loopentry.5.i72: ; preds = %hamming.exit.i71
+ br i1 false, label %shortcirc_next.i74.preheader, label %loopexit.5.i77
+shortcirc_next.i74.preheader: ; preds = %loopentry.5.i72
+ br label %shortcirc_next.i74
+shortcirc_next.i74: ; preds = %no_exit.5.i76, %shortcirc_next.i74.preheader
+ br i1 undef, label %no_exit.5.i76, label %loopexit.5.i77.loopexit
+no_exit.5.i76: ; preds = %shortcirc_next.i74
+ br i1 undef, label %shortcirc_next.i74, label %loopexit.5.i77.loopexit
+loopexit.5.i77.loopexit: ; preds = %no_exit.5.i76, %shortcirc_next.i74
+ br label %loopexit.5.i77
+loopexit.5.i77: ; preds = %loopexit.5.i77.loopexit, %loopentry.5.i72
+ br i1 undef, label %loopentry.2.i39, label %loopexit.1.i79.loopexit
+endif.2.i: ; preds = %hamming.exit.i71
+ br label %loopentry.1.i
+loopexit.1.i79.loopexit: ; preds = %loopexit.5.i77
+ br label %loopexit.1.i79
+loopexit.1.i79.loopexit2: ; preds = %loopentry.1.i
+ br label %loopexit.1.i79
+loopexit.1.i79: ; preds = %loopexit.1.i79.loopexit2, %loopexit.1.i79.loopexit
+ br i1 undef, label %then.3.i, label %loopentry.6.i80
+then.3.i: ; preds = %loopexit.1.i79
+ br i1 false, label %no_exit.6.i82.preheader, label %run.exit
+loopentry.6.i80: ; preds = %loopexit.1.i79
+ br i1 false, label %no_exit.6.i82.preheader, label %run.exit
+no_exit.6.i82.preheader: ; preds = %loopentry.6.i80, %then.3.i
+ br label %no_exit.6.i82
+no_exit.6.i82: ; preds = %no_exit.6.i82, %no_exit.6.i82.preheader
+ br i1 undef, label %no_exit.6.i82, label %run.exit.loopexit
+run.exit.loopexit: ; preds = %no_exit.6.i82
+ br label %run.exit
+run.exit: ; preds = %run.exit.loopexit, %loopentry.6.i80, %then.3.i
+ br i1 false, label %no_exit.1.i36.preheader, label %loopentry.3.i37
+else.0.i: ; preds = %no_exit.0.i31
+ br i1 false, label %then.0.i4, label %loopentry.0.i6
+then.0.i4: ; preds = %else.0.i
+ unreachable
+loopentry.0.i6: ; preds = %else.0.i
+ br i1 false, label %no_exit.0.i8.preheader, label %loopentry.2.i.preheader
+no_exit.0.i8.preheader: ; preds = %loopentry.0.i6
+ br label %no_exit.0.i8
+no_exit.0.i8: ; preds = %no_exit.0.i8, %no_exit.0.i8.preheader
+ br i1 false, label %no_exit.0.i8, label %loopentry.2.i.preheader.loopexit
+loopentry.2.i.preheader.loopexit: ; preds = %no_exit.0.i8
+ br label %loopentry.2.i.preheader
+loopentry.2.i.preheader: ; preds = %loopentry.2.i.preheader.loopexit, %loopentry.0.i6
+ br label %loopentry.2.i
+loopentry.2.i: ; preds = %endif.3.i19, %loopentry.2.i.preheader
+ br i1 false, label %loopentry.3.i10.preheader, label %loopentry.4.i15
+loopentry.3.i10.preheader: ; preds = %loopentry.2.i
+ br label %loopentry.3.i10
+loopentry.3.i10: ; preds = %loopexit.3.i14, %loopentry.3.i10.preheader
+ br i1 false, label %no_exit.3.preheader.i, label %loopexit.3.i14
+no_exit.3.preheader.i: ; preds = %loopentry.3.i10
+ br label %no_exit.3.i12
+no_exit.3.i12: ; preds = %no_exit.3.i12, %no_exit.3.preheader.i
+ br i1 false, label %no_exit.3.i12, label %loopexit.3.i14.loopexit
+loopexit.3.i14.loopexit: ; preds = %no_exit.3.i12
+ br label %loopexit.3.i14
+loopexit.3.i14: ; preds = %loopexit.3.i14.loopexit, %loopentry.3.i10
+ br i1 false, label %loopentry.3.i10, label %loopentry.4.i15.loopexit
+loopentry.4.i15.loopexit: ; preds = %loopexit.3.i14
+ br label %loopentry.4.i15
+loopentry.4.i15: ; preds = %loopentry.4.i15.loopexit, %loopentry.2.i
+ br i1 false, label %loopentry.5.outer.i.preheader, label %loopentry.7.i
+loopentry.5.outer.i.preheader: ; preds = %loopentry.4.i15
+ br label %loopentry.5.outer.i
+loopentry.5.outer.i: ; preds = %loopexit.5.i, %loopentry.5.outer.i.preheader
+ br label %loopentry.5.i
+loopentry.5.i: ; preds = %endif.1.i18, %loopentry.5.outer.i
+ br i1 false, label %no_exit.5.i.preheader, label %loopexit.5.i.loopexit3
+no_exit.5.i.preheader: ; preds = %loopentry.5.i
+ br label %no_exit.5.i
+no_exit.5.i: ; preds = %then.2.i, %no_exit.5.i.preheader
+ br i1 false, label %loopentry.6.i, label %endif.1.i18
+loopentry.6.i: ; preds = %no_exit.5.i
+ br i1 false, label %no_exit.6.preheader.i, label %loopexit.6.i
+no_exit.6.preheader.i: ; preds = %loopentry.6.i
+ br label %no_exit.6.i
+no_exit.6.i: ; preds = %no_exit.6.i, %no_exit.6.preheader.i
+ br i1 false, label %no_exit.6.i, label %loopexit.6.i.loopexit
+loopexit.6.i.loopexit: ; preds = %no_exit.6.i
+ br label %loopexit.6.i
+loopexit.6.i: ; preds = %loopexit.6.i.loopexit, %loopentry.6.i
+ br i1 false, label %then.2.i, label %endif.1.i18
+then.2.i: ; preds = %loopexit.6.i
+ br i1 false, label %no_exit.5.i, label %loopexit.5.i.loopexit
+endif.1.i18: ; preds = %loopexit.6.i, %no_exit.5.i
+ br label %loopentry.5.i
+loopexit.5.i.loopexit: ; preds = %then.2.i
+ br label %loopexit.5.i
+loopexit.5.i.loopexit3: ; preds = %loopentry.5.i
+ br label %loopexit.5.i
+loopexit.5.i: ; preds = %loopexit.5.i.loopexit3, %loopexit.5.i.loopexit
+ br i1 false, label %loopentry.5.outer.i, label %loopentry.7.i.loopexit
+loopentry.7.i.loopexit: ; preds = %loopexit.5.i
+ br label %loopentry.7.i
+loopentry.7.i: ; preds = %loopentry.7.i.loopexit, %loopentry.4.i15
+ br i1 false, label %no_exit.7.i.preheader, label %hamming.exit.i
+no_exit.7.i.preheader: ; preds = %loopentry.7.i
+ br label %no_exit.7.i
+no_exit.7.i: ; preds = %no_exit.7.i, %no_exit.7.i.preheader
+ br i1 false, label %no_exit.7.i, label %loopexit.7.i
+loopexit.7.i: ; preds = %no_exit.7.i
+ br i1 false, label %no_exit.i.i.preheader, label %hamming.exit.i
+no_exit.i.i.preheader: ; preds = %loopexit.7.i
+ br label %no_exit.i.i
+no_exit.i.i: ; preds = %no_exit.i.i, %no_exit.i.i.preheader
+ br i1 false, label %no_exit.i.i, label %hamming.exit.i.loopexit
+hamming.exit.i.loopexit: ; preds = %no_exit.i.i
+ br label %hamming.exit.i
+hamming.exit.i: ; preds = %hamming.exit.i.loopexit, %loopexit.7.i, %loopentry.7.i
+ br i1 false, label %endif.3.i19, label %loopentry.8.i
+loopentry.8.i: ; preds = %hamming.exit.i
+ br i1 false, label %shortcirc_next.i.preheader, label %loopexit.8.i
+shortcirc_next.i.preheader: ; preds = %loopentry.8.i
+ br label %shortcirc_next.i
+shortcirc_next.i: ; preds = %no_exit.8.i, %shortcirc_next.i.preheader
+ br i1 false, label %no_exit.8.i, label %loopexit.8.i.loopexit
+no_exit.8.i: ; preds = %shortcirc_next.i
+ br i1 false, label %shortcirc_next.i, label %loopexit.8.i.loopexit
+loopexit.8.i.loopexit: ; preds = %no_exit.8.i, %shortcirc_next.i
+ br label %loopexit.8.i
+loopexit.8.i: ; preds = %loopexit.8.i.loopexit, %loopentry.8.i
+ br i1 false, label %no_exit.9.i.preheader, label %endif.3.i19
+no_exit.9.i.preheader: ; preds = %loopexit.8.i
+ br label %no_exit.9.i
+no_exit.9.i: ; preds = %no_exit.9.i, %no_exit.9.i.preheader
+ br i1 false, label %no_exit.9.i, label %endif.3.i19.loopexit
+endif.3.i19.loopexit: ; preds = %no_exit.9.i
+ br label %endif.3.i19
+endif.3.i19: ; preds = %endif.3.i19.loopexit, %loopexit.8.i, %hamming.exit.i
+ br i1 false, label %loopentry.2.i, label %loopexit.1.i20
+loopexit.1.i20: ; preds = %endif.3.i19
+ br i1 false, label %then.4.i, label %UnifiedReturnBlock.i
+then.4.i: ; preds = %loopexit.1.i20
+ br label %runcont.exit
+UnifiedReturnBlock.i: ; preds = %loopexit.1.i20
+ br label %runcont.exit
+runcont.exit: ; preds = %UnifiedReturnBlock.i, %then.4.i
+ br i1 false, label %no_exit.1.i36.preheader, label %loopentry.3.i37
+no_exit.1.i36.preheader: ; preds = %runcont.exit, %run.exit
+ br label %no_exit.1.i36
+no_exit.1.i36: ; preds = %no_exit.1.i36, %no_exit.1.i36.preheader
+ br i1 false, label %no_exit.1.i36, label %loopentry.3.i37.loopexit
+loopentry.3.i37.loopexit: ; preds = %no_exit.1.i36
+ br label %loopentry.3.i37
+loopentry.3.i37: ; preds = %loopentry.3.i37.loopexit, %runcont.exit, %run.exit
+ br i1 false, label %loopentry.4.i38.preheader, label %loopexit.3.i
+loopentry.4.i38.preheader: ; preds = %loopentry.3.i37
+ br label %loopentry.4.i38
+loopentry.4.i38: ; preds = %loopexit.4.i42, %loopentry.4.i38.preheader
+ br i1 false, label %no_exit.3.i.preheader, label %loopexit.4.i42
+no_exit.3.i.preheader: ; preds = %loopentry.4.i38
+ br label %no_exit.3.i
+no_exit.3.i: ; preds = %no_exit.3.i.backedge, %no_exit.3.i.preheader
+ br i1 false, label %endif.3.i, label %else.1.i
+else.1.i: ; preds = %no_exit.3.i
+ br i1 false, label %no_exit.3.i.backedge, label %loopexit.4.i42.loopexit
+no_exit.3.i.backedge: ; preds = %endif.3.i, %else.1.i
+ br label %no_exit.3.i
+endif.3.i: ; preds = %no_exit.3.i
+ br i1 false, label %no_exit.3.i.backedge, label %loopexit.4.i42.loopexit
+loopexit.4.i42.loopexit: ; preds = %endif.3.i, %else.1.i
+ br label %loopexit.4.i42
+loopexit.4.i42: ; preds = %loopexit.4.i42.loopexit, %loopentry.4.i38
+ br i1 false, label %loopentry.4.i38, label %loopexit.3.i.loopexit
+loopexit.3.i.loopexit: ; preds = %loopexit.4.i42
+ br label %loopexit.3.i
+loopexit.3.i: ; preds = %loopexit.3.i.loopexit, %loopentry.3.i37
+ %tmp.13.i155 = icmp slt i32 0, 0 ; <i1> [#uses=1]
+ br i1 %tmp.13.i155, label %no_exit.0.i31, label %loopentry.1.i30.loopexit
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-08-03-Crash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-08-03-Crash.ll
new file mode 100644
index 0000000..d60481f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-08-03-Crash.ll
@@ -0,0 +1,96 @@
+; RUN: opt < %s -gvn -simplifycfg -disable-output
+; PR867
+
+target datalayout = "E-p:32:32"
+target triple = "powerpc-apple-darwin8"
+ %struct.CUMULATIVE_ARGS = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
+ %struct.eh_status = type opaque
+ %struct.emit_status = type { i32, i32, %struct.rtx_def*, %struct.rtx_def*, %struct.sequence_stack*, i32, %struct.location_t, i32, i8*, %struct.rtx_def** }
+ %struct.expr_status = type { i32, i32, i32, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def* }
+ %struct.function = type { %struct.eh_status*, %struct.expr_status*, %struct.emit_status*, %struct.varasm_status*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.function*, i32, i32, i32, i32, %struct.rtx_def*, %struct.CUMULATIVE_ARGS, %struct.rtx_def*, %struct.rtx_def*, %struct.initial_value_struct*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, i8, i32, i64, %struct.tree_node*, %struct.tree_node*, %struct.rtx_def*, %struct.varray_head_tag*, %struct.temp_slot*, i32, %struct.var_refs_queue*, i32, i32, %struct.rtvec_def*, %struct.tree_node*, i32, i32, i32, %struct.machine_function*, i32, i32, i8, i8, %struct.language_function*, %struct.rtx_def*, i32, i32, i32, i32, %struct.location_t, %struct.varray_head_tag*, %struct.tree_node*, i8, i8, i8 }
+ %struct.initial_value_struct = type opaque
+ %struct.lang_decl = type opaque
+ %struct.lang_type = type opaque
+ %struct.language_function = type opaque
+ %struct.location_t = type { i8*, i32 }
+ %struct.machine_function = type { i32, i32, i8*, i32, i32 }
+ %struct.rtunion = type { i32 }
+ %struct.rtvec_def = type { i32, [1 x %struct.rtx_def*] }
+ %struct.rtx_def = type { i16, i8, i8, %struct.u }
+ %struct.sequence_stack = type { %struct.rtx_def*, %struct.rtx_def*, %struct.sequence_stack* }
+ %struct.temp_slot = type opaque
+ %struct.tree_common = type { %struct.tree_node*, %struct.tree_node*, %union.tree_ann_d*, i8, i8, i8, i8, i8 }
+ %struct.tree_decl = type { %struct.tree_common, %struct.location_t, i32, %struct.tree_node*, i8, i8, i8, i8, i8, i8, i8, i8, i32, %struct.tree_decl_u1, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.rtx_def*, %struct.tree_decl_u2, %struct.tree_node*, %struct.tree_node*, i64, %struct.lang_decl* }
+ %struct.tree_decl_u1 = type { i64 }
+ %struct.tree_decl_u2 = type { %struct.function* }
+ %struct.tree_node = type { %struct.tree_decl }
+ %struct.tree_type = type { %struct.tree_common, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, i32, i16, i8, i8, i32, %struct.tree_node*, %struct.tree_node*, %struct.rtunion, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, %struct.tree_node*, i64, %struct.lang_type* }
+ %struct.u = type { [1 x i64] }
+ %struct.var_refs_queue = type { %struct.rtx_def*, i32, i32, %struct.var_refs_queue* }
+ %struct.varasm_status = type opaque
+ %struct.varray_head_tag = type { i32, i32, i32, i8*, %struct.u }
+ %union.tree_ann_d = type opaque
+@mode_class = external global [35 x i8] ; <[35 x i8]*> [#uses=3]
+
+define void @fold_builtin_classify() {
+entry:
+ %tmp63 = load i32* null ; <i32> [#uses=1]
+ switch i32 %tmp63, label %bb276 [
+ i32 414, label %bb145
+ i32 417, label %bb
+ ]
+bb: ; preds = %entry
+ ret void
+bb145: ; preds = %entry
+ %tmp146 = load %struct.tree_node** null ; <%struct.tree_node*> [#uses=1]
+ %tmp148 = getelementptr %struct.tree_node* %tmp146, i32 0, i32 0, i32 0, i32 1 ; <%struct.tree_node**> [#uses=1]
+ %tmp149 = load %struct.tree_node** %tmp148 ; <%struct.tree_node*> [#uses=1]
+ %tmp150 = bitcast %struct.tree_node* %tmp149 to %struct.tree_type* ; <%struct.tree_type*> [#uses=1]
+ %tmp151 = getelementptr %struct.tree_type* %tmp150, i32 0, i32 6 ; <i16*> [#uses=1]
+ %tmp151.upgrd.1 = bitcast i16* %tmp151 to i32* ; <i32*> [#uses=1]
+ %tmp152 = load i32* %tmp151.upgrd.1 ; <i32> [#uses=1]
+ %tmp154 = lshr i32 %tmp152, 16 ; <i32> [#uses=1]
+ %tmp154.mask = and i32 %tmp154, 127 ; <i32> [#uses=1]
+ %gep.upgrd.2 = zext i32 %tmp154.mask to i64 ; <i64> [#uses=1]
+ %tmp155 = getelementptr [35 x i8]* @mode_class, i32 0, i64 %gep.upgrd.2 ; <i8*> [#uses=1]
+ %tmp156 = load i8* %tmp155 ; <i8> [#uses=1]
+ %tmp157 = icmp eq i8 %tmp156, 4 ; <i1> [#uses=1]
+ br i1 %tmp157, label %cond_next241, label %cond_true158
+cond_true158: ; preds = %bb145
+ %tmp172 = load %struct.tree_node** null ; <%struct.tree_node*> [#uses=1]
+ %tmp174 = getelementptr %struct.tree_node* %tmp172, i32 0, i32 0, i32 0, i32 1 ; <%struct.tree_node**> [#uses=1]
+ %tmp175 = load %struct.tree_node** %tmp174 ; <%struct.tree_node*> [#uses=1]
+ %tmp176 = bitcast %struct.tree_node* %tmp175 to %struct.tree_type* ; <%struct.tree_type*> [#uses=1]
+ %tmp177 = getelementptr %struct.tree_type* %tmp176, i32 0, i32 6 ; <i16*> [#uses=1]
+ %tmp177.upgrd.3 = bitcast i16* %tmp177 to i32* ; <i32*> [#uses=1]
+ %tmp178 = load i32* %tmp177.upgrd.3 ; <i32> [#uses=1]
+ %tmp180 = lshr i32 %tmp178, 16 ; <i32> [#uses=1]
+ %tmp180.mask = and i32 %tmp180, 127 ; <i32> [#uses=1]
+ %gep.upgrd.4 = zext i32 %tmp180.mask to i64 ; <i64> [#uses=1]
+ %tmp181 = getelementptr [35 x i8]* @mode_class, i32 0, i64 %gep.upgrd.4 ; <i8*> [#uses=1]
+ %tmp182 = load i8* %tmp181 ; <i8> [#uses=1]
+ %tmp183 = icmp eq i8 %tmp182, 8 ; <i1> [#uses=1]
+ br i1 %tmp183, label %cond_next241, label %cond_true184
+cond_true184: ; preds = %cond_true158
+ %tmp185 = load %struct.tree_node** null ; <%struct.tree_node*> [#uses=1]
+ %tmp187 = getelementptr %struct.tree_node* %tmp185, i32 0, i32 0, i32 0, i32 1 ; <%struct.tree_node**> [#uses=1]
+ %tmp188 = load %struct.tree_node** %tmp187 ; <%struct.tree_node*> [#uses=1]
+ %tmp189 = bitcast %struct.tree_node* %tmp188 to %struct.tree_type* ; <%struct.tree_type*> [#uses=1]
+ %tmp190 = getelementptr %struct.tree_type* %tmp189, i32 0, i32 6 ; <i16*> [#uses=1]
+ %tmp190.upgrd.5 = bitcast i16* %tmp190 to i32* ; <i32*> [#uses=1]
+ %tmp191 = load i32* %tmp190.upgrd.5 ; <i32> [#uses=1]
+ %tmp193 = lshr i32 %tmp191, 16 ; <i32> [#uses=1]
+ %tmp193.mask = and i32 %tmp193, 127 ; <i32> [#uses=1]
+ %gep.upgrd.6 = zext i32 %tmp193.mask to i64 ; <i64> [#uses=1]
+ %tmp194 = getelementptr [35 x i8]* @mode_class, i32 0, i64 %gep.upgrd.6 ; <i8*> [#uses=1]
+ %tmp195 = load i8* %tmp194 ; <i8> [#uses=1]
+ %tmp196 = icmp eq i8 %tmp195, 4 ; <i1> [#uses=1]
+ br i1 %tmp196, label %cond_next241, label %cond_true197
+cond_true197: ; preds = %cond_true184
+ ret void
+cond_next241: ; preds = %cond_true184, %cond_true158, %bb145
+ %tmp245 = load i32* null ; <i32> [#uses=0]
+ ret void
+bb276: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-10-19-UncondDiv.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-10-19-UncondDiv.ll
new file mode 100644
index 0000000..63d45b3
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-10-19-UncondDiv.ll
@@ -0,0 +1,28 @@
+; PR957
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep select
+
+@G = extern_weak global i32
+
+define i32 @test(i32 %tmp) {
+cond_false179:
+ %tmp181 = icmp eq i32 %tmp, 0 ; <i1> [#uses=1]
+ br i1 %tmp181, label %cond_true182, label %cond_next185
+cond_true182: ; preds = %cond_false179
+ br label %cond_next185
+cond_next185: ; preds = %cond_true182, %cond_false179
+ %d0.3 = phi i32 [ udiv (i32 1, i32 ptrtoint (i32* @G to i32)), %cond_true182 ], [ %tmp, %cond_false179 ] ; <i32> [#uses=1]
+ ret i32 %d0.3
+}
+
+define i32 @test2(i32 %tmp) {
+cond_false179:
+ %tmp181 = icmp eq i32 %tmp, 0 ; <i1> [#uses=1]
+ br i1 %tmp181, label %cond_true182, label %cond_next185
+cond_true182: ; preds = %cond_false179
+ br label %cond_next185
+cond_next185: ; preds = %cond_true182, %cond_false179
+ %d0.3 = phi i32 [ udiv (i32 1, i32 ptrtoint (i32* @G to i32)), %cond_true182 ], [ %tmp, %cond_false179 ] ; <i32> [#uses=1]
+ call i32 @test( i32 4 ) ; <i32>:0 [#uses=0]
+ ret i32 %d0.3
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-10-29-InvokeCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-10-29-InvokeCrash.ll
new file mode 100644
index 0000000..72a15fa
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-10-29-InvokeCrash.ll
@@ -0,0 +1,567 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; END.
+ %struct..4._102 = type { %struct.QVectorData* }
+ %struct..5._125 = type { %struct.QMapData* }
+ %struct.QAbstractTextDocumentLayout = type { %struct.QObject }
+ %struct.QBasicAtomic = type { i32 }
+ %struct.QFont = type { %struct.QFontPrivate*, i32 }
+ %struct.QFontMetrics = type { %struct.QFontPrivate* }
+ %struct.QFontPrivate = type opaque
+ %"struct.QFragmentMap<QTextBlockData>" = type { %struct.QFragmentMapData }
+ %struct.QFragmentMapData = type { %"struct.QFragmentMapData::._154", i32 }
+ %"struct.QFragmentMapData::._154" = type { %"struct.QFragmentMapData::Header"* }
+ %"struct.QFragmentMapData::Header" = type { i32, i32, i32, i32, i32, i32, i32, i32 }
+ %"struct.QHash<uint,QHashDummyValue>" = type { %"struct.QHash<uint,QHashDummyValue>::._152" }
+ %"struct.QHash<uint,QHashDummyValue>::._152" = type { %struct.QHashData* }
+ %struct.QHashData = type { %"struct.QHashData::Node"*, %"struct.QHashData::Node"**, %struct.QBasicAtomic, i32, i32, i16, i16, i32, i8 }
+ %"struct.QHashData::Node" = type { %"struct.QHashData::Node"*, i32 }
+ %"struct.QList<QObject*>::._92" = type { %struct.QListData }
+ %"struct.QList<QPointer<QObject> >" = type { %"struct.QList<QObject*>::._92" }
+ %struct.QListData = type { %"struct.QListData::Data"* }
+ %"struct.QListData::Data" = type { %struct.QBasicAtomic, i32, i32, i32, i8, [1 x i8*] }
+ %"struct.QMap<QUrl,QVariant>" = type { %struct..5._125 }
+ %struct.QMapData = type { %"struct.QMapData::Node"*, [12 x %"struct.QMapData::Node"*], %struct.QBasicAtomic, i32, i32, i32, i8 }
+ %"struct.QMapData::Node" = type { %"struct.QMapData::Node"*, [1 x %"struct.QMapData::Node"*] }
+ %struct.QObject = type { i32 (...)**, %struct.QObjectData* }
+ %struct.QObjectData = type { i32 (...)**, %struct.QObject*, %struct.QObject*, %"struct.QList<QPointer<QObject> >", i8, [3 x i8], i32, i32 }
+ %struct.QObjectPrivate = type { %struct.QObjectData, i32, %struct.QObject*, %"struct.QList<QPointer<QObject> >", %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %struct.QString }
+ %struct.QPaintDevice = type { i32 (...)**, i16 }
+ %struct.QPainter = type { %struct.QPainterPrivate* }
+ %struct.QPainterPrivate = type opaque
+ %struct.QPointF = type { double, double }
+ %struct.QPrinter = type { %struct.QPaintDevice, %struct.QPrinterPrivate* }
+ %struct.QPrinterPrivate = type opaque
+ %struct.QRectF = type { double, double, double, double }
+ %"struct.QSet<uint>" = type { %"struct.QHash<uint,QHashDummyValue>" }
+ %"struct.QSharedDataPointer<QTextFormatPrivate>" = type { %struct.QTextFormatPrivate* }
+ %struct.QString = type { %"struct.QString::Data"* }
+ %"struct.QString::Data" = type { %struct.QBasicAtomic, i32, i32, i16*, i8, i8, [1 x i16] }
+ %struct.QTextBlockFormat = type { %struct.QTextFormat }
+ %struct.QTextBlockGroup = type { %struct.QAbstractTextDocumentLayout }
+ %struct.QTextDocumentConfig = type { %struct.QString }
+ %struct.QTextDocumentPrivate = type { %struct.QObjectPrivate, %struct.QString, %"struct.QVector<QAbstractTextDocumentLayout::Selection>", i1, i32, i32, i1, i32, i32, i32, i32, i1, %struct.QTextFormatCollection, %struct.QTextBlockGroup*, %struct.QAbstractTextDocumentLayout*, %"struct.QFragmentMap<QTextBlockData>", %"struct.QFragmentMap<QTextBlockData>", i32, %"struct.QList<QPointer<QObject> >", %"struct.QList<QPointer<QObject> >", %"struct.QMap<QUrl,QVariant>", %"struct.QMap<QUrl,QVariant>", %"struct.QMap<QUrl,QVariant>", %struct.QTextDocumentConfig, i1, i1, %struct.QPointF }
+ %struct.QTextFormat = type { %"struct.QSharedDataPointer<QTextFormatPrivate>", i32 }
+ %struct.QTextFormatCollection = type { %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %"struct.QSet<uint>", %struct.QFont }
+ %struct.QTextFormatPrivate = type opaque
+ %"struct.QVector<QAbstractTextDocumentLayout::Selection>" = type { %struct..4._102 }
+ %struct.QVectorData = type { %struct.QBasicAtomic, i32, i32, i8 }
+
+define void @_ZNK13QTextDocument5printEP8QPrinter(%struct.QAbstractTextDocumentLayout* %this, %struct.QPrinter* %printer) {
+entry:
+ %tmp = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=2]
+ %tmp.upgrd.1 = alloca %struct.QRectF, align 16 ; <%struct.QRectF*> [#uses=5]
+ %tmp2 = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=3]
+ %tmp.upgrd.2 = alloca %struct.QFontMetrics, align 16 ; <%struct.QFontMetrics*> [#uses=4]
+ %tmp.upgrd.3 = alloca %struct.QFont, align 16 ; <%struct.QFont*> [#uses=4]
+ %tmp3 = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=2]
+ %p = alloca %struct.QPainter, align 16 ; <%struct.QPainter*> [#uses=14]
+ %body = alloca %struct.QRectF, align 16 ; <%struct.QRectF*> [#uses=9]
+ %pageNumberPos = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=4]
+ %scaledPageSize = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=6]
+ %printerPageSize = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=3]
+ %fmt = alloca %struct.QTextBlockFormat, align 16 ; <%struct.QTextBlockFormat*> [#uses=5]
+ %font = alloca %struct.QFont, align 16 ; <%struct.QFont*> [#uses=5]
+ %tmp.upgrd.4 = call %struct.QTextDocumentPrivate* @_ZNK13QTextDocument6d_funcEv( %struct.QAbstractTextDocumentLayout* %this ) ; <%struct.QTextDocumentPrivate*> [#uses=5]
+ %tmp.upgrd.5 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ call void @_ZN8QPainterC1EP12QPaintDevice( %struct.QPainter* %p, %struct.QPaintDevice* %tmp.upgrd.5 )
+ %tmp.upgrd.6 = invoke i1 @_ZNK8QPainter8isActiveEv( %struct.QPainter* %p )
+ to label %invcont unwind label %cleanup329 ; <i1> [#uses=1]
+invcont: ; preds = %entry
+ br i1 %tmp.upgrd.6, label %cond_next, label %cleanup328
+cond_next: ; preds = %invcont
+ %tmp8 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %this )
+ to label %invcont7 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=0]
+invcont7: ; preds = %cond_next
+ %tmp10 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ call void @_ZN7QPointFC1Edd( %struct.QPointF* %tmp, double 0.000000e+00, double 0.000000e+00 )
+ call void @_ZN6QRectFC1ERK7QPointFRK6QSizeF( %struct.QRectF* %body, %struct.QPointF* %tmp, %struct.QPointF* %tmp10 )
+ call void @_ZN7QPointFC1Ev( %struct.QPointF* %pageNumberPos )
+ %tmp12 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ %tmp13 = call i1 @_ZNK6QSizeF7isValidEv( %struct.QPointF* %tmp12 ) ; <i1> [#uses=1]
+ br i1 %tmp13, label %cond_next15, label %bb
+cond_next15: ; preds = %invcont7
+ %tmp17 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ %tmp.upgrd.7 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %tmp17 ) ; <double> [#uses=1]
+ %tmp18 = fcmp oeq double %tmp.upgrd.7, 0x41DFFFFFFFC00000 ; <i1> [#uses=1]
+ br i1 %tmp18, label %bb, label %cond_next20
+cond_next20: ; preds = %cond_next15
+ br label %bb21
+bb: ; preds = %cond_next15, %invcont7
+ br label %bb21
+bb21: ; preds = %bb, %cond_next20
+ %iftmp.406.0 = phi i1 [ false, %bb ], [ true, %cond_next20 ] ; <i1> [#uses=1]
+ br i1 %iftmp.406.0, label %cond_true24, label %cond_false
+cond_true24: ; preds = %bb21
+ %tmp.upgrd.8 = invoke i32 @_Z13qt_defaultDpiv( )
+ to label %invcont25 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont25: ; preds = %cond_true24
+ %tmp26 = sitofp i32 %tmp.upgrd.8 to double ; <double> [#uses=2]
+ %tmp30 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %this )
+ to label %invcont29 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=1]
+invcont29: ; preds = %invcont25
+ %tmp32 = invoke %struct.QPaintDevice* @_ZNK27QAbstractTextDocumentLayout11paintDeviceEv( %struct.QAbstractTextDocumentLayout* %tmp30 )
+ to label %invcont31 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=3]
+invcont31: ; preds = %invcont29
+ %tmp34 = icmp eq %struct.QPaintDevice* %tmp32, null ; <i1> [#uses=1]
+ br i1 %tmp34, label %cond_next42, label %cond_true35
+cond_true35: ; preds = %invcont31
+ %tmp38 = invoke i32 @_ZNK12QPaintDevice11logicalDpiXEv( %struct.QPaintDevice* %tmp32 )
+ to label %invcont37 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont37: ; preds = %cond_true35
+ %tmp38.upgrd.9 = sitofp i32 %tmp38 to double ; <double> [#uses=1]
+ %tmp41 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp32 )
+ to label %invcont40 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont40: ; preds = %invcont37
+ %tmp41.upgrd.10 = sitofp i32 %tmp41 to double ; <double> [#uses=1]
+ br label %cond_next42
+cond_next42: ; preds = %invcont40, %invcont31
+ %sourceDpiY.2 = phi double [ %tmp41.upgrd.10, %invcont40 ], [ %tmp26, %invcont31 ] ; <double> [#uses=1]
+ %sourceDpiX.2 = phi double [ %tmp38.upgrd.9, %invcont40 ], [ %tmp26, %invcont31 ] ; <double> [#uses=1]
+ %tmp44 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp46 = invoke i32 @_ZNK12QPaintDevice11logicalDpiXEv( %struct.QPaintDevice* %tmp44 )
+ to label %invcont45 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont45: ; preds = %cond_next42
+ %tmp46.upgrd.11 = sitofp i32 %tmp46 to double ; <double> [#uses=1]
+ %tmp48 = fdiv double %tmp46.upgrd.11, %sourceDpiX.2 ; <double> [#uses=2]
+ %tmp50 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp52 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp50 )
+ to label %invcont51 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont51: ; preds = %invcont45
+ %tmp52.upgrd.12 = sitofp i32 %tmp52 to double ; <double> [#uses=1]
+ %tmp54 = fdiv double %tmp52.upgrd.12, %sourceDpiY.2 ; <double> [#uses=2]
+ invoke void @_ZN8QPainter5scaleEdd( %struct.QPainter* %p, double %tmp48, double %tmp54 )
+ to label %invcont57 unwind label %cleanup329
+invcont57: ; preds = %invcont51
+ %tmp.upgrd.13 = getelementptr %struct.QPointF* %scaledPageSize, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp60 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26, i32 0 ; <double*> [#uses=1]
+ %tmp61 = load double* %tmp60 ; <double> [#uses=1]
+ store double %tmp61, double* %tmp.upgrd.13
+ %tmp62 = getelementptr %struct.QPointF* %scaledPageSize, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp63 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26, i32 1 ; <double*> [#uses=1]
+ %tmp64 = load double* %tmp63 ; <double> [#uses=1]
+ store double %tmp64, double* %tmp62
+ %tmp65 = call double* @_ZN6QSizeF6rwidthEv( %struct.QPointF* %scaledPageSize ) ; <double*> [#uses=2]
+ %tmp67 = load double* %tmp65 ; <double> [#uses=1]
+ %tmp69 = fmul double %tmp67, %tmp48 ; <double> [#uses=1]
+ store double %tmp69, double* %tmp65
+ %tmp71 = call double* @_ZN6QSizeF7rheightEv( %struct.QPointF* %scaledPageSize ) ; <double*> [#uses=2]
+ %tmp73 = load double* %tmp71 ; <double> [#uses=1]
+ %tmp75 = fmul double %tmp73, %tmp54 ; <double> [#uses=1]
+ store double %tmp75, double* %tmp71
+ %tmp78 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp80 = invoke i32 @_ZNK12QPaintDevice6heightEv( %struct.QPaintDevice* %tmp78 )
+ to label %invcont79 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont79: ; preds = %invcont57
+ %tmp82 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp84 = invoke i32 @_ZNK12QPaintDevice5widthEv( %struct.QPaintDevice* %tmp82 )
+ to label %invcont83 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont83: ; preds = %invcont79
+ %tmp80.upgrd.14 = sitofp i32 %tmp80 to double ; <double> [#uses=1]
+ %tmp84.upgrd.15 = sitofp i32 %tmp84 to double ; <double> [#uses=1]
+ call void @_ZN6QSizeFC1Edd( %struct.QPointF* %printerPageSize, double %tmp84.upgrd.15, double %tmp80.upgrd.14 )
+ %tmp85 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %printerPageSize ) ; <double> [#uses=1]
+ %tmp86 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %scaledPageSize ) ; <double> [#uses=1]
+ %tmp87 = fdiv double %tmp85, %tmp86 ; <double> [#uses=1]
+ %tmp88 = call double @_ZNK6QSizeF5widthEv( %struct.QPointF* %printerPageSize ) ; <double> [#uses=1]
+ %tmp89 = call double @_ZNK6QSizeF5widthEv( %struct.QPointF* %scaledPageSize ) ; <double> [#uses=1]
+ %tmp90 = fdiv double %tmp88, %tmp89 ; <double> [#uses=1]
+ invoke void @_ZN8QPainter5scaleEdd( %struct.QPainter* %p, double %tmp90, double %tmp87 )
+ to label %cond_next194 unwind label %cleanup329
+cond_false: ; preds = %bb21
+ %tmp.upgrd.16 = getelementptr %struct.QAbstractTextDocumentLayout* %this, i32 0, i32 0 ; <%struct.QObject*> [#uses=1]
+ %tmp95 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument5cloneEP7QObject( %struct.QAbstractTextDocumentLayout* %this, %struct.QObject* %tmp.upgrd.16 )
+ to label %invcont94 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=9]
+invcont94: ; preds = %cond_false
+ %tmp99 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont98 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=1]
+invcont98: ; preds = %invcont94
+ %tmp101 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont100 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=1]
+invcont100: ; preds = %invcont98
+ invoke void @_ZN27QAbstractTextDocumentLayout14setPaintDeviceEP12QPaintDevice( %struct.QAbstractTextDocumentLayout* %tmp99, %struct.QPaintDevice* %tmp101 )
+ to label %invcont103 unwind label %cleanup329
+invcont103: ; preds = %invcont100
+ %tmp105 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont104 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=1]
+invcont104: ; preds = %invcont103
+ %tmp107 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp105 )
+ to label %invcont106 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont106: ; preds = %invcont104
+ %tmp108 = sitofp i32 %tmp107 to double ; <double> [#uses=1]
+ %tmp109 = fmul double %tmp108, 0x3FE93264C993264C ; <double> [#uses=1]
+ %tmp109.upgrd.17 = fptosi double %tmp109 to i32 ; <i32> [#uses=3]
+ %tmp.upgrd.18 = call %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv( %struct.QAbstractTextDocumentLayout* %tmp95 ) ; <%struct.QTextBlockGroup*> [#uses=1]
+ invoke void @_ZNK10QTextFrame11frameFormatEv( %struct.QTextBlockFormat* sret %fmt, %struct.QTextBlockGroup* %tmp.upgrd.18 )
+ to label %invcont111 unwind label %cleanup329
+invcont111: ; preds = %invcont106
+ %tmp112 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ invoke void @_ZN16QTextFrameFormat9setMarginEd( %struct.QTextBlockFormat* %fmt, double %tmp112 )
+ to label %invcont114 unwind label %cleanup192
+invcont114: ; preds = %invcont111
+ %tmp116 = call %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv( %struct.QAbstractTextDocumentLayout* %tmp95 ) ; <%struct.QTextBlockGroup*> [#uses=1]
+ invoke void @_ZN10QTextFrame14setFrameFormatERK16QTextFrameFormat( %struct.QTextBlockGroup* %tmp116, %struct.QTextBlockFormat* %fmt )
+ to label %invcont117 unwind label %cleanup192
+invcont117: ; preds = %invcont114
+ %tmp119 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont118 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont118: ; preds = %invcont117
+ %tmp121 = invoke i32 @_ZNK12QPaintDevice6heightEv( %struct.QPaintDevice* %tmp119 )
+ to label %invcont120 unwind label %cleanup192 ; <i32> [#uses=1]
+invcont120: ; preds = %invcont118
+ %tmp121.upgrd.19 = sitofp i32 %tmp121 to double ; <double> [#uses=1]
+ %tmp123 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont122 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont122: ; preds = %invcont120
+ %tmp125 = invoke i32 @_ZNK12QPaintDevice5widthEv( %struct.QPaintDevice* %tmp123 )
+ to label %invcont124 unwind label %cleanup192 ; <i32> [#uses=1]
+invcont124: ; preds = %invcont122
+ %tmp125.upgrd.20 = sitofp i32 %tmp125 to double ; <double> [#uses=1]
+ call void @_ZN6QRectFC1Edddd( %struct.QRectF* %tmp.upgrd.1, double 0.000000e+00, double 0.000000e+00, double %tmp125.upgrd.20, double %tmp121.upgrd.19 )
+ %tmp126 = getelementptr %struct.QRectF* %body, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp127 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp128 = load double* %tmp127 ; <double> [#uses=1]
+ store double %tmp128, double* %tmp126
+ %tmp129 = getelementptr %struct.QRectF* %body, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp130 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp131 = load double* %tmp130 ; <double> [#uses=1]
+ store double %tmp131, double* %tmp129
+ %tmp132 = getelementptr %struct.QRectF* %body, i32 0, i32 2 ; <double*> [#uses=1]
+ %tmp133 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 2 ; <double*> [#uses=1]
+ %tmp134 = load double* %tmp133 ; <double> [#uses=1]
+ store double %tmp134, double* %tmp132
+ %tmp135 = getelementptr %struct.QRectF* %body, i32 0, i32 3 ; <double*> [#uses=1]
+ %tmp136 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 3 ; <double*> [#uses=1]
+ %tmp137 = load double* %tmp136 ; <double> [#uses=1]
+ store double %tmp137, double* %tmp135
+ %tmp138 = call double @_ZNK6QRectF6heightEv( %struct.QRectF* %body ) ; <double> [#uses=1]
+ %tmp139 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ %tmp140 = fsub double %tmp138, %tmp139 ; <double> [#uses=1]
+ %tmp142 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont141 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont141: ; preds = %invcont124
+ invoke void @_ZNK13QTextDocument11defaultFontEv( %struct.QFont* sret %tmp.upgrd.3, %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont144 unwind label %cleanup192
+invcont144: ; preds = %invcont141
+ invoke void @_ZN12QFontMetricsC1ERK5QFontP12QPaintDevice( %struct.QFontMetrics* %tmp.upgrd.2, %struct.QFont* %tmp.upgrd.3, %struct.QPaintDevice* %tmp142 )
+ to label %invcont146 unwind label %cleanup173
+invcont146: ; preds = %invcont144
+ %tmp149 = invoke i32 @_ZNK12QFontMetrics6ascentEv( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %invcont148 unwind label %cleanup168 ; <i32> [#uses=1]
+invcont148: ; preds = %invcont146
+ %tmp149.upgrd.21 = sitofp i32 %tmp149 to double ; <double> [#uses=1]
+ %tmp150 = fadd double %tmp140, %tmp149.upgrd.21 ; <double> [#uses=1]
+ %tmp152 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont151 unwind label %cleanup168 ; <%struct.QPaintDevice*> [#uses=1]
+invcont151: ; preds = %invcont148
+ %tmp154 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp152 )
+ to label %invcont153 unwind label %cleanup168 ; <i32> [#uses=1]
+invcont153: ; preds = %invcont151
+ %tmp155 = mul i32 %tmp154, 5 ; <i32> [#uses=1]
+ %tmp156 = sdiv i32 %tmp155, 72 ; <i32> [#uses=1]
+ %tmp156.upgrd.22 = sitofp i32 %tmp156 to double ; <double> [#uses=1]
+ %tmp157 = fadd double %tmp150, %tmp156.upgrd.22 ; <double> [#uses=1]
+ %tmp158 = call double @_ZNK6QRectF5widthEv( %struct.QRectF* %body ) ; <double> [#uses=1]
+ %tmp159 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ %tmp160 = fsub double %tmp158, %tmp159 ; <double> [#uses=1]
+ call void @_ZN7QPointFC1Edd( %struct.QPointF* %tmp2, double %tmp160, double %tmp157 )
+ %tmp161 = getelementptr %struct.QPointF* %pageNumberPos, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp162 = getelementptr %struct.QPointF* %tmp2, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp163 = load double* %tmp162 ; <double> [#uses=1]
+ store double %tmp163, double* %tmp161
+ %tmp164 = getelementptr %struct.QPointF* %pageNumberPos, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp165 = getelementptr %struct.QPointF* %tmp2, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp166 = load double* %tmp165 ; <double> [#uses=1]
+ store double %tmp166, double* %tmp164
+ invoke void @_ZN12QFontMetricsD1Ev( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %cleanup171 unwind label %cleanup173
+cleanup168: ; preds = %invcont151, %invcont148, %invcont146
+ %val168 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN12QFontMetricsD1Ev( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %cleanup173 unwind label %cleanup173
+cleanup171: ; preds = %invcont153
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %tmp.upgrd.3 )
+ to label %finally170 unwind label %cleanup192
+cleanup173: ; preds = %cleanup168, %cleanup168, %invcont153, %invcont144
+ %val173 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %tmp.upgrd.3 )
+ to label %cleanup192 unwind label %cleanup192
+finally170: ; preds = %cleanup171
+ invoke void @_ZNK13QTextDocument11defaultFontEv( %struct.QFont* sret %font, %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont177 unwind label %cleanup192
+invcont177: ; preds = %finally170
+ invoke void @_ZN5QFont12setPointSizeEi( %struct.QFont* %font, i32 10 )
+ to label %invcont179 unwind label %cleanup187
+invcont179: ; preds = %invcont177
+ invoke void @_ZN13QTextDocument14setDefaultFontERK5QFont( %struct.QAbstractTextDocumentLayout* %tmp95, %struct.QFont* %font )
+ to label %invcont181 unwind label %cleanup187
+invcont181: ; preds = %invcont179
+ call void @_ZNK6QRectF4sizeEv( %struct.QPointF* sret %tmp3, %struct.QRectF* %body )
+ invoke void @_ZN13QTextDocument11setPageSizeERK6QSizeF( %struct.QAbstractTextDocumentLayout* %tmp95, %struct.QPointF* %tmp3 )
+ to label %cleanup185 unwind label %cleanup187
+cleanup185: ; preds = %invcont181
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %font )
+ to label %cleanup190 unwind label %cleanup192
+cleanup187: ; preds = %invcont181, %invcont179, %invcont177
+ %val187 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %font )
+ to label %cleanup192 unwind label %cleanup192
+cleanup190: ; preds = %cleanup185
+ invoke void @_ZN16QTextFrameFormatD1Ev( %struct.QTextBlockFormat* %fmt )
+ to label %cond_next194 unwind label %cleanup329
+cleanup192: ; preds = %cleanup187, %cleanup187, %cleanup185, %finally170, %cleanup173, %cleanup173, %cleanup171, %invcont141, %invcont124, %invcont122, %invcont120, %invcont118, %invcont117, %invcont114, %invcont111
+ %val192 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN16QTextFrameFormatD1Ev( %struct.QTextBlockFormat* %fmt )
+ to label %cleanup329 unwind label %cleanup329
+cond_next194: ; preds = %cleanup190, %invcont83
+ %clonedDoc.1 = phi %struct.QAbstractTextDocumentLayout* [ null, %invcont83 ], [ %tmp95, %cleanup190 ] ; <%struct.QAbstractTextDocumentLayout*> [#uses=3]
+ %doc.1 = phi %struct.QAbstractTextDocumentLayout* [ %this, %invcont83 ], [ %tmp95, %cleanup190 ] ; <%struct.QAbstractTextDocumentLayout*> [#uses=2]
+ %tmp197 = invoke i1 @_ZNK8QPrinter13collateCopiesEv( %struct.QPrinter* %printer )
+ to label %invcont196 unwind label %cleanup329 ; <i1> [#uses=1]
+invcont196: ; preds = %cond_next194
+ br i1 %tmp197, label %cond_true200, label %cond_false204
+cond_true200: ; preds = %invcont196
+ %tmp203 = invoke i32 @_ZNK8QPrinter9numCopiesEv( %struct.QPrinter* %printer )
+ to label %invcont202 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont202: ; preds = %cond_true200
+ br label %cond_next208
+cond_false204: ; preds = %invcont196
+ %tmp207 = invoke i32 @_ZNK8QPrinter9numCopiesEv( %struct.QPrinter* %printer )
+ to label %invcont206 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont206: ; preds = %cond_false204
+ br label %cond_next208
+cond_next208: ; preds = %invcont206, %invcont202
+ %pageCopies.0 = phi i32 [ %tmp203, %invcont202 ], [ 1, %invcont206 ] ; <i32> [#uses=2]
+ %docCopies.0 = phi i32 [ 1, %invcont202 ], [ %tmp207, %invcont206 ] ; <i32> [#uses=2]
+ %tmp211 = invoke i32 @_ZNK8QPrinter8fromPageEv( %struct.QPrinter* %printer )
+ to label %invcont210 unwind label %cleanup329 ; <i32> [#uses=3]
+invcont210: ; preds = %cond_next208
+ %tmp214 = invoke i32 @_ZNK8QPrinter6toPageEv( %struct.QPrinter* %printer )
+ to label %invcont213 unwind label %cleanup329 ; <i32> [#uses=3]
+invcont213: ; preds = %invcont210
+ %tmp216 = icmp eq i32 %tmp211, 0 ; <i1> [#uses=1]
+ br i1 %tmp216, label %cond_true217, label %cond_next225
+cond_true217: ; preds = %invcont213
+ %tmp219 = icmp eq i32 %tmp214, 0 ; <i1> [#uses=1]
+ br i1 %tmp219, label %cond_true220, label %cond_next225
+cond_true220: ; preds = %cond_true217
+ %tmp223 = invoke i32 @_ZNK13QTextDocument9pageCountEv( %struct.QAbstractTextDocumentLayout* %doc.1 )
+ to label %invcont222 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont222: ; preds = %cond_true220
+ br label %cond_next225
+cond_next225: ; preds = %invcont222, %cond_true217, %invcont213
+ %toPage.1 = phi i32 [ %tmp223, %invcont222 ], [ %tmp214, %cond_true217 ], [ %tmp214, %invcont213 ] ; <i32> [#uses=2]
+ %fromPage.1 = phi i32 [ 1, %invcont222 ], [ %tmp211, %cond_true217 ], [ %tmp211, %invcont213 ] ; <i32> [#uses=2]
+ %tmp.page = invoke i32 @_ZNK8QPrinter9pageOrderEv( %struct.QPrinter* %printer )
+ to label %invcont227 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont227: ; preds = %cond_next225
+ %tmp228 = icmp eq i32 %tmp.page, 1 ; <i1> [#uses=1]
+ br i1 %tmp228, label %cond_true230, label %cond_next234
+cond_true230: ; preds = %invcont227
+ br label %cond_next234
+cond_next234: ; preds = %cond_true230, %invcont227
+ %ascending.1 = phi i1 [ false, %cond_true230 ], [ true, %invcont227 ] ; <i1> [#uses=1]
+ %toPage.2 = phi i32 [ %fromPage.1, %cond_true230 ], [ %toPage.1, %invcont227 ] ; <i32> [#uses=1]
+ %fromPage.2 = phi i32 [ %toPage.1, %cond_true230 ], [ %fromPage.1, %invcont227 ] ; <i32> [#uses=1]
+ br label %bb309
+bb237: ; preds = %cond_true313, %cond_next293
+ %iftmp.410.4 = phi i1 [ %iftmp.410.5, %cond_true313 ], [ %iftmp.410.1, %cond_next293 ] ; <i1> [#uses=1]
+ %page.4 = phi i32 [ %fromPage.2, %cond_true313 ], [ %page.3, %cond_next293 ] ; <i32> [#uses=4]
+ br label %bb273
+invcont240: ; preds = %cond_true277
+ %tmp242 = icmp eq i32 %tmp241, 2 ; <i1> [#uses=1]
+ br i1 %tmp242, label %bb252, label %cond_next244
+cond_next244: ; preds = %invcont240
+ %tmp247 = invoke i32 @_ZNK8QPrinter12printerStateEv( %struct.QPrinter* %printer )
+ to label %invcont246 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont246: ; preds = %cond_next244
+ %tmp248 = icmp eq i32 %tmp247, 3 ; <i1> [#uses=1]
+ br i1 %tmp248, label %bb252, label %bb253
+bb252: ; preds = %invcont246, %invcont240
+ br label %bb254
+bb253: ; preds = %invcont246
+ br label %bb254
+bb254: ; preds = %bb253, %bb252
+ %iftmp.410.0 = phi i1 [ true, %bb252 ], [ false, %bb253 ] ; <i1> [#uses=2]
+ br i1 %iftmp.410.0, label %UserCanceled, label %cond_next258
+cond_next258: ; preds = %bb254
+ invoke fastcc void @_Z9printPageiP8QPainterPK13QTextDocumentRK6QRectFRK7QPointF( i32 %page.4, %struct.QPainter* %p, %struct.QAbstractTextDocumentLayout* %doc.1, %struct.QRectF* %body, %struct.QPointF* %pageNumberPos )
+ to label %invcont261 unwind label %cleanup329
+invcont261: ; preds = %cond_next258
+ %tmp263 = add i32 %pageCopies.0, -1 ; <i32> [#uses=1]
+ %tmp265 = icmp sgt i32 %tmp263, %j.4 ; <i1> [#uses=1]
+ br i1 %tmp265, label %cond_true266, label %cond_next270
+cond_true266: ; preds = %invcont261
+ %tmp269 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %cond_next270 unwind label %cleanup329 ; <i1> [#uses=0]
+cond_next270: ; preds = %cond_true266, %invcont261
+ %tmp272 = add i32 %j.4, 1 ; <i32> [#uses=1]
+ br label %bb273
+bb273: ; preds = %cond_next270, %bb237
+ %iftmp.410.1 = phi i1 [ %iftmp.410.4, %bb237 ], [ %iftmp.410.0, %cond_next270 ] ; <i1> [#uses=2]
+ %j.4 = phi i32 [ 0, %bb237 ], [ %tmp272, %cond_next270 ] ; <i32> [#uses=3]
+ %tmp276 = icmp slt i32 %j.4, %pageCopies.0 ; <i1> [#uses=1]
+ br i1 %tmp276, label %cond_true277, label %bb280
+cond_true277: ; preds = %bb273
+ %tmp241 = invoke i32 @_ZNK8QPrinter12printerStateEv( %struct.QPrinter* %printer )
+ to label %invcont240 unwind label %cleanup329 ; <i32> [#uses=1]
+bb280: ; preds = %bb273
+ %tmp283 = icmp eq i32 %page.4, %toPage.2 ; <i1> [#uses=1]
+ br i1 %tmp283, label %bb297, label %cond_next285
+cond_next285: ; preds = %bb280
+ br i1 %ascending.1, label %cond_true287, label %cond_false290
+cond_true287: ; preds = %cond_next285
+ %tmp289 = add i32 %page.4, 1 ; <i32> [#uses=1]
+ br label %cond_next293
+cond_false290: ; preds = %cond_next285
+ %tmp292 = add i32 %page.4, -1 ; <i32> [#uses=1]
+ br label %cond_next293
+cond_next293: ; preds = %cond_false290, %cond_true287
+ %page.3 = phi i32 [ %tmp289, %cond_true287 ], [ %tmp292, %cond_false290 ] ; <i32> [#uses=1]
+ %tmp296 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %bb237 unwind label %cleanup329 ; <i1> [#uses=0]
+bb297: ; preds = %bb280
+ %tmp299 = add i32 %docCopies.0, -1 ; <i32> [#uses=1]
+ %tmp301 = icmp sgt i32 %tmp299, %i.1 ; <i1> [#uses=1]
+ br i1 %tmp301, label %cond_true302, label %cond_next306
+cond_true302: ; preds = %bb297
+ %tmp305 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %cond_next306 unwind label %cleanup329 ; <i1> [#uses=0]
+cond_next306: ; preds = %cond_true302, %bb297
+ %tmp308 = add i32 %i.1, 1 ; <i32> [#uses=1]
+ br label %bb309
+bb309: ; preds = %cond_next306, %cond_next234
+ %iftmp.410.5 = phi i1 [ undef, %cond_next234 ], [ %iftmp.410.1, %cond_next306 ] ; <i1> [#uses=1]
+ %i.1 = phi i32 [ 0, %cond_next234 ], [ %tmp308, %cond_next306 ] ; <i32> [#uses=3]
+ %tmp312 = icmp slt i32 %i.1, %docCopies.0 ; <i1> [#uses=1]
+ br i1 %tmp312, label %cond_true313, label %UserCanceled
+cond_true313: ; preds = %bb309
+ br label %bb237
+UserCanceled: ; preds = %bb309, %bb254
+ %tmp318 = icmp eq %struct.QAbstractTextDocumentLayout* %clonedDoc.1, null ; <i1> [#uses=1]
+ br i1 %tmp318, label %cleanup327, label %cond_true319
+cond_true319: ; preds = %UserCanceled
+ %tmp.upgrd.23 = getelementptr %struct.QAbstractTextDocumentLayout* %clonedDoc.1, i32 0, i32 0, i32 0 ; <i32 (...)***> [#uses=1]
+ %tmp.upgrd.24 = load i32 (...)*** %tmp.upgrd.23 ; <i32 (...)**> [#uses=1]
+ %tmp322 = getelementptr i32 (...)** %tmp.upgrd.24, i32 4 ; <i32 (...)**> [#uses=1]
+ %tmp.upgrd.25 = load i32 (...)** %tmp322 ; <i32 (...)*> [#uses=1]
+ %tmp.upgrd.26 = bitcast i32 (...)* %tmp.upgrd.25 to void (%struct.QAbstractTextDocumentLayout*)* ; <void (%struct.QAbstractTextDocumentLayout*)*> [#uses=1]
+ invoke void %tmp.upgrd.26( %struct.QAbstractTextDocumentLayout* %clonedDoc.1 )
+ to label %cleanup327 unwind label %cleanup329
+cleanup327: ; preds = %cond_true319, %UserCanceled
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ ret void
+cleanup328: ; preds = %invcont
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ ret void
+cleanup329: ; preds = %cond_true319, %cond_true302, %cond_next293, %cond_true277, %cond_true266, %cond_next258, %cond_next244, %cond_next225, %cond_true220, %invcont210, %cond_next208, %cond_false204, %cond_true200, %cond_next194, %cleanup192, %cleanup192, %cleanup190, %invcont106, %invcont104, %invcont103, %invcont100, %invcont98, %invcont94, %cond_false, %invcont83, %invcont79, %invcont57, %invcont51, %invcont45, %cond_next42, %invcont37, %cond_true35, %invcont29, %invcont25, %cond_true24, %cond_next, %entry
+ %val = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ resume { i8*, i32 } %val
+}
+
+declare void @_ZN6QSizeFC1Edd(%struct.QPointF*, double, double)
+
+declare i1 @_ZNK6QSizeF7isValidEv(%struct.QPointF*)
+
+declare double @_ZNK6QSizeF5widthEv(%struct.QPointF*)
+
+declare double @_ZNK6QSizeF6heightEv(%struct.QPointF*)
+
+declare double* @_ZN6QSizeF6rwidthEv(%struct.QPointF*)
+
+declare double* @_ZN6QSizeF7rheightEv(%struct.QPointF*)
+
+declare %struct.QTextDocumentPrivate* @_ZNK13QTextDocument6d_funcEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN7QPointFC1Ev(%struct.QPointF*)
+
+declare void @_ZN7QPointFC1Edd(%struct.QPointF*, double, double)
+
+declare void @_ZN16QTextFrameFormat9setMarginEd(%struct.QTextBlockFormat*, double)
+
+declare void @_ZN6QRectFC1Edddd(%struct.QRectF*, double, double, double, double)
+
+declare void @_ZN6QRectFC1ERK7QPointFRK6QSizeF(%struct.QRectF*, %struct.QPointF*, %struct.QPointF*)
+
+declare double @_ZNK6QRectF5widthEv(%struct.QRectF*)
+
+declare double @_ZNK6QRectF6heightEv(%struct.QRectF*)
+
+declare void @_ZNK6QRectF4sizeEv(%struct.QPointF*, %struct.QRectF*)
+
+declare void @_ZN16QTextFrameFormatD1Ev(%struct.QTextBlockFormat*)
+
+declare void @_ZNK10QTextFrame11frameFormatEv(%struct.QTextBlockFormat*, %struct.QTextBlockGroup*)
+
+declare void @_ZN10QTextFrame14setFrameFormatERK16QTextFrameFormat(%struct.QTextBlockGroup*, %struct.QTextBlockFormat*)
+
+declare i32 @_ZNK12QPaintDevice5widthEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice6heightEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice11logicalDpiXEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice11logicalDpiYEv(%struct.QPaintDevice*)
+
+declare %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument5cloneEP7QObject(%struct.QAbstractTextDocumentLayout*, %struct.QObject*)
+
+declare void @_ZN5QFontD1Ev(%struct.QFont*)
+
+declare %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv(%struct.QAbstractTextDocumentLayout*)
+
+declare %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv(%struct.QAbstractTextDocumentLayout*)
+
+declare i32 @_ZNK13QTextDocument9pageCountEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZNK13QTextDocument11defaultFontEv(%struct.QFont*, %struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN13QTextDocument14setDefaultFontERK5QFont(%struct.QAbstractTextDocumentLayout*, %struct.QFont*)
+
+declare void @_ZN13QTextDocument11setPageSizeERK6QSizeF(%struct.QAbstractTextDocumentLayout*, %struct.QPointF*)
+
+declare void @_Z9printPageiP8QPainterPK13QTextDocumentRK6QRectFRK7QPointF(i32, %struct.QPainter*, %struct.QAbstractTextDocumentLayout*, %struct.QRectF*, %struct.QPointF*)
+
+declare void @_ZN12QFontMetricsD1Ev(%struct.QFontMetrics*)
+
+declare void @_ZN8QPainterC1EP12QPaintDevice(%struct.QPainter*, %struct.QPaintDevice*)
+
+declare i1 @_ZNK8QPainter8isActiveEv(%struct.QPainter*)
+
+declare i32 @_Z13qt_defaultDpiv()
+
+declare %struct.QPaintDevice* @_ZNK27QAbstractTextDocumentLayout11paintDeviceEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN8QPainter5scaleEdd(%struct.QPainter*, double, double)
+
+declare %struct.QPaintDevice* @_ZNK8QPainter6deviceEv(%struct.QPainter*)
+
+declare void @_ZN27QAbstractTextDocumentLayout14setPaintDeviceEP12QPaintDevice(%struct.QAbstractTextDocumentLayout*, %struct.QPaintDevice*)
+
+declare void @_ZN12QFontMetricsC1ERK5QFontP12QPaintDevice(%struct.QFontMetrics*, %struct.QFont*, %struct.QPaintDevice*)
+
+declare i32 @_ZNK12QFontMetrics6ascentEv(%struct.QFontMetrics*)
+
+declare void @_ZN5QFont12setPointSizeEi(%struct.QFont*, i32)
+
+declare i1 @_ZNK8QPrinter13collateCopiesEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter9numCopiesEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter8fromPageEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter6toPageEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter9pageOrderEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter12printerStateEv(%struct.QPrinter*)
+
+declare i1 @_ZN8QPrinter7newPageEv(%struct.QPrinter*)
+
+declare void @_ZN8QPainterD1Ev(%struct.QPainter*)
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2006-12-08-Ptr-ICmp-Branch.ll b/src/LLVM/test/Transforms/SimplifyCFG/2006-12-08-Ptr-ICmp-Branch.ll
new file mode 100644
index 0000000..24b1455
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2006-12-08-Ptr-ICmp-Branch.ll
@@ -0,0 +1,131 @@
+; RUN: opt < %s -simplifycfg | llvm-dis
+; END.
+
+; ModuleID = '2006-12-08-Ptr-ICmp-Branch.ll'
+target datalayout = "e-p:32:32"
+target triple = "i686-pc-linux-gnu"
+ %struct.FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct.FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i32, i32, [40 x i8] }
+ %struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct.FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i32, i32, [40 x i8] }
+ %struct._IO_marker = type { %struct._IO_marker*, %struct.FILE*, i32 }
+ %struct.charsequence = type { i8*, i32, i32 }
+ %struct.trie_s = type { [26 x %struct.trie_s*], i32 }
+@str = external global [14 x i8] ; <[14 x i8]*> [#uses=0]
+@str.upgrd.1 = external global [32 x i8] ; <[32 x i8]*> [#uses=0]
+@str.upgrd.2 = external global [12 x i8] ; <[12 x i8]*> [#uses=0]
+@C.0.2294 = external global %struct.charsequence ; <%struct.charsequence*> [#uses=3]
+@t = external global %struct.trie_s* ; <%struct.trie_s**> [#uses=0]
+@str.upgrd.3 = external global [3 x i8] ; <[3 x i8]*> [#uses=0]
+@str.upgrd.4 = external global [26 x i8] ; <[26 x i8]*> [#uses=0]
+
+declare void @charsequence_reset(%struct.charsequence*)
+
+declare void @free(i8*)
+
+declare void @charsequence_push(%struct.charsequence*, i8)
+
+declare i8* @charsequence_val(%struct.charsequence*)
+
+declare i32 @_IO_getc(%struct.FILE*)
+
+declare i32 @tolower(i32)
+
+declare %struct.trie_s* @trie_insert(%struct.trie_s*, i8*)
+
+declare i32 @feof(%struct.FILE*)
+
+define void @addfile(%struct.trie_s* %t, %struct.FILE* %f) {
+entry:
+ %t_addr = alloca %struct.trie_s* ; <%struct.trie_s**> [#uses=2]
+ %f_addr = alloca %struct.FILE* ; <%struct.FILE**> [#uses=3]
+ %c = alloca i8, align 1 ; <i8*> [#uses=7]
+ %wstate = alloca i32, align 4 ; <i32*> [#uses=4]
+ %cs = alloca %struct.charsequence, align 16 ; <%struct.charsequence*> [#uses=7]
+ %str = alloca i8*, align 4 ; <i8**> [#uses=3]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store %struct.trie_s* %t, %struct.trie_s** %t_addr
+ store %struct.FILE* %f, %struct.FILE** %f_addr
+ store i32 0, i32* %wstate
+ %tmp = getelementptr %struct.charsequence* %cs, i64 0, i32 0 ; <i8**> [#uses=1]
+ %tmp1 = getelementptr %struct.charsequence* @C.0.2294, i64 0, i32 0 ; <i8**> [#uses=1]
+ %tmp.upgrd.5 = load i8** %tmp1 ; <i8*> [#uses=1]
+ store i8* %tmp.upgrd.5, i8** %tmp
+ %tmp.upgrd.6 = getelementptr %struct.charsequence* %cs, i64 0, i32 1 ; <i32*> [#uses=1]
+ %tmp2 = getelementptr %struct.charsequence* @C.0.2294, i64 0, i32 1 ; <i32*> [#uses=1]
+ %tmp.upgrd.7 = load i32* %tmp2 ; <i32> [#uses=1]
+ store i32 %tmp.upgrd.7, i32* %tmp.upgrd.6
+ %tmp3 = getelementptr %struct.charsequence* %cs, i64 0, i32 2 ; <i32*> [#uses=1]
+ %tmp4 = getelementptr %struct.charsequence* @C.0.2294, i64 0, i32 2 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %tmp4 ; <i32> [#uses=1]
+ store i32 %tmp5, i32* %tmp3
+ br label %bb33
+bb: ; preds = %bb33
+ %tmp.upgrd.8 = load %struct.FILE** %f_addr ; <%struct.FILE*> [#uses=1]
+ %tmp.upgrd.9 = call i32 @_IO_getc( %struct.FILE* %tmp.upgrd.8 ) ; <i32> [#uses=1]
+ %tmp6 = call i32 @tolower( i32 %tmp.upgrd.9 ) ; <i32> [#uses=1]
+ %tmp6.upgrd.10 = trunc i32 %tmp6 to i8 ; <i8> [#uses=1]
+ store i8 %tmp6.upgrd.10, i8* %c
+ %tmp7 = load i32* %wstate ; <i32> [#uses=1]
+ %tmp.upgrd.11 = icmp ne i32 %tmp7, 0 ; <i1> [#uses=1]
+ br i1 %tmp.upgrd.11, label %cond_true, label %cond_false
+cond_true: ; preds = %bb
+ %tmp.upgrd.12 = load i8* %c ; <i8> [#uses=1]
+ %tmp8 = icmp sle i8 %tmp.upgrd.12, 96 ; <i1> [#uses=1]
+ br i1 %tmp8, label %cond_true9, label %cond_next
+cond_true9: ; preds = %cond_true
+ br label %bb16
+cond_next: ; preds = %cond_true
+ %tmp10 = load i8* %c ; <i8> [#uses=1]
+ %tmp11 = icmp sgt i8 %tmp10, 122 ; <i1> [#uses=1]
+ br i1 %tmp11, label %cond_true12, label %cond_next13
+cond_true12: ; preds = %cond_next
+ br label %bb16
+cond_next13: ; preds = %cond_next
+ %tmp14 = load i8* %c ; <i8> [#uses=1]
+ %tmp14.upgrd.13 = sext i8 %tmp14 to i32 ; <i32> [#uses=1]
+ %tmp1415 = trunc i32 %tmp14.upgrd.13 to i8 ; <i8> [#uses=1]
+ call void @charsequence_push( %struct.charsequence* %cs, i8 %tmp1415 )
+ br label %bb21
+bb16: ; preds = %cond_true12, %cond_true9
+ %tmp17 = call i8* @charsequence_val( %struct.charsequence* %cs ) ; <i8*> [#uses=1]
+ store i8* %tmp17, i8** %str
+ %tmp.upgrd.14 = load %struct.trie_s** %t_addr ; <%struct.trie_s*> [#uses=1]
+ %tmp18 = load i8** %str ; <i8*> [#uses=1]
+ %tmp19 = call %struct.trie_s* @trie_insert( %struct.trie_s* %tmp.upgrd.14, i8* %tmp18 ) ; <%struct.trie_s*> [#uses=0]
+ %tmp20 = load i8** %str ; <i8*> [#uses=1]
+ call void @free( i8* %tmp20 )
+ store i32 0, i32* %wstate
+ br label %bb21
+bb21: ; preds = %bb16, %cond_next13
+ br label %cond_next32
+cond_false: ; preds = %bb
+ %tmp22 = load i8* %c ; <i8> [#uses=1]
+ %tmp23 = icmp sgt i8 %tmp22, 96 ; <i1> [#uses=1]
+ br i1 %tmp23, label %cond_true24, label %cond_next31
+cond_true24: ; preds = %cond_false
+ %tmp25 = load i8* %c ; <i8> [#uses=1]
+ %tmp26 = icmp sle i8 %tmp25, 122 ; <i1> [#uses=1]
+ br i1 %tmp26, label %cond_true27, label %cond_next30
+cond_true27: ; preds = %cond_true24
+ call void @charsequence_reset( %struct.charsequence* %cs )
+ %tmp28 = load i8* %c ; <i8> [#uses=1]
+ %tmp28.upgrd.15 = sext i8 %tmp28 to i32 ; <i32> [#uses=1]
+ %tmp2829 = trunc i32 %tmp28.upgrd.15 to i8 ; <i8> [#uses=1]
+ call void @charsequence_push( %struct.charsequence* %cs, i8 %tmp2829 )
+ store i32 1, i32* %wstate
+ br label %cond_next30
+cond_next30: ; preds = %cond_true27, %cond_true24
+ br label %cond_next31
+cond_next31: ; preds = %cond_next30, %cond_false
+ br label %cond_next32
+cond_next32: ; preds = %cond_next31, %bb21
+ br label %bb33
+bb33: ; preds = %cond_next32, %entry
+ %tmp34 = load %struct.FILE** %f_addr ; <%struct.FILE*> [#uses=1]
+ %tmp35 = call i32 @feof( %struct.FILE* %tmp34 ) ; <i32> [#uses=1]
+ %tmp36 = icmp eq i32 %tmp35, 0 ; <i1> [#uses=1]
+ br i1 %tmp36, label %bb, label %bb37
+bb37: ; preds = %bb33
+ br label %return
+return: ; preds = %bb37
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2007-11-22-InvokeNoUnwind.ll b/src/LLVM/test/Transforms/SimplifyCFG/2007-11-22-InvokeNoUnwind.ll
new file mode 100644
index 0000000..a20c46e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2007-11-22-InvokeNoUnwind.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -simplifycfg -S | not grep invoke
+
+declare i32 @func(i8*) nounwind
+
+define i32 @test() {
+ invoke i32 @func( i8* null )
+ to label %Cont unwind label %Other ; <i32>:1 [#uses=0]
+
+Cont: ; preds = %0
+ ret i32 0
+
+Other: ; preds = %0
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2007-12-21-Crash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2007-12-21-Crash.ll
new file mode 100644
index 0000000..46df0f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2007-12-21-Crash.ll
@@ -0,0 +1,37 @@
+;RUN: opt < %s -simplifycfg -disable-output
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+define i32 @bork() nounwind {
+entry:
+ br label %bb5.outer
+
+bb5.outer.loopexit: ; preds = %bb5
+ br label %bb5.outer
+
+bb5.outer: ; preds = %bb5.outer.loopexit, %entry
+ %undo.0.ph = phi i32 [ 0, %entry ], [ 1, %bb5.outer.loopexit ] ; <i32> [#uses=1]
+ br label %bb5
+
+bb5: ; preds = %bb5, %bb5.outer
+ %tmp6 = tail call i32 (...)* @foo( ) nounwind ; <i32> [#uses=1]
+ switch i32 %tmp6, label %bb13 [
+ i32 -1, label %bb10
+ i32 102, label %bb5
+ i32 110, label %bb5.outer.loopexit
+ ]
+
+bb10: ; preds = %bb5
+ %tmp12 = tail call i32 (...)* @bar( i32 %undo.0.ph ) nounwind ; <i32> [#uses=0]
+ br label %UnifiedReturnBlock
+
+bb13: ; preds = %bb5
+ br label %UnifiedReturnBlock
+
+UnifiedReturnBlock: ; preds = %bb13, %bb10
+ %UnifiedRetVal = phi i32 [ 1, %bb10 ], [ 258, %bb13 ] ; <i32> [#uses=1]
+ ret i32 %UnifiedRetVal
+}
+
+declare i32 @foo(...)
+
+declare i32 @bar(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-01-02-hoist-fp-add.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-01-02-hoist-fp-add.ll
new file mode 100644
index 0000000..00f2d5b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-01-02-hoist-fp-add.ll
@@ -0,0 +1,26 @@
+; The phi should not be eliminated in this case, because the fp op could trap.
+; RUN: opt < %s -simplifycfg -S | grep {= phi double}
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-apple-darwin8"
+@G = weak global double 0.000000e+00, align 8 ; <double*> [#uses=2]
+
+define void @test(i32 %X, i32 %Y, double %Z) {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ %tmp = load double* @G, align 8 ; <double> [#uses=2]
+ %tmp3 = icmp eq i32 %X, %Y ; <i1> [#uses=1]
+ %tmp34 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
+ %toBool = icmp ne i8 %tmp34, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %cond_true, label %cond_next
+
+cond_true: ; preds = %entry
+ %tmp7 = fadd double %tmp, %Z ; <double> [#uses=1]
+ br label %cond_next
+
+cond_next: ; preds = %cond_true, %entry
+ %F.0 = phi double [ %tmp, %entry ], [ %tmp7, %cond_true ] ; <double> [#uses=1]
+ store double %F.0, double* @G, align 8
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-05-16-PHIBlockMerge.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-05-16-PHIBlockMerge.ll
new file mode 100644
index 0000000..56f43b6
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-05-16-PHIBlockMerge.ll
@@ -0,0 +1,131 @@
+; RUN: opt < %s -simplifycfg -S > %t
+; RUN: not grep {^BB.tomerge} %t
+; RUN: grep {^BB.nomerge} %t | count 2
+
+; ModuleID = '<stdin>'
+declare i1 @foo()
+
+declare i1 @bar(i32)
+
+; This function can't be merged
+define void @a() {
+entry:
+ br label %BB.nomerge
+
+BB.nomerge: ; preds = %Common, %entry
+ ; This phi has a conflicting value (0) with below phi (2), so blocks
+ ; can't be merged.
+ %a = phi i32 [ 1, %entry ], [ 0, %Common ] ; <i32> [#uses=1]
+ br label %Succ
+
+Succ: ; preds = %Common, %BB.nomerge
+ %b = phi i32 [ %a, %BB.nomerge ], [ 2, %Common ] ; <i32> [#uses=0]
+ %conde = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %conde, label %Common, label %Exit
+
+Common: ; preds = %Succ
+ %cond = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %cond, label %BB.nomerge, label %Succ
+
+Exit: ; preds = %Succ
+ ret void
+}
+
+; This function can't be merged
+define void @b() {
+entry:
+ br label %BB.nomerge
+
+BB.nomerge: ; preds = %Common, %entry
+ br label %Succ
+
+Succ: ; preds = %Common, %BB.nomerge
+ ; This phi has confliction values for Common and (through BB) Common,
+ ; blocks can't be merged
+ %b = phi i32 [ 1, %BB.nomerge ], [ 2, %Common ] ; <i32> [#uses=0]
+ %conde = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %conde, label %Common, label %Exit
+
+Common: ; preds = %Succ
+ %cond = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %cond, label %BB.nomerge, label %Succ
+
+Exit: ; preds = %Succ
+ ret void
+}
+
+; This function can be merged
+define void @c() {
+entry:
+ br label %BB.tomerge
+
+BB.tomerge: ; preds = %Common, %entry
+ br label %Succ
+
+Succ: ; preds = %Common, %BB.tomerge, %Pre-Exit
+ ; This phi has identical values for Common and (through BB) Common,
+ ; blocks can't be merged
+ %b = phi i32 [ 1, %BB.tomerge ], [ 1, %Common ], [ 2, %Pre-Exit ]
+ %conde = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %conde, label %Common, label %Pre-Exit
+
+Common: ; preds = %Succ
+ %cond = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %cond, label %BB.tomerge, label %Succ
+
+Pre-Exit: ; preds = %Succ
+ ; This adds a backedge, so the %b phi node gets a third branch and is
+ ; not completely trivial
+ %cond2 = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %cond2, label %Succ, label %Exit
+
+Exit: ; preds = %Pre-Exit
+ ret void
+}
+
+; This function can be merged
+define void @d() {
+entry:
+ br label %BB.tomerge
+
+BB.tomerge: ; preds = %Common, %entry
+ ; This phi has a matching value (0) with below phi (0), so blocks
+ ; can be merged.
+ %a = phi i32 [ 1, %entry ], [ 0, %Common ] ; <i32> [#uses=1]
+ br label %Succ
+
+Succ: ; preds = %Common, %BB.tomerge
+ %b = phi i32 [ %a, %BB.tomerge ], [ 0, %Common ] ; <i32> [#uses=0]
+ %conde = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %conde, label %Common, label %Exit
+
+Common: ; preds = %Succ
+ %cond = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %cond, label %BB.tomerge, label %Succ
+
+Exit: ; preds = %Succ
+ ret void
+}
+
+; This function can be merged
+define void @e() {
+entry:
+ br label %BB.tomerge
+
+BB.tomerge: ; preds = %Use, %entry
+ ; This phi is used somewhere else than Succ, but this should not prevent
+ ; merging this block
+ %a = phi i32 [ 1, %entry ], [ 0, %Use ] ; <i32> [#uses=1]
+ br label %Succ
+
+Succ: ; preds = %BB.tomerge
+ %conde = call i1 @foo( ) ; <i1> [#uses=1]
+ br i1 %conde, label %Use, label %Exit
+
+Use: ; preds = %Succ
+ %cond = call i1 @bar( i32 %a ) ; <i1> [#uses=1]
+ br i1 %cond, label %BB.tomerge, label %Exit
+
+Exit: ; preds = %Use, %Succ
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll
new file mode 100644
index 0000000..d025dee
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -simplifycfg -S | grep {%outval = phi i32 .*mux}
+; PR2540
+; Outval should end up with a select from 0/2, not all constants.
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+@g_37 = common global i32 0 ; <i32*> [#uses=1]
+@.str = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+define i32 @main() nounwind {
+entry:
+ %l = load i32* @g_37, align 4 ; <i32> [#uses=1]
+ %cmpa = icmp ne i32 %l, 0 ; <i1> [#uses=3]
+ br i1 %cmpa, label %func_1.exit, label %mooseblock
+
+mooseblock: ; preds = %entry
+ %cmpb = icmp eq i1 %cmpa, false ; <i1> [#uses=2]
+ br i1 %cmpb, label %monkeyblock, label %beeblock
+
+monkeyblock: ; preds = %monkeyblock, %mooseblock
+ br i1 %cmpb, label %cowblock, label %monkeyblock
+
+beeblock: ; preds = %beeblock, %mooseblock
+ br i1 %cmpa, label %cowblock, label %beeblock
+
+cowblock: ; preds = %beeblock, %monkeyblock
+ %cowval = phi i32 [ 2, %beeblock ], [ 0, %monkeyblock ] ; <i32> [#uses=1]
+ br label %func_1.exit
+
+func_1.exit: ; preds = %cowblock, %entry
+ %outval = phi i32 [ %cowval, %cowblock ], [ 1, %entry ] ; <i32> [#uses=1]
+ %pout = tail call i32 (i8*, ...)* @printf( i8* noalias getelementptr ([4 x i8]* @.str, i32 0, i32 0), i32 %outval ) nounwind ; <i32> [#uses=0]
+ ret i32 0
+}
+
+declare i32 @printf(i8*, ...) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-09-08-MultiplePred.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-09-08-MultiplePred.ll
new file mode 100644
index 0000000..ac9622d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-09-08-MultiplePred.ll
@@ -0,0 +1,60 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; PR 2777
+@g_103 = common global i32 0 ; <i32*> [#uses=1]
+
+define i32 @func_127(i32 %p_129) nounwind {
+entry:
+ load i32* @g_103, align 4 ; <i32>:0 [#uses=1]
+ icmp eq i32 %0, 0 ; <i1>:1 [#uses=2]
+ br i1 %1, label %bb6.preheader, label %entry.return_crit_edge
+
+entry.return_crit_edge: ; preds = %entry
+ br label %return
+
+bb6.preheader: ; preds = %entry
+ br i1 %1, label %bb6.preheader.split.us, label %bb6.preheader.split
+
+bb6.preheader.split.us: ; preds = %bb6.preheader
+ br label %return.loopexit.split
+
+bb6.preheader.split: ; preds = %bb6.preheader
+ br label %bb6
+
+bb6: ; preds = %bb17.bb6_crit_edge, %bb6.preheader.split
+ %indvar35 = phi i32 [ 0, %bb6.preheader.split ], [ %indvar.next36, %bb17.bb6_crit_edge ] ; <i32> [#uses=1]
+ %p_129_addr.3.reg2mem.0 = phi i32 [ %p_129_addr.2, %bb17.bb6_crit_edge ], [ %p_129, %bb6.preheader.split ] ; <i32> [#uses=3]
+ icmp eq i32 %p_129_addr.3.reg2mem.0, 0 ; <i1>:2 [#uses=1]
+ br i1 %2, label %bb6.bb17_crit_edge, label %bb8
+
+bb6.bb17_crit_edge: ; preds = %bb6
+ br label %bb17
+
+bb8: ; preds = %bb6
+ br label %bb13
+
+bb13: ; preds = %bb8
+ br label %bb17
+
+bb17: ; preds = %bb13, %bb6.bb17_crit_edge
+ %p_129_addr.2 = phi i32 [ %p_129_addr.3.reg2mem.0, %bb13 ], [ %p_129_addr.3.reg2mem.0, %bb6.bb17_crit_edge ] ; <i32> [#uses=1]
+ %indvar.next36 = add i32 %indvar35, 1 ; <i32> [#uses=2]
+ %exitcond37 = icmp eq i32 %indvar.next36, -1 ; <i1> [#uses=1]
+ br i1 %exitcond37, label %return.loopexit, label %bb17.bb6_crit_edge
+
+bb17.bb6_crit_edge: ; preds = %bb17
+ br label %bb6
+
+return.loopexit: ; preds = %bb17
+ br label %return.loopexit.split
+
+return.loopexit.split: ; preds = %return.loopexit, %bb6.preheader.split.us
+ br label %return
+
+return: ; preds = %return.loopexit.split, %entry.return_crit_edge
+ ret i32 1
+}
+
+define i32 @func_135(i8 zeroext %p_137, i32 %p_138, i32 %p_140) nounwind {
+entry:
+ ret i32 undef
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-09-17-SpeculativeHoist.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-09-17-SpeculativeHoist.ll
new file mode 100644
index 0000000..f864184
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-09-17-SpeculativeHoist.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; PR 2800
+
+define void @foo() {
+start:
+ %tmp = call i1 @bar( ) ; <i1> [#uses=4]
+ br i1 %tmp, label %brtrue, label %brfalse
+
+brtrue: ; preds = %start
+ %tmpnew = and i1 %tmp, %tmp ; <i1> [#uses=1]
+ br label %brfalse
+
+brfalse: ; preds = %brtrue, %start
+ %andandtmp.0 = phi i1 [ %tmp, %start ], [ %tmpnew, %brtrue ] ; <i1> [#uses=0]
+ ret void
+}
+
+declare i1 @bar()
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll
new file mode 100644
index 0000000..bb137c1
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-10-03-SpeculativelyExecuteBeforePHI.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -simplifycfg
+; PR2855
+
+define i32 @_Z1fPii(i32* %b, i32 %f) nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb9, %bb7, %bb, %entry
+ %__c2.2 = phi i32 [ undef, %entry ], [ %__c2.1, %bb7 ], [ %__c2.1, %bb9 ] ; <i32> [#uses=2]
+ %s.0 = phi i32 [ 0, %entry ], [ 0, %bb7 ], [ %2, %bb9 ] ; <i32> [#uses=1]
+ br label %bb1
+
+bb1: ; preds = %bb
+ %0 = icmp slt i32 0, %f ; <i1> [#uses=1]
+ br i1 %0, label %bb3, label %bb6
+
+bb3: ; preds = %bb1
+ %1 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+ br i1 %1, label %bb6, label %bb5
+
+bb5: ; preds = %bb3
+ br label %bb7
+
+bb6: ; preds = %bb3, %bb1
+ %__c2.0 = phi i32 [ 0, %bb3 ], [ %__c2.2, %bb1 ] ; <i32> [#uses=1]
+ br label %bb7
+
+bb7: ; preds = %bb6, %bb5
+ %__c2.1 = phi i32 [ 0, %bb5 ], [ %__c2.0, %bb6 ] ; <i32> [#uses=2]
+ %iftmp.1.0 = phi i1 [ false, %bb5 ], [ true, %bb6 ] ; <i1> [#uses=1]
+ br i1 %iftmp.1.0, label %bb, label %bb9
+
+bb9: ; preds = %bb7
+ %2 = add i32 %s.0, 2 ; <i32> [#uses=1]
+ br label %bb
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-12-06-SingleEntryPhi.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-12-06-SingleEntryPhi.ll
new file mode 100644
index 0000000..d3c7c32
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-12-06-SingleEntryPhi.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -simplifycfg | llvm-dis
+define i32 @test() {
+entry:
+ br label %T
+T:
+ %C = phi i1 [false, %entry]
+ br i1 %C, label %X, label %Y
+X:
+ ret i32 2
+Y:
+ add i32 1, 2
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll b/src/LLVM/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
new file mode 100644
index 0000000..7271024
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
@@ -0,0 +1,46 @@
+; RUN: opt < %s -simplifycfg -S | not grep icmp
+; ModuleID = '/tmp/x.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i686-pc-linux-gnu"
+
+define i32 @x(i32 %x) {
+entry:
+ %cmp = icmp eq i32 %x, 8 ; <i1> [#uses=1]
+ br i1 %cmp, label %ifthen, label %ifend
+
+ifthen: ; preds = %entry
+ %call = call i32 (...)* @foo() ; <i32> [#uses=0]
+ br label %ifend
+
+ifend: ; preds = %ifthen, %entry
+ %cmp2 = icmp ne i32 %x, 8 ; <i1> [#uses=1]
+ br i1 %cmp2, label %ifthen3, label %ifend5
+
+ifthen3: ; preds = %ifend
+ %call4 = call i32 (...)* @foo() ; <i32> [#uses=0]
+ br label %ifend5
+
+ifend5: ; preds = %ifthen3, %ifend
+ %cmp7 = icmp eq i32 %x, 9 ; <i1> [#uses=1]
+ br i1 %cmp7, label %ifthen8, label %ifend10
+
+ifthen8: ; preds = %ifend5
+ %call9 = call i32 (...)* @bar() ; <i32> [#uses=0]
+ br label %ifend10
+
+ifend10: ; preds = %ifthen8, %ifend5
+ %cmp12 = icmp ne i32 %x, 9 ; <i1> [#uses=1]
+ br i1 %cmp12, label %ifthen13, label %ifend15
+
+ifthen13: ; preds = %ifend10
+ %call14 = call i32 (...)* @bar() ; <i32> [#uses=0]
+ br label %ifend15
+
+ifend15: ; preds = %ifthen13, %ifend10
+ ret i32 0
+}
+
+declare i32 @foo(...)
+
+declare i32 @bar(...)
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2009-01-18-PHIPropCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2009-01-18-PHIPropCrash.ll
new file mode 100644
index 0000000..c6ae6ac
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2009-01-18-PHIPropCrash.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; PR3016
+; Dead use caused invariant violation.
+
+define i32 @func_105(i1 %tmp5, i1 %tmp7) nounwind {
+BB:
+ br i1 true, label %BB2, label %BB1
+
+BB1: ; preds = %BB
+ br label %BB2
+
+BB2: ; preds = %BB1, %BB
+ %tmp3 = phi i1 [ true, %BB ], [ false, %BB1 ] ; <i1> [#uses=1]
+ br label %BB9
+
+BB9: ; preds = %BB11, %BB2
+ %tmp10 = phi i32 [ 0, %BB2 ], [ %tmp12, %BB11 ] ; <i32> [#uses=1]
+ br i1 %tmp5, label %BB11, label %BB13
+
+BB11: ; preds = %BB13, %BB9
+ %tmp12 = phi i32 [ 0, %BB13 ], [ %tmp10, %BB9 ] ; <i32> [#uses=2]
+ br i1 %tmp3, label %BB9, label %BB20
+
+BB13: ; preds = %BB13, %BB9
+ %tmp14 = phi i32 [ 0, %BB9 ], [ %tmp14, %BB13 ] ; <i32> [#uses=1]
+ br i1 %tmp7, label %BB13, label %BB11
+
+BB20: ; preds = %BB11
+ ret i32 %tmp12
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2009-01-19-UnconditionalTrappingConstantExpr.ll b/src/LLVM/test/Transforms/SimplifyCFG/2009-01-19-UnconditionalTrappingConstantExpr.ll
new file mode 100644
index 0000000..568e61c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2009-01-19-UnconditionalTrappingConstantExpr.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -simplifycfg -S | grep {br i1 } | count 4
+; PR3354
+; Do not merge bb1 into the entry block, it might trap.
+
+@G = extern_weak global i32
+
+define i32 @test(i32 %tmp21, i32 %tmp24) {
+ %tmp25 = icmp sle i32 %tmp21, %tmp24
+ br i1 %tmp25, label %bb2, label %bb1
+
+bb1: ; preds = %bb
+ %tmp26 = icmp sgt i32 sdiv (i32 -32768, i32 ptrtoint (i32* @G to i32)), 0
+ br i1 %tmp26, label %bb6, label %bb2
+bb2:
+ ret i32 42
+
+bb6:
+ ret i32 927
+}
+
+define i32 @test2(i32 %tmp21, i32 %tmp24, i1 %tmp34) {
+ br i1 %tmp34, label %bb5, label %bb6
+
+bb5: ; preds = %bb4
+ br i1 icmp sgt (i32 sdiv (i32 32767, i32 ptrtoint (i32* @G to i32)), i32 0), label %bb6, label %bb7
+bb6:
+ ret i32 42
+bb7:
+ ret i32 927
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll b/src/LLVM/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
new file mode 100644
index 0000000..419feb6
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -simplifycfg -S | not grep select
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin10.0"
+module asm ".globl _foo"
+module asm "_foo: ret"
+module asm ".globl _i"
+module asm ".set _i, 0"
+@i = extern_weak global i32 ; <i32*> [#uses=2]
+@j = common global i32 0 ; <i32*> [#uses=1]
+@ed = common global double 0.000000e+00, align 8 ; <double*> [#uses=1]
+
+define i32 @main() nounwind ssp {
+entry:
+ br label %bb4
+
+bb: ; preds = %bb4
+ br i1 icmp ne (i32* @i, i32* null), label %bb1, label %bb2
+
+bb1: ; preds = %bb
+ %0 = load i32* @i, align 4 ; <i32> [#uses=1]
+ br label %bb3
+
+bb2: ; preds = %bb
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %storemerge = phi i32 [ %0, %bb1 ], [ 0, %bb2 ] ; <i32> [#uses=2]
+ store i32 %storemerge, i32* @j
+ %1 = sitofp i32 %storemerge to double ; <double> [#uses=1]
+ %2 = call double @sin(double %1) nounwind readonly ; <double> [#uses=1]
+ %3 = fadd double %2, %d.0 ; <double> [#uses=1]
+ %4 = add i32 %l.0, 1 ; <i32> [#uses=1]
+ br label %bb4
+
+bb4: ; preds = %bb3, %entry
+ %d.0 = phi double [ undef, %entry ], [ %3, %bb3 ] ; <double> [#uses=2]
+ %l.0 = phi i32 [ 0, %entry ], [ %4, %bb3 ] ; <i32> [#uses=2]
+ %5 = icmp sgt i32 %l.0, 99 ; <i1> [#uses=1]
+ br i1 %5, label %bb5, label %bb
+
+bb5: ; preds = %bb4
+ store double %d.0, double* @ed, align 8
+ ret i32 0
+}
+
+declare double @sin(double) nounwind readonly
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll
new file mode 100644
index 0000000..abf4455
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll
@@ -0,0 +1,569 @@
+; RUN: opt < %s -simplifycfg -disable-output
+; END.
+ %struct..4._102 = type { %struct.QVectorData* }
+ %struct..5._125 = type { %struct.QMapData* }
+ %struct.QAbstractTextDocumentLayout = type { %struct.QObject }
+ %struct.QBasicAtomic = type { i32 }
+ %struct.QFont = type { %struct.QFontPrivate*, i32 }
+ %struct.QFontMetrics = type { %struct.QFontPrivate* }
+ %struct.QFontPrivate = type opaque
+ %"struct.QFragmentMap<QTextBlockData>" = type { %struct.QFragmentMapData }
+ %struct.QFragmentMapData = type { %"struct.QFragmentMapData::._154", i32 }
+ %"struct.QFragmentMapData::._154" = type { %"struct.QFragmentMapData::Header"* }
+ %"struct.QFragmentMapData::Header" = type { i32, i32, i32, i32, i32, i32, i32, i32 }
+ %"struct.QHash<uint,QHashDummyValue>" = type { %"struct.QHash<uint,QHashDummyValue>::._152" }
+ %"struct.QHash<uint,QHashDummyValue>::._152" = type { %struct.QHashData* }
+ %struct.QHashData = type { %"struct.QHashData::Node"*, %"struct.QHashData::Node"**, %struct.QBasicAtomic, i32, i32, i16, i16, i32, i8 }
+ %"struct.QHashData::Node" = type { %"struct.QHashData::Node"*, i32 }
+ %"struct.QList<QObject*>::._92" = type { %struct.QListData }
+ %"struct.QList<QPointer<QObject> >" = type { %"struct.QList<QObject*>::._92" }
+ %struct.QListData = type { %"struct.QListData::Data"* }
+ %"struct.QListData::Data" = type { %struct.QBasicAtomic, i32, i32, i32, i8, [1 x i8*] }
+ %"struct.QMap<QUrl,QVariant>" = type { %struct..5._125 }
+ %struct.QMapData = type { %"struct.QMapData::Node"*, [12 x %"struct.QMapData::Node"*], %struct.QBasicAtomic, i32, i32, i32, i8 }
+ %"struct.QMapData::Node" = type { %"struct.QMapData::Node"*, [1 x %"struct.QMapData::Node"*] }
+ %struct.QObject = type { i32 (...)**, %struct.QObjectData* }
+ %struct.QObjectData = type { i32 (...)**, %struct.QObject*, %struct.QObject*, %"struct.QList<QPointer<QObject> >", i8, [3 x i8], i32, i32 }
+ %struct.QObjectPrivate = type { %struct.QObjectData, i32, %struct.QObject*, %"struct.QList<QPointer<QObject> >", %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %struct.QString }
+ %struct.QPaintDevice = type { i32 (...)**, i16 }
+ %struct.QPainter = type { %struct.QPainterPrivate* }
+ %struct.QPainterPrivate = type opaque
+ %struct.QPointF = type { double, double }
+ %struct.QPrinter = type { %struct.QPaintDevice, %struct.QPrinterPrivate* }
+ %struct.QPrinterPrivate = type opaque
+ %struct.QRectF = type { double, double, double, double }
+ %"struct.QSet<uint>" = type { %"struct.QHash<uint,QHashDummyValue>" }
+ %"struct.QSharedDataPointer<QTextFormatPrivate>" = type { %struct.QTextFormatPrivate* }
+ %struct.QString = type { %"struct.QString::Data"* }
+ %"struct.QString::Data" = type { %struct.QBasicAtomic, i32, i32, i16*, i8, i8, [1 x i16] }
+ %struct.QTextBlockFormat = type { %struct.QTextFormat }
+ %struct.QTextBlockGroup = type { %struct.QAbstractTextDocumentLayout }
+ %struct.QTextDocumentConfig = type { %struct.QString }
+ %struct.QTextDocumentPrivate = type { %struct.QObjectPrivate, %struct.QString, %"struct.QVector<QAbstractTextDocumentLayout::Selection>", i1, i32, i32, i1, i32, i32, i32, i32, i1, %struct.QTextFormatCollection, %struct.QTextBlockGroup*, %struct.QAbstractTextDocumentLayout*, %"struct.QFragmentMap<QTextBlockData>", %"struct.QFragmentMap<QTextBlockData>", i32, %"struct.QList<QPointer<QObject> >", %"struct.QList<QPointer<QObject> >", %"struct.QMap<QUrl,QVariant>", %"struct.QMap<QUrl,QVariant>", %"struct.QMap<QUrl,QVariant>", %struct.QTextDocumentConfig, i1, i1, %struct.QPointF }
+ %struct.QTextFormat = type { %"struct.QSharedDataPointer<QTextFormatPrivate>", i32 }
+ %struct.QTextFormatCollection = type { %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %"struct.QVector<QAbstractTextDocumentLayout::Selection>", %"struct.QSet<uint>", %struct.QFont }
+ %struct.QTextFormatPrivate = type opaque
+ %"struct.QVector<QAbstractTextDocumentLayout::Selection>" = type { %struct..4._102 }
+ %struct.QVectorData = type { %struct.QBasicAtomic, i32, i32, i8 }
+
+define void @_ZNK13QTextDocument5printEP8QPrinter(%struct.QAbstractTextDocumentLayout* %this, %struct.QPrinter* %printer) {
+entry:
+ %tmp = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=2]
+ %tmp.upgrd.1 = alloca %struct.QRectF, align 16 ; <%struct.QRectF*> [#uses=5]
+ %tmp2 = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=3]
+ %tmp.upgrd.2 = alloca %struct.QFontMetrics, align 16 ; <%struct.QFontMetrics*> [#uses=4]
+ %tmp.upgrd.3 = alloca %struct.QFont, align 16 ; <%struct.QFont*> [#uses=4]
+ %tmp3 = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=2]
+ %p = alloca %struct.QPainter, align 16 ; <%struct.QPainter*> [#uses=14]
+ %body = alloca %struct.QRectF, align 16 ; <%struct.QRectF*> [#uses=9]
+ %foo = alloca double, align 8
+ %bar = alloca double, align 8
+ %pageNumberPos = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=4]
+ %scaledPageSize = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=6]
+ %printerPageSize = alloca %struct.QPointF, align 16 ; <%struct.QPointF*> [#uses=3]
+ %fmt = alloca %struct.QTextBlockFormat, align 16 ; <%struct.QTextBlockFormat*> [#uses=5]
+ %font = alloca %struct.QFont, align 16 ; <%struct.QFont*> [#uses=5]
+ %tmp.upgrd.4 = call %struct.QTextDocumentPrivate* @_ZNK13QTextDocument6d_funcEv( %struct.QAbstractTextDocumentLayout* %this ) ; <%struct.QTextDocumentPrivate*> [#uses=5]
+ %tmp.upgrd.5 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ call void @_ZN8QPainterC1EP12QPaintDevice( %struct.QPainter* %p, %struct.QPaintDevice* %tmp.upgrd.5 )
+ %tmp.upgrd.6 = invoke i1 @_ZNK8QPainter8isActiveEv( %struct.QPainter* %p )
+ to label %invcont unwind label %cleanup329 ; <i1> [#uses=1]
+invcont: ; preds = %entry
+ br i1 %tmp.upgrd.6, label %cond_next, label %cleanup328
+cond_next: ; preds = %invcont
+ %tmp8 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %this )
+ to label %invcont7 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=0]
+invcont7: ; preds = %cond_next
+ %tmp10 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ call void @_ZN7QPointFC1Edd( %struct.QPointF* %tmp, double 0.000000e+00, double 0.000000e+00 )
+ call void @_ZN6QRectFC1ERK7QPointFRK6QSizeF( %struct.QRectF* %body, %struct.QPointF* %tmp, %struct.QPointF* %tmp10 )
+ call void @_ZN7QPointFC1Ev( %struct.QPointF* %pageNumberPos )
+ %tmp12 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ %tmp13 = call i1 @_ZNK6QSizeF7isValidEv( %struct.QPointF* %tmp12 ) ; <i1> [#uses=1]
+ br i1 %tmp13, label %cond_next15, label %bb
+cond_next15: ; preds = %invcont7
+ %tmp17 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26 ; <%struct.QPointF*> [#uses=1]
+ %tmp.upgrd.7 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %tmp17 ) ; <double> [#uses=1]
+ %tmp18 = fcmp oeq double %tmp.upgrd.7, 0x41DFFFFFFFC00000 ; <i1> [#uses=1]
+ br i1 %tmp18, label %bb, label %cond_next20
+cond_next20: ; preds = %cond_next15
+ br label %bb21
+bb: ; preds = %cond_next15, %invcont7
+ br label %bb21
+bb21: ; preds = %bb, %cond_next20
+ %iftmp.406.0 = phi i1 [ false, %bb ], [ true, %cond_next20 ] ; <i1> [#uses=1]
+ br i1 %iftmp.406.0, label %cond_true24, label %cond_false
+cond_true24: ; preds = %bb21
+ %tmp.upgrd.8 = invoke i32 @_Z13qt_defaultDpiv( )
+ to label %invcont25 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont25: ; preds = %cond_true24
+ %tmp26 = sitofp i32 %tmp.upgrd.8 to double ; <double> [#uses=2]
+ %tmp30 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %this )
+ to label %invcont29 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=1]
+invcont29: ; preds = %invcont25
+ %tmp32 = invoke %struct.QPaintDevice* @_ZNK27QAbstractTextDocumentLayout11paintDeviceEv( %struct.QAbstractTextDocumentLayout* %tmp30 )
+ to label %invcont31 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=3]
+invcont31: ; preds = %invcont29
+ %tmp34 = icmp eq %struct.QPaintDevice* %tmp32, null ; <i1> [#uses=1]
+ br i1 %tmp34, label %cond_next42, label %cond_true35
+cond_true35: ; preds = %invcont31
+ %tmp38 = invoke i32 @_ZNK12QPaintDevice11logicalDpiXEv( %struct.QPaintDevice* %tmp32 )
+ to label %invcont37 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont37: ; preds = %cond_true35
+ %tmp38.upgrd.9 = sitofp i32 %tmp38 to double ; <double> [#uses=1]
+ %tmp41 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp32 )
+ to label %invcont40 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont40: ; preds = %invcont37
+ %tmp41.upgrd.10 = sitofp i32 %tmp41 to double ; <double> [#uses=1]
+ br label %cond_next42
+cond_next42: ; preds = %invcont40, %invcont31
+ %sourceDpiY.2 = phi double [ %tmp41.upgrd.10, %invcont40 ], [ %tmp26, %invcont31 ] ; <double> [#uses=1]
+ %sourceDpiX.2 = phi double [ %tmp38.upgrd.9, %invcont40 ], [ %tmp26, %invcont31 ] ; <double> [#uses=1]
+ %tmp44 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp46 = invoke i32 @_ZNK12QPaintDevice11logicalDpiXEv( %struct.QPaintDevice* %tmp44 )
+ to label %invcont45 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont45: ; preds = %cond_next42
+ %tmp46.upgrd.11 = sitofp i32 %tmp46 to double ; <double> [#uses=1]
+ %tmp48 = fdiv double %tmp46.upgrd.11, %sourceDpiX.2 ; <double> [#uses=2]
+ %tmp50 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp52 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp50 )
+ to label %invcont51 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont51: ; preds = %invcont45
+ %tmp52.upgrd.12 = sitofp i32 %tmp52 to double ; <double> [#uses=1]
+ %tmp54 = fdiv double %tmp52.upgrd.12, %sourceDpiY.2 ; <double> [#uses=2]
+ invoke void @_ZN8QPainter5scaleEdd( %struct.QPainter* %p, double %tmp48, double %tmp54 )
+ to label %invcont57 unwind label %cleanup329
+invcont57: ; preds = %invcont51
+ %tmp.upgrd.13 = getelementptr %struct.QPointF* %scaledPageSize, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp60 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26, i32 0 ; <double*> [#uses=1]
+ %tmp61 = load double* %tmp60 ; <double> [#uses=1]
+ store double %tmp61, double* %tmp.upgrd.13
+ %tmp62 = getelementptr %struct.QPointF* %scaledPageSize, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp63 = getelementptr %struct.QTextDocumentPrivate* %tmp.upgrd.4, i32 0, i32 26, i32 1 ; <double*> [#uses=1]
+ %tmp64 = load double* %tmp63 ; <double> [#uses=1]
+ store double %tmp64, double* %tmp62
+ %tmp65 = call double* @_ZN6QSizeF6rwidthEv( %struct.QPointF* %scaledPageSize ) ; <double*> [#uses=2]
+ %tmp67 = load double* %tmp65 ; <double> [#uses=1]
+ %tmp69 = fmul double %tmp67, %tmp48 ; <double> [#uses=1]
+ store double %tmp69, double* %tmp65
+ %tmp71 = call double* @_ZN6QSizeF7rheightEv( %struct.QPointF* %scaledPageSize ) ; <double*> [#uses=2]
+ %tmp73 = load double* %tmp71 ; <double> [#uses=1]
+ %tmp75 = fmul double %tmp73, %tmp54 ; <double> [#uses=1]
+ store double %tmp75, double* %tmp71
+ %tmp78 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp80 = invoke i32 @_ZNK12QPaintDevice6heightEv( %struct.QPaintDevice* %tmp78 )
+ to label %invcont79 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont79: ; preds = %invcont57
+ %tmp82 = getelementptr %struct.QPrinter* %printer, i32 0, i32 0 ; <%struct.QPaintDevice*> [#uses=1]
+ %tmp84 = invoke i32 @_ZNK12QPaintDevice5widthEv( %struct.QPaintDevice* %tmp82 )
+ to label %invcont83 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont83: ; preds = %invcont79
+ %tmp80.upgrd.14 = sitofp i32 %tmp80 to double ; <double> [#uses=1]
+ %tmp84.upgrd.15 = sitofp i32 %tmp84 to double ; <double> [#uses=1]
+ call void @_ZN6QSizeFC1Edd( %struct.QPointF* %printerPageSize, double %tmp84.upgrd.15, double %tmp80.upgrd.14 )
+ %tmp85 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %printerPageSize ) ; <double> [#uses=1]
+ %tmp86 = call double @_ZNK6QSizeF6heightEv( %struct.QPointF* %scaledPageSize ) ; <double> [#uses=1]
+ %tmp87 = fdiv double %tmp85, %tmp86 ; <double> [#uses=1]
+ %tmp88 = call double @_ZNK6QSizeF5widthEv( %struct.QPointF* %printerPageSize ) ; <double> [#uses=1]
+ %tmp89 = call double @_ZNK6QSizeF5widthEv( %struct.QPointF* %scaledPageSize ) ; <double> [#uses=1]
+ %tmp90 = fdiv double %tmp88, %tmp89 ; <double> [#uses=1]
+ invoke void @_ZN8QPainter5scaleEdd( %struct.QPainter* %p, double %tmp90, double %tmp87 )
+ to label %cond_next194 unwind label %cleanup329
+cond_false: ; preds = %bb21
+ %tmp.upgrd.16 = getelementptr %struct.QAbstractTextDocumentLayout* %this, i32 0, i32 0 ; <%struct.QObject*> [#uses=1]
+ %tmp95 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument5cloneEP7QObject( %struct.QAbstractTextDocumentLayout* %this, %struct.QObject* %tmp.upgrd.16 )
+ to label %invcont94 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=9]
+invcont94: ; preds = %cond_false
+ %tmp99 = invoke %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv( %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont98 unwind label %cleanup329 ; <%struct.QAbstractTextDocumentLayout*> [#uses=1]
+invcont98: ; preds = %invcont94
+ %tmp101 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont100 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=1]
+invcont100: ; preds = %invcont98
+ invoke void @_ZN27QAbstractTextDocumentLayout14setPaintDeviceEP12QPaintDevice( %struct.QAbstractTextDocumentLayout* %tmp99, %struct.QPaintDevice* %tmp101 )
+ to label %invcont103 unwind label %cleanup329
+invcont103: ; preds = %invcont100
+ %tmp105 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont104 unwind label %cleanup329 ; <%struct.QPaintDevice*> [#uses=1]
+invcont104: ; preds = %invcont103
+ %tmp107 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp105 )
+ to label %invcont106 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont106: ; preds = %invcont104
+ %tmp108 = sitofp i32 %tmp107 to double ; <double> [#uses=1]
+ %tmp109 = fmul double %tmp108, 0x3FE93264C993264C ; <double> [#uses=1]
+ %tmp109.upgrd.17 = fptosi double %tmp109 to i32 ; <i32> [#uses=3]
+ %tmp.upgrd.18 = call %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv( %struct.QAbstractTextDocumentLayout* %tmp95 ) ; <%struct.QTextBlockGroup*> [#uses=1]
+ invoke void @_ZNK10QTextFrame11frameFormatEv( %struct.QTextBlockFormat* sret %fmt, %struct.QTextBlockGroup* %tmp.upgrd.18 )
+ to label %invcont111 unwind label %cleanup329
+invcont111: ; preds = %invcont106
+ %tmp112 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ invoke void @_ZN16QTextFrameFormat9setMarginEd( %struct.QTextBlockFormat* %fmt, double %tmp112 )
+ to label %invcont114 unwind label %cleanup192
+invcont114: ; preds = %invcont111
+ %tmp116 = call %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv( %struct.QAbstractTextDocumentLayout* %tmp95 ) ; <%struct.QTextBlockGroup*> [#uses=1]
+ invoke void @_ZN10QTextFrame14setFrameFormatERK16QTextFrameFormat( %struct.QTextBlockGroup* %tmp116, %struct.QTextBlockFormat* %fmt )
+ to label %invcont117 unwind label %cleanup192
+invcont117: ; preds = %invcont114
+ %tmp119 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont118 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont118: ; preds = %invcont117
+ %tmp121 = invoke i32 @_ZNK12QPaintDevice6heightEv( %struct.QPaintDevice* %tmp119 )
+ to label %invcont120 unwind label %cleanup192 ; <i32> [#uses=1]
+invcont120: ; preds = %invcont118
+ %tmp121.upgrd.19 = sitofp i32 %tmp121 to double ; <double> [#uses=1]
+ %tmp123 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont122 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont122: ; preds = %invcont120
+ %tmp125 = invoke i32 @_ZNK12QPaintDevice5widthEv( %struct.QPaintDevice* %tmp123 )
+ to label %invcont124 unwind label %cleanup192 ; <i32> [#uses=1]
+invcont124: ; preds = %invcont122
+ %tmp125.upgrd.20 = sitofp i32 %tmp125 to double ; <double> [#uses=1]
+ call void @_ZN6QRectFC1Edddd( %struct.QRectF* %tmp.upgrd.1, double 0.000000e+00, double 0.000000e+00, double %tmp125.upgrd.20, double %tmp121.upgrd.19 )
+ %tmp126 = getelementptr %struct.QRectF* %body, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp127 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp128 = load double* %tmp127 ; <double> [#uses=1]
+ store double %tmp128, double* %tmp126
+ %tmp129 = getelementptr %struct.QRectF* %body, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp130 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp131 = load double* %tmp130 ; <double> [#uses=1]
+ store double %tmp131, double* %tmp129
+ %tmp132 = getelementptr %struct.QRectF* %body, i32 0, i32 2 ; <double*> [#uses=1]
+ %tmp133 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 2 ; <double*> [#uses=1]
+ %tmp134 = load double* %tmp133 ; <double> [#uses=1]
+ store double %tmp134, double* %tmp132
+ %tmp135 = getelementptr %struct.QRectF* %body, i32 0, i32 3 ; <double*> [#uses=1]
+ %tmp136 = getelementptr %struct.QRectF* %tmp.upgrd.1, i32 0, i32 3 ; <double*> [#uses=1]
+ %tmp137 = load double* %tmp136 ; <double> [#uses=1]
+ store double %tmp137, double* %tmp135
+ %tmp138 = call double @_ZNK6QRectF6heightEv( %struct.QRectF* %body ) ; <double> [#uses=1]
+ %tmp139 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ %tmp140 = fsub double %tmp138, %tmp139 ; <double> [#uses=1]
+ %tmp142 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont141 unwind label %cleanup192 ; <%struct.QPaintDevice*> [#uses=1]
+invcont141: ; preds = %invcont124
+ invoke void @_ZNK13QTextDocument11defaultFontEv( %struct.QFont* sret %tmp.upgrd.3, %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont144 unwind label %cleanup192
+invcont144: ; preds = %invcont141
+ invoke void @_ZN12QFontMetricsC1ERK5QFontP12QPaintDevice( %struct.QFontMetrics* %tmp.upgrd.2, %struct.QFont* %tmp.upgrd.3, %struct.QPaintDevice* %tmp142 )
+ to label %invcont146 unwind label %cleanup173
+invcont146: ; preds = %invcont144
+ %tmp149 = invoke i32 @_ZNK12QFontMetrics6ascentEv( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %invcont148 unwind label %cleanup168 ; <i32> [#uses=1]
+invcont148: ; preds = %invcont146
+ %tmp149.upgrd.21 = sitofp i32 %tmp149 to double ; <double> [#uses=1]
+ %tmp150 = fadd double %tmp140, %tmp149.upgrd.21 ; <double> [#uses=1]
+ %tmp152 = invoke %struct.QPaintDevice* @_ZNK8QPainter6deviceEv( %struct.QPainter* %p )
+ to label %invcont151 unwind label %cleanup168 ; <%struct.QPaintDevice*> [#uses=1]
+invcont151: ; preds = %invcont148
+ %tmp154 = invoke i32 @_ZNK12QPaintDevice11logicalDpiYEv( %struct.QPaintDevice* %tmp152 )
+ to label %invcont153 unwind label %cleanup168 ; <i32> [#uses=1]
+invcont153: ; preds = %invcont151
+ %tmp155 = mul i32 %tmp154, 5 ; <i32> [#uses=1]
+ %tmp156 = sdiv i32 %tmp155, 72 ; <i32> [#uses=1]
+ %tmp156.upgrd.22 = sitofp i32 %tmp156 to double ; <double> [#uses=1]
+ %tmp157 = fadd double %tmp150, %tmp156.upgrd.22 ; <double> [#uses=1]
+ %tmp158 = call double @_ZNK6QRectF5widthEv( %struct.QRectF* %body ) ; <double> [#uses=1]
+ %tmp159 = sitofp i32 %tmp109.upgrd.17 to double ; <double> [#uses=1]
+ %tmp160 = fsub double %tmp158, %tmp159 ; <double> [#uses=1]
+ call void @_ZN7QPointFC1Edd( %struct.QPointF* %tmp2, double %tmp160, double %tmp157 )
+ %tmp161 = getelementptr %struct.QPointF* %pageNumberPos, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp162 = getelementptr %struct.QPointF* %tmp2, i32 0, i32 0 ; <double*> [#uses=1]
+ %tmp163 = load double* %tmp162 ; <double> [#uses=1]
+ store double %tmp163, double* %tmp161
+ %tmp164 = getelementptr %struct.QPointF* %pageNumberPos, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp165 = getelementptr %struct.QPointF* %tmp2, i32 0, i32 1 ; <double*> [#uses=1]
+ %tmp166 = load double* %tmp165 ; <double> [#uses=1]
+ store double %tmp166, double* %tmp164
+ invoke void @_ZN12QFontMetricsD1Ev( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %cleanup171 unwind label %cleanup173
+cleanup168: ; preds = %invcont151, %invcont148, %invcont146
+ %val168 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN12QFontMetricsD1Ev( %struct.QFontMetrics* %tmp.upgrd.2 )
+ to label %cleanup173 unwind label %cleanup173
+cleanup171: ; preds = %invcont153
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %tmp.upgrd.3 )
+ to label %finally170 unwind label %cleanup192
+cleanup173: ; preds = %cleanup168, %cleanup168, %invcont153, %invcont144
+ %val173 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %tmp.upgrd.3 )
+ to label %cleanup192 unwind label %cleanup192
+finally170: ; preds = %cleanup171
+ invoke void @_ZNK13QTextDocument11defaultFontEv( %struct.QFont* sret %font, %struct.QAbstractTextDocumentLayout* %tmp95 )
+ to label %invcont177 unwind label %cleanup192
+invcont177: ; preds = %finally170
+ invoke void @_ZN5QFont12setPointSizeEi( %struct.QFont* %font, i32 10 )
+ to label %invcont179 unwind label %cleanup187
+invcont179: ; preds = %invcont177
+ invoke void @_ZN13QTextDocument14setDefaultFontERK5QFont( %struct.QAbstractTextDocumentLayout* %tmp95, %struct.QFont* %font )
+ to label %invcont181 unwind label %cleanup187
+invcont181: ; preds = %invcont179
+ call void @_ZNK6QRectF4sizeEv( %struct.QPointF* sret %tmp3, %struct.QRectF* %body )
+ invoke void @_ZN13QTextDocument11setPageSizeERK6QSizeF( %struct.QAbstractTextDocumentLayout* %tmp95, %struct.QPointF* %tmp3 )
+ to label %cleanup185 unwind label %cleanup187
+cleanup185: ; preds = %invcont181
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %font )
+ to label %cleanup190 unwind label %cleanup192
+cleanup187: ; preds = %invcont181, %invcont179, %invcont177
+ %val187 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN5QFontD1Ev( %struct.QFont* %font )
+ to label %cleanup192 unwind label %cleanup192
+cleanup190: ; preds = %cleanup185
+ invoke void @_ZN16QTextFrameFormatD1Ev( %struct.QTextBlockFormat* %fmt )
+ to label %cond_next194 unwind label %cleanup329
+cleanup192: ; preds = %cleanup187, %cleanup187, %cleanup185, %finally170, %cleanup173, %cleanup173, %cleanup171, %invcont141, %invcont124, %invcont122, %invcont120, %invcont118, %invcont117, %invcont114, %invcont111
+ %val192 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ invoke void @_ZN16QTextFrameFormatD1Ev( %struct.QTextBlockFormat* %fmt )
+ to label %cleanup329 unwind label %cleanup329
+cond_next194: ; preds = %cleanup190, %invcont83
+ %clonedDoc.1 = phi %struct.QAbstractTextDocumentLayout* [ null, %invcont83 ], [ %tmp95, %cleanup190 ] ; <%struct.QAbstractTextDocumentLayout*> [#uses=3]
+ %doc.1 = phi %struct.QAbstractTextDocumentLayout* [ %this, %invcont83 ], [ %tmp95, %cleanup190 ] ; <%struct.QAbstractTextDocumentLayout*> [#uses=2]
+ %tmp197 = invoke i1 @_ZNK8QPrinter13collateCopiesEv( %struct.QPrinter* %printer )
+ to label %invcont196 unwind label %cleanup329 ; <i1> [#uses=1]
+invcont196: ; preds = %cond_next194
+ br i1 %tmp197, label %cond_true200, label %cond_false204
+cond_true200: ; preds = %invcont196
+ %tmp2000 = load double* %foo
+ store double %tmp2000, double* %bar
+ %tmp203 = invoke i32 @_ZNK8QPrinter9numCopiesEv( %struct.QPrinter* %printer )
+ to label %cond_next208 unwind label %cleanup329 ; <i32> [#uses=1]
+cond_false204: ; preds = %invcont196
+ %tmp2001 = load double* %foo
+ store double %tmp2001, double* %bar
+ %tmp207 = invoke i32 @_ZNK8QPrinter9numCopiesEv( %struct.QPrinter* %printer )
+ to label %cond_next208 unwind label %cleanup329 ; <i32> [#uses=1]
+cond_next208: ; preds = %invcont206, %invcont202
+ %pageCopies.0 = phi i32 [ %tmp203, %cond_true200 ], [ 1, %cond_false204 ] ; <i32> [#uses=2]
+ %docCopies.0 = phi i32 [ 1, %cond_true200 ], [ %tmp207, %cond_false204 ] ; <i32> [#uses=2]
+ %tmp211 = invoke i32 @_ZNK8QPrinter8fromPageEv( %struct.QPrinter* %printer )
+ to label %invcont210 unwind label %cleanup329 ; <i32> [#uses=3]
+invcont210: ; preds = %cond_next208
+ %tmp214 = invoke i32 @_ZNK8QPrinter6toPageEv( %struct.QPrinter* %printer )
+ to label %invcont213 unwind label %cleanup329 ; <i32> [#uses=3]
+invcont213: ; preds = %invcont210
+ %tmp216 = icmp eq i32 %tmp211, 0 ; <i1> [#uses=1]
+ br i1 %tmp216, label %cond_true217, label %cond_next225
+cond_true217: ; preds = %invcont213
+ %tmp219 = icmp eq i32 %tmp214, 0 ; <i1> [#uses=1]
+ br i1 %tmp219, label %cond_true220, label %cond_next225
+cond_true220: ; preds = %cond_true217
+ %tmp223 = invoke i32 @_ZNK13QTextDocument9pageCountEv( %struct.QAbstractTextDocumentLayout* %doc.1 )
+ to label %invcont222 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont222: ; preds = %cond_true220
+ br label %cond_next225
+cond_next225: ; preds = %invcont222, %cond_true217, %invcont213
+ %toPage.1 = phi i32 [ %tmp223, %invcont222 ], [ %tmp214, %cond_true217 ], [ %tmp214, %invcont213 ] ; <i32> [#uses=2]
+ %fromPage.1 = phi i32 [ 1, %invcont222 ], [ %tmp211, %cond_true217 ], [ %tmp211, %invcont213 ] ; <i32> [#uses=2]
+ %tmp.page = invoke i32 @_ZNK8QPrinter9pageOrderEv( %struct.QPrinter* %printer )
+ to label %invcont227 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont227: ; preds = %cond_next225
+ %tmp228 = icmp eq i32 %tmp.page, 1 ; <i1> [#uses=1]
+ br i1 %tmp228, label %cond_true230, label %cond_next234
+cond_true230: ; preds = %invcont227
+ br label %cond_next234
+cond_next234: ; preds = %cond_true230, %invcont227
+ %ascending.1 = phi i1 [ false, %cond_true230 ], [ true, %invcont227 ] ; <i1> [#uses=1]
+ %toPage.2 = phi i32 [ %fromPage.1, %cond_true230 ], [ %toPage.1, %invcont227 ] ; <i32> [#uses=1]
+ %fromPage.2 = phi i32 [ %toPage.1, %cond_true230 ], [ %fromPage.1, %invcont227 ] ; <i32> [#uses=1]
+ br label %bb309
+bb237: ; preds = %cond_true313, %cond_next293
+ %iftmp.410.4 = phi i1 [ %iftmp.410.5, %cond_true313 ], [ %iftmp.410.1, %cond_next293 ] ; <i1> [#uses=1]
+ %page.4 = phi i32 [ %fromPage.2, %cond_true313 ], [ %page.3, %cond_next293 ] ; <i32> [#uses=4]
+ br label %bb273
+invcont240: ; preds = %cond_true277
+ %tmp242 = icmp eq i32 %tmp241, 2 ; <i1> [#uses=1]
+ br i1 %tmp242, label %bb252, label %cond_next244
+cond_next244: ; preds = %invcont240
+ %tmp247 = invoke i32 @_ZNK8QPrinter12printerStateEv( %struct.QPrinter* %printer )
+ to label %invcont246 unwind label %cleanup329 ; <i32> [#uses=1]
+invcont246: ; preds = %cond_next244
+ %tmp248 = icmp eq i32 %tmp247, 3 ; <i1> [#uses=1]
+ br i1 %tmp248, label %bb252, label %bb253
+bb252: ; preds = %invcont246, %invcont240
+ br label %bb254
+bb253: ; preds = %invcont246
+ br label %bb254
+bb254: ; preds = %bb253, %bb252
+ %iftmp.410.0 = phi i1 [ true, %bb252 ], [ false, %bb253 ] ; <i1> [#uses=2]
+ br i1 %iftmp.410.0, label %UserCanceled, label %cond_next258
+cond_next258: ; preds = %bb254
+ invoke fastcc void @_Z9printPageiP8QPainterPK13QTextDocumentRK6QRectFRK7QPointF( i32 %page.4, %struct.QPainter* %p, %struct.QAbstractTextDocumentLayout* %doc.1, %struct.QRectF* %body, %struct.QPointF* %pageNumberPos )
+ to label %invcont261 unwind label %cleanup329
+invcont261: ; preds = %cond_next258
+ %tmp263 = add i32 %pageCopies.0, -1 ; <i32> [#uses=1]
+ %tmp265 = icmp sgt i32 %tmp263, %j.4 ; <i1> [#uses=1]
+ br i1 %tmp265, label %cond_true266, label %cond_next270
+cond_true266: ; preds = %invcont261
+ %tmp269 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %cond_next270 unwind label %cleanup329 ; <i1> [#uses=0]
+cond_next270: ; preds = %cond_true266, %invcont261
+ %tmp272 = add i32 %j.4, 1 ; <i32> [#uses=1]
+ br label %bb273
+bb273: ; preds = %cond_next270, %bb237
+ %iftmp.410.1 = phi i1 [ %iftmp.410.4, %bb237 ], [ %iftmp.410.0, %cond_next270 ] ; <i1> [#uses=2]
+ %j.4 = phi i32 [ 0, %bb237 ], [ %tmp272, %cond_next270 ] ; <i32> [#uses=3]
+ %tmp276 = icmp slt i32 %j.4, %pageCopies.0 ; <i1> [#uses=1]
+ br i1 %tmp276, label %cond_true277, label %bb280
+cond_true277: ; preds = %bb273
+ %tmp241 = invoke i32 @_ZNK8QPrinter12printerStateEv( %struct.QPrinter* %printer )
+ to label %invcont240 unwind label %cleanup329 ; <i32> [#uses=1]
+bb280: ; preds = %bb273
+ %tmp283 = icmp eq i32 %page.4, %toPage.2 ; <i1> [#uses=1]
+ br i1 %tmp283, label %bb297, label %cond_next285
+cond_next285: ; preds = %bb280
+ br i1 %ascending.1, label %cond_true287, label %cond_false290
+cond_true287: ; preds = %cond_next285
+ %tmp289 = add i32 %page.4, 1 ; <i32> [#uses=1]
+ br label %cond_next293
+cond_false290: ; preds = %cond_next285
+ %tmp292 = add i32 %page.4, -1 ; <i32> [#uses=1]
+ br label %cond_next293
+cond_next293: ; preds = %cond_false290, %cond_true287
+ %page.3 = phi i32 [ %tmp289, %cond_true287 ], [ %tmp292, %cond_false290 ] ; <i32> [#uses=1]
+ %tmp296 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %bb237 unwind label %cleanup329 ; <i1> [#uses=0]
+bb297: ; preds = %bb280
+ %tmp299 = add i32 %docCopies.0, -1 ; <i32> [#uses=1]
+ %tmp301 = icmp sgt i32 %tmp299, %i.1 ; <i1> [#uses=1]
+ br i1 %tmp301, label %cond_true302, label %cond_next306
+cond_true302: ; preds = %bb297
+ %tmp305 = invoke i1 @_ZN8QPrinter7newPageEv( %struct.QPrinter* %printer )
+ to label %cond_next306 unwind label %cleanup329 ; <i1> [#uses=0]
+cond_next306: ; preds = %cond_true302, %bb297
+ %tmp308 = add i32 %i.1, 1 ; <i32> [#uses=1]
+ br label %bb309
+bb309: ; preds = %cond_next306, %cond_next234
+ %iftmp.410.5 = phi i1 [ undef, %cond_next234 ], [ %iftmp.410.1, %cond_next306 ] ; <i1> [#uses=1]
+ %i.1 = phi i32 [ 0, %cond_next234 ], [ %tmp308, %cond_next306 ] ; <i32> [#uses=3]
+ %tmp312 = icmp slt i32 %i.1, %docCopies.0 ; <i1> [#uses=1]
+ br i1 %tmp312, label %cond_true313, label %UserCanceled
+cond_true313: ; preds = %bb309
+ br label %bb237
+UserCanceled: ; preds = %bb309, %bb254
+ %tmp318 = icmp eq %struct.QAbstractTextDocumentLayout* %clonedDoc.1, null ; <i1> [#uses=1]
+ br i1 %tmp318, label %cleanup327, label %cond_true319
+cond_true319: ; preds = %UserCanceled
+ %tmp.upgrd.23 = getelementptr %struct.QAbstractTextDocumentLayout* %clonedDoc.1, i32 0, i32 0, i32 0 ; <i32 (...)***> [#uses=1]
+ %tmp.upgrd.24 = load i32 (...)*** %tmp.upgrd.23 ; <i32 (...)**> [#uses=1]
+ %tmp322 = getelementptr i32 (...)** %tmp.upgrd.24, i32 4 ; <i32 (...)**> [#uses=1]
+ %tmp.upgrd.25 = load i32 (...)** %tmp322 ; <i32 (...)*> [#uses=1]
+ %tmp.upgrd.26 = bitcast i32 (...)* %tmp.upgrd.25 to void (%struct.QAbstractTextDocumentLayout*)* ; <void (%struct.QAbstractTextDocumentLayout*)*> [#uses=1]
+ invoke void %tmp.upgrd.26( %struct.QAbstractTextDocumentLayout* %clonedDoc.1 )
+ to label %cleanup327 unwind label %cleanup329
+cleanup327: ; preds = %cond_true319, %UserCanceled
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ ret void
+cleanup328: ; preds = %invcont
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ ret void
+cleanup329: ; preds = %cond_true319, %cond_true302, %cond_next293, %cond_true277, %cond_true266, %cond_next258, %cond_next244, %cond_next225, %cond_true220, %invcont210, %cond_next208, %cond_false204, %cond_true200, %cond_next194, %cleanup192, %cleanup192, %cleanup190, %invcont106, %invcont104, %invcont103, %invcont100, %invcont98, %invcont94, %cond_false, %invcont83, %invcont79, %invcont57, %invcont51, %invcont45, %cond_next42, %invcont37, %cond_true35, %invcont29, %invcont25, %cond_true24, %cond_next, %entry
+ %val329 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+ cleanup
+ call void @_ZN8QPainterD1Ev( %struct.QPainter* %p )
+ resume { i8*, i32 } %val329
+}
+
+declare void @_ZN6QSizeFC1Edd(%struct.QPointF*, double, double)
+
+declare i1 @_ZNK6QSizeF7isValidEv(%struct.QPointF*)
+
+declare double @_ZNK6QSizeF5widthEv(%struct.QPointF*)
+
+declare double @_ZNK6QSizeF6heightEv(%struct.QPointF*)
+
+declare double* @_ZN6QSizeF6rwidthEv(%struct.QPointF*)
+
+declare double* @_ZN6QSizeF7rheightEv(%struct.QPointF*)
+
+declare %struct.QTextDocumentPrivate* @_ZNK13QTextDocument6d_funcEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN7QPointFC1Ev(%struct.QPointF*)
+
+declare void @_ZN7QPointFC1Edd(%struct.QPointF*, double, double)
+
+declare void @_ZN16QTextFrameFormat9setMarginEd(%struct.QTextBlockFormat*, double)
+
+declare void @_ZN6QRectFC1Edddd(%struct.QRectF*, double, double, double, double)
+
+declare void @_ZN6QRectFC1ERK7QPointFRK6QSizeF(%struct.QRectF*, %struct.QPointF*, %struct.QPointF*)
+
+declare double @_ZNK6QRectF5widthEv(%struct.QRectF*)
+
+declare double @_ZNK6QRectF6heightEv(%struct.QRectF*)
+
+declare void @_ZNK6QRectF4sizeEv(%struct.QPointF*, %struct.QRectF*)
+
+declare void @_ZN16QTextFrameFormatD1Ev(%struct.QTextBlockFormat*)
+
+declare void @_ZNK10QTextFrame11frameFormatEv(%struct.QTextBlockFormat*, %struct.QTextBlockGroup*)
+
+declare void @_ZN10QTextFrame14setFrameFormatERK16QTextFrameFormat(%struct.QTextBlockGroup*, %struct.QTextBlockFormat*)
+
+declare i32 @_ZNK12QPaintDevice5widthEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice6heightEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice11logicalDpiXEv(%struct.QPaintDevice*)
+
+declare i32 @_ZNK12QPaintDevice11logicalDpiYEv(%struct.QPaintDevice*)
+
+declare %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument5cloneEP7QObject(%struct.QAbstractTextDocumentLayout*, %struct.QObject*)
+
+declare void @_ZN5QFontD1Ev(%struct.QFont*)
+
+declare %struct.QAbstractTextDocumentLayout* @_ZNK13QTextDocument14documentLayoutEv(%struct.QAbstractTextDocumentLayout*)
+
+declare %struct.QTextBlockGroup* @_ZNK13QTextDocument9rootFrameEv(%struct.QAbstractTextDocumentLayout*)
+
+declare i32 @_ZNK13QTextDocument9pageCountEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZNK13QTextDocument11defaultFontEv(%struct.QFont*, %struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN13QTextDocument14setDefaultFontERK5QFont(%struct.QAbstractTextDocumentLayout*, %struct.QFont*)
+
+declare void @_ZN13QTextDocument11setPageSizeERK6QSizeF(%struct.QAbstractTextDocumentLayout*, %struct.QPointF*)
+
+declare void @_Z9printPageiP8QPainterPK13QTextDocumentRK6QRectFRK7QPointF(i32, %struct.QPainter*, %struct.QAbstractTextDocumentLayout*, %struct.QRectF*, %struct.QPointF*)
+
+declare void @_ZN12QFontMetricsD1Ev(%struct.QFontMetrics*)
+
+declare void @_ZN8QPainterC1EP12QPaintDevice(%struct.QPainter*, %struct.QPaintDevice*)
+
+declare i1 @_ZNK8QPainter8isActiveEv(%struct.QPainter*)
+
+declare i32 @_Z13qt_defaultDpiv()
+
+declare %struct.QPaintDevice* @_ZNK27QAbstractTextDocumentLayout11paintDeviceEv(%struct.QAbstractTextDocumentLayout*)
+
+declare void @_ZN8QPainter5scaleEdd(%struct.QPainter*, double, double)
+
+declare %struct.QPaintDevice* @_ZNK8QPainter6deviceEv(%struct.QPainter*)
+
+declare void @_ZN27QAbstractTextDocumentLayout14setPaintDeviceEP12QPaintDevice(%struct.QAbstractTextDocumentLayout*, %struct.QPaintDevice*)
+
+declare void @_ZN12QFontMetricsC1ERK5QFontP12QPaintDevice(%struct.QFontMetrics*, %struct.QFont*, %struct.QPaintDevice*)
+
+declare i32 @_ZNK12QFontMetrics6ascentEv(%struct.QFontMetrics*)
+
+declare void @_ZN5QFont12setPointSizeEi(%struct.QFont*, i32)
+
+declare i1 @_ZNK8QPrinter13collateCopiesEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter9numCopiesEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter8fromPageEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter6toPageEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter9pageOrderEv(%struct.QPrinter*)
+
+declare i32 @_ZNK8QPrinter12printerStateEv(%struct.QPrinter*)
+
+declare i1 @_ZN8QPrinter7newPageEv(%struct.QPrinter*)
+
+declare void @_ZN8QPainterD1Ev(%struct.QPainter*)
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2010-03-30-InvokeCrash.ll b/src/LLVM/test/Transforms/SimplifyCFG/2010-03-30-InvokeCrash.ll
new file mode 100644
index 0000000..7bffa1a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2010-03-30-InvokeCrash.ll
@@ -0,0 +1,22 @@
+; RUN: opt %s -simplifycfg -disable-output
+; END.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @bar(i32)
+
+define void @foo() {
+entry:
+ invoke void @bar(i32 undef)
+ to label %r unwind label %u
+
+r: ; preds = %entry
+ ret void
+
+u: ; preds = %entry
+ %val = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %val
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll b/src/LLVM/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll
new file mode 100644
index 0000000..ebacf2f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2010-10-24-OnlyUnwindInEntry.ll
@@ -0,0 +1,6 @@
+; RUN: opt %s -simplifycfg -disable-output
+; PR8445
+
+define void @test() {
+ unwind
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2011-03-08-UnreachableUse.ll b/src/LLVM/test/Transforms/SimplifyCFG/2011-03-08-UnreachableUse.ll
new file mode 100644
index 0000000..329774e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2011-03-08-UnreachableUse.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; PR9420
+
+; Note that the crash in PR9420 test is sensitive to the ordering of
+; the transformations done by SimplifyCFG, so this test is likely to rot
+; quickly.
+
+define noalias i8* @func_29() nounwind {
+; CHECK: entry:
+; CHECK-NEXT: unreachable
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc38, %entry
+ %p_34.addr.0 = phi i16 [ 1, %entry ], [ %conv40, %for.inc38 ]
+ br label %for.cond1
+
+for.cond1: ; preds = %for.inc29, %for.cond
+ %p_32.addr.0 = phi i1 [ true, %for.cond ], [ true, %for.inc29 ]
+ br i1 %p_32.addr.0, label %for.body8, label %for.inc38
+
+for.body8: ; preds = %for.cond1
+ unreachable
+
+for.inc29: ; preds = %for.cond17
+ br label %for.cond1
+
+for.inc38: ; preds = %for.end32
+ %conv40 = add i16 %p_34.addr.0, 1
+ br label %for.cond
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/2011-09-05-TrivialLPad.ll b/src/LLVM/test/Transforms/SimplifyCFG/2011-09-05-TrivialLPad.ll
new file mode 100644
index 0000000..7558419
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/2011-09-05-TrivialLPad.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+; CHECK-NOT: invoke
+; CHECK-NOT: landingpad
+
+declare void @bar()
+
+define i32 @foo() {
+entry:
+ invoke void @bar()
+ to label %return unwind label %lpad
+
+return:
+ ret i32 0
+
+lpad:
+ %lp = landingpad { i8*, i32 } personality i32 (i32, i64, i8*, i8*)* @__gxx_personality_v0
+ cleanup
+ resume { i8*, i32 } %lp
+}
+
+declare i32 @__gxx_personality_v0(i32, i64, i8*, i8*)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/BrUnwind.ll b/src/LLVM/test/Transforms/SimplifyCFG/BrUnwind.ll
new file mode 100644
index 0000000..e83da81
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/BrUnwind.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {br label}
+
+define void @test(i1 %C) {
+ br i1 %C, label %A, label %B
+A: ; preds = %0
+ call void @test( i1 %C )
+ br label %X
+B: ; preds = %0
+ call void @test( i1 %C )
+ br label %X
+X: ; preds = %B, %A
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/DeadSetCC.ll b/src/LLVM/test/Transforms/SimplifyCFG/DeadSetCC.ll
new file mode 100644
index 0000000..7f57ced
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/DeadSetCC.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {icmp eq}
+
+; Check that simplifycfg deletes a dead 'seteq' instruction when it
+; folds a conditional branch into a switch instruction.
+
+declare void @foo()
+
+declare void @bar()
+
+define void @testcfg(i32 %V) {
+ %C = icmp eq i32 %V, 18 ; <i1> [#uses=1]
+ %D = icmp eq i32 %V, 180 ; <i1> [#uses=1]
+ %E = or i1 %C, %D ; <i1> [#uses=1]
+ br i1 %E, label %L1, label %Sw
+Sw: ; preds = %0
+ switch i32 %V, label %L1 [
+ i32 15, label %L2
+ i32 16, label %L2
+ ]
+L1: ; preds = %Sw, %0
+ call void @foo( )
+ ret void
+L2: ; preds = %Sw, %Sw
+ call void @bar( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/EqualPHIEdgeBlockMerge.ll b/src/LLVM/test/Transforms/SimplifyCFG/EqualPHIEdgeBlockMerge.ll
new file mode 100644
index 0000000..c8aff1f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/EqualPHIEdgeBlockMerge.ll
@@ -0,0 +1,18 @@
+; Test merging of blocks with phi nodes.
+;
+; RUN: opt < %s -simplifycfg -S | not grep N:
+;
+
+define i32 @test(i1 %a) {
+Q:
+ br i1 %a, label %N, label %M
+N: ; preds = %Q
+ br label %M
+M: ; preds = %N, %Q
+ ; It's ok to merge N and M because the incoming values for W are the
+ ; same for both cases...
+ %W = phi i32 [ 2, %N ], [ 2, %Q ] ; <i32> [#uses=1]
+ %R = add i32 %W, 1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll b/src/LLVM/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
new file mode 100644
index 0000000..1b70c06
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep " switch"
+; PR10131
+
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+define i32 @t(i32 %m) nounwind readnone {
+entry:
+ switch i32 %m, label %sw.bb4 [
+ i32 0, label %sw.bb0
+ i32 1, label %sw.bb1
+ i32 2, label %sw.bb2
+ i32 3, label %sw.bb3
+ ]
+
+sw.bb0: ; preds = %entry
+ br label %return
+
+sw.bb1: ; preds = %entry
+ br label %return
+
+sw.bb2: ; preds = %entry
+ br label %return
+
+sw.bb3: ; preds = %entry
+ br label %return
+
+sw.bb4: ; preds = %entry
+ br label %return
+
+return: ; preds = %entry, %sw.bb4, %sw.bb3, %sw.bb2, %sw.bb1
+ %retval.0 = phi i32 [ 4, %sw.bb4 ], [ 3, %sw.bb3 ], [ 2, %sw.bb2 ], [ 1, %sw.bb1 ], [ 0, %sw.bb0 ]
+ ret i32 %retval.0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/HoistCode.ll b/src/LLVM/test/Transforms/SimplifyCFG/HoistCode.ll
new file mode 100644
index 0000000..771dd00
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/HoistCode.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define void @foo(i1 %C, i32* %P) {
+ br i1 %C, label %T, label %F
+T: ; preds = %0
+ store i32 7, i32* %P
+ ret void
+F: ; preds = %0
+ store i32 7, i32* %P
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/MagicPointer.ll b/src/LLVM/test/Transforms/SimplifyCFG/MagicPointer.ll
new file mode 100644
index 0000000..93b9a27
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/MagicPointer.ll
@@ -0,0 +1,75 @@
+; Test that simplifycfg can create switch instructions from constant pointers.
+;
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+; CHECK: switch i64 %magicptr
+; CHECK: i64 0, label
+; CHECK: i64 1, label
+; CHECK: i64 2, label
+; CHECK: i64 3, label
+; CHECK: i64 4, label
+; CHECK: }
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-apple-darwin10.0.0"
+
+@.str = private constant [5 x i8] c"null\00" ; <[5 x i8]*> [#uses=2]
+@.str1 = private constant [4 x i8] c"one\00" ; <[4 x i8]*> [#uses=2]
+@.str2 = private constant [4 x i8] c"two\00" ; <[4 x i8]*> [#uses=2]
+@.str3 = private constant [5 x i8] c"four\00" ; <[5 x i8]*> [#uses=2]
+
+define void @f(i8* %x) nounwind ssp {
+entry:
+ %tobool = icmp eq i8* %x, null ; <i1> [#uses=1]
+ br i1 %tobool, label %if.then, label %if.else
+
+if.then: ; preds = %entry
+ %call = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
+ br label %if.end21
+
+if.else: ; preds = %entry
+ %cmp = icmp eq i8* %x, inttoptr (i64 1 to i8*) ; <i1> [#uses=1]
+ br i1 %cmp, label %if.then2, label %if.else4
+
+if.then2: ; preds = %if.else
+ %call3 = call i32 @puts(i8* getelementptr inbounds ([4 x i8]* @.str1, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
+ br label %if.end20
+
+if.else4: ; preds = %if.else
+ %cmp6 = icmp eq i8* %x, inttoptr (i64 2 to i8*) ; <i1> [#uses=1]
+ br i1 %cmp6, label %if.then9, label %lor.lhs.false
+
+lor.lhs.false: ; preds = %if.else4
+ %cmp8 = icmp eq i8* %x, inttoptr (i64 3 to i8*) ; <i1> [#uses=1]
+ br i1 %cmp8, label %if.then9, label %if.else11
+
+if.then9: ; preds = %lor.lhs.false, %if.else4
+ %call10 = call i32 @puts(i8* getelementptr inbounds ([4 x i8]* @.str2, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
+ br label %if.end19
+
+if.else11: ; preds = %lor.lhs.false
+ %cmp13 = icmp eq i8* %x, inttoptr (i64 4 to i8*) ; <i1> [#uses=1]
+ br i1 %cmp13, label %if.then14, label %if.else16
+
+if.then14: ; preds = %if.else11
+ %call15 = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str3, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
+ br label %if.end
+
+if.else16: ; preds = %if.else11
+ %call18 = call i32 @puts(i8* %x) nounwind ; <i32> [#uses=0]
+ br label %if.end
+
+if.end: ; preds = %if.else16, %if.then14
+ br label %if.end19
+
+if.end19: ; preds = %if.end, %if.then9
+ br label %if.end20
+
+if.end20: ; preds = %if.end19, %if.then2
+ br label %if.end21
+
+if.end21: ; preds = %if.end20, %if.then
+ ret void
+}
+
+declare i32 @puts(i8*)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PR9946.ll b/src/LLVM/test/Transforms/SimplifyCFG/PR9946.ll
new file mode 100644
index 0000000..4a61b84
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PR9946.ll
@@ -0,0 +1,18 @@
+; RUN: opt %s -simplifycfg -disable-output
+
+@foo = external constant i32
+
+define i32 @f() {
+entry:
+ br i1 icmp eq (i64 and (i64 ptrtoint (i32* @foo to i64), i64 15), i64 0), label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %storemerge = phi i32 [ 1, %if.end ], [ 0, %if.then ]
+ ret i32 %storemerge
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge.ll
new file mode 100644
index 0000000..ab16c72
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge.ll
@@ -0,0 +1,26 @@
+; Test merging of blocks that only have PHI nodes in them
+;
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+;
+
+define i32 @test(i1 %a, i1 %b) {
+; CHECK: br i1 %a
+ br i1 %a, label %M, label %O
+; CHECK: O:
+O: ; preds = %0
+; CHECK: select i1 %b, i32 0, i32 1
+; CHECK-NOT: phi
+ br i1 %b, label %N, label %Q
+Q: ; preds = %O
+ br label %N
+N: ; preds = %Q, %O
+ ; This block should be foldable into M
+ %Wp = phi i32 [ 0, %O ], [ 1, %Q ] ; <i32> [#uses=1]
+ br label %M
+M: ; preds = %N, %0
+; CHECK: %W = phi i32
+ %W = phi i32 [ %Wp, %N ], [ 2, %0 ] ; <i32> [#uses=1]
+ %R = add i32 %W, 1 ; <i32> [#uses=1]
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge2.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge2.ll
new file mode 100644
index 0000000..1202f2b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiBlockMerge2.ll
@@ -0,0 +1,27 @@
+; Test merging of blocks that only have PHI nodes in them. This tests the case
+; where the mergedinto block doesn't have any PHI nodes, and is in fact
+; dominated by the block-to-be-eliminated
+;
+; RUN: opt < %s -simplifycfg -S | not grep N:
+;
+
+declare i1 @foo()
+
+define i32 @test(i1 %a, i1 %b) {
+ %c = call i1 @foo()
+ br i1 %c, label %N, label %P
+P:
+ %d = call i1 @foo()
+ br i1 %d, label %N, label %Q
+Q:
+ br label %N
+N:
+ %W = phi i32 [0, %0], [1, %Q], [2, %P]
+ ; This block should be foldable into M
+ br label %M
+
+M:
+ %R = add i32 %W, 1
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate.ll
new file mode 100644
index 0000000..4b4e609
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate.ll
@@ -0,0 +1,27 @@
+; Test a bunch of cases where the cfg simplification code should
+; be able to fold PHI nodes into computation in common cases. Folding the PHI
+; nodes away allows the branches to be eliminated, performing a simple form of
+; 'if conversion'.
+
+; RUN: opt < %s -simplifycfg -S > %t.xform
+; RUN: not grep phi %t.xform
+; RUN: grep ret %t.xform
+
+declare void @use(i1)
+
+declare void @use.upgrd.1(i32)
+
+
+define void @test(i1 %c, i32 %V, i32 %V2) {
+; <label>:0
+ br i1 %c, label %T, label %F
+T: ; preds = %0
+ br label %F
+F: ; preds = %T, %0
+ %B1 = phi i1 [ true, %0 ], [ false, %T ] ; <i1> [#uses=1]
+ %I6 = phi i32 [ %V, %0 ], [ 0, %T ] ; <i32> [#uses=1]
+ call void @use( i1 %B1 )
+ call void @use.upgrd.1( i32 %I6 )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate2.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate2.ll
new file mode 100644
index 0000000..976d857
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate2.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define i32 @test(i1 %C, i32 %V1, i32 %V2, i16 %V3) {
+entry:
+ br i1 %C, label %then, label %else
+then: ; preds = %entry
+ %V4 = or i32 %V2, %V1 ; <i32> [#uses=1]
+ br label %Cont
+else: ; preds = %entry
+ %V5 = sext i16 %V3 to i32 ; <i32> [#uses=1]
+ br label %Cont
+Cont: ; preds = %then, %else
+ %V6 = phi i32 [ %V5, %else ], [ %V4, %then ] ; <i32> [#uses=0]
+ call i32 @test( i1 false, i32 0, i32 0, i16 0 ) ; <i32>:0 [#uses=0]
+ ret i32 %V1
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate3.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate3.ll
new file mode 100644
index 0000000..3566b87
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiEliminate3.ll
@@ -0,0 +1,34 @@
+; Test merging of blocks containing complex expressions,
+; with various folding thresholds
+;
+; RUN: opt < %s -simplifycfg -S -phi-node-folding-threshold=1 | grep N:
+; RUN: opt < %s -simplifycfg -S -phi-node-folding-threshold=2 | not grep N:
+; RUN: opt < %s -simplifycfg -S -phi-node-folding-threshold=2 | grep M:
+; RUN: opt < %s -simplifycfg -S -phi-node-folding-threshold=7 | not grep M:
+;
+
+define i32 @test(i1 %a, i1 %b, i32 %i, i32 %j, i32 %k) {
+entry:
+ br i1 %a, label %M, label %O
+O:
+ br i1 %b, label %P, label %Q
+P:
+ %iaj = add i32 %i, %j
+ %iajak = add i32 %iaj, %k
+ br label %N
+Q:
+ %ixj = xor i32 %i, %j
+ %ixjxk = xor i32 %ixj, %k
+ br label %N
+N:
+ ; This phi should be foldable if threshold >= 2
+ %Wp = phi i32 [ %iajak, %P ], [ %ixjxk, %Q ]
+ %Wp2 = add i32 %Wp, %Wp
+ br label %M
+M:
+ ; This phi should be foldable if threshold >= 7
+ %W = phi i32 [ %Wp2, %N ], [ 2, %entry ]
+ %R = add i32 %W, 1
+ ret i32 %R
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/PhiNoEliminate.ll b/src/LLVM/test/Transforms/SimplifyCFG/PhiNoEliminate.ll
new file mode 100644
index 0000000..f196ec7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/PhiNoEliminate.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep select
+
+;; The PHI node in this example should not be turned into a select, as we are
+;; not able to ifcvt the entire block. As such, converting to a select just
+;; introduces inefficiency without saving copies.
+
+define i32 @bar(i1 %C) {
+entry:
+ br i1 %C, label %then, label %endif
+then: ; preds = %entry
+ %tmp.3 = call i32 @qux( ) ; <i32> [#uses=0]
+ br label %endif
+endif: ; preds = %then, %entry
+ %R = phi i32 [ 123, %entry ], [ 12312, %then ] ; <i32> [#uses=1]
+ ;; stuff to disable tail duplication
+ call i32 @qux( ) ; <i32>:0 [#uses=0]
+ call i32 @qux( ) ; <i32>:1 [#uses=0]
+ call i32 @qux( ) ; <i32>:2 [#uses=0]
+ call i32 @qux( ) ; <i32>:3 [#uses=0]
+ call i32 @qux( ) ; <i32>:4 [#uses=0]
+ call i32 @qux( ) ; <i32>:5 [#uses=0]
+ call i32 @qux( ) ; <i32>:6 [#uses=0]
+ ret i32 %R
+}
+
+declare i32 @qux()
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/SpeculativeExec.ll b/src/LLVM/test/Transforms/SimplifyCFG/SpeculativeExec.ll
new file mode 100644
index 0000000..5cfc77c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/SpeculativeExec.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -simplifycfg -S | grep select
+; RUN: opt < %s -simplifycfg -S | grep br | count 2
+
+define i32 @t2(i32 %a, i32 %b, i32 %c) nounwind {
+entry:
+ %tmp1 = icmp eq i32 %b, 0
+ br i1 %tmp1, label %bb1, label %bb3
+
+bb1: ; preds = %entry
+ %tmp2 = icmp sgt i32 %c, 1
+ br i1 %tmp2, label %bb2, label %bb3
+
+bb2: ; preds = bb1
+ %tmp3 = add i32 %a, 1
+ br label %bb3
+
+bb3: ; preds = %bb2, %entry
+ %tmp4 = phi i32 [ %b, %entry ], [ %a, %bb1 ], [ %tmp3, %bb2 ]
+ %tmp5 = sub i32 %tmp4, 1
+ ret i32 %tmp5
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll b/src/LLVM/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
new file mode 100644
index 0000000..39e6e83
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
@@ -0,0 +1,33 @@
+; The unify-function-exit-nodes pass often makes basic blocks that just contain
+; a PHI node and a return. Make sure the simplify cfg can straighten out this
+; important case. This is basically the most trivial form of tail-duplication.
+
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {br label}
+
+define i32 @test(i1 %B, i32 %A, i32 %B.upgrd.1) {
+ br i1 %B, label %T, label %F
+T: ; preds = %0
+ br label %ret
+F: ; preds = %0
+ br label %ret
+ret: ; preds = %F, %T
+ %X = phi i32 [ %A, %F ], [ %B.upgrd.1, %T ] ; <i32> [#uses=1]
+ ret i32 %X
+}
+
+
+; Make sure it's willing to move unconditional branches to return instructions
+; as well, even if the return block is shared and the source blocks are
+; non-empty.
+define i32 @test2(i1 %B, i32 %A, i32 %B.upgrd.2) {
+ br i1 %B, label %T, label %F
+T: ; preds = %0
+ call i32 @test( i1 true, i32 5, i32 8 ) ; <i32>:1 [#uses=0]
+ br label %ret
+F: ; preds = %0
+ call i32 @test( i1 true, i32 5, i32 8 ) ; <i32>:2 [#uses=0]
+ br label %ret
+ret: ; preds = %F, %T
+ ret i32 %A
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/UnreachableEliminate.ll b/src/LLVM/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
new file mode 100644
index 0000000..1a88df3
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
@@ -0,0 +1,73 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+define void @test1(i1 %C, i1* %BP) {
+; CHECK: @test1
+; CHECK: entry:
+; CHECK-NEXT: ret void
+entry:
+ br i1 %C, label %T, label %F
+T:
+ store i1 %C, i1* %BP
+ unreachable
+F:
+ ret void
+}
+
+define void @test2() {
+; CHECK: @test2
+; CHECK: entry:
+; CHECK-NEXT: call void @test2()
+; CHECK-NEXT: ret void
+entry:
+ invoke void @test2( )
+ to label %N unwind label %U
+U:
+ unreachable
+N:
+ ret void
+}
+
+define i32 @test3(i32 %v) {
+; CHECK: @test3
+; CHECK: entry:
+; CHECK-NEXT: [[CMP:%[A-Za-z0-9]+]] = icmp eq i32 %v, 2
+; CHECK-NEXT: select i1 [[CMP]], i32 2, i32 1
+; CHECK-NEXT: ret
+entry:
+ switch i32 %v, label %default [
+ i32 1, label %U
+ i32 2, label %T
+ ]
+default:
+ ret i32 1
+U:
+ unreachable
+T:
+ ret i32 2
+}
+
+; PR9450
+define i32 @test4(i32 %v) {
+; CHECK: entry:
+; CHECK-NEXT: switch i32 %v, label %T [
+; CHECK-NEXT: i32 3, label %V
+; CHECK-NEXT: i32 2, label %U
+; CHECK-NEXT: ]
+
+entry:
+ br label %SWITCH
+V:
+ ret i32 7
+SWITCH:
+ switch i32 %v, label %default [
+ i32 1, label %T
+ i32 2, label %U
+ i32 3, label %V
+ ]
+default:
+ unreachable
+U:
+ ret i32 1
+T:
+ ret i32 2
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/basictest.ll b/src/LLVM/test/Transforms/SimplifyCFG/basictest.ll
new file mode 100644
index 0000000..cb4ba5c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/basictest.ll
@@ -0,0 +1,43 @@
+; Test CFG simplify removal of branch instructions.
+;
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+define void @test1() {
+ br label %1
+ ret void
+; CHECK: @test1
+; CHECK-NEXT: ret void
+}
+
+define void @test2() {
+ ret void
+ ret void
+; CHECK: @test2
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+}
+
+define void @test3(i1 %T) {
+ br i1 %T, label %1, label %1
+ ret void
+; CHECK: @test3
+; CHECK-NEXT: ret void
+}
+
+
+; PR5795
+define void @test5(i32 %A) {
+ switch i32 %A, label %return [
+ i32 2, label %1
+ i32 10, label %2
+ ]
+
+ ret void
+
+ ret void
+
+return: ; preds = %entry
+ ret void
+; CHECK: @test5
+; CHECK-NEXT: ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-branch-dbginfo.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-branch-dbginfo.ll
new file mode 100644
index 0000000..761f0d5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-branch-dbginfo.ll
@@ -0,0 +1,70 @@
+; RUN: opt < %s -simplifycfg -S | grep {br i1} | count 1
+
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8* }
+ %llvm.dbg.derivedtype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }* }
+ %llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 }
+ %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }* }
+@llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 393262, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), i1 false, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 393233, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([7 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([5 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([52 x i8]* @.str2, i32 0, i32 0) }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@.str = internal constant [7 x i8] c"cond.c\00", section "llvm.metadata" ; <[7 x i8]*> [#uses=1]
+@.str1 = internal constant [5 x i8] c"/tmp\00", section "llvm.metadata" ; <[5 x i8]*> [#uses=1]
+@.str2 = internal constant [52 x i8] c"4.2.1 (Based on Apple Inc. build 5555) (LLVM build)\00", section "llvm.metadata" ; <[52 x i8]*> [#uses=1]
+@.str3 = internal constant [4 x i8] c"foo\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type { i32 393252, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), { }* null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@.str4 = internal constant [4 x i8] c"int\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@llvm.dbg.variable = internal constant %llvm.dbg.variable.type { i32 393473, { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*), i8* getelementptr ([2 x i8]* @.str5, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.variable.type*> [#uses=0]
+@.str5 = internal constant [2 x i8] c"x\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.variable6 = internal constant %llvm.dbg.variable.type { i32 393473, { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*), i8* getelementptr ([2 x i8]* @.str7, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 4, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.variable.type*> [#uses=0]
+@.str7 = internal constant [2 x i8] c"y\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.derivedtype = internal constant %llvm.dbg.derivedtype.type { i32 393238, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([6 x i8]* @.str8, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 1, i64 0, i64 0, i64 0, i32 0, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype9 to { }*) }, section "llvm.metadata" ; <%llvm.dbg.derivedtype.type*> [#uses=1]
+@.str8 = internal constant [6 x i8] c"uint1\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@llvm.dbg.basictype9 = internal constant %llvm.dbg.basictype.type { i32 393252, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* null, i32 0, i64 8, i64 8, i64 0, i32 0, i32 7 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+
+define i32 @foo(i32 %x1, i1 zeroext %y2) nounwind {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.func.start({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp4 = icmp eq i32 %x1, 0 ; <i1> [#uses=1]
+ br i1 %tmp4, label %bb, label %bb14
+
+bb: ; preds = %entry
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %y2, label %bb14, label %bb10
+
+bb7: ; preds = %bb
+ call void @llvm.dbg.stoppoint(i32 7, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp9 = call i32 @g1(i32 %x1) nounwind ; <i32> [#uses=1]
+ ret i32 %tmp9
+
+bb10: ; preds = %bb
+ call void @llvm.dbg.stoppoint(i32 8, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp12 = add i32 %x1, 1 ; <i32> [#uses=1]
+ %tmp13 = call i32 @g2(i32 %tmp12) nounwind ; <i32> [#uses=1]
+ ret i32 %tmp13
+
+bb14: ; preds = %entry
+ call void @llvm.dbg.stoppoint(i32 10, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp16 = call i32 @g1(i32 %x1) nounwind ; <i32> [#uses=1]
+ call void @llvm.dbg.region.end({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+ ret i32 %tmp16
+}
+
+declare void @llvm.dbg.func.start({ }*) nounwind
+
+declare void @llvm.dbg.declare({ }*, { }*) nounwind
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+declare i32 @g1(i32)
+
+declare i32 @g2(i32)
+
+declare void @llvm.dbg.region.end({ }*) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-merge.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-merge.ll
new file mode 100644
index 0000000..d029416
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-merge.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -simplifycfg -instcombine \
+; RUN: -simplifycfg -S | not grep call
+
+declare void @bar()
+
+define void @test(i32 %X, i32 %Y) {
+entry:
+ %tmp.2 = icmp ne i32 %X, %Y ; <i1> [#uses=1]
+ br i1 %tmp.2, label %shortcirc_next, label %UnifiedReturnBlock
+shortcirc_next: ; preds = %entry
+ %tmp.3 = icmp ne i32 %X, %Y ; <i1> [#uses=1]
+ br i1 %tmp.3, label %UnifiedReturnBlock, label %then
+then: ; preds = %shortcirc_next
+ call void @bar( )
+ ret void
+UnifiedReturnBlock: ; preds = %shortcirc_next, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-prop.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-prop.ll
new file mode 100644
index 0000000..8cc4741
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-cond-prop.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -simplifycfg -S | not grep call
+
+declare void @bar()
+
+define void @test(i32 %X, i32 %Y) {
+entry:
+ %tmp.2 = icmp slt i32 %X, %Y ; <i1> [#uses=2]
+ br i1 %tmp.2, label %shortcirc_next, label %UnifiedReturnBlock
+shortcirc_next: ; preds = %entry
+ br i1 %tmp.2, label %UnifiedReturnBlock, label %then
+then: ; preds = %shortcirc_next
+ call void @bar( )
+ ret void
+UnifiedReturnBlock: ; preds = %shortcirc_next, %entry
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
new file mode 100644
index 0000000..0897c95
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-dbg.ll
@@ -0,0 +1,58 @@
+; RUN: opt -simplifycfg -S %s | FileCheck %s
+
+%0 = type { i32*, i32* }
+
+@0 = external hidden constant [5 x %0], align 4
+
+define void @foo(i32) nounwind ssp {
+Entry:
+ %1 = icmp slt i32 %0, 0, !dbg !5
+ br i1 %1, label %BB5, label %BB1, !dbg !5
+
+BB1: ; preds = %Entry
+ %2 = icmp sgt i32 %0, 4, !dbg !5
+ br i1 %2, label %BB5, label %BB2, !dbg !5
+
+BB2: ; preds = %BB1
+ %3 = shl i32 1, %0, !dbg !5
+ %4 = and i32 %3, 31, !dbg !5
+ %5 = icmp eq i32 %4, 0, !dbg !5
+ br i1 %5, label %BB5, label %BB3, !dbg !5
+
+;CHECK: icmp eq
+;CHECK-NEXT: getelementptr
+;CHECK-NEXT: icmp eq
+
+BB3: ; preds = %BB2
+ %6 = getelementptr inbounds [5 x %0]* @0, i32 0, i32 %0, !dbg !6
+ call void @llvm.dbg.value(metadata !{%0* %6}, i64 0, metadata !7), !dbg !12
+ %7 = icmp eq %0* %6, null, !dbg !13
+ br i1 %7, label %BB5, label %BB4, !dbg !13
+
+BB4: ; preds = %BB3
+ %8 = icmp slt i32 %0, 0, !dbg !5
+ ret void, !dbg !14
+
+BB5: ; preds = %BB3, %BB2, %BB1, %Entry
+ ret void, !dbg !14
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 231, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, void (i32)* @foo, null} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"a.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"a.i", metadata !"/private/tmp", metadata !"clang (trunk 129006)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 131, i32 2, metadata !0, null}
+!6 = metadata !{i32 134, i32 2, metadata !0, null}
+!7 = metadata !{i32 590080, metadata !8, metadata !"bar", metadata !1, i32 232, metadata !9, i32 0} ; [ DW_TAG_auto_variable ]
+!8 = metadata !{i32 589835, metadata !0, i32 231, i32 1, metadata !1, i32 3} ; [ DW_TAG_lexical_block ]
+!9 = metadata !{i32 589839, metadata !2, metadata !"", null, i32 0, i64 32, i64 32, i64 0, i32 0, metadata !10} ; [ DW_TAG_pointer_type ]
+!10 = metadata !{i32 589862, metadata !2, metadata !"", null, i32 0, i64 0, i64 0, i64 0, i32 0, metadata !11} ; [ DW_TAG_const_type ]
+!11 = metadata !{i32 589860, metadata !2, metadata !"unsigned int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ]
+!12 = metadata !{i32 232, i32 40, metadata !8, null}
+!13 = metadata !{i32 234, i32 2, metadata !8, null}
+!14 = metadata !{i32 274, i32 1, metadata !8, null}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-test.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-test.ll
new file mode 100644
index 0000000..0797a58
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold-test.ll
@@ -0,0 +1,17 @@
+; This test ensures that the simplifycfg pass continues to constant fold
+; terminator instructions.
+
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define i32 @test(i32 %A, i32 %B) {
+J:
+ %C = add i32 %A, 12 ; <i32> [#uses=2]
+ br i1 true, label %L, label %K
+L: ; preds = %J
+ %D = add i32 %C, %B ; <i32> [#uses=1]
+ ret i32 %D
+K: ; preds = %J
+ %E = add i32 %C, %B ; <i32> [#uses=1]
+ ret i32 %E
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-fold.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold.ll
new file mode 100644
index 0000000..2c8b6d8
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-fold.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -simplifycfg -S | grep {br i1} | count 1
+
+define void @test(i32* %P, i32* %Q, i1 %A, i1 %B) {
+ br i1 %A, label %a, label %b
+a: ; preds = %0
+ br i1 %B, label %b, label %c
+b: ; preds = %a, %0
+ store i32 123, i32* %P
+ ret void
+c: ; preds = %a
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch-phi-thread.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch-phi-thread.ll
new file mode 100644
index 0000000..24b8466
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch-phi-thread.ll
@@ -0,0 +1,66 @@
+; RUN: opt < %s -simplifycfg -adce -S | \
+; RUN: not grep {call void @f1}
+; END.
+
+declare void @f1()
+
+declare void @f2()
+
+declare void @f3()
+
+declare void @f4()
+
+define i32 @test1(i32 %X, i1 %D) {
+E:
+ %C = icmp eq i32 %X, 0 ; <i1> [#uses=2]
+ br i1 %C, label %T, label %F
+T: ; preds = %A, %E
+ br i1 %C, label %B, label %A
+A: ; preds = %T
+ call void @f1( )
+ br i1 %D, label %T, label %F
+B: ; preds = %T
+ call void @f2( )
+ ret i32 345
+F: ; preds = %A, %E
+ call void @f3( )
+ ret i32 123
+}
+
+define i32 @test2(i32 %X, i1 %D) {
+E:
+ %C = icmp eq i32 %X, 0 ; <i1> [#uses=2]
+ br i1 %C, label %T, label %F
+T: ; preds = %A, %E
+ %P = phi i1 [ true, %E ], [ %C, %A ] ; <i1> [#uses=1]
+ br i1 %P, label %B, label %A
+A: ; preds = %T
+ call void @f1( )
+ br i1 %D, label %T, label %F
+B: ; preds = %T
+ call void @f2( )
+ ret i32 345
+F: ; preds = %A, %E
+ call void @f3( )
+ ret i32 123
+}
+
+define i32 @test3(i32 %X, i1 %D, i32* %AP, i32* %BP) {
+E:
+ %C = icmp eq i32 %X, 0 ; <i1> [#uses=2]
+ br i1 %C, label %T, label %F
+T: ; preds = %A, %E
+ call void @f3( )
+ %XX = load i32* %AP ; <i32> [#uses=1]
+ store i32 %XX, i32* %BP
+ br i1 %C, label %B, label %A
+A: ; preds = %T
+ call void @f1( )
+ br i1 %D, label %T, label %F
+B: ; preds = %T
+ call void @f2( )
+ ret i32 345
+F: ; preds = %A, %E
+ call void @f3( )
+ ret i32 123
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/branch_fold_dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/branch_fold_dbg.ll
new file mode 100644
index 0000000..6a500de
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/branch_fold_dbg.ll
@@ -0,0 +1,122 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+; END.
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata"
+
+@.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+
+define void @main() {
+entry:
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.14.i19 = icmp eq i32 0, 2 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.14.i19, label %endif.1.i20, label %read_min.exit
+endif.1.i20: ; preds = %entry
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.9.i.i = icmp eq i8* null, null ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.9.i.i, label %then.i12.i, label %then.i.i
+then.i.i: ; preds = %endif.1.i20
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+then.i12.i: ; preds = %endif.1.i20
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.9.i4.i = icmp eq i8* null, null ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.9.i4.i, label %endif.2.i33, label %then.i5.i
+then.i5.i: ; preds = %then.i12.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+endif.2.i33: ; preds = %then.i12.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %loopexit.0.i40, label %no_exit.0.i35
+no_exit.0.i35: ; preds = %no_exit.0.i35, %endif.2.i33
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.130.i = icmp slt i32 0, 0 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.130.i, label %loopexit.0.i40.loopexit, label %no_exit.0.i35
+loopexit.0.i40.loopexit: ; preds = %no_exit.0.i35
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %loopexit.0.i40
+loopexit.0.i40: ; preds = %loopexit.0.i40.loopexit, %endif.2.i33
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.341.i = icmp eq i32 0, 0 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.341.i, label %loopentry.1.i, label %read_min.exit
+loopentry.1.i: ; preds = %loopexit.0.i40
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.347.i = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.347.i, label %no_exit.1.i41, label %loopexit.2.i44
+no_exit.1.i41: ; preds = %endif.5.i, %loopentry.1.i
+ %indvar.i42 = phi i32 [ %indvar.next.i, %endif.5.i ], [ 0, %loopentry.1.i ] ; <i32> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.355.i = icmp eq i32 0, 3 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.355.i, label %endif.5.i, label %read_min.exit
+endif.5.i: ; preds = %no_exit.1.i41
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.34773.i = icmp sgt i32 0, 0 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %indvar.next.i = add i32 %indvar.i42, 1 ; <i32> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.34773.i, label %no_exit.1.i41, label %loopexit.1.i.loopexit
+loopexit.1.i.loopexit: ; preds = %endif.5.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+loopexit.2.i44: ; preds = %loopentry.1.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+read_min.exit: ; preds = %no_exit.1.i41, %loopexit.0.i40, %entry
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.23 = icmp eq i32 0, 0 ; <i1> [#uses=1]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 %tmp.23, label %endif.1, label %then.1
+then.1: ; preds = %read_min.exit
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %endif.0.i, label %then.0.i
+then.0.i: ; preds = %then.1
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %endif.1.i, label %then.1.i
+endif.0.i: ; preds = %then.1
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %endif.1.i, label %then.1.i
+then.1.i: ; preds = %endif.0.i, %then.0.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %getfree.exit, label %then.2.i
+endif.1.i: ; preds = %endif.0.i, %then.0.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %getfree.exit, label %then.2.i
+then.2.i: ; preds = %endif.1.i, %then.1.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+getfree.exit: ; preds = %endif.1.i, %then.1.i
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+endif.1: ; preds = %read_min.exit
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.27.i = getelementptr i32* null, i32 0 ; <i32*> [#uses=0]
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %loopexit.0.i15, label %no_exit.0.i14
+no_exit.0.i14: ; preds = %endif.1
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+loopexit.0.i15: ; preds = %endif.1
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %primal_start_artificial.exit, label %no_exit.1.i16
+no_exit.1.i16: ; preds = %no_exit.1.i16, %loopexit.0.i15
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br i1 false, label %primal_start_artificial.exit, label %no_exit.1.i16
+primal_start_artificial.exit: ; preds = %no_exit.1.i16, %loopexit.0.i15
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/dbginfo.ll b/src/LLVM/test/Transforms/SimplifyCFG/dbginfo.ll
new file mode 100644
index 0000000..1a9f20a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/dbginfo.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -simplifycfg -S | not grep "br label"
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+ %llvm.dbg.composite.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }*, { }* }
+ %llvm.dbg.derivedtype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }* }
+ %llvm.dbg.global_variable.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1, { }* }
+ %llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 }
+ %llvm.dbg.subrange.type = type { i32, i64, i64 }
+ %struct.Group = type { %struct.Scene, %struct.Sphere, %"struct.std::list<Scene*,std::allocator<Scene*> >" }
+ %struct.Ray = type { %struct.Vec, %struct.Vec }
+ %struct.Scene = type { i32 (...)** }
+ %struct.Sphere = type { %struct.Scene, %struct.Vec, double }
+ %struct.Vec = type { double, double, double }
+ %struct.__class_type_info_pseudo = type { %struct.__type_info_pseudo }
+ %struct.__false_type = type <{ i8 }>
+ %"struct.__gnu_cxx::new_allocator<Scene*>" = type <{ i8 }>
+ %"struct.__gnu_cxx::new_allocator<std::_List_node<Scene*> >" = type <{ i8 }>
+ %struct.__si_class_type_info_pseudo = type { %struct.__type_info_pseudo, %"struct.std::type_info"* }
+ %struct.__type_info_pseudo = type { i8*, i8* }
+ %"struct.std::Hit" = type { double, %struct.Vec }
+ %"struct.std::_List_base<Scene*,std::allocator<Scene*> >" = type { %"struct.std::_List_base<Scene*,std::allocator<Scene*> >::_List_impl" }
+ %"struct.std::_List_base<Scene*,std::allocator<Scene*> >::_List_impl" = type { %"struct.std::_List_node_base" }
+ %"struct.std::_List_const_iterator<Scene*>" = type { %"struct.std::_List_node_base"* }
+ %"struct.std::_List_iterator<Scene*>" = type { %"struct.std::_List_node_base"* }
+ %"struct.std::_List_node<Scene*>" = type { %"struct.std::_List_node_base", %struct.Scene* }
+ %"struct.std::_List_node_base" = type { %"struct.std::_List_node_base"*, %"struct.std::_List_node_base"* }
+ %"struct.std::allocator<Scene*>" = type <{ i8 }>
+ %"struct.std::allocator<std::_List_node<Scene*> >" = type <{ i8 }>
+ %"struct.std::basic_ios<char,std::char_traits<char> >" = type { %"struct.std::ios_base", %"struct.std::basic_ostream<char,std::char_traits<char> >"*, i8, i8, %"struct.std::basic_streambuf<char,std::char_traits<char> >"*, %"struct.std::ctype<char>"*, %"struct.std::num_get<char,std::istreambuf_iterator<char, std::char_traits<char> > >"*, %"struct.std::num_get<char,std::istreambuf_iterator<char, std::char_traits<char> > >"* }
+ %"struct.std::basic_ostream<char,std::char_traits<char> >" = type { i32 (...)**, %"struct.std::basic_ios<char,std::char_traits<char> >" }
+ %"struct.std::basic_streambuf<char,std::char_traits<char> >" = type { i32 (...)**, i8*, i8*, i8*, i8*, i8*, i8*, %"struct.std::locale" }
+ %"struct.std::ctype<char>" = type { %"struct.std::locale::facet", i32*, i8, i32*, i32*, i32*, i8, [256 x i8], [256 x i8], i8 }
+ %"struct.std::ios_base" = type { i32 (...)**, i32, i32, i32, i32, i32, %"struct.std::ios_base::_Callback_list"*, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, %"struct.std::ios_base::_Words"*, %"struct.std::locale" }
+ %"struct.std::ios_base::Init" = type <{ i8 }>
+ %"struct.std::ios_base::_Callback_list" = type { %"struct.std::ios_base::_Callback_list"*, void (i32, %"struct.std::ios_base"*, i32)*, i32, i32 }
+ %"struct.std::ios_base::_Words" = type { i8*, i32 }
+ %"struct.std::list<Scene*,std::allocator<Scene*> >" = type { %"struct.std::_List_base<Scene*,std::allocator<Scene*> >" }
+ %"struct.std::locale" = type { %"struct.std::locale::_Impl"* }
+ %"struct.std::locale::_Impl" = type { i32, %"struct.std::locale::facet"**, i32, %"struct.std::locale::facet"**, i8** }
+ %"struct.std::locale::facet" = type { i32 (...)**, i32 }
+ %"struct.std::num_get<char,std::istreambuf_iterator<char, std::char_traits<char> > >" = type { %"struct.std::locale::facet" }
+ %"struct.std::num_put<char,std::ostreambuf_iterator<char, std::char_traits<char> > >" = type { %"struct.std::locale::facet" }
+ %"struct.std::numeric_limits<double>" = type <{ i8 }>
+ %"struct.std::type_info" = type { i32 (...)**, i8* }
+@llvm.dbg.subprogram947 = external constant %llvm.dbg.subprogram.type ; <%llvm.dbg.subprogram.type*> [#uses=1]
+
+declare void @llvm.dbg.func.start({ }*) nounwind
+
+declare void @llvm.dbg.region.end({ }*) nounwind
+
+declare void @_ZN9__gnu_cxx13new_allocatorIP5SceneED2Ev(%struct.__false_type*) nounwind
+
+define void @_ZNSaIP5SceneED1Ev(%struct.__false_type* %this) nounwind {
+entry:
+ %this_addr = alloca %struct.__false_type* ; <%struct.__false_type**> [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.func.start({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram947 to { }*))
+ store %struct.__false_type* %this, %struct.__false_type** %this_addr
+ %0 = load %struct.__false_type** %this_addr, align 4 ; <%struct.__false_type*> [#uses=1]
+ call void @_ZN9__gnu_cxx13new_allocatorIP5SceneED2Ev(%struct.__false_type* %0) nounwind
+ br label %bb
+
+bb: ; preds = %entry
+ br label %return
+
+return: ; preds = %bb
+ call void @llvm.dbg.region.end({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram947 to { }*))
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/dce-cond-after-folding-terminator.ll b/src/LLVM/test/Transforms/SimplifyCFG/dce-cond-after-folding-terminator.ll
new file mode 100644
index 0000000..3996efd
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/dce-cond-after-folding-terminator.ll
@@ -0,0 +1,52 @@
+; RUN: opt -S <%s -simplifycfg | FileCheck %s
+
+define void @test_br(i32 %x) {
+entry:
+; CHECK: @test_br
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret void
+ %cmp = icmp eq i32 %x, 10
+ br i1 %cmp, label %if.then, label %if.then
+
+if.then: ; preds = %entry
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ ret void
+}
+
+define void @test_switch(i32 %x) nounwind {
+entry:
+; CHECK: @test_switch
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret void
+ %rem = srem i32 %x, 3
+ switch i32 %rem, label %sw.bb [
+ i32 1, label %sw.bb
+ i32 10, label %sw.bb
+ ]
+
+sw.bb: ; preds = %sw.default, %entry, %entry
+ br label %sw.epilog
+
+sw.epilog: ; preds = %sw.bb
+ ret void
+}
+
+define void @test_indirectbr(i32 %x) {
+entry:
+; CHECK: @test_indirectbr
+; CHECK-NEXT: entry:
+; Ideally this should now check:
+; CHK-NEXT: ret void
+; But that doesn't happen yet. Instead:
+; CHECK-NEXT: br label %L1
+
+ %label = bitcast i8* blockaddress(@test_indirectbr, %L1) to i8*
+ indirectbr i8* %label, [label %L1, label %L2]
+
+L1: ; preds = %entry
+ ret void
+L2: ; preds = %entry
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/dg.exp b/src/LLVM/test/Transforms/SimplifyCFG/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/duplicate-phis.ll b/src/LLVM/test/Transforms/SimplifyCFG/duplicate-phis.ll
new file mode 100644
index 0000000..5129f9f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/duplicate-phis.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instcombine -simplifycfg -S | grep { = phi } | count 1
+
+; instcombine should sort the PHI operands so that simplifycfg can see the
+; duplicate and remove it.
+
+define i32 @foo(i1 %t) {
+entry:
+ call void @bar()
+ br i1 %t, label %true, label %false
+true:
+ call void @bar()
+ br label %false
+false:
+ %a = phi i32 [ 2, %true ], [ 5, %entry ]
+ %b = phi i32 [ 5, %entry ], [ 2, %true ]
+ call void @bar()
+ %c = add i32 %a, %b
+ ret i32 %c
+}
+
+declare void @bar()
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.dbg.ll
new file mode 100644
index 0000000..6fbbb1b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.dbg.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata"
+
+@.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+declare void @bar(i32)
+
+define void @test(i1 %P, i32* %Q) {
+ br i1 %P, label %T, label %F
+T: ; preds = %0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ store i32 1, i32* %Q
+ %A = load i32* %Q ; <i32> [#uses=1]
+ call void @bar( i32 %A )
+ ret void
+F: ; preds = %0
+ store i32 1, i32* %Q
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %B = load i32* %Q ; <i32> [#uses=1]
+ call void @bar( i32 %B )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.ll b/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.ll
new file mode 100644
index 0000000..c12354b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/hoist-common-code.ll
@@ -0,0 +1,18 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+declare void @bar(i32)
+
+define void @test(i1 %P, i32* %Q) {
+ br i1 %P, label %T, label %F
+T: ; preds = %0
+ store i32 1, i32* %Q
+ %A = load i32* %Q ; <i32> [#uses=1]
+ call void @bar( i32 %A )
+ ret void
+F: ; preds = %0
+ store i32 1, i32* %Q
+ %B = load i32* %Q ; <i32> [#uses=1]
+ call void @bar( i32 %B )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll b/src/LLVM/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll
new file mode 100644
index 0000000..03053f0
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll
@@ -0,0 +1,53 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+define i32 @foo(i32 %i) nounwind ssp {
+ call void @llvm.dbg.value(metadata !{i32 %i}, i64 0, metadata !6), !dbg !7
+ call void @llvm.dbg.value(metadata !8, i64 0, metadata !9), !dbg !11
+ %1 = icmp ne i32 %i, 0, !dbg !12
+;CHECK: call i32 (...)* @bar()
+;CHECK-NEXT: llvm.dbg.value
+ br i1 %1, label %2, label %4, !dbg !12
+
+; <label>:2 ; preds = %0
+ %3 = call i32 (...)* @bar(), !dbg !13
+ call void @llvm.dbg.value(metadata !{i32 %3}, i64 0, metadata !9), !dbg !13
+ br label %6, !dbg !15
+
+; <label>:4 ; preds = %0
+ %5 = call i32 (...)* @bar(), !dbg !16
+ call void @llvm.dbg.value(metadata !{i32 %5}, i64 0, metadata !9), !dbg !16
+ br label %6, !dbg !18
+
+; <label>:6 ; preds = %4, %2
+ %k.0 = phi i32 [ %3, %2 ], [ %5, %4 ]
+ ret i32 %k.0, !dbg !19
+}
+
+declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
+
+declare i32 @bar(...)
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 2, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 256, i1 false, i32 (i32)* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"b.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"b.c", metadata !"/private/tmp", metadata !"clang", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{metadata !5}
+!5 = metadata !{i32 589860, metadata !2, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!6 = metadata !{i32 590081, metadata !0, metadata !"i", metadata !1, i32 16777218, metadata !5, i32 0} ; [ DW_TAG_arg_variable ]
+!7 = metadata !{i32 2, i32 13, metadata !0, null}
+!8 = metadata !{i32 0}
+!9 = metadata !{i32 590080, metadata !10, metadata !"k", metadata !1, i32 3, metadata !5, i32 0} ; [ DW_TAG_auto_variable ]
+!10 = metadata !{i32 589835, metadata !0, i32 2, i32 16, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
+!11 = metadata !{i32 3, i32 12, metadata !10, null}
+!12 = metadata !{i32 4, i32 3, metadata !10, null}
+!13 = metadata !{i32 5, i32 5, metadata !14, null}
+!14 = metadata !{i32 589835, metadata !10, i32 4, i32 10, metadata !1, i32 1} ; [ DW_TAG_lexical_block ]
+!15 = metadata !{i32 6, i32 3, metadata !14, null}
+!16 = metadata !{i32 7, i32 5, metadata !17, null}
+!17 = metadata !{i32 589835, metadata !10, i32 6, i32 10, metadata !1, i32 2} ; [ DW_TAG_lexical_block ]
+!18 = metadata !{i32 8, i32 3, metadata !17, null}
+!19 = metadata !{i32 9, i32 3, metadata !10, null}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/indirectbr.ll b/src/LLVM/test/Transforms/SimplifyCFG/indirectbr.ll
new file mode 100644
index 0000000..7853e9a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/indirectbr.ll
@@ -0,0 +1,251 @@
+; RUN: opt -S -simplifycfg < %s | FileCheck %s
+
+; SimplifyCFG should eliminate redundant indirectbr edges.
+
+; CHECK: indbrtest0
+; CHECK: indirectbr i8* %t, [label %BB0, label %BB1, label %BB2]
+; CHECK: %x = phi i32 [ 0, %BB0 ], [ 1, %entry ]
+
+declare void @foo()
+declare void @A()
+declare void @B(i32)
+declare void @C()
+
+define void @indbrtest0(i8** %P, i8** %Q) {
+entry:
+ store i8* blockaddress(@indbrtest0, %BB0), i8** %P
+ store i8* blockaddress(@indbrtest0, %BB1), i8** %P
+ store i8* blockaddress(@indbrtest0, %BB2), i8** %P
+ call void @foo()
+ %t = load i8** %Q
+ indirectbr i8* %t, [label %BB0, label %BB1, label %BB2, label %BB0, label %BB1, label %BB2]
+BB0:
+ call void @A()
+ br label %BB1
+BB1:
+ %x = phi i32 [ 0, %BB0 ], [ 1, %entry ], [ 1, %entry ]
+ call void @B(i32 %x)
+ ret void
+BB2:
+ call void @C()
+ ret void
+}
+
+; SimplifyCFG should convert the indirectbr into a directbr. It would be even
+; better if it removed the branch altogether, but simplifycfdg currently misses
+; that because the predecessor is the entry block.
+
+; CHECK: indbrtest1
+; CHECK: br label %BB0
+
+define void @indbrtest1(i8** %P, i8** %Q) {
+entry:
+ store i8* blockaddress(@indbrtest1, %BB0), i8** %P
+ call void @foo()
+ %t = load i8** %Q
+ indirectbr i8* %t, [label %BB0, label %BB0]
+BB0:
+ call void @A()
+ ret void
+}
+
+; SimplifyCFG should notice that BB0 does not have its address taken and
+; remove it from entry's successor list.
+
+; CHECK: indbrtest2
+; CHECK: entry:
+; CHECK-NEXT: unreachable
+
+define void @indbrtest2(i8* %t) {
+entry:
+ indirectbr i8* %t, [label %BB0, label %BB0]
+BB0:
+ ret void
+}
+
+
+; Make sure the blocks in the next few tests aren't trivially removable as
+; successors by taking their addresses.
+
+@anchor = constant [13 x i8*] [
+ i8* blockaddress(@indbrtest3, %L1), i8* blockaddress(@indbrtest3, %L2), i8* blockaddress(@indbrtest3, %L3),
+ i8* blockaddress(@indbrtest4, %L1), i8* blockaddress(@indbrtest4, %L2), i8* blockaddress(@indbrtest4, %L3),
+ i8* blockaddress(@indbrtest5, %L1), i8* blockaddress(@indbrtest5, %L2), i8* blockaddress(@indbrtest5, %L3), i8* blockaddress(@indbrtest5, %L4),
+ i8* blockaddress(@indbrtest6, %L1), i8* blockaddress(@indbrtest6, %L2), i8* blockaddress(@indbrtest6, %L3)
+]
+
+; SimplifyCFG should turn the indirectbr into a conditional branch on the
+; condition of the select.
+
+; CHECK: @indbrtest3
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 %cond, label %L1, label %L2
+; CHECK-NOT: indirectbr
+; CHECK-NOT: br
+; CHECK-NOT: L3:
+define void @indbrtest3(i1 %cond, i8* %address) nounwind {
+entry:
+ %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest3, %L1), i8* blockaddress(@indbrtest3, %L2)
+ indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
+
+L1:
+ call void @A()
+ ret void
+L2:
+ call void @C()
+ ret void
+L3:
+ call void @foo()
+ ret void
+}
+
+; SimplifyCFG should turn the indirectbr into an unconditional branch to the
+; only possible destination.
+; As in @indbrtest1, it should really remove the branch entirely, but it doesn't
+; because it's in the entry block.
+
+; CHECK: @indbrtest4
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %L1
+define void @indbrtest4(i1 %cond) nounwind {
+entry:
+ %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest4, %L1), i8* blockaddress(@indbrtest4, %L1)
+ indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
+
+L1:
+ call void @A()
+ ret void
+L2:
+ call void @C()
+ ret void
+L3:
+ call void @foo()
+ ret void
+}
+
+; SimplifyCFG should turn the indirectbr into an unreachable because neither
+; destination is listed as a successor.
+
+; CHECK: @indbrtest5
+; CHECK-NEXT: entry:
+; CHECK-NEXT: unreachable
+; CHECK-NEXT: }
+define void @indbrtest5(i1 %cond, i8* %anchor) nounwind {
+entry:
+ %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest5, %L1), i8* blockaddress(@indbrtest5, %L2)
+; This needs to have more than one successor for this test, otherwise it gets
+; replaced with an unconditional branch to the single successor.
+ indirectbr i8* %indirect.goto.dest, [label %L3, label %L4]
+
+L1:
+ call void @A()
+ ret void
+L2:
+ call void @C()
+ ret void
+L3:
+ call void @foo()
+ ret void
+L4:
+ call void @foo()
+
+; This keeps blockaddresses not otherwise listed as successors from being zapped
+; before SimplifyCFG even looks at the indirectbr.
+ indirectbr i8* %anchor, [label %L1, label %L2]
+}
+
+; The same as above, except the selected addresses are equal.
+
+; CHECK: @indbrtest6
+; CHECK-NEXT: entry:
+; CHECK-NEXT: unreachable
+; CHECK-NEXT: }
+define void @indbrtest6(i1 %cond, i8* %anchor) nounwind {
+entry:
+ %indirect.goto.dest = select i1 %cond, i8* blockaddress(@indbrtest6, %L1), i8* blockaddress(@indbrtest6, %L1)
+; This needs to have more than one successor for this test, otherwise it gets
+; replaced with an unconditional branch to the single successor.
+ indirectbr i8* %indirect.goto.dest, [label %L2, label %L3]
+
+L1:
+ call void @A()
+ ret void
+L2:
+ call void @C()
+ ret void
+L3:
+ call void @foo()
+
+; This keeps blockaddresses not otherwise listed as successors from being zapped
+; before SimplifyCFG even looks at the indirectbr.
+ indirectbr i8* %anchor, [label %L1, label %L2]
+}
+
+; PR10072
+
+@xblkx.bbs = internal unnamed_addr constant [9 x i8*] [i8* blockaddress(@indbrtest7, %xblkx.begin), i8* blockaddress(@indbrtest7, %xblkx.begin3), i8* blockaddress(@indbrtest7, %xblkx.begin4), i8* blockaddress(@indbrtest7, %xblkx.begin5), i8* blockaddress(@indbrtest7, %xblkx.begin6), i8* blockaddress(@indbrtest7, %xblkx.begin7), i8* blockaddress(@indbrtest7, %xblkx.begin8), i8* blockaddress(@indbrtest7, %xblkx.begin9), i8* blockaddress(@indbrtest7, %xblkx.end)]
+
+define void @indbrtest7() {
+escape-string.top:
+ %xval202x = call i32 @xfunc5x()
+ br label %xlab5x
+
+xlab8x: ; preds = %xlab5x
+ %xvaluex = call i32 @xselectorx()
+ %xblkx.x = getelementptr [9 x i8*]* @xblkx.bbs, i32 0, i32 %xvaluex
+ %xblkx.load = load i8** %xblkx.x
+ indirectbr i8* %xblkx.load, [label %xblkx.begin, label %xblkx.begin3, label %xblkx.begin4, label %xblkx.begin5, label %xblkx.begin6, label %xblkx.begin7, label %xblkx.begin8, label %xblkx.begin9, label %xblkx.end]
+
+xblkx.begin:
+ br label %xblkx.end
+
+xblkx.begin3:
+ br label %xblkx.end
+
+xblkx.begin4:
+ br label %xblkx.end
+
+xblkx.begin5:
+ br label %xblkx.end
+
+xblkx.begin6:
+ br label %xblkx.end
+
+xblkx.begin7:
+ br label %xblkx.end
+
+xblkx.begin8:
+ br label %xblkx.end
+
+xblkx.begin9:
+ br label %xblkx.end
+
+xblkx.end:
+ %yes.0 = phi i1 [ false, %xblkx.begin ], [ true, %xlab8x ], [ false, %xblkx.begin9 ], [ false, %xblkx.begin8 ], [ false, %xblkx.begin7 ], [ false, %xblkx.begin6 ], [ false, %xblkx.begin5 ], [ true, %xblkx.begin4 ], [ false, %xblkx.begin3 ]
+ br i1 %yes.0, label %v2j, label %xlab17x
+
+v2j:
+; CHECK: %xunusedx = call i32 @xactionx()
+ %xunusedx = call i32 @xactionx()
+ br label %xlab4x
+
+xlab17x:
+ br label %xlab4x
+
+xlab4x:
+ %incr19 = add i32 %xval704x.0, 1
+ br label %xlab5x
+
+xlab5x:
+ %xval704x.0 = phi i32 [ 0, %escape-string.top ], [ %incr19, %xlab4x ]
+ %xval10x = icmp ult i32 %xval704x.0, %xval202x
+ br i1 %xval10x, label %xlab8x, label %xlab9x
+
+xlab9x:
+ ret void
+}
+
+declare i32 @xfunc5x()
+declare i8 @xfunc7x()
+declare i32 @xselectorx()
+declare i32 @xactionx()
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/invoke_unwind.ll b/src/LLVM/test/Transforms/SimplifyCFG/invoke_unwind.ll
new file mode 100644
index 0000000..17a01e9
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/invoke_unwind.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+declare void @bar()
+
+; This testcase checks to see if the simplifycfg pass is converting invoke
+; instructions to call instructions if the handler just rethrows the exception.
+define i32 @test1() {
+; CHECK: @test1
+; CHECK-NEXT: call void @bar()
+; CHECK-NEXT: ret i32 0
+ invoke void @bar( )
+ to label %1 unwind label %Rethrow
+ ret i32 0
+Rethrow:
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ catch i8* null
+ resume { i8*, i32 } %exn
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/iterative-simplify.ll b/src/LLVM/test/Transforms/SimplifyCFG/iterative-simplify.ll
new file mode 100644
index 0000000..a397411
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/iterative-simplify.ll
@@ -0,0 +1,100 @@
+; RUN: opt < %s -simplifycfg -S | not grep bb17
+; PR1786
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=1]
+ %i = alloca i32, align 4 ; <i32*> [#uses=7]
+ %z = alloca i32, align 4 ; <i32*> [#uses=4]
+ %z16 = alloca i32, align 4 ; <i32*> [#uses=4]
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ store i32 0, i32* %i
+ %toBool = icmp ne i8 1, 0 ; <i1> [#uses=1]
+ br i1 %toBool, label %cond_true, label %cond_false
+
+cond_true: ; preds = %entry
+ store i32 0, i32* %z
+ br label %bb
+
+bb: ; preds = %cond_next, %cond_true
+ %tmp = load i32* %z ; <i32> [#uses=1]
+ %tmp1 = sub i32 %tmp, 16384 ; <i32> [#uses=1]
+ store i32 %tmp1, i32* %z
+ %tmp2 = load i32* %i ; <i32> [#uses=1]
+ %tmp3 = add i32 %tmp2, 1 ; <i32> [#uses=1]
+ store i32 %tmp3, i32* %i
+ %tmp4 = load i32* %i ; <i32> [#uses=1]
+ %tmp5 = icmp sgt i32 %tmp4, 262144 ; <i1> [#uses=1]
+ %tmp56 = zext i1 %tmp5 to i8 ; <i8> [#uses=1]
+ %toBool7 = icmp ne i8 %tmp56, 0 ; <i1> [#uses=1]
+ br i1 %toBool7, label %cond_true8, label %cond_next
+
+cond_true8: ; preds = %bb
+ call void @abort( )
+ unreachable
+
+cond_next: ; preds = %bb
+ %tmp9 = load i32* %z ; <i32> [#uses=1]
+ %tmp10 = icmp ne i32 %tmp9, 0 ; <i1> [#uses=1]
+ %tmp1011 = zext i1 %tmp10 to i8 ; <i8> [#uses=1]
+ %toBool12 = icmp ne i8 %tmp1011, 0 ; <i1> [#uses=1]
+ br i1 %toBool12, label %bb, label %bb13
+
+bb13: ; preds = %cond_next
+ call void @exit( i32 0 )
+ unreachable
+
+cond_false: ; preds = %entry
+ %toBool14 = icmp ne i8 1, 0 ; <i1> [#uses=1]
+ br i1 %toBool14, label %cond_true15, label %cond_false33
+
+cond_true15: ; preds = %cond_false
+ store i32 0, i32* %z16
+ br label %bb17
+
+bb17: ; preds = %cond_next27, %cond_true15
+ %tmp18 = load i32* %z16 ; <i32> [#uses=1]
+ %tmp19 = sub i32 %tmp18, 16384 ; <i32> [#uses=1]
+ store i32 %tmp19, i32* %z16
+ %tmp20 = load i32* %i ; <i32> [#uses=1]
+ %tmp21 = add i32 %tmp20, 1 ; <i32> [#uses=1]
+ store i32 %tmp21, i32* %i
+ %tmp22 = load i32* %i ; <i32> [#uses=1]
+ %tmp23 = icmp sgt i32 %tmp22, 262144 ; <i1> [#uses=1]
+ %tmp2324 = zext i1 %tmp23 to i8 ; <i8> [#uses=1]
+ %toBool25 = icmp ne i8 %tmp2324, 0 ; <i1> [#uses=1]
+ br i1 %toBool25, label %cond_true26, label %cond_next27
+
+cond_true26: ; preds = %bb17
+ call void @abort( )
+ unreachable
+
+cond_next27: ; preds = %bb17
+ %tmp28 = load i32* %z16 ; <i32> [#uses=1]
+ %tmp29 = icmp ne i32 %tmp28, 0 ; <i1> [#uses=1]
+ %tmp2930 = zext i1 %tmp29 to i8 ; <i8> [#uses=1]
+ %toBool31 = icmp ne i8 %tmp2930, 0 ; <i1> [#uses=1]
+ br i1 %toBool31, label %bb17, label %bb32
+
+bb32: ; preds = %cond_next27
+ call void @exit( i32 0 )
+ unreachable
+
+cond_false33: ; preds = %cond_false
+ call void @exit( i32 0 )
+ unreachable
+
+cond_next34: ; No predecessors!
+ br label %cond_next35
+
+cond_next35: ; preds = %cond_next34
+ br label %return
+
+return: ; preds = %cond_next35
+ %retval36 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %retval36
+}
+
+declare void @abort()
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/lifetime.ll b/src/LLVM/test/Transforms/SimplifyCFG/lifetime.ll
new file mode 100644
index 0000000..b794221
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/lifetime.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+; Test that a lifetime intrinsic doesn't prevent us from simplifying this.
+
+; CHECK: foo
+; CHECK: entry:
+; CHECK-NOT: bb0:
+; CHECK-NOT: bb1:
+; CHECK: ret
+define void @foo(i1 %x) {
+entry:
+ %a = alloca i8
+ call void @llvm.lifetime.start(i64 -1, i8* %a) nounwind
+ br i1 %x, label %bb0, label %bb1
+
+bb0:
+ call void @llvm.lifetime.end(i64 -1, i8* %a) nounwind
+ br label %bb1
+
+bb1:
+ call void @f()
+ ret void
+}
+
+declare void @f()
+
+declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
+
+declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/noreturn-call.ll b/src/LLVM/test/Transforms/SimplifyCFG/noreturn-call.ll
new file mode 100644
index 0000000..b454778
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/noreturn-call.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -simplifycfg -S | grep unreachable
+; PR1796
+
+declare void @Finisher(i32) noreturn
+
+define void @YYY(i32) {
+ tail call void @Finisher(i32 %0) noreturn
+ tail call void @Finisher(i32 %0) noreturn
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll b/src/LLVM/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll
new file mode 100644
index 0000000..65d888e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/phi-undef-loadstore.ll
@@ -0,0 +1,87 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+declare void @bar() nounwind
+
+define i32 @test1(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
+entry:
+ %tobool = icmp eq i32 %b, 0
+ br i1 %tobool, label %if.else, label %if.then
+
+if.then: ; preds = %entry
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.else: ; preds = %entry
+ %tobool3 = icmp eq i32 %d, 0
+ br i1 %tobool3, label %if.end7, label %if.then4
+
+if.then4: ; preds = %if.else
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.end7: ; preds = %if.else, %if.then4, %if.then
+ %x.0 = phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
+ %tmp9 = load i32* %x.0
+ ret i32 %tmp9
+
+; CHECK: @test1
+; CHECK: if.else:
+; CHECK: br label %if.end7
+
+; CHECK: phi i32* [ %a, %if.then ], [ %c, %if.else ]
+}
+
+define i32 @test2(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
+entry:
+ %tobool = icmp eq i32 %b, 0
+ br i1 %tobool, label %if.else, label %if.then
+
+if.then: ; preds = %entry
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.else: ; preds = %entry
+ %tobool3 = icmp eq i32 %d, 0
+ br i1 %tobool3, label %if.end7, label %if.then4
+
+if.then4: ; preds = %if.else
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.end7: ; preds = %if.else, %if.then4, %if.then
+ %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
+ %tmp9 = load i32* %x.0
+ ret i32 %tmp9
+; CHECK: @test2
+; CHECK: if.else:
+; CHECK: unreachable
+
+; CHECK-NOT: phi
+}
+
+define i32 @test3(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
+entry:
+ %tobool = icmp eq i32 %b, 0
+ br i1 %tobool, label %if.else, label %if.then
+
+if.then: ; preds = %entry
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.else: ; preds = %entry
+ %tobool3 = icmp eq i32 %d, 0
+ br i1 %tobool3, label %if.end7, label %if.then4
+
+if.then4: ; preds = %if.else
+ tail call void @bar() nounwind
+ br label %if.end7
+
+if.end7: ; preds = %if.else, %if.then4, %if.then
+ %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
+ tail call void @bar() nounwind
+ %tmp9 = load i32* %x.0
+ ret i32 %tmp9
+; CHECK: @test3
+; CHECK: if.end7:
+; CHECK: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/return-merge.ll b/src/LLVM/test/Transforms/SimplifyCFG/return-merge.ll
new file mode 100644
index 0000000..637938d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/return-merge.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define i32 @test1(i1 %C) {
+entry:
+ br i1 %C, label %T, label %F
+T: ; preds = %entry
+ ret i32 1
+F: ; preds = %entry
+ ret i32 0
+}
+
+define void @test2(i1 %C) {
+ br i1 %C, label %T, label %F
+T: ; preds = %0
+ ret void
+F: ; preds = %0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/select-gep.ll b/src/LLVM/test/Transforms/SimplifyCFG/select-gep.ll
new file mode 100644
index 0000000..009f05e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/select-gep.ll
@@ -0,0 +1,40 @@
+; RUN: opt -S -simplifycfg %s | FileCheck %s
+
+define i8* @test1(i8* %x, i64 %y) nounwind {
+entry:
+ %tmp1 = load i8* %x, align 1
+ %cmp = icmp eq i8 %tmp1, 47
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+ %incdec.ptr = getelementptr inbounds i8* %x, i64 %y
+ br label %if.end
+
+if.end:
+ %x.addr = phi i8* [ %incdec.ptr, %if.then ], [ %x, %entry ]
+ ret i8* %x.addr
+
+; CHECK: @test1
+; CHECK-NOT: select
+; CHECK: ret i8* %x.addr
+}
+
+%ST = type { i8, i8 }
+
+define i8* @test2(%ST* %x, i8* %y) nounwind {
+entry:
+ %cmp = icmp eq %ST* %x, null
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+ %incdec.ptr = getelementptr %ST* %x, i32 0, i32 1
+ br label %if.end
+
+if.end:
+ %x.addr = phi i8* [ %incdec.ptr, %if.then ], [ %y, %entry ]
+ ret i8* %x.addr
+
+; CHECK: @test2
+; CHECK: %x.addr = select i1 %cmp, i8* %incdec.ptr, i8* %y
+; CHECK: ret i8* %x.addr
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/speculate-with-offset.ll b/src/LLVM/test/Transforms/SimplifyCFG/speculate-with-offset.ll
new file mode 100644
index 0000000..a737d56
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/speculate-with-offset.ll
@@ -0,0 +1,94 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+; This load is safe to speculate, as it's from a safe offset
+; within an alloca.
+
+; CHECK: @yes
+; CHECK-NOT: br
+
+define void @yes(i1 %c) nounwind {
+entry:
+ %a = alloca [4 x i64*], align 8
+ %__a.addr = getelementptr [4 x i64*]* %a, i64 0, i64 3
+ call void @frob(i64** %__a.addr)
+ br i1 %c, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ %tmp5 = load i64** %__a.addr, align 8
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %storemerge = phi i64* [ undef, %if.then ], [ %tmp5, %if.end ]
+ ret void
+}
+
+; CHECK: @no0
+; CHECK: br i1 %c
+
+define void @no0(i1 %c) nounwind {
+entry:
+ %a = alloca [4 x i64*], align 8
+ %__a.addr = getelementptr [4 x i64*]* %a, i64 0, i64 4
+ call void @frob(i64** %__a.addr)
+ br i1 %c, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ %tmp5 = load i64** %__a.addr, align 8
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %storemerge = phi i64* [ undef, %if.then ], [ %tmp5, %if.end ]
+ ret void
+}
+
+; CHECK: @no1
+; CHECK: br i1 %c
+
+define void @no1(i1 %c, i64 %n) nounwind {
+entry:
+ %a = alloca [4 x i64*], align 8
+ %__a.addr = getelementptr [4 x i64*]* %a, i64 0, i64 %n
+ call void @frob(i64** %__a.addr)
+ br i1 %c, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ %tmp5 = load i64** %__a.addr, align 8
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %storemerge = phi i64* [ undef, %if.then ], [ %tmp5, %if.end ]
+ ret void
+}
+
+; CHECK: @no2
+; CHECK: br i1 %c
+
+define void @no2(i1 %c, i64 %n) nounwind {
+entry:
+ %a = alloca [4 x i64*], align 8
+ %__a.addr = getelementptr [4 x i64*]* %a, i64 1, i64 0
+ call void @frob(i64** %__a.addr)
+ br i1 %c, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ %tmp5 = load i64** %__a.addr, align 8
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %storemerge = phi i64* [ undef, %if.then ], [ %tmp5, %if.end ]
+ ret void
+}
+
+declare void @frob(i64** nocapture %p)
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch-masked-bits.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch-masked-bits.ll
new file mode 100644
index 0000000..fc83ec2
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch-masked-bits.ll
@@ -0,0 +1,38 @@
+; RUN: opt -S -simplifycfg < %s | FileCheck %s
+
+define i32 @test1(i32 %x) nounwind {
+ %i = shl i32 %x, 1
+ switch i32 %i, label %a [
+ i32 21, label %b
+ i32 24, label %c
+ ]
+
+a:
+ ret i32 0
+b:
+ ret i32 3
+c:
+ ret i32 5
+; CHECK: @test1
+; CHECK: %cond = icmp eq i32 %i, 24
+; CHECK: %merge = select i1 %cond, i32 5, i32 0
+; CHECK: ret i32 %merge
+}
+
+
+define i32 @test2(i32 %x) nounwind {
+ %i = shl i32 %x, 1
+ switch i32 %i, label %a [
+ i32 21, label %b
+ i32 23, label %c
+ ]
+
+a:
+ ret i32 0
+b:
+ ret i32 3
+c:
+ ret i32 5
+; CHECK: @test2
+; CHECK: ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch-on-const-select.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch-on-const-select.ll
new file mode 100644
index 0000000..5494a65
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch-on-const-select.ll
@@ -0,0 +1,138 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+; Test basic folding to a conditional branch.
+define i32 @foo(i64 %x, i64 %y) nounwind {
+; CHECK: @foo
+entry:
+ %eq = icmp eq i64 %x, %y
+ br i1 %eq, label %b, label %switch
+switch:
+ %lt = icmp slt i64 %x, %y
+; CHECK: br i1 %lt, label %a, label %b
+ %qux = select i1 %lt, i32 0, i32 2
+ switch i32 %qux, label %bees [
+ i32 0, label %a
+ i32 1, label %b
+ i32 2, label %b
+ ]
+a:
+ tail call void @bees.a() nounwind
+ ret i32 1
+; CHECK: b:
+; CHECK-NEXT: %retval = phi i32 [ 0, %switch ], [ 2, %entry ]
+b:
+ %retval = phi i32 [0, %switch], [0, %switch], [2, %entry]
+ tail call void @bees.b() nounwind
+ ret i32 %retval
+; CHECK-NOT: bees:
+bees:
+ tail call void @llvm.trap() nounwind
+ unreachable
+}
+
+; Test basic folding to an unconditional branch.
+define i32 @bar(i64 %x, i64 %y) nounwind {
+; CHECK: @bar
+entry:
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call void @bees.a() nounwind
+; CHECK-NEXT: ret i32 0
+ %lt = icmp slt i64 %x, %y
+ %qux = select i1 %lt, i32 0, i32 2
+ switch i32 %qux, label %bees [
+ i32 0, label %a
+ i32 1, label %b
+ i32 2, label %a
+ ]
+a:
+ %retval = phi i32 [0, %entry], [0, %entry], [1, %b]
+ tail call void @bees.a() nounwind
+ ret i32 0
+b:
+ tail call void @bees.b() nounwind
+ br label %a
+bees:
+ tail call void @llvm.trap() nounwind
+ unreachable
+}
+
+; Test the edge case where both values from the select are the default case.
+define void @bazz(i64 %x, i64 %y) nounwind {
+; CHECK: @bazz
+entry:
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call void @bees.b() nounwind
+; CHECK-NEXT: ret void
+ %lt = icmp slt i64 %x, %y
+ %qux = select i1 %lt, i32 10, i32 12
+ switch i32 %qux, label %b [
+ i32 0, label %a
+ i32 1, label %bees
+ i32 2, label %bees
+ ]
+a:
+ tail call void @bees.a() nounwind
+ ret void
+b:
+ tail call void @bees.b() nounwind
+ ret void
+bees:
+ tail call void @llvm.trap()
+ unreachable
+}
+
+; Test the edge case where both values from the select are equal.
+define void @quux(i64 %x, i64 %y) nounwind {
+; CHECK: @quux
+entry:
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call void @bees.a() nounwind
+; CHECK-NEXT: ret void
+ %lt = icmp slt i64 %x, %y
+ %qux = select i1 %lt, i32 0, i32 0
+ switch i32 %qux, label %b [
+ i32 0, label %a
+ i32 1, label %bees
+ i32 2, label %bees
+ ]
+a:
+ tail call void @bees.a() nounwind
+ ret void
+b:
+ tail call void @bees.b() nounwind
+ ret void
+bees:
+ tail call void @llvm.trap()
+ unreachable
+}
+
+; A final test, for phi node munging.
+define i32 @xyzzy(i64 %x, i64 %y) {
+; CHECK: @xyzzy
+entry:
+ %eq = icmp eq i64 %x, %y
+ br i1 %eq, label %r, label %cont
+cont:
+; CHECK: %lt = icmp slt i64 %x, %y
+ %lt = icmp slt i64 %x, %y
+; CHECK-NEXT: br i1 %lt, label %a, label %r
+ %qux = select i1 %lt, i32 0, i32 2
+ switch i32 %qux, label %bees [
+ i32 0, label %a
+ i32 1, label %r
+ i32 2, label %r
+ ]
+r:
+ %val = phi i32 [0, %entry], [1, %cont], [1, %cont]
+ ret i32 %val
+a:
+ ret i32 -1
+; CHECK-NOT: bees:
+bees:
+ tail call void @llvm.trap()
+ unreachable
+}
+
+declare void @llvm.trap() nounwind noreturn
+declare void @bees.a() nounwind
+declare void @bees.b() nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch-simplify-crash.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch-simplify-crash.ll
new file mode 100644
index 0000000..3afbfd5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch-simplify-crash.ll
@@ -0,0 +1,108 @@
+; RUN: opt < %s -simplifycfg -disable-output
+
+define void @NewExtractNames() {
+entry:
+ br i1 false, label %endif.0, label %then.0
+then.0: ; preds = %entry
+ br i1 false, label %shortcirc_next.i, label %shortcirc_done.i
+shortcirc_next.i: ; preds = %then.0
+ br label %shortcirc_done.i
+shortcirc_done.i: ; preds = %shortcirc_next.i, %then.0
+ br i1 false, label %then.0.i, label %else.0.i
+then.0.i: ; preds = %shortcirc_done.i
+ br label %NewBase.exit
+else.0.i: ; preds = %shortcirc_done.i
+ br i1 false, label %endif.0.i, label %else.1.i
+else.1.i: ; preds = %else.0.i
+ br i1 false, label %endif.0.i, label %else.2.i
+else.2.i: ; preds = %else.1.i
+ br label %NewBase.exit
+endif.0.i: ; preds = %else.1.i, %else.0.i
+ br label %NewBase.exit
+NewBase.exit: ; preds = %endif.0.i, %else.2.i, %then.0.i
+ br label %endif.0
+endif.0: ; preds = %NewBase.exit, %entry
+ %tmp.32.mask = and i32 0, 31 ; <i32> [#uses=1]
+ switch i32 %tmp.32.mask, label %label.9 [
+ i32 16, label %loopentry.2
+ i32 15, label %loopentry.2
+ i32 14, label %loopentry.2
+ i32 13, label %loopentry.2
+ i32 10, label %loopentry.2
+ i32 20, label %loopentry.1
+ i32 19, label %loopentry.1
+ i32 2, label %loopentry.0
+ i32 0, label %switchexit
+ ]
+loopentry.0: ; preds = %endif.1, %endif.0
+ br i1 false, label %no_exit.0, label %switchexit
+no_exit.0: ; preds = %loopentry.0
+ br i1 false, label %then.1, label %else.1
+then.1: ; preds = %no_exit.0
+ br label %endif.1
+else.1: ; preds = %no_exit.0
+ br i1 false, label %shortcirc_next.0, label %shortcirc_done.0
+shortcirc_next.0: ; preds = %else.1
+ br label %shortcirc_done.0
+shortcirc_done.0: ; preds = %shortcirc_next.0, %else.1
+ br i1 false, label %then.2, label %endif.2
+then.2: ; preds = %shortcirc_done.0
+ br label %endif.2
+endif.2: ; preds = %then.2, %shortcirc_done.0
+ br label %endif.1
+endif.1: ; preds = %endif.2, %then.1
+ br label %loopentry.0
+loopentry.1: ; preds = %endif.3, %endif.0, %endif.0
+ br i1 false, label %no_exit.1, label %switchexit
+no_exit.1: ; preds = %loopentry.1
+ br i1 false, label %then.3, label %else.2
+then.3: ; preds = %no_exit.1
+ br label %endif.3
+else.2: ; preds = %no_exit.1
+ br i1 false, label %shortcirc_next.1, label %shortcirc_done.1
+shortcirc_next.1: ; preds = %else.2
+ br label %shortcirc_done.1
+shortcirc_done.1: ; preds = %shortcirc_next.1, %else.2
+ br i1 false, label %then.4, label %endif.4
+then.4: ; preds = %shortcirc_done.1
+ br label %endif.4
+endif.4: ; preds = %then.4, %shortcirc_done.1
+ br label %endif.3
+endif.3: ; preds = %endif.4, %then.3
+ br label %loopentry.1
+loopentry.2: ; preds = %endif.5, %endif.0, %endif.0, %endif.0, %endif.0, %endif.0
+ %i.3 = phi i32 [ 0, %endif.5 ], [ 0, %endif.0 ], [ 0, %endif.0 ], [ 0, %endif.0 ], [ 0, %endif.0 ], [ 0, %endif.0 ] ; <i32> [#uses=1]
+ %tmp.158 = icmp slt i32 %i.3, 0 ; <i1> [#uses=1]
+ br i1 %tmp.158, label %no_exit.2, label %switchexit
+no_exit.2: ; preds = %loopentry.2
+ br i1 false, label %shortcirc_next.2, label %shortcirc_done.2
+shortcirc_next.2: ; preds = %no_exit.2
+ br label %shortcirc_done.2
+shortcirc_done.2: ; preds = %shortcirc_next.2, %no_exit.2
+ br i1 false, label %then.5, label %endif.5
+then.5: ; preds = %shortcirc_done.2
+ br label %endif.5
+endif.5: ; preds = %then.5, %shortcirc_done.2
+ br label %loopentry.2
+label.9: ; preds = %endif.0
+ br i1 false, label %then.6, label %endif.6
+then.6: ; preds = %label.9
+ br label %endif.6
+endif.6: ; preds = %then.6, %label.9
+ store i32 0, i32* null
+ br label %switchexit
+switchexit: ; preds = %endif.6, %loopentry.2, %loopentry.1, %loopentry.0, %endif.0
+ br i1 false, label %endif.7, label %then.7
+then.7: ; preds = %switchexit
+ br i1 false, label %shortcirc_next.3, label %shortcirc_done.3
+shortcirc_next.3: ; preds = %then.7
+ br label %shortcirc_done.3
+shortcirc_done.3: ; preds = %shortcirc_next.3, %then.7
+ br i1 false, label %then.8, label %endif.8
+then.8: ; preds = %shortcirc_done.3
+ br label %endif.8
+endif.8: ; preds = %then.8, %shortcirc_done.3
+ br label %endif.7
+endif.7: ; preds = %endif.8, %switchexit
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch-to-icmp.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch-to-icmp.ll
new file mode 100644
index 0000000..414f847
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch-to-icmp.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -simplifycfg < %s | FileCheck %s
+
+define zeroext i1 @test1(i32 %x) nounwind readnone ssp noredzone {
+entry:
+ switch i32 %x, label %lor.rhs [
+ i32 2, label %lor.end
+ i32 1, label %lor.end
+ i32 3, label %lor.end
+ ]
+
+lor.rhs:
+ br label %lor.end
+
+lor.end:
+ %0 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ], [ true, %entry ]
+ ret i1 %0
+
+; CHECK: @test1
+; CHECK: %x.off = add i32 %x, -1
+; CHECK: %switch = icmp ult i32 %x.off, 3
+}
+
+define zeroext i1 @test2(i32 %x) nounwind readnone ssp noredzone {
+entry:
+ switch i32 %x, label %lor.rhs [
+ i32 0, label %lor.end
+ i32 1, label %lor.end
+ ]
+
+lor.rhs:
+ br label %lor.end
+
+lor.end:
+ %0 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ]
+ ret i1 %0
+
+; CHECK: @test2
+; CHECK: %switch = icmp ult i32 %x, 2
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch_create.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch_create.ll
new file mode 100644
index 0000000..075a495
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch_create.ll
@@ -0,0 +1,481 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+declare void @foo1()
+
+declare void @foo2()
+
+define void @test1(i32 %V) {
+ %C1 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
+ %C2 = icmp eq i32 %V, 17 ; <i1> [#uses=1]
+ %CN = or i1 %C1, %C2 ; <i1> [#uses=1]
+ br i1 %CN, label %T, label %F
+T: ; preds = %0
+ call void @foo1( )
+ ret void
+F: ; preds = %0
+ call void @foo2( )
+ ret void
+; CHECK: @test1
+; CHECK: switch i32 %V, label %F [
+; CHECK: i32 17, label %T
+; CHECK: i32 4, label %T
+; CHECK: ]
+}
+
+define void @test2(i32 %V) {
+ %C1 = icmp ne i32 %V, 4 ; <i1> [#uses=1]
+ %C2 = icmp ne i32 %V, 17 ; <i1> [#uses=1]
+ %CN = and i1 %C1, %C2 ; <i1> [#uses=1]
+ br i1 %CN, label %T, label %F
+T: ; preds = %0
+ call void @foo1( )
+ ret void
+F: ; preds = %0
+ call void @foo2( )
+ ret void
+; CHECK: @test2
+; CHECK: switch i32 %V, label %T [
+; CHECK: i32 17, label %F
+; CHECK: i32 4, label %F
+; CHECK: ]
+}
+
+define void @test3(i32 %V) {
+ %C1 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
+ br i1 %C1, label %T, label %N
+N: ; preds = %0
+ %C2 = icmp eq i32 %V, 17 ; <i1> [#uses=1]
+ br i1 %C2, label %T, label %F
+T: ; preds = %N, %0
+ call void @foo1( )
+ ret void
+F: ; preds = %N
+ call void @foo2( )
+ ret void
+
+; CHECK: @test3
+; CHECK: switch i32 %V, label %F [
+; CHECK: i32 4, label %T
+; CHECK: i32 17, label %T
+; CHECK: ]
+}
+
+
+
+define i32 @test4(i8 zeroext %c) nounwind ssp noredzone {
+entry:
+ %cmp = icmp eq i8 %c, 62
+ br i1 %cmp, label %lor.end, label %lor.lhs.false
+
+lor.lhs.false: ; preds = %entry
+ %cmp4 = icmp eq i8 %c, 34
+ br i1 %cmp4, label %lor.end, label %lor.rhs
+
+lor.rhs: ; preds = %lor.lhs.false
+ %cmp8 = icmp eq i8 %c, 92
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %lor.lhs.false, %entry
+ %0 = phi i1 [ true, %lor.lhs.false ], [ true, %entry ], [ %cmp8, %lor.rhs ]
+ %lor.ext = zext i1 %0 to i32
+ ret i32 %lor.ext
+
+; CHECK: @test4
+; CHECK: switch i8 %c, label %lor.rhs [
+; CHECK: i8 62, label %lor.end
+; CHECK: i8 34, label %lor.end
+; CHECK: i8 92, label %lor.end
+; CHECK: ]
+}
+
+define i32 @test5(i8 zeroext %c) nounwind ssp noredzone {
+entry:
+ switch i8 %c, label %lor.rhs [
+ i8 62, label %lor.end
+ i8 34, label %lor.end
+ i8 92, label %lor.end
+ ]
+
+lor.rhs: ; preds = %entry
+ %V = icmp eq i8 %c, 92
+ br label %lor.end
+
+lor.end: ; preds = %entry, %entry, %entry, %lor.rhs
+ %0 = phi i1 [ true, %entry ], [ %V, %lor.rhs ], [ true, %entry ], [ true, %entry ]
+ %lor.ext = zext i1 %0 to i32
+ ret i32 %lor.ext
+; CHECK: @test5
+; CHECK: switch i8 %c, label %lor.rhs [
+; CHECK: i8 62, label %lor.end
+; CHECK: i8 34, label %lor.end
+; CHECK: i8 92, label %lor.end
+; CHECK: ]
+}
+
+
+define i1 @test6({ i32, i32 }* %I) {
+entry:
+ %tmp.1.i = getelementptr { i32, i32 }* %I, i64 0, i32 1 ; <i32*> [#uses=1]
+ %tmp.2.i = load i32* %tmp.1.i ; <i32> [#uses=6]
+ %tmp.2 = icmp eq i32 %tmp.2.i, 14 ; <i1> [#uses=1]
+ br i1 %tmp.2, label %shortcirc_done.4, label %shortcirc_next.0
+shortcirc_next.0: ; preds = %entry
+ %tmp.6 = icmp eq i32 %tmp.2.i, 15 ; <i1> [#uses=1]
+ br i1 %tmp.6, label %shortcirc_done.4, label %shortcirc_next.1
+shortcirc_next.1: ; preds = %shortcirc_next.0
+ %tmp.11 = icmp eq i32 %tmp.2.i, 16 ; <i1> [#uses=1]
+ br i1 %tmp.11, label %shortcirc_done.4, label %shortcirc_next.2
+shortcirc_next.2: ; preds = %shortcirc_next.1
+ %tmp.16 = icmp eq i32 %tmp.2.i, 17 ; <i1> [#uses=1]
+ br i1 %tmp.16, label %shortcirc_done.4, label %shortcirc_next.3
+shortcirc_next.3: ; preds = %shortcirc_next.2
+ %tmp.21 = icmp eq i32 %tmp.2.i, 18 ; <i1> [#uses=1]
+ br i1 %tmp.21, label %shortcirc_done.4, label %shortcirc_next.4
+shortcirc_next.4: ; preds = %shortcirc_next.3
+ %tmp.26 = icmp eq i32 %tmp.2.i, 19 ; <i1> [#uses=1]
+ br label %UnifiedReturnBlock
+shortcirc_done.4: ; preds = %shortcirc_next.3, %shortcirc_next.2, %shortcirc_next.1, %shortcirc_next.0, %entry
+ br label %UnifiedReturnBlock
+UnifiedReturnBlock: ; preds = %shortcirc_done.4, %shortcirc_next.4
+ %UnifiedRetVal = phi i1 [ %tmp.26, %shortcirc_next.4 ], [ true, %shortcirc_done.4 ] ; <i1> [#uses=1]
+ ret i1 %UnifiedRetVal
+
+; CHECK: @test6
+; CHECK: %tmp.2.i.off = add i32 %tmp.2.i, -14
+; CHECK: %switch = icmp ult i32 %tmp.2.i.off, 6
+}
+
+define void @test7(i8 zeroext %c, i32 %x) nounwind ssp noredzone {
+entry:
+ %cmp = icmp ult i32 %x, 32
+ %cmp4 = icmp eq i8 %c, 97
+ %or.cond = or i1 %cmp, %cmp4
+ %cmp9 = icmp eq i8 %c, 99
+ %or.cond11 = or i1 %or.cond, %cmp9
+ br i1 %or.cond11, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ tail call void @foo1() nounwind noredzone
+ ret void
+
+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: ]
+}
+
+define i32 @test8(i8 zeroext %c, i32 %x, i1 %C) nounwind ssp noredzone {
+entry:
+ br i1 %C, label %N, label %if.then
+N:
+ %cmp = icmp ult i32 %x, 32
+ %cmp4 = icmp eq i8 %c, 97
+ %or.cond = or i1 %cmp, %cmp4
+ %cmp9 = icmp eq i8 %c, 99
+ %or.cond11 = or i1 %or.cond, %cmp9
+ br i1 %or.cond11, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %A = phi i32 [0, %entry], [42, %N]
+ tail call void @foo1() nounwind noredzone
+ ret i32 %A
+
+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 ]
+}
+
+;; 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
+ br i1 %cmp, label %lor.end, label %lor.lhs.false
+
+lor.lhs.false: ; preds = %entry
+ %cmp4 = icmp eq i8 %c, 46
+ br i1 %cmp4, label %lor.end, label %lor.lhs.false6
+
+lor.lhs.false6: ; preds = %lor.lhs.false
+ %cmp9 = icmp eq i8 %c, 44
+ br i1 %cmp9, label %lor.end, label %lor.lhs.false11
+
+lor.lhs.false11: ; preds = %lor.lhs.false6
+ %cmp14 = icmp eq i8 %c, 58
+ br i1 %cmp14, label %lor.end, label %lor.lhs.false16
+
+lor.lhs.false16: ; preds = %lor.lhs.false11
+ %cmp19 = icmp eq i8 %c, 59
+ br i1 %cmp19, label %lor.end, label %lor.lhs.false21
+
+lor.lhs.false21: ; preds = %lor.lhs.false16
+ %cmp24 = icmp eq i8 %c, 60
+ br i1 %cmp24, label %lor.end, label %lor.lhs.false26
+
+lor.lhs.false26: ; preds = %lor.lhs.false21
+ %cmp29 = icmp eq i8 %c, 62
+ br i1 %cmp29, label %lor.end, label %lor.lhs.false31
+
+lor.lhs.false31: ; preds = %lor.lhs.false26
+ %cmp34 = icmp eq i8 %c, 34
+ br i1 %cmp34, label %lor.end, label %lor.lhs.false36
+
+lor.lhs.false36: ; preds = %lor.lhs.false31
+ %cmp39 = icmp eq i8 %c, 92
+ br i1 %cmp39, label %lor.end, label %lor.rhs
+
+lor.rhs: ; preds = %lor.lhs.false36
+ %cmp43 = icmp eq i8 %c, 39
+ br label %lor.end
+
+lor.end: ; preds = %lor.rhs, %lor.lhs.false36, %lor.lhs.false31, %lor.lhs.false26, %lor.lhs.false21, %lor.lhs.false16, %lor.lhs.false11, %lor.lhs.false6, %lor.lhs.false, %entry
+ %0 = phi i1 [ true, %lor.lhs.false36 ], [ true, %lor.lhs.false31 ], [ true, %lor.lhs.false26 ], [ true, %lor.lhs.false21 ], [ true, %lor.lhs.false16 ], [ true, %lor.lhs.false11 ], [ true, %lor.lhs.false6 ], [ true, %lor.lhs.false ], [ true, %entry ], [ %cmp43, %lor.rhs ]
+ %conv46 = zext i1 %0 to i32
+ ret i32 %conv46
+
+; 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 92, label %lor.end
+; CHECK: i8 62, label %lor.end
+; CHECK: i8 60, label %lor.end
+; CHECK: i8 59, label %lor.end
+; CHECK: i8 58, label %lor.end
+; CHECK: i8 46, label %lor.end
+; CHECK: i8 44, label %lor.end
+; CHECK: i8 34, 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: ]
+}
+
+; PR8780
+define i32 @test11(i32 %bar) nounwind {
+entry:
+ %cmp = icmp eq i32 %bar, 4
+ %cmp2 = icmp eq i32 %bar, 35
+ %or.cond = or i1 %cmp, %cmp2
+ %cmp5 = icmp eq i32 %bar, 53
+ %or.cond1 = or i1 %or.cond, %cmp5
+ %cmp8 = icmp eq i32 %bar, 24
+ %or.cond2 = or i1 %or.cond1, %cmp8
+ %cmp11 = icmp eq i32 %bar, 23
+ %or.cond3 = or i1 %or.cond2, %cmp11
+ %cmp14 = icmp eq i32 %bar, 55
+ %or.cond4 = or i1 %or.cond3, %cmp14
+ %cmp17 = icmp eq i32 %bar, 12
+ %or.cond5 = or i1 %or.cond4, %cmp17
+ %cmp20 = icmp eq i32 %bar, 35
+ %or.cond6 = or i1 %or.cond5, %cmp20
+ br i1 %or.cond6, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %retval.0 = phi i32 [ 1, %if.then ], [ 0, %if.end ]
+ ret i32 %retval.0
+
+; CHECK: @test11
+; CHECK: switch i32 %bar, label %if.end [
+; CHECK: i32 55, label %return
+; CHECK: i32 53, label %return
+; CHECK: i32 35, label %return
+; CHECK: i32 24, label %return
+; CHECK: i32 23, label %return
+; CHECK: i32 12, label %return
+; CHECK: i32 4, label %return
+; CHECK: ]
+}
+
+define void @test12() nounwind {
+entry:
+ br label %bb49.us.us
+
+bb49.us.us:
+ %A = icmp eq i32 undef, undef
+ br i1 %A, label %bb55.us.us, label %malformed
+
+bb48.us.us:
+ %B = icmp ugt i32 undef, undef
+ br i1 %B, label %bb55.us.us, label %bb49.us.us
+
+bb55.us.us:
+ br label %bb48.us.us
+
+malformed:
+ ret void
+; CHECK: @test12
+
+}
+
+; test13 - handle switch formation with ult.
+define void @test13(i32 %x) nounwind ssp noredzone {
+entry:
+ %cmp = icmp ult i32 %x, 2
+ br i1 %cmp, label %if.then, label %lor.lhs.false3
+
+lor.lhs.false3: ; preds = %lor.lhs.false
+ %cmp5 = icmp eq i32 %x, 3
+ br i1 %cmp5, label %if.then, label %lor.lhs.false6
+
+lor.lhs.false6: ; preds = %lor.lhs.false3
+ %cmp8 = icmp eq i32 %x, 4
+ br i1 %cmp8, label %if.then, label %lor.lhs.false9
+
+lor.lhs.false9: ; preds = %lor.lhs.false6
+ %cmp11 = icmp eq i32 %x, 6
+ br i1 %cmp11, label %if.then, label %if.end
+
+if.then: ; preds = %lor.lhs.false9, %lor.lhs.false6, %lor.lhs.false3, %lor.lhs.false, %entry
+ call void @foo1() noredzone
+ br label %if.end
+
+if.end: ; preds = %if.then, %lor.lhs.false9
+ ret void
+; CHECK: @test13
+; CHECK: switch i32 %x, label %if.end [
+; CHECK: i32 6, label %if.then
+; CHECK: i32 4, label %if.then
+; CHECK: i32 3, label %if.then
+; CHECK: i32 1, label %if.then
+; CHECK: i32 0, label %if.then
+; CHECK: ]
+}
+
+; test14 - handle switch formation with ult.
+define void @test14(i32 %x) nounwind ssp noredzone {
+entry:
+ %cmp = icmp ugt i32 %x, 2
+ br i1 %cmp, label %lor.lhs.false3, label %if.then
+
+lor.lhs.false3: ; preds = %lor.lhs.false
+ %cmp5 = icmp ne i32 %x, 3
+ br i1 %cmp5, label %lor.lhs.false6, label %if.then
+
+lor.lhs.false6: ; preds = %lor.lhs.false3
+ %cmp8 = icmp ne i32 %x, 4
+ br i1 %cmp8, label %lor.lhs.false9, label %if.then
+
+lor.lhs.false9: ; preds = %lor.lhs.false6
+ %cmp11 = icmp ne i32 %x, 6
+ br i1 %cmp11, label %if.end, label %if.then
+
+if.then: ; preds = %lor.lhs.false9, %lor.lhs.false6, %lor.lhs.false3, %lor.lhs.false, %entry
+ call void @foo1() noredzone
+ br label %if.end
+
+if.end: ; preds = %if.then, %lor.lhs.false9
+ ret void
+; CHECK: @test14
+; CHECK: switch i32 %x, label %if.end [
+; CHECK: i32 6, label %if.then
+; CHECK: i32 4, label %if.then
+; CHECK: i32 3, label %if.then
+; CHECK: i32 1, label %if.then
+; CHECK: i32 0, label %if.then
+; CHECK: ]
+}
+
+; Don't crash on ginormous ranges.
+define void @test15(i128 %x) nounwind {
+ %cmp = icmp ugt i128 %x, 2
+ br i1 %cmp, label %if.end, label %lor.false
+
+lor.false:
+ %cmp2 = icmp ne i128 %x, 100000000000000000000
+ br i1 %cmp2, label %if.end, label %if.then
+
+if.then:
+ call void @foo1() noredzone
+ br label %if.end
+
+if.end:
+ ret void
+
+; CHECK: @test15
+; CHECK-NOT: switch
+; CHECK: ret void
+}
+
+; PR8675
+; rdar://5134905
+define zeroext i1 @test16(i32 %x) nounwind {
+entry:
+; CHECK: @test16
+; CHECK: %x.off = add i32 %x, -1
+; CHECK: %switch = icmp ult i32 %x.off, 3
+ %cmp.i = icmp eq i32 %x, 1
+ br i1 %cmp.i, label %lor.end, label %lor.lhs.false
+
+lor.lhs.false:
+ %cmp.i2 = icmp eq i32 %x, 2
+ br i1 %cmp.i2, label %lor.end, label %lor.rhs
+
+lor.rhs:
+ %cmp.i1 = icmp eq i32 %x, 3
+ br label %lor.end
+
+lor.end:
+ %0 = phi i1 [ true, %lor.lhs.false ], [ true, %entry ], [ %cmp.i1, %lor.rhs ]
+ ret i1 %0
+}
+
+; Check that we don't turn an icmp into a switch where it's not useful.
+define void @test17(i32 %x, i32 %y) {
+ %cmp = icmp ult i32 %x, 3
+ %switch = icmp ult i32 %y, 2
+ %or.cond775 = or i1 %cmp, %switch
+ br i1 %or.cond775, label %lor.lhs.false8, label %return
+
+lor.lhs.false8:
+ tail call void @foo1()
+ ret void
+
+return:
+ ret void
+
+; CHECK: @test17
+; CHECK-NOT: switch.early.test
+; CHECK-NOT: switch i32
+; CHECK: ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch_formation.dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch_formation.dbg.ll
new file mode 100644
index 0000000..2723ec6
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch_formation.dbg.ll
@@ -0,0 +1,50 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata"
+
+@.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+define i1 @t({ i32, i32 }* %I) {
+; CHECK: @t
+; CHECK: %tmp.2.i.off = add i32 %tmp.2.i, -14
+; CHECK: %switch = icmp ult i32 %tmp.2.i.off, 6
+entry:
+ %tmp.1.i = getelementptr { i32, i32 }* %I, i64 0, i32 1 ; <i32*> [#uses=1]
+ %tmp.2.i = load i32* %tmp.1.i ; <i32> [#uses=6]
+ %tmp.2 = icmp eq i32 %tmp.2.i, 14 ; <i1> [#uses=1]
+ br i1 %tmp.2, label %shortcirc_done.4, label %shortcirc_next.0
+shortcirc_next.0: ; preds = %entry
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.6 = icmp eq i32 %tmp.2.i, 15 ; <i1> [#uses=1]
+ br i1 %tmp.6, label %shortcirc_done.4, label %shortcirc_next.1
+shortcirc_next.1: ; preds = %shortcirc_next.0
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.11 = icmp eq i32 %tmp.2.i, 16 ; <i1> [#uses=1]
+ br i1 %tmp.11, label %shortcirc_done.4, label %shortcirc_next.2
+shortcirc_next.2: ; preds = %shortcirc_next.1
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.16 = icmp eq i32 %tmp.2.i, 17 ; <i1> [#uses=1]
+ br i1 %tmp.16, label %shortcirc_done.4, label %shortcirc_next.3
+shortcirc_next.3: ; preds = %shortcirc_next.2
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.21 = icmp eq i32 %tmp.2.i, 18 ; <i1> [#uses=1]
+ br i1 %tmp.21, label %shortcirc_done.4, label %shortcirc_next.4
+shortcirc_next.4: ; preds = %shortcirc_next.3
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp.26 = icmp eq i32 %tmp.2.i, 19 ; <i1> [#uses=1]
+ br label %UnifiedReturnBlock
+shortcirc_done.4: ; preds = %shortcirc_next.3, %shortcirc_next.2, %shortcirc_next.1, %shortcirc_next.0, %entry
+ br label %UnifiedReturnBlock
+UnifiedReturnBlock: ; preds = %shortcirc_done.4, %shortcirc_next.4
+ %UnifiedRetVal = phi i1 [ %tmp.26, %shortcirc_next.4 ], [ true, %shortcirc_done.4 ] ; <i1> [#uses=1]
+ ret i1 %UnifiedRetVal
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold.ll
new file mode 100644
index 0000000..a53ebe7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold.ll
@@ -0,0 +1,47 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: grep switch | count 1
+
+; Test that a switch going to a switch on the same value can be merged. All
+; three switches in this example can be merged into one big one.
+
+declare void @foo1()
+
+declare void @foo2()
+
+declare void @foo3()
+
+declare void @foo4()
+
+define void @test1(i32 %V) {
+ switch i32 %V, label %F [
+ i32 4, label %T
+ i32 17, label %T
+ i32 5, label %T
+ i32 1234, label %F
+ ]
+T: ; preds = %0, %0, %0
+ switch i32 %V, label %F [
+ i32 4, label %A
+ i32 17, label %B
+ i32 42, label %C
+ ]
+A: ; preds = %T
+ call void @foo1( )
+ ret void
+B: ; preds = %F, %F, %T
+ call void @foo2( )
+ ret void
+C: ; preds = %T
+ call void @foo3( )
+ ret void
+F: ; preds = %F, %T, %0, %0
+ switch i32 %V, label %F [
+ i32 4, label %B
+ i32 18, label %B
+ i32 42, label %D
+ ]
+D: ; preds = %F
+ call void @foo4( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold_dbginfo.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold_dbginfo.ll
new file mode 100644
index 0000000..343e169
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch_switch_fold_dbginfo.ll
@@ -0,0 +1,116 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep " switch"
+
+; ModuleID = '<stdin>'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8*, i32 }
+ %llvm.dbg.composite.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }*, { }*, i32 }
+ %llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 }
+ %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }* }
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@.str = internal constant [10 x i8] c"swithh2.c\00", section "llvm.metadata" ; <[10 x i8]*> [#uses=1]
+@.str1 = internal constant [38 x i8] c"/developer/home2/zsth/test/debug/tmp/\00", section "llvm.metadata" ; <[38 x i8]*> [#uses=1]
+@.str2 = internal constant [52 x i8] c"4.2.1 (Based on Apple Inc. build 5641) (LLVM build)\00", section "llvm.metadata" ; <[52 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([10 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([38 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([52 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null, i32 -1 }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+@.str3 = internal constant [4 x i8] c"int\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type { i32 458788, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 32, i64 32, i64 0, i32 0, i32 5 }, section "llvm.metadata" ; <%llvm.dbg.basictype.type*> [#uses=1]
+@llvm.dbg.array = internal constant [2 x { }*] [{ }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*), { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*)], section "llvm.metadata" ; <[2 x { }*]*> [#uses=1]
+@llvm.dbg.composite = internal constant %llvm.dbg.composite.type { i32 458773, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 0, i64 0, i64 0, i64 0, i32 0, { }* null, { }* bitcast ([2 x { }*]* @llvm.dbg.array to { }*), i32 0 }, section "llvm.metadata" ; <%llvm.dbg.composite.type*> [#uses=1]
+@llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@.str4 = internal constant [4 x i8] c"foo\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 458798, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str4, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 1, { }* bitcast (%llvm.dbg.composite.type* @llvm.dbg.composite to { }*), i1 false, i1 true }, section "llvm.metadata" ; <%llvm.dbg.subprogram.type*> [#uses=1]
+@.str5 = internal constant [2 x i8] c"x\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@llvm.dbg.variable = internal constant %llvm.dbg.variable.type { i32 459009, { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*), i8* getelementptr ([2 x i8]* @.str5, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 1, { }* bitcast (%llvm.dbg.basictype.type* @llvm.dbg.basictype to { }*) }, section "llvm.metadata" ; <%llvm.dbg.variable.type*> [#uses=0]
+
+define i32 @foo(i32 %x) nounwind {
+entry:
+ %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
+ call void @llvm.dbg.func.start({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+ call void @llvm.dbg.stoppoint(i32 2, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ switch i32 %x, label %bb4 [
+ i32 1, label %bb
+ i32 2, label %bb1
+ i32 3, label %bb2
+ i32 4, label %bb3
+ ]
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 2, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb
+
+bb: ; preds = %0, %entry
+ call void @llvm.dbg.stoppoint(i32 3, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 3, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb1
+
+bb1: ; preds = %1, %entry
+ call void @llvm.dbg.stoppoint(i32 4, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 4, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb2
+
+bb2: ; preds = %2, %entry
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb3
+
+bb3: ; preds = %3, %entry
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 6, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb4
+
+bb4: ; preds = %4, %entry
+ call void @llvm.dbg.stoppoint(i32 10, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ switch i32 %x, label %bb7 [
+ i32 5, label %bb5
+ i32 6, label %bb6
+ ]
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 10, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb5
+
+bb5: ; preds = %5, %bb4
+ call void @llvm.dbg.stoppoint(i32 11, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 11, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb6
+
+bb6: ; preds = %6, %bb4
+ call void @llvm.dbg.stoppoint(i32 12, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+ ; No predecessors!
+ call void @llvm.dbg.stoppoint(i32 12, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb7
+
+bb7: ; preds = %7, %bb4
+ call void @llvm.dbg.stoppoint(i32 13, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %bb8
+
+bb8: ; preds = %bb7, %bb6, %bb5, %bb3, %bb2, %bb1, %bb
+ %.0 = phi i32 [ 4, %bb3 ], [ 3, %bb2 ], [ 2, %bb1 ], [ 1, %bb ], [ 6, %bb6 ], [ 5, %bb5 ], [ 0, %bb7 ] ; <i32> [#uses=1]
+ call void @llvm.dbg.stoppoint(i32 13, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ br label %return
+
+return: ; preds = %bb8
+ call void @llvm.dbg.stoppoint(i32 13, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ call void @llvm.dbg.region.end({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+ ret i32 %.0
+}
+
+declare void @llvm.dbg.func.start({ }*) nounwind
+
+declare void @llvm.dbg.declare({ }*, { }*) nounwind
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+declare void @llvm.dbg.region.end({ }*) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/switch_thread.ll b/src/LLVM/test/Transforms/SimplifyCFG/switch_thread.ll
new file mode 100644
index 0000000..5a6537a
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/switch_thread.ll
@@ -0,0 +1,79 @@
+; RUN: opt < %s -simplifycfg -S | \
+; RUN: not grep {call void @DEAD}
+
+; Test that we can thread a simple known condition through switch statements.
+
+declare void @foo1()
+
+declare void @foo2()
+
+declare void @DEAD()
+
+define void @test1(i32 %V) {
+ switch i32 %V, label %A [
+ i32 4, label %T
+ i32 17, label %Done
+ i32 1234, label %A
+ ]
+;; V == 4 if we get here.
+T: ; preds = %0
+ call void @foo1( )
+ ;; This switch is always statically determined.
+ switch i32 %V, label %A2 [
+ i32 4, label %B
+ i32 17, label %C
+ i32 42, label %C
+ ]
+A2: ; preds = %T
+ call void @DEAD( )
+ call void @DEAD( )
+ ;; always true
+ %cond2 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
+ br i1 %cond2, label %Done, label %C
+A: ; preds = %0, %0
+ call void @foo1( )
+ ;; always true
+ %cond = icmp ne i32 %V, 4 ; <i1> [#uses=1]
+ br i1 %cond, label %Done, label %C
+Done: ; preds = %B, %A, %A2, %0
+ ret void
+B: ; preds = %T
+ call void @foo2( )
+ ;; always true
+ %cond3 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
+ br i1 %cond3, label %Done, label %C
+C: ; preds = %B, %A, %A2, %T, %T
+ call void @DEAD( )
+ ret void
+}
+
+define void @test2(i32 %V) {
+ switch i32 %V, label %A [
+ i32 4, label %T
+ i32 17, label %D
+ i32 1234, label %E
+ ]
+;; V != 4, 17, 1234 here.
+A: ; preds = %0
+ call void @foo1( )
+ ;; This switch is always statically determined.
+ switch i32 %V, label %E [
+ i32 4, label %C
+ i32 17, label %C
+ i32 42, label %D
+ ]
+;; unreacahble.
+C: ; preds = %A, %A
+ call void @DEAD( )
+ ret void
+T: ; preds = %0
+ call void @foo1( )
+ call void @foo1( )
+ ret void
+D: ; preds = %A, %0
+ call void @foo1( )
+ ret void
+E: ; preds = %A, %0
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/trap-debugloc.ll b/src/LLVM/test/Transforms/SimplifyCFG/trap-debugloc.ll
new file mode 100644
index 0000000..24540e5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/trap-debugloc.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; Radar 9342286
+; Assign DebugLoc to trap instruction.
+define void @foo() nounwind ssp {
+; CHECK: call void @llvm.trap(), !dbg
+ store i32 42, i32* null, !dbg !5
+ ret void, !dbg !7
+}
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 3, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 0, i1 false, void ()* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"foo.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"foo.c", metadata !"/private/tmp", metadata !"Apple clang version 3.0 (tags/Apple/clang-206.1) (based on LLVM 3.0svn)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 4, i32 2, metadata !6, null}
+!6 = metadata !{i32 589835, metadata !0, i32 3, i32 12, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
+!7 = metadata !{i32 5, i32 1, metadata !6, null}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll b/src/LLVM/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll
new file mode 100644
index 0000000..10d6981
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/trapping-load-unreachable.ll
@@ -0,0 +1,87 @@
+; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; PR2967
+
+target datalayout =
+"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define void @test1(i32 %x) nounwind {
+entry:
+ %0 = icmp eq i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %0, label %bb, label %return
+
+bb: ; preds = %entry
+ %1 = load volatile i32* null
+ unreachable
+
+ br label %return
+return: ; preds = %entry
+ ret void
+; CHECK: @test1
+; CHECK: load volatile
+}
+
+; rdar://7958343
+define void @test2() nounwind {
+entry:
+ store i32 4,i32* null
+ ret void
+
+; CHECK: @test2
+; CHECK: call void @llvm.trap
+; CHECK: unreachable
+}
+
+; PR7369
+define void @test3() nounwind {
+entry:
+ store volatile i32 4, i32* null
+ ret void
+
+; CHECK: @test3
+; CHECK: store volatile i32 4, i32* null
+; CHECK: ret
+}
+
+; Check store before unreachable.
+define void @test4(i1 %C, i32* %P) {
+; CHECK: @test4
+; CHECK: entry:
+; CHECK-NEXT: br i1 %C
+entry:
+ br i1 %C, label %T, label %F
+T:
+ store volatile i32 0, i32* %P
+ unreachable
+F:
+ ret void
+}
+
+; Check cmpxchg before unreachable.
+define void @test5(i1 %C, i32* %P) {
+; CHECK: @test5
+; CHECK: entry:
+; CHECK-NEXT: br i1 %C
+entry:
+ br i1 %C, label %T, label %F
+T:
+ cmpxchg volatile i32* %P, i32 0, i32 1 seq_cst
+ unreachable
+F:
+ ret void
+}
+
+; Check atomicrmw before unreachable.
+define void @test6(i1 %C, i32* %P) {
+; CHECK: @test6
+; CHECK: entry:
+; CHECK-NEXT: br i1 %C
+entry:
+ br i1 %C, label %T, label %F
+T:
+ atomicrmw volatile xchg i32* %P, i32 0 seq_cst
+ unreachable
+F:
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.dbg.ll b/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.dbg.ll
new file mode 100644
index 0000000..01041eb
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.dbg.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+ %llvm.dbg.anchor.type = type { i32, i32 }
+ %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8*, i1, i1, i8* }
+
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 458752, i32 17 }, section "llvm.metadata"
+
+@.str = internal constant [4 x i8] c"a.c\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [6 x i8] c"/tmp/\00", section "llvm.metadata" ; <[6 x i8]*> [#uses=1]
+@.str2 = internal constant [55 x i8] c"4.2.1 (Based on Apple Inc. build 5636) (LLVM build 00)\00", section "llvm.metadata" ; <[55 x i8]*> [#uses=1]
+@llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 458769, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([6 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([55 x i8]* @.str2, i32 0, i32 0), i1 true, i1 false, i8* null }, section "llvm.metadata" ; <%llvm.dbg.compile_unit.type*> [#uses=1]
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+define i1 @qux(i8* %m, i8* %n, i8* %o, i8* %p) nounwind {
+entry:
+ %tmp7 = icmp eq i8* %m, %n
+ br i1 %tmp7, label %bb, label %UnifiedReturnBlock
+
+bb:
+call void @llvm.dbg.stoppoint(i32 5, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+ %tmp15 = icmp eq i8* %o, %p
+ br label %UnifiedReturnBlock
+
+UnifiedReturnBlock:
+ %result = phi i1 [ 0, %entry ], [ %tmp15, %bb ]
+ ret i1 %result
+}
diff --git a/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.ll b/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
new file mode 100644
index 0000000..fb18624
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -simplifycfg -S | not grep br
+
+define i1 @qux(i8* %m, i8* %n, i8* %o, i8* %p) nounwind {
+entry:
+ %tmp7 = icmp eq i8* %m, %n
+ br i1 %tmp7, label %bb, label %UnifiedReturnBlock
+
+bb:
+ %tmp15 = icmp eq i8* %o, %p
+ br label %UnifiedReturnBlock
+
+UnifiedReturnBlock:
+ %result = phi i1 [ 0, %entry ], [ %tmp15, %bb ]
+ ret i1 %result
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll
new file mode 100644
index 0000000..9d57167
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2005-05-20-sprintf-crash.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -simplify-libcalls -disable-output
+
+@G = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1]
+
+declare i32 @sprintf(i8*, i8*, ...)
+
+define void @foo(i8* %P, i32* %X) {
+ call i32 (i8*, i8*, ...)* @sprintf( i8* %P, i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i32* %X ) ; <i32>:1 [#uses=0]
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll
new file mode 100644
index 0000000..81de2dd
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2007-04-06-strchr-miscompile.ll
@@ -0,0 +1,29 @@
+; PR1307
+; RUN: opt < %s -simplify-libcalls -instcombine -S > %t
+; RUN: grep {@str,.*i64 3} %t
+; RUN: grep {@str1,.*i64 7} %t
+; RUN: grep {ret i8.*null} %t
+; END.
+
+@str = internal constant [5 x i8] c"foog\00"
+@str1 = internal constant [8 x i8] c"blahhh!\00"
+@str2 = internal constant [5 x i8] c"Ponk\00"
+
+define i8* @test1() {
+ %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str, i32 0, i32 2), i32 103 ) ; <i8*> [#uses=1]
+ ret i8* %tmp3
+}
+
+declare i8* @strchr(i8*, i32)
+
+define i8* @test2() {
+ %tmp3 = tail call i8* @strchr( i8* getelementptr ([8 x i8]* @str1, i32 0, i32 2), i32 0 ) ; <i8*> [#uses=1]
+ ret i8* %tmp3
+}
+
+define i8* @test3() {
+entry:
+ %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8]* @str2, i32 0, i32 1), i32 80 ) ; <i8*> [#uses=1]
+ ret i8* %tmp3
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2008-05-19-memcmp.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2008-05-19-memcmp.ll
new file mode 100644
index 0000000..b687432
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2008-05-19-memcmp.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -simplify-libcalls -S | grep i32
+; PR2341
+
+@_2E_str = external constant [5 x i8] ; <[5 x i8]*> [#uses=1]
+
+declare i32 @memcmp(i8*, i8*, i32) nounwind readonly
+
+define i1 @f(i8** %start_addr) {
+entry:
+ %tmp4 = load i8** %start_addr, align 4 ; <i8*> [#uses=1]
+ %tmp5 = call i32 @memcmp( i8* %tmp4, i8* getelementptr ([5 x i8]* @_2E_str, i32 0, i32 0), i32 4 ) nounwind readonly ; <i32> [#uses=1]
+ %tmp6 = icmp eq i32 %tmp5, 0 ; <i1> [#uses=1]
+ ret i1 %tmp6
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-01-04-Annotate.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-01-04-Annotate.ll
new file mode 100644
index 0000000..73eb05b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-01-04-Annotate.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -simplify-libcalls -S > %t
+; RUN: grep noalias %t | count 2
+; RUN: grep nocapture %t | count 3
+; RUN: grep nounwind %t | count 3
+; RUN: grep readonly %t | count 1
+
+declare i8* @fopen(i8*, i8*)
+declare i8 @strlen(i8*)
+declare i32* @realloc(i32*, i32)
+
+; Test deliberately wrong declaration
+declare i32 @strcpy(...)
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll
new file mode 100644
index 0000000..ac89199
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-11-NotInitialized.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -inline -simplify-libcalls -functionattrs | \
+; RUN: llvm-dis | grep nocapture | count 2
+; Check that nocapture attributes are added when run after an SCC pass.
+; PR3520
+
+define i32 @use(i8* %x) nounwind readonly {
+entry:
+ %0 = tail call i64 @strlen(i8* %x) nounwind readonly ; <i64> [#uses=1]
+ %1 = trunc i64 %0 to i32 ; <i32> [#uses=1]
+ ret i32 %1
+}
+
+declare i64 @strlen(i8*) nounwind readonly
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll
new file mode 100644
index 0000000..f8a0c88
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -simplify-libcalls -S > %t
+; RUN: grep nocapture %t | count 2
+; RUN: grep null %t | grep nocapture | count 1
+; RUN: grep null %t | grep call | not grep readonly
+
+; Test that we add nocapture to the declaration, and to the second call only.
+
+declare float @strtol(i8* %s, i8** %endptr, i32 %base)
+
+define void @foo(i8* %x, i8** %endptr) {
+ call float @strtol(i8* %x, i8** %endptr, i32 10)
+ call float @strtol(i8* %x, i8** null, i32 10)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-05-30-memcmp-byte.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-05-30-memcmp-byte.ll
new file mode 100644
index 0000000..9056499
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-05-30-memcmp-byte.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -simplify-libcalls -instcombine -S | grep {ret i32 -65}
+; PR4284
+
+define i32 @test() nounwind {
+entry:
+ %c0 = alloca i8, align 1 ; <i8*> [#uses=2]
+ %c2 = alloca i8, align 1 ; <i8*> [#uses=2]
+ store i8 64, i8* %c0
+ store i8 -127, i8* %c2
+ %call = call i32 @memcmp(i8* %c0, i8* %c2, i32 1) ; <i32> [#uses=1]
+ ret i32 %call
+}
+
+declare i32 @memcmp(i8*, i8*, i32)
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-28-Exit.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-28-Exit.ll
new file mode 100644
index 0000000..7af0a26
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-28-Exit.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -simplify-libcalls -disable-output
+; PR4641
+
+ %struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, i8*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64, %struct.pthread_mutex*, %struct.pthread*, i32, i32, %union.anon }
+ %struct.__sbuf = type { i8*, i32, [4 x i8] }
+ %struct.pthread = type opaque
+ %struct.pthread_mutex = type opaque
+ %union.anon = type { i64, [120 x i8] }
+@.str13 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
+@.str14 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
+
+define i32 @main(i32 %argc, i8** %argv) nounwind {
+entry:
+ call void @exit(i32 0) nounwind
+ %cond392 = select i1 undef, i8* getelementptr ([2 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([2 x i8]* @.str14, i32 0, i32 0) ; <i8*> [#uses=1]
+ %call393 = call %struct.__sFILE* @fopen(i8* undef, i8* %cond392) nounwind ; <%struct.__sFILE*> [#uses=0]
+ unreachable
+}
+
+declare %struct.__sFILE* @fopen(i8*, i8*)
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll
new file mode 100644
index 0000000..b5a788e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2009-07-29-Exit2.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -simplify-libcalls -disable-output
+; PR4645
+
+define i32 @main() {
+entry:
+ br label %if.then
+
+lor.lhs.false: ; preds = %while.body
+ br i1 undef, label %if.then, label %for.cond
+
+if.then: ; preds = %lor.lhs.false, %while.body
+ call void @exit(i32 1)
+ br label %for.cond
+
+for.cond: ; preds = %for.end, %if.then, %lor.lhs.false
+ %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1]
+ unreachable
+
+for.end: ; preds = %for.cond20
+ %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1]
+ br label %for.cond
+}
+
+declare void @exit(i32)
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/2010-05-30-memcpy-Struct.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/2010-05-30-memcpy-Struct.ll
new file mode 100644
index 0000000..f67bae7
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/2010-05-30-memcpy-Struct.ll
@@ -0,0 +1,20 @@
+; RUN: opt -simplify-libcalls %s -S -o - | FileCheck %s
+; PR7265
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+%union.anon = type { i32, [4 x i8] }
+
+@.str = private constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=2]
+
+define void @CopyEventArg(%union.anon* %ev) nounwind {
+entry:
+ %call = call i32 (i8*, i8*, ...)* @sprintf(i8* undef, i8* getelementptr inbounds ([3 x i8]* @.str, i64 0, i64 0), %union.anon* %ev) nounwind ; <i32> [#uses=0]
+; CHECK: bitcast %union.anon* %ev to i8*
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
+ ret void
+}
+
+declare i32 @sprintf(i8*, i8*, ...)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/FFS.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/FFS.ll
new file mode 100644
index 0000000..2e1dbe9
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/FFS.ll
@@ -0,0 +1,36 @@
+; Test that the ToAsciiOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*@ffs}
+
+@non_const = external global i32 ; <i32*> [#uses=1]
+
+declare i32 @ffs(i32)
+
+declare i32 @ffsl(i32)
+
+declare i32 @ffsll(i64)
+
+define i32 @main() {
+ %arg = load i32* @non_const ; <i32> [#uses=1]
+ %val0 = call i32 @ffs( i32 %arg ) ; <i32> [#uses=1]
+ %val1 = call i32 @ffs( i32 1 ) ; <i32> [#uses=1]
+ %val2 = call i32 @ffs( i32 2048 ) ; <i32> [#uses=1]
+ %val3 = call i32 @ffsl( i32 65536 ) ; <i32> [#uses=1]
+ %val4 = call i32 @ffsll( i64 1024 ) ; <i32> [#uses=1]
+ %val5 = call i32 @ffsll( i64 17179869184 ) ; <i32> [#uses=1]
+ %val6 = call i32 @ffsll( i64 1152921504606846976 ) ; <i32> [#uses=1]
+ %rslt1 = add i32 %val1, %val2 ; <i32> [#uses=1]
+ %rslt2 = add i32 %val3, %val4 ; <i32> [#uses=1]
+ %rslt3 = add i32 %val5, %val6 ; <i32> [#uses=1]
+ %rslt4 = add i32 %rslt1, %rslt2 ; <i32> [#uses=1]
+ %rslt5 = add i32 %rslt4, %rslt3 ; <i32> [#uses=2]
+ %rslt6 = add i32 %rslt5, %val0 ; <i32> [#uses=0]
+ ret i32 %rslt5
+}
+
+
+; PR4206
+define i32 @a(i64) nounwind {
+ %2 = call i32 @ffsll(i64 %0) ; <i32> [#uses=1]
+ ret i32 %2
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/FPrintF.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/FPrintF.ll
new file mode 100644
index 0000000..81a2f3e
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/FPrintF.ll
@@ -0,0 +1,28 @@
+; Test that the FPrintFOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*fprintf}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+ %struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i32, [52 x i8] }
+ %struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
+@str = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1]
+@chr = constant [3 x i8] c"%c\00" ; <[3 x i8]*> [#uses=1]
+@hello = constant [13 x i8] c"hello world\0A\00" ; <[13 x i8]*> [#uses=1]
+@stdout = external global %struct._IO_FILE* ; <%struct._IO_FILE**> [#uses=3]
+
+declare i32 @fprintf(%struct._IO_FILE*, i8*, ...)
+
+define i32 @foo() {
+entry:
+ %tmp.1 = load %struct._IO_FILE** @stdout ; <%struct._IO_FILE*> [#uses=1]
+ %tmp.0 = call i32 (%struct._IO_FILE*, i8*, ...)* @fprintf( %struct._IO_FILE* %tmp.1, i8* getelementptr ([13 x i8]* @hello, i32 0, i32 0) ) ; <i32> [#uses=0]
+ %tmp.4 = load %struct._IO_FILE** @stdout ; <%struct._IO_FILE*> [#uses=1]
+ %tmp.3 = call i32 (%struct._IO_FILE*, i8*, ...)* @fprintf( %struct._IO_FILE* %tmp.4, i8* getelementptr ([3 x i8]* @str, i32 0, i32 0), i8* getelementptr ([13 x i8]* @hello, i32 0, i32 0) ) ; <i32> [#uses=0]
+ %tmp.8 = load %struct._IO_FILE** @stdout ; <%struct._IO_FILE*> [#uses=1]
+ %tmp.7 = call i32 (%struct._IO_FILE*, i8*, ...)* @fprintf( %struct._IO_FILE* %tmp.8, i8* getelementptr ([3 x i8]* @chr, i32 0, i32 0), i32 33 ) ; <i32> [#uses=0]
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/FPuts.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/FPuts.ll
new file mode 100644
index 0000000..25a984d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/FPuts.ll
@@ -0,0 +1,29 @@
+; Test that the FPutsOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*fputs}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+ %struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i32, [52 x i8] }
+ %struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
+@stdout = external global %struct._IO_FILE* ; <%struct._IO_FILE**> [#uses=1]
+@empty = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@len1 = constant [2 x i8] c"A\00" ; <[2 x i8]*> [#uses=1]
+@long = constant [7 x i8] c"hello\0A\00" ; <[7 x i8]*> [#uses=1]
+
+declare i32 @fputs(i8*, %struct._IO_FILE*)
+
+define i32 @main() {
+entry:
+ %out = load %struct._IO_FILE** @stdout ; <%struct._IO_FILE*> [#uses=3]
+ %s1 = getelementptr [1 x i8]* @empty, i32 0, i32 0 ; <i8*> [#uses=1]
+ %s2 = getelementptr [2 x i8]* @len1, i32 0, i32 0 ; <i8*> [#uses=1]
+ %s3 = getelementptr [7 x i8]* @long, i32 0, i32 0 ; <i8*> [#uses=1]
+ %a = call i32 @fputs( i8* %s1, %struct._IO_FILE* %out ) ; <i32> [#uses=0]
+ %b = call i32 @fputs( i8* %s2, %struct._IO_FILE* %out ) ; <i32> [#uses=0]
+ %c = call i32 @fputs( i8* %s3, %struct._IO_FILE* %out ) ; <i32> [#uses=0]
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/IsDigit.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/IsDigit.ll
new file mode 100644
index 0000000..dedae3c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/IsDigit.ll
@@ -0,0 +1,21 @@
+; Test that the IsDigitOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep call
+
+declare i32 @isdigit(i32)
+
+declare i32 @isascii(i32)
+
+define i32 @main() {
+ %val1 = call i32 @isdigit( i32 47 ) ; <i32> [#uses=1]
+ %val2 = call i32 @isdigit( i32 48 ) ; <i32> [#uses=1]
+ %val3 = call i32 @isdigit( i32 57 ) ; <i32> [#uses=1]
+ %val4 = call i32 @isdigit( i32 58 ) ; <i32> [#uses=1]
+ %rslt1 = add i32 %val1, %val2 ; <i32> [#uses=1]
+ %rslt2 = add i32 %val3, %val4 ; <i32> [#uses=1]
+ %sum = add i32 %rslt1, %rslt2 ; <i32> [#uses=1]
+ %rslt = call i32 @isdigit( i32 %sum ) ; <i32> [#uses=1]
+ %tmp = call i32 @isascii( i32 %rslt ) ; <i32> [#uses=1]
+ ret i32 %tmp
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/MemCpy.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/MemCpy.ll
new file mode 100644
index 0000000..4c5d90f
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/MemCpy.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -constprop -instcombine -S | not grep {call.*llvm.memcpy.i32}
+
+@h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1]
+@hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=1]
+@hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=1]
+
+define i32 @main() {
+ %h_p = getelementptr [2 x i8]* @h, i32 0, i32 0
+ %hel_p = getelementptr [4 x i8]* @hel, i32 0, i32 0
+ %hello_u_p = getelementptr [8 x i8]* @hello_u, i32 0, i32 0
+ %target = alloca [1024 x i8]
+ %target_p = getelementptr [1024 x i8]* %target, i32 0, i32 0
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %h_p, i32 2, i32 2, i1 false)
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hel_p, i32 4, i32 4, i1 false)
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hello_u_p, i32 8, i32 8, i1 false)
+ ret i32 0
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/PR7357.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/PR7357.ll
new file mode 100644
index 0000000..6d5c1d5
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/PR7357.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -default-data-layout="e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32" -simplify-libcalls -S | FileCheck %s
+@.str1 = private constant [11 x i8] c"(){};[]&|:\00", align 4
+
+; check that simplify libcalls will not replace a call with one calling
+; convention with a new call with a different calling convention.
+
+; CHECK: define arm_aapcscc i32 @foo(i32 %argc)
+; CHECK: call arm_aapcscc i8* @strchr
+define arm_aapcscc i32 @foo(i32 %argc) nounwind {
+bb.nph:
+ call arm_aapcscc i8* @strchr(i8* getelementptr ([11 x i8]* @.str1, i32 0,
+i32 0), i32 %argc) nounwind readonly
+ ret i32 0
+}
+
+declare arm_aapcscc i8* @strchr(i8*, i32) nounwind readonly
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/Printf.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/Printf.ll
new file mode 100644
index 0000000..544ad8d
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/Printf.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -simplify-libcalls -S -o %t
+; RUN: FileCheck < %t %s
+
+@str = internal constant [13 x i8] c"hello world\0A\00" ; <[13 x i8]*> [#uses=1]
+@str1 = internal constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1]
+
+declare i32 @printf(i8*, ...)
+
+; CHECK: define void @f0
+; CHECK-NOT: printf
+; CHECK: }
+define void @f0() {
+entry:
+ %tmp1 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([13 x i8]* @str, i32 0, i32 0) ) ; <i32> [#uses=0]
+ ret void
+}
+
+; CHECK: define void @f1
+; CHECK-NOT: printf
+; CHECK: }
+define void @f1() {
+entry:
+ %tmp1 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([2 x i8]* @str1, i32 0, i32 0) ) ; <i32> [#uses=0]
+ ret void
+}
+
+; Verify that we don't turn this into a putchar call (thus changing the return
+; value).
+;
+; CHECK: define i32 @f2
+; CHECK: printf
+; CHECK: }
+define i32 @f2() {
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([2 x i8]* @str1, i32 0, i32 0))
+ ret i32 %call
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/Puts.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/Puts.ll
new file mode 100644
index 0000000..4843143
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/Puts.ll
@@ -0,0 +1,15 @@
+; Test that the PutsOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "-p:64:64:64"
+
+@.str = private constant [1 x i8] zeroinitializer
+
+declare i32 @puts(i8*)
+
+define void @foo() {
+entry:
+; CHECK: call i32 @putchar(i32 10)
+ %call = call i32 @puts(i8* getelementptr inbounds ([1 x i8]* @.str, i32 0, i32 0))
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/SPrintF.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/SPrintF.ll
new file mode 100644
index 0000000..7b74915
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/SPrintF.ll
@@ -0,0 +1,40 @@
+; Test that the SPrintFOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*sprintf}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
+@fmt1 = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1]
+@fmt2 = constant [3 x i8] c"%c\00" ; <[3 x i8]*> [#uses=1]
+
+declare i32 @sprintf(i8*, i8*, ...)
+
+declare i32 @puts(i8*)
+
+define i32 @foo(i8* %p) {
+ %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
+ %target_p = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=7]
+ %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=2]
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %nh_p = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %fmt1_p = getelementptr [3 x i8]* @fmt1, i32 0, i32 0 ; <i8*> [#uses=2]
+ %fmt2_p = getelementptr [3 x i8]* @fmt2, i32 0, i32 0 ; <i8*> [#uses=1]
+ store i8 0, i8* %target_p
+ %r1 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %hello_p ) ; <i32> [#uses=1]
+ %r2 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %null_p ) ; <i32> [#uses=1]
+ %r3 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %nh_p ) ; <i32> [#uses=1]
+ %r4 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %fmt1_p, i8* %hello_p ) ; <i32> [#uses=1]
+ %r4.1 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %fmt1_p, i8* %p ) ; <i32> [#uses=1]
+ %r5 = call i32 (i8*, i8*, ...)* @sprintf( i8* %target_p, i8* %fmt2_p, i32 82 ) ; <i32> [#uses=1]
+ %r6 = add i32 %r1, %r2 ; <i32> [#uses=1]
+ %r7 = add i32 %r3, %r6 ; <i32> [#uses=1]
+ %r8 = add i32 %r5, %r7 ; <i32> [#uses=1]
+ %r9 = add i32 %r8, %r4 ; <i32> [#uses=1]
+ %r10 = add i32 %r9, %r4.1 ; <i32> [#uses=1]
+ ret i32 %r10
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrCat.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCat.ll
new file mode 100644
index 0000000..1e904ee
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCat.ll
@@ -0,0 +1,33 @@
+; Test that the StrCatOptimizer works correctly
+; PR3661
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*strcat}
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: grep {puts.*%arg1}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
+
+declare i8* @strcat(i8*, i8*)
+
+declare i32 @puts(i8*)
+
+define i32 @main() {
+ %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
+ %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=2]
+ store i8 0, i8* %arg1
+ %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt1 = call i8* @strcat( i8* %arg1, i8* %arg2 ) ; <i8*> [#uses=1]
+ %arg3 = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt2 = call i8* @strcat( i8* %rslt1, i8* %arg3 ) ; <i8*> [#uses=1]
+ %arg4 = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt3 = call i8* @strcat( i8* %rslt2, i8* %arg4 ) ; <i8*> [#uses=1]
+ call i32 @puts( i8* %rslt3 ) ; <i32>:1 [#uses=0]
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrChr.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrChr.ll
new file mode 100644
index 0000000..661654b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrChr.ll
@@ -0,0 +1,26 @@
+; Test that the StrChrOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+@hello = constant [14 x i8] c"hello world\5Cn\00"
+@null = constant [1 x i8] zeroinitializer
+
+declare i8* @strchr(i8*, i32)
+
+define i32 @foo(i32 %index) {
+ %hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %world = call i8* @strchr(i8* %hello_p, i32 119)
+; CHECK: getelementptr i8* %hello_p, i64 6
+ %ignore = call i8* @strchr(i8* %null_p, i32 119)
+; CHECK-NOT: call i8* strchr
+ %null = call i8* @strchr(i8* %hello_p, i32 0)
+; CHECK: getelementptr i8* %hello_p, i64 13
+ %result = call i8* @strchr(i8* %hello_p, i32 %index)
+; CHECK: call i8* @memchr(i8* %hello_p, i32 %index, i64 14)
+ ret i32 %index
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrCmp.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCmp.ll
new file mode 100644
index 0000000..965b0ca
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCmp.ll
@@ -0,0 +1,65 @@
+; Test that the StrCmpOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@hell = constant [5 x i8] c"hell\00" ; <[5 x i8]*> [#uses=1]
+@bell = constant [5 x i8] c"bell\00" ; <[5 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+
+declare i32 @strcmp(i8*, i8*)
+
+; strcmp("", x) -> -*x
+define i32 @test1(i8* %str) {
+ %temp1 = call i32 @strcmp(i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0), i8* %str)
+ ret i32 %temp1
+ ; CHECK: @test1
+ ; CHECK: %strcmpload = load i8* %str
+ ; CHECK: %1 = zext i8 %strcmpload to i32
+ ; CHECK: %temp1 = sub i32 0, %1
+ ; CHECK: ret i32 %temp1
+}
+
+; strcmp(x, "") -> *x
+define i32 @test2(i8* %str) {
+ %temp1 = call i32 @strcmp(i8* %str, i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0))
+ ret i32 %temp1
+ ; CHECK: @test2
+ ; CHECK: %strcmpload = load i8* %str
+ ; CHECK: %temp1 = zext i8 %strcmpload to i32
+ ; CHECK: ret i32 %temp1
+}
+
+; strcmp(x, y) -> cnst
+define i32 @test3() {
+ %temp1 = call i32 @strcmp(i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8]* @hello, i32 0, i32 0))
+ ret i32 %temp1
+ ; CHECK: @test3
+ ; CHECK: ret i32 -1
+}
+define i32 @test4() {
+ %temp1 = call i32 @strcmp(i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0))
+ ret i32 %temp1
+ ; CHECK: @test4
+ ; CHECK: ret i32 1
+}
+
+; strcmp(x, y) -> memcmp(x, y, <known length>)
+; (This transform is rather difficult to trigger in a useful manner)
+define i32 @test5(i1 %b) {
+ %sel = select i1 %b, i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8]* @bell, i32 0, i32 0)
+ %temp1 = call i32 @strcmp(i8* getelementptr inbounds ([6 x i8]* @hello, i32 0, i32 0), i8* %sel)
+ ret i32 %temp1
+ ; CHECK: @test5
+ ; CHECK: %memcmp = call i32 @memcmp(i8* getelementptr inbounds ([6 x i8]* @hello, i32 0, i32 0), i8* %sel, i32 5)
+ ; CHECK: ret i32 %memcmp
+}
+
+; strcmp(x,x) -> 0
+define i32 @test6(i8* %str) {
+ %temp1 = call i32 @strcmp(i8* %str, i8* %str)
+ ret i32 %temp1
+ ; CHECK: @test6
+ ; CHECK: ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrCpy.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCpy.ll
new file mode 100644
index 0000000..8d34377
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrCpy.ll
@@ -0,0 +1,37 @@
+; Test that the StrCpyOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+
+@hello = constant [6 x i8] c"hello\00"
+
+declare i8* @strcpy(i8*, i8*)
+
+declare i8* @__strcpy_chk(i8*, i8*, i32) nounwind
+
+declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
+
+; rdar://6839935
+
+define i32 @t1() {
+; CHECK: @t1
+ %target = alloca [1024 x i8]
+ %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
+ %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
+ %rslt1 = call i8* @strcpy( i8* %arg1, i8* %arg2 )
+; CHECK: @llvm.memcpy.p0i8.p0i8.i32
+ ret i32 0
+}
+
+define i32 @t2() {
+; CHECK: @t2
+ %target = alloca [1024 x i8]
+ %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
+ %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
+ %tmp1 = call i32 @llvm.objectsize.i32(i8* %arg1, i1 false)
+ %rslt1 = call i8* @__strcpy_chk(i8* %arg1, i8* %arg2, i32 %tmp1)
+; CHECK: @__memcpy_chk
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrLen.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrLen.ll
new file mode 100644
index 0000000..1ea64b4
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrLen.ll
@@ -0,0 +1,56 @@
+; Test that the StrCatOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*strlen}
+
+target datalayout = "e-p:32:32"
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=3]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=3]
+@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
+
+declare i32 @strlen(i8*)
+
+define i32 @test1() {
+ %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
+ ret i32 %hello_l
+}
+
+define i32 @test2() {
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
+ ret i32 %null_l
+}
+
+define i32 @test3() {
+ %null_hello_p = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %null_hello_l = call i32 @strlen( i8* %null_hello_p ) ; <i32> [#uses=1]
+ ret i32 %null_hello_l
+}
+
+define i1 @test4() {
+ %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
+ %eq_hello = icmp eq i32 %hello_l, 0 ; <i1> [#uses=1]
+ ret i1 %eq_hello
+}
+
+define i1 @test5() {
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
+ %eq_null = icmp eq i32 %null_l, 0 ; <i1> [#uses=1]
+ ret i1 %eq_null
+}
+
+define i1 @test6() {
+ %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
+ %ne_hello = icmp ne i32 %hello_l, 0 ; <i1> [#uses=1]
+ ret i1 %ne_hello
+}
+
+define i1 @test7() {
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
+ %ne_null = icmp ne i32 %null_l, 0 ; <i1> [#uses=1]
+ ret i1 %ne_null
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCat.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCat.ll
new file mode 100644
index 0000000..d09c022
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCat.ll
@@ -0,0 +1,31 @@
+; Test that the StrNCatOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*strncat}
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: grep {puts.*%arg1}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
+
+declare i8* @strncat(i8*, i8*, i32)
+
+declare i32 @puts(i8*)
+
+define i32 @main() {
+ %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
+ %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=2]
+ store i8 0, i8* %arg1
+ %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt1 = call i8* @strncat( i8* %arg1, i8* %arg2, i32 6 ) ; <i8*> [#uses=1]
+ %arg3 = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt2 = call i8* @strncat( i8* %rslt1, i8* %arg3, i32 42 ) ; <i8*> [#uses=1]
+ %arg4 = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt3 = call i8* @strncat( i8* %rslt2, i8* %arg4, i32 42 ) ; <i8*> [#uses=1]
+ call i32 @puts( i8* %rslt3 ) ; <i32>:1 [#uses=0]
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCmp.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCmp.ll
new file mode 100644
index 0000000..f8a29f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCmp.ll
@@ -0,0 +1,78 @@
+; Test that the StrCmpOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@hell = constant [5 x i8] c"hell\00" ; <[5 x i8]*> [#uses=1]
+@bell = constant [5 x i8] c"bell\00" ; <[5 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+
+declare i32 @strncmp(i8*, i8*, i32)
+
+; strcmp("", x) -> -*x
+define i32 @test1(i8* %str) {
+ %temp1 = call i32 @strncmp(i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0), i8* %str, i32 10)
+ ret i32 %temp1
+ ; CHECK: @test1
+ ; CHECK: %strcmpload = load i8* %str
+ ; CHECK: %1 = zext i8 %strcmpload to i32
+ ; CHECK: %temp1 = sub i32 0, %1
+ ; CHECK: ret i32 %temp1
+}
+
+; strcmp(x, "") -> *x
+define i32 @test2(i8* %str) {
+ %temp1 = call i32 @strncmp(i8* %str, i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0), i32 10)
+ ret i32 %temp1
+ ; CHECK: @test2
+ ; CHECK: %strcmpload = load i8* %str
+ ; CHECK: %temp1 = zext i8 %strcmpload to i32
+ ; CHECK: ret i32 %temp1
+}
+
+; strncmp(x, y, n) -> cnst
+define i32 @test3() {
+ %temp1 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8]* @hello, i32 0, i32 0), i32 10)
+ ret i32 %temp1
+ ; CHECK: @test3
+ ; CHECK: ret i32 -1
+}
+define i32 @test4() {
+ %temp1 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8]* @null, i32 0, i32 0), i32 10)
+ ret i32 %temp1
+ ; CHECK: @test4
+ ; CHECK: ret i32 1
+}
+define i32 @test5() {
+ %temp1 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8]* @hello, i32 0, i32 0), i32 4)
+ ret i32 %temp1
+ ; CHECK: @test5
+ ; CHECK: ret i32 0
+}
+
+; strncmp(x,y,1) -> memcmp(x,y,1)
+define i32 @test6(i8* %str1, i8* %str2) {
+ %temp1 = call i32 @strncmp(i8* %str1, i8* %str2, i32 1)
+ ret i32 %temp1
+ ; CHECK: @test6
+ ; CHECK: load i8*
+ ; CHECK: load i8*
+ ; CHECK: sub i32
+}
+
+; strncmp(x,y,0) -> 0
+define i32 @test7(i8* %str1, i8* %str2) {
+ %temp1 = call i32 @strncmp(i8* %str1, i8* %str2, i32 0)
+ ret i32 %temp1
+ ; CHECK: @test7
+ ; CHECK: ret i32 0
+}
+
+; strncmp(x,x,n) -> 0
+define i32 @test8(i8* %str, i32 %n) {
+ %temp1 = call i32 @strncmp(i8* %str, i8* %str, i32 %n)
+ ret i32 %temp1
+ ; CHECK: @test8
+ ; CHECK: ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCpy.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCpy.ll
new file mode 100644
index 0000000..c8af3ca
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrNCpy.ll
@@ -0,0 +1,29 @@
+; Test that the StrNCpyOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*strncpy}
+
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
+
+@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
+@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
+
+declare i8* @strncpy(i8*, i8*, i32)
+
+declare i32 @puts(i8*)
+
+define i32 @main() {
+ %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
+ %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=2]
+ store i8 0, i8* %arg1
+ %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt1 = call i8* @strncpy( i8* %arg1, i8* %arg2, i32 6 ) ; <i8*> [#uses=1]
+ %arg3 = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt2 = call i8* @strncpy( i8* %rslt1, i8* %arg3, i32 42 ) ; <i8*> [#uses=1]
+ %arg4 = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
+ %rslt3 = call i8* @strncpy( i8* %rslt2, i8* %arg4, i32 42 ) ; <i8*> [#uses=1]
+ call i32 @puts( i8* %rslt3 ) ; <i32>:1 [#uses=0]
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrPBrk.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrPBrk.ll
new file mode 100644
index 0000000..29c3b74
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrPBrk.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "-p:64:64:64"
+
+@hello = constant [12 x i8] c"hello world\00"
+@w = constant [2 x i8] c"w\00"
+@null = constant [1 x i8] zeroinitializer
+
+declare i8* @strpbrk(i8*, i8*)
+
+define void @test(i8* %s1, i8* %s2) {
+ %hello_p = getelementptr [12 x i8]* @hello, i32 0, i32 0
+ %w_p = getelementptr [2 x i8]* @w, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %test1 = call i8* @strpbrk(i8* %null_p, i8* %s2)
+ %test2 = call i8* @strpbrk(i8* %s1, i8* %null_p)
+; CHECK-NOT: call i8* @strpbrk
+ %test3 = call i8* @strpbrk(i8* %s1, i8* %w_p)
+; CHECK: call i8* @strchr(i8* %s1, i32 119)
+ %test4 = call i8* @strpbrk(i8* %hello_p, i8* %w_p)
+; CHECK: getelementptr i8* %hello_p, i64 6
+ %test5 = call i8* @strpbrk(i8* %s1, i8* %s2)
+; CHECK: call i8* @strpbrk(i8* %s1, i8* %s2)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrRChr.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrRChr.ll
new file mode 100644
index 0000000..2259fc0
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrRChr.ll
@@ -0,0 +1,23 @@
+; Test that the StrRChrOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "-p:64:64:64"
+
+@hello = constant [14 x i8] c"hello world\5Cn\00"
+@null = constant [1 x i8] zeroinitializer
+
+declare i8* @strrchr(i8*, i32)
+
+define void @foo(i8* %bar) {
+ %hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %world = call i8* @strrchr(i8* %hello_p, i32 119)
+; CHECK: getelementptr i8* %hello_p, i64 6
+ %ignore = call i8* @strrchr(i8* %null_p, i32 119)
+; CHECK-NOT: call i8* strrchr
+ %null = call i8* @strrchr(i8* %hello_p, i32 0)
+; CHECK: getelementptr i8* %hello_p, i64 13
+ %strchr = call i8* @strrchr(i8* %bar, i32 0)
+; CHECK: call i8* @strchr(i8* %bar, i32 0)
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrSpn.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrSpn.ll
new file mode 100644
index 0000000..800c190
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrSpn.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "-p:64:64:64"
+
+@abcba = constant [6 x i8] c"abcba\00"
+@abc = constant [4 x i8] c"abc\00"
+@null = constant [1 x i8] zeroinitializer
+
+declare i64 @strspn(i8*, i8*)
+
+define i64 @testspn(i8* %s1, i8* %s2) {
+ %abcba_p = getelementptr [6 x i8]* @abcba, i32 0, i32 0
+ %abc_p = getelementptr [4 x i8]* @abc, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %test1 = call i64 @strspn(i8* %s1, i8* %null_p)
+ %test2 = call i64 @strspn(i8* %null_p, i8* %s2)
+ %test3 = call i64 @strspn(i8* %abcba_p, i8* %abc_p)
+; CHECK-NOT: call i64 @strspn
+ %test4 = call i64 @strspn(i8* %s1, i8* %s2)
+; CHECK: call i64 @strspn(i8* %s1, i8* %s2)
+ ret i64 %test3
+; CHECK: ret i64 5
+}
+
+declare i64 @strcspn(i8*, i8*)
+
+define i64 @testcspn(i8* %s1, i8* %s2) {
+ %abcba_p = getelementptr [6 x i8]* @abcba, i32 0, i32 0
+ %abc_p = getelementptr [4 x i8]* @abc, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %test1 = call i64 @strcspn(i8* %s1, i8* %null_p)
+; CHECK: call i64 @strlen(i8* %s1)
+ %test2 = call i64 @strcspn(i8* %null_p, i8* %s2)
+ %test3 = call i64 @strcspn(i8* %abcba_p, i8* %abc_p)
+; CHECK-NOT: call i64 @strcspn
+ %test4 = call i64 @strcspn(i8* %s1, i8* %s2)
+; CHECK: call i64 @strcspn(i8* %s1, i8* %s2)
+ %add0 = add i64 %test1, %test3
+; CHECK: add i64 %{{.+}}, 0
+ ret i64 %add0
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/StrStr.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/StrStr.ll
new file mode 100644
index 0000000..eefd2e8
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/StrStr.ll
@@ -0,0 +1,60 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+; PR5783
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.0"
+
+@.str = private constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@.str1 = private constant [2 x i8] c"a\00" ; <[2 x i8]*> [#uses=1]
+@.str2 = private constant [6 x i8] c"abcde\00" ; <[6 x i8]*> [#uses=1]
+@.str3 = private constant [4 x i8] c"bcd\00" ; <[4 x i8]*> [#uses=1]
+
+define i8* @test1(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* getelementptr inbounds ([1 x i8]* @.str, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, "") -> P
+; CHECK: @test1
+; CHECK: ret i8* %P
+}
+
+declare i8* @strstr(i8*, i8* nocapture) nounwind readonly
+
+define i8* @test2(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* getelementptr inbounds ([2 x i8]* @.str1, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, "a") -> strchr(P, 'a')
+; CHECK: @test2
+; CHECK: @strchr(i8* %P, i32 97)
+}
+
+define i8* @test3(i8* nocapture %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8]* @.str3, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr("abcde", "bcd") -> "abcde"+1
+; CHECK: @test3
+; CHECK: getelementptr inbounds ([6 x i8]* @.str2, i32 0, i64 1)
+}
+
+define i8* @test4(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* %P) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, P) -> P
+; CHECK: @test4
+; CHECK: ret i8* %P
+}
+
+define i1 @test5(i8* %P, i8* %Q) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* %Q) nounwind ; <i8*> [#uses=1]
+ %cmp = icmp eq i8* %call, %P
+ ret i1 %cmp
+; CHECK: @test5
+; CHECK: [[LEN:%[a-z]+]] = call {{i[0-9]+}} @strlen(i8* %Q)
+; CHECK: [[NCMP:%[a-z]+]] = call {{i[0-9]+}} @strncmp(i8* %P, i8* %Q, {{i[0-9]+}} [[LEN]])
+; CHECK: icmp eq {{i[0-9]+}} [[NCMP]], 0
+; CHECK: ret i1
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/ToAscii.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/ToAscii.ll
new file mode 100644
index 0000000..79182f8
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/ToAscii.ll
@@ -0,0 +1,21 @@
+; Test that the ToAsciiOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | \
+; RUN: not grep {call.*toascii}
+
+declare i32 @toascii(i32)
+
+define i32 @main() {
+ %val1 = call i32 @toascii( i32 1 ) ; <i32> [#uses=1]
+ %val2 = call i32 @toascii( i32 0 ) ; <i32> [#uses=1]
+ %val3 = call i32 @toascii( i32 127 ) ; <i32> [#uses=1]
+ %val4 = call i32 @toascii( i32 128 ) ; <i32> [#uses=1]
+ %val5 = call i32 @toascii( i32 255 ) ; <i32> [#uses=1]
+ %val6 = call i32 @toascii( i32 256 ) ; <i32> [#uses=1]
+ %rslt1 = add i32 %val1, %val2 ; <i32> [#uses=1]
+ %rslt2 = add i32 %val3, %val4 ; <i32> [#uses=1]
+ %rslt3 = add i32 %val5, %val6 ; <i32> [#uses=1]
+ %rslt4 = add i32 %rslt1, %rslt2 ; <i32> [#uses=1]
+ %rslt5 = add i32 %rslt4, %rslt3 ; <i32> [#uses=1]
+ ret i32 %rslt5
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/abs.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/abs.ll
new file mode 100644
index 0000000..6fbe0b9
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/abs.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -simplify-libcalls -S | grep {select i1 %ispos}
+; PR2337
+
+define i32 @test(i32 %x) {
+entry:
+ %call = call i32 @abs( i32 %x ) ; <i32> [#uses=1]
+ ret i32 %call
+}
+
+declare i32 @abs(i32)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/debug-line.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/debug-line.ll
new file mode 100644
index 0000000..b668e4b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/debug-line.ll
@@ -0,0 +1,24 @@
+; RUN: opt -simplify-libcalls -S < %s | FileCheck %s
+
+
+@.str = private constant [3 x i8] c"%c\00"
+
+define void @foo() nounwind ssp {
+;CHECK: call i32 @putchar{{.+}} !dbg
+ %1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i32 97), !dbg !5
+ ret void, !dbg !7
+}
+
+declare i32 @printf(i8*, ...)
+
+!llvm.dbg.sp = !{!0}
+
+!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"", metadata !1, i32 4, metadata !3, i1 false, i1 true, i32 0, i32 0, null, i32 0, i1 false, void ()* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 589865, metadata !"m.c", metadata !"/private/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"m.c", metadata !"/private/tmp", metadata !"clang", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 589845, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 5, i32 2, metadata !6, null}
+!6 = metadata !{i32 589835, metadata !0, i32 4, i32 12, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
+!7 = metadata !{i32 6, i32 1, metadata !6, null}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/dg.exp b/src/LLVM/test/Transforms/SimplifyLibCalls/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/exp2.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/exp2.ll
new file mode 100644
index 0000000..2f5d910
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/exp2.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -simplify-libcalls -S | grep {call.*ldexp} | count 4
+; rdar://5852514
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin8"
+
+define double @t1(i32 %x) nounwind {
+entry:
+ %tmp12 = sitofp i32 %x to double ; <double> [#uses=1]
+ %exp2 = tail call double @exp2( double %tmp12 ) ; <double> [#uses=1]
+ ret double %exp2
+}
+
+define float @t4(i8 zeroext %x) nounwind {
+entry:
+ %tmp12 = uitofp i8 %x to float ; <float> [#uses=1]
+ %tmp3 = tail call float @exp2f( float %tmp12 ) nounwind readonly ; <float> [#uses=1]
+ ret float %tmp3
+}
+
+declare float @exp2f(float) nounwind readonly
+
+define double @t3(i16 zeroext %x) nounwind {
+entry:
+ %tmp12 = uitofp i16 %x to double ; <double> [#uses=1]
+ %exp2 = tail call double @exp2( double %tmp12 ) ; <double> [#uses=1]
+ ret double %exp2
+}
+
+define double @t2(i16 signext %x) nounwind {
+entry:
+ %tmp12 = sitofp i16 %x to double ; <double> [#uses=1]
+ %exp2 = tail call double @exp2( double %tmp12 ) ; <double> [#uses=1]
+ ret double %exp2
+}
+
+declare double @exp2(double)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/floor.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/floor.ll
new file mode 100644
index 0000000..2aa8025
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/floor.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -simplify-libcalls -S > %t
+; RUN: not grep {call.*floor(} %t
+; RUN: grep {call.*floorf(} %t
+; RUN: not grep {call.*ceil(} %t
+; RUN: grep {call.*ceilf(} %t
+; RUN: not grep {call.*nearbyint(} %t
+; RUN: grep {call.*nearbyintf(} %t
+; XFAIL: sparc
+
+declare double @floor(double)
+
+declare double @ceil(double)
+
+declare double @nearbyint(double)
+
+define float @test_floor(float %C) {
+ %D = fpext float %C to double ; <double> [#uses=1]
+ ; --> floorf
+ %E = call double @floor( double %D ) ; <double> [#uses=1]
+ %F = fptrunc double %E to float ; <float> [#uses=1]
+ ret float %F
+}
+
+define float @test_ceil(float %C) {
+ %D = fpext float %C to double ; <double> [#uses=1]
+ ; --> ceilf
+ %E = call double @ceil( double %D ) ; <double> [#uses=1]
+ %F = fptrunc double %E to float ; <float> [#uses=1]
+ ret float %F
+}
+
+; PR8466
+; XFAIL: win32
+define float @test_nearbyint(float %C) {
+ %D = fpext float %C to double ; <double> [#uses=1]
+ ; --> nearbyintf
+ %E = call double @nearbyint( double %D ) ; <double> [#uses=1]
+ %F = fptrunc double %E to float ; <float> [#uses=1]
+ ret float %F
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/iprintf.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/iprintf.ll
new file mode 100644
index 0000000..7f036fe
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/iprintf.ll
@@ -0,0 +1,71 @@
+; RUN: opt < %s -simplify-libcalls -S -o %t
+; RUN: FileCheck < %t %s
+target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32"
+target triple = "xcore-xmos-elf"
+
+@.str = internal constant [4 x i8] c"%f\0A\00" ; <[4 x i8]*> [#uses=1]
+@.str1 = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
+
+; Verify printf with no floating point arguments is transformed to iprintf
+define i32 @f0(i32 %x) nounwind {
+entry:
+; CHECK: define i32 @f0
+; CHECK: @iprintf
+; CHECK: }
+ %0 = tail call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @.str1, i32 0, i32 0), i32 %x) ; <i32> [#uses=0]
+ ret i32 %0
+}
+
+; Verify we don't turn this into an iprintf call
+define void @f1(double %x) nounwind {
+entry:
+; CHECK: define void @f1
+; CHECK: @printf
+; CHECK: }
+ %0 = tail call i32 (i8*, ...)* @printf(i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), double %x) nounwind ; <i32> [#uses=0]
+ ret void
+}
+
+; Verify sprintf with no floating point arguments is transformed to siprintf
+define i32 @f2(i8* %p, i32 %x) nounwind {
+entry:
+; CHECK: define i32 @f2
+; CHECK: @siprintf
+; CHECK: }
+ %0 = tail call i32 (i8*, i8*, ...)* @sprintf(i8 *%p, i8* getelementptr ([4 x i8]* @.str1, i32 0, i32 0), i32 %x)
+ ret i32 %0
+}
+
+; Verify we don't turn this into an siprintf call
+define i32 @f3(i8* %p, double %x) nounwind {
+entry:
+; CHECK: define i32 @f3
+; CHECK: @sprintf
+; CHECK: }
+ %0 = tail call i32 (i8*, i8*, ...)* @sprintf(i8 *%p, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), double %x)
+ ret i32 %0
+}
+
+; Verify fprintf with no floating point arguments is transformed to fiprintf
+define i32 @f4(i8* %p, i32 %x) nounwind {
+entry:
+; CHECK: define i32 @f4
+; CHECK: @fiprintf
+; CHECK: }
+ %0 = tail call i32 (i8*, i8*, ...)* @fprintf(i8 *%p, i8* getelementptr ([4 x i8]* @.str1, i32 0, i32 0), i32 %x)
+ ret i32 %0
+}
+
+; Verify we don't turn this into an fiprintf call
+define i32 @f5(i8* %p, double %x) nounwind {
+entry:
+; CHECK: define i32 @f5
+; CHECK: @fprintf
+; CHECK: }
+ %0 = tail call i32 (i8*, i8*, ...)* @fprintf(i8 *%p, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), double %x)
+ ret i32 %0
+}
+
+declare i32 @printf(i8* nocapture, ...) nounwind
+declare i32 @sprintf(i8* nocapture, i8* nocapture, ...) nounwind
+declare i32 @fprintf(i8* nocapture, i8* nocapture, ...) nounwind
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/memcmp.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/memcmp.ll
new file mode 100644
index 0000000..ce1622c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/memcmp.ll
@@ -0,0 +1,35 @@
+; Test that the memcmpOptimizer works correctly
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+@h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=0]
+@hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=0]
+@hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=0]
+
+declare i32 @memcmp(i8*, i8*, i32)
+
+define void @test(i8* %P, i8* %Q, i32 %N, i32* %IP, i1* %BP) {
+ %A = call i32 @memcmp( i8* %P, i8* %P, i32 %N ) ; <i32> [#uses=1]
+; CHECK-NOT: call {{.*}} memcmp
+; CHECK: store volatile
+ store volatile i32 %A, i32* %IP
+ %B = call i32 @memcmp( i8* %P, i8* %Q, i32 0 ) ; <i32> [#uses=1]
+; CHECK-NOT: call {{.*}} memcmp
+; CHECK: store volatile
+ store volatile i32 %B, i32* %IP
+ %C = call i32 @memcmp( i8* %P, i8* %Q, i32 1 ) ; <i32> [#uses=1]
+; CHECK: load
+; CHECK: zext
+; CHECK: load
+; CHECK: zext
+; CHECK: sub
+; CHECK: store volatile
+ store volatile i32 %C, i32* %IP
+ %F = call i32 @memcmp(i8* getelementptr ([4 x i8]* @hel, i32 0, i32 0),
+ i8* getelementptr ([8 x i8]* @hello_u, i32 0, i32 0),
+ i32 3)
+; CHECK-NOT: call {{.*}} memcmp
+; CHECK: store volatile
+ store volatile i32 %F, i32* %IP
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/memmove.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/memmove.ll
new file mode 100644
index 0000000..c0c0050
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/memmove.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -simplify-libcalls -S | grep {llvm.memmove}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+
+define i8* @test(i8* %a, i8* %b, i32 %x) {
+entry:
+ %call = call i8* @memmove(i8* %a, i8* %b, i32 %x )
+ ret i8* %call
+}
+
+declare i8* @memmove(i8*,i8*,i32)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/memset-64.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/memset-64.ll
new file mode 100644
index 0000000..fb752c4
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/memset-64.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -simplify-libcalls -S | grep {llvm.memset}
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-pc-linux-gnu"
+
+define void @a(i8* %x) nounwind {
+entry:
+ %call = call i8* @memset(i8* %x, i32 1, i64 100) ; <i8*> [#uses=0]
+ ret void
+}
+
+declare i8* @memset(i8*, i32, i64)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/memset.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/memset.ll
new file mode 100644
index 0000000..0aede06
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/memset.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -simplify-libcalls -S | grep {llvm.memset}
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i686-pc-linux-gnu"
+
+define i8* @test(i8* %a, i32 %b, i32 %x) {
+entry:
+ %call = call i8* @memset(i8* %a, i32 %b, i32 %x )
+ ret i8* %call
+}
+
+declare i8* @memset(i8*,i32,i32)
+
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/pow-to-sqrt.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/pow-to-sqrt.ll
new file mode 100644
index 0000000..0480fdd
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/pow-to-sqrt.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+; rdar://7251832
+
+; SimplifyLibcalls should optimize pow(x, 0.5) to sqrt plus code to handle
+; special cases. The readonly attribute on the call should be preserved.
+
+; CHECK: define float @foo(float %x) nounwind {
+; CHECK: %sqrtf = call float @sqrtf(float %x) nounwind readonly
+; CHECK: %fabsf = call float @fabsf(float %sqrtf) nounwind readonly
+; CHECK: %1 = fcmp oeq float %x, 0xFFF0000000000000
+; CHECK: %retval = select i1 %1, float 0x7FF0000000000000, float %fabsf
+; CHECK: ret float %retval
+
+define float @foo(float %x) nounwind {
+ %retval = call float @powf(float %x, float 0.5)
+ ret float %retval
+}
+
+; CHECK: define double @doo(double %x) nounwind {
+; CHECK: %sqrt = call double @sqrt(double %x) nounwind readonly
+; CHECK: %fabs = call double @fabs(double %sqrt) nounwind readonly
+; CHECK: %1 = fcmp oeq double %x, 0xFFF0000000000000
+; CHECK: %retval = select i1 %1, double 0x7FF0000000000000, double %fabs
+; CHECK: ret double %retval
+; CHECK: }
+
+define double @doo(double %x) nounwind {
+ %retval = call double @pow(double %x, double 0.5)
+ ret double %retval
+}
+
+declare float @powf(float, float) nounwind readonly
+declare double @pow(double, double) nounwind readonly
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/pow2.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/pow2.ll
new file mode 100644
index 0000000..f04156c
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/pow2.ll
@@ -0,0 +1,37 @@
+; Testcase for calls to the standard C "pow" function
+;
+; RUN: opt < %s -simplify-libcalls -S | not grep {call .pow}
+
+
+declare double @pow(double, double)
+declare float @powf(float, float)
+
+define double @test1(double %X) {
+ %Y = call double @pow( double %X, double 0.000000e+00 ) ; <double> [#uses=1]
+ ret double %Y
+}
+
+define double @test2(double %X) {
+ %Y = call double @pow( double %X, double -0.000000e+00 ) ; <double> [#uses=1]
+ ret double %Y
+}
+
+define double @test3(double %X) {
+ %Y = call double @pow( double 1.000000e+00, double %X ) ; <double> [#uses=1]
+ ret double %Y
+}
+
+define double @test4(double %X) {
+ %Y = call double @pow( double %X, double 2.0)
+ ret double %Y
+}
+
+define float @test4f(float %X) {
+ %Y = call float @powf( float %X, float 2.0)
+ ret float %Y
+}
+
+define float @test5f(float %X) {
+ %Y = call float @powf(float 2.0, float %X) ;; exp2
+ ret float %Y
+}
diff --git a/src/LLVM/test/Transforms/SimplifyLibCalls/weak-symbols.ll b/src/LLVM/test/Transforms/SimplifyLibCalls/weak-symbols.ll
new file mode 100644
index 0000000..5875b21
--- /dev/null
+++ b/src/LLVM/test/Transforms/SimplifyLibCalls/weak-symbols.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+; PR4738
+
+; SimplifyLibcalls shouldn't assume anything about weak symbols.
+
+@real_init = weak_odr constant [2 x i8] c"y\00"
+@fake_init = weak constant [2 x i8] c"y\00"
+@.str = private constant [2 x i8] c"y\00"
+
+; CHECK: define i32 @foo
+; CHECK: call i32 @strcmp
+define i32 @foo() nounwind {
+entry:
+ %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @fake_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly
+ ret i32 %t0
+}
+
+; CHECK: define i32 @bar
+; CHECK: ret i32 0
+define i32 @bar() nounwind {
+entry:
+ %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @real_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly
+ ret i32 %t0
+}
+
+declare i32 @strcmp(i8*, i8*) nounwind readonly
diff --git a/src/LLVM/test/Transforms/Sink/basic.ll b/src/LLVM/test/Transforms/Sink/basic.ll
new file mode 100644
index 0000000..2343372
--- /dev/null
+++ b/src/LLVM/test/Transforms/Sink/basic.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -basicaa -sink -S | FileCheck %s
+
+@A = external global i32
+@B = external global i32
+
+; Sink should sink the load past the store (which doesn't overlap) into
+; the block that uses it.
+
+; CHECK: @foo
+; CHECK: true:
+; CHECK-NEXT: %l = load i32* @A
+; CHECK-NEXT: ret i32 %l
+
+define i32 @foo(i1 %z) {
+ %l = load i32* @A
+ store i32 0, i32* @B
+ br i1 %z, label %true, label %false
+true:
+ ret i32 %l
+false:
+ ret i32 0
+}
+
+; But don't sink volatile loads...
+
+; CHECK: @foo2
+; CHECK: load volatile
+; CHECK-NEXT: store i32
+
+define i32 @foo2(i1 %z) {
+ %l = load volatile i32* @A
+ store i32 0, i32* @B
+ br i1 %z, label %true, label %false
+true:
+ ret i32 %l
+false:
+ ret i32 0
+}
diff --git a/src/LLVM/test/Transforms/Sink/dg.exp b/src/LLVM/test/Transforms/Sink/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/Sink/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll b/src/LLVM/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
new file mode 100644
index 0000000..69febc3
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -strip -S | grep foo | count 2
+; RUN: opt < %s -strip -S | grep bar | count 2
+@llvm.used = appending global [2 x i8*] [ i8* bitcast (i32* @foo to i8*), i8* bitcast (i32 ()* @bar to i8*) ], section "llvm.metadata" ; <[2 x i8*]*> [#uses=0]
+@foo = internal constant i32 41 ; <i32*> [#uses=1]
+
+define internal i32 @bar() nounwind {
+entry:
+ ret i32 42
+}
+
+define i32 @main() nounwind {
+entry:
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/StripSymbols/2010-06-30-StripDebug.ll b/src/LLVM/test/Transforms/StripSymbols/2010-06-30-StripDebug.ll
new file mode 100644
index 0000000..f5899d2
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/2010-06-30-StripDebug.ll
@@ -0,0 +1,28 @@
+; RUN: opt -strip-debug < %s | llvm-dis | grep -v llvm.dbg
+
+@x = common global i32 0 ; <i32*> [#uses=0]
+
+define void @foo() nounwind readnone optsize ssp {
+entry:
+ tail call void @llvm.dbg.value(metadata !9, i64 0, metadata !5), !dbg !10
+ ret void, !dbg !11
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+!llvm.dbg.sp = !{!0}
+!llvm.dbg.lv.foo = !{!5}
+!llvm.dbg.gv = !{!8}
+
+!0 = metadata !{i32 524334, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"foo", metadata !1, i32 2, metadata !3, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 true, void ()* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 524329, metadata !"b.c", metadata !"/tmp", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 524305, i32 0, i32 1, metadata !"b.c", metadata !"/tmp", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 true, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 524544, metadata !6, metadata !"y", metadata !1, i32 3, metadata !7} ; [ DW_TAG_auto_variable ]
+!6 = metadata !{i32 524299, metadata !0, i32 2, i32 0} ; [ DW_TAG_lexical_block ]
+!7 = metadata !{i32 524324, metadata !1, metadata !"int", metadata !1, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!8 = metadata !{i32 524340, i32 0, metadata !1, metadata !"x", metadata !"x", metadata !"", metadata !1, i32 1, metadata !7, i1 false, i1 true, i32* @x} ; [ DW_TAG_variable ]
+!9 = metadata !{i32 0}
+!10 = metadata !{i32 3, i32 0, metadata !6, null}
+!11 = metadata !{i32 4, i32 0, metadata !6, null}
diff --git a/src/LLVM/test/Transforms/StripSymbols/2010-07-01-DeadDbgInfo.ll b/src/LLVM/test/Transforms/StripSymbols/2010-07-01-DeadDbgInfo.ll
new file mode 100644
index 0000000..1df0351
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/2010-07-01-DeadDbgInfo.ll
@@ -0,0 +1,47 @@
+; RUN: opt -strip-dead-debug-info < %s | llvm-dis -o %t.ll
+; RUN: grep -v bar %t.ll
+; RUN: grep -v abcd %t.ll
+
+@xyz = global i32 2 ; <i32*> [#uses=1]
+
+declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
+
+define i32 @fn() nounwind readnone ssp {
+entry:
+ ret i32 0, !dbg !17
+}
+
+define i32 @foo(i32 %i) nounwind readonly ssp {
+entry:
+ tail call void @llvm.dbg.value(metadata !{i32 %i}, i64 0, metadata !14), !dbg !19
+ %.0 = load i32* @xyz, align 4 ; <i32> [#uses=1]
+ ret i32 %.0, !dbg !20
+}
+
+!llvm.dbg.sp = !{!0, !5, !9}
+!llvm.dbg.lv.bar = !{!12}
+!llvm.dbg.lv.foo = !{!14}
+!llvm.dbg.gv = !{!15, !16}
+
+!0 = metadata !{i32 524334, i32 0, metadata !1, metadata !"bar", metadata !"bar", metadata !"", metadata !1, i32 5, metadata !3, i1 true, i1 true, i32 0, i32 0, null, i1 false, i1 true, null} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 524329, metadata !"g.c", metadata !"/tmp/", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 524305, i32 0, i32 1, metadata !"g.c", metadata !"/tmp/", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 true, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{null}
+!5 = metadata !{i32 524334, i32 0, metadata !1, metadata !"fn", metadata !"fn", metadata !"fn", metadata !1, i32 6, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 true, i32 ()* @fn} ; [ DW_TAG_subprogram ]
+!6 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!7 = metadata !{metadata !8}
+!8 = metadata !{i32 524324, metadata !1, metadata !"int", metadata !1, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!9 = metadata !{i32 524334, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"foo", metadata !1, i32 7, metadata !10, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 true, i32 (i32)* @foo} ; [ DW_TAG_subprogram ]
+!10 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !11, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!11 = metadata !{metadata !8, metadata !8}
+!12 = metadata !{i32 524544, metadata !13, metadata !"bb", metadata !1, i32 5, metadata !8} ; [ DW_TAG_auto_variable ]
+!13 = metadata !{i32 524299, metadata !0, i32 5, i32 0} ; [ DW_TAG_lexical_block ]
+!14 = metadata !{i32 524545, metadata !9, metadata !"i", metadata !1, i32 7, metadata !8} ; [ DW_TAG_arg_variable ]
+!15 = metadata !{i32 524340, i32 0, metadata !1, metadata !"abcd", metadata !"abcd", metadata !"", metadata !1, i32 2, metadata !8, i1 true, i1 true, null} ; [ DW_TAG_variable ]
+!16 = metadata !{i32 524340, i32 0, metadata !1, metadata !"xyz", metadata !"xyz", metadata !"", metadata !1, i32 3, metadata !8, i1 false, i1 true, i32* @xyz} ; [ DW_TAG_variable ]
+!17 = metadata !{i32 6, i32 0, metadata !18, null}
+!18 = metadata !{i32 524299, metadata !5, i32 6, i32 0} ; [ DW_TAG_lexical_block ]
+!19 = metadata !{i32 7, i32 0, metadata !9, null}
+!20 = metadata !{i32 10, i32 0, metadata !21, null}
+!21 = metadata !{i32 524299, metadata !9, i32 7, i32 0} ; [ DW_TAG_lexical_block ]
diff --git a/src/LLVM/test/Transforms/StripSymbols/2010-08-25-crash.ll b/src/LLVM/test/Transforms/StripSymbols/2010-08-25-crash.ll
new file mode 100644
index 0000000..3965c37
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/2010-08-25-crash.ll
@@ -0,0 +1,19 @@
+; RUN: opt -strip-dead-debug-info -disable-output %s
+define i32 @foo() nounwind ssp {
+entry:
+ ret i32 0, !dbg !8
+}
+
+!llvm.dbg.sp = !{!0}
+!llvm.dbg.gv = !{!6}
+
+!0 = metadata !{i32 524334, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"foo", metadata !1, i32 3, metadata !3, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false, i32 ()* @foo} ; [ DW_TAG_subprogram ]
+!1 = metadata !{i32 524329, metadata !"/tmp/a.c", metadata !"/Volumes/Lalgate/clean/D.CW", metadata !2} ; [ DW_TAG_file_type ]
+!2 = metadata !{i32 524305, i32 0, i32 12, metadata !"/tmp/a.c", metadata !"/Volumes/Lalgate/clean/D.CW", metadata !"clang version 2.8 (trunk 112062)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
+!3 = metadata !{i32 524309, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !4, i32 0, null} ; [ DW_TAG_subroutine_type ]
+!4 = metadata !{metadata !5}
+!5 = metadata !{i32 524324, metadata !1, metadata !"int", metadata !1, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
+!6 = metadata !{i32 524340, i32 0, metadata !1, metadata !"i", metadata !"i", metadata !"i", metadata !1, i32 2, metadata !7, i1 true, i1 true, i32 0} ; [ DW_TAG_variable ]
+!7 = metadata !{i32 524326, metadata !1, metadata !"", metadata !1, i32 0, i64 0, i64 0, i64 0, i32 0, metadata !5} ; [ DW_TAG_const_type ]
+!8 = metadata !{i32 3, i32 13, metadata !9, null}
+!9 = metadata !{i32 524299, metadata !0, i32 3, i32 11, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
diff --git a/src/LLVM/test/Transforms/StripSymbols/block-address.ll b/src/LLVM/test/Transforms/StripSymbols/block-address.ll
new file mode 100644
index 0000000..d22c6b1
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/block-address.ll
@@ -0,0 +1,23 @@
+; RUN: opt %s -strip -S | FileCheck %s
+; PR10286
+
+@main_addrs = constant [2 x i8*] [i8* blockaddress(@f, %FOO), i8* blockaddress(@f, %BAR)]
+; CHECK: @main_addrs = constant [2 x i8*] [i8* blockaddress(@f, %2), i8* blockaddress(@f, %3)]
+
+declare void @foo() nounwind
+declare void @bar() nounwind
+
+define void @f(i8* %indirect.goto.dest) nounwind uwtable ssp {
+entry:
+ indirectbr i8* %indirect.goto.dest, [label %FOO, label %BAR]
+
+ ; CHECK: indirectbr i8* %0, [label %2, label %3]
+
+FOO:
+ call void @foo()
+ ret void
+
+BAR:
+ call void @bar()
+ ret void
+}
diff --git a/src/LLVM/test/Transforms/StripSymbols/dg.exp b/src/LLVM/test/Transforms/StripSymbols/dg.exp
new file mode 100644
index 0000000..f200589
--- /dev/null
+++ b/src/LLVM/test/Transforms/StripSymbols/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll b/src/LLVM/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
new file mode 100644
index 0000000..0626592
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+; PR7328
+; PR7506
+define i32 @foo(i32 %x) {
+; CHECK: define i32 @foo
+; CHECK: %accumulator.tr = phi i32 [ 1, %entry ], [ 0, %body ]
+entry:
+ %cond = icmp ugt i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %return, label %body
+
+body: ; preds = %entry
+ %y = add i32 %x, 1 ; <i32> [#uses=1]
+ %tmp = call i32 @foo(i32 %y) ; <i32> [#uses=0]
+; CHECK-NOT: call
+ ret i32 0
+; CHECK: ret i32 %accumulator.tr
+
+return: ; preds = %entry
+ ret i32 1
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/accum_recursion.ll b/src/LLVM/test/Transforms/TailCallElim/accum_recursion.ll
new file mode 100644
index 0000000..dd8c522
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/accum_recursion.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+
+define i32 @test1_factorial(i32 %x) {
+entry:
+ %tmp.1 = icmp sgt i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %then, label %else
+then: ; preds = %entry
+ %tmp.6 = add i32 %x, -1 ; <i32> [#uses=1]
+ %tmp.4 = call i32 @test1_factorial( i32 %tmp.6 ) ; <i32> [#uses=1]
+ %tmp.7 = mul i32 %tmp.4, %x ; <i32> [#uses=1]
+ ret i32 %tmp.7
+else: ; preds = %entry
+ ret i32 1
+}
+
+; CHECK: define i32 @test1_factorial
+; CHECK: phi i32
+; CHECK-NOT: call i32
+; CHECK: else:
+
+; This is a more aggressive form of accumulator recursion insertion, which
+; requires noticing that X doesn't change as we perform the tailcall.
+
+define i32 @test2_mul(i32 %x, i32 %y) {
+entry:
+ %tmp.1 = icmp eq i32 %y, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %return, label %endif
+endif: ; preds = %entry
+ %tmp.8 = add i32 %y, -1 ; <i32> [#uses=1]
+ %tmp.5 = call i32 @test2_mul( i32 %x, i32 %tmp.8 ) ; <i32> [#uses=1]
+ %tmp.9 = add i32 %tmp.5, %x ; <i32> [#uses=1]
+ ret i32 %tmp.9
+return: ; preds = %entry
+ ret i32 %x
+}
+
+; CHECK: define i32 @test2_mul
+; CHECK: phi i32
+; CHECK-NOT: call i32
+; CHECK: return:
+
+
+define i64 @test3_fib(i64 %n) nounwind readnone {
+; CHECK: @test3_fib
+entry:
+; CHECK: tailrecurse:
+; CHECK: %accumulator.tr = phi i64 [ %n, %entry ], [ %3, %bb1 ]
+; CHECK: %n.tr = phi i64 [ %n, %entry ], [ %2, %bb1 ]
+ switch i64 %n, label %bb1 [
+; CHECK: switch i64 %n.tr, label %bb1 [
+ i64 0, label %bb2
+ i64 1, label %bb2
+ ]
+
+bb1:
+; CHECK: bb1:
+ %0 = add i64 %n, -1
+; CHECK: %0 = add i64 %n.tr, -1
+ %1 = tail call i64 @test3_fib(i64 %0) nounwind
+; CHECK: %1 = tail call i64 @test3_fib(i64 %0)
+ %2 = add i64 %n, -2
+; CHECK: %2 = add i64 %n.tr, -2
+ %3 = tail call i64 @test3_fib(i64 %2) nounwind
+; CHECK-NOT: tail call i64 @test3_fib
+ %4 = add nsw i64 %3, %1
+; CHECK: add nsw i64 %accumulator.tr, %1
+ ret i64 %4
+; CHECK: br label %tailrecurse
+
+bb2:
+; CHECK: bb2:
+ ret i64 %n
+; CHECK: ret i64 %accumulator.tr
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/ackermann.ll b/src/LLVM/test/Transforms/TailCallElim/ackermann.ll
new file mode 100644
index 0000000..58247b7
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/ackermann.ll
@@ -0,0 +1,25 @@
+; This function contains two tail calls, which should be eliminated
+; RUN: opt < %s -tailcallelim -stats -disable-output |& grep {2 tailcallelim}
+
+define i32 @Ack(i32 %M.1, i32 %N.1) {
+entry:
+ %tmp.1 = icmp eq i32 %M.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %then.0, label %endif.0
+then.0: ; preds = %entry
+ %tmp.4 = add i32 %N.1, 1 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+endif.0: ; preds = %entry
+ %tmp.6 = icmp eq i32 %N.1, 0 ; <i1> [#uses=1]
+ br i1 %tmp.6, label %then.1, label %endif.1
+then.1: ; preds = %endif.0
+ %tmp.10 = add i32 %M.1, -1 ; <i32> [#uses=1]
+ %tmp.8 = call i32 @Ack( i32 %tmp.10, i32 1 ) ; <i32> [#uses=1]
+ ret i32 %tmp.8
+endif.1: ; preds = %endif.0
+ %tmp.13 = add i32 %M.1, -1 ; <i32> [#uses=1]
+ %tmp.17 = add i32 %N.1, -1 ; <i32> [#uses=1]
+ %tmp.14 = call i32 @Ack( i32 %M.1, i32 %tmp.17 ) ; <i32> [#uses=1]
+ %tmp.11 = call i32 @Ack( i32 %tmp.13, i32 %tmp.14 ) ; <i32> [#uses=1]
+ ret i32 %tmp.11
+}
+
diff --git a/src/LLVM/test/Transforms/TailCallElim/dg.exp b/src/LLVM/test/Transforms/TailCallElim/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
diff --git a/src/LLVM/test/Transforms/TailCallElim/dont-tce-tail-marked-call.ll b/src/LLVM/test/Transforms/TailCallElim/dont-tce-tail-marked-call.ll
new file mode 100644
index 0000000..48fa678
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/dont-tce-tail-marked-call.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -tailcallelim -S | \
+; RUN: grep {call i32 @foo}
+
+declare void @bar(i32*)
+
+define i32 @foo(i32 %N) {
+ %A = alloca i32, i32 %N ; <i32*> [#uses=2]
+ store i32 17, i32* %A
+ call void @bar( i32* %A )
+ %X = tail call i32 @foo( i32 %N ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/TailCallElim/dont_reorder_load.ll b/src/LLVM/test/Transforms/TailCallElim/dont_reorder_load.ll
new file mode 100644
index 0000000..899e115
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/dont_reorder_load.ll
@@ -0,0 +1,64 @@
+; RUN: opt < %s -tailcallelim -S | grep call | count 3
+; PR4323
+
+; Several cases where tail call elimination should not move the load above the
+; call, and thus can't eliminate the tail recursion.
+
+
+@extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
+
+
+; This load can't be safely moved above the call because the load is from an
+; extern_weak global and may trap, but the call may unwind before that happens.
+define fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 37
+
+else: ; preds = %entry
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = load i32* @extern_weak_global ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
+
+
+; This load can't be safely moved above the call because function may write to the pointer.
+define fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ store i32 1, i32* %a_arg
+ ret i32 0
+
+else: ; preds = %entry
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = load i32* %a_arg ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
+
+; This load can't be safely moved above the call because that would change the
+; order in which the volatile loads are performed.
+define fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 0
+
+else: ; preds = %entry
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = volatile load i32* %a_arg ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/dup_tail.ll b/src/LLVM/test/Transforms/TailCallElim/dup_tail.ll
new file mode 100644
index 0000000..9363880
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/dup_tail.ll
@@ -0,0 +1,23 @@
+; Duplicate the return into if.end to enable TCE.
+; RUN: opt %s -tailcallelim -stats -disable-output |& grep {Number of return duplicated}
+
+define i32 @fib(i32 %n) nounwind ssp {
+entry:
+ %cmp = icmp slt i32 %n, 2
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ br label %return
+
+if.end: ; preds = %entry
+ %sub = add nsw i32 %n, -2
+ %call = call i32 @fib(i32 %sub)
+ %sub3 = add nsw i32 %n, -1
+ %call4 = call i32 @fib(i32 %sub3)
+ %add = add nsw i32 %call, %call4
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %retval.0 = phi i32 [ 1, %if.then ], [ %add, %if.end ]
+ ret i32 %retval.0
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/inf-recursion.ll b/src/LLVM/test/Transforms/TailCallElim/inf-recursion.ll
new file mode 100644
index 0000000..c427869
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/inf-recursion.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+
+; Don't turn this into an infinite loop, this is probably the implementation
+; of fabs and we expect the codegen to lower fabs.
+; CHECK: @fabs(double %f)
+; CHECK: call
+; CHECK: ret
+
+define double @fabs(double %f) {
+entry:
+ %tmp2 = call double @fabs( double %f ) ; <double> [#uses=1]
+ ret double %tmp2
+}
+
+; Do turn other calls into infinite loops though.
+
+; CHECK: define double @foo
+; CHECK-NOT: call
+; CHECK: }
+define double @foo(double %f) {
+ %t= call double @foo(double %f)
+ ret double %t
+}
+
+; CHECK: define float @fabsf
+; CHECK-NOT: call
+; CHECK: }
+define float @fabsf(float %f) {
+ %t= call float @fabsf(float 2.0)
+ ret float %t
+}
+
+declare x86_fp80 @fabsl(x86_fp80 %f)
diff --git a/src/LLVM/test/Transforms/TailCallElim/intervening-inst.ll b/src/LLVM/test/Transforms/TailCallElim/intervening-inst.ll
new file mode 100644
index 0000000..e1eb0d6
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/intervening-inst.ll
@@ -0,0 +1,17 @@
+; This function contains intervening instructions which should be moved out of the way
+; RUN: opt < %s -tailcallelim -S | not grep call
+
+define i32 @Test(i32 %X) {
+entry:
+ %tmp.1 = icmp eq i32 %X, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %then.0, label %endif.0
+then.0: ; preds = %entry
+ %tmp.4 = add i32 %X, 1 ; <i32> [#uses=1]
+ ret i32 %tmp.4
+endif.0: ; preds = %entry
+ %tmp.10 = add i32 %X, -1 ; <i32> [#uses=1]
+ %tmp.8 = call i32 @Test( i32 %tmp.10 ) ; <i32> [#uses=1]
+ %DUMMY = add i32 %X, 1 ; <i32> [#uses=0]
+ ret i32 %tmp.8
+}
+
diff --git a/src/LLVM/test/Transforms/TailCallElim/move_alloca_for_tail_call.ll b/src/LLVM/test/Transforms/TailCallElim/move_alloca_for_tail_call.ll
new file mode 100644
index 0000000..fe44d99
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/move_alloca_for_tail_call.ll
@@ -0,0 +1,15 @@
+; RUN: opt -tailcallelim %s -S | FileCheck %s
+; PR615
+
+declare void @bar(i32*)
+
+define i32 @foo() {
+; CHECK: i32 @foo()
+; CHECK-NEXT: alloca
+ %A = alloca i32 ; <i32*> [#uses=2]
+ store i32 17, i32* %A
+ call void @bar( i32* %A )
+ %X = tail call i32 @foo( ) ; <i32> [#uses=1]
+ ret i32 %X
+}
+
diff --git a/src/LLVM/test/Transforms/TailCallElim/nocapture.ll b/src/LLVM/test/Transforms/TailCallElim/nocapture.ll
new file mode 100644
index 0000000..87cb9dd
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/nocapture.ll
@@ -0,0 +1,25 @@
+; RUN: opt %s -tailcallelim -S | FileCheck %s
+; XFAIL: *
+
+declare void @use(i8* nocapture, i8* nocapture)
+
+define i8* @foo(i8* nocapture %A, i1 %cond) {
+; CHECK: tailrecurse:
+; CHECK: %A.tr = phi i8* [ %A, %0 ], [ %B, %cond_true ]
+; CHECK: %cond.tr = phi i1 [ %cond, %0 ], [ false, %cond_true ]
+ %B = alloca i8
+; CHECK: %B = alloca i8
+ br i1 %cond, label %cond_true, label %cond_false
+; CHECK: br i1 %cond.tr, label %cond_true, label %cond_false
+cond_true:
+; CHECK: cond_true:
+; CHECK: br label %tailrecurse
+ call i8* @foo(i8* %B, i1 false)
+ ret i8* null
+cond_false:
+; CHECK: cond_false
+ call void @use(i8* %A, i8* %B)
+; CHECK: tail call void @use(i8* %A.tr, i8* %B)
+ ret i8* null
+; CHECK: ret i8* null
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/reorder_load.ll b/src/LLVM/test/Transforms/TailCallElim/reorder_load.ll
new file mode 100644
index 0000000..7f5c36e
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/reorder_load.ll
@@ -0,0 +1,101 @@
+; RUN: opt < %s -tailcallelim -S | not grep call
+; PR4323
+
+; Several cases where tail call elimination should move the load above the call,
+; then eliminate the tail recursion.
+
+
+@global = external global i32 ; <i32*> [#uses=1]
+@extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
+
+
+; This load can be moved above the call because the function won't write to it
+; and the call has no side effects.
+define fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 0
+
+else: ; preds = %entry
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = load i32* %a_arg ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
+
+
+; This load can be moved above the call because the function won't write to it
+; and the load provably can't trap.
+define fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 0
+
+else: ; preds = %entry
+ %nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
+ br i1 %nullcheck, label %unwind, label %recurse
+
+unwind: ; preds = %else
+ unreachable
+
+recurse: ; preds = %else
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = load i32* @global ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
+
+
+; This load can be safely moved above the call (even though it's from an
+; extern_weak global) because the call has no side effects.
+define fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 0
+
+else: ; preds = %entry
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
+ %tmp9 = load i32* @extern_weak_global ; <i32> [#uses=1]
+ %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
+
+
+; The second load can be safely moved above the call even though it's from an
+; unknown pointer (which normally means it might trap) because the first load
+; proves it doesn't trap.
+define fastcc i32 @raise_load_4(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
+entry:
+ %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
+ br i1 %tmp2, label %if, label %else
+
+if: ; preds = %entry
+ ret i32 0
+
+else: ; preds = %entry
+ %nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
+ br i1 %nullcheck, label %unwind, label %recurse
+
+unwind: ; preds = %else
+ unreachable
+
+recurse: ; preds = %else
+ %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
+ %first = load i32* %a_arg ; <i32> [#uses=1]
+ %tmp8 = call fastcc i32 @raise_load_4(i32* %a_arg, i32 %first, i32 %tmp7) ; <i32> [#uses=1]
+ %second = load i32* %a_arg ; <i32> [#uses=1]
+ %tmp10 = add i32 %second, %tmp8 ; <i32> [#uses=1]
+ ret i32 %tmp10
+}
diff --git a/src/LLVM/test/Transforms/TailCallElim/return_constant.ll b/src/LLVM/test/Transforms/TailCallElim/return_constant.ll
new file mode 100644
index 0000000..ff04332
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/return_constant.ll
@@ -0,0 +1,17 @@
+; Though this case seems to be fairly unlikely to occur in the wild, someone
+; plunked it into the demo script, so maybe they care about it.
+;
+; RUN: opt < %s -tailcallelim -S | not grep call
+
+define i32 @aaa(i32 %c) {
+entry:
+ %tmp.1 = icmp eq i32 %c, 0 ; <i1> [#uses=1]
+ br i1 %tmp.1, label %return, label %else
+else: ; preds = %entry
+ %tmp.5 = add i32 %c, -1 ; <i32> [#uses=1]
+ %tmp.3 = call i32 @aaa( i32 %tmp.5 ) ; <i32> [#uses=0]
+ ret i32 0
+return: ; preds = %entry
+ ret i32 0
+}
+
diff --git a/src/LLVM/test/Transforms/TailCallElim/setjmp.ll b/src/LLVM/test/Transforms/TailCallElim/setjmp.ll
new file mode 100644
index 0000000..7ef9cb3
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/setjmp.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+
+; Test that we don't tail call in a functions that calls returns_twice
+; functions.
+
+declare void @bar()
+
+; CHECK: foo1
+; CHECK-NOT: tail call void @bar()
+
+define void @foo1(i32* %x) {
+bb:
+ %tmp75 = tail call i32 @setjmp(i32* %x)
+ call void @bar()
+ ret void
+}
+
+declare i32 @setjmp(i32*)
+
+; CHECK: foo2
+; CHECK-NOT: tail call void @bar()
+
+define void @foo2(i32* %x) {
+bb:
+ %tmp75 = tail call i32 @zed2(i32* %x)
+ call void @bar()
+ ret void
+}
+declare i32 @zed2(i32*) returns_twice
diff --git a/src/LLVM/test/Transforms/TailCallElim/trivial_codegen_tailcall.ll b/src/LLVM/test/Transforms/TailCallElim/trivial_codegen_tailcall.ll
new file mode 100644
index 0000000..8ab7aa2
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailCallElim/trivial_codegen_tailcall.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -tailcallelim -S | \
+; RUN: grep {tail call void @foo}
+
+
+declare void @foo()
+
+define void @bar() {
+ call void @foo( )
+ ret void
+}
+
diff --git a/src/LLVM/test/Transforms/TailDup/2008-06-11-AvoidDupLoopHeader.ll b/src/LLVM/test/Transforms/TailDup/2008-06-11-AvoidDupLoopHeader.ll
new file mode 100644
index 0000000..03e99bc
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailDup/2008-06-11-AvoidDupLoopHeader.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -tailduplicate -taildup-threshold=3 -stats -disable-output |& not grep tailduplicate
+; XFAIL: *
+
+define i32 @foo(i32 %l) nounwind {
+entry:
+ %cond = icmp eq i32 %l, 1 ; <i1> [#uses=1]
+ br i1 %cond, label %bb, label %bb9
+
+bb: ; preds = %entry
+ br label %bb9
+
+bb5: ; preds = %bb9
+ %tmp7 = call i32 (...)* @bar( i32 %x.0 ) nounwind ; <i32> [#uses=1]
+ br label %bb9
+
+bb9: ; preds = %bb5, %bb, %entry
+ %x.0 = phi i32 [ 0, %entry ], [ %tmp7, %bb5 ], [ 1525, %bb ] ; <i32> [#uses=2]
+ %l_addr.0 = phi i32 [ %l, %entry ], [ %tmp11, %bb5 ], [ %l, %bb ] ; <i32> [#uses=1]
+ %tmp11 = add i32 %l_addr.0, -1 ; <i32> [#uses=2]
+ %tmp13 = icmp eq i32 %tmp11, -1 ; <i1> [#uses=1]
+ br i1 %tmp13, label %bb15, label %bb5
+
+bb15: ; preds = %bb9
+ ret i32 %x.0
+}
+
+declare i32 @bar(...)
diff --git a/src/LLVM/test/Transforms/TailDup/X86/dg.exp b/src/LLVM/test/Transforms/TailDup/X86/dg.exp
new file mode 100644
index 0000000..7b7bd4e
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailDup/X86/dg.exp
@@ -0,0 +1,5 @@
+load_lib llvm.exp
+
+if { [llvm_supports_target X86] } {
+ RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll}]]
+}
diff --git a/src/LLVM/test/Transforms/TailDup/dg.exp b/src/LLVM/test/Transforms/TailDup/dg.exp
new file mode 100644
index 0000000..f2e8f3b
--- /dev/null
+++ b/src/LLVM/test/Transforms/TailDup/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]