[llvm] [InstCombine] enable more factorization in SimplifyUsingDistributiveLaws (PR #69892)

Alex Cameron via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 18:50:58 PDT 2023


================
@@ -997,11 +1009,33 @@ Value *InstCombinerImpl::foldUsingDistributiveLaws(BinaryOperator &I) {
   BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS);
   BinaryOperator *Op1 = dyn_cast<BinaryOperator>(RHS);
   Instruction::BinaryOps TopLevelOpcode = I.getOpcode();
+  Value *A, *B, *C, *D;
+  Instruction::BinaryOps LHSOpcode, RHSOpcode;
 
   // Factorization.
   if (Value *R = tryFactorizationFolds(I))
     return R;
 
+  if (Op0)
+    LHSOpcode = getBinOpsForFactorization(TopLevelOpcode, Op0, A, B);
+  if (Op1)
+    RHSOpcode = getBinOpsForFactorization(TopLevelOpcode, Op1, C, D);
+
+  // The instruction has the form "(A op' B) op' (C * D)". See if expanding it
+  // out to "(C * D) op' (A op' B)" results in simplifications.
+  if (Op0 && Op1 && RHSOpcode == Instruction::Mul && A == C &&
----------------
tetsuo-cpp wrote:

If this is still a sticking point, I can investigate what regressions Allen was talking about and explain why exactly we can't generalise this.

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


More information about the llvm-commits mailing list