diff options
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 52f19cc6e1ab..1e470318ced0 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -11413,13 +11413,9 @@ SDValue TargetLowering::expandVecReduce(SDNode *Node, SelectionDAG &DAG) const { SDValue Op = Node->getOperand(0); EVT VT = Op.getValueType(); - if (VT.isScalableVector()) - report_fatal_error( - "Expanding reductions for scalable vectors is undefined."); - // Try to use a shuffle reduction for power of two vectors. if (VT.isPow2VectorType()) { - while (VT.getVectorNumElements() > 1) { + while (VT.getVectorElementCount().isKnownMultipleOf(2)) { EVT HalfVT = VT.getHalfNumVectorElementsVT(*DAG.getContext()); if (!isOperationLegalOrCustom(BaseOpcode, HalfVT)) break; @@ -11428,9 +11424,18 @@ SDValue TargetLowering::expandVecReduce(SDNode *Node, SelectionDAG &DAG) const { std::tie(Lo, Hi) = DAG.SplitVector(Op, dl); Op = DAG.getNode(BaseOpcode, dl, HalfVT, Lo, Hi, Node->getFlags()); VT = HalfVT; + + // Stop if splitting is enough to make the reduction legal. + if (isOperationLegalOrCustom(Node->getOpcode(), HalfVT)) + return DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Op, + Node->getFlags()); } } + if (VT.isScalableVector()) + reportFatalInternalError( + "Expanding reductions for scalable vectors is undefined."); + EVT EltVT = VT.getVectorElementType(); unsigned NumElts = VT.getVectorNumElements(); |
