[llvm] [CodeGen] Keep physreg copies when successors use-before-def (PR #182732)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 12:05:55 PST 2026


================
@@ -563,6 +563,26 @@ void MachineCopyPropagation::readSuccessorLiveIns(
   }
 }
 
+// Conservatively detect a physical-register use in a successor block before
+// the register is redefined there. This guards against stale/incomplete
+// live-in information, which can otherwise make a required copy look
+// dead at block exit
+static bool hasUseBeforeDefInSuccessor(const MachineBasicBlock &MBB,
+                                       MCRegister Reg,
+                                       const TargetRegisterInfo &TRI) {
+  for (const MachineBasicBlock *Succ : MBB.successors()) {
+    for (const MachineInstr &MI : *Succ) {
+      if (MI.isPHI())
----------------
arsenm wrote:

This pass only runs post-SSA 

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


More information about the llvm-commits mailing list