llvm.org GIT mirror llvm / ed7df98
[Reassociate] regenerate checks; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336211 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 2 months ago
1 changed file(s) with 115 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s
12 ; RUN: opt < %s -passes='reassociate,gvn,instcombine' -S | FileCheck %s
23
34 define i32 @test1(i32 %arg) {
5 ; CHECK-LABEL: @test1(
6 ; CHECK-NEXT: [[ARG_NEG:%.*]] = sub i32 0, [[ARG:%.*]]
7 ; CHECK-NEXT: ret i32 [[ARG_NEG]]
8 ;
49 %tmp1 = sub i32 -12, %arg
510 %tmp2 = add i32 %tmp1, 12
611 ret i32 %tmp2
7
8 ; CHECK-LABEL: @test1
9 ; CHECK-NEXT: sub i32 0, %arg
10 ; CHECK-NEXT: ret i32
1112 }
1213
1314 define i32 @test2(i32 %reg109, i32 %reg1111) {
15 ; CHECK-LABEL: @test2(
16 ; CHECK-NEXT: [[REG117:%.*]] = add i32 [[REG1111:%.*]], [[REG109:%.*]]
17 ; CHECK-NEXT: ret i32 [[REG117]]
18 ;
1419 %reg115 = add i32 %reg109, -30
1520 %reg116 = add i32 %reg115, %reg1111
1621 %reg117 = add i32 %reg116, 30
1722 ret i32 %reg117
18
19 ; CHECK-LABEL: @test2
20 ; CHECK-NEXT: %reg117 = add i32 %reg1111, %reg109
21 ; CHECK-NEXT: ret i32 %reg117
2223 }
2324
2425 @e = external global i32
2829 @f = external global i32
2930
3031 define void @test3() {
32 ; CHECK-LABEL: @test3(
33 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* @a, align 4
34 ; CHECK-NEXT: [[B:%.*]] = load i32, i32* @b, align 4
35 ; CHECK-NEXT: [[C:%.*]] = load i32, i32* @c, align 4
36 ; CHECK-NEXT: [[T1:%.*]] = add i32 [[B]], [[A]]
37 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], [[C]]
38 ; CHECK-NEXT: store i32 [[T2]], i32* @e, align 4
39 ; CHECK-NEXT: store i32 [[T2]], i32* @f, align 4
40 ; CHECK-NEXT: ret void
41 ;
3142 %A = load i32, i32* @a
3243 %B = load i32, i32* @b
3344 %C = load i32, i32* @c
4051 ; f = (a+c)+b
4152 store i32 %t4, i32* @f
4253 ret void
43
44 ; CHECK-LABEL: @test3
45 ; CHECK: add i32
46 ; CHECK: add i32
47 ; CHECK-NOT: add i32
48 ; CHECK: ret void
4954 }
5055
5156 define void @test4() {
57 ; CHECK-LABEL: @test4(
58 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* @a, align 4
59 ; CHECK-NEXT: [[B:%.*]] = load i32, i32* @b, align 4
60 ; CHECK-NEXT: [[C:%.*]] = load i32, i32* @c, align 4
61 ; CHECK-NEXT: [[T1:%.*]] = add i32 [[B]], [[A]]
62 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], [[C]]
63 ; CHECK-NEXT: store i32 [[T2]], i32* @e, align 4
64 ; CHECK-NEXT: store i32 [[T2]], i32* @f, align 4
65 ; CHECK-NEXT: ret void
66 ;
5267 %A = load i32, i32* @a
5368 %B = load i32, i32* @b
5469 %C = load i32, i32* @c
6176 ; f = (c+a)+b
6277 store i32 %t4, i32* @f
6378 ret void
64
65 ; CHECK-LABEL: @test4
66 ; CHECK: add i32
67 ; CHECK: add i32
68 ; CHECK-NOT: add i32
69 ; CHECK: ret void
7079 }
7180
7281 define void @test5() {
82 ; CHECK-LABEL: @test5(
83 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* @a, align 4
84 ; CHECK-NEXT: [[B:%.*]] = load i32, i32* @b, align 4
85 ; CHECK-NEXT: [[C:%.*]] = load i32, i32* @c, align 4
86 ; CHECK-NEXT: [[T1:%.*]] = add i32 [[B]], [[A]]
87 ; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], [[C]]
88 ; CHECK-NEXT: store i32 [[T2]], i32* @e, align 4
89 ; CHECK-NEXT: store i32 [[T2]], i32* @f, align 4
90 ; CHECK-NEXT: ret void
91 ;
7392 %A = load i32, i32* @a
7493 %B = load i32, i32* @b
7594 %C = load i32, i32* @c
82101 ; f = (c+a)+b
83102 store i32 %t4, i32* @f
84103 ret void
85
86 ; CHECK-LABEL: @test5
87 ; CHECK: add i32
88 ; CHECK: add i32
89 ; CHECK-NOT: add i32
90 ; CHECK: ret void
91104 }
92105
93106 define i32 @test6() {
107 ; CHECK-LABEL: @test6(
108 ; CHECK-NEXT: ret i32 0
109 ;
94110 %tmp.0 = load i32, i32* @a
95111 %tmp.1 = load i32, i32* @b
96112 ; (a+b)
105121 ; X ^ X = 0
106122 %RV = xor i32 %tmp.5, %tmp.11
107123 ret i32 %RV
108
109 ; CHECK-LABEL: @test6
110 ; CHECK: ret i32 0
111124 }
112125
113126 ; This should be one add and two multiplies.
127 ; A*A*B + A*C*A
128
114129 define i32 @test7(i32 %A, i32 %B, i32 %C) {
115 ; A*A*B + A*C*A
130 ; CHECK-LABEL: @test7(
131 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = add i32 [[C:%.*]], [[B:%.*]]
132 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = mul i32 [[A:%.*]], [[A]]
133 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_MUL2]], [[REASS_ADD1]]
134 ; CHECK-NEXT: ret i32 [[REASS_MUL]]
135 ;
116136 %aa = mul i32 %A, %A
117137 %aab = mul i32 %aa, %B
118138 %ac = mul i32 %A, %C
119139 %aac = mul i32 %ac, %A
120140 %r = add i32 %aab, %aac
121141 ret i32 %r
122
123 ; CHECK-LABEL: @test7
124 ; CHECK-NEXT: add i32 %C, %B
125 ; CHECK-NEXT: mul i32
126 ; CHECK-NEXT: mul i32
127 ; CHECK-NEXT: ret i32
128142 }
129143
130144 define i32 @test8(i32 %X, i32 %Y, i32 %Z) {
145 ; CHECK-LABEL: @test8(
146 ; CHECK-NEXT: [[A:%.*]] = mul i32 [[Y:%.*]], [[X:%.*]]
147 ; CHECK-NEXT: [[C:%.*]] = sub i32 [[Z:%.*]], [[A]]
148 ; CHECK-NEXT: ret i32 [[C]]
149 ;
131150 %A = sub i32 0, %X
132151 %B = mul i32 %A, %Y
133152 ; (-X)*Y + Z -> Z-X*Y
134153 %C = add i32 %B, %Z
135154 ret i32 %C
136
137 ; CHECK-LABEL: @test8
138 ; CHECK-NEXT: %A = mul i32 %Y, %X
139 ; CHECK-NEXT: %C = sub i32 %Z, %A
140 ; CHECK-NEXT: ret i32 %C
141155 }
142156
143157 ; PR5458
158
144159 define i32 @test9(i32 %X) {
160 ; CHECK-LABEL: @test9(
161 ; CHECK-NEXT: [[FACTOR:%.*]] = mul i32 [[X:%.*]], 94
162 ; CHECK-NEXT: ret i32 [[FACTOR]]
163 ;
145164 %Y = mul i32 %X, 47
146165 %Z = add i32 %Y, %Y
147166 ret i32 %Z
148 ; CHECK-LABEL: @test9
149 ; CHECK-NEXT: mul i32 %X, 94
150 ; CHECK-NEXT: ret i32
151167 }
152168
153169 define i32 @test10(i32 %X) {
170 ; CHECK-LABEL: @test10(
171 ; CHECK-NEXT: [[FACTOR:%.*]] = mul i32 [[X:%.*]], 3
172 ; CHECK-NEXT: ret i32 [[FACTOR]]
173 ;
154174 %Y = add i32 %X ,%X
155175 %Z = add i32 %Y, %X
156176 ret i32 %Z
157 ; CHECK-LABEL: @test10
158 ; CHECK-NEXT: mul i32 %X, 3
159 ; CHECK-NEXT: ret i32
160177 }
161178
162179 define i32 @test11(i32 %W) {
180 ; CHECK-LABEL: @test11(
181 ; CHECK-NEXT: [[FACTOR:%.*]] = mul i32 [[W:%.*]], 381
182 ; CHECK-NEXT: ret i32 [[FACTOR]]
183 ;
163184 %X = mul i32 %W, 127
164185 %Y = add i32 %X ,%X
165186 %Z = add i32 %Y, %X
166187 ret i32 %Z
167 ; CHECK-LABEL: @test11
168 ; CHECK-NEXT: mul i32 %W, 381
169 ; CHECK-NEXT: ret i32
170188 }
171189
172190 declare void @mumble(i32)
173191
174192 define i32 @test12(i32 %X) {
193 ; CHECK-LABEL: @test12(
194 ; CHECK-NEXT: [[X_NEG:%.*]] = sub i32 0, [[X:%.*]]
195 ; CHECK-NEXT: call void @mumble(i32 [[X_NEG]])
196 ; CHECK-NEXT: [[FACTOR:%.*]] = mul i32 [[X]], -3
197 ; CHECK-NEXT: [[Z:%.*]] = add i32 [[FACTOR]], 6
198 ; CHECK-NEXT: ret i32 [[Z]]
199 ;
175200 %X.neg = sub nsw nuw i32 0, %X
176201 call void @mumble(i32 %X.neg)
177202 %A = sub i32 1, %X
180205 %Y = add i32 %A ,%B
181206 %Z = add i32 %Y, %C
182207 ret i32 %Z
183 ; CHECK-LABEL: @test12
184 ; CHECK: %[[mul:.*]] = mul i32 %X, -3
185 ; CHECK-NEXT: add i32 %[[mul]], 6
186 ; CHECK-NEXT: ret i32
187208 }
188209
189210 define i32 @test13(i32 %X1, i32 %X2, i32 %X3) {
211 ; CHECK-LABEL: @test13(
212 ; CHECK-NEXT: [[REASS_ADD:%.*]] = sub i32 [[X3:%.*]], [[X2:%.*]]
213 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], [[X1:%.*]]
214 ; CHECK-NEXT: ret i32 [[REASS_MUL]]
215 ;
190216 %A = sub i32 0, %X1
191217 %B = mul i32 %A, %X2 ; -X1*X2
192218 %C = mul i32 %X1, %X3 ; X1*X3
193219 %D = add i32 %B, %C ; -X1*X2 + X1*X3 -> X1*(X3-X2)
194220 ret i32 %D
195 ; CHECK-LABEL: @test13
196 ; CHECK-NEXT: sub i32 %X3, %X2
197 ; CHECK-NEXT: mul i32 {{.*}}, %X1
198 ; CHECK-NEXT: ret i32
199221 }
200222
201223 ; PR5359
224
202225 define i32 @test14(i32 %X1, i32 %X2) {
226 ; CHECK-LABEL: @test14(
227 ; CHECK-NEXT: [[REASS_ADD:%.*]] = sub i32 [[X1:%.*]], [[X2:%.*]]
228 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], 47
229 ; CHECK-NEXT: ret i32 [[REASS_MUL]]
230 ;
203231 %B = mul i32 %X1, 47 ; X1*47
204232 %C = mul i32 %X2, -47 ; X2*-47
205233 %D = add i32 %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2)
206234 ret i32 %D
207
208 ; CHECK-LABEL: @test14
209 ; CHECK-NEXT: %[[SUB:.*]] = sub i32 %X1, %X2
210 ; CHECK-NEXT: mul i32 %[[SUB]], 47
211 ; CHECK-NEXT: ret i32
212235 }
213236
214237 ; Do not reassociate expressions of type i1
238
215239 define i32 @test15(i32 %X1, i32 %X2, i32 %X3) {
240 ; CHECK-LABEL: @test15(
241 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X1:%.*]], 0
242 ; CHECK-NEXT: [[B:%.*]] = icmp slt i32 [[X2:%.*]], [[X3:%.*]]
243 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
244 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X1]], i32 0
245 ; CHECK-NEXT: ret i32 [[D]]
246 ;
216247 %A = icmp ne i32 %X1, 0
217248 %B = icmp slt i32 %X2, %X3
218249 %C = and i1 %A, %B
219250 %D = select i1 %C, i32 %X1, i32 0
220251 ret i32 %D
221 ; CHECK-LABEL: @test15
222 ; CHECK: and i1 %A, %B
223252 }
224253
225254 ; PR30256 - previously this asserted.
226 ; CHECK-LABEL: @test16
227 ; CHECK: %[[FACTOR:.*]] = mul i64 %a, -4
228 ; CHECK-NEXT: %[[RES:.*]] = add i64 %[[FACTOR]], %b
229 ; CHECK-NEXT: ret i64 %[[RES]]
255
230256 define i64 @test16(i1 %cmp, i64 %a, i64 %b) {
257 ; CHECK-LABEL: @test16(
258 ; CHECK-NEXT: entry:
259 ; CHECK-NEXT: br i1 [[CMP:%.*]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
260 ; CHECK: if.then:
261 ; CHECK-NEXT: [[FACTOR:%.*]] = mul i64 [[A:%.*]], -4
262 ; CHECK-NEXT: [[ADD2:%.*]] = add i64 [[FACTOR]], [[B:%.*]]
263 ; CHECK-NEXT: ret i64 [[ADD2]]
264 ; CHECK: if.end:
265 ; CHECK-NEXT: ret i64 0
266 ;
231267 entry:
232268 %shl = shl i64 %a, 1
233269 %shl.neg = sub i64 0, %shl
234270 br i1 %cmp, label %if.then, label %if.end
235271
236 if.then: ; preds = %entry
272 if.then:
237273 %add1 = add i64 %shl.neg, %shl.neg
238274 %add2 = add i64 %add1, %b
239275 ret i64 %add2
240276
241 if.end: ; preds = %entry
277 if.end:
242278 ret i64 0
243279 }
244280
245 ; CHECK-LABEL: @test17
246 ; CHECK: %[[A:.*]] = mul i32 %X4, %X3
247 ; CHECK-NEXT: %[[C:.*]] = mul i32 %[[A]], %X1
248 ; CHECK-NEXT: %[[D:.*]] = mul i32 %[[A]], %X2
249 ; CHECK-NEXT: %[[E:.*]] = xor i32 %[[C]], %[[D]]
250 ; CHECK-NEXT: ret i32 %[[E]]
251281 define i32 @test17(i32 %X1, i32 %X2, i32 %X3, i32 %X4) {
282 ; CHECK-LABEL: @test17(
283 ; CHECK-NEXT: [[A:%.*]] = mul i32 [[X4:%.*]], [[X3:%.*]]
284 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A]], [[X1:%.*]]
285 ; CHECK-NEXT: [[D:%.*]] = mul i32 [[A]], [[X2:%.*]]
286 ; CHECK-NEXT: [[E:%.*]] = xor i32 [[C]], [[D]]
287 ; CHECK-NEXT: ret i32 [[E]]
288 ;
252289 %A = mul i32 %X3, %X1
253290 %B = mul i32 %X3, %X2
254291 %C = mul i32 %A, %X4
256293 %E = xor i32 %C, %D
257294 ret i32 %E
258295 }
296