[llvm-commits] [PATCH, PowerPC] Fix int-to-fp double-rounding errors

Hal Finkel hfinkel at anl.gov
Wed Oct 17 07:57:45 PDT 2012



----- Original Message -----
> From: "Ulrich Weigand" <Ulrich.Weigand at de.ibm.com>
> To: llvm-commits at cs.uiuc.edu
> Sent: Wednesday, October 17, 2012 8:31:47 AM
> Subject: [llvm-commits] [PATCH, PowerPC] Fix int-to-fp double-rounding errors
> 
> 
> Hello,
> 
> the SingleSource/Regression/C/uint64_to_float test case currently
> fails on
> PowerPC, as it (correctly) detects rounding errors when converting
> from a
> 64-bit integer to a single-precision floating point. The reason for
> this
> are double-rounding effects, since on PowerPC we have to convert to
> an
> intermediate double-precision value first, which gets rounded to the
> final
> single-precision result.
> 
> The appended patch fixes the problem by preparing the 64-bit integer
> so
> that the first conversion step to double-precision will always be
> exact,
> and the final rounding step will result in the correctly-rounded
> single-precision result.  The generated code sequence is equivalent
> to what
> GCC would generate.
> 
> When -enable-unsafe-fp-math is in effect, that extra effort is
> omitted and
> we accept possible rounding errors (just like GCC does as well).
> 
> This fixes the uint64_to_float test case.  (Since there was already a
> test
> case checking for exactly this problem, I didn't think I need to add
> another test ...)   No regression in any other test.
> 
> OK to commit?

Please also include a regression test (in test/CodeGen/PowerPC). In addition, can you please include a more in-depth explanation of the associated math; this currently introduces a bunch of "magic numbers" (2047, etc.) which seem non-obvious.

Thanks again,
Hal

> 
> Bye,
> Ulrich
> 
> (See attached file: diff-llvm-sitofp-doublerounding)
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list