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

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 12:11:31 PDT 2021


spatel added a comment.

In D102574#2764241 <https://reviews.llvm.org/D102574#2764241>, @vdsered wrote:

> 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))

Yes - let's give that line a name (not sure what's best - "hasRemovableUser" ?), so we don't have to repeat it.

> 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)

Yes - please make a different patch. It's probably only mul/fmul that have a need for this. Most other binops should simplify if both operands are the same.
For example, the sqrt pattern should get folded by instsimplify, so I don't think that needs any changes.


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

https://reviews.llvm.org/D102574



More information about the llvm-commits mailing list