[llvm] [LVI] Learn value ranges from ctpop/ctlz/cttz results (PR #121945)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 12 21:43:00 PST 2025
================
@@ -1159,6 +1162,49 @@ getRangeViaSLT(CmpInst::Predicate Pred, APInt RHS,
return std::nullopt;
}
+static bool matchBitIntrinsic(Value *LHS, Value *Val, Intrinsic::ID &IID) {
+ auto *II = dyn_cast<IntrinsicInst>(LHS);
+ if (!II)
+ return false;
+ auto ID = II->getIntrinsicID();
+ switch (ID) {
+ case Intrinsic::ctpop:
+ case Intrinsic::ctlz:
+ case Intrinsic::cttz:
+ break;
+ default:
+ return false;
+ }
+ if (II->getArgOperand(0) != Val)
+ return false;
+ IID = ID;
+ return true;
+}
+
+/// Get value range for a "ctpop(Val) Pred RHS" condition.
+ValueLatticeElement
+LazyValueInfoImpl::getValueFromICmpCtpop(ICmpInst::Predicate Pred, Value *RHS) {
+ unsigned BitWidth = RHS->getType()->getPrimitiveSizeInBits();
+
+ auto RHSConst = dyn_cast<ConstantInt>(RHS);
+ if (!RHSConst)
+ return ValueLatticeElement::getOverdefined();
+
+ auto &RHSVal = RHSConst->getValue();
+
+ ConstantRange ResValRange =
+ ConstantRange::makeAllowedICmpRegion(Pred, {RHSVal, RHSVal + 1});
----------------
dtcxzyw wrote:
```suggestion
ConstantRange::makeExactICmpRegion(Pred, RHSVal);
```
https://github.com/llvm/llvm-project/pull/121945
More information about the llvm-commits
mailing list