From: Thomas Lively Date: Tue, 5 Feb 2019 20:57:40 +0000 (+0000) Subject: [WebAssembly] Lower memmove to memory.copy X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a517c5b25e3aa98cb8e7ce2ad0c710f4afe31ca;p=llvm [WebAssembly] Lower memmove to memory.copy Summary: The lowering is identical to the memcpy lowering. Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57727 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353216 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index b17c7fae043..ca13161afb5 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -248,6 +248,8 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering( // Using memory.copy is always better than using multiple loads and stores MaxStoresPerMemcpy = 1; MaxStoresPerMemcpyOptSize = 1; + MaxStoresPerMemmove = 1; + MaxStoresPerMemmoveOptSize = 1; } } diff --git a/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp b/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp index a23128f05a3..04be3d7d21e 100644 --- a/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp +++ b/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp @@ -20,7 +20,7 @@ WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy( SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2, - SDValue Op3, unsigned Align, bool isVolatile, bool AlwaysInline, + SDValue Op3, unsigned Align, bool IsVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { if (!DAG.getMachineFunction() .getSubtarget() @@ -30,3 +30,12 @@ SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy( return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other, Chain, Op1, Op2, Op3); } + +SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove( + SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2, + SDValue Op3, unsigned Align, bool IsVolatile, + MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { + return EmitTargetCodeForMemcpy(DAG, DL, Chain, Op1, Op2, Op3, Align, + IsVolatile, false, DstPtrInfo, + SrcPtrInfo); +} diff --git a/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h b/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h index 349a7c94621..29e23e96aeb 100644 --- a/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h +++ b/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h @@ -28,6 +28,11 @@ public: bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const override; + SDValue EmitTargetCodeForMemmove(SelectionDAG &DAG, const SDLoc &dl, + SDValue Chain, SDValue Op1, SDValue Op2, + SDValue Op3, unsigned Align, bool isVolatile, + MachinePointerInfo DstPtrInfo, + MachinePointerInfo SrcPtrInfo) const override; }; } // end namespace llvm diff --git a/test/CodeGen/WebAssembly/bulk-memory.ll b/test/CodeGen/WebAssembly/bulk-memory.ll index 9c3a61dfc44..acece86b7b1 100644 --- a/test/CodeGen/WebAssembly/bulk-memory.ll +++ b/test/CodeGen/WebAssembly/bulk-memory.ll @@ -19,6 +19,19 @@ define void @memcpy_i8(i8* %dest, i8* %src, i32 %len) { ret void } +; CHECK-LABEL: memmove_i8: +; NO-BULK-MEM-NOT: memory.copy +; BULK-MEM-NEXT: .functype memmove_i8 (i32, i32, i32) -> () +; BULK-MEM-NEXT: memory.copy $0, $1, $2 +; BULK-MEM-NEXT: return +declare void @llvm.memmove.p0i8.p0i8.i32( + i8* %dest, i8* %src, i32 %len, i1 %volatile +) +define void @memmove_i8(i8* %dest, i8* %src, i32 %len) { + call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 0) + ret void +} + ; CHECK-LABEL: memcpy_i32: ; NO-BULK-MEM-NOT: memory.copy ; BULK-MEM-NEXT: .functype memcpy_i32 (i32, i32, i32) -> () @@ -32,6 +45,19 @@ define void @memcpy_i32(i32* %dest, i32* %src, i32 %len) { ret void } +; CHECK-LABEL: memmove_i32: +; NO-BULK-MEM-NOT: memory.copy +; BULK-MEM-NEXT: .functype memmove_i32 (i32, i32, i32) -> () +; BULK-MEM-NEXT: memory.copy $0, $1, $2 +; BULK-MEM-NEXT: return +declare void @llvm.memmove.p0i32.p0i32.i32( + i32* %dest, i32* %src, i32 %len, i1 %volatile +) +define void @memmove_i32(i32* %dest, i32* %src, i32 %len) { + call void @llvm.memmove.p0i32.p0i32.i32(i32* %dest, i32* %src, i32 %len, i1 0) + ret void +} + ; CHECK-LABEL: memcpy_1: ; CHECK-NEXT: .functype memcpy_1 (i32, i32) -> () ; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1) @@ -42,6 +68,16 @@ define void @memcpy_1(i8* %dest, i8* %src) { ret void } +; CHECK-LABEL: memmove_1: +; CHECK-NEXT: .functype memmove_1 (i32, i32) -> () +; CHECK-NEXT: i32.load8_u $push[[L0:[0-9]+]]=, 0($1) +; CHECK-NEXT: i32.store8 0($0), $pop[[L0]] +; CHECK-NEXT: return +define void @memmove_1(i8* %dest, i8* %src) { + call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1, i1 0) + ret void +} + ; CHECK-LABEL: memcpy_1024: ; NO-BULK-MEM-NOT: memory.copy ; BULK-MEM-NEXT: .functype memcpy_1024 (i32, i32) -> () @@ -52,3 +88,14 @@ define void @memcpy_1024(i8* %dest, i8* %src) { call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0) ret void } + +; CHECK-LABEL: memmove_1024: +; NO-BULK-MEM-NOT: memory.copy +; BULK-MEM-NEXT: .functype memmove_1024 (i32, i32) -> () +; BULK-MEM-NEXT: i32.const $push[[L0:[0-9]+]]=, 1024 +; BULK-MEM-NEXT: memory.copy $0, $1, $pop[[L0]] +; BULK-MEM-NEXT: return +define void @memmove_1024(i8* %dest, i8* %src) { + call void @llvm.memmove.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 1024, i1 0) + ret void +}