1; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers -fast-isel -fast-isel-abort=1 | FileCheck %s
2
3; TODO: Merge this with offset.ll when fast-isel matches better.
4
5target triple = "wasm32-unknown-unknown"
6
7; CHECK-LABEL: store_i8_with_variable_gep_offset:
8; CHECK: i32.add    $push[[L0:[0-9]+]]=, $0, $1{{$}}
9; CHECK: i32.const  $push[[L1:[0-9]+]]=, 0{{$}}
10; CHECK: i32.store8 0($pop[[L0]]), $pop[[L1]]{{$}}
11define void @store_i8_with_variable_gep_offset(i8* %p, i32 %idx) {
12  %s = getelementptr inbounds i8, i8* %p, i32 %idx
13  store i8 0, i8* %s
14  ret void
15}
16
17; CHECK-LABEL: store_i8_with_array_alloca_gep:
18; CHECK: global.get  $push[[L0:[0-9]+]]=, __stack_pointer
19; CHECK: i32.const   $push[[L1:[0-9]+]]=, 32{{$}}
20; CHECK: i32.sub     $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
21; CHECK: local.copy  $push[[L3:[0-9]+]]=, $pop[[L2]]
22; CHECK: i32.add     $push[[L4:[0-9]+]]=, $pop[[L3]], $0{{$}}
23; CHECK: i32.const   $push[[L5:[0-9]+]]=, 0{{$}}
24; CHECK: i32.store8  0($pop[[L4]]), $pop[[L5]]{{$}}
25define hidden void @store_i8_with_array_alloca_gep(i32 %idx) {
26  %A = alloca [30 x i8], align 16
27  %s = getelementptr inbounds [30 x i8], [30 x i8]* %A, i32 0, i32 %idx
28  store i8 0, i8* %s, align 1
29  ret void
30}
31
32; CHECK-LABEL: store_i32_with_unfolded_gep_offset:
33; CHECK: i32.const $push[[L0:[0-9]+]]=, 24{{$}}
34; CHECK: i32.add   $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
35; CHECK: i32.const $push[[L2:[0-9]+]]=, 0{{$}}
36; CHECK: i32.store 0($pop[[L1]]), $pop[[L2]]{{$}}
37define void @store_i32_with_unfolded_gep_offset(i32* %p) {
38  %s = getelementptr i32, i32* %p, i32 6
39  store i32 0, i32* %s
40  ret void
41}
42
43; CHECK-LABEL: store_i32_with_folded_gep_offset:
44; CHECK: i32.store 24($0), $pop{{[0-9]+$}}
45define void @store_i32_with_folded_gep_offset(i32* %p) {
46  %s = getelementptr inbounds i32, i32* %p, i32 6
47  store i32 0, i32* %s
48  ret void
49}
50
51; CHECK-LABEL: load_i32_with_folded_gep_offset:
52; CHECK: i32.load  $push{{[0-9]+}}=, 24($0){{$}}
53define i32 @load_i32_with_folded_gep_offset(i32* %p) {
54  %s = getelementptr inbounds i32, i32* %p, i32 6
55  %t = load i32, i32* %s
56  ret i32 %t
57}
58
59; CHECK-LABEL: store_i64_with_unfolded_gep_offset:
60; CHECK: i32.const $push[[L0:[0-9]+]]=, 24{{$}}
61; CHECK: i32.add   $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
62; CHECK: i64.const $push[[L2:[0-9]+]]=, 0{{$}}
63; CHECK: i64.store 0($pop[[L1]]), $pop[[L2]]{{$}}
64define void @store_i64_with_unfolded_gep_offset(i64* %p) {
65  %s = getelementptr i64, i64* %p, i32 3
66  store i64 0, i64* %s
67  ret void
68}
69
70; CHECK-LABEL: store_i8_with_folded_gep_offset:
71; CHECK: i32.store8 24($0), $pop{{[0-9]+$}}
72define void @store_i8_with_folded_gep_offset(i8* %p) {
73  %s = getelementptr inbounds i8, i8* %p, i32 24
74  store i8 0, i8* %s
75  ret void
76}
77
78; CHECK-LABEL: load_i8_u_with_folded_offset:
79; CHECK: i32.load8_u $push{{[0-9]+}}=, 24($0){{$}}
80define i32 @load_i8_u_with_folded_offset(i8* %p) {
81  %q = ptrtoint i8* %p to i32
82  %r = add nuw i32 %q, 24
83  %s = inttoptr i32 %r to i8*
84  %t = load i8, i8* %s
85  %u = zext i8 %t to i32
86  ret i32 %u
87}
88
89; TODO: this should be load8_s, need to fold sign-/zero-extend in fast-isel
90; CHECK-LABEL: load_i8_s_with_folded_offset:
91; CHECK: i32.load8_u $push{{[0-9]+}}=, 24($0){{$}}
92define i32 @load_i8_s_with_folded_offset(i8* %p) {
93  %q = ptrtoint i8* %p to i32
94  %r = add nuw i32 %q, 24
95  %s = inttoptr i32 %r to i8*
96  %t = load i8, i8* %s
97  %u = sext i8 %t to i32
98  ret i32 %u
99}
100