[llvm] MTM: improve operand latency when missing sched info (PR #101389)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 10:10:00 PDT 2024
================
@@ -761,6 +762,64 @@ static void updatePhysDepsDownwards(const MachineInstr *UseMI,
}
}
+/// Estimates the number of cycles elapsed between DefMI and UseMI if they're
+/// non-null and in the same BasicBlock. Returns std::nullopt when UseMI is in a
+/// different MBB than DefMI.
+static std::optional<unsigned>
+estimateDefUseCycles(const TargetSchedModel &Sched, const MachineInstr *DefMI,
+ const MachineInstr *UseMI) {
+ if (!DefMI || !UseMI || DefMI == UseMI)
+ return 0;
+ const MachineBasicBlock *ParentBB = DefMI->getParent();
+ if (ParentBB != UseMI->getParent())
+ return std::nullopt;
+
+ const auto DefIt =
+ llvm::find_if(ParentBB->instrs(),
+ [DefMI](const MachineInstr &MI) { return DefMI == &MI; });
+ const auto UseIt =
+ llvm::find_if(ParentBB->instrs(),
+ [UseMI](const MachineInstr &MI) { return UseMI == &MI; });
+
+ unsigned NumMicroOps = 0;
+ for (auto It = DefIt; It != UseIt; ++It) {
+ // In cases where the UseMI is a PHI at the beginning of the MBB, compute
+ // MicroOps until the end of the MBB.
+ if (It.isEnd())
+ break;
+
+ NumMicroOps += Sched.getNumMicroOps(&*It);
+ }
+ return NumMicroOps / Sched.getIssueWidth();
----------------
michaelmaitland wrote:
@RKSimon do you still have concerns about use of micro-ops and issue width here?
I think it makes sense to use issue width in determining "the number of cycles between two instructions" in the calculation here. For example:
```
a = def
b = ...
c = use
```
If the issue width is 1, then `a` is issued in once cycle, and `b` the next. But if the issue width is `2` then `a` and `b` are issued in the same cycle. In the former case we should estimate 2 cycles between `[a, c)` and in the latter estimate 1 cycle.
https://github.com/llvm/llvm-project/pull/101389
More information about the llvm-commits
mailing list