[llvm-bugs] [Bug 42190] New: Simplify pow(C, sitofp(X))

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 7 12:49:37 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42190

            Bug ID: 42190
           Summary: Simplify pow(C, sitofp(X))
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

Pattern extracted from
https://github.com/philipl/pifs/blob/master/src/piqpr8.c#L94

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

?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190607/210fb3b4/attachment.html>


More information about the llvm-bugs mailing list