[llvm] 58f3b0d - [CodeGen] Optimize/simplify finalizeBundle. NFC (#155448)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 23:54:06 PDT 2025


Author: Björn Pettersson
Date: 2025-08-27T08:54:02+02:00
New Revision: 58f3b0dd8d7b2e09d82dae95908cf34ef50468af

URL: https://github.com/llvm/llvm-project/commit/58f3b0dd8d7b2e09d82dae95908cf34ef50468af
DIFF: https://github.com/llvm/llvm-project/commit/58f3b0dd8d7b2e09d82dae95908cf34ef50468af.diff

LOG: [CodeGen] Optimize/simplify finalizeBundle. NFC (#155448)

When tracking defs in finalizeBundle two sets are used. LocalDefs is
used to track defined virtual and physical registers, while LocalDefsP
is used to track defined register units for the physical registers.

This patch moves the updates of LocalDefsP to only iterate over regunits
when a new physical register is added to LocalDefs. When the physical
register already is present in LocalDefs, then the corresponding
register units are present in LocalDefsP. So it was a waste of time to
add them to the set again.

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineInstrBundle.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index d9e8484c08d76..5830ecfe4aa20 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -173,6 +173,9 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
       if (LocalDefs.insert(Reg)) {
         if (MO.isDead())
           DeadDefSet.insert(Reg);
+        else if (Reg.isPhysical())
+          for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
+            LocalDefsP.set(Unit);
       } else {
         // Re-defined inside the bundle, it's no longer killed.
         KilledDefSet.erase(Reg);
@@ -181,11 +184,6 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
           DeadDefSet.erase(Reg);
         }
       }
-
-      if (!MO.isDead() && Reg.isPhysical()) {
-        for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
-          LocalDefsP.set(Unit);
-      }
     }
 
     // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions


        


More information about the llvm-commits mailing list