Skip to content

Commit

Permalink
[NFC][SCEV] createNodeForSelectOrPHIInstWithICmpInstCond(): return …
Browse files Browse the repository at this point in the history
…optional

We only want about the result if it succeeds, and don't want `SCEVUnknown`.
  • Loading branch information
LebedevRI committed Jan 22, 2023
1 parent 6aaac4c commit d10adf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
7 changes: 3 additions & 4 deletions llvm/include/llvm/Analysis/ScalarEvolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -6204,7 +6207,7 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
break;
}

return getUnknown(I);
return std::nullopt;
}

static std::optional<const SCEV *>
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit d10adf6

Please sign in to comment.