Skip to content

Commit ad2b609

Browse files
committed
[AArch64] Handle ANY_EXTEND in BuildShuffleExtendCombine
Handle ANY_EXTEND when combining a buildvector/shuffle of extended operands, as we can safely ignore ANY_EXTENDS when checking if all signs of the other extends are matching.
1 parent 0bc96c0 commit ad2b609

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

llvm/test/CodeGen/AArch64/aarch64-dup-ext.ll

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,8 @@ entry:
161161
define <2 x i32> @dupzext_v2i32_v2i64_trunc(i32 %src, <2 x i32> %b) {
162162
; CHECK-SD-LABEL: dupzext_v2i32_v2i64_trunc:
163163
; CHECK-SD: // %bb.0: // %entry
164-
; CHECK-SD-NEXT: ushll v0.2d, v0.2s, #0
165-
; CHECK-SD-NEXT: fmov x9, d0
166-
; CHECK-SD-NEXT: mov x8, v0.d[1]
167-
; CHECK-SD-NEXT: mul w9, w0, w9
168-
; CHECK-SD-NEXT: mul w8, w0, w8
169-
; CHECK-SD-NEXT: fmov d0, x9
170-
; CHECK-SD-NEXT: mov v0.d[1], x8
164+
; CHECK-SD-NEXT: dup v1.2s, w0
165+
; CHECK-SD-NEXT: smull v0.2d, v1.2s, v0.2s
171166
; CHECK-SD-NEXT: xtn v0.2s, v0.2d
172167
; CHECK-SD-NEXT: ret
173168
;

0 commit comments

Comments
 (0)