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

Rohit Aggarwal via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 04:29:07 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))
----------------
rohitaggarwal007 wrote:

The instructions which are of my interest are:
  renamable $r9d = MOV32r0 implicit-def dead $eflags, implicit-def $r9
  renamable $eax = MOV32r0 implicit-def dead $eflags, implicit-def $rax
  
 I am following these instruction pattern to find and remove them.
 There is review comment suggestion to use regOverlaps instead of isSubRegister. As per my usecase, it should be isSubRegister i.e. $eax is the subregister of $rax. It will limit the scope of the match. I am not aware any case in which 3rd operand is not super register of 1st register.
 
 @arsenm Please add your view on this.


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


More information about the llvm-commits mailing list