Skip to content

Commit a2ed216

Browse files
committed
[LVI] Simplify the getPredicateResult() implementation (NFC)
By using ConstantRange::icmp().
1 parent 899fe2c commit a2ed216

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,27 +1792,11 @@ getPredicateResult(CmpInst::Predicate Pred, Constant *C,
17921792
if (!CI) return LazyValueInfo::Unknown;
17931793

17941794
const ConstantRange &CR = Val.getConstantRange();
1795-
if (Pred == ICmpInst::ICMP_EQ) {
1796-
if (!CR.contains(CI->getValue()))
1797-
return LazyValueInfo::False;
1798-
1799-
if (CR.isSingleElement())
1800-
return LazyValueInfo::True;
1801-
} else if (Pred == ICmpInst::ICMP_NE) {
1802-
if (!CR.contains(CI->getValue()))
1803-
return LazyValueInfo::True;
1804-
1805-
if (CR.isSingleElement())
1806-
return LazyValueInfo::False;
1807-
} else {
1808-
// Handle more complex predicates.
1809-
ConstantRange TrueValues =
1810-
ConstantRange::makeExactICmpRegion(Pred, CI->getValue());
1811-
if (TrueValues.contains(CR))
1812-
return LazyValueInfo::True;
1813-
if (TrueValues.inverse().contains(CR))
1814-
return LazyValueInfo::False;
1815-
}
1795+
ConstantRange RHS(CI->getValue());
1796+
if (CR.icmp(Pred, RHS))
1797+
return LazyValueInfo::True;
1798+
if (CR.icmp(CmpInst::getInversePredicate(Pred), RHS))
1799+
return LazyValueInfo::False;
18161800
return LazyValueInfo::Unknown;
18171801
}
18181802

0 commit comments

Comments
 (0)