aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorAntonio Frighetto <me@antoniofrighetto.com>2024-06-06 08:26:40 +0200
committerAntonio Frighetto <me@antoniofrighetto.com>2024-06-17 21:13:52 +0200
commitc22d3917b93a6d54613d2e5b2ea4c97546144c46 (patch)
tree7ffae85640b3d3449a92ffa7a878aa2fac39381e /llvm/lib/Analysis
parentc9549e10e9ea70428ada80a34d15afeaf5710b2d (diff)
downloadllvm-c22d3917b93a6d54613d2e5b2ea4c97546144c46.zip
llvm-c22d3917b93a6d54613d2e5b2ea4c97546144c46.tar.gz
llvm-c22d3917b93a6d54613d2e5b2ea4c97546144c46.tar.bz2
[LVI][ConstantRange] Generalize mask not equal conditions handling
Extend `V & Mask != 0` for non-zero constants if satisfiable, when retrieving constraint value information from a non-equality comparison. Proof: https://alive2.llvm.org/ce/z/dc5BeT. Motivating example: https://github.com/gcc-mirror/gcc/blob/master/gcc/testsuite/gcc.dg/tree-ssa/vrp76.c.
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/LazyValueInfo.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 8b6e56c..aaa7baa 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1188,13 +1188,10 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
return ValueLatticeElement::getRange(
ConstantRange::fromKnownBits(Known, /*IsSigned*/ false));
}
- // 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()) {
- return ValueLatticeElement::getRange(ConstantRange::getNonEmpty(
- APInt::getOneBitSet(BitWidth, Mask->countr_zero()),
- APInt::getZero(BitWidth)));
- }
+
+ if (EdgePred == ICmpInst::ICMP_NE)
+ return ValueLatticeElement::getRange(
+ ConstantRange::makeMaskNotEqualRange(*Mask, *C));
}
// If (X urem Modulus) >= C, then X >= C.