diff options
| author | Craig Topper <craig.topper@intel.com> | 2018-01-09 18:14:22 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2018-01-09 18:14:22 +0000 |
| commit | c4d2dd80b6d6bd446bfdbba0e084f1769aef59b6 (patch) | |
| tree | 74adcf75ee5f72431cbad3221b705f73ed726118 /llvm/lib/Target/X86/X86ISelLowering.cpp | |
| parent | 243f20f1171e6730aa5b57ad28b10b50244dc2c9 (diff) | |
| download | bcm5719-llvm-c4d2dd80b6d6bd446bfdbba0e084f1769aef59b6.tar.gz bcm5719-llvm-c4d2dd80b6d6bd446bfdbba0e084f1769aef59b6.zip | |
[X86] Add a DAG combine to combine (sext (setcc)) with VLX
Normally target independent DAG combine would do this combine based on getSetCCResultType, but with VLX getSetCCResultType returns a vXi1 type preventing the DAG combining from kicking in.
But doing this combine can allow us to remove the explicit sign extend that would otherwise be emitted.
This patch adds a target specific DAG combine to combine the sext+setcc when the result type is the same size as the input to the setcc. I've restricted this to FP compares and things that can be represented with PCMPEQ and PCMPGT since we don't have full integer compare support on the older ISAs.
Differential Revision: https://reviews.llvm.org/D41850
llvm-svn: 322101
Diffstat (limited to 'llvm/lib/Target/X86/X86ISelLowering.cpp')
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index ae5eb552b73..eb09a4386dd 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -35996,6 +35996,45 @@ static SDValue combineToExtendVectorInReg(SDNode *N, SelectionDAG &DAG, return SDValue(); } +// Attempt to combine a (sext/zext (setcc)) to a setcc with a xmm/ymm/zmm +// result type. +static SDValue combineExtSetcc(SDNode *N, SelectionDAG &DAG, + const X86Subtarget &Subtarget) { + SDValue N0 = N->getOperand(0); + EVT VT = N->getValueType(0); + SDLoc dl(N); + + // Only do this combine with AVX512 for vector extends. + if (!Subtarget.hasAVX512() || !VT.isVector() || N0->getOpcode() != ISD::SETCC) + return SDValue(); + + // Only combine legal element types. + EVT SVT = VT.getVectorElementType(); + if (SVT != MVT::i8 && SVT != MVT::i16 && SVT != MVT::i32 && + SVT != MVT::i64 && SVT != MVT::f32 && SVT != MVT::f64) + return SDValue(); + + // We can only do this if the vector size in 256 bits or less. + unsigned Size = VT.getSizeInBits(); + if (Size > 256) + return SDValue(); + + // Don't fold if the condition code can't be handled by PCMPEQ/PCMPGT since + // that's the only integer compares with we have. + ISD::CondCode CC = cast<CondCodeSDNode>(N0->getOperand(2))->get(); + if (ISD::isUnsignedIntSetCC(CC) || CC == ISD::SETLE || CC == ISD::SETGE || + CC == ISD::SETNE) + return SDValue(); + + // Only do this combine if the extension will be fully consumed by the setcc. + EVT N00VT = N0.getOperand(0).getValueType(); + EVT MatchingVecType = N00VT.changeVectorElementTypeToInteger(); + if (Size != MatchingVecType.getSizeInBits()) + return SDValue(); + + return DAG.getSetCC(dl, VT, N0.getOperand(0), N0.getOperand(1), CC); +} + static SDValue combineSext(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const X86Subtarget &Subtarget) { @@ -36013,6 +36052,9 @@ static SDValue combineSext(SDNode *N, SelectionDAG &DAG, if (!DCI.isBeforeLegalizeOps()) return SDValue(); + if (SDValue V = combineExtSetcc(N, DAG, Subtarget)) + return V; + if (InVT == MVT::i1 && N0.getOpcode() == ISD::XOR && isAllOnesConstant(N0.getOperand(1)) && N0.hasOneUse()) { // Invert and sign-extend a boolean is the same as zero-extend and subtract |

