<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missed optimization in math expression: log of pow or exp of log"
   href="https://bugs.llvm.org/show_bug.cgi?id=35742">35742</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization in math expression: log of pow or exp of log
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zheltonozhskiy@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <cmath>

double f(double a)
{
    return exp(log(a)) ;
}


double f2(double a, double b)
{
    return log(pow(a,b)) ;
}

clang(trunk) -g0 -O3 -march=bdver4 -ffast-math generates following assembly:

f(double): # @f(double)
  pushq %rax
  callq log
  popq %rax
  jmp exp # TAILCALL
f2(double, double): # @f2(double, double)
  pushq %rax
  callq pow
  popq %rax
  jmp log # TAILCALL 

While gcc generates

f(double):
  ret
f2(double, double):
  subq $24, %rsp
  vmovsd %xmm1, 8(%rsp)
  call __log_finite
  vmovsd 8(%rsp), %xmm1
  addq $24, %rsp
  vmulsd %xmm0, %xmm1, %xmm0
  ret

replacing exponent of natural logarithm with the number itself and ln(a^b) with
b*ln(a) (same for log10/log2)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>