[llvm] [InstCombine] Fold Minimum over Trailing/Leading Bits Counts (PR #90402)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 18:58:22 PDT 2024


================
@@ -1633,6 +1667,21 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
       Value *Cmp = Builder.CreateICmpNE(I0, Zero);
       return CastInst::Create(Instruction::ZExt, Cmp, II->getType());
     }
+    // umin(cttz(x), const) --> cttz(x | (1 << const))
+    Value *X;
+    Constant *Y;
+    Value *Z;
+    if (match(I0, m_OneUse(m_Cttz(m_Value(X), m_Value(Z)))) &&
+        match(I1, m_Constant(Y))) {
----------------
nikic wrote:

```suggestion
        match(I1, m_ImmConstant(Y))) {
```
Otherwise this will crash and burn with constant expressions.

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


More information about the llvm-commits mailing list