[llvm] [RegAllocFast] Give an undef tied use the register of its tied def (PR #222249)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 01:18:08 PDT 2026


================
@@ -1031,6 +1031,28 @@ void RegAllocFastImpl::allocVirtRegUndef(MachineOperand &MO) {
   if (!shouldAllocateRegister(VirtReg))
     return;
 
+  // The def is freed before the uses are allocated, so a tie is the only
+  // record left of its register. Rewrite every read of VirtReg so they agree.
+  MachineInstr &MI = *MO.getParent();
+  for (const MachineOperand &Tied : MI.all_uses()) {
+    if (!Tied.isTied() || Tied.getReg() != VirtReg)
+      continue;
+    unsigned TiedIdx = MI.findTiedOperandIdx(MI.getOperandNo(&Tied));
+    MCRegister DefReg = MI.getOperand(TiedIdx).getReg().asMCReg();
----------------
phoebewang wrote:

How do we know DefReg is physical register?

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


More information about the llvm-commits mailing list