@@ -1814,24 +1814,18 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
1814
1814
StackOffset::getFixed ((int64_t )MFI.getStackSize () - NumBytes));
1815
1815
}
1816
1816
if (NeedsRealignment) {
1817
- const unsigned NrBitsToZero = Log2 (MFI.getMaxAlign ());
1818
- assert (NrBitsToZero > 1 );
1817
+ assert (MFI.getMaxAlign () > Align (1 ));
1819
1818
assert (scratchSPReg != AArch64::SP);
1820
1819
1821
1820
// SUB X9, SP, NumBytes
1822
1821
// -- X9 is temporary register, so shouldn't contain any live data here,
1823
1822
// -- free to use. This is already produced by emitFrameOffset above.
1824
1823
// 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 );
1831
1825
1832
1826
BuildMI (MBB, MBBI, DL, TII->get (AArch64::ANDXri), AArch64::SP)
1833
1827
.addReg (scratchSPReg, RegState::Kill)
1834
- .addImm (andMaskEncoded );
1828
+ .addImm (AArch64_AM::encodeLogicalImmediate (AndMask, 64 ) );
1835
1829
AFI->setStackRealigned (true );
1836
1830
1837
1831
// No need for SEH instructions here; if we're realigning the stack,
0 commit comments