[llvm] [ARM] Check all terms in emitPopInst when clearing Restored for LR. (PR #75527)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 19 10:02:00 PST 2023


================
@@ -1645,9 +1645,21 @@ void ARMFrameLowering::emitPopInst(MachineBasicBlock &MBB,
         // Fold the return instruction into the LDM.
         DeleteRet = true;
         LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET;
-        // We 'restore' LR into PC so it is not live out of the return block:
-        // Clear Restored bit.
-        Info.setRestored(false);
+        // Check if all terminators do not implicitly use LR. Then we can
+        // 'restore' LR into PC so it is not live out of the return block: Clear
+        // Restored bit.
+        if (all_of(MF, [MI](const MachineBasicBlock &MBB) {
+              return all_of(MBB.terminators(), [MI](const MachineInstr &Term) {
+                //  MI's terminator is to be re-written, don't check the old
+                //  opcode.
+                if (&*MI == &Term)
+                  return true;
+                return Term.getOpcode() == ARM::LDMIA_RET ||
+                       Term.getOpcode() == ARM::t2LDMIA_RET ||
+                       Term.getOpcode() == ARM::tPOP_RET;
----------------
fhahn wrote:

Thanks, I added an `isReturn` check in the latest version and moved setting `IsRestored` to `processFunctionBeforeFrameFinalized`, which runs just after spilling the callee-saved registers

https://github.com/llvm/llvm-project/pull/75527


More information about the llvm-commits mailing list