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

Neil Nelson via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 6 09:54:27 PDT 2019

Qiu Chaofan,

Yes, clearly, two floating point operations instead of one will increase the degree of resulting error already present in the necessarily or commonly fixed length number representations.

The reason for the two operations appears to be that there may be machine instructions for a reciprocal that when combined with a multiplication obtains fewer machine cycles than a division.

The trade-off is then precision vs. speed. There may be additional computations along this line and perhaps an additional compile flag, along with code changes, would allow that choice.

Regards, Neil Nelson

On 8/5/19 11:20 PM, 邱 超凡 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.
> Regards,
> Qiu Chaofan
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190806/35fc3eb0/attachment.html>

More information about the llvm-dev mailing list