[llvm] [LVI] Generalize mask not equal conditions handling (PR #92946)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 01:16:56 PDT 2024
================
@@ -364,6 +364,29 @@ ConstantRange ConstantRange::makeExactNoWrapRegion(Instruction::BinaryOps BinOp,
return makeGuaranteedNoWrapRegion(BinOp, ConstantRange(Other), NoWrapKind);
}
+ConstantRange ConstantRange::makeMaskNotEqualRange(const APInt &Mask,
+ const APInt &C) {
+ assert(!Mask.isZero() && "Mask cannot be zero.");
+ unsigned BitWidth = Mask.getBitWidth();
+ unsigned TrailingZeroesOfMask = Mask.countr_zero();
+
+ // If (Val & Mask) != 0 then the value must be larger than the lowest set
+ // bit of Mask.
+ if (C.isZero())
+ return ConstantRange::getNonEmpty(
+ APInt::getOneBitSet(BitWidth, TrailingZeroesOfMask),
+ APInt::getZero(BitWidth));
----------------
antoniofrighetto wrote:
It it is indeed equivalent, but thought it was a bit nice / helpful to have the base case explicit.
https://github.com/llvm/llvm-project/pull/92946
More information about the llvm-commits
mailing list