1; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefixes CHECK,CHK32 %s
2; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck --check-prefixes CHECK,CHK64 %s
3
4; Test that i1 extending loads and truncating stores are assembled properly.
5
6; CHECK-LABEL: load_u_i1_i32:
7; CHECK:      i32.load8_u $push[[NUM0:[0-9]+]]=, 0($0){{$}}
8; CHECK-NEXT: return $pop[[NUM0]]{{$}}
9define i32 @load_u_i1_i32(i1* %p) {
10  %v = load i1, i1* %p
11  %e = zext i1 %v to i32
12  ret i32 %e
13}
14
15; CHECK-LABEL: load_s_i1_i32:
16; CHECK:      i32.const $push[[NUM3:[0-9]+]]=, 0{{$}}
17; CHECK-NEXT: i32.load8_u $push[[NUM0:[0-9]+]]=, 0($0){{$}}
18; CHECK-NEXT: i32.const $push[[NUM1:[0-9]+]]=, 1{{$}}
19; CHECK-NEXT: i32.and $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
20; CHECK-NEXT: i32.sub $push[[NUM4:[0-9]+]]=, $pop[[NUM3]], $pop[[NUM2]]{{$}}
21; CHECK-NEXT: return $pop[[NUM4]]{{$}}
22define i32 @load_s_i1_i32(i1* %p) {
23  %v = load i1, i1* %p
24  %e = sext i1 %v to i32
25  ret i32 %e
26}
27
28; CHECK-LABEL: load_u_i1_i64:
29; CHECK:      i64.load8_u $push[[NUM0:[0-9]+]]=, 0($0){{$}}
30; CHECK-NEXT: return $pop[[NUM0]]{{$}}
31define i64 @load_u_i1_i64(i1* %p) {
32  %v = load i1, i1* %p
33  %e = zext i1 %v to i64
34  ret i64 %e
35}
36
37; CHECK-LABEL: load_s_i1_i64:
38; CHECK:      i64.const $push[[NUM3:[0-9]+]]=, 0{{$}}
39; CHECK-NEXT: i64.load8_u $push[[NUM0:[0-9]+]]=, 0($0){{$}}
40; CHECK-NEXT: i64.const $push[[NUM1:[0-9]+]]=, 1{{$}}
41; CHECK-NEXT: i64.and $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
42; CHECK-NEXT: i64.sub $push[[NUM4:[0-9]+]]=, $pop[[NUM3]], $pop[[NUM2]]{{$}}
43; CHECK-NEXT: return $pop[[NUM4]]{{$}}
44define i64 @load_s_i1_i64(i1* %p) {
45  %v = load i1, i1* %p
46  %e = sext i1 %v to i64
47  ret i64 %e
48}
49
50; CHECK-LABEL: store_i32_i1:
51; CHECK:      i32.const $push[[NUM0:[0-9]+]]=, 1{{$}}
52; CHECK-NEXT: i32.and $push[[NUM1:[0-9]+]]=, $1, $pop[[NUM0]]{{$}}
53; CHECK-NEXT: i32.store8 0($0), $pop[[NUM1]]{{$}}
54define void @store_i32_i1(i1* %p, i32 %v) {
55  %t = trunc i32 %v to i1
56  store i1 %t, i1* %p
57  ret void
58}
59
60; CHECK-LABEL: store_i64_i1:
61; CHECK:      i64.const $push[[NUM0:[0-9]+]]=, 1{{$}}
62; CHECK-NEXT: i64.and $push[[NUM1:[0-9]+]]=, $1, $pop[[NUM0]]{{$}}
63; CHECK-NEXT: i64.store8 0($0), $pop[[NUM1]]{{$}}
64define void @store_i64_i1(i1* %p, i64 %v) {
65  %t = trunc i64 %v to i1
66  store i1 %t, i1* %p
67  ret void
68}
69