Skip to content

Commit 5125e75

Browse files
committed
[AArch64] Recognize legal add immediates for addvl
1 parent f5ee2b5 commit 5125e75

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16561,8 +16561,22 @@ LLT AArch64TargetLowering::getOptimalMemOpLLT(
1656116561
// 12-bit optionally shifted immediates are legal for adds.
1656216562
bool AArch64TargetLowering::isLegalAddImmediate(int64_t Immed,
1656316563
int64_t ScalableImm) const {
16564-
if (ScalableImm)
16565-
return false;
16564+
if (ScalableImm) {
16565+
// Scalable immediates require SVE support; mixed fixed + scalable
16566+
// immediates are not supported by the current instructions.
16567+
if (Immed || !Subtarget->hasSVE())
16568+
return false;
16569+
16570+
// addvl's immediates are in terms of the number of bytes in a register.
16571+
// Since there are 16 in the base supported size (128bits), we need to
16572+
// divide the immediate by that much to give us a useful immediate to
16573+
// multiply by vscale. We can't have a remainder as a result of this.
16574+
if (ScalableImm % 16 != 0)
16575+
return false;
16576+
int64_t Imm = ScalableImm / 16;
16577+
16578+
return Imm >= -32 && Imm <= 31;
16579+
}
1656616580

1656716581
if (Immed == std::numeric_limits<int64_t>::min()) {
1656816582
LLVM_DEBUG(dbgs() << "Illegal add imm " << Immed

llvm/unittests/Target/AArch64/Immediates.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const std::initializer_list<TestCase> Tests = {
3131

3232
// Scalable; addvl increments by whole registers, range [-32,31]
3333
// +(16 * vscale), one register's worth
34-
{0, 16, false},
34+
{0, 16, true},
3535
// +(8 * vscale), half a register's worth
3636
{0, 8, false},
3737
// -(32 * 16 * vscale)
38-
{0, -512, false},
38+
{0, -512, true},
3939
// -(33 * 16 * vscale)
4040
{0, -528, false},
4141
// +(31 * 16 * vscale)
42-
{0, 496, false},
42+
{0, 496, true},
4343
// +(32 * 16 * vscale)
4444
{0, 512, false},
4545

0 commit comments

Comments
 (0)