blob: 54a8636b53e223217923e9058ec34fdcda205fe5 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
Dan Gohmana4b710a2015-12-06 19:33:32 +00002
3; Test that constant offsets can be folded into global addresses.
4
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00006target triple = "wasm32-unknown-unknown"
Dan Gohmana4b710a2015-12-06 19:33:32 +00007
Dan Gohmanf2f92f12016-01-15 23:47:19 +00008@x = external global [0 x i32]
Dan Gohmana4b710a2015-12-06 19:33:32 +00009@y = global [50 x i32] zeroinitializer
10
11; Test basic constant offsets of both defined and external symbols.
12
13; CHECK-LABEL: test0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000014; CHECK-NEXT: .functype test0 () -> (i32){{$}}
Dan Gohmana4b710a2015-12-06 19:33:32 +000015; CHECK-NEXT: i32.const $push0=, x+188{{$}}
16; CHECK=NEXT: return $pop0{{$}}
17define i32* @test0() {
18 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 47)
19}
20
21; CHECK-LABEL: test1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000022; CHECK-NEXT: .functype test1 () -> (i32){{$}}
Dan Gohmana4b710a2015-12-06 19:33:32 +000023; CHECK-NEXT: i32.const $push0=, y+188{{$}}
24; CHECK=NEXT: return $pop0{{$}}
25define i32* @test1() {
26 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 47)
27}
28
29; Test zero offsets.
30
31; CHECK-LABEL: test2:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000032; CHECK-NEXT: .functype test2 () -> (i32){{$}}
Dan Gohmana4b710a2015-12-06 19:33:32 +000033; CHECK-NEXT: i32.const $push0=, x{{$}}
34; CHECK=NEXT: return $pop0{{$}}
35define i32* @test2() {
36 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 0)
37}
38
39; CHECK-LABEL: test3:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000040; CHECK-NEXT: .functype test3 () -> (i32){{$}}
Dan Gohmana4b710a2015-12-06 19:33:32 +000041; CHECK-NEXT: i32.const $push0=, y{{$}}
42; CHECK=NEXT: return $pop0{{$}}
43define i32* @test3() {
44 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 0)
45}
Dan Gohman619db962016-01-25 15:19:39 +000046
47; Test negative offsets.
48
49; CHECK-LABEL: test4:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000050; CHECK-NEXT: .functype test4 () -> (i32){{$}}
Dan Gohman619db962016-01-25 15:19:39 +000051; CHECK-NEXT: i32.const $push0=, x-188{{$}}
52; CHECK=NEXT: return $pop0{{$}}
53define i32* @test4() {
54 ret i32* getelementptr ([0 x i32], [0 x i32]* @x, i32 0, i32 -47)
55}
56
57; CHECK-LABEL: test5:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000058; CHECK-NEXT: .functype test5 () -> (i32){{$}}
Dan Gohman619db962016-01-25 15:19:39 +000059; CHECK-NEXT: i32.const $push0=, y-188{{$}}
60; CHECK=NEXT: return $pop0{{$}}
61define i32* @test5() {
62 ret i32* getelementptr ([50 x i32], [50 x i32]* @y, i32 0, i32 -47)
63}