blob: 7fe40a1dbec6e9d337c4a4c93a4a53fabb6181c2 [file] [log] [blame]
Sam Clegg492f7522019-03-26 19:46:15 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=CHECK,NON-PIC
2; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -relocation-model=pic | FileCheck %s -check-prefixes=CHECK,PIC
3
Dan Gohman0bf3ae82016-01-22 03:57:34 +00004
5; Test folding constant offsets and symbols into load and store addresses under
6; a variety of circumstances.
7
8target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman53572d02019-06-05 20:01:01 +00009target triple = "wasm32-unknown-emscripten"
Dan Gohman0bf3ae82016-01-22 03:57:34 +000010
11@g = external global [0 x i32], align 4
12
13; CHECK-LABEL: load_test0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000014; CHECK-NEXT: .functype load_test0 () -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000015; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
16; NON-PIC-NEXT: i32.load $push1=, g+40($pop0){{$}}
17; PIC-NEXT: global.get $push0=, g@GOT{{$}}
18; PIC-NEXT: i32.load $push1=, 40($pop0){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000019; CHECK-NEXT: return $pop1{{$}}
20define i32 @load_test0() {
21 %t = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), align 4
22 ret i32 %t
23}
24
25; CHECK-LABEL: load_test0_noinbounds:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000026; CHECK-NEXT: .functype load_test0_noinbounds () -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000027; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
28; NON-PIC-NEXT: i32.load $push1=, g+40($pop0){{$}}
29; PIC-NEXT: global.get $push0=, g@GOT{{$}}
30; PIC-NEXT: i32.load $push1=, 40($pop0){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000031; CHECK-NEXT: return $pop1{{$}}
32define i32 @load_test0_noinbounds() {
33 %t = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @g, i32 0, i32 10), align 4
34 ret i32 %t
35}
36
Derek Schuff1b258d32016-08-31 20:27:20 +000037; TODO: load_test1 - load_test8 are disabled because folding GA+reg is disabled
38; (there are cases where the value in the reg can be negative).
39; Likewise for stores.
40
Dan Gohman0bf3ae82016-01-22 03:57:34 +000041; CHECK-LABEL: load_test1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000042; CHECK-NEXT: .functype load_test1 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000043; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +000044; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
45; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
46; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000047define i32 @load_test1(i32 %n) {
48 %add = add nsw i32 %n, 10
49 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
50 %t = load i32, i32* %arrayidx, align 4
51 ret i32 %t
52}
53
54; CHECK-LABEL: load_test2:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000055; CHECK-NEXT: .functype load_test2 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000056; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +000057; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
58; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
59; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000060define i32 @load_test2(i32 %n) {
61 %add = add nsw i32 10, %n
62 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
63 %t = load i32, i32* %arrayidx, align 4
64 ret i32 %t
65}
66
67; CHECK-LABEL: load_test3:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000068; CHECK-NEXT: .functype load_test3 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000069; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +000070; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
71; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
72; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000073define i32 @load_test3(i32 %n) {
74 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %n
75 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
76 %t = load i32, i32* %add.ptr1, align 4
77 ret i32 %t
78}
79
80; CHECK-LABEL: load_test4:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000081; CHECK-NEXT: .functype load_test4 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000082; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +000083; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
84; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
85; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000086define i32 @load_test4(i32 %n) {
87 %add.ptr = getelementptr inbounds i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), i32 %n
88 %t = load i32, i32* %add.ptr, align 4
89 ret i32 %t
90}
91
92; CHECK-LABEL: load_test5:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000093; CHECK-NEXT: .functype load_test5 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +000094; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +000095; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
96; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
97; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +000098define i32 @load_test5(i32 %n) {
99 %add.ptr = getelementptr inbounds i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), i32 %n
100 %t = load i32, i32* %add.ptr, align 4
101 ret i32 %t
102}
103
104; CHECK-LABEL: load_test6:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000105; CHECK-NEXT: .functype load_test6 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000106; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000107; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
108; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
109; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000110define i32 @load_test6(i32 %n) {
111 %add = add nsw i32 %n, 10
112 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
113 %t = load i32, i32* %add.ptr, align 4
114 ret i32 %t
115}
116
117; CHECK-LABEL: load_test7:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000118; CHECK-NEXT: .functype load_test7 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000119; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000120; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
121; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
122; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000123define i32 @load_test7(i32 %n) {
124 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %n
125 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
126 %t = load i32, i32* %add.ptr1, align 4
127 ret i32 %t
128}
129
130; CHECK-LABEL: load_test8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000131; CHECK-NEXT: .functype load_test8 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000132; CHECK-NEX T: i32.const $push0=, 2{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000133; CHECK-NEX T: i32.shl $push1=, $0, $pop0{{$}}
134; CHECK-NEX T: i32.load $push2=, g+40($pop1){{$}}
135; CHECK-NEX T: return $pop2{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000136define i32 @load_test8(i32 %n) {
137 %add = add nsw i32 10, %n
138 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
139 %t = load i32, i32* %add.ptr, align 4
140 ret i32 %t
141}
142
143; CHECK-LABEL: load_test9:
Sam Clegg492f7522019-03-26 19:46:15 +0000144; CHECK-NEXT: .functype load_test9 () -> (i32){{$}}
145; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
146; NON-PIC-NEXT: i32.load $push1=, g-40($pop0){{$}}
147; NON-PIC_NEXT: return $pop1{{$}}
148
149; PIC-NEXT: global.get $push1=, g@GOT{{$}}
150; PIC-NEXT: i32.const $push0=, -40{{$}}
151; PIC-NEXT: i32.add $push2=, $pop1, $pop0{{$}}
152; PIC-NEXT: i32.load $push3=, 0($pop2)
153; PIC-NEXT: return $pop3{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000154define i32 @load_test9() {
155 %t = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 1073741814), align 4
156 ret i32 %t
157}
158
159; CHECK-LABEL: load_test10:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000160; CHECK-NEXT: .functype load_test10 (i32) -> (i32){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000161; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
162; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
163; NON-PIC-NEXT: i32.const $push2=, g-40{{$}}
164; NON-PIC-NEXT: i32.add $push3=, $pop1, $pop2{{$}}
165; NON-PIC-NEXT: i32.load $push4=, 0($pop3){{$}}
166; NON-PIC-NEXT: return $pop4{{$}}
167
Sam Clegg492f7522019-03-26 19:46:15 +0000168; PIC-NEXT: i32.const $push0=, 2{{$}}
169; PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000170; PIC-NEXT: global.get $push2=, g@GOT{{$}}
171; PIC-NEXT: i32.add $push3=, $pop1, $pop2{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000172; PIC-NEXT: i32.const $push4=, -40{{$}}
173; PIC-NEXT: i32.add $push5=, $pop3, $pop4{{$}}
174; PIC-NEXT: i32.load $push6=, 0($pop5){{$}}
175; PIC-NEXT: return $pop6{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000176define i32 @load_test10(i32 %n) {
177 %add = add nsw i32 %n, -10
178 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
179 %t = load i32, i32* %arrayidx, align 4
180 ret i32 %t
181}
182
183; CHECK-LABEL: load_test11:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000184; CHECK-NEXT: .functype load_test11 (i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000185; CHECK-NEXT: i32.load $push0=, 40($0){{$}}
186; CHECK-NEXT: return $pop0{{$}}
187define i32 @load_test11(i32* %p) {
188 %arrayidx = getelementptr inbounds i32, i32* %p, i32 10
189 %t = load i32, i32* %arrayidx, align 4
190 ret i32 %t
191}
192
193; CHECK-LABEL: load_test11_noinbounds:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000194; CHECK-NEXT: .functype load_test11_noinbounds (i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000195; CHECK-NEXT: i32.const $push0=, 40{{$}}
196; CHECK-NEXT: i32.add $push1=, $0, $pop0{{$}}
197; CHECK-NEXT: i32.load $push2=, 0($pop1){{$}}
198; CHECK-NEXT: return $pop2{{$}}
199define i32 @load_test11_noinbounds(i32* %p) {
200 %arrayidx = getelementptr i32, i32* %p, i32 10
201 %t = load i32, i32* %arrayidx, align 4
202 ret i32 %t
203}
204
205; CHECK-LABEL: load_test12:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000206; CHECK-NEXT: .functype load_test12 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000207; CHECK-NEXT: i32.const $push0=, 2{{$}}
208; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000209; CHECK-NEXT: i32.add $push2=, $pop1, $0{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000210; CHECK-NEXT: i32.const $push3=, 40{{$}}
211; CHECK-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
212; CHECK-NEXT: i32.load $push5=, 0($pop4){{$}}
213; CHECK-NEXT: return $pop5{{$}}
214define i32 @load_test12(i32* %p, i32 %n) {
215 %add = add nsw i32 %n, 10
216 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
217 %t = load i32, i32* %arrayidx, align 4
218 ret i32 %t
219}
220
221; CHECK-LABEL: load_test13:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000222; CHECK-NEXT: .functype load_test13 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000223; CHECK-NEXT: i32.const $push0=, 2{{$}}
224; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000225; CHECK-NEXT: i32.add $push2=, $pop1, $0{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000226; CHECK-NEXT: i32.const $push3=, 40{{$}}
227; CHECK-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
228; CHECK-NEXT: i32.load $push5=, 0($pop4){{$}}
229; CHECK-NEXT: return $pop5{{$}}
230define i32 @load_test13(i32* %p, i32 %n) {
231 %add = add nsw i32 10, %n
232 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
233 %t = load i32, i32* %arrayidx, align 4
234 ret i32 %t
235}
236
237; CHECK-LABEL: load_test14:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000238; CHECK-NEXT: .functype load_test14 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000239; CHECK-NEXT: i32.const $push0=, 2{{$}}
240; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
241; CHECK-NEXT: i32.add $push2=, $0, $pop1{{$}}
242; CHECK-NEXT: i32.load $push3=, 40($pop2){{$}}
243; CHECK-NEXT: return $pop3{{$}}
244define i32 @load_test14(i32* %p, i32 %n) {
245 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %n
246 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
247 %t = load i32, i32* %add.ptr1, align 4
248 ret i32 %t
249}
250
251; CHECK-LABEL: load_test15:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000252; CHECK-NEXT: .functype load_test15 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000253; CHECK-NEXT: i32.const $push0=, 2{{$}}
254; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
255; CHECK-NEXT: i32.add $push2=, $0, $pop1{{$}}
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{{$}}
260define i32 @load_test15(i32* %p, i32 %n) {
261 %add.ptr = getelementptr inbounds i32, i32* %p, i32 10
262 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %n
263 %t = load i32, i32* %add.ptr1, align 4
264 ret i32 %t
265}
266
267; CHECK-LABEL: load_test16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000268; CHECK-NEXT: .functype load_test16 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000269; CHECK-NEXT: i32.const $push0=, 2{{$}}
270; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
271; CHECK-NEXT: i32.add $push2=, $0, $pop1{{$}}
272; CHECK-NEXT: i32.const $push3=, 40{{$}}
273; CHECK-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
274; CHECK-NEXT: i32.load $push5=, 0($pop4){{$}}
275; CHECK-NEXT: return $pop5{{$}}
276define i32 @load_test16(i32* %p, i32 %n) {
277 %add.ptr = getelementptr inbounds i32, i32* %p, i32 10
278 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %n
279 %t = load i32, i32* %add.ptr1, align 4
280 ret i32 %t
281}
282
283; CHECK-LABEL: load_test17:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000284; CHECK-NEXT: .functype load_test17 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000285; CHECK-NEXT: i32.const $push0=, 2{{$}}
286; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000287; CHECK-NEXT: i32.add $push2=, $pop1, $0{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000288; 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{{$}}
292define i32 @load_test17(i32* %p, i32 %n) {
293 %add = add nsw i32 %n, 10
294 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %add
295 %t = load i32, i32* %add.ptr, align 4
296 ret i32 %t
297}
298
299; CHECK-LABEL: load_test18:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000300; CHECK-NEXT: .functype load_test18 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000301; CHECK-NEXT: i32.const $push0=, 2{{$}}
302; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
303; CHECK-NEXT: i32.add $push2=, $0, $pop1{{$}}
304; CHECK-NEXT: i32.load $push3=, 40($pop2){{$}}
305; CHECK-NEXT: return $pop3{{$}}
306define i32 @load_test18(i32* %p, i32 %n) {
307 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %n
308 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
309 %t = load i32, i32* %add.ptr1, align 4
310 ret i32 %t
311}
312
313; CHECK-LABEL: load_test19:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000314; CHECK-NEXT: .functype load_test19 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000315; CHECK-NEXT: i32.const $push0=, 2{{$}}
316; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000317; CHECK-NEXT: i32.add $push2=, $pop1, $0{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000318; CHECK-NEXT: i32.const $push3=, 40{{$}}
319; CHECK-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
320; CHECK-NEXT: i32.load $push5=, 0($pop4){{$}}
321; CHECK-NEXT: return $pop5{{$}}
322define i32 @load_test19(i32* %p, i32 %n) {
323 %add = add nsw i32 10, %n
324 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %add
325 %t = load i32, i32* %add.ptr, align 4
326 ret i32 %t
327}
328
329; CHECK-LABEL: load_test20:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000330; CHECK-NEXT: .functype load_test20 (i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000331; CHECK-NEXT: i32.const $push0=, -40{{$}}
332; CHECK-NEXT: i32.add $push1=, $0, $pop0{{$}}
333; CHECK-NEXT: i32.load $push2=, 0($pop1){{$}}
334; CHECK-NEXT: return $pop2{{$}}
335define i32 @load_test20(i32* %p) {
336 %arrayidx = getelementptr inbounds i32, i32* %p, i32 -10
337 %t = load i32, i32* %arrayidx, align 4
338 ret i32 %t
339}
340
341; CHECK-LABEL: load_test21:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000342; CHECK-NEXT: .functype load_test21 (i32, i32) -> (i32){{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000343; CHECK-NEXT: i32.const $push0=, 2{{$}}
344; CHECK-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000345; CHECK-NEXT: i32.add $push2=, $pop1, $0{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000346; CHECK-NEXT: i32.const $push3=, -40{{$}}
347; CHECK-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
348; CHECK-NEXT: i32.load $push5=, 0($pop4){{$}}
349; CHECK-NEXT: return $pop5{{$}}
350define i32 @load_test21(i32* %p, i32 %n) {
351 %add = add nsw i32 %n, -10
352 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
353 %t = load i32, i32* %arrayidx, align 4
354 ret i32 %t
355}
356
357; CHECK-LABEL: store_test0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000358; CHECK-NEXT: .functype store_test0 (i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000359; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
360; NON-PIC-NEXT: i32.store g+40($pop0), $0{{$}}
361; PIC-NEXT: global.get $push0=, g@GOT{{$}}
362; PIC-NEXT: i32.store 40($pop0), $0
363; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000364define void @store_test0(i32 %i) {
365 store i32 %i, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), align 4
366 ret void
367}
368
369; CHECK-LABEL: store_test0_noinbounds:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000370; CHECK-NEXT: .functype store_test0_noinbounds (i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000371; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
372; NON-PIC-NEXT: i32.store g+40($pop0), $0{{$}}
373; PIC-NEXT: global.get $push0=, g@GOT{{$}}
374; PIC-NEXT: i32.store 40($pop0), $0{{$}}
375; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000376define void @store_test0_noinbounds(i32 %i) {
377 store i32 %i, i32* getelementptr ([0 x i32], [0 x i32]* @g, i32 0, i32 10), align 4
378 ret void
379}
380
381; CHECK-LABEL: store_test1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000382; CHECK-NEXT: .functype store_test1 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000383; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
384; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000385; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
386; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000387define void @store_test1(i32 %n, i32 %i) {
388 %add = add nsw i32 %n, 10
389 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
390 store i32 %i, i32* %arrayidx, align 4
391 ret void
392}
393
394; CHECK-LABEL: store_test2:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000395; CHECK-NEXT: .functype store_test2 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000396; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
397; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000398; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
399; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000400define void @store_test2(i32 %n, i32 %i) {
401 %add = add nsw i32 10, %n
402 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
403 store i32 %i, i32* %arrayidx, align 4
404 ret void
405}
406
407; CHECK-LABEL: store_test3:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000408; CHECK-NEXT: .functype store_test3 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000409; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
410; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000411; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
412; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000413define void @store_test3(i32 %n, i32 %i) {
414 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %n
415 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
416 store i32 %i, i32* %add.ptr1, align 4
417 ret void
418}
419
420; CHECK-LABEL: store_test4:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000421; CHECK-NEXT: .functype store_test4 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000422; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
423; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000424; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
425; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000426define void @store_test4(i32 %n, i32 %i) {
427 %add.ptr = getelementptr inbounds i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), i32 %n
428 store i32 %i, i32* %add.ptr, align 4
429 ret void
430}
431
432; CHECK-LABEL: store_test5:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000433; CHECK-NEXT: .functype store_test5 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000434; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
435; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000436; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
437; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000438define void @store_test5(i32 %n, i32 %i) {
439 %add.ptr = getelementptr inbounds i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 10), i32 %n
440 store i32 %i, i32* %add.ptr, align 4
441 ret void
442}
443
444; CHECK-LABEL: store_test6:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000445; CHECK-NEXT: .functype store_test6 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000446; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
447; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000448; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
449; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000450define void @store_test6(i32 %n, i32 %i) {
451 %add = add nsw i32 %n, 10
452 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
453 store i32 %i, i32* %add.ptr, align 4
454 ret void
455}
456
457; CHECK-LABEL: store_test7:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000458; CHECK-NEXT: .functype store_test7 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000459; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
460; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000461; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
462; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000463define void @store_test7(i32 %n, i32 %i) {
464 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %n
465 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
466 store i32 %i, i32* %add.ptr1, align 4
467 ret void
468}
469
470; CHECK-LABEL: store_test8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000471; CHECK-NEXT: .functype store_test8 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000472; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
473; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Krasimir Georgiev004f9d42018-07-05 11:30:15 +0000474; CHECK-NEX T: i32.store g+40($pop1), $1{{$}}
475; CHECK-NEX T: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000476define void @store_test8(i32 %n, i32 %i) {
477 %add = add nsw i32 10, %n
478 %add.ptr = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
479 store i32 %i, i32* %add.ptr, align 4
480 ret void
481}
482
483; CHECK-LABEL: store_test9:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000484; CHECK-NEXT: .functype store_test9 (i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000485; NON-PIC-NEXT: i32.const $push0=, 0{{$}}
486; NON-PIC-NEXT: i32.store g-40($pop0), $0{{$}}
487; PIC-NEXT: global.get $push1=, g@GOT{{$}}
488; PIC-NEXT: i32.const $push0=, -40{{$}}
489; PIC-NEXT: i32.add $push2=, $pop1, $pop0{{$}}
490; PIC-NEXT: i32.store 0($pop2), $0
491; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000492define void @store_test9(i32 %i) {
493 store i32 %i, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @g, i32 0, i32 1073741814), align 4
494 ret void
495}
496
497; CHECK-LABEL: store_test10:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000498; CHECK-NEXT: .functype store_test10 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000499; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
500; NON-PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
501; NON-PIC-NEXT: i32.const $push2=, g-40{{$}}
502; NON-PIC-NEXT: i32.add $push3=, $pop1, $pop2{{$}}
503; NON-PIC-NEXT: i32.store 0($pop3), $1{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000504; PIC-NEXT: i32.const $push0=, 2{{$}}
505; PIC-NEXT: i32.shl $push1=, $0, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000506; PIC-NEXT: global.get $push2=, g@GOT{{$}}
507; PIC-NEXT: i32.add $push3=, $pop1, $pop2{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000508; PIC-NEXT: i32.const $push4=, -40{{$}}
509; PIC-NEXT: i32.add $push5=, $pop3, $pop4{{$}}
510; PIC-NEXT: i32.store 0($pop5), $1{{$}}
511; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000512define void @store_test10(i32 %n, i32 %i) {
513 %add = add nsw i32 %n, -10
514 %arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i32 0, i32 %add
515 store i32 %i, i32* %arrayidx, align 4
516 ret void
517}
518
519; CHECK-LABEL: store_test11:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000520; CHECK-NEXT: .functype store_test11 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000521; CHECK-NEXT: i32.store 40($0), $1{{$}}
522; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000523define void @store_test11(i32* %p, i32 %i) {
524 %arrayidx = getelementptr inbounds i32, i32* %p, i32 10
525 store i32 %i, i32* %arrayidx, align 4
526 ret void
527}
528
529; CHECK-LABEL: store_test11_noinbounds:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000530; CHECK-NEXT: .functype store_test11_noinbounds (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000531; CHECK-NEXT: i32.const $push0=, 40{{$}}
532; CHECK-NEXT: i32.add $push1=, $0, $pop0{{$}}
533; CHECK-NEXT: i32.store 0($pop1), $1{{$}}
534; CHECK-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000535define void @store_test11_noinbounds(i32* %p, i32 %i) {
536 %arrayidx = getelementptr i32, i32* %p, i32 10
537 store i32 %i, i32* %arrayidx, align 4
538 ret void
539}
540
541; CHECK-LABEL: store_test12:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000542; CHECK-NEXT: .functype store_test12 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000543; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
544; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000545; NON-PIC-NEXT: i32.add $push2=, $pop1, $0{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000546; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
547; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
548; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
549; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000550define void @store_test12(i32* %p, i32 %n, i32 %i) {
551 %add = add nsw i32 %n, 10
552 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
553 store i32 %i, i32* %arrayidx, align 4
554 ret void
555}
556
557; CHECK-LABEL: store_test13:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000558; CHECK-NEXT: .functype store_test13 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000559; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
560; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000561; NON-PIC-NEXT: i32.add $push2=, $pop1, $0{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000562; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
563; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
564; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
565; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000566define void @store_test13(i32* %p, i32 %n, i32 %i) {
567 %add = add nsw i32 10, %n
568 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
569 store i32 %i, i32* %arrayidx, align 4
570 ret void
571}
572
573; CHECK-LABEL: store_test14:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000574; CHECK-NEXT: .functype store_test14 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000575; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
576; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
577; NON-PIC-NEXT: i32.add $push2=, $0, $pop1{{$}}
578; NON-PIC-NEXT: i32.store 40($pop2), $2{{$}}
579; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000580define void @store_test14(i32* %p, i32 %n, i32 %i) {
581 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %n
582 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
583 store i32 %i, i32* %add.ptr1, align 4
584 ret void
585}
586
587; CHECK-LABEL: store_test15:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000588; CHECK-NEXT: .functype store_test15 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000589; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
590; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
591; NON-PIC-NEXT: i32.add $push2=, $0, $pop1{{$}}
592; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
593; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
594; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
595; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000596define void @store_test15(i32* %p, i32 %n, i32 %i) {
597 %add.ptr = getelementptr inbounds i32, i32* %p, i32 10
598 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %n
599 store i32 %i, i32* %add.ptr1, align 4
600 ret void
601}
602
603; CHECK-LABEL: store_test16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000604; CHECK-NEXT: .functype store_test16 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000605; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
606; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
607; NON-PIC-NEXT: i32.add $push2=, $0, $pop1{{$}}
608; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
609; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
610; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
611; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000612define void @store_test16(i32* %p, i32 %n, i32 %i) {
613 %add.ptr = getelementptr inbounds i32, i32* %p, i32 10
614 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 %n
615 store i32 %i, i32* %add.ptr1, align 4
616 ret void
617}
618
619; CHECK-LABEL: store_test17:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000620; CHECK-NEXT: .functype store_test17 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000621; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
622; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000623; NON-PIC-NEXT: i32.add $push2=, $pop1, $0{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000624; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
625; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
626; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
627; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000628define void @store_test17(i32* %p, i32 %n, i32 %i) {
629 %add = add nsw i32 %n, 10
630 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %add
631 store i32 %i, i32* %add.ptr, align 4
632 ret void
633}
634
635; CHECK-LABEL: store_test18:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000636; CHECK-NEXT: .functype store_test18 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000637; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
638; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
639; NON-PIC-NEXT: i32.add $push2=, $0, $pop1{{$}}
640; NON-PIC-NEXT: i32.store 40($pop2), $2{{$}}
641; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000642define void @store_test18(i32* %p, i32 %n, i32 %i) {
643 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %n
644 %add.ptr1 = getelementptr inbounds i32, i32* %add.ptr, i32 10
645 store i32 %i, i32* %add.ptr1, align 4
646 ret void
647}
648
649; CHECK-LABEL: store_test19:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000650; CHECK-NEXT: .functype store_test19 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000651; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
652; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000653; NON-PIC-NEXT: i32.add $push2=, $pop1, $0{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000654; NON-PIC-NEXT: i32.const $push3=, 40{{$}}
655; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
656; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
657; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000658define void @store_test19(i32* %p, i32 %n, i32 %i) {
659 %add = add nsw i32 10, %n
660 %add.ptr = getelementptr inbounds i32, i32* %p, i32 %add
661 store i32 %i, i32* %add.ptr, align 4
662 ret void
663}
664
665; CHECK-LABEL: store_test20:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000666; CHECK-NEXT: .functype store_test20 (i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000667; NON-PIC-NEXT: i32.const $push0=, -40{{$}}
668; NON-PIC-NEXT: i32.add $push1=, $0, $pop0{{$}}
669; NON-PIC-NEXT: i32.store 0($pop1), $1{{$}}
670; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000671define void @store_test20(i32* %p, i32 %i) {
672 %arrayidx = getelementptr inbounds i32, i32* %p, i32 -10
673 store i32 %i, i32* %arrayidx, align 4
674 ret void
675}
676
677; CHECK-LABEL: store_test21:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000678; CHECK-NEXT: .functype store_test21 (i32, i32, i32) -> (){{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000679; NON-PIC-NEXT: i32.const $push0=, 2{{$}}
680; NON-PIC-NEXT: i32.shl $push1=, $1, $pop0{{$}}
Bjorn Pettersson82099452019-04-29 17:50:10 +0000681; NON-PIC-NEXT: i32.add $push2=, $pop1, $0{{$}}
Sam Clegg492f7522019-03-26 19:46:15 +0000682; NON-PIC-NEXT: i32.const $push3=, -40{{$}}
683; NON-PIC-NEXT: i32.add $push4=, $pop2, $pop3{{$}}
684; NON-PIC-NEXT: i32.store 0($pop4), $2{{$}}
685; NON-PIC-NEXT: return{{$}}
Dan Gohman0bf3ae82016-01-22 03:57:34 +0000686define void @store_test21(i32* %p, i32 %n, i32 %i) {
687 %add = add nsw i32 %n, -10
688 %arrayidx = getelementptr inbounds i32, i32* %p, i32 %add
689 store i32 %i, i32* %arrayidx, align 4
690 ret void
691}