[llvm] [CodeGen][MachineLICM] Use RegUnits in HoistRegionPostRA (PR #94608)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 07:52:44 PDT 2024


================
@@ -488,19 +531,18 @@ void MachineLICMBase::ProcessMI(MachineInstr *MI, BitVector &PhysRegDefs,
     // If we have already seen another instruction that defines the same
     // register, then this is not safe.  Two defs is indicated by setting a
     // PhysRegClobbers bit.
-    for (MCRegAliasIterator AS(Reg, TRI, true); AS.isValid(); ++AS) {
-      if (PhysRegDefs.test(*AS))
-        PhysRegClobbers.set(*AS);
+    for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI) {
+      if (RUDefs.test(*RUI)) {
+        RUClobbers.set(*RUI);
+        RuledOut = true;
+      } else if (RUClobbers.test(*RUI)) {
+        // MI defined register is seen defined by another instruction in
+        // the loop, it cannot be a LICM candidate.
+        RuledOut = true;
+      }
+
+      RUDefs.set(*RUI);
----------------
jayfoad wrote:

Your code calls RUDefs.set even if it was already set. How about:
```suggestion
      if (RUDefs.test(*RUI)) {
        RUClobbers.set(*RUI);
        RuledOut = true;
      } else {
        RUDefs.set(*RUI);
        if (RUClobbers.test(*RUI)) {
          // MI defined register is seen defined by another instruction in
          // the loop, it cannot be a LICM candidate.
          RuledOut = true;
        }
      }
```
Maybe it doesn't actually run any faster.

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


More information about the llvm-commits mailing list