llvm.org GIT mirror llvm / 7f40dea
Upgrade tests to not use llvm-upgrade. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48530 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 11 years ago
23 changed file(s) with 286 addition(s) and 271 deletion(s). Raw diff Collapse all Expand all
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine -constprop -dce | llvm-dis | not grep add
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine -constprop -dce | llvm-dis | not grep add
11
2 int %test(int %A) {
3 %X = add int %A, 1
4 %Y = add int %A, 1
5 %r = sub int %X, %Y
6 ret int %r ; Should be equal to 0!
2 define i32 @test(i32 %A) {
3 %X = add i32 %A, 1 ; [#uses=1]
4 %Y = add i32 %A, 1 ; [#uses=1]
5 %r = sub i32 %X, %Y ; [#uses=1]
6 ret i32 %r
77 }
8
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine -constprop -die | llvm-dis | not grep 5
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine -constprop -die | llvm-dis | not grep 5
11
2 int %test(int %A, int %B) {
3 %W = add int %B, -5
4 %Y = add int %A, 5
5 %Z = add int %W, %Y
6 ret int %Z
2 define i32 @test(i32 %A, i32 %B) {
3 %W = add i32 %B, -5 ; [#uses=1]
4 %Y = add i32 %A, 5 ; [#uses=1]
5 %Z = add i32 %W, %Y ; [#uses=1]
6 ret i32 %Z
77 }
8
0 ; With sub reassociation, constant folding can eliminate all of the constants.
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -dce | llvm-dis | not grep add
2 ; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -dce | llvm-dis | not grep add
33
4 int %test(int %A, int %B) {
5 %W = add int 5, %B
6 %X = add int -7, %A
7 %Y = sub int %X, %W
8 %Z = add int %Y, 12
9 ret int %Z
4 define i32 @test(i32 %A, i32 %B) {
5 %W = add i32 5, %B ; [#uses=1]
6 %X = add i32 -7, %A ; [#uses=1]
7 %Y = sub i32 %X, %W ; [#uses=1]
8 %Z = add i32 %Y, 12 ; [#uses=1]
9 ret i32 %Z
1010 }
11
0 ; With sub reassociation, constant folding can eliminate the two 12 constants.
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -dce | llvm-dis | not grep 12
2 ; RUN: llvm-as < %s | opt -reassociate -constprop -dce | llvm-dis | not grep 12
33
4 int "test"(int %A, int %B, int %C, int %D) {
5 %M = add int %A, 12
6 %N = add int %M, %B
7 %O = add int %N, %C
8 %P = sub int %D, %O
9 %Q = add int %P, 12
10 ret int %Q
4 define i32 @test(i32 %A, i32 %B, i32 %C, i32 %D) {
5 %M = add i32 %A, 12 ; [#uses=1]
6 %N = add i32 %M, %B ; [#uses=1]
7 %O = add i32 %N, %C ; [#uses=1]
8 %P = sub i32 %D, %O ; [#uses=1]
9 %Q = add i32 %P, 12 ; [#uses=1]
10 ret i32 %Q
1111 }
12
0 ; The reassociate pass is not preserving dominance properties correctly
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate
2 ; RUN: llvm-as < %s | opt -reassociate
33
4 int %compute_dist(int %i, int %j) {
5 %reg119 = sub int %j, %i
6 ret int %reg119
4 define i32 @compute_dist(i32 %i, i32 %j) {
5 %reg119 = sub i32 %j, %i ; [#uses=1]
6 ret i32 %reg119
77 }
88
99
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
0 ; RUN: llvm-as < %s | opt -reassociate -disable-output
11
2 implementation ; Functions:
2 define i32 @test(i32 %A.1, i32 %B.1, i32 %C.1, i32 %D.1) {
3 %tmp.16 = and i32 %A.1, %B.1 ; [#uses=1]
4 %tmp.18 = and i32 %tmp.16, %C.1 ; [#uses=1]
5 %tmp.20 = and i32 %tmp.18, %D.1 ; [#uses=1]
6 ret i32 %tmp.20
7 }
38
4 int %test(int %A.1, int %B.1, int %C.1, int %D.1) {
5 %tmp.16 = and int %A.1, %B.1 ; [#uses=1]
6 %tmp.18 = and int %tmp.16, %C.1 ; [#uses=1]
7 %tmp.20 = and int %tmp.18, %D.1 ; [#uses=1]
8 ret int %tmp.20
9 }
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
0 ; RUN: llvm-as < %s | opt -reassociate -disable-output
11
2 void %test(int %a, int %b, int %c, int %d) {
3 %tmp.2 = xor int %a, %b ; [#uses=1]
4 %tmp.5 = xor int %c, %d ; [#uses=1]
5 %tmp.6 = xor int %tmp.2, %tmp.5 ; [#uses=1]
6 %tmp.9 = xor int %c, %a ; [#uses=1]
7 %tmp.12 = xor int %b, %d ; [#uses=1]
8 %tmp.13 = xor int %tmp.9, %tmp.12 ; [#uses=1]
9 %tmp.16 = xor int %tmp.6, %tmp.13 ; [#uses=0]
2 define void @test(i32 %a, i32 %b, i32 %c, i32 %d) {
3 %tmp.2 = xor i32 %a, %b ; [#uses=1]
4 %tmp.5 = xor i32 %c, %d ; [#uses=1]
5 %tmp.6 = xor i32 %tmp.2, %tmp.5 ; [#uses=1]
6 %tmp.9 = xor i32 %c, %a ; [#uses=1]
7 %tmp.12 = xor i32 %b, %d ; [#uses=1]
8 %tmp.13 = xor i32 %tmp.9, %tmp.12 ; [#uses=1]
9 %tmp.16 = xor i32 %tmp.6, %tmp.13 ; [#uses=0]
1010 ret void
1111 }
12
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\
11 ; RUN: grep {ret i32 0}
22
3 int %f(int %a0, int %a1, int %a2, int %a3, int %a4) {
4 %tmp.2 = add int %a4, %a3 ; [#uses=1]
5 %tmp.4 = add int %tmp.2, %a2 ; [#uses=1]
6 %tmp.6 = add int %tmp.4, %a1 ; [#uses=1]
7 %tmp.8 = add int %tmp.6, %a0 ; [#uses=1]
8 %tmp.11 = add int %a3, %a2 ; [#uses=1]
9 %tmp.13 = add int %tmp.11, %a1 ; [#uses=1]
10 %tmp.15 = add int %tmp.13, %a0 ; [#uses=1]
11 %tmp.18 = add int %a2, %a1 ; [#uses=1]
12 %tmp.20 = add int %tmp.18, %a0 ; [#uses=1]
13 %tmp.23 = add int %a1, %a0 ; [#uses=1]
14 %tmp.26 = sub int %tmp.8, %tmp.15 ; [#uses=1]
15 %tmp.28 = add int %tmp.26, %tmp.20 ; [#uses=1]
16 %tmp.30 = sub int %tmp.28, %tmp.23 ; [#uses=1]
17 %tmp.32 = sub int %tmp.30, %a4 ; [#uses=1]
18 %tmp.34 = sub int %tmp.32, %a2 ; [#uses=2]
19 %T = mul int %tmp.34, %tmp.34
20 ret int %T
3 define i32 @f(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {
4 %tmp.2 = add i32 %a4, %a3 ; [#uses=1]
5 %tmp.4 = add i32 %tmp.2, %a2 ; [#uses=1]
6 %tmp.6 = add i32 %tmp.4, %a1 ; [#uses=1]
7 %tmp.8 = add i32 %tmp.6, %a0 ; [#uses=1]
8 %tmp.11 = add i32 %a3, %a2 ; [#uses=1]
9 %tmp.13 = add i32 %tmp.11, %a1 ; [#uses=1]
10 %tmp.15 = add i32 %tmp.13, %a0 ; [#uses=1]
11 %tmp.18 = add i32 %a2, %a1 ; [#uses=1]
12 %tmp.20 = add i32 %tmp.18, %a0 ; [#uses=1]
13 %tmp.23 = add i32 %a1, %a0 ; [#uses=1]
14 %tmp.26 = sub i32 %tmp.8, %tmp.15 ; [#uses=1]
15 %tmp.28 = add i32 %tmp.26, %tmp.20 ; [#uses=1]
16 %tmp.30 = sub i32 %tmp.28, %tmp.23 ; [#uses=1]
17 %tmp.32 = sub i32 %tmp.30, %a4 ; [#uses=1]
18 %tmp.34 = sub i32 %tmp.32, %a2 ; [#uses=2]
19 %T = mul i32 %tmp.34, %tmp.34 ; [#uses=1]
20 ret i32 %T
2121 }
22
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -disable-output
0 ; RUN: llvm-as < %s | opt -reassociate -disable-output
11
2 void %foo() {
3 %tmp162 = sub <4 x float> zeroinitializer, zeroinitializer
4 %tmp164 = mul <4 x float> zeroinitializer, %tmp162
2 define void @foo() {
3 %tmp162 = sub <4 x float> zeroinitializer, zeroinitializer ; <<4 x float>> [#uses=1]
4 %tmp164 = mul <4 x float> zeroinitializer, %tmp162 ; <<4 x float>> [#uses=0]
55 ret void
66 }
7
0 ; With reassociation, constant folding can eliminate the 12 and -12 constants.
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep add
2 ; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep add
33
4 int %test(int %arg) {
5 %tmp1 = sub int -12, %arg
6 %tmp2 = add int %tmp1, 12
7 ret int %tmp2
4 define i32 @test(i32 %arg) {
5 %tmp1 = sub i32 -12, %arg ; [#uses=1]
6 %tmp2 = add i32 %tmp1, 12 ; [#uses=1]
7 ret i32 %tmp2
88 }
9
0 ; With reassociation, constant folding can eliminate the +/- 30 constants.
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 30
2 ; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 30
33
4 int "test"(int %reg109, int %reg1111) {
5 %reg115 = add int %reg109, -30 ; [#uses=1]
6 %reg116 = add int %reg115, %reg1111 ; [#uses=1]
7 %reg117 = add int %reg116, 30 ; [#uses=1]
8 ret int %reg117
4 define i32 @test(i32 %reg109, i32 %reg1111) {
5 %reg115 = add i32 %reg109, -30 ; [#uses=1]
6 %reg116 = add i32 %reg115, %reg1111 ; [#uses=1]
7 %reg117 = add i32 %reg116, 30 ; [#uses=1]
8 ret i32 %reg117
99 }
10
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -gcse | llvm-dis | grep add | count 6
0 ; RUN: llvm-as < %s | opt -reassociate -gcse | llvm-dis | grep add | count 6
11 ; Each of these functions should turn into two adds each.
22
3 %e = external global int
4 %a = external global int
5 %b = external global int
6 %c = external global int
7 %f = external global int
3 @e = external global i32 ; [#uses=3]
4 @a = external global i32 ; [#uses=3]
5 @b = external global i32 ; [#uses=3]
6 @c = external global i32 ; [#uses=3]
7 @f = external global i32 ; [#uses=3]
88
9 implementation
10
11 void %test1() {
12 %A = load int* %a
13 %B = load int* %b
14 %C = load int* %c
15 %t1 = add int %A, %B
16 %t2 = add int %t1, %C
17 %t3 = add int %C, %A
18 %t4 = add int %t3, %B
19 store int %t2, int* %e ; e = (a+b)+c;
20 store int %t4, int* %f ; f = (a+c)+b
21 ret void
9 define void @test1() {
10 %A = load i32* @a ; [#uses=2]
11 %B = load i32* @b ; [#uses=2]
12 %C = load i32* @c ; [#uses=2]
13 %t1 = add i32 %A, %B ; [#uses=1]
14 %t2 = add i32 %t1, %C ; [#uses=1]
15 %t3 = add i32 %C, %A ; [#uses=1]
16 %t4 = add i32 %t3, %B ; [#uses=1]
17 ; e = (a+b)+c;
18 store i32 %t2, i32* @e
19 ; f = (a+c)+b
20 store i32 %t4, i32* @f
21 ret void
2222 }
2323
24 void %test2() {
25 %A = load int* %a
26 %B = load int* %b
27 %C = load int* %c
28 %t1 = add int %A, %B
29 %t2 = add int %t1, %C
30 %t3 = add int %C, %A
31 %t4 = add int %t3, %B
32 store int %t2, int* %e ; e = c+(a+b)
33 store int %t4, int* %f ; f = (c+a)+b
34 ret void
24 define void @test2() {
25 %A = load i32* @a ; [#uses=2]
26 %B = load i32* @b ; [#uses=2]
27 %C = load i32* @c ; [#uses=2]
28 %t1 = add i32 %A, %B ; [#uses=1]
29 %t2 = add i32 %t1, %C ; [#uses=1]
30 %t3 = add i32 %C, %A ; [#uses=1]
31 %t4 = add i32 %t3, %B ; [#uses=1]
32 ; e = c+(a+b)
33 store i32 %t2, i32* @e
34 ; f = (c+a)+b
35 store i32 %t4, i32* @f
36 ret void
3537 }
3638
37 void %test3() {
38 %A = load int* %a
39 %B = load int* %b
40 %C = load int* %c
41 %t1 = add int %B, %A
42 %t2 = add int %t1, %C
43 %t3 = add int %C, %A
44 %t4 = add int %t3, %B
45 store int %t2, int* %e ; e = c+(b+a)
46 store int %t4, int* %f ; f = (c+a)+b
47 ret void
39 define void @test3() {
40 %A = load i32* @a ; [#uses=2]
41 %B = load i32* @b ; [#uses=2]
42 %C = load i32* @c ; [#uses=2]
43 %t1 = add i32 %B, %A ; [#uses=1]
44 %t2 = add i32 %t1, %C ; [#uses=1]
45 %t3 = add i32 %C, %A ; [#uses=1]
46 %t4 = add i32 %t3, %B ; [#uses=1]
47 ; e = c+(b+a)
48 store i32 %t2, i32* @e
49 ; f = (c+a)+b
50 store i32 %t4, i32* @f
51 ret void
4852 }
4953
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -gcse -instcombine | llvm-dis | not grep add
0 ; RUN: llvm-as < %s | opt -reassociate -gcse -instcombine | llvm-dis | not grep add
11
2 %a = weak global int 0
3 %b = weak global int 0
4 %c = weak global int 0
5 %d = weak global int 0
2 @a = weak global i32 0 ; [#uses=1]
3 @b = weak global i32 0 ; [#uses=1]
4 @c = weak global i32 0 ; [#uses=1]
5 @d = weak global i32 0 ; [#uses=0]
66
7 implementation
8
9 int %foo() {
10 %tmp.0 = load int* %a
11 %tmp.1 = load int* %b
12 %tmp.2 = add int %tmp.0, %tmp.1 ; (a+b)
13 %tmp.4 = load int* %c
14 %tmp.5 = add int %tmp.2, %tmp.4 ; (a+b)+c
15 %tmp.8 = add int %tmp.0, %tmp.4 ; (a+c)
16 %tmp.11 = add int %tmp.8, %tmp.1 ; (a+c)+b
17 %RV = xor int %tmp.5, %tmp.11 ; X ^ X = 0
18 ret int %RV
7 define i32 @foo() {
8 %tmp.0 = load i32* @a ; [#uses=2]
9 %tmp.1 = load i32* @b ; [#uses=2]
10 ; (a+b)
11 %tmp.2 = add i32 %tmp.0, %tmp.1 ; [#uses=1]
12 %tmp.4 = load i32* @c ; [#uses=2]
13 ; (a+b)+c
14 %tmp.5 = add i32 %tmp.2, %tmp.4 ; [#uses=1]
15 ; (a+c)
16 %tmp.8 = add i32 %tmp.0, %tmp.4 ; [#uses=1]
17 ; (a+c)+b
18 %tmp.11 = add i32 %tmp.8, %tmp.1 ; [#uses=1]
19 ; X ^ X = 0
20 %RV = xor i32 %tmp.5, %tmp.11 ; [#uses=1]
21 ret i32 %RV
1922 }
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -dce | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -reassociate -dce | llvm-dis | \
11 ; RUN: not grep {\\(and\\|sub\\)}
22
3 int %test1(int %a, int %b) {
4 %tmp.2 = and int %b, %a
5 %tmp.4 = xor int %a, -1
6 %tmp.5 = and int %tmp.2, %tmp.4 ; (A&B)&~A == 0
7 ret int %tmp.5
3 define i32 @test1(i32 %a, i32 %b) {
4 %tmp.2 = and i32 %b, %a ; [#uses=1]
5 %tmp.4 = xor i32 %a, -1 ; [#uses=1]
6 ; (A&B)&~A == 0
7 %tmp.5 = and i32 %tmp.2, %tmp.4 ; [#uses=1]
8 ret i32 %tmp.5
89 }
910
10 int %test2(int %a, int %b) {
11 %tmp.1 = and int %a, 1234
12 %tmp.2 = and int %b, %tmp.1
13 %tmp.4 = xor int %a, -1
14 %tmp.5 = and int %tmp.2, %tmp.4 ; A&~A == 0
15 ret int %tmp.5
11 define i32 @test2(i32 %a, i32 %b) {
12 %tmp.1 = and i32 %a, 1234 ; [#uses=1]
13 %tmp.2 = and i32 %b, %tmp.1 ; [#uses=1]
14 %tmp.4 = xor i32 %a, -1 ; [#uses=1]
15 ; A&~A == 0
16 %tmp.5 = and i32 %tmp.2, %tmp.4 ; [#uses=1]
17 ret i32 %tmp.5
1618 }
1719
18 int %test3(int %b, int %a) {
19 %tmp.1 = add int %a, 1234
20 %tmp.2 = add int %b, %tmp.1
21 %tmp.4 = sub int 0, %a
22 %tmp.5 = add int %tmp.2, %tmp.4 ; (b+(a+1234))+-a -> b+1234
23 ret int %tmp.5
20 define i32 @test3(i32 %b, i32 %a) {
21 %tmp.1 = add i32 %a, 1234 ; [#uses=1]
22 %tmp.2 = add i32 %b, %tmp.1 ; [#uses=1]
23 %tmp.4 = sub i32 0, %a ; [#uses=1]
24 ; (b+(a+1234))+-a -> b+1234
25 %tmp.5 = add i32 %tmp.2, %tmp.4 ; [#uses=1]
26 ret i32 %tmp.5
2427 }
1111 ; In this case, we want to reassociate the specified expr so that i+j can be
1212 ; hoisted out of the inner most loop.
1313 ;
14 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate | llvm-dis | grep 115 | not grep 117
14 ; RUN: llvm-as < %s | opt -reassociate | llvm-dis | grep 115 | not grep 117
15 ; END.
16 @.LC0 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
1517
16 %.LC0 = internal global [4 x sbyte] c"%d\0A\00" ; <[4 x sbyte]*> [#uses=1]
18 declare i32 @printf(i8*, ...)
1719
18 declare int "printf"(sbyte*, ...)
19
20 void "test"(uint %Num, int* %Array) {
21 bb0: ;[#uses=1]
22 %cond221 = seteq uint 0, %Num ; [#uses=3]
23 br bool %cond221, label %bb7, label %bb2
24
25 bb2: ;[#uses=3]
26 %reg115 = phi uint [ %reg120, %bb6 ], [ 0, %bb0 ] ; [#uses=2]
27 br bool %cond221, label %bb6, label %bb3
28
29 bb3: ;[#uses=3]
30 %reg116 = phi uint [ %reg119, %bb5 ], [ 0, %bb2 ] ; [#uses=2]
31 br bool %cond221, label %bb5, label %bb4
32
33 bb4: ;[#uses=3]
34 %reg117 = phi uint [ %reg118, %bb4 ], [ 0, %bb3 ] ; [#uses=2]
35 %reg113 = add uint %reg115, %reg117 ; [#uses=1]
36 %reg114 = add uint %reg113, %reg116 ; [#uses=1]
37 %cast227 = getelementptr [4 x sbyte]* %.LC0, long 0, long 0 ; [#uses=1]
38 call int (sbyte*, ...)* %printf( sbyte* %cast227, uint %reg114 ) ; :0 [#uses=0]
39 %reg118 = add uint %reg117, 1 ; [#uses=2]
40 %cond224 = setne uint %reg118, %Num ; [#uses=1]
41 br bool %cond224, label %bb4, label %bb5
42
43 bb5: ;[#uses=3]
44 %reg119 = add uint %reg116, 1 ; [#uses=2]
45 %cond225 = setne uint %reg119, %Num ; [#uses=1]
46 br bool %cond225, label %bb3, label %bb6
47
48 bb6: ;[#uses=3]
49 %reg120 = add uint %reg115, 1 ; [#uses=2]
50 %cond226 = setne uint %reg120, %Num ; [#uses=1]
51 br bool %cond226, label %bb2, label %bb7
52
53 bb7: ;[#uses=2]
20 define void @test(i32 %Num, i32* %Array) {
21 bb0:
22 %cond221 = icmp eq i32 0, %Num ; [#uses=3]
23 br i1 %cond221, label %bb7, label %bb2
24 bb2: ; preds = %bb6, %bb0
25 %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; [#uses=2]
26 br i1 %cond221, label %bb6, label %bb3
27 bb3: ; preds = %bb5, %bb2
28 %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; [#uses=2]
29 br i1 %cond221, label %bb5, label %bb4
30 bb4: ; preds = %bb4, %bb3
31 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; [#uses=2]
32 %reg113 = add i32 %reg115, %reg117 ; [#uses=1]
33 %reg114 = add i32 %reg113, %reg116 ; [#uses=1]
34 %cast227 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0 ; [#uses=1]
35 call i32 (i8*, ...)* @printf( i8* %cast227, i32 %reg114 ) ; :0 [#uses=0]
36 %reg118 = add i32 %reg117, 1 ; [#uses=2]
37 %cond224 = icmp ne i32 %reg118, %Num ; [#uses=1]
38 br i1 %cond224, label %bb4, label %bb5
39 bb5: ; preds = %bb4, %bb3
40 %reg119 = add i32 %reg116, 1 ; [#uses=2]
41 %cond225 = icmp ne i32 %reg119, %Num ; [#uses=1]
42 br i1 %cond225, label %bb3, label %bb6
43 bb6: ; preds = %bb5, %bb2
44 %reg120 = add i32 %reg115, 1 ; [#uses=2]
45 %cond226 = icmp ne i32 %reg120, %Num ; [#uses=1]
46 br i1 %cond226, label %bb2, label %bb7
47 bb7: ; preds = %bb6, %bb0
5448 ret void
5549 }
0 ; This should be one add and two multiplies.
11
2 ; RUN: llvm-upgrade < %s | llvm-as | \
2 ; RUN: llvm-as < %s | \
33 ; RUN: opt -reassociate -instcombine | llvm-dis > %t
44 ; RUN: grep mul %t | count 2
55 ; RUN: grep add %t | count 1
66
7 int %test(int %A, int %B, int %C) {
8 %aa = mul int %A, %A
9 %aab = mul int %aa, %B
7 define i32 @test(i32 %A, i32 %B, i32 %C) {
8 %aa = mul i32 %A, %A ; [#uses=1]
9 %aab = mul i32 %aa, %B ; [#uses=1]
10 %ac = mul i32 %A, %C ; [#uses=1]
11 %aac = mul i32 %ac, %A ; [#uses=1]
12 %r = add i32 %aab, %aac ; [#uses=1]
13 ret i32 %r
14 }
1015
11 %ac = mul int %A, %C
12 %aac = mul int %ac, %A
13 %r = add int %aab, %aac
14 ret int %r
15 }
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\
11 ; RUN: not grep {sub i32 0}
22
3 int %test(int %X, int %Y, int %Z) {
4 %A = sub int 0, %X
5 %B = mul int %A, %Y
6 %C = add int %B, %Z ; (-X)*Y + Z -> Z-X*Y
7 ret int %C
3 define i32 @test(i32 %X, i32 %Y, i32 %Z) {
4 %A = sub i32 0, %X ; [#uses=1]
5 %B = mul i32 %A, %Y ; [#uses=1]
6 ; (-X)*Y + Z -> Z-X*Y
7 %C = add i32 %B, %Z ; [#uses=1]
8 ret i32 %C
89 }
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | grep mul | count 2
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | grep mul | count 2
11
22 ; This should have exactly 2 multiplies when we're done.
33
4 int %f(int %a, int %b) {
5 %tmp.2 = mul int %a, %a
6 %tmp.5 = shl int %a, ubyte 1
7 %tmp.6 = mul int %tmp.5, %b
8 %tmp.10 = mul int %b, %b
9 %tmp.7 = add int %tmp.6, %tmp.2
10 %tmp.11 = add int %tmp.7, %tmp.10
11 ret int %tmp.11
4 define i32 @f(i32 %a, i32 %b) {
5 %tmp.2 = mul i32 %a, %a ; [#uses=1]
6 %tmp.5 = shl i32 %a, 1 ; [#uses=1]
7 %tmp.6 = mul i32 %tmp.5, %b ; [#uses=1]
8 %tmp.10 = mul i32 %b, %b ; [#uses=1]
9 %tmp.7 = add i32 %tmp.6, %tmp.2 ; [#uses=1]
10 %tmp.11 = add i32 %tmp.7, %tmp.10 ; [#uses=1]
11 ret i32 %tmp.11
1212 }
1313
0 ; This should turn into one multiply and one add.
11
2 ; RUN: llvm-upgrade < %s | llvm-as | \
2 ; RUN: llvm-as < %s | \
33 ; RUN: opt -instcombine -reassociate -instcombine | llvm-dis -o %t
44 ; RUN: grep mul %t | count 1
55 ; RUN: grep add %t | count 1
66
7 int %main(int %t) {
8 %tmp.3 = mul int %t, 12 ; [#uses=1]
9 %tmp.4 = add int %tmp.3, 5 ; [#uses=1]
10 %tmp.6 = mul int %t, 6 ; [#uses=1]
11 %tmp.8 = mul int %tmp.4, 3 ; [#uses=1]
12 %tmp.9 = add int %tmp.8, %tmp.6 ; [#uses=1]
13 ret int %tmp.9
7 define i32 @main(i32 %t) {
8 %tmp.3 = mul i32 %t, 12 ; [#uses=1]
9 %tmp.4 = add i32 %tmp.3, 5 ; [#uses=1]
10 %tmp.6 = mul i32 %t, 6 ; [#uses=1]
11 %tmp.8 = mul i32 %tmp.4, 3 ; [#uses=1]
12 %tmp.9 = add i32 %tmp.8, %tmp.6 ; [#uses=1]
13 ret i32 %tmp.9
1414 }
1515
None ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis | not grep sub
0 ; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | not grep sub
11
22 ; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
33
4 int %test1(int %a, int %b, int %z) {
5 %c = sub int 0, %z
6 %d = mul int %a, %b
7 %e = mul int %c, %d
8 %f = mul int %e, 12345
9 %g = sub int 0, %f
10 ret int %g
4 define i32 @test1(i32 %a, i32 %b, i32 %z) {
5 %c = sub i32 0, %z ; [#uses=1]
6 %d = mul i32 %a, %b ; [#uses=1]
7 %e = mul i32 %c, %d ; [#uses=1]
8 %f = mul i32 %e, 12345 ; [#uses=1]
9 %g = sub i32 0, %f ; [#uses=1]
10 ret i32 %g
1111 }
1212
13 int %test2(int %a, int %b, int %z) {
14 %d = mul int %z, 40
15 %c = sub int 0, %d
16 %e = mul int %a, %c
17 %f = sub int 0, %e
18 ret int %f
13 define i32 @test2(i32 %a, i32 %b, i32 %z) {
14 %d = mul i32 %z, 40 ; [#uses=1]
15 %c = sub i32 0, %d ; [#uses=1]
16 %e = mul i32 %a, %c ; [#uses=1]
17 %f = sub i32 0, %e ; [#uses=1]
18 ret i32 %f
1919 }
20
0 ; Reassociation should apply to Add, Mul, And, Or, & Xor
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 12
2 ; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 12
33
4 int "test_mul"(int %arg) {
5 %tmp1 = mul int 12, %arg
6 %tmp2 = mul int %tmp1, 12
7 ret int %tmp2
4 define i32 @test_mul(i32 %arg) {
5 %tmp1 = mul i32 12, %arg ; [#uses=1]
6 %tmp2 = mul i32 %tmp1, 12 ; [#uses=1]
7 ret i32 %tmp2
88 }
99
10 int "test_and"(int %arg) {
11 %tmp1 = and int 14, %arg
12 %tmp2 = and int %tmp1, 14
13 ret int %tmp2
10 define i32 @test_and(i32 %arg) {
11 %tmp1 = and i32 14, %arg ; [#uses=1]
12 %tmp2 = and i32 %tmp1, 14 ; [#uses=1]
13 ret i32 %tmp2
1414 }
1515
16 int "test_or"(int %arg) {
17 %tmp1 = or int 14, %arg
18 %tmp2 = or int %tmp1, 14
19 ret int %tmp2
16 define i32 @test_or(i32 %arg) {
17 %tmp1 = or i32 14, %arg ; [#uses=1]
18 %tmp2 = or i32 %tmp1, 14 ; [#uses=1]
19 ret i32 %tmp2
2020 }
2121
22 int "test_xor"(int %arg) {
23 %tmp1 = xor int 12, %arg
24 %tmp2 = xor int %tmp1, 12
25 ret int %tmp2
22 define i32 @test_xor(i32 %arg) {
23 %tmp1 = xor i32 12, %arg ; [#uses=1]
24 %tmp2 = xor i32 %tmp1, 12 ; [#uses=1]
25 ret i32 %tmp2
2626 }
2727
0 ; There should be exactly one shift and one add left.
1 ; RUN: llvm-upgrade < %s | llvm-as | \
1 ; RUN: llvm-as < %s | \
22 ; RUN: opt -reassociate -instcombine | llvm-dis > %t
33 ; RUN: grep shl %t | count 1
44 ; RUN: grep add %t | count 1
55
6 int %test(int %X, int %Y) {
7 %tmp.2 = shl int %X, ubyte 1 ; [#uses=1]
8 %tmp.6 = shl int %Y, ubyte 1 ; [#uses=1]
9 %tmp.4 = add int %tmp.6, %tmp.2 ; [#uses=1]
10 ret int %tmp.4
6 define i32 @test(i32 %X, i32 %Y) {
7 %tmp.2 = shl i32 %X, 1 ; [#uses=1]
8 %tmp.6 = shl i32 %Y, 1 ; [#uses=1]
9 %tmp.4 = add i32 %tmp.6, %tmp.2 ; [#uses=1]
10 ret i32 %tmp.4
1111 }
1212
0 ; With shl->mul reassociation, we can see that this is (shl A, 9) * A
11 ;
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -reassociate -instcombine | llvm-dis |\
2 ; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\
33 ; RUN: grep {shl .*, 9}
44
5 int %test(int %A, int %B) {
6 %X = shl int %A, ubyte 5
7 %Y = shl int %A, ubyte 4
8 %Z = mul int %Y, %X
9 ret int %Z
5 define i32 @test(i32 %A, i32 %B) {
6 %X = shl i32 %A, 5 ; [#uses=1]
7 %Y = shl i32 %A, 4 ; [#uses=1]
8 %Z = mul i32 %Y, %X ; [#uses=1]
9 ret i32 %Z
1010 }
11