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

Sizov Nikita via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 2 12:35:36 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_ConstantInt(CInt), m_Value(X))) &&
+        match(Op1, m_One())) {
+      Value *ConstCttz =
+          IC.Builder.CreateBinaryIntrinsic(Intrinsic::cttz, CInt, Op1);
+      return IC.replaceInstUsesWith(II, IC.Builder.CreateAdd(ConstCttz, X));
----------------
snikitav wrote:

What's profit in inferring this flags for SUB?

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


More information about the llvm-commits mailing list