diff options
author | Jonas Paulsson <paulsson@linux.vnet.ibm.com> | 2018-10-25 21:47:22 +0000 |
---|---|---|
committer | Jonas Paulsson <paulsson@linux.vnet.ibm.com> | 2018-10-25 21:47:22 +0000 |
commit | 4645711a8d54eb34d0040dde1748376d0992068b (patch) | |
tree | 86e3a0cb26d46634422198e718d9dc2cdddd3e65 /llvm/lib/Target/SystemZ/SystemZISelLowering.cpp | |
parent | 2f9c42c99453b9f33d5f4311075c357134e84120 (diff) | |
download | bcm5719-llvm-4645711a8d54eb34d0040dde1748376d0992068b.tar.gz bcm5719-llvm-4645711a8d54eb34d0040dde1748376d0992068b.zip |
[SystemZ] Improve handling and cost estimates of vector integer div/rem
Enable the DAG optimization that converts vector div/rem with constants into
multiply+shifts sequences by expanding them early. This is needed since
ISD::SMUL_LOHI is 'Custom' lowered on SystemZ, and will therefore not be
available to BuildSDIV after legalization.
Better cost values for these instructions based on how they will be
implemented (a constant divisor is cheaper).
Review: Ulrich Weigand
https://reviews.llvm.org/D53196
llvm-svn: 345321
Diffstat (limited to 'llvm/lib/Target/SystemZ/SystemZISelLowering.cpp')
-rw-r--r-- | llvm/lib/Target/SystemZ/SystemZISelLowering.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp index 53cd21c4236..d86737e2192 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -527,6 +527,10 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM, setTargetDAGCombine(ISD::EXTRACT_VECTOR_ELT); setTargetDAGCombine(ISD::FP_ROUND); setTargetDAGCombine(ISD::BSWAP); + setTargetDAGCombine(ISD::SDIV); + setTargetDAGCombine(ISD::UDIV); + setTargetDAGCombine(ISD::SREM); + setTargetDAGCombine(ISD::UREM); // Handle intrinsics. setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom); @@ -5664,6 +5668,23 @@ SDValue SystemZTargetLowering::combineGET_CCMASK( return Select->getOperand(4); } +SDValue SystemZTargetLowering::combineIntDIVREM( + SDNode *N, DAGCombinerInfo &DCI) const { + SelectionDAG &DAG = DCI.DAG; + EVT VT = N->getValueType(0); + // In the case where the divisor is a vector of constants a cheaper + // sequence of instructions can replace the divide. BuildSDIV is called to + // do this during DAG combining, but it only succeeds when it can build a + // multiplication node. The only option for SystemZ is ISD::SMUL_LOHI, and + // since it is not Legal but Custom it can only happen before + // legalization. Therefore we must scalarize this early before Combine + // 1. For widened vectors, this is already the result of type legalization. + if (VT.isVector() && isTypeLegal(VT) && + DAG.isConstantIntBuildVectorOrConstantInt(N->getOperand(1))) + return DAG.UnrollVectorOp(N); + return SDValue(); +} + SDValue SystemZTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const { switch(N->getOpcode()) { @@ -5681,6 +5702,10 @@ SDValue SystemZTargetLowering::PerformDAGCombine(SDNode *N, case SystemZISD::BR_CCMASK: return combineBR_CCMASK(N, DCI); case SystemZISD::SELECT_CCMASK: return combineSELECT_CCMASK(N, DCI); case SystemZISD::GET_CCMASK: return combineGET_CCMASK(N, DCI); + case ISD::SDIV: + case ISD::UDIV: + case ISD::SREM: + case ISD::UREM: return combineIntDIVREM(N, DCI); } return SDValue(); |