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

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 18:22:05 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 &&
+      computeKnownBits(Y, 0, &I).countMaxActiveBits() <= 1) {
+    return BinaryOperator::CreateAnd(X, Y);
+  }
----------------
c8ef wrote:

Done.

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


More information about the llvm-commits mailing list