llvm.org GIT mirror llvm / e1f5460
filecheckize git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92352 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
4 changed file(s) with 101 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
0 ; With reassociation, constant folding can eliminate the 12 and -12 constants.
11 ;
2 ; RUN: opt < %s -reassociate -constprop -instcombine -die -S | not grep add
2 ; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s
33
4 define i32 @test(i32 %arg) {
5 %tmp1 = sub i32 -12, %arg ; [#uses=1]
6 %tmp2 = add i32 %tmp1, 12 ; [#uses=1]
4 define i32 @test1(i32 %arg) {
5 %tmp1 = sub i32 -12, %arg
6 %tmp2 = add i32 %tmp1, 12
77 ret i32 %tmp2
8 ; CHECK: @test1
9 ; CHECK-NEXT: sub i32 0, %arg
10 ; CHECK-NEXT: ret i32
811 }
912
13 define i32 @test2(i32 %reg109, i32 %reg1111) {
14 %reg115 = add i32 %reg109, -30 ; [#uses=1]
15 %reg116 = add i32 %reg115, %reg1111 ; [#uses=1]
16 %reg117 = add i32 %reg116, 30 ; [#uses=1]
17 ret i32 %reg117
18 ; CHECK: @test2
19 ; CHECK-NEXT: add i32 %reg1111, %reg109
20 ; CHECK-NEXT: ret i32
21 }
22
23 @e = external global i32 ; [#uses=3]
24 @a = external global i32 ; [#uses=3]
25 @b = external global i32 ; [#uses=3]
26 @c = external global i32 ; [#uses=3]
27 @f = external global i32 ; [#uses=3]
28
29 define void @test3() {
30 %A = load i32* @a ; [#uses=2]
31 %B = load i32* @b ; [#uses=2]
32 %C = load i32* @c ; [#uses=2]
33 %t1 = add i32 %A, %B ; [#uses=1]
34 %t2 = add i32 %t1, %C ; [#uses=1]
35 %t3 = add i32 %C, %A ; [#uses=1]
36 %t4 = add i32 %t3, %B ; [#uses=1]
37 ; e = (a+b)+c;
38 store i32 %t2, i32* @e
39 ; f = (a+c)+b
40 store i32 %t4, i32* @f
41 ret void
42 ; CHECK: @test3
43 ; CHECK: add i32
44 ; CHECK: add i32
45 ; CHECK-NOT: add i32
46 ; CHECK: ret void
47 }
48
49 define void @test4() {
50 %A = load i32* @a ; [#uses=2]
51 %B = load i32* @b ; [#uses=2]
52 %C = load i32* @c ; [#uses=2]
53 %t1 = add i32 %A, %B ; [#uses=1]
54 %t2 = add i32 %t1, %C ; [#uses=1]
55 %t3 = add i32 %C, %A ; [#uses=1]
56 %t4 = add i32 %t3, %B ; [#uses=1]
57 ; e = c+(a+b)
58 store i32 %t2, i32* @e
59 ; f = (c+a)+b
60 store i32 %t4, i32* @f
61 ret void
62 ; CHECK: @test4
63 ; CHECK: add i32
64 ; CHECK: add i32
65 ; CHECK-NOT: add i32
66 ; CHECK: ret void
67 }
68
69 define void @test5() {
70 %A = load i32* @a ; [#uses=2]
71 %B = load i32* @b ; [#uses=2]
72 %C = load i32* @c ; [#uses=2]
73 %t1 = add i32 %B, %A ; [#uses=1]
74 %t2 = add i32 %t1, %C ; [#uses=1]
75 %t3 = add i32 %C, %A ; [#uses=1]
76 %t4 = add i32 %t3, %B ; [#uses=1]
77 ; e = c+(b+a)
78 store i32 %t2, i32* @e
79 ; f = (c+a)+b
80 store i32 %t4, i32* @f
81 ret void
82 ; CHECK: @test5
83 ; CHECK: add i32
84 ; CHECK: add i32
85 ; CHECK-NOT: add i32
86 ; CHECK: ret void
87 }
88
89 define i32 @test6() {
90 %tmp.0 = load i32* @a ; [#uses=2]
91 %tmp.1 = load i32* @b ; [#uses=2]
92 ; (a+b)
93 %tmp.2 = add i32 %tmp.0, %tmp.1 ; [#uses=1]
94 %tmp.4 = load i32* @c ; [#uses=2]
95 ; (a+b)+c
96 %tmp.5 = add i32 %tmp.2, %tmp.4 ; [#uses=1]
97 ; (a+c)
98 %tmp.8 = add i32 %tmp.0, %tmp.4 ; [#uses=1]
99 ; (a+c)+b
100 %tmp.11 = add i32 %tmp.8, %tmp.1 ; [#uses=1]
101 ; X ^ X = 0
102 %RV = xor i32 %tmp.5, %tmp.11 ; [#uses=1]
103 ret i32 %RV
104 ; CHECK: @test6
105 ; CHECK: ret i32 0
106 }
+0
-11
test/Transforms/Reassociate/basictest2.ll less more
None ; With reassociation, constant folding can eliminate the +/- 30 constants.
1 ;
2 ; RUN: opt < %s -reassociate -constprop -instcombine -die -S | not grep 30
3
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
9 }
10
+0
-54
test/Transforms/Reassociate/basictest3.ll less more
None ; RUN: opt < %s -reassociate -gvn -S | grep add | count 6
1 ; Each of these functions should turn into two adds each.
2
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]
8
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
22 }
23
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
37 }
38
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
52 }
53
+0
-23
test/Transforms/Reassociate/basictest4.ll less more
None ; RUN: opt < %s -reassociate -gvn -instcombine -S | not grep add
1
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]
6
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
22 }