Skip to content

Commit

Permalink
[WebAssembly] Lower memmove to memory.copy
Browse files Browse the repository at this point in the history
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

llvm-svn: 353216
  • Loading branch information
tlively committed Feb 5, 2019
1 parent a53eb79 commit 3150566
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Expand Up @@ -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;
}
}

Expand Down
11 changes: 10 additions & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp
Expand Up @@ -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<WebAssemblySubtarget>()
Expand All @@ -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);
}
5 changes: 5 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
Expand Up @@ -28,6 +28,11 @@ class WebAssemblySelectionDAGInfo final : public SelectionDAGTargetInfo {
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
Expand Down
47 changes: 47 additions & 0 deletions llvm/test/CodeGen/WebAssembly/bulk-memory.ll
Expand Up @@ -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) -> ()
Expand All @@ -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)
Expand All @@ -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) -> ()
Expand All @@ -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
}

0 comments on commit 3150566

Please sign in to comment.