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

Francesco Petrogalli via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 00:31:27 PST 2023


================
@@ -155,22 +155,21 @@ unsigned PPCInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
     if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
       continue;
 
-    int Cycle = ItinData->getOperandCycle(DefClass, i);
-    if (Cycle < 0)
+    std::optional<unsigned> Cycle = ItinData->getOperandCycle(DefClass, i);
+    if (!Cycle)
----------------
fpetrogalli wrote:

nit: The test`!Cycle` returns true if `Cycle == 0`. However, given that we are using optional with numbers, I think it would be clearer to use `.has_value()` explicitly, to avoid the question "what happens if the value is set but 0". If you do this change, please to it consistently everywhere. (You don't have to apply this request if you disagree, it really a matter of personal preference here.)

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


More information about the llvm-commits mailing list