2b4e8a90b0f0da32eca3e0f6b949616635727fab
[oota-llvm.git] / test / CodeGen / WebAssembly / offset-folding.ll
1 ; RUN: llc < %s -asm-verbose=false | FileCheck %s
2
3 ; Test that constant offsets can be folded into global addresses.
4
5 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
7
8 ; FIXME: make this 'external' and make sure it still works. WebAssembly
9 ;        currently only supports linking single files, so 'external' makes
10 ;        little sense.
11 @x = global [0 x i32] zeroinitializer
12 @y = global [50 x i32] zeroinitializer
13
14 ; Test basic constant offsets of both defined and external symbols.
15
16 ; CHECK-LABEL: test0:
17 ; CHECK-NEXT: .result i32{{$}}
18 ; CHECK-NEXT: i32.const $push0=, x+188{{$}}
19 ; CHECK=NEXT: return $pop0{{$}}
20 define i32* @test0() {
21   ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
22 }
23
24 ; CHECK-LABEL: test1:
25 ; CHECK-NEXT: .result i32{{$}}
26 ; CHECK-NEXT: i32.const $push0=, y+188{{$}}
27 ; CHECK=NEXT: return $pop0{{$}}
28 define i32* @test1() {
29   ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
30 }
31
32 ; Test zero offsets.
33
34 ; CHECK-LABEL: test2:
35 ; CHECK-NEXT: .result i32{{$}}
36 ; CHECK-NEXT: i32.const $push0=, x{{$}}
37 ; CHECK=NEXT: return $pop0{{$}}
38 define i32* @test2() {
39   ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
40 }
41
42 ; CHECK-LABEL: test3:
43 ; CHECK-NEXT: .result i32{{$}}
44 ; CHECK-NEXT: i32.const $push0=, y{{$}}
45 ; CHECK=NEXT: return $pop0{{$}}
46 define i32* @test3() {
47   ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
48 }