<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 - Simplify pow(C, sitofp(X))"
   href="https://bugs.llvm.org/show_bug.cgi?id=42190">42190</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Simplify pow(C, sitofp(X))
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Pattern extracted from
<a href="https://github.com/philipl/pifs/blob/master/src/piqpr8.c#L94">https://github.com/philipl/pifs/blob/master/src/piqpr8.c#L94</a>

double foo(int id, int k) {
    return pow (7., id - k);
}

So I am wondering if we could do nice speed optimization.


Current TOT of clang produces IR:
%doublevalfromint = sitofp i32 %sub to double
%result = tail call double @pow(double 7.000000e+00, double %doublevalfromint)

Some suggestions:

1, Maybe we can, under -Ofast or so, transform following IR to something like:

%result = call pow_double_with_integer_exp(double 7.000000e+00,
%doublevalfromint)?

Ideally, we could match constant integer base (7 here) and use
pow_integer_with_integer_exp.

But the problem is, I am not aware whether we have any helpers for
pow_double_with_integer_exp / pow_integer_with_integer_exp. But I think this is
quite promising.

2, Specific transformation for base 2
From:
%doubleval = sitofp i32 %sub to double
%result = tail call double @pow(double 2.000000e+00, double %doubleval)
To:
%intpow = shl i32 2, %%doubleval
%result = sitofp i32 %intpow to double

?</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>