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

Ulrich Weigand Ulrich.Weigand at de.ibm.com
Wed Oct 17 06:31:47 PDT 2012


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?

Bye,
Ulrich

(See attached file: diff-llvm-sitofp-doublerounding)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff-llvm-sitofp-doublerounding
Type: application/octet-stream
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121017/54f4ee3a/attachment.obj>


More information about the llvm-commits mailing list