1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -relocation-model=pic | FileCheck %s
4 ; Test folding constant offsets and symbols into load and store addresses under
5 ; a variety of circumstances.
7 target triple = "wasm32-unknown-emscripten"
9 @g = external global [0 x i32], align 4
11 define i32 @load_test0() {
12 ; CHECK-LABEL: load_test0:
13 ; CHECK: .functype load_test0 () -> (i32)
14 ; CHECK-NEXT: # %bb.0:
15 ; CHECK-NEXT: global.get $push0=, g@GOT
16 ; CHECK-NEXT: i32.load $push1=, 40($pop0)
17 ; CHECK-NEXT: return $pop1
18 %t = load i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), align 4
22 define i32 @load_test0_noinbounds() {
23 ; CHECK-LABEL: load_test0_noinbounds:
24 ; CHECK: .functype load_test0_noinbounds () -> (i32)
25 ; CHECK-NEXT: # %bb.0:
26 ; CHECK-NEXT: global.get $push1=, g@GOT
27 ; CHECK-NEXT: i32.const $push0=, 40
28 ; CHECK-NEXT: i32.add $push2=, $pop1, $pop0
29 ; CHECK-NEXT: i32.load $push3=, 0($pop2)
30 ; CHECK-NEXT: return $pop3
31 %t = load i32, ptr getelementptr ([0 x i32], ptr @g, i32 0, i32 10), align 4
35 ; TODO: load_test1 - load_test8 are disabled because folding GA+reg is disabled
36 ; (there are cases where the value in the reg can be negative).
37 ; Likewise for stores.
39 define i32 @load_test1(i32 %n) {
40 ; CHECK-LABEL: load_test1:
41 ; CHECK: .functype load_test1 (i32) -> (i32)
42 ; CHECK-NEXT: # %bb.0:
43 ; CHECK-NEXT: i32.const $push0=, 2
44 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
45 ; CHECK-NEXT: global.get $push2=, g@GOT
46 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
47 ; CHECK-NEXT: i32.const $push4=, 40
48 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
49 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
50 ; CHECK-NEXT: return $pop6
51 %add = add nsw i32 %n, 10
52 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
53 %t = load i32, ptr %arrayidx, align 4
57 define i32 @load_test2(i32 %n) {
58 ; CHECK-LABEL: load_test2:
59 ; CHECK: .functype load_test2 (i32) -> (i32)
60 ; CHECK-NEXT: # %bb.0:
61 ; CHECK-NEXT: i32.const $push0=, 2
62 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
63 ; CHECK-NEXT: global.get $push2=, g@GOT
64 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
65 ; CHECK-NEXT: i32.const $push4=, 40
66 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
67 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
68 ; CHECK-NEXT: return $pop6
69 %add = add nsw i32 10, %n
70 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
71 %t = load i32, ptr %arrayidx, align 4
75 define i32 @load_test3(i32 %n) {
76 ; CHECK-LABEL: load_test3:
77 ; CHECK: .functype load_test3 (i32) -> (i32)
78 ; CHECK-NEXT: # %bb.0:
79 ; CHECK-NEXT: global.get $push2=, g@GOT
80 ; CHECK-NEXT: i32.const $push0=, 2
81 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
82 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
83 ; CHECK-NEXT: i32.load $push4=, 40($pop3)
84 ; CHECK-NEXT: return $pop4
85 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %n
86 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
87 %t = load i32, ptr %add.ptr1, align 4
91 define i32 @load_test4(i32 %n) {
92 ; CHECK-LABEL: load_test4:
93 ; CHECK: .functype load_test4 (i32) -> (i32)
94 ; CHECK-NEXT: # %bb.0:
95 ; CHECK-NEXT: global.get $push2=, g@GOT
96 ; CHECK-NEXT: i32.const $push0=, 2
97 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
98 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
99 ; CHECK-NEXT: i32.const $push4=, 40
100 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
101 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
102 ; CHECK-NEXT: return $pop6
103 %add.ptr = getelementptr inbounds i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), i32 %n
104 %t = load i32, ptr %add.ptr, align 4
108 define i32 @load_test5(i32 %n) {
109 ; CHECK-LABEL: load_test5:
110 ; CHECK: .functype load_test5 (i32) -> (i32)
111 ; CHECK-NEXT: # %bb.0:
112 ; CHECK-NEXT: global.get $push2=, g@GOT
113 ; CHECK-NEXT: i32.const $push0=, 2
114 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
115 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
116 ; CHECK-NEXT: i32.const $push4=, 40
117 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
118 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
119 ; CHECK-NEXT: return $pop6
120 %add.ptr = getelementptr inbounds i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), i32 %n
121 %t = load i32, ptr %add.ptr, align 4
125 define i32 @load_test6(i32 %n) {
126 ; CHECK-LABEL: load_test6:
127 ; CHECK: .functype load_test6 (i32) -> (i32)
128 ; CHECK-NEXT: # %bb.0:
129 ; CHECK-NEXT: i32.const $push0=, 2
130 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
131 ; CHECK-NEXT: global.get $push2=, g@GOT
132 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
133 ; CHECK-NEXT: i32.const $push4=, 40
134 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
135 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
136 ; CHECK-NEXT: return $pop6
137 %add = add nsw i32 %n, 10
138 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
139 %t = load i32, ptr %add.ptr, align 4
143 define i32 @load_test7(i32 %n) {
144 ; CHECK-LABEL: load_test7:
145 ; CHECK: .functype load_test7 (i32) -> (i32)
146 ; CHECK-NEXT: # %bb.0:
147 ; CHECK-NEXT: global.get $push2=, g@GOT
148 ; CHECK-NEXT: i32.const $push0=, 2
149 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
150 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
151 ; CHECK-NEXT: i32.load $push4=, 40($pop3)
152 ; CHECK-NEXT: return $pop4
153 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %n
154 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
155 %t = load i32, ptr %add.ptr1, align 4
159 define i32 @load_test8(i32 %n) {
160 ; CHECK-LABEL: load_test8:
161 ; CHECK: .functype load_test8 (i32) -> (i32)
162 ; CHECK-NEXT: # %bb.0:
163 ; CHECK-NEXT: i32.const $push0=, 2
164 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
165 ; CHECK-NEXT: global.get $push2=, g@GOT
166 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
167 ; CHECK-NEXT: i32.const $push4=, 40
168 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
169 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
170 ; CHECK-NEXT: return $pop6
171 %add = add nsw i32 10, %n
172 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
173 %t = load i32, ptr %add.ptr, align 4
177 define i32 @load_test9() {
178 ; CHECK-LABEL: load_test9:
179 ; CHECK: .functype load_test9 () -> (i32)
180 ; CHECK-NEXT: # %bb.0:
181 ; CHECK-NEXT: global.get $push1=, g@GOT
182 ; CHECK-NEXT: i32.const $push0=, -40
183 ; CHECK-NEXT: i32.add $push2=, $pop1, $pop0
184 ; CHECK-NEXT: i32.load $push3=, 0($pop2)
185 ; CHECK-NEXT: return $pop3
186 %t = load i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 1073741814), align 4
190 define i32 @load_test10(i32 %n) {
191 ; CHECK-LABEL: load_test10:
192 ; CHECK: .functype load_test10 (i32) -> (i32)
193 ; CHECK-NEXT: # %bb.0:
194 ; CHECK-NEXT: i32.const $push0=, 2
195 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
196 ; CHECK-NEXT: global.get $push2=, g@GOT
197 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
198 ; CHECK-NEXT: i32.const $push4=, -40
199 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
200 ; CHECK-NEXT: i32.load $push6=, 0($pop5)
201 ; CHECK-NEXT: return $pop6
202 %add = add nsw i32 %n, -10
203 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
204 %t = load i32, ptr %arrayidx, align 4
208 define i32 @load_test11(ptr %p) {
209 ; CHECK-LABEL: load_test11:
210 ; CHECK: .functype load_test11 (i32) -> (i32)
211 ; CHECK-NEXT: # %bb.0:
212 ; CHECK-NEXT: i32.load $push0=, 40($0)
213 ; CHECK-NEXT: return $pop0
214 %arrayidx = getelementptr inbounds i32, ptr %p, i32 10
215 %t = load i32, ptr %arrayidx, align 4
219 define i32 @load_test11_noinbounds(ptr %p) {
220 ; CHECK-LABEL: load_test11_noinbounds:
221 ; CHECK: .functype load_test11_noinbounds (i32) -> (i32)
222 ; CHECK-NEXT: # %bb.0:
223 ; CHECK-NEXT: i32.const $push0=, 40
224 ; CHECK-NEXT: i32.add $push1=, $0, $pop0
225 ; CHECK-NEXT: i32.load $push2=, 0($pop1)
226 ; CHECK-NEXT: return $pop2
227 %arrayidx = getelementptr i32, ptr %p, i32 10
228 %t = load i32, ptr %arrayidx, align 4
232 define i32 @load_test12(ptr %p, i32 %n) {
233 ; CHECK-LABEL: load_test12:
234 ; CHECK: .functype load_test12 (i32, i32) -> (i32)
235 ; CHECK-NEXT: # %bb.0:
236 ; CHECK-NEXT: i32.const $push0=, 2
237 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
238 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
239 ; CHECK-NEXT: i32.const $push3=, 40
240 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
241 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
242 ; CHECK-NEXT: return $pop5
243 %add = add nsw i32 %n, 10
244 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
245 %t = load i32, ptr %arrayidx, align 4
249 define i32 @load_test13(ptr %p, i32 %n) {
250 ; CHECK-LABEL: load_test13:
251 ; CHECK: .functype load_test13 (i32, i32) -> (i32)
252 ; CHECK-NEXT: # %bb.0:
253 ; CHECK-NEXT: i32.const $push0=, 2
254 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
255 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
256 ; CHECK-NEXT: i32.const $push3=, 40
257 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
258 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
259 ; CHECK-NEXT: return $pop5
260 %add = add nsw i32 10, %n
261 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
262 %t = load i32, ptr %arrayidx, align 4
266 define i32 @load_test14(ptr %p, i32 %n) {
267 ; CHECK-LABEL: load_test14:
268 ; CHECK: .functype load_test14 (i32, i32) -> (i32)
269 ; CHECK-NEXT: # %bb.0:
270 ; CHECK-NEXT: i32.const $push0=, 2
271 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
272 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
273 ; CHECK-NEXT: i32.load $push3=, 40($pop2)
274 ; CHECK-NEXT: return $pop3
275 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %n
276 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
277 %t = load i32, ptr %add.ptr1, align 4
281 define i32 @load_test15(ptr %p, i32 %n) {
282 ; CHECK-LABEL: load_test15:
283 ; CHECK: .functype load_test15 (i32, i32) -> (i32)
284 ; CHECK-NEXT: # %bb.0:
285 ; CHECK-NEXT: i32.const $push0=, 2
286 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
287 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
288 ; CHECK-NEXT: i32.const $push3=, 40
289 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
290 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
291 ; CHECK-NEXT: return $pop5
292 %add.ptr = getelementptr inbounds i32, ptr %p, i32 10
293 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %n
294 %t = load i32, ptr %add.ptr1, align 4
298 define i32 @load_test16(ptr %p, i32 %n) {
299 ; CHECK-LABEL: load_test16:
300 ; CHECK: .functype load_test16 (i32, i32) -> (i32)
301 ; CHECK-NEXT: # %bb.0:
302 ; CHECK-NEXT: i32.const $push0=, 2
303 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
304 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
305 ; CHECK-NEXT: i32.const $push3=, 40
306 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
307 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
308 ; CHECK-NEXT: return $pop5
309 %add.ptr = getelementptr inbounds i32, ptr %p, i32 10
310 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %n
311 %t = load i32, ptr %add.ptr1, align 4
315 define i32 @load_test17(ptr %p, i32 %n) {
316 ; CHECK-LABEL: load_test17:
317 ; CHECK: .functype load_test17 (i32, i32) -> (i32)
318 ; CHECK-NEXT: # %bb.0:
319 ; CHECK-NEXT: i32.const $push0=, 2
320 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
321 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
322 ; CHECK-NEXT: i32.const $push3=, 40
323 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
324 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
325 ; CHECK-NEXT: return $pop5
326 %add = add nsw i32 %n, 10
327 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %add
328 %t = load i32, ptr %add.ptr, align 4
332 define i32 @load_test18(ptr %p, i32 %n) {
333 ; CHECK-LABEL: load_test18:
334 ; CHECK: .functype load_test18 (i32, i32) -> (i32)
335 ; CHECK-NEXT: # %bb.0:
336 ; CHECK-NEXT: i32.const $push0=, 2
337 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
338 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
339 ; CHECK-NEXT: i32.load $push3=, 40($pop2)
340 ; CHECK-NEXT: return $pop3
341 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %n
342 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
343 %t = load i32, ptr %add.ptr1, align 4
347 define i32 @load_test19(ptr %p, i32 %n) {
348 ; CHECK-LABEL: load_test19:
349 ; CHECK: .functype load_test19 (i32, i32) -> (i32)
350 ; CHECK-NEXT: # %bb.0:
351 ; CHECK-NEXT: i32.const $push0=, 2
352 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
353 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
354 ; CHECK-NEXT: i32.const $push3=, 40
355 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
356 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
357 ; CHECK-NEXT: return $pop5
358 %add = add nsw i32 10, %n
359 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %add
360 %t = load i32, ptr %add.ptr, align 4
364 define i32 @load_test20(ptr %p) {
365 ; CHECK-LABEL: load_test20:
366 ; CHECK: .functype load_test20 (i32) -> (i32)
367 ; CHECK-NEXT: # %bb.0:
368 ; CHECK-NEXT: i32.const $push0=, -40
369 ; CHECK-NEXT: i32.add $push1=, $0, $pop0
370 ; CHECK-NEXT: i32.load $push2=, 0($pop1)
371 ; CHECK-NEXT: return $pop2
372 %arrayidx = getelementptr inbounds i32, ptr %p, i32 -10
373 %t = load i32, ptr %arrayidx, align 4
377 define i32 @load_test21(ptr %p, i32 %n) {
378 ; CHECK-LABEL: load_test21:
379 ; CHECK: .functype load_test21 (i32, i32) -> (i32)
380 ; CHECK-NEXT: # %bb.0:
381 ; CHECK-NEXT: i32.const $push0=, 2
382 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
383 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
384 ; CHECK-NEXT: i32.const $push3=, -40
385 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
386 ; CHECK-NEXT: i32.load $push5=, 0($pop4)
387 ; CHECK-NEXT: return $pop5
388 %add = add nsw i32 %n, -10
389 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
390 %t = load i32, ptr %arrayidx, align 4
394 define void @store_test0(i32 %i) {
395 ; CHECK-LABEL: store_test0:
396 ; CHECK: .functype store_test0 (i32) -> ()
397 ; CHECK-NEXT: # %bb.0:
398 ; CHECK-NEXT: global.get $push0=, g@GOT
399 ; CHECK-NEXT: i32.store 40($pop0), $0
401 store i32 %i, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), align 4
405 define void @store_test0_noinbounds(i32 %i) {
406 ; CHECK-LABEL: store_test0_noinbounds:
407 ; CHECK: .functype store_test0_noinbounds (i32) -> ()
408 ; CHECK-NEXT: # %bb.0:
409 ; CHECK-NEXT: global.get $push1=, g@GOT
410 ; CHECK-NEXT: i32.const $push0=, 40
411 ; CHECK-NEXT: i32.add $push2=, $pop1, $pop0
412 ; CHECK-NEXT: i32.store 0($pop2), $0
414 store i32 %i, ptr getelementptr ([0 x i32], ptr @g, i32 0, i32 10), align 4
418 define void @store_test1(i32 %n, i32 %i) {
419 ; CHECK-LABEL: store_test1:
420 ; CHECK: .functype store_test1 (i32, i32) -> ()
421 ; CHECK-NEXT: # %bb.0:
422 ; CHECK-NEXT: i32.const $push0=, 2
423 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
424 ; CHECK-NEXT: global.get $push2=, g@GOT
425 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
426 ; CHECK-NEXT: i32.const $push4=, 40
427 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
428 ; CHECK-NEXT: i32.store 0($pop5), $1
430 %add = add nsw i32 %n, 10
431 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
432 store i32 %i, ptr %arrayidx, align 4
436 define void @store_test2(i32 %n, i32 %i) {
437 ; CHECK-LABEL: store_test2:
438 ; CHECK: .functype store_test2 (i32, i32) -> ()
439 ; CHECK-NEXT: # %bb.0:
440 ; CHECK-NEXT: i32.const $push0=, 2
441 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
442 ; CHECK-NEXT: global.get $push2=, g@GOT
443 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
444 ; CHECK-NEXT: i32.const $push4=, 40
445 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
446 ; CHECK-NEXT: i32.store 0($pop5), $1
448 %add = add nsw i32 10, %n
449 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
450 store i32 %i, ptr %arrayidx, align 4
454 define void @store_test3(i32 %n, i32 %i) {
455 ; CHECK-LABEL: store_test3:
456 ; CHECK: .functype store_test3 (i32, i32) -> ()
457 ; CHECK-NEXT: # %bb.0:
458 ; CHECK-NEXT: global.get $push2=, g@GOT
459 ; CHECK-NEXT: i32.const $push0=, 2
460 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
461 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
462 ; CHECK-NEXT: i32.store 40($pop3), $1
464 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %n
465 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
466 store i32 %i, ptr %add.ptr1, align 4
470 define void @store_test4(i32 %n, i32 %i) {
471 ; CHECK-LABEL: store_test4:
472 ; CHECK: .functype store_test4 (i32, i32) -> ()
473 ; CHECK-NEXT: # %bb.0:
474 ; CHECK-NEXT: global.get $push2=, g@GOT
475 ; CHECK-NEXT: i32.const $push0=, 2
476 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
477 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
478 ; CHECK-NEXT: i32.const $push4=, 40
479 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
480 ; CHECK-NEXT: i32.store 0($pop5), $1
482 %add.ptr = getelementptr inbounds i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), i32 %n
483 store i32 %i, ptr %add.ptr, align 4
487 define void @store_test5(i32 %n, i32 %i) {
488 ; CHECK-LABEL: store_test5:
489 ; CHECK: .functype store_test5 (i32, i32) -> ()
490 ; CHECK-NEXT: # %bb.0:
491 ; CHECK-NEXT: global.get $push2=, g@GOT
492 ; CHECK-NEXT: i32.const $push0=, 2
493 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
494 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
495 ; CHECK-NEXT: i32.const $push4=, 40
496 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
497 ; CHECK-NEXT: i32.store 0($pop5), $1
499 %add.ptr = getelementptr inbounds i32, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 10), i32 %n
500 store i32 %i, ptr %add.ptr, align 4
504 define void @store_test6(i32 %n, i32 %i) {
505 ; CHECK-LABEL: store_test6:
506 ; CHECK: .functype store_test6 (i32, i32) -> ()
507 ; CHECK-NEXT: # %bb.0:
508 ; CHECK-NEXT: i32.const $push0=, 2
509 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
510 ; CHECK-NEXT: global.get $push2=, g@GOT
511 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
512 ; CHECK-NEXT: i32.const $push4=, 40
513 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
514 ; CHECK-NEXT: i32.store 0($pop5), $1
516 %add = add nsw i32 %n, 10
517 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
518 store i32 %i, ptr %add.ptr, align 4
522 define void @store_test7(i32 %n, i32 %i) {
523 ; CHECK-LABEL: store_test7:
524 ; CHECK: .functype store_test7 (i32, i32) -> ()
525 ; CHECK-NEXT: # %bb.0:
526 ; CHECK-NEXT: global.get $push2=, g@GOT
527 ; CHECK-NEXT: i32.const $push0=, 2
528 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
529 ; CHECK-NEXT: i32.add $push3=, $pop2, $pop1
530 ; CHECK-NEXT: i32.store 40($pop3), $1
532 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %n
533 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
534 store i32 %i, ptr %add.ptr1, align 4
538 define void @store_test8(i32 %n, i32 %i) {
539 ; CHECK-LABEL: store_test8:
540 ; CHECK: .functype store_test8 (i32, i32) -> ()
541 ; CHECK-NEXT: # %bb.0:
542 ; CHECK-NEXT: i32.const $push0=, 2
543 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
544 ; CHECK-NEXT: global.get $push2=, g@GOT
545 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
546 ; CHECK-NEXT: i32.const $push4=, 40
547 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
548 ; CHECK-NEXT: i32.store 0($pop5), $1
550 %add = add nsw i32 10, %n
551 %add.ptr = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
552 store i32 %i, ptr %add.ptr, align 4
556 define void @store_test9(i32 %i) {
557 ; CHECK-LABEL: store_test9:
558 ; CHECK: .functype store_test9 (i32) -> ()
559 ; CHECK-NEXT: # %bb.0:
560 ; CHECK-NEXT: global.get $push1=, g@GOT
561 ; CHECK-NEXT: i32.const $push0=, -40
562 ; CHECK-NEXT: i32.add $push2=, $pop1, $pop0
563 ; CHECK-NEXT: i32.store 0($pop2), $0
565 store i32 %i, ptr getelementptr inbounds ([0 x i32], ptr @g, i32 0, i32 1073741814), align 4
569 define void @store_test10(i32 %n, i32 %i) {
570 ; CHECK-LABEL: store_test10:
571 ; CHECK: .functype store_test10 (i32, i32) -> ()
572 ; CHECK-NEXT: # %bb.0:
573 ; CHECK-NEXT: i32.const $push0=, 2
574 ; CHECK-NEXT: i32.shl $push1=, $0, $pop0
575 ; CHECK-NEXT: global.get $push2=, g@GOT
576 ; CHECK-NEXT: i32.add $push3=, $pop1, $pop2
577 ; CHECK-NEXT: i32.const $push4=, -40
578 ; CHECK-NEXT: i32.add $push5=, $pop3, $pop4
579 ; CHECK-NEXT: i32.store 0($pop5), $1
581 %add = add nsw i32 %n, -10
582 %arrayidx = getelementptr inbounds [0 x i32], ptr @g, i32 0, i32 %add
583 store i32 %i, ptr %arrayidx, align 4
587 define void @store_test11(ptr %p, i32 %i) {
588 ; CHECK-LABEL: store_test11:
589 ; CHECK: .functype store_test11 (i32, i32) -> ()
590 ; CHECK-NEXT: # %bb.0:
591 ; CHECK-NEXT: i32.store 40($0), $1
593 %arrayidx = getelementptr inbounds i32, ptr %p, i32 10
594 store i32 %i, ptr %arrayidx, align 4
598 define void @store_test11_noinbounds(ptr %p, i32 %i) {
599 ; CHECK-LABEL: store_test11_noinbounds:
600 ; CHECK: .functype store_test11_noinbounds (i32, i32) -> ()
601 ; CHECK-NEXT: # %bb.0:
602 ; CHECK-NEXT: i32.const $push0=, 40
603 ; CHECK-NEXT: i32.add $push1=, $0, $pop0
604 ; CHECK-NEXT: i32.store 0($pop1), $1
606 %arrayidx = getelementptr i32, ptr %p, i32 10
607 store i32 %i, ptr %arrayidx, align 4
611 define void @store_test12(ptr %p, i32 %n, i32 %i) {
612 ; CHECK-LABEL: store_test12:
613 ; CHECK: .functype store_test12 (i32, i32, i32) -> ()
614 ; CHECK-NEXT: # %bb.0:
615 ; CHECK-NEXT: i32.const $push0=, 2
616 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
617 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
618 ; CHECK-NEXT: i32.const $push3=, 40
619 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
620 ; CHECK-NEXT: i32.store 0($pop4), $2
622 %add = add nsw i32 %n, 10
623 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
624 store i32 %i, ptr %arrayidx, align 4
628 define void @store_test13(ptr %p, i32 %n, i32 %i) {
629 ; CHECK-LABEL: store_test13:
630 ; CHECK: .functype store_test13 (i32, i32, i32) -> ()
631 ; CHECK-NEXT: # %bb.0:
632 ; CHECK-NEXT: i32.const $push0=, 2
633 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
634 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
635 ; CHECK-NEXT: i32.const $push3=, 40
636 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
637 ; CHECK-NEXT: i32.store 0($pop4), $2
639 %add = add nsw i32 10, %n
640 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
641 store i32 %i, ptr %arrayidx, align 4
645 define void @store_test14(ptr %p, i32 %n, i32 %i) {
646 ; CHECK-LABEL: store_test14:
647 ; CHECK: .functype store_test14 (i32, i32, i32) -> ()
648 ; CHECK-NEXT: # %bb.0:
649 ; CHECK-NEXT: i32.const $push0=, 2
650 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
651 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
652 ; CHECK-NEXT: i32.store 40($pop2), $2
654 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %n
655 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
656 store i32 %i, ptr %add.ptr1, align 4
660 define void @store_test15(ptr %p, i32 %n, i32 %i) {
661 ; CHECK-LABEL: store_test15:
662 ; CHECK: .functype store_test15 (i32, i32, i32) -> ()
663 ; CHECK-NEXT: # %bb.0:
664 ; CHECK-NEXT: i32.const $push0=, 2
665 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
666 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
667 ; CHECK-NEXT: i32.const $push3=, 40
668 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
669 ; CHECK-NEXT: i32.store 0($pop4), $2
671 %add.ptr = getelementptr inbounds i32, ptr %p, i32 10
672 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %n
673 store i32 %i, ptr %add.ptr1, align 4
677 define void @store_test16(ptr %p, i32 %n, i32 %i) {
678 ; CHECK-LABEL: store_test16:
679 ; CHECK: .functype store_test16 (i32, i32, i32) -> ()
680 ; CHECK-NEXT: # %bb.0:
681 ; CHECK-NEXT: i32.const $push0=, 2
682 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
683 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
684 ; CHECK-NEXT: i32.const $push3=, 40
685 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
686 ; CHECK-NEXT: i32.store 0($pop4), $2
688 %add.ptr = getelementptr inbounds i32, ptr %p, i32 10
689 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 %n
690 store i32 %i, ptr %add.ptr1, align 4
694 define void @store_test17(ptr %p, i32 %n, i32 %i) {
695 ; CHECK-LABEL: store_test17:
696 ; CHECK: .functype store_test17 (i32, i32, i32) -> ()
697 ; CHECK-NEXT: # %bb.0:
698 ; CHECK-NEXT: i32.const $push0=, 2
699 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
700 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
701 ; CHECK-NEXT: i32.const $push3=, 40
702 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
703 ; CHECK-NEXT: i32.store 0($pop4), $2
705 %add = add nsw i32 %n, 10
706 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %add
707 store i32 %i, ptr %add.ptr, align 4
711 define void @store_test18(ptr %p, i32 %n, i32 %i) {
712 ; CHECK-LABEL: store_test18:
713 ; CHECK: .functype store_test18 (i32, i32, i32) -> ()
714 ; CHECK-NEXT: # %bb.0:
715 ; CHECK-NEXT: i32.const $push0=, 2
716 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
717 ; CHECK-NEXT: i32.add $push2=, $0, $pop1
718 ; CHECK-NEXT: i32.store 40($pop2), $2
720 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %n
721 %add.ptr1 = getelementptr inbounds i32, ptr %add.ptr, i32 10
722 store i32 %i, ptr %add.ptr1, align 4
726 define void @store_test19(ptr %p, i32 %n, i32 %i) {
727 ; CHECK-LABEL: store_test19:
728 ; CHECK: .functype store_test19 (i32, i32, i32) -> ()
729 ; CHECK-NEXT: # %bb.0:
730 ; CHECK-NEXT: i32.const $push0=, 2
731 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
732 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
733 ; CHECK-NEXT: i32.const $push3=, 40
734 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
735 ; CHECK-NEXT: i32.store 0($pop4), $2
737 %add = add nsw i32 10, %n
738 %add.ptr = getelementptr inbounds i32, ptr %p, i32 %add
739 store i32 %i, ptr %add.ptr, align 4
743 define void @store_test20(ptr %p, i32 %i) {
744 ; CHECK-LABEL: store_test20:
745 ; CHECK: .functype store_test20 (i32, i32) -> ()
746 ; CHECK-NEXT: # %bb.0:
747 ; CHECK-NEXT: i32.const $push0=, -40
748 ; CHECK-NEXT: i32.add $push1=, $0, $pop0
749 ; CHECK-NEXT: i32.store 0($pop1), $1
751 %arrayidx = getelementptr inbounds i32, ptr %p, i32 -10
752 store i32 %i, ptr %arrayidx, align 4
756 define void @store_test21(ptr %p, i32 %n, i32 %i) {
757 ; CHECK-LABEL: store_test21:
758 ; CHECK: .functype store_test21 (i32, i32, i32) -> ()
759 ; CHECK-NEXT: # %bb.0:
760 ; CHECK-NEXT: i32.const $push0=, 2
761 ; CHECK-NEXT: i32.shl $push1=, $1, $pop0
762 ; CHECK-NEXT: i32.add $push2=, $pop1, $0
763 ; CHECK-NEXT: i32.const $push3=, -40
764 ; CHECK-NEXT: i32.add $push4=, $pop2, $pop3
765 ; CHECK-NEXT: i32.store 0($pop4), $2
767 %add = add nsw i32 %n, -10
768 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %add
769 store i32 %i, ptr %arrayidx, align 4