[llvm-branch-commits] [llvm] [4/4]: [MCP] Never eliminate frame-setup/destroy instructions (PR #186237)
Scott Linder via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 12 13:50:01 PDT 2026
https://github.com/slinder1 updated https://github.com/llvm/llvm-project/pull/186237
>From 816b52f45f207e227a2f6db5993c00e4279fb30a Mon Sep 17 00:00:00 2001
From: Scott Linder <Scott.Linder at amd.com>
Date: Thu, 12 Mar 2026 18:08:00 +0000
Subject: [PATCH] [MCP] Never eliminate frame-setup/destroy instructions
Presumably targets only insert frame instructions which are significant,
and there may be effects MCP doesn't model. Similar to reserved registers this
is probably overly conservative, but as this causes no codegen change in
any lit test I think it is benign.
The motivation is just to clean up #183149 for AMDGPU, as we can spill
to physical registers, and currently have to spill the EXEC mask purely
to enable debug-info.
Change-Id: I9ea4a09b34464c43322edd2900361bf635efd9f7
---
llvm/lib/CodeGen/MachineCopyPropagation.cpp | 5 ++++-
llvm/test/CodeGen/X86/machine-copy-prop.mir | 22 +++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index d2d6b1f8d2b33..b1a6a6b6be16b 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -503,7 +503,10 @@ class MachineCopyPropagation {
// zero).
return MRI->isReserved(CopyOperand);
}
- bool isNeverRedundant(const MachineInstr &Copy) { return false; }
+ bool isNeverRedundant(const MachineInstr &Copy) {
+ return Copy.getFlag(MachineInstr::FrameSetup) ||
+ Copy.getFlag(MachineInstr::FrameDestroy);
+ }
bool isNeverRedundant(const MachineInstr &Copy,
const DefSrcPair &CopyOperands) {
auto [Def, Src] = CopyOperands.getDefSrcMCRegs();
diff --git a/llvm/test/CodeGen/X86/machine-copy-prop.mir b/llvm/test/CodeGen/X86/machine-copy-prop.mir
index f4fed03a75e67..e04d638ef092a 100644
--- a/llvm/test/CodeGen/X86/machine-copy-prop.mir
+++ b/llvm/test/CodeGen/X86/machine-copy-prop.mir
@@ -16,6 +16,8 @@
define void @nocopyprop3() { ret void }
define void @nocopyprop4() { ret void }
define void @nocopyprop5() { ret void }
+ define void @nocopyprop_frame_setup() { ret void }
+ define void @nocopyprop_frame_destroy() { ret void }
...
---
# The second copy is redundant and will be removed, check that we also remove
@@ -253,3 +255,23 @@ body: |
$rip = COPY $rax
$rip = COPY $rax
...
+---
+# Conservatively assume prologue/epilogue instructions may have
+# additional effects.
+# CHECK-LABEL: name: nocopyprop_frame_setup
+# CHECK: bb.0:
+# CHECK-NEXT: $rbx = frame-setup COPY $rax
+name: nocopyprop_frame_setup
+body: |
+ bb.0:
+ $rbx = frame-setup COPY $rax
+...
+---
+# CHECK-LABEL: name: nocopyprop_frame_destroy
+# CHECK: bb.0:
+# CHECK-NEXT: $rbx = frame-destroy COPY $rax
+name: nocopyprop_frame_destroy
+body: |
+ bb.0:
+ $rbx = frame-destroy COPY $rax
+...
More information about the llvm-branch-commits
mailing list