@@ -18562,6 +18562,7 @@ static EVT calculatePreExtendType(SDValue Extend) {
1856218562 switch (Extend.getOpcode()) {
1856318563 case ISD::SIGN_EXTEND:
1856418564 case ISD::ZERO_EXTEND:
18565+ case ISD::ANY_EXTEND:
1856518566 return Extend.getOperand(0).getValueType();
1856618567 case ISD::AssertSext:
1856718568 case ISD::AssertZext:
@@ -18606,14 +18607,15 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1860618607 // extend, and make sure it looks valid.
1860718608 SDValue Extend = BV->getOperand(0);
1860818609 unsigned ExtendOpcode = Extend.getOpcode();
18610+ bool IsAnyExt = ExtendOpcode == ISD::ANY_EXTEND;
1860918611 bool IsSExt = ExtendOpcode == ISD::SIGN_EXTEND ||
1861018612 ExtendOpcode == ISD::SIGN_EXTEND_INREG ||
1861118613 ExtendOpcode == ISD::AssertSext;
18612- if (!IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
18614+ if (!IsAnyExt && ! IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
1861318615 ExtendOpcode != ISD::AssertZext && ExtendOpcode != ISD::AND)
1861418616 return SDValue();
18615- // Shuffle inputs are vector, limit to SIGN_EXTEND and ZERO_EXTEND to ensure
18616- // calculatePreExtendType will work without issue.
18617+ // Shuffle inputs are vector, limit to SIGN_EXTEND/ ZERO_EXTEND/ANY_EXTEND to
18618+ // ensure calculatePreExtendType will work without issue.
1861718619 if (BV.getOpcode() == ISD::VECTOR_SHUFFLE &&
1861818620 ExtendOpcode != ISD::SIGN_EXTEND && ExtendOpcode != ISD::ZERO_EXTEND)
1861918621 return SDValue();
@@ -18624,15 +18626,27 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1862418626 PreExtendType.getScalarSizeInBits() != VT.getScalarSizeInBits() / 2)
1862518627 return SDValue();
1862618628
18627- // Make sure all other operands are equally extended
18629+ // Make sure all other operands are equally extended.
18630+ bool SeenZExtOrSExt = !IsAnyExt;
1862818631 for (SDValue Op : drop_begin(BV->ops())) {
1862918632 if (Op.isUndef())
1863018633 continue;
18634+
18635+ if (calculatePreExtendType(Op) != PreExtendType)
18636+ return SDValue();
18637+
1863118638 unsigned Opc = Op.getOpcode();
18639+ if (Opc == ISD::ANY_EXTEND)
18640+ continue;
18641+
1863218642 bool OpcIsSExt = Opc == ISD::SIGN_EXTEND || Opc == ISD::SIGN_EXTEND_INREG ||
1863318643 Opc == ISD::AssertSext;
18634- if (OpcIsSExt != IsSExt || calculatePreExtendType(Op) != PreExtendType)
18644+
18645+ if (SeenZExtOrSExt && OpcIsSExt != IsSExt)
1863518646 return SDValue();
18647+
18648+ IsSExt = OpcIsSExt;
18649+ SeenZExtOrSExt = true;
1863618650 }
1863718651
1863818652 SDValue NBV;
@@ -18655,7 +18669,10 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
1865518669 : BV.getOperand(1).getOperand(0),
1865618670 cast<ShuffleVectorSDNode>(BV)->getMask());
1865718671 }
18658- return DAG.getNode(IsSExt ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, DL, VT, NBV);
18672+ unsigned ExtOpc = !SeenZExtOrSExt ? ISD::ANY_EXTEND
18673+ : IsSExt ? ISD::SIGN_EXTEND
18674+ : ISD::ZERO_EXTEND;
18675+ return DAG.getNode(ExtOpc, DL, VT, NBV);
1865918676}
1866018677
1866118678/// Combines a mul(dup(sext/zext)) node pattern into mul(sext/zext(dup))
0 commit comments