[llvm] [LVI] Generalize mask not equal conditions handling (PR #92946)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 8 13:12:00 PDT 2024
================
@@ -2788,4 +2788,31 @@ TEST_F(ConstantRangeTest, isSizeLargerThan) {
EXPECT_FALSE(One.isSizeLargerThan(1));
}
+TEST_F(ConstantRangeTest, MakeMaskNotEqualRangeExhaustive) {
+ unsigned Bits = 4;
+ unsigned Max = 1 << Bits;
+
+ for (unsigned MaskVal = 1; MaskVal < Max; ++MaskVal) {
+ APInt Mask(Bits, MaskVal);
+ for (unsigned CVal = 0; CVal < Max; ++CVal) {
+ APInt C(Bits, CVal);
+
+ SmallBitVector Elems(Max);
+ for (unsigned N = 0; N < Max; ++N) {
+ APInt Num(Bits, N);
+ if ((Num & Mask) == C)
+ continue;
+ Elems.set(Num.getZExtValue());
+ }
+
+ // Do not check for optimality, as levelling off for efficiency. E.g.,
+ // given Mask = 0b0011, C = 0b0000, the optimal range would be FullSet ∖
+ // {0, 4, 8, 12}, however we conservatively return [1, 0).
----------------
nikic wrote:
Note that `[1, 0)` *is* an optimal range in this case. Optimal isn't the same as precise, it's just the best we can do with a ConstantRange envelope.
https://github.com/llvm/llvm-project/pull/92946
More information about the llvm-commits
mailing list