diff options
| author | Elena Demikhovsky <elena.demikhovsky@intel.com> | 2013-01-17 09:59:53 +0000 |
|---|---|---|
| committer | Elena Demikhovsky <elena.demikhovsky@intel.com> | 2013-01-17 09:59:53 +0000 |
| commit | f6a30e05d58ec251a08e56f71d57feb747882ba3 (patch) | |
| tree | 744782299dbcca8cd714c23812d4ce85d9796bc2 /llvm/lib | |
| parent | b61b815fc83bca62e498a9951189a607a0d41f34 (diff) | |
| download | bcm5719-llvm-f6a30e05d58ec251a08e56f71d57feb747882ba3.tar.gz bcm5719-llvm-f6a30e05d58ec251a08e56f71d57feb747882ba3.zip | |
Optimization for the following SIGN_EXTEND pairs:
v8i8 -> v8i64,
v8i8 -> v8i32,
v4i8 -> v4i64,
v4i16 -> v4i64
for AVX and AVX2.
Bug 14865.
llvm-svn: 172708
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 18 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 27 |
3 files changed, 39 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index a82410ae6a0..3e5a446e6e5 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -4298,11 +4298,19 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) { if (isa<ConstantSDNode>(N0)) return DAG.getNode(ISD::SIGN_EXTEND, N->getDebugLoc(), VT, N0); - // fold (sext (sext x)) -> (sext x) - // fold (sext (aext x)) -> (sext x) - if (N0.getOpcode() == ISD::SIGN_EXTEND || N0.getOpcode() == ISD::ANY_EXTEND) - return DAG.getNode(ISD::SIGN_EXTEND, N->getDebugLoc(), VT, - N0.getOperand(0)); + // Folding (sext (sext x)) is obvious, but we do it only after the type + // legalization phase. When the sequence is like {(T1->T2), (T2->T3)} and + // T1 or T3 (or the both) are illegal types, the TypeLegalizer may not + // give a good sequence for the (T1->T3) pair. + // So we give a chance to target specific combiner to optimize T1->T2 and T2->T3 + // separately and may be fold them in a preceding of subsequent instruction. + if (Level >= AfterLegalizeTypes) { + // fold (sext (sext x)) -> (sext x) + // fold (sext (aext x)) -> (sext x) + if (N0.getOpcode() == ISD::SIGN_EXTEND || N0.getOpcode() == ISD::ANY_EXTEND) + return DAG.getNode(ISD::SIGN_EXTEND, N->getDebugLoc(), VT, + N0.getOperand(0)); + } if (N0.getOpcode() == ISD::TRUNCATE) { // fold (sext (truncate (load x))) -> (sext (smaller load x)) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 344d1447a8d..91491bfe802 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2554,9 +2554,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, DebugLoc DL, VT.getVectorNumElements() == Operand.getValueType().getVectorNumElements()) && "Vector element count mismatch!"); - if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND) - return getNode(OpOpcode, DL, VT, Operand.getNode()->getOperand(0)); - else if (OpOpcode == ISD::UNDEF) + if (OpOpcode == ISD::UNDEF) // sext(undef) = 0, because the top bits will all be the same. return getConstant(0, VT); break; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index f42884dd2e8..a8294b6de98 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -16970,14 +16970,37 @@ static SDValue PerformVZEXT_MOVLCombine(SDNode *N, SelectionDAG &DAG) { static SDValue PerformSExtCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const X86Subtarget *Subtarget) { + EVT VT = N->getValueType(0); + + if (!VT.isVector()) + return SDValue(); + + SDValue In = N->getOperand(0); + EVT InVT = In.getValueType(); + DebugLoc dl = N->getDebugLoc(); + unsigned ExtenedEltSize = VT.getVectorElementType().getSizeInBits(); + + // Split SIGN_EXTEND operation to use vmovsx instruction when possible + if (InVT == MVT::v8i8) { + if (ExtenedEltSize > 16 && !Subtarget->hasInt256()) + In = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, In); + if (ExtenedEltSize > 32) + In = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i32, In); + return DAG.getNode(ISD::SIGN_EXTEND, dl, VT, In); + } + + if ((InVT == MVT::v4i8 || InVT == MVT::v4i16) && + ExtenedEltSize > 32 && !Subtarget->hasInt256()) { + In = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, In); + return DAG.getNode(ISD::SIGN_EXTEND, dl, VT, In); + } if (!DCI.isBeforeLegalizeOps()) return SDValue(); if (!Subtarget->hasFp256()) return SDValue(); - EVT VT = N->getValueType(0); - if (VT.isVector() && VT.getSizeInBits() == 256) { + if (VT.is256BitVector()) { SDValue R = WidenMaskArithmetic(N, DAG, DCI, Subtarget); if (R.getNode()) return R; |

