aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-12-02 21:49:08 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-06-04 11:59:04 +0000
commit574b7079b96703a748f89ef5adb7dc3e26b8f7fc (patch)
tree195000196b1e0cc13dea43258fa240e006f48184 /contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp
parent1f6fd64fe9c996b4795ee4a6c66b8f9216747560 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp b/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp
index 50fa169c2081..5b5d48bf6fe5 100644
--- a/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/contrib/llvm-project/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1095,7 +1095,8 @@ static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI,
if (!Ty->isIntegerTy())
return ValueLatticeElement::getOverdefined();
- APInt Offset(Ty->getScalarSizeInBits(), 0);
+ unsigned BitWidth = Ty->getScalarSizeInBits();
+ APInt Offset(BitWidth, 0);
if (matchICmpOperand(Offset, LHS, Val, EdgePred))
return getValueFromSimpleICmpCondition(EdgePred, RHS, Offset);
@@ -1118,13 +1119,23 @@ static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI,
// If (Val & Mask) != 0 then the value must be larger than the lowest set
// bit of Mask.
if (EdgePred == ICmpInst::ICMP_NE && !Mask->isZero() && C->isZero()) {
- unsigned BitWidth = Ty->getIntegerBitWidth();
return ValueLatticeElement::getRange(ConstantRange::getNonEmpty(
APInt::getOneBitSet(BitWidth, Mask->countTrailingZeros()),
APInt::getZero(BitWidth)));
}
}
+ // If (X urem Modulus) >= C, then X >= C.
+ // TODO: An upper bound could be computed as well.
+ if (match(LHS, m_URem(m_Specific(Val), m_Value())) &&
+ match(RHS, m_APInt(C))) {
+ // Use the icmp region so we don't have to deal with different predicates.
+ ConstantRange CR = ConstantRange::makeExactICmpRegion(EdgePred, *C);
+ if (!CR.isEmptySet())
+ return ValueLatticeElement::getRange(ConstantRange::getNonEmpty(
+ CR.getUnsignedMin(), APInt(BitWidth, 0)));
+ }
+
return ValueLatticeElement::getOverdefined();
}