[llvm] [InstCombine] simplify average of lsb (PR #95684)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 05:25:39 PDT 2024


================
@@ -1284,6 +1284,13 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
     return NewSub;
   }
 
+  // Fold (X + Y) / 2 --> (X & Y) iff (X u<= 1) && (Y u<= 1)
+  if (match(Op0, m_Add(m_Value(X), m_Value(Y))) && match(Op1, m_One()) &&
+      computeKnownBits(X, 0, &I).countMaxActiveBits() <= 1 &&
----------------
dtcxzyw wrote:

@nikic Can you check compile-time impact of this change? If it is high, I suggest to revert the generalization.



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


More information about the llvm-commits mailing list