@@ -18501,6 +18501,7 @@ static EVT calculatePreExtendType(SDValue Extend) {
1850118501 switch (Extend.getOpcode()) {
1850218502 case ISD::SIGN_EXTEND:
1850318503 case ISD::ZERO_EXTEND:
18504+ case ISD::ANY_EXTEND:
1850418505 return Extend.getOperand(0).getValueType();
1850518506 case ISD::AssertSext:
1850618507 case ISD::AssertZext:
@@ -18545,14 +18546,15 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1854518546 // extend, and make sure it looks valid.
1854618547 SDValue Extend = BV->getOperand(0);
1854718548 unsigned ExtendOpcode = Extend.getOpcode();
18549+ bool IsAnyExt = ExtendOpcode == ISD::ANY_EXTEND;
1854818550 bool IsSExt = ExtendOpcode == ISD::SIGN_EXTEND ||
1854918551 ExtendOpcode == ISD::SIGN_EXTEND_INREG ||
1855018552 ExtendOpcode == ISD::AssertSext;
18551- if (!IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
18553+ if (!IsAnyExt && ! IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
1855218554 ExtendOpcode != ISD::AssertZext && ExtendOpcode != ISD::AND)
1855318555 return SDValue();
18554- // Shuffle inputs are vector, limit to SIGN_EXTEND and ZERO_EXTEND to ensure
18555- // calculatePreExtendType will work without issue.
18556+ // Shuffle inputs are vector, limit to SIGN_EXTEND/ ZERO_EXTEND/ANY_EXTEND to
18557+ // ensure calculatePreExtendType will work without issue.
1855618558 if (BV.getOpcode() == ISD::VECTOR_SHUFFLE &&
1855718559 ExtendOpcode != ISD::SIGN_EXTEND && ExtendOpcode != ISD::ZERO_EXTEND)
1855818560 return SDValue();
@@ -18563,15 +18565,27 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1856318565 PreExtendType.getScalarSizeInBits() != VT.getScalarSizeInBits() / 2)
1856418566 return SDValue();
1856518567
18566- // Make sure all other operands are equally extended
18568+ // Make sure all other operands are equally extended.
18569+ bool SeenZExtOrSExt = !IsAnyExt;
1856718570 for (SDValue Op : drop_begin(BV->ops())) {
1856818571 if (Op.isUndef())
1856918572 continue;
18573+
18574+ if (calculatePreExtendType(Op) != PreExtendType)
18575+ return SDValue();
18576+
1857018577 unsigned Opc = Op.getOpcode();
18578+ if (Opc == ISD::ANY_EXTEND)
18579+ continue;
18580+
1857118581 bool OpcIsSExt = Opc == ISD::SIGN_EXTEND || Opc == ISD::SIGN_EXTEND_INREG ||
1857218582 Opc == ISD::AssertSext;
18573- if (OpcIsSExt != IsSExt || calculatePreExtendType(Op) != PreExtendType)
18583+
18584+ if (SeenZExtOrSExt && OpcIsSExt != IsSExt)
1857418585 return SDValue();
18586+
18587+ IsSExt = OpcIsSExt;
18588+ SeenZExtOrSExt = true;
1857518589 }
1857618590
1857718591 SDValue NBV;
@@ -18594,7 +18608,10 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1859418608 : BV.getOperand(1).getOperand(0),
1859518609 cast<ShuffleVectorSDNode>(BV)->getMask());
1859618610 }
18597- return DAG.getNode(IsSExt ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, DL, VT, NBV);
18611+ unsigned ExtOpc = !SeenZExtOrSExt ? ISD::ANY_EXTEND
18612+ : IsSExt ? ISD::SIGN_EXTEND
18613+ : ISD::ZERO_EXTEND;
18614+ return DAG.getNode(ExtOpc, DL, VT, NBV);
1859818615}
1859918616
1860018617/// Combines a mul(dup(sext/zext)) node pattern into mul(sext/zext(dup))
0 commit comments