[llvm] TargetSchedule: factor out code in computeOperandLatency (NFC) (PR #73769)

Francesco Petrogalli via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 13:58:46 PST 2023


================
@@ -173,8 +173,11 @@ unsigned TargetSchedModel::computeOperandLatency(
   const MachineInstr *DefMI, unsigned DefOperIdx,
   const MachineInstr *UseMI, unsigned UseOperIdx) const {
 
+  unsigned InstrLatency = computeInstrLatency(DefMI);
+  unsigned DefaultDefLatency = TII->defaultDefLatency(SchedModel, *DefMI);
+
   if (!hasInstrSchedModel() && !hasInstrItineraries())
-    return TII->defaultDefLatency(SchedModel, *DefMI);
+    return InstrLatency;
 
   if (hasInstrItineraries()) {
     int OperLatency = 0;
----------------
fpetrogalli wrote:

I find confusing that the latency of an operand can be negative. It seems to be done only because `-1` has a special meaning in this method: [1]
```cpp
virtual int TargetInstrInfo::getOperandLatency (const InstrItineraryData *ItinData, 
                SDNode *DefNode, 
                unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const

```

[1] So may negative numbers left behind!

I wonder if, for the sake of refactoring, it's worth changing the interface of the TTI method, by returning `std::optional<unsigned>` instead of `int`?

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


More information about the llvm-commits mailing list