[llvm] [TailCallElim] Do not mark a call tail when it is handed the frame (PR #218797)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 01:15:36 PDT 2026


================
@@ -181,6 +181,14 @@ struct AllocaDerivedValueTracker {
       case Instruction::Call:
       case Instruction::Invoke: {
         auto &CB = cast<CallBase>(*I);
+        // llvm.stackrestore only assigns its argument to the stack pointer. It
+        // neither captures the value nor hands it to anything that could, so it
+        // is not an escape even though it writes memory and its argument is not
+        // marked nocapture. Without this every call after a VLA scope or a
+        // __builtin_stack_save would lose its tail marking.
+        if (auto *II = dyn_cast<IntrinsicInst>(I);
+            II && II->getIntrinsicID() == Intrinsic::stackrestore)
+          continue;
----------------
antoniofrighetto wrote:

This hardcoded check makes me wonder if we should mark stackrestore intrinsic argument as nocapture instead (and let this be handled by the current logic below, maybe cc/ @efriedma-quic).

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


More information about the llvm-commits mailing list