Skip to content

Commit

Permalink
[LVI] Check ConstantFoldCompareInstOperands() failure (NFCI)
Browse files Browse the repository at this point in the history
I don't believe this can happen right now (because we're only
working on icmps and as such can't hit the current fcmp null
paths), but this will be possible in the future when icmp
constant expressions are removed.
  • Loading branch information
nikic committed Jul 20, 2023
1 parent b846f43 commit 781beb3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
Constant *Res = nullptr;
if (Val.isConstant()) {
Res = ConstantFoldCompareInstOperands(Pred, Val.getConstant(), C, DL, TLI);
if (ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
if (ConstantInt *ResCI = dyn_cast_or_null<ConstantInt>(Res))

This comment has been minimized.

Copy link
@tbaederr

tbaederr Jul 20, 2023

Contributor

dyn_cast_if_present

return ResCI->isZero() ? LazyValueInfo::False : LazyValueInfo::True;
return LazyValueInfo::Unknown;
}
Expand Down Expand Up @@ -1791,14 +1791,14 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
Val.getNotConstant(), C, DL,
TLI);
if (Res->isNullValue())
if (Res && Res->isNullValue())
return LazyValueInfo::False;
} else if (Pred == ICmpInst::ICMP_NE) {
// !C1 != C -> true iff C1 == C.
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
Val.getNotConstant(), C, DL,
TLI);
if (Res->isNullValue())
if (Res && Res->isNullValue())
return LazyValueInfo::True;
}
return LazyValueInfo::Unknown;
Expand Down

0 comments on commit 781beb3

Please sign in to comment.