[llvm] [LVI] Learn value ranges from ctpop results (PR #121945)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 01:31:12 PST 2025


================
@@ -1159,6 +1159,28 @@ getRangeViaSLT(CmpInst::Predicate Pred, APInt RHS,
   return std::nullopt;
 }
 
+/// Get value range for a "ctpop(Val) Pred RHS" condition.
+static ValueLatticeElement getValueFromICmpCtpop(ICmpInst::Predicate Pred,
+                                                 Value *RHS) {
+  unsigned BitWidth = RHS->getType()->getPrimitiveSizeInBits();
----------------
nikic wrote:

getScalarSizeInBits() also works on vectors. It's not relevant here (unless maybe for select conditions?) but most code in LLVM handles scalars and vectors, so it's best to always use this API.

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


More information about the llvm-commits mailing list