[llvm] [ARM] Do not use r7 as a temporary in THUMB if it is a stack pointer (NFC) (PR #86156)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 10:13:07 PDT 2024


https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/86156

Many programs and debuggers do in fact poll the value of r7 to keep track of frame pointers and see which functions have been called.

If there is a way to ensure this is not happening, then maybe we can get the compiler to use r7. However, I do not even know if the TargetRegisterInfo class already takes care of that or not.

It is best to remove this code in the interim. Plus, because r7 is marked as reserved anyway, it will always be marked as unallocatable, and hence this code has no effect anyway, hence why it is marked as NFC, even though technically the only reason why this code has no effect is a bug. It is a bug that has prevented this code from causing problems.

>From 7a6d1cb6e8a6f323db4e02d8241baa91cb9dcb0b Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 21 Mar 2024 13:12:35 -0400
Subject: [PATCH] [ARM] Do not use r7 as a temporary in THUMB if it is a stack
 pointer (NFC)

Many programs and debuggers do in fact poll the value of r7 to keep track of frame pointers and see which functions have been called.

If there is a way to ensure this is not happening, then maybe we can get the compiler to use r7. However, I do not even know if the TargetRegisterInfo class already takes care of that or not.

It is best to remove this code in the interim. Plus, because r7 is marked as reserved anyway, it will always be marked as unallocatable, and hence this code has no effect anyway, hence why it is marked as NFC, even though technically the only reason why this code has no effect is a bug. It is a bug that has prevented this code from causing problems.
---
 llvm/lib/Target/ARM/Thumb1FrameLowering.cpp | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
index 0f4ece64bff532..5d5968c9c849ea 100644
--- a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
+++ b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -710,11 +710,6 @@ bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
   unsigned TemporaryReg = 0;
   BitVector PopFriendly =
       TRI.getAllocatableSet(MF, TRI.getRegClass(ARM::tGPRRegClassID));
-  // R7 may be used as a frame pointer, hence marked as not generally
-  // allocatable, however there's no reason to not use it as a temporary for
-  // restoring LR.
-  if (STI.getFramePointerReg() == ARM::R7)
-    PopFriendly.set(ARM::R7);
 
   assert(PopFriendly.any() && "No allocatable pop-friendly register?!");
   // Rebuild the GPRs from the high registers because they are removed



More information about the llvm-commits mailing list