[PATCH] D150855: MachineCombiner: consider all uses in getLatency()

Ramkumar Ramachandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 03:49:23 PDT 2023


artagnon updated this revision to Diff 523321.
artagnon added a comment.

Address review by barannikov88


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150855/new/

https://reviews.llvm.org/D150855

Files:
  llvm/lib/CodeGen/MachineCombiner.cpp


Index: llvm/lib/CodeGen/MachineCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCombiner.cpp
+++ llvm/lib/CodeGen/MachineCombiner.cpp
@@ -278,21 +278,17 @@
       continue;
     if (!MO.isDef())
       continue;
-    // Get the first instruction that uses MO
-    MachineRegisterInfo::reg_iterator RI = MRI->reg_begin(MO.getReg());
-    RI++;
-    if (RI == MRI->reg_end())
-      continue;
-    MachineInstr *UseMO = RI->getParent();
-    unsigned LatencyOp = 0;
-    if (UseMO && BlockTrace.isDepInTrace(*Root, *UseMO)) {
-      LatencyOp = TSchedModel.computeOperandLatency(
-          NewRoot, NewRoot->findRegisterDefOperandIdx(MO.getReg()), UseMO,
-          UseMO->findRegisterUseOperandIdx(MO.getReg()));
-    } else {
-      LatencyOp = TSchedModel.computeInstrLatency(NewRoot);
+    for (MachineInstr &UseInstr : MRI->use_instructions(MO.getReg())) {
+      unsigned LatencyOp = 0;
+      if (BlockTrace.isDepInTrace(*Root, UseInstr)) {
+        LatencyOp = TSchedModel.computeOperandLatency(
+            NewRoot, NewRoot->findRegisterDefOperandIdx(MO.getReg()), &UseInstr,
+            UseInstr.findRegisterUseOperandIdx(MO.getReg()));
+      } else {
+        LatencyOp = TSchedModel.computeInstrLatency(NewRoot);
+      }
+      NewRootLatency = std::max(NewRootLatency, LatencyOp);
     }
-    NewRootLatency = std::max(NewRootLatency, LatencyOp);
   }
   return NewRootLatency;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150855.523321.patch
Type: text/x-patch
Size: 1457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230518/c3303ad1/attachment.bin>


More information about the llvm-commits mailing list