From a2ed21648c5faa148037f9e022fccdcb5178cbc3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 3 Jul 2024 18:25:06 +0200 Subject: [PATCH] [LVI] Simplify the getPredicateResult() implementation (NFC) By using ConstantRange::icmp(). --- llvm/lib/Analysis/LazyValueInfo.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 4209ee4a779539..caa5b2559690a5 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -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; }