1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -tail-dup-placement=0 | FileCheck %s
3 ; Test memcpy, memmove, and memset intrinsics.
5 target triple = "wasm32-unknown-unknown"
7 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)
8 declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)
9 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1)
11 ; Test that return values are optimized.
13 ; CHECK-LABEL: copy_yes:
14 ; CHECK: call $push0=, memcpy, $0, $1, $2{{$}}
15 ; CHECK-NEXT: return $pop0{{$}}
16 define i8* @copy_yes(i8* %dst, i8* %src, i32 %len) {
17 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %len, i1 false)
21 ; CHECK-LABEL: copy_no:
22 ; CHECK: call $drop=, memcpy, $0, $1, $2{{$}}
23 ; CHECK-NEXT: return{{$}}
24 define void @copy_no(i8* %dst, i8* %src, i32 %len) {
25 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %len, i1 false)
29 ; CHECK-LABEL: move_yes:
30 ; CHECK: call $push0=, memmove, $0, $1, $2{{$}}
31 ; CHECK-NEXT: return $pop0{{$}}
32 define i8* @move_yes(i8* %dst, i8* %src, i32 %len) {
33 call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %len, i1 false)
37 ; CHECK-LABEL: move_no:
38 ; CHECK: call $drop=, memmove, $0, $1, $2{{$}}
39 ; CHECK-NEXT: return{{$}}
40 define void @move_no(i8* %dst, i8* %src, i32 %len) {
41 call void @llvm.memmove.p0i8.p0i8.i32(i8* %dst, i8* %src, i32 %len, i1 false)
45 ; CHECK-LABEL: set_yes:
46 ; CHECK: call $push0=, memset, $0, $1, $2{{$}}
47 ; CHECK-NEXT: return $pop0{{$}}
48 define i8* @set_yes(i8* %dst, i8 %src, i32 %len) {
49 call void @llvm.memset.p0i8.i32(i8* %dst, i8 %src, i32 %len, i1 false)
53 ; CHECK-LABEL: set_no:
54 ; CHECK: call $drop=, memset, $0, $1, $2{{$}}
55 ; CHECK-NEXT: return{{$}}
56 define void @set_no(i8* %dst, i8 %src, i32 %len) {
57 call void @llvm.memset.p0i8.i32(i8* %dst, i8 %src, i32 %len, i1 false)
62 ; CHECK-LABEL: frame_index:
63 ; CHECK: call $drop=, memset, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
64 ; CHECK: call $push{{[0-9]+}}=, memset, ${{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}}
66 define void @frame_index() {
68 %a = alloca [2048 x i8], align 16
69 %b = alloca [2048 x i8], align 16
70 %0 = getelementptr inbounds [2048 x i8], [2048 x i8]* %a, i32 0, i32 0
71 %1 = getelementptr inbounds [2048 x i8], [2048 x i8]* %b, i32 0, i32 0
72 call void @llvm.memset.p0i8.i32(i8* align 16 %0, i8 256, i32 1024, i1 false)
73 call void @llvm.memset.p0i8.i32(i8* align 16 %1, i8 256, i32 1024, i1 false)
77 ; If the result value of memset doesn't get stackified, it should be marked
78 ; $drop. Note that we use a call to prevent tail dup so that we can test
79 ; this specific functionality.
81 ; CHECK-LABEL: drop_result:
82 ; CHECK: call $drop=, memset, $0, $1, $2
84 declare void @block_tail_dup()
85 define i8* @drop_result(i8* %arg, i8 %arg1, i32 %arg2, i32 %arg3, i32 %arg4) {
87 %tmp = icmp eq i32 %arg3, 0
88 br i1 %tmp, label %bb5, label %bb9
91 %tmp6 = icmp eq i32 %arg4, 0
92 br i1 %tmp6, label %bb7, label %bb8
95 call void @llvm.memset.p0i8.i32(i8* %arg, i8 %arg1, i32 %arg2, i1 false)
102 %tmp10 = call i8* @def()
106 %tmp12 = phi i8* [ %arg, %bb7 ], [ %arg, %bb8 ], [ %tmp10, %bb9 ]
107 call void @block_tail_dup()
111 ; This is the same as drop_result, except we let tail dup happen, so the
112 ; result of the memset *is* stackified.
114 ; CHECK-LABEL: tail_dup_to_reuse_result:
115 ; CHECK: call $push{{[0-9]+}}=, memset, $0, $1, $2
116 define i8* @tail_dup_to_reuse_result(i8* %arg, i8 %arg1, i32 %arg2, i32 %arg3, i32 %arg4) {
118 %tmp = icmp eq i32 %arg3, 0
119 br i1 %tmp, label %bb5, label %bb9
122 %tmp6 = icmp eq i32 %arg4, 0
123 br i1 %tmp6, label %bb7, label %bb8
126 call void @llvm.memset.p0i8.i32(i8* %arg, i8 %arg1, i32 %arg2, i1 false)
133 %tmp10 = call i8* @def()
137 %tmp12 = phi i8* [ %arg, %bb7 ], [ %arg, %bb8 ], [ %tmp10, %bb9 ]