aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/Reassociate
diff options
context:
space:
mode:
authorDan Gohman <djg@cray.com>2007-07-18 16:29:46 +0000
committerDan Gohman <djg@cray.com>2007-07-18 16:29:46 +0000
commitf17a25c88b892d30c2b41ba7ecdfbdfb2b4be9cc (patch)
treeebb79ea1ee5e3bc1fdf38541a811a8b804f0679a /test/Transforms/Reassociate
downloadexternal_llvm-f17a25c88b892d30c2b41ba7ecdfbdfb2b4be9cc.zip
external_llvm-f17a25c88b892d30c2b41ba7ecdfbdfb2b4be9cc.tar.gz
external_llvm-f17a25c88b892d30c2b41ba7ecdfbdfb2b4be9cc.tar.bz2
It's not necessary to do rounding for alloca operations when the requested
alignment is equal to the stack alignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/Reassociate')
-rw-r--r--test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll8
-rw-r--r--test/Transforms/Reassociate/2002-05-15-MissedTree.ll8
-rw-r--r--test/Transforms/Reassociate/2002-05-15-SubReassociate.ll11
-rw-r--r--test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll12
-rw-r--r--test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll10
-rw-r--r--test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll10
-rw-r--r--test/Transforms/Reassociate/2005-08-24-Crash.ll12
-rw-r--r--test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll22
-rw-r--r--test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll7
-rw-r--r--test/Transforms/Reassociate/basictest.ll9
-rw-r--r--test/Transforms/Reassociate/basictest2.ll10
-rw-r--r--test/Transforms/Reassociate/basictest3.ll50
-rw-r--r--test/Transforms/Reassociate/basictest4.ll20
-rw-r--r--test/Transforms/Reassociate/dg.exp3
-rw-r--r--test/Transforms/Reassociate/inverses.ll25
-rw-r--r--test/Transforms/Reassociate/looptest.ll56
-rw-r--r--test/Transforms/Reassociate/mul-factor3.ll16
-rw-r--r--test/Transforms/Reassociate/mul-neg-add.ll9
-rw-r--r--test/Transforms/Reassociate/mulfactor.ll14
-rw-r--r--test/Transforms/Reassociate/mulfactor2.ll16
-rw-r--r--test/Transforms/Reassociate/negation.ll20
-rw-r--r--test/Transforms/Reassociate/otherops.ll28
-rw-r--r--test/Transforms/Reassociate/shift-factor.ll13
-rw-r--r--test/Transforms/Reassociate/shifttest.ll11
-rw-r--r--test/Transforms/Reassociate/subtest.ll10
25 files changed, 410 insertions, 0 deletions
diff --git a/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll
new file mode 100644
index 0000000..a7b0df1
--- /dev/null
+++ b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll
@@ -0,0 +1,8 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine -constprop -dce | llvm-dis | not grep add
+
+int %test(int %A) {
+ %X = add int %A, 1
+ %Y = add int %A, 1
+ %r = sub int %X, %Y
+ ret int %r ; Should be equal to 0!
+}
diff --git a/test/Transforms/Reassociate/2002-05-15-MissedTree.ll b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
new file mode 100644
index 0000000..176948a
--- /dev/null
+++ b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll
@@ -0,0 +1,8 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine -constprop -die | llvm-dis | not grep 5
+
+int %test(int %A, int %B) {
+ %W = add int %B, -5
+ %Y = add int %A, 5
+ %Z = add int %W, %Y
+ ret int %Z
+}
diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
new file mode 100644
index 0000000..be204e9
--- /dev/null
+++ b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll
@@ -0,0 +1,11 @@
+; With sub reassociation, constant folding can eliminate all of the constants.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -dce | llvm-dis | not grep add
+
+int %test(int %A, int %B) {
+ %W = add int 5, %B
+ %X = add int -7, %A
+ %Y = sub int %X, %W
+ %Z = add int %Y, 12
+ ret int %Z
+}
diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll
new file mode 100644
index 0000000..c46cc2e
--- /dev/null
+++ b/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll
@@ -0,0 +1,12 @@
+; With sub reassociation, constant folding can eliminate the two 12 constants.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -dce | llvm-dis | not grep 12
+
+int "test"(int %A, int %B, int %C, int %D) {
+ %M = add int %A, 12
+ %N = add int %M, %B
+ %O = add int %N, %C
+ %P = sub int %D, %O
+ %Q = add int %P, 12
+ ret int %Q
+}
diff --git a/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll b/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll
new file mode 100644
index 0000000..6a0ef53
--- /dev/null
+++ b/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll
@@ -0,0 +1,10 @@
+; The reassociate pass is not preserving dominance properties correctly
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate
+
+int %compute_dist(int %i, int %j) {
+ %reg119 = sub int %j, %i
+ ret int %reg119
+}
+
+
diff --git a/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll b/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll
new file mode 100644
index 0000000..a84297b
--- /dev/null
+++ b/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll
@@ -0,0 +1,10 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
+
+implementation ; Functions:
+
+int %test(int %A.1, int %B.1, int %C.1, int %D.1) {
+ %tmp.16 = and int %A.1, %B.1 ; <int> [#uses=1]
+ %tmp.18 = and int %tmp.16, %C.1 ; <int> [#uses=1]
+ %tmp.20 = and int %tmp.18, %D.1 ; <int> [#uses=1]
+ ret int %tmp.20
+}
diff --git a/test/Transforms/Reassociate/2005-08-24-Crash.ll b/test/Transforms/Reassociate/2005-08-24-Crash.ll
new file mode 100644
index 0000000..7e8e5d5
--- /dev/null
+++ b/test/Transforms/Reassociate/2005-08-24-Crash.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
+
+void %test(int %a, int %b, int %c, int %d) {
+ %tmp.2 = xor int %a, %b ; <int> [#uses=1]
+ %tmp.5 = xor int %c, %d ; <int> [#uses=1]
+ %tmp.6 = xor int %tmp.2, %tmp.5 ; <int> [#uses=1]
+ %tmp.9 = xor int %c, %a ; <int> [#uses=1]
+ %tmp.12 = xor int %b, %d ; <int> [#uses=1]
+ %tmp.13 = xor int %tmp.9, %tmp.12 ; <int> [#uses=1]
+ %tmp.16 = xor int %tmp.6, %tmp.13 ; <int> [#uses=0]
+ ret void
+}
diff --git a/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll
new file mode 100644
index 0000000..7ddad0b
--- /dev/null
+++ b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
+; RUN: grep {ret i32 0}
+
+int %f(int %a0, int %a1, int %a2, int %a3, int %a4) {
+ %tmp.2 = add int %a4, %a3 ; <int> [#uses=1]
+ %tmp.4 = add int %tmp.2, %a2 ; <int> [#uses=1]
+ %tmp.6 = add int %tmp.4, %a1 ; <int> [#uses=1]
+ %tmp.8 = add int %tmp.6, %a0 ; <int> [#uses=1]
+ %tmp.11 = add int %a3, %a2 ; <int> [#uses=1]
+ %tmp.13 = add int %tmp.11, %a1 ; <int> [#uses=1]
+ %tmp.15 = add int %tmp.13, %a0 ; <int> [#uses=1]
+ %tmp.18 = add int %a2, %a1 ; <int> [#uses=1]
+ %tmp.20 = add int %tmp.18, %a0 ; <int> [#uses=1]
+ %tmp.23 = add int %a1, %a0 ; <int> [#uses=1]
+ %tmp.26 = sub int %tmp.8, %tmp.15 ; <int> [#uses=1]
+ %tmp.28 = add int %tmp.26, %tmp.20 ; <int> [#uses=1]
+ %tmp.30 = sub int %tmp.28, %tmp.23 ; <int> [#uses=1]
+ %tmp.32 = sub int %tmp.30, %a4 ; <int> [#uses=1]
+ %tmp.34 = sub int %tmp.32, %a2 ; <int> [#uses=2]
+ %T = mul int %tmp.34, %tmp.34
+ ret int %T
+}
diff --git a/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll
new file mode 100644
index 0000000..2a5b5cd
--- /dev/null
+++ b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll
@@ -0,0 +1,7 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
+
+void %foo() {
+ %tmp162 = sub <4 x float> zeroinitializer, zeroinitializer
+ %tmp164 = mul <4 x float> zeroinitializer, %tmp162
+ ret void
+}
diff --git a/test/Transforms/Reassociate/basictest.ll b/test/Transforms/Reassociate/basictest.ll
new file mode 100644
index 0000000..a7ff84a
--- /dev/null
+++ b/test/Transforms/Reassociate/basictest.ll
@@ -0,0 +1,9 @@
+; With reassociation, constant folding can eliminate the 12 and -12 constants.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep add
+
+int %test(int %arg) {
+ %tmp1 = sub int -12, %arg
+ %tmp2 = add int %tmp1, 12
+ ret int %tmp2
+}
diff --git a/test/Transforms/Reassociate/basictest2.ll b/test/Transforms/Reassociate/basictest2.ll
new file mode 100644
index 0000000..7efa3cc
--- /dev/null
+++ b/test/Transforms/Reassociate/basictest2.ll
@@ -0,0 +1,10 @@
+; With reassociation, constant folding can eliminate the +/- 30 constants.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 30
+
+int "test"(int %reg109, int %reg1111) {
+ %reg115 = add int %reg109, -30 ; <int> [#uses=1]
+ %reg116 = add int %reg115, %reg1111 ; <int> [#uses=1]
+ %reg117 = add int %reg116, 30 ; <int> [#uses=1]
+ ret int %reg117
+}
diff --git a/test/Transforms/Reassociate/basictest3.ll b/test/Transforms/Reassociate/basictest3.ll
new file mode 100644
index 0000000..a3da5a0
--- /dev/null
+++ b/test/Transforms/Reassociate/basictest3.ll
@@ -0,0 +1,50 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -gcse | llvm-dis | grep add | wc -l | grep 6
+; Each of these functions should turn into two adds each.
+
+%e = external global int
+%a = external global int
+%b = external global int
+%c = external global int
+%f = external global int
+
+implementation
+
+void %test1() {
+ %A = load int* %a
+ %B = load int* %b
+ %C = load int* %c
+ %t1 = add int %A, %B
+ %t2 = add int %t1, %C
+ %t3 = add int %C, %A
+ %t4 = add int %t3, %B
+ store int %t2, int* %e ; e = (a+b)+c;
+ store int %t4, int* %f ; f = (a+c)+b
+ ret void
+}
+
+void %test2() {
+ %A = load int* %a
+ %B = load int* %b
+ %C = load int* %c
+ %t1 = add int %A, %B
+ %t2 = add int %t1, %C
+ %t3 = add int %C, %A
+ %t4 = add int %t3, %B
+ store int %t2, int* %e ; e = c+(a+b)
+ store int %t4, int* %f ; f = (c+a)+b
+ ret void
+}
+
+void %test3() {
+ %A = load int* %a
+ %B = load int* %b
+ %C = load int* %c
+ %t1 = add int %B, %A
+ %t2 = add int %t1, %C
+ %t3 = add int %C, %A
+ %t4 = add int %t3, %B
+ store int %t2, int* %e ; e = c+(b+a)
+ store int %t4, int* %f ; f = (c+a)+b
+ ret void
+}
+
diff --git a/test/Transforms/Reassociate/basictest4.ll b/test/Transforms/Reassociate/basictest4.ll
new file mode 100644
index 0000000..dcf7a55
--- /dev/null
+++ b/test/Transforms/Reassociate/basictest4.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -gcse -instcombine | llvm-dis | not grep add
+
+%a = weak global int 0
+%b = weak global int 0
+%c = weak global int 0
+%d = weak global int 0
+
+implementation
+
+int %foo() {
+ %tmp.0 = load int* %a
+ %tmp.1 = load int* %b
+ %tmp.2 = add int %tmp.0, %tmp.1 ; (a+b)
+ %tmp.4 = load int* %c
+ %tmp.5 = add int %tmp.2, %tmp.4 ; (a+b)+c
+ %tmp.8 = add int %tmp.0, %tmp.4 ; (a+c)
+ %tmp.11 = add int %tmp.8, %tmp.1 ; (a+c)+b
+ %RV = xor int %tmp.5, %tmp.11 ; X ^ X = 0
+ ret int %RV
+}
diff --git a/test/Transforms/Reassociate/dg.exp b/test/Transforms/Reassociate/dg.exp
new file mode 100644
index 0000000..879685c
--- /dev/null
+++ b/test/Transforms/Reassociate/dg.exp
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]
diff --git a/test/Transforms/Reassociate/inverses.ll b/test/Transforms/Reassociate/inverses.ll
new file mode 100644
index 0000000..e431328
--- /dev/null
+++ b/test/Transforms/Reassociate/inverses.ll
@@ -0,0 +1,25 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -dce | llvm-dis | \
+; RUN: not grep {\\(and\\|sub\\)}
+
+int %test1(int %a, int %b) {
+ %tmp.2 = and int %b, %a
+ %tmp.4 = xor int %a, -1
+ %tmp.5 = and int %tmp.2, %tmp.4 ; (A&B)&~A == 0
+ ret int %tmp.5
+}
+
+int %test2(int %a, int %b) {
+ %tmp.1 = and int %a, 1234
+ %tmp.2 = and int %b, %tmp.1
+ %tmp.4 = xor int %a, -1
+ %tmp.5 = and int %tmp.2, %tmp.4 ; A&~A == 0
+ ret int %tmp.5
+}
+
+int %test3(int %b, int %a) {
+ %tmp.1 = add int %a, 1234
+ %tmp.2 = add int %b, %tmp.1
+ %tmp.4 = sub int 0, %a
+ %tmp.5 = add int %tmp.2, %tmp.4 ; (b+(a+1234))+-a -> b+1234
+ ret int %tmp.5
+}
diff --git a/test/Transforms/Reassociate/looptest.ll b/test/Transforms/Reassociate/looptest.ll
new file mode 100644
index 0000000..97127bb
--- /dev/null
+++ b/test/Transforms/Reassociate/looptest.ll
@@ -0,0 +1,56 @@
+; 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: llvm-upgrade < %s | llvm-as | opt -reassociate | llvm-dis | grep 115 | not grep 117
+
+%.LC0 = internal global [4 x sbyte] c"%d\0A\00" ; <[4 x sbyte]*> [#uses=1]
+
+declare int "printf"(sbyte*, ...)
+
+void "test"(uint %Num, int* %Array) {
+bb0: ;[#uses=1]
+ %cond221 = seteq uint 0, %Num ; <bool> [#uses=3]
+ br bool %cond221, label %bb7, label %bb2
+
+bb2: ;[#uses=3]
+ %reg115 = phi uint [ %reg120, %bb6 ], [ 0, %bb0 ] ; <uint> [#uses=2]
+ br bool %cond221, label %bb6, label %bb3
+
+bb3: ;[#uses=3]
+ %reg116 = phi uint [ %reg119, %bb5 ], [ 0, %bb2 ] ; <uint> [#uses=2]
+ br bool %cond221, label %bb5, label %bb4
+
+bb4: ;[#uses=3]
+ %reg117 = phi uint [ %reg118, %bb4 ], [ 0, %bb3 ] ; <uint> [#uses=2]
+ %reg113 = add uint %reg115, %reg117 ; <uint> [#uses=1]
+ %reg114 = add uint %reg113, %reg116 ; <uint> [#uses=1]
+ %cast227 = getelementptr [4 x sbyte]* %.LC0, long 0, long 0 ; <sbyte*> [#uses=1]
+ call int (sbyte*, ...)* %printf( sbyte* %cast227, uint %reg114 ) ; <int>:0 [#uses=0]
+ %reg118 = add uint %reg117, 1 ; <uint> [#uses=2]
+ %cond224 = setne uint %reg118, %Num ; <bool> [#uses=1]
+ br bool %cond224, label %bb4, label %bb5
+
+bb5: ;[#uses=3]
+ %reg119 = add uint %reg116, 1 ; <uint> [#uses=2]
+ %cond225 = setne uint %reg119, %Num ; <bool> [#uses=1]
+ br bool %cond225, label %bb3, label %bb6
+
+bb6: ;[#uses=3]
+ %reg120 = add uint %reg115, 1 ; <uint> [#uses=2]
+ %cond226 = setne uint %reg120, %Num ; <bool> [#uses=1]
+ br bool %cond226, label %bb2, label %bb7
+
+bb7: ;[#uses=2]
+ ret void
+}
diff --git a/test/Transforms/Reassociate/mul-factor3.ll b/test/Transforms/Reassociate/mul-factor3.ll
new file mode 100644
index 0000000..1272ff6
--- /dev/null
+++ b/test/Transforms/Reassociate/mul-factor3.ll
@@ -0,0 +1,16 @@
+; This should be one add and two multiplies.
+
+; RUN: llvm-upgrade < %s | llvm-as | \
+; RUN: opt -reassociate -instcombine | llvm-dis > %t
+; RUN: grep mul %t | wc -l | grep 2
+; RUN: grep add %t | wc -l | grep 1
+
+int %test(int %A, int %B, int %C) {
+ %aa = mul int %A, %A
+ %aab = mul int %aa, %B
+
+ %ac = mul int %A, %C
+ %aac = mul int %ac, %A
+ %r = add int %aab, %aac
+ ret int %r
+}
diff --git a/test/Transforms/Reassociate/mul-neg-add.ll b/test/Transforms/Reassociate/mul-neg-add.ll
new file mode 100644
index 0000000..4219044
--- /dev/null
+++ b/test/Transforms/Reassociate/mul-neg-add.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
+; RUN: not grep {sub i32 0}
+
+int %test(int %X, int %Y, int %Z) {
+ %A = sub int 0, %X
+ %B = mul int %A, %Y
+ %C = add int %B, %Z ; (-X)*Y + Z -> Z-X*Y
+ ret int %C
+}
diff --git a/test/Transforms/Reassociate/mulfactor.ll b/test/Transforms/Reassociate/mulfactor.ll
new file mode 100644
index 0000000..bb7efc3
--- /dev/null
+++ b/test/Transforms/Reassociate/mulfactor.ll
@@ -0,0 +1,14 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | grep mul | wc -l | grep 2
+
+; This should have exactly 2 multiplies when we're done.
+
+int %f(int %a, int %b) {
+ %tmp.2 = mul int %a, %a
+ %tmp.5 = shl int %a, ubyte 1
+ %tmp.6 = mul int %tmp.5, %b
+ %tmp.10 = mul int %b, %b
+ %tmp.7 = add int %tmp.6, %tmp.2
+ %tmp.11 = add int %tmp.7, %tmp.10
+ ret int %tmp.11
+}
+
diff --git a/test/Transforms/Reassociate/mulfactor2.ll b/test/Transforms/Reassociate/mulfactor2.ll
new file mode 100644
index 0000000..dd1e8ae
--- /dev/null
+++ b/test/Transforms/Reassociate/mulfactor2.ll
@@ -0,0 +1,16 @@
+; This should turn into one multiply and one add.
+
+; RUN: llvm-upgrade < %s | llvm-as | \
+; RUN: opt -instcombine -reassociate -instcombine | llvm-dis -o %t
+; RUN: grep mul %t | wc -l | grep 1
+; RUN: grep add %t | wc -l | grep 1
+
+int %main(int %t) {
+ %tmp.3 = mul int %t, 12 ; <int> [#uses=1]
+ %tmp.4 = add int %tmp.3, 5 ; <int> [#uses=1]
+ %tmp.6 = mul int %t, 6 ; <int> [#uses=1]
+ %tmp.8 = mul int %tmp.4, 3 ; <int> [#uses=1]
+ %tmp.9 = add int %tmp.8, %tmp.6 ; <int> [#uses=1]
+ ret int %tmp.9
+}
+
diff --git a/test/Transforms/Reassociate/negation.ll b/test/Transforms/Reassociate/negation.ll
new file mode 100644
index 0000000..56e087a
--- /dev/null
+++ b/test/Transforms/Reassociate/negation.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | not grep sub
+
+; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
+
+int %test1(int %a, int %b, int %z) {
+ %c = sub int 0, %z
+ %d = mul int %a, %b
+ %e = mul int %c, %d
+ %f = mul int %e, 12345
+ %g = sub int 0, %f
+ ret int %g
+}
+
+int %test2(int %a, int %b, int %z) {
+ %d = mul int %z, 40
+ %c = sub int 0, %d
+ %e = mul int %a, %c
+ %f = sub int 0, %e
+ ret int %f
+}
diff --git a/test/Transforms/Reassociate/otherops.ll b/test/Transforms/Reassociate/otherops.ll
new file mode 100644
index 0000000..9e99d2c
--- /dev/null
+++ b/test/Transforms/Reassociate/otherops.ll
@@ -0,0 +1,28 @@
+; Reassociation should apply to Add, Mul, And, Or, & Xor
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 12
+
+int "test_mul"(int %arg) {
+ %tmp1 = mul int 12, %arg
+ %tmp2 = mul int %tmp1, 12
+ ret int %tmp2
+}
+
+int "test_and"(int %arg) {
+ %tmp1 = and int 14, %arg
+ %tmp2 = and int %tmp1, 14
+ ret int %tmp2
+}
+
+int "test_or"(int %arg) {
+ %tmp1 = or int 14, %arg
+ %tmp2 = or int %tmp1, 14
+ ret int %tmp2
+}
+
+int "test_xor"(int %arg) {
+ %tmp1 = xor int 12, %arg
+ %tmp2 = xor int %tmp1, 12
+ ret int %tmp2
+}
+
diff --git a/test/Transforms/Reassociate/shift-factor.ll b/test/Transforms/Reassociate/shift-factor.ll
new file mode 100644
index 0000000..ed8ed39
--- /dev/null
+++ b/test/Transforms/Reassociate/shift-factor.ll
@@ -0,0 +1,13 @@
+; There should be exactly one shift and one add left.
+; RUN: llvm-upgrade < %s | llvm-as | \
+; RUN: opt -reassociate -instcombine | llvm-dis > %t
+; RUN: grep shl %t | wc -l | grep 1
+; RUN: grep add %t | wc -l | grep 1
+
+int %test(int %X, int %Y) {
+ %tmp.2 = shl int %X, ubyte 1 ; <int> [#uses=1]
+ %tmp.6 = shl int %Y, ubyte 1 ; <int> [#uses=1]
+ %tmp.4 = add int %tmp.6, %tmp.2 ; <int> [#uses=1]
+ ret int %tmp.4
+}
+
diff --git a/test/Transforms/Reassociate/shifttest.ll b/test/Transforms/Reassociate/shifttest.ll
new file mode 100644
index 0000000..3603604
--- /dev/null
+++ b/test/Transforms/Reassociate/shifttest.ll
@@ -0,0 +1,11 @@
+; With shl->mul reassociation, we can see that this is (shl A, 9) * A
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
+; RUN: grep {shl .*, 9}
+
+int %test(int %A, int %B) {
+ %X = shl int %A, ubyte 5
+ %Y = shl int %A, ubyte 4
+ %Z = mul int %Y, %X
+ ret int %Z
+}
diff --git a/test/Transforms/Reassociate/subtest.ll b/test/Transforms/Reassociate/subtest.ll
new file mode 100644
index 0000000..097c355
--- /dev/null
+++ b/test/Transforms/Reassociate/subtest.ll
@@ -0,0 +1,10 @@
+; With sub reassociation, constant folding can eliminate the 12 and -12 constants.
+;
+; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 12
+
+int "test"(int %A, int %B) {
+ %X = add int -12, %A
+ %Y = sub int %X, %B
+ %Z = add int %Y, 12
+ ret int %Z
+}