Skip to content

Commit fd3e4f4

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 d7adec9 commit fd3e4f4

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

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

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ target triple = "aarch64-unknown-linux-gnu"
1010
define dso_local i32 @dupext_crashtest(i32 %e) local_unnamed_addr {
1111
; CHECK-LABEL: dupext_crashtest:
1212
; CHECK: // %bb.0: // %for.body.lr.ph
13+
; CHECK-NEXT: dup v0.2s, w0
1314
; CHECK-NEXT: .LBB0_1: // %vector.body
1415
; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
15-
; CHECK-NEXT: ldr d0, [x8]
16-
; CHECK-NEXT: ushll v0.2d, v0.2s, #0
17-
; CHECK-NEXT: fmov x9, d0
18-
; CHECK-NEXT: mov x8, v0.d[1]
19-
; CHECK-NEXT: mul w9, w0, w9
20-
; CHECK-NEXT: mul w8, w0, w8
21-
; CHECK-NEXT: fmov d0, x9
22-
; CHECK-NEXT: mov v0.d[1], x8
23-
; CHECK-NEXT: xtn v0.2s, v0.2d
24-
; CHECK-NEXT: str d0, [x8]
16+
; CHECK-NEXT: ldr d1, [x8]
17+
; CHECK-NEXT: smull v1.2d, v0.2s, v1.2s
18+
; CHECK-NEXT: xtn v1.2s, v1.2d
19+
; CHECK-NEXT: str d1, [x8]
2520
; CHECK-NEXT: b .LBB0_1
2621
for.body.lr.ph:
2722
%conv314 = zext i32 %e to i64

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)