[llvm-dev] [RFC] Improve iteration of estimating divisions

Finkel, Hal J. via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 6 13:04:34 PDT 2019


On 8/6/19 12:20 AM, 邱 超凡 via llvm-dev wrote:
> Hi there, I notice that our current implementation of fast division transformation (turn `a / b` into `a * (1/b)`) is worse in precision compared with GCC.  Like this case in ppc64le:
>
>          float fdiv(unsigned int a, unsigned int b) {
>                  return (float)a / (float)b;
>          }
>
> Result of Clang -Ofast is 41A00001 (in Hex), while GCC produces 41A00000 which is the same as no optimizations opened.
>
> Currently, DAGCombiner uses `BuildReciprocalEstimate` to calculate the reciprocal (`1/b`) first and multiply it with `a`.  But if we put the operand `a` into iterations in the estimate function, the result would be better.
>
> Patching such a change may break several existing test cases in different platforms since it’s target-independent code.  So any suggestions are welcome.  Thanks.


Test cases can be changed if the result is universally better, and 
alternatively, we can introduce a way for the target to control the 
behavior (e.g., how we choose between buildSqrtNROneConst and 
buildSqrtNRTwoConst). What's the effect on performance?

  -Hal


>
> Regards,
> Qiu Chaofan
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-dev mailing list