[llvm] [Reassociate] Distribute multiply over add to enable factorization (PR #178201)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 02:43:28 PDT 2026


================
@@ -963,6 +963,65 @@ static BinaryOperator *convertOrWithNoCommonBitsToAdd(Instruction *Or) {
   return New;
 }
 
+/// Return true if Mul is of the form (X+Y)*C or (X-Y)*C where C is a
+/// constant, and there exists a sibling instruction of the form X*C' or Y*C'
+/// in the same expression — indicating that distribution followed by
+/// factoring will reduce the instruction count.
+static bool ShouldBreakUpDistribution(Instruction *Mul) {
+  Value *A, *B;
+  if (!match(Mul, m_c_Mul(m_OneUse(m_CombineOr(m_Add(m_Value(A), m_Value(B)),
----------------
dtcxzyw wrote:

```suggestion
  if (!match(Mul, m_Mul(m_OneUse(m_CombineOr(m_Add(m_Value(A), m_Value(B)),
```

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


More information about the llvm-commits mailing list