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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 00:40:41 PST 2025


================
@@ -1191,6 +1257,13 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
   if (matchICmpOperand(Offset, RHS, Val, SwappedPred))
     return getValueFromSimpleICmpCondition(SwappedPred, LHS, Offset, ICI,
                                            UseBlockValue);
+  Intrinsic::ID IID;
+  if (matchBitIntrinsic(LHS, Val, IID))
+    return getValueFromICmpBitIntrinsic(EdgePred, BitWidth, IID, RHS, ICI,
+                                        UseBlockValue);
+  if (matchBitIntrinsic(RHS, Val, IID))
+    return getValueFromICmpBitIntrinsic(SwappedPred, BitWidth, IID, LHS, ICI,
----------------
dtcxzyw wrote:

Can you add a commuted test case?
```
define void @ctpop(i8 %v, i8 range(i8 0, 4) %upper) {
  %res = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %v)
   %c0.0 = icmp ule i8 %upper, %v
  ...
```


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


More information about the llvm-commits mailing list