[llvm] TargetInstrInfo: make getOperandLatency return optional (NFC) (PR #73769)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 3 13:52:04 PST 2023


================
@@ -168,16 +168,20 @@ static unsigned findUseIdx(const MachineInstr *MI, unsigned UseOperIdx) {
   return UseIdx;
 }
 
-// Top-level API for clients that know the operand indices.
+// Top-level API for clients that know the operand indices. This doesn't need to
+// return std::optional<unsigned>, as it always returns a valid latency.
 unsigned TargetSchedModel::computeOperandLatency(
   const MachineInstr *DefMI, unsigned DefOperIdx,
   const MachineInstr *UseMI, unsigned UseOperIdx) const {
 
+  const unsigned InstrLatency = computeInstrLatency(DefMI);
+  const unsigned DefaultDefLatency = TII->defaultDefLatency(SchedModel, *DefMI);
+
   if (!hasInstrSchedModel() && !hasInstrItineraries())
-    return TII->defaultDefLatency(SchedModel, *DefMI);
+    return InstrLatency;
----------------
bjope wrote:

Is the change here intentional?

The commit message gives the impression that this commit mostly is a refactoring. But as far as I can tell we used to return `DefaultDefLatency `here rather than `InstrLatency`.

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


More information about the llvm-commits mailing list