[NFC][SCEV] `createNodeForSelectOrPHIInstWithICmpInstCond()`: return optional
authorRoman Lebedev <lebedev.ri@gmail.com>
Sun, 22 Jan 2023 01:07:26 +0000 (04:07 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sun, 22 Jan 2023 02:03:42 +0000 (05:03 +0300)
We only want about the result if it succeeds, and don't want `SCEVUnknown`.

llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp

index 3c6d244..604ad36 100644 (file)
@@ -1705,10 +1705,9 @@ private:
   /// is either a select instruction or a phi node).  \p I is the instruction
   /// being processed, and it is assumed equivalent to "Cond ? TrueVal :
   /// FalseVal".
-  const SCEV *createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
-                                                           ICmpInst *Cond,
-                                                           Value *TrueVal,
-                                                           Value *FalseVal);
+  std::optional<const SCEV *>
+  createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I, ICmpInst *Cond,
+                                               Value *TrueVal, Value *FalseVal);
 
   /// See if we can model this select-like instruction via umin_seq expression.
   const SCEV *createNodeForSelectOrPHIViaUMinSeq(Value *I, Value *Cond,
index 4e381c4..5858916 100644 (file)
@@ -6103,8 +6103,11 @@ bool SCEVMinMaxExprContains(const SCEV *Root, const SCEV *OperandToFind,
   return FC.Found;
 }
 
-const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
-    Instruction *I, ICmpInst *Cond, Value *TrueVal, Value *FalseVal) {
+std::optional<const SCEV *>
+ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
+                                                              ICmpInst *Cond,
+                                                              Value *TrueVal,
+                                                              Value *FalseVal) {
   // Try to match some simple smax or umax patterns.
   auto *ICI = Cond;
 
@@ -6204,7 +6207,7 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
     break;
   }
 
-  return getUnknown(I);
+  return std::nullopt;
 }
 
 static std::optional<const SCEV *>
@@ -6280,10 +6283,10 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Value *V, Value *Cond,
 
   if (auto *I = dyn_cast<Instruction>(V)) {
     if (auto *ICI = dyn_cast<ICmpInst>(Cond)) {
-      const SCEV *S = createNodeForSelectOrPHIInstWithICmpInstCond(
-          I, ICI, TrueVal, FalseVal);
-      if (!isa<SCEVUnknown>(S))
-        return S;
+      if (std::optional<const SCEV *> S =
+              createNodeForSelectOrPHIInstWithICmpInstCond(I, ICI, TrueVal,
+                                                           FalseVal))
+        return *S;
     }
   }