197 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mcpu=mvp -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -tail-dup-placement=0 | FileCheck %s3 4; Test memcpy, memmove, and memset intrinsics.5 6target triple = "wasm32-unknown-unknown"7 8declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture readonly, i32, i1)9declare void @llvm.memmove.p0.p0.i32(ptr nocapture, ptr nocapture readonly, i32, i1)10declare void @llvm.memset.p0.i32(ptr nocapture, i8, i32, i1)11 12; Test that return values are optimized.13 14define ptr @copy_yes(ptr %dst, ptr %src, i32 %len) {15; CHECK-LABEL: copy_yes:16; CHECK: .functype copy_yes (i32, i32, i32) -> (i32)17; CHECK-NEXT: # %bb.0:18; CHECK-NEXT: call $push0=, memcpy, $0, $1, $219; CHECK-NEXT: return $pop020 call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %len, i1 false)21 ret ptr %dst22}23define void @copy_no(ptr %dst, ptr %src, i32 %len) {24; CHECK-LABEL: copy_no:25; CHECK: .functype copy_no (i32, i32, i32) -> ()26; CHECK-NEXT: # %bb.0:27; CHECK-NEXT: call $drop=, memcpy, $0, $1, $228; CHECK-NEXT: return29 call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %len, i1 false)30 ret void31}32 33define ptr @move_yes(ptr %dst, ptr %src, i32 %len) {34; CHECK-LABEL: move_yes:35; CHECK: .functype move_yes (i32, i32, i32) -> (i32)36; CHECK-NEXT: # %bb.0:37; CHECK-NEXT: call $push0=, memmove, $0, $1, $238; CHECK-NEXT: return $pop039 call void @llvm.memmove.p0.p0.i32(ptr %dst, ptr %src, i32 %len, i1 false)40 ret ptr %dst41}42 43define void @move_no(ptr %dst, ptr %src, i32 %len) {44; CHECK-LABEL: move_no:45; CHECK: .functype move_no (i32, i32, i32) -> ()46; CHECK-NEXT: # %bb.0:47; CHECK-NEXT: call $drop=, memmove, $0, $1, $248; CHECK-NEXT: return49 call void @llvm.memmove.p0.p0.i32(ptr %dst, ptr %src, i32 %len, i1 false)50 ret void51}52 53define ptr @set_yes(ptr %dst, i8 %src, i32 %len) {54; CHECK-LABEL: set_yes:55; CHECK: .functype set_yes (i32, i32, i32) -> (i32)56; CHECK-NEXT: # %bb.0:57; CHECK-NEXT: call $push0=, memset, $0, $1, $258; CHECK-NEXT: return $pop059 call void @llvm.memset.p0.i32(ptr %dst, i8 %src, i32 %len, i1 false)60 ret ptr %dst61}62 63define void @set_no(ptr %dst, i8 %src, i32 %len) {64; CHECK-LABEL: set_no:65; CHECK: .functype set_no (i32, i32, i32) -> ()66; CHECK-NEXT: # %bb.0:67; CHECK-NEXT: call $drop=, memset, $0, $1, $268; CHECK-NEXT: return69 call void @llvm.memset.p0.i32(ptr %dst, i8 %src, i32 %len, i1 false)70 ret void71}72 73define void @frame_index() {74; CHECK-LABEL: frame_index:75; CHECK: .functype frame_index () -> ()76; CHECK-NEXT: # %bb.0: # %entry77; CHECK-NEXT: global.get $push3=, __stack_pointer78; CHECK-NEXT: i32.const $push4=, 409679; CHECK-NEXT: i32.sub $push12=, $pop3, $pop480; CHECK-NEXT: local.tee $push11=, $0=, $pop1281; CHECK-NEXT: global.set __stack_pointer, $pop1182; CHECK-NEXT: i32.const $push7=, 204883; CHECK-NEXT: i32.add $push8=, $0, $pop784; CHECK-NEXT: i32.const $push1=, 085; CHECK-NEXT: i32.const $push0=, 102486; CHECK-NEXT: call $drop=, memset, $pop8, $pop1, $pop087; CHECK-NEXT: i32.const $push10=, 088; CHECK-NEXT: i32.const $push9=, 102489; CHECK-NEXT: call $push2=, memset, $0, $pop10, $pop990; CHECK-NEXT: i32.const $push5=, 409691; CHECK-NEXT: i32.add $push6=, $pop2, $pop592; CHECK-NEXT: global.set __stack_pointer, $pop693; CHECK-NEXT: return94entry:95 %a = alloca [2048 x i8], align 1696 %b = alloca [2048 x i8], align 1697 call void @llvm.memset.p0.i32(ptr align 16 %a, i8 256, i32 1024, i1 false)98 call void @llvm.memset.p0.i32(ptr align 16 %b, i8 256, i32 1024, i1 false)99 ret void100}101 102; If the result value of memset doesn't get stackified, it should be marked103; $drop. Note that we use a call to prevent tail dup so that we can test104; this specific functionality.105 106declare ptr @def()107declare void @block_tail_dup()108define ptr @drop_result(ptr %arg, i8 %arg1, i32 %arg2, i32 %arg3, i32 %arg4) {109; CHECK-LABEL: drop_result:110; CHECK: .functype drop_result (i32, i32, i32, i32, i32) -> (i32)111; CHECK-NEXT: # %bb.0: # %bb112; CHECK-NEXT: block113; CHECK-NEXT: block114; CHECK-NEXT: br_if 0, $3 # 0: down to label1115; CHECK-NEXT: # %bb.1: # %bb5116; CHECK-NEXT: br_if 1, $4 # 1: down to label0117; CHECK-NEXT: # %bb.2: # %bb7118; CHECK-NEXT: call $drop=, memset, $0, $1, $2119; CHECK-NEXT: call block_tail_dup120; CHECK-NEXT: return $0121; CHECK-NEXT: .LBB7_3: # %bb9122; CHECK-NEXT: end_block # label1:123; CHECK-NEXT: call $0=, def124; CHECK-NEXT: .LBB7_4: # %bb11125; CHECK-NEXT: end_block # label0:126; CHECK-NEXT: call block_tail_dup127; CHECK-NEXT: return $0128bb:129 %tmp = icmp eq i32 %arg3, 0130 br i1 %tmp, label %bb5, label %bb9131 132bb5:133 %tmp6 = icmp eq i32 %arg4, 0134 br i1 %tmp6, label %bb7, label %bb8135 136bb7:137 call void @llvm.memset.p0.i32(ptr %arg, i8 %arg1, i32 %arg2, i1 false)138 br label %bb11139 140bb8:141 br label %bb11142 143bb9:144 %tmp10 = call ptr @def()145 br label %bb11146 147bb11:148 %tmp12 = phi ptr [ %arg, %bb7 ], [ %arg, %bb8 ], [ %tmp10, %bb9 ]149 call void @block_tail_dup()150 ret ptr %tmp12151}152 153; This is the same as drop_result, except we let tail dup happen, so the154; result of the memset *is* stackified.155 156define ptr @tail_dup_to_reuse_result(ptr %arg, i8 %arg1, i32 %arg2, i32 %arg3, i32 %arg4) {157; CHECK-LABEL: tail_dup_to_reuse_result:158; CHECK: .functype tail_dup_to_reuse_result (i32, i32, i32, i32, i32) -> (i32)159; CHECK-NEXT: # %bb.0: # %bb160; CHECK-NEXT: block161; CHECK-NEXT: block162; CHECK-NEXT: br_if 0, $3 # 0: down to label3163; CHECK-NEXT: # %bb.1: # %bb5164; CHECK-NEXT: br_if 1, $4 # 1: down to label2165; CHECK-NEXT: # %bb.2: # %bb7166; CHECK-NEXT: call $push0=, memset, $0, $1, $2167; CHECK-NEXT: return $pop0168; CHECK-NEXT: .LBB8_3: # %bb9169; CHECK-NEXT: end_block # label3:170; CHECK-NEXT: call $0=, def171; CHECK-NEXT: .LBB8_4: # %bb11172; CHECK-NEXT: end_block # label2:173; CHECK-NEXT: return $0174bb:175 %tmp = icmp eq i32 %arg3, 0176 br i1 %tmp, label %bb5, label %bb9177 178bb5:179 %tmp6 = icmp eq i32 %arg4, 0180 br i1 %tmp6, label %bb7, label %bb8181 182bb7:183 call void @llvm.memset.p0.i32(ptr %arg, i8 %arg1, i32 %arg2, i1 false)184 br label %bb11185 186bb8:187 br label %bb11188 189bb9:190 %tmp10 = call ptr @def()191 br label %bb11192 193bb11:194 %tmp12 = phi ptr [ %arg, %bb7 ], [ %arg, %bb8 ], [ %tmp10, %bb9 ]195 ret ptr %tmp12196}197