[llvm] r353216 - [WebAssembly] Lower memmove to memory.copy

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 12:57:41 PST 2019


Author: tlively
Date: Tue Feb  5 12:57:40 2019
New Revision: 353216

URL: http://llvm.org/viewvc/llvm-project?rev=353216&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
    llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=353216&r1=353215&r2=353216&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Tue Feb  5 12:57:40 2019
@@ -248,6 +248,8 @@ WebAssemblyTargetLowering::WebAssemblyTa
     // Using memory.copy is always better than using multiple loads and stores
     MaxStoresPerMemcpy = 1;
     MaxStoresPerMemcpyOptSize = 1;
+    MaxStoresPerMemmove = 1;
+    MaxStoresPerMemmoveOptSize = 1;
   }
 }
 

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp?rev=353216&r1=353215&r2=353216&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp Tue Feb  5 12:57:40 2019
@@ -20,7 +20,7 @@ WebAssemblySelectionDAGInfo::~WebAssembl
 
 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<WebAssemblySubtarget>()
@@ -30,3 +30,12 @@ SDValue WebAssemblySelectionDAGInfo::Emi
   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);
+}

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h?rev=353216&r1=353215&r2=353216&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h Tue Feb  5 12:57:40 2019
@@ -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

Modified: llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll?rev=353216&r1=353215&r2=353216&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/bulk-memory.ll Tue Feb  5 12:57:40 2019
@@ -19,6 +19,19 @@ define void @memcpy_i8(i8* %dest, i8* %s
   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*
   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* %sr
   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*
   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
+}




More information about the llvm-commits mailing list