[PATCH] D41608: [InstCombine] Missed optimization in math expression: aggressive optimization with pow

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 10:54:09 PST 2018


spatel added a comment.

In https://reviews.llvm.org/D41608#969442, @Quolyk wrote:

> pow(a, x) * a * a * a * a   emits to
>
>   define double @pow_ab_x_aaaa_fast(double %a, double %x) {
>     %1 = call fast double @llvm.pow.f64(double %a, double %x)
>     %2 = fmul fast double %a, %a
>     %3 = fmul fast double %2, %2
>     %mul4 = fmul fast double %3, %1
>     ret double %mul4
>   }
>
>
> I don't see obvious ways to fold these instructions. I Would appreciate if somebody could help me with this.


This looks like it went through -reassociate first? I was checking with a straight IR translation, so we're just multiplying by 'a' over and over. This would require more complex logic, so that's a different patch (and I'm not sure where it would belong).



================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:713
+                                           Intrinsic::pow, I.getType());
+    // pow(A, B) * A -> pow(A, B+1)
+    if (match(Op0, m_Intrinsic<Intrinsic::pow>(m_Value(A0), m_Value(B0))) &&
----------------
spatel wrote:
> Need to handle commuted versions too (please add a test):
> 
> ```
> define double @pow_ab_x_a_fast_commute(double %a, double %b)  {
>   %c = fdiv double 1.0, %a  ; defeat complexity-based canonicalization of operands
>   %p = call fast double @llvm.pow.f64(double %a, double %b)
>   %mul = fmul fast double %c, %p
>   ret double %mul
> }
> 
> ```
This comment was marked 'Done', but I don't see code to account for this or the test that I suggested.


https://reviews.llvm.org/D41608





More information about the llvm-commits mailing list