[PATCH] D102574: [InstCombine] Missed optimization for pow(x, y) * pow(x, z) with fast-math

Daniil Seredkin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 11:59:07 PDT 2021


vdsered added a comment.

In D102574#2763320 <https://reviews.llvm.org/D102574#2763320>, @spatel wrote:

> In D102574#2763294 <https://reviews.llvm.org/D102574#2763294>, @vdsered wrote:
>
>> I have noticed that there are two similiar transformations below exp2(X) * exp2(Y) -> exp2(X + Y) and exp(X) * exp(Y) -> exp(X + Y) that are done when each operand of multiplication has exactly one use which is n't true if, for example, there is exp2(X) * exp2(X) where exp2(X) is the same instruction, so it can be improved a little. I'm going to update the patch
>
> I recommend that you make that use-check logic into a helper function as a preliminary step, so it can be be accessed from other places. For example, we miss this transform too because the use check is too restrictive:
> https://alive2.llvm.org/ce/z/27ryac

Are you talking about all checks that we do here? (see below)

  Op0->hasOneUse() || Op1->hasOneUse() || (Op1 == Op0 && Op1->hasNUses(2))

Because I think this condition is going to be the same for many patterns and I will create another patch to implement the helper function and refactor conditions at least for those transformations (below) before updating this one

1. exp(X) * exp(Y) -> exp(X + Y)
2. exp2(X) * exp2(Y) -> exp2(X + Y)
3. sqrt(X) * sqrt(Y) -> sqrt(X * Y)

There are more cases when this sort of check is useful like in InstCombinerImpl::SimplifyAssociativeOrCommutative

  // Transform: "(A op C1) op (B op C2)" ==> "(A op B) op (C1 op C2)"
  // if C1 and C2 are constants.
  Value *A, *B;
  Constant *C1, *C2;
  if (Op0 && Op1 &&
      Op0->getOpcode() == Opcode && Op1->getOpcode() == Opcode &&
      match(Op0, m_OneUse(m_BinOp(m_Value(A), m_Constant(C1)))) &&
      match(Op1, m_OneUse(m_BinOp(m_Value(B), m_Constant(C2))))) {

The only difference is how op0 and op1 are compared (via opcode), but the use-check can be relaxed too as I understand


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102574/new/

https://reviews.llvm.org/D102574



More information about the llvm-commits mailing list