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

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 11:13:08 PST 2023


================
@@ -984,6 +984,18 @@ Value *InstCombinerImpl::tryFactorizationFolds(BinaryOperator &I) {
               tryFactorization(I, SQ, Builder, RHSOpcode, LHS, Ident, C, D))
         return V;
 
+  // The instruction has the form "(A * B) op (C op D)".  Try to factorize
+  // common term for "(A * B) op C op D".
+  if (Op0 && Op1 && LHSOpcode == Instruction::Mul && isa<Constant>(D) &&
+      LHS->hasOneUse() && RHS->hasOneUse() && TopLevelOpcode == RHSOpcode &&
+      Instruction::isCommutative(RHSOpcode))
+    if (Value *Ident = getIdentityValue(LHSOpcode, C))
----------------
goldsteinn wrote:

Why are you taking identity op of `LHS` and then using in RHS? Looks like you are doing the following:
```(A * B) + (C + D) -> factorize((A * B) + (C + 1)) + D``` which doesn't seem correct.


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


More information about the llvm-commits mailing list