1 ; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z13 \
2 ; RUN: | FileCheck %s -check-prefixes=CHECK,Z13
3 ; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z14 \
4 ; RUN: | FileCheck %s -check-prefixes=CHECK,Z14
6 ; Test that loads into operations that can fold one memory operand get zero
7 ; cost. In the case that both operands are loaded, one load should get a cost
11 %li32 = load i32, i32* undef
14 %li32_0 = load i32, i32* undef
15 %li32_1 = load i32, i32* undef
16 add i32 %li32_0, %li32_1
18 %li64 = load i64, i64* undef
21 %li64_0 = load i64, i64* undef
22 %li64_1 = load i64, i64* undef
23 add i64 %li64_0, %li64_1
26 %li64_2 = load i64, i64* undef
27 %tr = trunc i64 %li64_2 to i32
31 %li16_0 = load i16, i16* undef
32 %sext_0 = sext i16 %li16_0 to i32
33 add i32 %sext_0, undef
35 %li16_1 = load i16, i16* undef
36 %sext_1 = sext i16 %li16_1 to i64
37 add i64 %sext_1, undef
39 %li32_2 = load i32, i32* undef
40 %sext_2 = sext i32 %li32_2 to i64
41 add i64 %sext_2, undef
44 %li32_3 = load i32, i32* undef
45 %zext_0 = zext i32 %li32_3 to i64
46 add i64 %zext_0, undef
48 ; Loads with multiple uses are *not* folded
49 %li16_3 = load i16, i16* undef
50 %sext_3 = sext i16 %li16_3 to i32
51 %sext_4 = sext i16 %li16_3 to i32
52 add i32 %sext_3, undef
56 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
57 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = add i32 %li32, undef
58 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
59 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
60 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = add i32 %li32_0, %li32_1
61 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
62 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = add i64 %li64, undef
63 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
64 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
65 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = add i64 %li64_0, %li64_1
66 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
67 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
68 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = add i32 %tr, undef
69 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li16_0 = load i16, i16* undef
70 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i16 %li16_0 to i32
71 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = add i32 %sext_0, undef
72 ; Z13: Cost Model: Found an estimated cost of 1 for instruction: %li16_1 = load i16, i16* undef
73 ; Z14: Cost Model: Found an estimated cost of 0 for instruction: %li16_1 = load i16, i16* undef
74 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i16 %li16_1 to i64
75 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %7 = add i64 %sext_1, undef
76 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_2 = load i32, i32* undef
77 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_2 to i64
78 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %8 = add i64 %sext_2, undef
79 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_3 = load i32, i32* undef
80 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %zext_0 = zext i32 %li32_3 to i64
81 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %9 = add i64 %zext_0, undef
82 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_3 = load i16, i16* undef
83 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_3 = sext i16 %li16_3 to i32
84 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_4 = sext i16 %li16_3 to i32
85 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %10 = add i32 %sext_3, undef
88 define void @add_i16_mem16(i16 %Arg, i16* %Src1, i16* %Src2, i16* %Dst, i32* %Src32) {
89 %L1 = load i16, i16* %Src1
90 %S0 = add i16 %L1, %Arg
91 store volatile i16 %S0, i16* %Dst
93 %L2 = load i16, i16* %Src1
94 %L3 = load i16, i16* %Src2
95 %S1 = add i16 %L2, %L3
96 store volatile i16 %S1, i16* %Dst
99 %L32 = load i32, i32* %Src32
100 %tr = trunc i32 %L32 to i16
101 %S2 = add i16 %tr, %Arg
102 store volatile i16 %S2, i16* %Dst
105 ; CHECK: Printing analysis 'Cost Model Analysis' for function 'add_i16_mem16':
106 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L1 = load i16, i16* %Src1
107 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %S0 = add i16 %L1, %Arg
108 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %S0, i16* %Dst
109 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L2 = load i16, i16* %Src1
110 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %L3 = load i16, i16* %Src2
111 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %S1 = add i16 %L2, %L3
112 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %S1, i16* %Dst
113 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L32 = load i32, i32* %Src32
114 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i32 %L32 to i16
115 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %S2 = add i16 %tr, %Arg
116 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %S2, i16* %Dst
119 define void @sub_lhs_mem() {
120 %li32 = load i32, i32* undef
123 %li32_0 = load i32, i32* undef
124 %li32_1 = load i32, i32* undef
125 sub i32 %li32_0, %li32_1
127 %li64 = load i64, i64* undef
130 %li64_0 = load i64, i64* undef
131 %li64_1 = load i64, i64* undef
132 sub i64 %li64_0, %li64_1
135 %li64_2 = load i64, i64* undef
136 %tr = trunc i64 %li64_2 to i32
139 ; Sign-extended loads
140 %li16_0 = load i16, i16* undef
141 %sext_0 = sext i16 %li16_0 to i32
142 sub i32 %sext_0, undef
144 %li16_1 = load i16, i16* undef
145 %sext_1 = sext i16 %li16_1 to i64
146 sub i64 %sext_1, undef
148 %li32_2 = load i32, i32* undef
149 %sext_2 = sext i32 %li32_2 to i64
150 sub i64 %sext_2, undef
152 ; Zero-extended loads
153 %li32_3 = load i32, i32* undef
154 %zext_0 = zext i32 %li32_3 to i64
155 sub i64 %zext_0, undef
157 ; Loads with multiple uses are *not* folded
158 %li16_3 = load i16, i16* undef
159 %sext_3 = sext i16 %li16_3 to i32
160 %sext_4 = sext i16 %li16_3 to i32
161 sub i32 %sext_3, undef
165 ; A sub LHS loaded operand is *not* foldable.
166 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32 = load i32, i32* undef
167 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = sub i32 %li32, undef
168 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_0 = load i32, i32* undef
169 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_1 = load i32, i32* undef
170 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = sub i32 %li32_0, %li32_1
171 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64 = load i64, i64* undef
172 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = sub i64 %li64, undef
173 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_0 = load i64, i64* undef
174 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_1 = load i64, i64* undef
175 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = sub i64 %li64_0, %li64_1
176 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_2 = load i64, i64* undef
177 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
178 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = sub i32 %tr, undef
179 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_0 = load i16, i16* undef
180 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i16 %li16_0 to i32
181 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = sub i32 %sext_0, undef
182 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_1 = load i16, i16* undef
183 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i16 %li16_1 to i64
184 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %7 = sub i64 %sext_1, undef
185 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_2 = load i32, i32* undef
186 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_2 to i64
187 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %8 = sub i64 %sext_2, undef
188 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_3 = load i32, i32* undef
189 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %zext_0 = zext i32 %li32_3 to i64
190 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %9 = sub i64 %zext_0, undef
191 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_3 = load i16, i16* undef
192 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_3 = sext i16 %li16_3 to i32
193 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_4 = sext i16 %li16_3 to i32
194 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %10 = sub i32 %sext_3, undef
197 define void @sub_rhs_mem() {
198 %li32 = load i32, i32* undef
201 %li64 = load i64, i64* undef
205 %li64_2 = load i64, i64* undef
206 %tr = trunc i64 %li64_2 to i32
209 ; Sign-extended loads
210 %li16_0 = load i16, i16* undef
211 %sext_0 = sext i16 %li16_0 to i32
212 sub i32 undef, %sext_0
214 %li16_1 = load i16, i16* undef
215 %sext_1 = sext i16 %li16_1 to i64
216 sub i64 undef, %sext_1
218 %li32_2 = load i32, i32* undef
219 %sext_2 = sext i32 %li32_2 to i64
220 sub i64 undef, %sext_2
222 ; Zero-extended loads
223 %li32_3 = load i32, i32* undef
224 %zext_0 = zext i32 %li32_3 to i64
225 sub i64 undef, %zext_0
227 ; Loads with multiple uses are *not* folded
228 %li16_3 = load i16, i16* undef
229 %sext_3 = sext i16 %li16_3 to i32
230 %sext_4 = sext i16 %li16_3 to i32
231 sub i32 undef, %sext_3
235 ; A sub RHS loaded operand is foldable.
236 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
237 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = sub i32 undef, %li32
238 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
239 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = sub i64 undef, %li64
240 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
241 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
242 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = sub i32 undef, %tr
243 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li16_0 = load i16, i16* undef
244 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i16 %li16_0 to i32
245 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = sub i32 undef, %sext_0
246 ; Z13: Cost Model: Found an estimated cost of 1 for instruction: %li16_1 = load i16, i16* undef
247 ; Z14: Cost Model: Found an estimated cost of 0 for instruction: %li16_1 = load i16, i16* undef
248 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i16 %li16_1 to i64
249 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = sub i64 undef, %sext_1
250 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_2 = load i32, i32* undef
251 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_2 to i64
252 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = sub i64 undef, %sext_2
253 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_3 = load i32, i32* undef
254 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %zext_0 = zext i32 %li32_3 to i64
255 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %7 = sub i64 undef, %zext_0
256 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_3 = load i16, i16* undef
257 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_3 = sext i16 %li16_3 to i32
258 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_4 = sext i16 %li16_3 to i32
259 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %8 = sub i32 undef, %sext_3
262 define void @sub_i16_mem16(i16 %Arg, i16* %Src1, i16* %Src2, i16* %Dst, i32* %Src32) {
263 %L1 = load i16, i16* %Src1
264 %D0 = sub i16 %Arg, %L1
265 store volatile i16 %D0, i16* %Dst
267 %L2 = load i16, i16* %Src1
268 %L3 = load i16, i16* %Src2
269 %D1 = sub i16 %L2, %L3
270 store volatile i16 %D1, i16* %Dst
273 %L32 = load i32, i32* %Src32
274 %tr = trunc i32 %L32 to i16
275 %D2 = sub i16 %Arg, %tr
276 store volatile i16 %D2, i16* %Dst
279 ; CHECK: Printing analysis 'Cost Model Analysis' for function 'sub_i16_mem16':
280 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L1 = load i16, i16* %Src1
281 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %D0 = sub i16 %Arg, %L1
282 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %D0, i16* %Dst
283 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %L2 = load i16, i16* %Src1
284 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L3 = load i16, i16* %Src2
285 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %D1 = sub i16 %L2, %L3
286 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %D1, i16* %Dst
287 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L32 = load i32, i32* %Src32
288 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i32 %L32 to i16
289 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %D2 = sub i16 %Arg, %tr
290 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %D2, i16* %Dst
294 %li32 = load i32, i32* undef
297 %li32_0 = load i32, i32* undef
298 %li32_1 = load i32, i32* undef
299 mul i32 %li32_0, %li32_1
301 %li64 = load i64, i64* undef
304 %li64_0 = load i64, i64* undef
305 %li64_1 = load i64, i64* undef
306 mul i64 %li64_0, %li64_1
309 %li64_2 = load i64, i64* undef
310 %tr = trunc i64 %li64_2 to i32
313 ; Sign-extended loads
314 %li16_0 = load i16, i16* undef
315 %sext_0 = sext i16 %li16_0 to i32
316 mul i32 %sext_0, undef
318 %li16_1 = load i16, i16* undef
319 %sext_1 = sext i16 %li16_1 to i64
320 mul i64 %sext_1, undef
322 %li32_2 = load i32, i32* undef
323 %sext_2 = sext i32 %li32_2 to i64
324 mul i64 %sext_2, undef
326 ; Zero-extended loads are *not* folded
327 %li16_2 = load i16, i16* undef
328 %zext_0 = zext i16 %li16_2 to i32
329 mul i32 %zext_0, undef
331 ; Loads with multiple uses are *not* folded
332 %li16_3 = load i16, i16* undef
333 %sext_3 = sext i16 %li16_3 to i32
334 %sext_4 = sext i16 %li16_3 to i32
335 mul i32 %sext_3, undef
338 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
339 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = mul i32 %li32, undef
340 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
341 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
342 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = mul i32 %li32_0, %li32_1
343 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
344 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = mul i64 %li64, undef
345 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
346 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
347 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = mul i64 %li64_0, %li64_1
348 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
349 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
350 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = mul i32 %tr, undef
351 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li16_0 = load i16, i16* undef
352 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i16 %li16_0 to i32
353 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = mul i32 %sext_0, undef
354 ; Z13: Cost Model: Found an estimated cost of 1 for instruction: %li16_1 = load i16, i16* undef
355 ; Z14: Cost Model: Found an estimated cost of 0 for instruction: %li16_1 = load i16, i16* undef
356 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i16 %li16_1 to i64
357 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %7 = mul i64 %sext_1, undef
358 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_2 = load i32, i32* undef
359 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_2 to i64
360 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %8 = mul i64 %sext_2, undef
361 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_2 = load i16, i16* undef
362 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %zext_0 = zext i16 %li16_2 to i32
363 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %9 = mul i32 %zext_0, undef
364 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li16_3 = load i16, i16* undef
365 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_3 = sext i16 %li16_3 to i32
366 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_4 = sext i16 %li16_3 to i32
367 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %10 = mul i32 %sext_3, undef
370 define void @mul_i16_mem16(i16 %Arg, i16* %Src1, i16* %Src2, i16* %Dst, i32* %Src32) {
371 %L1 = load i16, i16* %Src1
372 %P0 = mul i16 %Arg, %L1
373 store volatile i16 %P0, i16* %Dst
375 %L2 = load i16, i16* %Src1
376 %L3 = load i16, i16* %Src2
377 %P1 = mul i16 %L2, %L3
378 store volatile i16 %P1, i16* %Dst
381 %L32 = load i32, i32* %Src32
382 %tr = trunc i32 %L32 to i16
383 %P2 = mul i16 %Arg, %tr
384 store volatile i16 %P2, i16* %Dst
387 ; CHECK: Printing analysis 'Cost Model Analysis' for function 'mul_i16_mem16':
388 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L1 = load i16, i16* %Src1
389 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %P0 = mul i16 %Arg, %L1
390 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %P0, i16* %Dst
391 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L2 = load i16, i16* %Src1
392 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %L3 = load i16, i16* %Src2
393 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %P1 = mul i16 %L2, %L3
394 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %P1, i16* %Dst
395 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %L32 = load i32, i32* %Src32
396 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i32 %L32 to i16
397 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %P2 = mul i16 %Arg, %tr
398 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: store volatile i16 %P2, i16* %Dst
401 define void @sdiv_lhs(i32 %arg32, i64 %arg64) {
402 %li32 = load i32, i32* undef
403 sdiv i32 %li32, %arg32
405 %li32_0 = load i32, i32* undef
406 %li32_1 = load i32, i32* undef
407 sdiv i32 %li32_0, %li32_1
409 %li64 = load i64, i64* undef
410 sdiv i64 %li64, %arg64
412 %li64_0 = load i64, i64* undef
413 %li64_1 = load i64, i64* undef
414 sdiv i64 %li64_0, %li64_1
417 %li64_2 = load i64, i64* undef
418 %tr = trunc i64 %li64_2 to i32
421 ; Sign-extended loads
422 %li32_2 = load i32, i32* undef
423 %sext_0 = sext i32 %li32_2 to i64
424 sdiv i64 %sext_0, undef
426 ; Loads with multiple uses are *not* folded
427 %li32_3 = load i32, i32* undef
428 %sext_1 = sext i32 %li32_3 to i64
429 %sext_2 = sext i32 %li32_3 to i64
430 sdiv i64 %sext_1, undef
434 ; An sdiv loaded dividend (lhs) operand is *not* foldable.
435 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32 = load i32, i32* undef
436 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %1 = sdiv i32 %li32, %arg32
437 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_0 = load i32, i32* undef
438 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_1 = load i32, i32* undef
439 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %2 = sdiv i32 %li32_0, %li32_1
440 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64 = load i64, i64* undef
441 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %3 = sdiv i64 %li64, %arg64
442 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_0 = load i64, i64* undef
443 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_1 = load i64, i64* undef
444 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %4 = sdiv i64 %li64_0, %li64_1
445 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_2 = load i64, i64* undef
446 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
447 ; CHECK: Cost Model: Found an estimated cost of 10 for instruction: %5 = sdiv i32 %tr, undef
448 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_2 = load i32, i32* undef
449 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i32 %li32_2 to i64
450 ; CHECK: Cost Model: Found an estimated cost of 10 for instruction: %6 = sdiv i64 %sext_0, undef
451 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_3 = load i32, i32* undef
452 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i32 %li32_3 to i64
453 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_3 to i64
454 ; CHECK: Cost Model: Found an estimated cost of 10 for instruction: %7 = sdiv i64 %sext_1, undef
457 define void @sdiv_rhs(i32 %arg32, i64 %arg64) {
458 %li32 = load i32, i32* undef
459 sdiv i32 %arg32, %li32
461 %li64 = load i64, i64* undef
462 sdiv i64 %arg64, %li64
465 %li64_2 = load i64, i64* undef
466 %tr = trunc i64 %li64_2 to i32
469 ; Sign-extended loads
470 %li32_2 = load i32, i32* undef
471 %sext_0 = sext i32 %li32_2 to i64
472 sdiv i64 undef, %sext_0
474 ; Loads with multiple uses are *not* folded
475 %li32_3 = load i32, i32* undef
476 %sext_1 = sext i32 %li32_3 to i64
477 %sext_2 = sext i32 %li32_3 to i64
478 sdiv i64 undef, %sext_1
482 ; An sdiv loaded divisor (rhs) operand is foldable.
483 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
484 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %1 = sdiv i32 %arg32, %li32
485 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
486 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %2 = sdiv i64 %arg64, %li64
487 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
488 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr = trunc i64 %li64_2 to i32
489 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %3 = sdiv i32 undef, %tr
490 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_2 = load i32, i32* undef
491 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_0 = sext i32 %li32_2 to i64
492 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %4 = sdiv i64 undef, %sext_0
493 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_3 = load i32, i32* undef
494 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_1 = sext i32 %li32_3 to i64
495 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext_2 = sext i32 %li32_3 to i64
496 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %5 = sdiv i64 undef, %sext_1
499 define void @udiv_lhs(i32 %arg32, i64 %arg64) {
500 %li32 = load i32, i32* undef
501 udiv i32 %li32, %arg32
503 %li32_0 = load i32, i32* undef
504 %li32_1 = load i32, i32* undef
505 udiv i32 %li32_0, %li32_1
507 %li64 = load i64, i64* undef
508 udiv i64 %li64, %arg64
510 %li64_0 = load i64, i64* undef
511 %li64_1 = load i64, i64* undef
512 udiv i64 %li64_0, %li64_1
515 %li64_2 = load i64, i64* undef
516 %tr_0 = trunc i64 %li64_2 to i32
517 udiv i32 %tr_0, undef
519 ; Loads with multiple uses are *not* folded
520 %li64_3 = load i64, i64* undef
521 %tr_1 = trunc i64 %li64_3 to i32
522 udiv i64 %li64_3, undef
526 ; An udiv loaded dividend (lhs) operand is *not* foldable.
527 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32 = load i32, i32* undef
528 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %1 = udiv i32 %li32, %arg32
529 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_0 = load i32, i32* undef
530 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_1 = load i32, i32* undef
531 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %2 = udiv i32 %li32_0, %li32_1
532 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64 = load i64, i64* undef
533 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %3 = udiv i64 %li64, %arg64
534 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_0 = load i64, i64* undef
535 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_1 = load i64, i64* undef
536 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %4 = udiv i64 %li64_0, %li64_1
537 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_2 = load i64, i64* undef
538 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
539 ; CHECK: Cost Model: Found an estimated cost of 10 for instruction: %5 = udiv i32 %tr_0, undef
540 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
541 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
542 ; CHECK: Cost Model: Found an estimated cost of 10 for instruction: %6 = udiv i64 %li64_3, undef
545 define void @udiv_rhs(i32 %arg32, i64 %arg64) {
546 %li32 = load i32, i32* undef
547 udiv i32 %arg32, %li32
549 %li64 = load i64, i64* undef
550 udiv i64 %arg64, %li64
553 %li64_2 = load i64, i64* undef
554 %tr_0 = trunc i64 %li64_2 to i32
555 udiv i32 undef, %tr_0
557 ; Loads with multiple uses are *not* folded
558 %li64_3 = load i64, i64* undef
559 %tr_1 = trunc i64 %li64_3 to i32
560 udiv i64 undef, %li64_3
564 ; An udiv loaded divisor (rhs) operand is foldable.
565 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
566 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %1 = udiv i32 %arg32, %li32
567 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
568 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %2 = udiv i64 %arg64, %li64
569 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
570 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
571 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %3 = udiv i32 undef, %tr_0
572 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
573 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
574 ; CHECK: Cost Model: Found an estimated cost of 20 for instruction: %4 = udiv i64 undef, %li64_3
578 %li32 = load i32, i32* undef
581 %li32_0 = load i32, i32* undef
582 %li32_1 = load i32, i32* undef
583 and i32 %li32_0, %li32_1
585 %li64 = load i64, i64* undef
588 %li64_0 = load i64, i64* undef
589 %li64_1 = load i64, i64* undef
590 and i64 %li64_0, %li64_1
593 %li64_2 = load i64, i64* undef
594 %tr_0 = trunc i64 %li64_2 to i32
597 ; Loads with multiple uses are *not* folded
598 %li64_3 = load i64, i64* undef
599 %tr_1 = trunc i64 %li64_3 to i32
600 and i64 %li64_3, undef
603 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
604 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = and i32 %li32, undef
605 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
606 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
607 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = and i32 %li32_0, %li32_1
608 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
609 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = and i64 %li64, undef
610 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
611 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
612 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = and i64 %li64_0, %li64_1
613 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
614 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
615 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = and i32 %tr_0, undef
616 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
617 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
618 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = and i64 %li64_3, undef
622 %li32 = load i32, i32* undef
625 %li32_0 = load i32, i32* undef
626 %li32_1 = load i32, i32* undef
627 or i32 %li32_0, %li32_1
629 %li64 = load i64, i64* undef
632 %li64_0 = load i64, i64* undef
633 %li64_1 = load i64, i64* undef
634 or i64 %li64_0, %li64_1
637 %li64_2 = load i64, i64* undef
638 %tr_0 = trunc i64 %li64_2 to i32
641 ; Loads with multiple uses are *not* folded
642 %li64_3 = load i64, i64* undef
643 %tr_1 = trunc i64 %li64_3 to i32
644 or i64 %li64_3, undef
647 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
648 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = or i32 %li32, undef
649 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
650 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
651 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = or i32 %li32_0, %li32_1
652 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
653 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = or i64 %li64, undef
654 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
655 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
656 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = or i64 %li64_0, %li64_1
657 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
658 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
659 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = or i32 %tr_0, undef
660 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
661 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
662 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = or i64 %li64_3, undef
666 %li32 = load i32, i32* undef
669 %li32_0 = load i32, i32* undef
670 %li32_1 = load i32, i32* undef
671 xor i32 %li32_0, %li32_1
673 %li64 = load i64, i64* undef
676 %li64_0 = load i64, i64* undef
677 %li64_1 = load i64, i64* undef
678 xor i64 %li64_0, %li64_1
681 %li64_2 = load i64, i64* undef
682 %tr_0 = trunc i64 %li64_2 to i32
685 ; Loads with multiple uses are *not* folded
686 %li64_3 = load i64, i64* undef
687 %tr_1 = trunc i64 %li64_3 to i32
688 xor i64 %li64_3, undef
691 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
692 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = xor i32 %li32, undef
693 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
694 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
695 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = xor i32 %li32_0, %li32_1
696 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
697 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = xor i64 %li64, undef
698 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
699 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
700 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = xor i64 %li64_0, %li64_1
701 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
702 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
703 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = xor i32 %tr_0, undef
704 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
705 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
706 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = xor i64 %li64_3, undef
709 define void @icmp() {
710 %li32 = load i32, i32* undef
711 icmp eq i32 %li32, undef
713 %li32_0 = load i32, i32* undef
714 %li32_1 = load i32, i32* undef
715 icmp eq i32 %li32_0, %li32_1
717 %li64 = load i64, i64* undef
718 icmp eq i64 %li64, undef
720 %li64_0 = load i64, i64* undef
721 %li64_1 = load i64, i64* undef
722 icmp eq i64 %li64_0, %li64_1
725 %li64_2 = load i64, i64* undef
726 %tr_0 = trunc i64 %li64_2 to i32
727 icmp eq i32 %tr_0, undef
730 %li32_2 = load i32, i32* undef
731 %sext = sext i32 %li32_2 to i64
732 icmp eq i64 %sext, undef
735 %li32_3 = load i32, i32* undef
736 %zext = zext i32 %li32_3 to i64
737 icmp eq i64 %zext, undef
739 ; Loads with multiple uses are *not* folded
740 %li64_3 = load i64, i64* undef
741 %tr_1 = trunc i64 %li64_3 to i32
742 icmp eq i64 %li64_3, undef
745 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32 = load i32, i32* undef
746 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %1 = icmp eq i32 %li32, undef
747 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_0 = load i32, i32* undef
748 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li32_1 = load i32, i32* undef
749 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %2 = icmp eq i32 %li32_0, %li32_1
750 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64 = load i64, i64* undef
751 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %3 = icmp eq i64 %li64, undef
752 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_0 = load i64, i64* undef
753 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_1 = load i64, i64* undef
754 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %4 = icmp eq i64 %li64_0, %li64_1
755 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li64_2 = load i64, i64* undef
756 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_0 = trunc i64 %li64_2 to i32
757 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %5 = icmp eq i32 %tr_0, undef
758 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_2 = load i32, i32* undef
759 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %sext = sext i32 %li32_2 to i64
760 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %6 = icmp eq i64 %sext, undef
761 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %li32_3 = load i32, i32* undef
762 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %zext = zext i32 %li32_3 to i64
763 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %7 = icmp eq i64 %zext, undef
764 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %li64_3 = load i64, i64* undef
765 ; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %tr_1 = trunc i64 %li64_3 to i32
766 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %8 = icmp eq i64 %li64_3, undef