Skip to content

Conversation

AZero13
Copy link
Contributor

@AZero13 AZero13 commented Mar 13, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2024

@llvm/pr-subscribers-backend-arm

Author: AtariDreams (AtariDreams)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/85014.diff

1 Files Affected:

  • (modified) llvm/lib/Target/ARM/Thumb1FrameLowering.cpp (+20-8)
diff --git a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
index 0f4ece64bff532..2c4019f2acfa44 100644
--- a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
+++ b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -1049,16 +1049,28 @@ static void popRegsFromStack(MachineBasicBlock &MBB,
         continue;
 
       if (Reg == ARM::LR) {
-        if (!MBB.succ_empty() ||
-            MI->getOpcode() == ARM::TCRETURNdi ||
-            MI->getOpcode() == ARM::TCRETURNri)
-          // LR may only be popped into PC, as part of return sequence.
-          // If this isn't the return sequence, we'll need emitPopSpecialFixUp
-          // to restore LR the hard way.
-          // FIXME: if we don't pass any stack arguments it would be actually
+        if (!MBB.succ_empty() || MI->getOpcode() == ARM::TCRETURNdi ||
+            MI->getOpcode() == ARM::TCRETURNri) {
+          
+          // If we don't pass any stack arguments it would be actually
           // advantageous *and* correct to do the conversion to an ordinary call
           // instruction here.
-          continue;
+
+          // Get the MachineFrameInfo.
+          const MachineFrameInfo &MFI = MF.getFrameInfo();
+
+          // Check if there are any stack arguments.
+          bool hasStackArgs = MFI.hasStackObjects();
+
+          // If we have stack args, then LR may only be popped into PC,
+          // as part of the return sequence.
+          //
+          // If this isn't the return sequence, and we have the stack to deal
+          // with, we'll need emitPopSpecialFixUp to restore LR the hard way.
+          if (hasStackArgs)
+            continue;
+        }
+
         // Special epilogue for vararg functions. See emitEpilogue
         if (IsVarArg)
           continue;

Copy link

github-actions bot commented Mar 13, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@AZero13 AZero13 marked this pull request as draft May 16, 2024 00:17
@AZero13 AZero13 closed this Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants