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: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to