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