Skip to content

Commit 9d127ef

Browse files
committed
[AArch64] Stop reserved registers from being saved in prolog/epilog
GCC's man page is clear on how -ffixed-reg must behave: ``` Treat the register named reg as a fixed register; generated code should never refer to it (except perhaps as a stack pointer, frame pointer or in some other fixed role). ``` This implies prolog/epilog code also must not save/restore explicitly fixed registers, even when it is callee-saved. Some projects rely on this (GCC's) behavior. For example, ``` void f() { register uint64_t x28 asm("x28") = 0xee; asm volatile("" : "+r"(x28)); // avoid mov being eliminated } ``` should not touch x28 outside of `mov w28,#0xee`. For riscv64 clang behaves the same as GCC. Fixes #111379.
1 parent 4e81ee4 commit 9d127ef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,14 @@ void AArch64FrameLowering::determineCalleeSaves(MachineFunction &MF,
36193619
if (Reg == BasePointerReg)
36203620
SavedRegs.set(Reg);
36213621

3622+
// Don't save fixed registers specified with -ffixed-reg.
3623+
if (!produceCompactUnwindFrame(MF) &&
3624+
AArch64::GPR64RegClass.contains(Reg) &&
3625+
RegInfo->isReservedReg(MF, Reg)) {
3626+
SavedRegs.reset(Reg);
3627+
continue;
3628+
}
3629+
36223630
bool RegUsed = SavedRegs.test(Reg);
36233631
unsigned PairedReg = AArch64::NoRegister;
36243632
const bool RegIsGPR64 = AArch64::GPR64RegClass.contains(Reg);

0 commit comments

Comments
 (0)