1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mcpu=mvp -mattr=+bulk-memory | FileCheck %s --check-prefixes CHECK,BULK-MEM
2 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mcpu=mvp -mattr=-bulk-memory | FileCheck %s --check-prefixes CHECK,NO-BULK-MEM
4 ; Test that basic bulk memory codegen works correctly
6 target triple = "wasm64-unknown-unknown"
8 declare void @llvm.memcpy.p0.p0.i8(ptr, ptr, i8, i1)
9 declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)
11 declare void @llvm.memmove.p0.p0.i8(ptr, ptr, i8, i1)
12 declare void @llvm.memmove.p0.p0.i64(ptr, ptr, i64, i1)
14 declare void @llvm.memset.p0.i8(ptr, i8, i8, i1)
15 declare void @llvm.memset.p0.i64(ptr, i8, i64, i1)
17 ; CHECK-LABEL: memcpy_i8:
18 ; NO-BULK-MEM-NOT: memory.copy
19 ; BULK-MEM-NEXT: .functype memcpy_i8 (i64, i64, i32) -> ()
20 ; BULK-MEM-NEXT: i64.extend_i32_u $push0=, $2
21 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop0
22 ; BULK-MEM-NEXT: return
23 define void @memcpy_i8(ptr %dest, ptr %src, i8 zeroext %len) {
24 call void @llvm.memcpy.p0.p0.i8(ptr %dest, ptr %src, i8 %len, i1 0)
28 ; CHECK-LABEL: memmove_i8:
29 ; NO-BULK-MEM-NOT: memory.copy
30 ; BULK-MEM-NEXT: .functype memmove_i8 (i64, i64, i32) -> ()
31 ; BULK-MEM-NEXT: i64.extend_i32_u $push0=, $2
32 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop0
33 ; BULK-MEM-NEXT: return
34 define void @memmove_i8(ptr %dest, ptr %src, i8 zeroext %len) {
35 call void @llvm.memmove.p0.p0.i8(ptr %dest, ptr %src, i8 %len, i1 0)
39 ; CHECK-LABEL: memset_i8:
40 ; NO-BULK-MEM-NOT: memory.fill
41 ; BULK-MEM-NEXT: .functype memset_i8 (i64, i32, i32) -> ()
42 ; BULK-MEM-NEXT: i64.extend_i32_u $push0=, $2
43 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $pop0
44 ; BULK-MEM-NEXT: return
45 define void @memset_i8(ptr %dest, i8 %val, i8 zeroext %len) {
46 call void @llvm.memset.p0.i8(ptr %dest, i8 %val, i8 %len, i1 0)
50 ; CHECK-LABEL: memcpy_i32:
51 ; NO-BULK-MEM-NOT: memory.copy
52 ; BULK-MEM-NEXT: .functype memcpy_i32 (i64, i64, i64) -> ()
53 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
54 ; BULK-MEM-NEXT: return
55 define void @memcpy_i32(ptr %dest, ptr %src, i64 %len) {
56 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 %len, i1 0)
60 ; CHECK-LABEL: memmove_i32:
61 ; NO-BULK-MEM-NOT: memory.copy
62 ; BULK-MEM-NEXT: .functype memmove_i32 (i64, i64, i64) -> ()
63 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
64 ; BULK-MEM-NEXT: return
65 define void @memmove_i32(ptr %dest, ptr %src, i64 %len) {
66 call void @llvm.memmove.p0.p0.i64(ptr %dest, ptr %src, i64 %len, i1 0)
70 ; CHECK-LABEL: memset_i32:
71 ; NO-BULK-MEM-NOT: memory.fill
72 ; BULK-MEM-NEXT: .functype memset_i32 (i64, i32, i64) -> ()
73 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $2
74 ; BULK-MEM-NEXT: return
75 define void @memset_i32(ptr %dest, i8 %val, i64 %len) {
76 call void @llvm.memset.p0.i64(ptr %dest, i8 %val, i64 %len, i1 0)
80 ; CHECK-LABEL: memcpy_1:
81 ; CHECK-NEXT: .functype memcpy_1 (i64, i64) -> ()
82 ; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1)
83 ; CHECK-NEXT: i32.store8 0($0), $pop[[L0]]
85 define void @memcpy_1(ptr %dest, ptr %src) {
86 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1, i1 0)
90 ; CHECK-LABEL: memmove_1:
91 ; CHECK-NEXT: .functype memmove_1 (i64, i64) -> ()
92 ; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1)
93 ; CHECK-NEXT: i32.store8 0($0), $pop[[L0]]
95 define void @memmove_1(ptr %dest, ptr %src) {
96 call void @llvm.memmove.p0.p0.i64(ptr %dest, ptr %src, i64 1, i1 0)
100 ; CHECK-LABEL: memset_1:
101 ; NO-BULK-MEM-NOT: memory.fill
102 ; BULK-MEM-NEXT: .functype memset_1 (i64, i32) -> ()
103 ; BULK-MEM-NEXT: i32.store8 0($0), $1
104 ; BULK-MEM-NEXT: return
105 define void @memset_1(ptr %dest, i8 %val) {
106 call void @llvm.memset.p0.i64(ptr %dest, i8 %val, i64 1, i1 0)
110 ; CHECK-LABEL: memcpy_1024:
111 ; NO-BULK-MEM-NOT: memory.copy
112 ; BULK-MEM-NEXT: .functype memcpy_1024 (i64, i64) -> ()
113 ; BULK-MEM-NEXT: i64.const $push[[L0:[0-9]+]]=, 1024
114 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
115 ; BULK-MEM-NEXT: return
116 define void @memcpy_1024(ptr %dest, ptr %src) {
117 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1024, i1 0)
121 ; CHECK-LABEL: memmove_1024:
122 ; NO-BULK-MEM-NOT: memory.copy
123 ; BULK-MEM-NEXT: .functype memmove_1024 (i64, i64) -> ()
124 ; BULK-MEM-NEXT: i64.const $push[[L0:[0-9]+]]=, 1024
125 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
126 ; BULK-MEM-NEXT: return
127 define void @memmove_1024(ptr %dest, ptr %src) {
128 call void @llvm.memmove.p0.p0.i64(ptr %dest, ptr %src, i64 1024, i1 0)
132 ; CHECK-LABEL: memset_1024:
133 ; NO-BULK-MEM-NOT: memory.fill
134 ; BULK-MEM-NEXT: .functype memset_1024 (i64, i32) -> ()
135 ; BULK-MEM-NEXT: i64.const $push[[L0:[0-9]+]]=, 1024
136 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $pop[[L0]]
137 ; BULK-MEM-NEXT: return
138 define void @memset_1024(ptr %dest, i8 %val) {
139 call void @llvm.memset.p0.i64(ptr %dest, i8 %val, i64 1024, i1 0)
143 ; The following tests check that frame index elimination works for
144 ; bulk memory instructions. The stack pointer is bumped by 112 instead
145 ; of 100 because the stack pointer in WebAssembly is currently always
146 ; 16-byte aligned, even in leaf functions, although it is not written
147 ; back to the global in this case.
149 ; TODO: Change TransientStackAlignment to 1 to avoid this extra
150 ; arithmetic. This will require forcing the use of StackAlignment in
151 ; PrologEpilogEmitter.cpp when
152 ; WebAssemblyFrameLowering::needsSPWriteback would be true.
154 ; CHECK-LABEL: memcpy_alloca_src:
155 ; NO-BULK-MEM-NOT: memory.copy
156 ; BULK-MEM-NEXT: .functype memcpy_alloca_src (i64) -> ()
157 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
158 ; BULK-MEM-NEXT: i64.const $push[[L1:[0-9]+]]=, 112
159 ; BULK-MEM-NEXT: i64.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
160 ; BULK-MEM-NEXT: i64.const $push[[L3:[0-9]+]]=, 12
161 ; BULK-MEM-NEXT: i64.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
162 ; BULK-MEM-NEXT: i64.const $push[[L5:[0-9]+]]=, 100
163 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $pop[[L4]], $pop[[L5]]
164 ; BULK-MEM-NEXT: return
165 define void @memcpy_alloca_src(ptr %dst) {
166 %a = alloca [100 x i8]
167 call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %a, i64 100, i1 false)
171 ; CHECK-LABEL: memcpy_alloca_dst:
172 ; NO-BULK-MEM-NOT: memory.copy
173 ; BULK-MEM-NEXT: .functype memcpy_alloca_dst (i64) -> ()
174 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
175 ; BULK-MEM-NEXT: i64.const $push[[L1:[0-9]+]]=, 112
176 ; BULK-MEM-NEXT: i64.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
177 ; BULK-MEM-NEXT: i64.const $push[[L3:[0-9]+]]=, 12
178 ; BULK-MEM-NEXT: i64.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
179 ; BULK-MEM-NEXT: i64.const $push[[L5:[0-9]+]]=, 100
180 ; BULK-MEM-NEXT: memory.copy 0, 0, $pop[[L4]], $0, $pop[[L5]]
181 ; BULK-MEM-NEXT: return
182 define void @memcpy_alloca_dst(ptr %src) {
183 %a = alloca [100 x i8]
184 call void @llvm.memcpy.p0.p0.i64(ptr %a, ptr %src, i64 100, i1 false)
188 ; CHECK-LABEL: memset_alloca:
189 ; NO-BULK-MEM-NOT: memory.fill
190 ; BULK-MEM-NEXT: .functype memset_alloca (i32) -> ()
191 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
192 ; BULK-MEM-NEXT: i64.const $push[[L1:[0-9]+]]=, 112
193 ; BULK-MEM-NEXT: i64.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
194 ; BULK-MEM-NEXT: i64.const $push[[L3:[0-9]+]]=, 12
195 ; BULK-MEM-NEXT: i64.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
196 ; BULK-MEM-NEXT: i64.const $push[[L5:[0-9]+]]=, 100
197 ; BULK-MEM-NEXT: memory.fill 0, $pop[[L4]], $0, $pop[[L5]]
198 ; BULK-MEM-NEXT: return
199 define void @memset_alloca(i8 %val) {
200 %a = alloca [100 x i8]
201 call void @llvm.memset.p0.i64(ptr %a, i8 %val, i64 100, i1 false)