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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 01:04:35 PST 2023


================
@@ -202,24 +204,25 @@ class InstrItineraryData {
   /// Compute and return the use operand latency of a given itinerary
   /// class and operand index if the value is produced by an instruction of the
   /// specified itinerary class and def operand index.
-  int getOperandLatency(unsigned DefClass, unsigned DefIdx,
-                        unsigned UseClass, unsigned UseIdx) const {
+  std::optional<unsigned> getOperandLatency(unsigned DefClass, unsigned DefIdx,
+                                            unsigned UseClass,
+                                            unsigned UseIdx) const {
     if (isEmpty())
-      return -1;
+      return std::nullopt;
 
-    int DefCycle = getOperandCycle(DefClass, DefIdx);
-    if (DefCycle == -1)
-      return -1;
+    std::optional<unsigned> DefCycle = getOperandCycle(DefClass, DefIdx);
+    std::optional<unsigned> UseCycle = getOperandCycle(UseClass, UseIdx);
+    if (!DefCycle || !UseCycle)
+      return std::nullopt;
 
-    int UseCycle = getOperandCycle(UseClass, UseIdx);
-    if (UseCycle == -1)
-      return -1;
+    if (UseCycle > *DefCycle + 1)
----------------
artagnon wrote:

Yes, it is needed. See

```
    UseCycle = *DefCycle - *UseCycle + 1;
```

which could be negative.

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


More information about the llvm-commits mailing list