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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 15 18:46:21 PDT 2024


================
@@ -1284,6 +1284,14 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
     return NewSub;
   }
 
+  // ((X % 2) + (Y % 2)) / 2 --> (X & Y & 1)
+  if (match(Op0,
+            m_Add(m_And(m_Value(X), m_One()), m_And(m_Value(Y), m_One()))) &&
----------------
goldsteinn wrote:

Think this can be generalized as just `(X + Y)/2` -> `(X & Y & 1)` where we can prove `X u<= 1` and `Y u<= 1`.

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


More information about the llvm-commits mailing list