[llvm] [LVI] Generalize mask not equal conditions handling (PR #92946)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 12:38:38 PDT 2024


================
@@ -364,6 +364,26 @@ ConstantRange ConstantRange::makeExactNoWrapRegion(Instruction::BinaryOps BinOp,
   return makeGuaranteedNoWrapRegion(BinOp, ConstantRange(Other), NoWrapKind);
 }
 
+ConstantRange ConstantRange::makeMaskNotEqualRange(const APInt &Mask,
+                                                   const APInt &C) {
+  unsigned BitWidth = Mask.getBitWidth();
+
+  if (Mask.isZero()) {
+    if (C.isZero())
+      return getEmpty(BitWidth);
+    return getFull(BitWidth);
+  }
+
+  // If (Val & Mask) != C, constrained to the non-equality being
+  // satisfiable, then the value must be larger than the lowest set bit of
+  // Mask, offset by constant C.
+  if ((Mask & C) == C)
----------------
nikic wrote:

I think it would be slightly more elegant if you do a `if ((Mask & C) != C) return getFull(BitWidth);` check at the start of the function? Then in the Mask.isZero() case you can always return getEmpty().

https://github.com/llvm/llvm-project/pull/92946


More information about the llvm-commits mailing list