[llvm] [Codegen] Remove redundant instruction using machinelateCleanup (PR #139716)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 05:06:48 PDT 2025


================
@@ -189,7 +189,13 @@ static bool isCandidate(const MachineInstr *MI, Register &DefedReg,
       if (MO.isDef()) {
         if (i == 0 && !MO.isImplicit() && !MO.isDead())
           DefedReg = MO.getReg();
-        else
+        else if (i != 0 && DefedReg != MCRegister::NoRegister) {
+          if (MO.isDead() && MO.isImplicit())
+            continue;
+          if (MO.isImplicit() && TRI->regsOverlap(MO.getReg(), DefedReg))
----------------
jayfoad wrote:

In the general case I don't think it's safe to remove an instruction like this, because that it removing a def of the upper bits of $rax, which could be used by some other instruction:
```
renamable $eax = MOV32r0 implicit-def dead $eflags, implicit-def $rax
```

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


More information about the llvm-commits mailing list