1 ; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
3 ; Test that constant offsets can be folded into global addresses.
5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 @x = external global [0 x i32]
9 @y = global [50 x i32] zeroinitializer
11 ; Test basic constant offsets of both defined and external symbols.
14 ; CHECK-NEXT: .functype test0 () -> (i32){{$}}
15 ; CHECK-NEXT: i32.const $push0=, x+188{{$}}
16 ; CHECK=NEXT: return $pop0{{$}}
17 define i32* @test0() {
18 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
22 ; CHECK-NEXT: .functype test1 () -> (i32){{$}}
23 ; CHECK-NEXT: i32.const $push0=, y+188{{$}}
24 ; CHECK=NEXT: return $pop0{{$}}
25 define i32* @test1() {
26 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
32 ; CHECK-NEXT: .functype test2 () -> (i32){{$}}
33 ; CHECK-NEXT: i32.const $push0=, x{{$}}
34 ; CHECK=NEXT: return $pop0{{$}}
35 define i32* @test2() {
36 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
40 ; CHECK-NEXT: .functype test3 () -> (i32){{$}}
41 ; CHECK-NEXT: i32.const $push0=, y{{$}}
42 ; CHECK=NEXT: return $pop0{{$}}
43 define i32* @test3() {
44 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
47 ; Test negative offsets.
50 ; CHECK-NEXT: .functype test4 () -> (i32){{$}}
51 ; CHECK-NEXT: i32.const $push0=, x-188{{$}}
52 ; CHECK=NEXT: return $pop0{{$}}
53 define i32* @test4() {
54 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 -47)
58 ; CHECK-NEXT: .functype test5 () -> (i32){{$}}
59 ; CHECK-NEXT: i32.const $push0=, y-188{{$}}
60 ; CHECK=NEXT: return $pop0{{$}}
61 define i32* @test5() {
62 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 -47)