1; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
2
3; Test that constant offsets can be folded into global addresses.
4
5target triple = "wasm32-unknown-unknown"
6
7@x = external dso_local global [0 x i32]
8@y = dso_local global [50 x i32] zeroinitializer
9
10; Test basic constant offsets of both defined and external symbols.
11
12; CHECK-LABEL: test0:
13; CHECK-NEXT: .functype test0 () -> (i32){{$}}
14; CHECK-NEXT: i32.const $push0=, x+188{{$}}
15; CHECK=NEXT: return $pop0{{$}}
16define dso_local i32* @test0() {
17  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
18}
19
20; CHECK-LABEL: test1:
21; CHECK-NEXT: .functype test1 () -> (i32){{$}}
22; CHECK-NEXT: i32.const $push0=, y+188{{$}}
23; CHECK=NEXT: return $pop0{{$}}
24define dso_local i32* @test1() {
25  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
26}
27
28; Test zero offsets.
29
30; CHECK-LABEL: test2:
31; CHECK-NEXT: .functype test2 () -> (i32){{$}}
32; CHECK-NEXT: i32.const $push0=, x{{$}}
33; CHECK=NEXT: return $pop0{{$}}
34define dso_local i32* @test2() {
35  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
36}
37
38; CHECK-LABEL: test3:
39; CHECK-NEXT: .functype test3 () -> (i32){{$}}
40; CHECK-NEXT: i32.const $push0=, y{{$}}
41; CHECK=NEXT: return $pop0{{$}}
42define dso_local i32* @test3() {
43  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
44}
45
46; Test negative offsets.
47
48; CHECK-LABEL: test4:
49; CHECK-NEXT: .functype test4 () -> (i32){{$}}
50; CHECK-NEXT: i32.const $push0=, x-188{{$}}
51; CHECK=NEXT: return $pop0{{$}}
52define dso_local i32* @test4() {
53  ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 -47)
54}
55
56; CHECK-LABEL: test5:
57; CHECK-NEXT: .functype test5 () -> (i32){{$}}
58; CHECK-NEXT: i32.const $push0=, y-188{{$}}
59; CHECK=NEXT: return $pop0{{$}}
60define dso_local i32* @test5() {
61  ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 -47)
62}
63