From ab882abce85b65c300349a2bebd49ef57fc1f79e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 24 Mar 2006 07:48:08 +0000 Subject: [PATCH] add support for using vxor to build zero vectors. This implements Regression/CodeGen/PowerPC/vec_zero.ll llvm-svn: 27059 --- llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 36 +++++++++++++++++++-- llvm/lib/Target/PowerPC/PPCISelLowering.h | 4 +++ llvm/lib/Target/PowerPC/PPCInstrInfo.td | 8 ++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index d29ec20b2d25..f228cc22b01c 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -170,9 +170,6 @@ PPCTargetLowering::PPCTargetLowering(TargetMachine &TM) setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Expand); setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Expand); setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Expand); - - // FIXME: We don't support any BUILD_VECTOR's yet. We should custom expand - // the ones we do, like splat(0.0) and splat(-0.0). setOperationAction(ISD::BUILD_VECTOR, (MVT::ValueType)VT, Expand); } @@ -193,6 +190,9 @@ PPCTargetLowering::PPCTargetLowering(TargetMachine &TM) setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom); setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i32, Custom); + + setOperationAction(ISD::BUILD_VECTOR, MVT::v4i32, Custom); + setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); } setSetCCResultContents(ZeroOrOneSetCCResult); @@ -276,6 +276,26 @@ unsigned PPC::getVSPLTImmediate(SDNode *N) { return cast(N->getOperand(0))->getValue(); } +/// isZeroVector - Return true if this build_vector is an all-zero vector. +/// +bool PPC::isZeroVector(SDNode *N) { + if (MVT::isInteger(N->getOperand(0).getValueType())) { + for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) + if (!isa(N->getOperand(i)) || + cast(N->getOperand(i))->getValue() != 0) + return false; + } else { + assert(MVT::isFloatingPoint(N->getOperand(0).getValueType()) && + "Vector of non-int, non-float values?"); + // See if this is all zeros. + for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) + if (!isa(N->getOperand(i)) || + !cast(N->getOperand(i))->isExactlyValue(0.0)) + return false; + } + return true; +} + /// LowerOperation - Provide custom lowering hooks for some operations. /// @@ -634,6 +654,16 @@ SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { return DAG.getNode(PPCISD::LVE_X, Op.getValueType(), Store, FIdx, DAG.getSrcValue(NULL)); } + case ISD::BUILD_VECTOR: + // If this is a case we can't handle, return null and let the default + // expansion code take care of it. If we CAN select this case, return Op. + + // See if this is all zeros. + // FIXME: We should handle splat(-0.0), and other cases here. + if (PPC::isZeroVector(Op.Val)) + return Op; + return SDOperand(); + case ISD::VECTOR_SHUFFLE: { SDOperand V1 = Op.getOperand(0); SDOperand V2 = Op.getOperand(1); diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.h b/llvm/lib/Target/PowerPC/PPCISelLowering.h index abf7a79db8f3..5482e9aa5c0d 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.h +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.h @@ -101,6 +101,10 @@ namespace llvm { /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the /// specified isSplatShuffleMask VECTOR_SHUFFLE mask. unsigned getVSPLTImmediate(SDNode *N); + + /// isZeroVector - Return true if this build_vector is an all-zero vector. + /// + bool isZeroVector(SDNode *N); } class PPCTargetLowering : public TargetLowering { diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td index b1772376f52b..ff2dc315ac18 100644 --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td @@ -135,6 +135,11 @@ def VSPLT_shuffle_mask : PatLeaf<(build_vector), [{ return PPC::isSplatShuffleMask(N); }], VSPLT_get_imm>; +def vecimm0 : PatLeaf<(build_vector), [{ + return PPC::isZeroVector(N); +}]>; + + //===----------------------------------------------------------------------===// // PowerPC Flag Definitions. @@ -1061,7 +1066,7 @@ def VSPLTW : VXForm_1<652, (ops VRRC:$vD, u5imm:$UIMM, VRRC:$vB), def V_SET0 : VXForm_setzero<1220, (ops VRRC:$vD), "vxor $vD, $vD, $vD", VecFP, - []>; + [(set VRRC:$vD, (v4f32 vecimm0))]>; } @@ -1209,6 +1214,7 @@ def : Pat<(v4i32 (PPClve_x xoaddr:$src)), (v4i32 (LVEWX xoaddr:$src))>; def : Pat<(v4i32 (undef)), (v4i32 (IMPLICIT_DEF_VRRC))>; +def : Pat<(v4i32 vecimm0), (v4i32 (V_SET0))>; // bit_convert def : Pat<(v4i32 (bitconvert (v4f32 VRRC:$src))), (v4i32 VRRC:$src)>;