[llvm] r190130 - [SystemZ] Use XC for a memset of 0
Richard Sandiford
rsandifo at linux.vnet.ibm.com
Fri Sep 6 03:25:07 PDT 2013
Author: rsandifo
Date: Fri Sep 6 05:25:07 2013
New Revision: 190130
URL: http://llvm.org/viewvc/llvm-project?rev=190130&view=rev
Log:
[SystemZ] Use XC for a memset of 0
Modified:
llvm/trunk/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
llvm/trunk/test/CodeGen/SystemZ/memset-03.ll
Modified: llvm/trunk/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp?rev=190130&r1=190129&r2=190130&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp Fri Sep 6 05:25:07 2013
@@ -25,10 +25,14 @@ SystemZSelectionDAGInfo(const SystemZTar
SystemZSelectionDAGInfo::~SystemZSelectionDAGInfo() {
}
-// Use MVC to copy Size bytes from Src to Dest, deciding whether to use
-// a loop or straight-line code.
-static SDValue emitMVC(SelectionDAG &DAG, SDLoc DL, SDValue Chain,
- SDValue Dst, SDValue Src, uint64_t Size) {
+// Decide whether it is best to use a loop or straight-line code for
+// a block operation of Size bytes with source address Src and destination
+// address Dest. Sequence is the opcode to use for straight-line code
+// (such as MVC) and Loop is the opcode to use for loops (such as MVC_LOOP).
+// Return the chain for the completed operation.
+static SDValue emitMemMem(SelectionDAG &DAG, SDLoc DL, unsigned Sequence,
+ unsigned Loop, SDValue Chain, SDValue Dst,
+ SDValue Src, uint64_t Size) {
EVT PtrVT = Src.getValueType();
// The heuristic we use is to prefer loops for anything that would
// require 7 or more MVCs. With these kinds of sizes there isn't
@@ -42,10 +46,10 @@ static SDValue emitMVC(SelectionDAG &DAG
// The next value up, 6 * 256, can be implemented in the same
// number of straight-line MVCs as 6 * 256 - 1.
if (Size > 6 * 256)
- return DAG.getNode(SystemZISD::MVC_LOOP, DL, MVT::Other, Chain, Dst, Src,
+ return DAG.getNode(Loop, DL, MVT::Other, Chain, Dst, Src,
DAG.getConstant(Size, PtrVT),
DAG.getConstant(Size / 256, PtrVT));
- return DAG.getNode(SystemZISD::MVC, DL, MVT::Other, Chain, Dst, Src,
+ return DAG.getNode(Sequence, DL, MVT::Other, Chain, Dst, Src,
DAG.getConstant(Size, PtrVT));
}
@@ -59,7 +63,8 @@ EmitTargetCodeForMemcpy(SelectionDAG &DA
return SDValue();
if (ConstantSDNode *CSize = dyn_cast<ConstantSDNode>(Size))
- return emitMVC(DAG, DL, Chain, Dst, Src, CSize->getZExtValue());
+ return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
+ Chain, Dst, Src, CSize->getZExtValue());
return SDValue();
}
@@ -130,13 +135,21 @@ EmitTargetCodeForMemset(SelectionDAG &DA
}
}
assert(Bytes >= 2 && "Should have dealt with 0- and 1-byte cases already");
+
+ // Handle the special case of a memset of 0, which can use XC.
+ ConstantSDNode *CByte = dyn_cast<ConstantSDNode>(Byte);
+ if (CByte && CByte->getZExtValue() == 0)
+ return emitMemMem(DAG, DL, SystemZISD::XC, SystemZISD::XC_LOOP,
+ Chain, Dst, Dst, Bytes);
+
// Copy the byte to the first location and then use MVC to copy
// it to the rest.
Chain = DAG.getStore(Chain, DL, Byte, Dst, DstPtrInfo,
false, false, Align);
SDValue DstPlus1 = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
DAG.getConstant(1, PtrVT));
- return emitMVC(DAG, DL, Chain, DstPlus1, Dst, Bytes - 1);
+ return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
+ Chain, DstPlus1, Dst, Bytes - 1);
}
return SDValue();
}
Modified: llvm/trunk/test/CodeGen/SystemZ/memset-03.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/memset-03.ll?rev=190130&r1=190129&r2=190130&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/memset-03.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/memset-03.ll Fri Sep 6 05:25:07 2013
@@ -140,8 +140,7 @@ define void @f14(i8 *%dest) {
; 7 bytes, i32 version.
define void @f15(i8 *%dest) {
; CHECK-LABEL: f15:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(6,%r2), 0(%r2)
+; CHECK: xc 0(7,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 7, i32 1, i1 false)
ret void
@@ -150,8 +149,7 @@ define void @f15(i8 *%dest) {
; 7 bytes, i64 version.
define void @f16(i8 *%dest) {
; CHECK-LABEL: f16:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(6,%r2), 0(%r2)
+; CHECK: xc 0(7,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 7, i32 1, i1 false)
ret void
@@ -218,8 +216,7 @@ define void @f22(i8 *%dest) {
; 11 bytes, i32 version.
define void @f23(i8 *%dest) {
; CHECK-LABEL: f23:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(10,%r2), 0(%r2)
+; CHECK: xc 0(11,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 11, i32 1, i1 false)
ret void
@@ -228,8 +225,7 @@ define void @f23(i8 *%dest) {
; 11 bytes, i64 version.
define void @f24(i8 *%dest) {
; CHECK-LABEL: f24:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(10,%r2), 0(%r2)
+; CHECK: xc 0(11,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 11, i32 1, i1 false)
ret void
@@ -258,8 +254,7 @@ define void @f26(i8 *%dest) {
; 13 bytes, i32 version.
define void @f27(i8 *%dest) {
; CHECK-LABEL: f27:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(12,%r2), 0(%r2)
+; CHECK: xc 0(13,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 13, i32 1, i1 false)
ret void
@@ -268,8 +263,7 @@ define void @f27(i8 *%dest) {
; 13 bytes, i64 version.
define void @f28(i8 *%dest) {
; CHECK-LABEL: f28:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(12,%r2), 0(%r2)
+; CHECK: xc 0(13,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 13, i32 1, i1 false)
ret void
@@ -278,8 +272,7 @@ define void @f28(i8 *%dest) {
; 14 bytes, i32 version.
define void @f29(i8 *%dest) {
; CHECK-LABEL: f29:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(13,%r2), 0(%r2)
+; CHECK: xc 0(14,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 14, i32 1, i1 false)
ret void
@@ -288,8 +281,7 @@ define void @f29(i8 *%dest) {
; 14 bytes, i64 version.
define void @f30(i8 *%dest) {
; CHECK-LABEL: f30:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(13,%r2), 0(%r2)
+; CHECK: xc 0(14,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 14, i32 1, i1 false)
ret void
@@ -298,8 +290,7 @@ define void @f30(i8 *%dest) {
; 15 bytes, i32 version.
define void @f31(i8 *%dest) {
; CHECK-LABEL: f31:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(14,%r2), 0(%r2)
+; CHECK: xc 0(15,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 15, i32 1, i1 false)
ret void
@@ -308,8 +299,7 @@ define void @f31(i8 *%dest) {
; 15 bytes, i64 version.
define void @f32(i8 *%dest) {
; CHECK-LABEL: f32:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(14,%r2), 0(%r2)
+; CHECK: xc 0(15,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 15, i32 1, i1 false)
ret void
@@ -338,8 +328,7 @@ define void @f34(i8 *%dest) {
; 17 bytes, i32 version.
define void @f35(i8 *%dest) {
; CHECK-LABEL: f35:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(16,%r2), 0(%r2)
+; CHECK: xc 0(17,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 17, i32 1, i1 false)
ret void
@@ -348,51 +337,46 @@ define void @f35(i8 *%dest) {
; 17 bytes, i64 version.
define void @f36(i8 *%dest) {
; CHECK-LABEL: f36:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(16,%r2), 0(%r2)
+; CHECK: xc 0(17,%r2), 0(%r2)
; CHECK: br %r14
call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 17, i32 1, i1 false)
ret void
}
-; 257 bytes, i32 version.
+; 256 bytes, i32 version.
define void @f37(i8 *%dest) {
; CHECK-LABEL: f37:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(256,%r2), 0(%r2)
+; CHECK: xc 0(256,%r2), 0(%r2)
; CHECK: br %r14
- call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 257, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 256, i32 1, i1 false)
ret void
}
-; 257 bytes, i64 version.
+; 256 bytes, i64 version.
define void @f38(i8 *%dest) {
; CHECK-LABEL: f38:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(256,%r2), 0(%r2)
+; CHECK: xc 0(256,%r2), 0(%r2)
; CHECK: br %r14
- call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 257, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 256, i32 1, i1 false)
ret void
}
-; 258 bytes, i32 version. We need two MVCs.
+; 257 bytes, i32 version. We need two MVCs.
define void @f39(i8 *%dest) {
; CHECK-LABEL: f39:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(256,%r2), 0(%r2)
-; CHECK: mvc 257(1,%r2), 256(%r2)
+; CHECK: xc 0(256,%r2), 0(%r2)
+; CHECK: xc 256(1,%r2), 256(%r2)
; CHECK: br %r14
- call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 258, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i32(i8 *%dest, i8 0, i32 257, i32 1, i1 false)
ret void
}
-; 258 bytes, i64 version.
+; 257 bytes, i64 version.
define void @f40(i8 *%dest) {
; CHECK-LABEL: f40:
-; CHECK: mvi 0(%r2), 0
-; CHECK: mvc 1(256,%r2), 0(%r2)
-; CHECK: mvc 257(1,%r2), 256(%r2)
+; CHECK: xc 0(256,%r2), 0(%r2)
+; CHECK: xc 256(1,%r2), 256(%r2)
; CHECK: br %r14
- call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 258, i32 1, i1 false)
+ call void @llvm.memset.p0i8.i64(i8 *%dest, i8 0, i64 257, i32 1, i1 false)
ret void
}
More information about the llvm-commits
mailing list