@@ -7311,8 +7311,6 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) {
7311
7311
// Generate a vp.reduce_op if it is custom/legal for the target. This avoids
7312
7312
// needing to pad the source vector, because the inactive lanes can simply be
7313
7313
// disabled and not contribute to the result.
7314
- // TODO: VECREDUCE_FADD, VECREDUCE_FMUL aren't currently mapped correctly,
7315
- // and thus don't take this path.
7316
7314
if (auto VPOpcode = ISD::getVPForBaseOpcode (Opc);
7317
7315
VPOpcode && TLI.isOperationLegalOrCustom (*VPOpcode, WideVT)) {
7318
7316
SDValue Start = NeutralElem;
@@ -7351,6 +7349,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE_SEQ(SDNode *N) {
7351
7349
SDValue VecOp = N->getOperand (1 );
7352
7350
SDValue Op = GetWidenedVector (VecOp);
7353
7351
7352
+ EVT VT = N->getValueType (0 );
7354
7353
EVT OrigVT = VecOp.getValueType ();
7355
7354
EVT WideVT = Op.getValueType ();
7356
7355
EVT ElemVT = OrigVT.getVectorElementType ();
@@ -7364,6 +7363,19 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE_SEQ(SDNode *N) {
7364
7363
unsigned OrigElts = OrigVT.getVectorMinNumElements ();
7365
7364
unsigned WideElts = WideVT.getVectorMinNumElements ();
7366
7365
7366
+ // Generate a vp.reduce_op if it is custom/legal for the target. This avoids
7367
+ // needing to pad the source vector, because the inactive lanes can simply be
7368
+ // disabled and not contribute to the result.
7369
+ if (auto VPOpcode = ISD::getVPForBaseOpcode (Opc);
7370
+ VPOpcode && TLI.isOperationLegalOrCustom (*VPOpcode, WideVT)) {
7371
+ EVT WideMaskVT = EVT::getVectorVT (*DAG.getContext (), MVT::i1,
7372
+ WideVT.getVectorElementCount ());
7373
+ SDValue Mask = DAG.getAllOnesConstant (dl, WideMaskVT);
7374
+ SDValue EVL = DAG.getElementCount (dl, TLI.getVPExplicitVectorLengthTy (),
7375
+ OrigVT.getVectorElementCount ());
7376
+ return DAG.getNode (*VPOpcode, dl, VT, {AccOp, Op, Mask, EVL}, Flags);
7377
+ }
7378
+
7367
7379
if (WideVT.isScalableVector ()) {
7368
7380
unsigned GCD = std::gcd (OrigElts, WideElts);
7369
7381
EVT SplatVT = EVT::getVectorVT (*DAG.getContext (), ElemVT,
@@ -7372,14 +7384,14 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE_SEQ(SDNode *N) {
7372
7384
for (unsigned Idx = OrigElts; Idx < WideElts; Idx = Idx + GCD)
7373
7385
Op = DAG.getNode (ISD::INSERT_SUBVECTOR, dl, WideVT, Op, SplatNeutral,
7374
7386
DAG.getVectorIdxConstant (Idx, dl));
7375
- return DAG.getNode (Opc, dl, N-> getValueType ( 0 ) , AccOp, Op, Flags);
7387
+ return DAG.getNode (Opc, dl, VT , AccOp, Op, Flags);
7376
7388
}
7377
7389
7378
7390
for (unsigned Idx = OrigElts; Idx < WideElts; Idx++)
7379
7391
Op = DAG.getNode (ISD::INSERT_VECTOR_ELT, dl, WideVT, Op, NeutralElem,
7380
7392
DAG.getVectorIdxConstant (Idx, dl));
7381
7393
7382
- return DAG.getNode (Opc, dl, N-> getValueType ( 0 ) , AccOp, Op, Flags);
7394
+ return DAG.getNode (Opc, dl, VT , AccOp, Op, Flags);
7383
7395
}
7384
7396
7385
7397
SDValue DAGTypeLegalizer::WidenVecOp_VP_REDUCE (SDNode *N) {
0 commit comments