llvm.org GIT mirror llvm / 469555a
[GlobalISel] Translate memset/memmove/memcpy from undef ptrs into nops If the source is undef, then just don't do anything. This matches SelectionDAG's behaviour in SelectionDAG.cpp. Also add a test showing that we do the right thing here. (irtranslator-memfunc-undef.ll) Differential Revision: https://reviews.llvm.org/D63095 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362989 91177308-0d34-0410-b5e6-96231b3b80d8 Jessica Paquette 4 months ago
2 changed file(s) with 54 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
727727 bool IRTranslator::translateMemfunc(const CallInst &CI,
728728 MachineIRBuilder &MIRBuilder,
729729 unsigned ID) {
730
731 // If the source is undef, then just emit a nop.
732 if (isa(CI.getArgOperand(1))) {
733 switch (ID) {
734 case Intrinsic::memmove:
735 case Intrinsic::memcpy:
736 case Intrinsic::memset:
737 return true;
738 default:
739 break;
740 }
741 }
742
730743 LLT SizeTy = getLLTForType(*CI.getArgOperand(2)->getType(), *DL);
731744 Type *DstTy = CI.getArgOperand(0)->getType();
732745 if (cast(DstTy)->getAddressSpace() != 0 ||
0 ; RUN: llc -mtriple=aarch64-unknown-unknown -global-isel -verify-machineinstrs -stop-after=irtranslator %s -o - | FileCheck %s
1
2 define void @memset() {
3 ; CHECK-LABEL: name: memset
4 ; CHECK: bb.1.entry:
5 ; CHECK-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.buf
6 ; CHECK-NEXT: RET_ReallyLR
7 entry:
8 %buf = alloca [512 x i8], align 1
9 %ptr = getelementptr inbounds [512 x i8], [512 x i8]* %buf, i32 0, i32 0
10 call void @llvm.memset.p0i8.i32(i8* %ptr, i8 undef, i32 512, i1 false)
11 ret void
12 }
13
14 define void @memcpy() {
15 ; CHECK-LABEL: name: memcpy
16 ; CHECK: bb.1.entry:
17 ; CHECK-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.buf
18 ; CHECK-NEXT: RET_ReallyLR
19 entry:
20 %buf = alloca [512 x i8], align 1
21 %ptr = getelementptr inbounds [512 x i8], [512 x i8]* %buf, i32 0, i32 0
22 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* undef, i32 512, i1 false)
23 ret void
24 }
25
26 define void @memmove() {
27 ; CHECK-LABEL: name: memmove
28 ; CHECK: bb.1.entry:
29 ; CHECK-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.buf
30 ; CHECK-NEXT: RET_ReallyLR
31 entry:
32 %buf = alloca [512 x i8], align 1
33 %ptr = getelementptr inbounds [512 x i8], [512 x i8]* %buf, i32 0, i32 0
34 call void @llvm.memmove.p0i8.p0i8.i32(i8* %ptr, i8* undef, i32 512, i1 false)
35 ret void
36 }
37
38 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
39 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) nounwind
40 declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind