Skip to content

Commit 24303e3

Browse files
committed
[AArch64] Use encodeLogicalImmediate for forming the immediate to an AND. NFC.
Differential Revision: https://reviews.llvm.org/D135817
1 parent 19e2b40 commit 24303e3

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,24 +1814,18 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
18141814
StackOffset::getFixed((int64_t)MFI.getStackSize() - NumBytes));
18151815
}
18161816
if (NeedsRealignment) {
1817-
const unsigned NrBitsToZero = Log2(MFI.getMaxAlign());
1818-
assert(NrBitsToZero > 1);
1817+
assert(MFI.getMaxAlign() > Align(1));
18191818
assert(scratchSPReg != AArch64::SP);
18201819

18211820
// SUB X9, SP, NumBytes
18221821
// -- X9 is temporary register, so shouldn't contain any live data here,
18231822
// -- free to use. This is already produced by emitFrameOffset above.
18241823
// AND SP, X9, 0b11111...0000
1825-
// The logical immediates have a non-trivial encoding. The following
1826-
// formula computes the encoded immediate with all ones but
1827-
// NrBitsToZero zero bits as least significant bits.
1828-
uint32_t andMaskEncoded = (1 << 12) // = N
1829-
| ((64 - NrBitsToZero) << 6) // immr
1830-
| ((64 - NrBitsToZero - 1) << 0); // imms
1824+
uint64_t AndMask = ~(MFI.getMaxAlign().value() - 1);
18311825

18321826
BuildMI(MBB, MBBI, DL, TII->get(AArch64::ANDXri), AArch64::SP)
18331827
.addReg(scratchSPReg, RegState::Kill)
1834-
.addImm(andMaskEncoded);
1828+
.addImm(AArch64_AM::encodeLogicalImmediate(AndMask, 64));
18351829
AFI->setStackRealigned(true);
18361830

18371831
// No need for SEH instructions here; if we're realigning the stack,

0 commit comments

Comments
 (0)