Skip to content

Commit

Permalink
[LVI] Simplify the getPredicateResult() implementation (NFC)
Browse files Browse the repository at this point in the history
By using ConstantRange::icmp().
  • Loading branch information
nikic committed Jul 4, 2024
1 parent 899fe2c commit a2ed216
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,27 +1792,11 @@ getPredicateResult(CmpInst::Predicate Pred, Constant *C,
if (!CI) return LazyValueInfo::Unknown;

const ConstantRange &CR = Val.getConstantRange();
if (Pred == ICmpInst::ICMP_EQ) {
if (!CR.contains(CI->getValue()))
return LazyValueInfo::False;

if (CR.isSingleElement())
return LazyValueInfo::True;
} else if (Pred == ICmpInst::ICMP_NE) {
if (!CR.contains(CI->getValue()))
return LazyValueInfo::True;

if (CR.isSingleElement())
return LazyValueInfo::False;
} else {
// Handle more complex predicates.
ConstantRange TrueValues =
ConstantRange::makeExactICmpRegion(Pred, CI->getValue());
if (TrueValues.contains(CR))
return LazyValueInfo::True;
if (TrueValues.inverse().contains(CR))
return LazyValueInfo::False;
}
ConstantRange RHS(CI->getValue());
if (CR.icmp(Pred, RHS))
return LazyValueInfo::True;
if (CR.icmp(CmpInst::getInversePredicate(Pred), RHS))
return LazyValueInfo::False;
return LazyValueInfo::Unknown;
}

Expand Down

0 comments on commit a2ed216

Please sign in to comment.