[llvm] [InstCombine] enable more factorization in SimplifyUsingDistributiveLaws (PR #69892)
Alex Cameron via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 19:57:35 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:
> **spatel**: It seems odd for this function to specify the exact opcode. Everything else is generalized based on association and distribution laws. Is mul really the only opcode where this transform works?
> **Allen (Author)**: Thanks, I restrict to mul as some performance regression of logic combination tests
https://github.com/llvm/llvm-project/pull/69892
More information about the llvm-commits
mailing list