[llvm] [InstCombine] Fold mul (lshr exact (X, N)), 2^N + 1 -> add (X , lshr exact (X, N)) (PR #95042)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 08:35:30 PDT 2024


================
@@ -255,6 +255,38 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
     }
   }
 
+  {
+    // mul (lshr exact X, N), (2^N + 1) -> add (X , lshr (X, N))
+    Value *NewOp;
+    const APInt *ShiftC;
+    const APInt *MulAP;
+    if ((HasNSW || HasNUW) &&
+        match(&I, m_Mul(m_CombineOr(m_LShr(m_Value(NewOp), m_APInt(ShiftC)),
+                                    m_AShr(m_Value(NewOp), m_APInt(ShiftC))),
----------------
nikic wrote:

```suggestion
        match(&I, m_Mul(m_Shr(m_Value(NewOp), m_APInt(ShiftC)),
```

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


More information about the llvm-commits mailing list