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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 28 20:51:09 PDT 2024


================
@@ -1633,6 +1633,39 @@ 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;
+    const APInt *Y;
+    Value *Z;
+    if (match(I0, m_OneUse(m_Cttz(m_Value(X), m_Value(Z)))) &&
+        match(I1, m_APInt(Y))) {
+      Value *CttzOp = X;
+      if (Y->ult(I1->getType()->getScalarType()->getIntegerBitWidth())) {
----------------
nikic wrote:

```suggestion
      if (Y->ult(I1->getType()->getScalarSizeInBits())) {
```
etc.

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


More information about the llvm-commits mailing list