@@ -18562,6 +18562,7 @@ static EVT calculatePreExtendType(SDValue Extend) {
18562
18562
switch (Extend.getOpcode()) {
18563
18563
case ISD::SIGN_EXTEND:
18564
18564
case ISD::ZERO_EXTEND:
18565
+ case ISD::ANY_EXTEND:
18565
18566
return Extend.getOperand(0).getValueType();
18566
18567
case ISD::AssertSext:
18567
18568
case ISD::AssertZext:
@@ -18606,14 +18607,15 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
18606
18607
// extend, and make sure it looks valid.
18607
18608
SDValue Extend = BV->getOperand(0);
18608
18609
unsigned ExtendOpcode = Extend.getOpcode();
18610
+ bool IsAnyExt = ExtendOpcode == ISD::ANY_EXTEND;
18609
18611
bool IsSExt = ExtendOpcode == ISD::SIGN_EXTEND ||
18610
18612
ExtendOpcode == ISD::SIGN_EXTEND_INREG ||
18611
18613
ExtendOpcode == ISD::AssertSext;
18612
- if (!IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
18614
+ if (!IsAnyExt && ! IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
18613
18615
ExtendOpcode != ISD::AssertZext && ExtendOpcode != ISD::AND)
18614
18616
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.
18617
18619
if (BV.getOpcode() == ISD::VECTOR_SHUFFLE &&
18618
18620
ExtendOpcode != ISD::SIGN_EXTEND && ExtendOpcode != ISD::ZERO_EXTEND)
18619
18621
return SDValue();
@@ -18624,15 +18626,27 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
18624
18626
PreExtendType.getScalarSizeInBits() != VT.getScalarSizeInBits() / 2)
18625
18627
return SDValue();
18626
18628
18627
- // Make sure all other operands are equally extended
18629
+ // Make sure all other operands are equally extended.
18630
+ bool SeenZExtOrSExt = !IsAnyExt;
18628
18631
for (SDValue Op : drop_begin(BV->ops())) {
18629
18632
if (Op.isUndef())
18630
18633
continue;
18634
+
18635
+ if (calculatePreExtendType(Op) != PreExtendType)
18636
+ return SDValue();
18637
+
18631
18638
unsigned Opc = Op.getOpcode();
18639
+ if (Opc == ISD::ANY_EXTEND)
18640
+ continue;
18641
+
18632
18642
bool OpcIsSExt = Opc == ISD::SIGN_EXTEND || Opc == ISD::SIGN_EXTEND_INREG ||
18633
18643
Opc == ISD::AssertSext;
18634
- if (OpcIsSExt != IsSExt || calculatePreExtendType(Op) != PreExtendType)
18644
+
18645
+ if (SeenZExtOrSExt && OpcIsSExt != IsSExt)
18635
18646
return SDValue();
18647
+
18648
+ IsSExt = OpcIsSExt;
18649
+ SeenZExtOrSExt = true;
18636
18650
}
18637
18651
18638
18652
SDValue NBV;
@@ -18655,7 +18669,10 @@ static SDValue performBuildShuffleExtendCombine(SDValue BV, SelectionDAG &DAG) {
18655
18669
: BV.getOperand(1).getOperand(0),
18656
18670
cast<ShuffleVectorSDNode>(BV)->getMask());
18657
18671
}
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);
18659
18676
}
18660
18677
18661
18678
/// Combines a mul(dup(sext/zext)) node pattern into mul(sext/zext(dup))
0 commit comments