Skip to content

Commit 2a0017d

Browse files
committed
[AArch64] Recognize legal add immediates for addvl
1 parent ae1af94 commit 2a0017d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16595,6 +16595,21 @@ bool AArch64TargetLowering::isLegalAddImmediate(int64_t Immed) const {
1659516595
return IsLegal;
1659616596
}
1659716597

16598+
bool AArch64TargetLowering::isLegalAddScalableImmediate(int64_t Imm) const {
16599+
// Scalable immediates require SVE support.
16600+
if (!Subtarget->hasSVE())
16601+
return false;
16602+
16603+
// addvl's immediates are in terms of the number of bytes in a register.
16604+
// Since there are 16 in the base supported size (128bits), we need to
16605+
// divide the immediate by that much to give us a useful immediate to
16606+
// multiply by vscale. We can't have a remainder as a result of this.
16607+
if (Imm % 16 != 0)
16608+
return false;
16609+
16610+
return isInt<6>(Imm / 16);
16611+
}
16612+
1659816613
// Return false to prevent folding
1659916614
// (mul (add x, c1), c2) -> (add (mul x, c2), c2*c1) in DAGCombine,
1660016615
// if the folding leads to worse code.

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ class AArch64TargetLowering : public TargetLowering {
689689
StoreInst *SI) const override;
690690

691691
bool isLegalAddImmediate(int64_t) const override;
692+
bool isLegalAddScalableImmediate(int64_t) const override;
692693
bool isLegalICmpImmediate(int64_t) const override;
693694

694695
bool isMulAddWithConstProfitable(SDValue AddNode,

llvm/unittests/Target/AArch64/Immediates.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ struct TestCase {
2020
const std::initializer_list<TestCase> Tests = {
2121
// ScalableImm, Result
2222
// No change, easily 'supported'
23-
{0, false},
23+
{0, true},
2424

2525
// addvl increments by whole registers, range [-32,31]
2626
// +(16 * vscale), one register's worth
27-
{16, false},
27+
{16, true},
2828
// +(8 * vscale), half a register's worth
2929
{8, false},
3030
// -(32 * 16 * vscale)
31-
{-512, false},
31+
{-512, true},
3232
// -(33 * 16 * vscale)
3333
{-528, false},
3434
// +(31 * 16 * vscale)
35-
{496, false},
35+
{496, true},
3636
// +(32 * 16 * vscale)
3737
{512, false},
3838
};

0 commit comments

Comments
 (0)