Skip to content

Commit 1f5ee80

Browse files
committed
[LVI] Don't return optional from getEdgeValueLocal() (NFC)
The general convention inside LVI is that std::nullopt means that a value has been pushed to the worklist. However, getEdgeValueLocal() used it as an additional spelling for getOverdefined() instead.
1 parent cb8690f commit 1f5ee80

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,9 @@ static ValueLatticeElement constantFoldUser(User *Usr, Value *Op,
13011301
return ValueLatticeElement::getOverdefined();
13021302
}
13031303

1304-
/// Compute the value of Val on the edge BBFrom -> BBTo. Returns false if
1305-
/// Val is not constrained on the edge. Result is unspecified if return value
1306-
/// is false.
1307-
static std::optional<ValueLatticeElement> getEdgeValueLocal(Value *Val,
1308-
BasicBlock *BBFrom,
1309-
BasicBlock *BBTo) {
1304+
/// Compute the value of Val on the edge BBFrom -> BBTo.
1305+
static ValueLatticeElement getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
1306+
BasicBlock *BBTo) {
13101307
// TODO: Handle more complex conditionals. If (v == 0 || v2 < 1) is false, we
13111308
// know that v != 0.
13121309
if (BranchInst *BI = dyn_cast<BranchInst>(BBFrom->getTerminator())) {
@@ -1380,15 +1377,15 @@ static std::optional<ValueLatticeElement> getEdgeValueLocal(Value *Val,
13801377
if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) {
13811378
Value *Condition = SI->getCondition();
13821379
if (!isa<IntegerType>(Val->getType()))
1383-
return std::nullopt;
1380+
return ValueLatticeElement::getOverdefined();
13841381
bool ValUsesConditionAndMayBeFoldable = false;
13851382
if (Condition != Val) {
13861383
// Check if Val has Condition as an operand.
13871384
if (User *Usr = dyn_cast<User>(Val))
13881385
ValUsesConditionAndMayBeFoldable = isOperationFoldable(Usr) &&
13891386
usesOperand(Usr, Condition);
13901387
if (!ValUsesConditionAndMayBeFoldable)
1391-
return std::nullopt;
1388+
return ValueLatticeElement::getOverdefined();
13921389
}
13931390
assert((Condition == Val || ValUsesConditionAndMayBeFoldable) &&
13941391
"Condition != Val nor Val doesn't use Condition");
@@ -1406,7 +1403,7 @@ static std::optional<ValueLatticeElement> getEdgeValueLocal(Value *Val,
14061403
ValueLatticeElement EdgeLatticeVal =
14071404
constantFoldUser(Usr, Condition, CaseValue, DL);
14081405
if (EdgeLatticeVal.isOverdefined())
1409-
return std::nullopt;
1406+
return ValueLatticeElement::getOverdefined();
14101407
EdgeVal = EdgeLatticeVal.getConstantRange();
14111408
}
14121409
if (DefaultCase) {
@@ -1423,7 +1420,7 @@ static std::optional<ValueLatticeElement> getEdgeValueLocal(Value *Val,
14231420
}
14241421
return ValueLatticeElement::getRange(std::move(EdgesVals));
14251422
}
1426-
return std::nullopt;
1423+
return ValueLatticeElement::getOverdefined();
14271424
}
14281425

14291426
/// Compute the value of Val on the edge BBFrom -> BBTo or the value at
@@ -1435,9 +1432,7 @@ LazyValueInfoImpl::getEdgeValue(Value *Val, BasicBlock *BBFrom,
14351432
if (Constant *VC = dyn_cast<Constant>(Val))
14361433
return ValueLatticeElement::get(VC);
14371434

1438-
ValueLatticeElement LocalResult =
1439-
getEdgeValueLocal(Val, BBFrom, BBTo)
1440-
.value_or(ValueLatticeElement::getOverdefined());
1435+
ValueLatticeElement LocalResult = getEdgeValueLocal(Val, BBFrom, BBTo);
14411436
if (hasSingleValue(LocalResult))
14421437
// Can't get any more precise here
14431438
return LocalResult;

0 commit comments

Comments
 (0)