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 = "wasm32-unknown-unknown"
8 declare void @llvm.memcpy.p0.p0.i8(ptr, ptr, i8, i1)
9 declare void @llvm.memcpy.p0.p0.i32(ptr, ptr, i32, i1)
11 declare void @llvm.memmove.p0.p0.i8(ptr, ptr, i8, i1)
12 declare void @llvm.memmove.p0.p0.i32(ptr, ptr, i32, i1)
14 declare void @llvm.memset.p0.i8(ptr, i8, i8, i1)
15 declare void @llvm.memset.p0.i32(ptr, i8, i32, i1)
17 ; CHECK-LABEL: memcpy_i8:
18 ; NO-BULK-MEM-NOT: memory.copy
19 ; BULK-MEM-NEXT: .functype memcpy_i8 (i32, i32, i32) -> ()
20 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
21 ; BULK-MEM-NEXT: return
22 define void @memcpy_i8(ptr %dest, ptr %src, i8 zeroext %len) {
23 call void @llvm.memcpy.p0.p0.i8(ptr %dest, ptr %src, i8 %len, i1 0)
27 ; CHECK-LABEL: memmove_i8:
28 ; NO-BULK-MEM-NOT: memory.copy
29 ; BULK-MEM-NEXT: .functype memmove_i8 (i32, i32, i32) -> ()
30 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
31 ; BULK-MEM-NEXT: return
32 define void @memmove_i8(ptr %dest, ptr %src, i8 zeroext %len) {
33 call void @llvm.memmove.p0.p0.i8(ptr %dest, ptr %src, i8 %len, i1 0)
37 ; CHECK-LABEL: memset_i8:
38 ; NO-BULK-MEM-NOT: memory.fill
39 ; BULK-MEM-NEXT: .functype memset_i8 (i32, i32, i32) -> ()
40 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $2
41 ; BULK-MEM-NEXT: return
42 define void @memset_i8(ptr %dest, i8 %val, i8 zeroext %len) {
43 call void @llvm.memset.p0.i8(ptr %dest, i8 %val, i8 %len, i1 0)
47 ; CHECK-LABEL: memcpy_i32:
48 ; NO-BULK-MEM-NOT: memory.copy
49 ; BULK-MEM-NEXT: .functype memcpy_i32 (i32, i32, i32) -> ()
50 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
51 ; BULK-MEM-NEXT: return
52 define void @memcpy_i32(ptr %dest, ptr %src, i32 %len) {
53 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 %len, i1 0)
57 ; CHECK-LABEL: memmove_i32:
58 ; NO-BULK-MEM-NOT: memory.copy
59 ; BULK-MEM-NEXT: .functype memmove_i32 (i32, i32, i32) -> ()
60 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $2
61 ; BULK-MEM-NEXT: return
62 define void @memmove_i32(ptr %dest, ptr %src, i32 %len) {
63 call void @llvm.memmove.p0.p0.i32(ptr %dest, ptr %src, i32 %len, i1 0)
67 ; CHECK-LABEL: memset_i32:
68 ; NO-BULK-MEM-NOT: memory.fill
69 ; BULK-MEM-NEXT: .functype memset_i32 (i32, i32, i32) -> ()
70 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $2
71 ; BULK-MEM-NEXT: return
72 define void @memset_i32(ptr %dest, i8 %val, i32 %len) {
73 call void @llvm.memset.p0.i32(ptr %dest, i8 %val, i32 %len, i1 0)
77 ; CHECK-LABEL: memcpy_1:
78 ; CHECK-NEXT: .functype memcpy_1 (i32, i32) -> ()
79 ; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1)
80 ; CHECK-NEXT: i32.store8 0($0), $pop[[L0]]
82 define void @memcpy_1(ptr %dest, ptr %src) {
83 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 1, i1 0)
87 ; CHECK-LABEL: memmove_1:
88 ; CHECK-NEXT: .functype memmove_1 (i32, i32) -> ()
89 ; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1)
90 ; CHECK-NEXT: i32.store8 0($0), $pop[[L0]]
92 define void @memmove_1(ptr %dest, ptr %src) {
93 call void @llvm.memmove.p0.p0.i32(ptr %dest, ptr %src, i32 1, i1 0)
97 ; CHECK-LABEL: memset_1:
98 ; NO-BULK-MEM-NOT: memory.fill
99 ; BULK-MEM-NEXT: .functype memset_1 (i32, i32) -> ()
100 ; BULK-MEM-NEXT: i32.store8 0($0), $1
101 ; BULK-MEM-NEXT: return
102 define void @memset_1(ptr %dest, i8 %val) {
103 call void @llvm.memset.p0.i32(ptr %dest, i8 %val, i32 1, i1 0)
107 ; CHECK-LABEL: memcpy_1024:
108 ; NO-BULK-MEM-NOT: memory.copy
109 ; BULK-MEM-NEXT: .functype memcpy_1024 (i32, i32) -> ()
110 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
111 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
112 ; BULK-MEM-NEXT: return
113 define void @memcpy_1024(ptr %dest, ptr %src) {
114 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 1024, i1 0)
118 ; CHECK-LABEL: memmove_1024:
119 ; NO-BULK-MEM-NOT: memory.copy
120 ; BULK-MEM-NEXT: .functype memmove_1024 (i32, i32) -> ()
121 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
122 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $1, $pop[[L0]]
123 ; BULK-MEM-NEXT: return
124 define void @memmove_1024(ptr %dest, ptr %src) {
125 call void @llvm.memmove.p0.p0.i32(ptr %dest, ptr %src, i32 1024, i1 0)
129 ; CHECK-LABEL: memset_1024:
130 ; NO-BULK-MEM-NOT: memory.fill
131 ; BULK-MEM-NEXT: .functype memset_1024 (i32, i32) -> ()
132 ; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024
133 ; BULK-MEM-NEXT: memory.fill 0, $0, $1, $pop[[L0]]
134 ; BULK-MEM-NEXT: return
135 define void @memset_1024(ptr %dest, i8 %val) {
136 call void @llvm.memset.p0.i32(ptr %dest, i8 %val, i32 1024, i1 0)
140 ; The following tests check that frame index elimination works for
141 ; bulk memory instructions. The stack pointer is bumped by 112 instead
142 ; of 100 because the stack pointer in WebAssembly is currently always
143 ; 16-byte aligned, even in leaf functions, although it is not written
144 ; back to the global in this case.
146 ; TODO: Change TransientStackAlignment to 1 to avoid this extra
147 ; arithmetic. This will require forcing the use of StackAlignment in
148 ; PrologEpilogEmitter.cpp when
149 ; WebAssemblyFrameLowering::needsSPWriteback would be true.
151 ; CHECK-LABEL: memcpy_alloca_src:
152 ; NO-BULK-MEM-NOT: memory.copy
153 ; BULK-MEM-NEXT: .functype memcpy_alloca_src (i32) -> ()
154 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
155 ; BULK-MEM-NEXT: i32.const $push[[L1:[0-9]+]]=, 112
156 ; BULK-MEM-NEXT: i32.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
157 ; BULK-MEM-NEXT: i32.const $push[[L3:[0-9]+]]=, 12
158 ; BULK-MEM-NEXT: i32.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
159 ; BULK-MEM-NEXT: i32.const $push[[L5:[0-9]+]]=, 100
160 ; BULK-MEM-NEXT: memory.copy 0, 0, $0, $pop[[L4]], $pop[[L5]]
161 ; BULK-MEM-NEXT: return
162 define void @memcpy_alloca_src(ptr %dst) {
163 %a = alloca [100 x i8]
164 call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %a, i32 100, i1 false)
168 ; CHECK-LABEL: memcpy_alloca_dst:
169 ; NO-BULK-MEM-NOT: memory.copy
170 ; BULK-MEM-NEXT: .functype memcpy_alloca_dst (i32) -> ()
171 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
172 ; BULK-MEM-NEXT: i32.const $push[[L1:[0-9]+]]=, 112
173 ; BULK-MEM-NEXT: i32.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
174 ; BULK-MEM-NEXT: i32.const $push[[L3:[0-9]+]]=, 12
175 ; BULK-MEM-NEXT: i32.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
176 ; BULK-MEM-NEXT: i32.const $push[[L5:[0-9]+]]=, 100
177 ; BULK-MEM-NEXT: memory.copy 0, 0, $pop[[L4]], $0, $pop[[L5]]
178 ; BULK-MEM-NEXT: return
179 define void @memcpy_alloca_dst(ptr %src) {
180 %a = alloca [100 x i8]
181 call void @llvm.memcpy.p0.p0.i32(ptr %a, ptr %src, i32 100, i1 false)
185 ; CHECK-LABEL: memset_alloca:
186 ; NO-BULK-MEM-NOT: memory.fill
187 ; BULK-MEM-NEXT: .functype memset_alloca (i32) -> ()
188 ; BULK-MEM-NEXT: global.get $push[[L0:[0-9]+]]=, __stack_pointer
189 ; BULK-MEM-NEXT: i32.const $push[[L1:[0-9]+]]=, 112
190 ; BULK-MEM-NEXT: i32.sub $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]
191 ; BULK-MEM-NEXT: i32.const $push[[L3:[0-9]+]]=, 12
192 ; BULK-MEM-NEXT: i32.add $push[[L4:[0-9]+]]=, $pop[[L2]], $pop[[L3]]
193 ; BULK-MEM-NEXT: i32.const $push[[L5:[0-9]+]]=, 100
194 ; BULK-MEM-NEXT: memory.fill 0, $pop[[L4]], $0, $pop[[L5]]
195 ; BULK-MEM-NEXT: return
196 define void @memset_alloca(i8 %val) {
197 %a = alloca [100 x i8]
198 call void @llvm.memset.p0.i32(ptr %a, i8 %val, i32 100, i1 false)