[llvm] d10adf6 - [NFC][SCEV] `createNodeForSelectOrPHIInstWithICmpInstCond()`: return optional
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 21 18:03:58 PST 2023
Author: Roman Lebedev
Date: 2023-01-22T05:03:42+03:00
New Revision: d10adf614296849c6028cf1e0bc43204267564b4
URL: https://github.com/llvm/llvm-project/commit/d10adf614296849c6028cf1e0bc43204267564b4
DIFF: https://github.com/llvm/llvm-project/commit/d10adf614296849c6028cf1e0bc43204267564b4.diff
LOG: [NFC][SCEV] `createNodeForSelectOrPHIInstWithICmpInstCond()`: return optional
We only want about the result if it succeeds, and don't want `SCEVUnknown`.
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 3c6d244b1f053..604ad3612a4a6 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1705,10 +1705,9 @@ class ScalarEvolution {
/// 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,
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 4e381c4599d95..58589161b4287 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -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;
}
}
More information about the llvm-commits
mailing list