[llvm] Missing opt with ctlz and shifts of power of 2 constants (#41333) (PR #74175)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 07:00:47 PST 2023


================
@@ -549,6 +551,36 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
 
     if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X))))
       return IC.replaceOperand(II, 0, X);
+
+    // cttz(shl(%const, %val), 1) --> add(cttz(%const, 1), %val)
+    if (match(Op0, m_Shl(m_Constant(C), m_Value(X))) && match(Op1, m_One())) {
----------------
nikic wrote:

```suggestion
    if (match(Op0, m_Shl(m_ImmConstant(C), m_Value(X))) && match(Op1, m_One())) {
```
Here and elsewhere to exclude constant expressions.

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


More information about the llvm-commits mailing list