Change representation of Floating-point literals

Tickets: #8364 (closed) #9811 (closed) #18897 (closed) #21227 (closed) #26919

This is a revival of MR !7800 (closed), rebased and with additional fixes.

This MR changes the representation of floating point literals throughough the compiler, in particular in Core and Cmm. The Rational type is deficient for this purpose, dealing poorly with NaN, +/-Infinity, and negative zero. Instead, the new module GHC.Types.Literal.Floating uses the host Float/Double type to represent NaNs, infinities and negative zero. It also contains a Rational constructor, for the benefit of -fexcess-precision.

Other changes:

  • Remove Note [negative zero] and related code This also removes the restrictions on constant-folding of division by zero, and should make any problems with NaN/Infinity more obvious.

  • Use -0.0 as the additive identity for Core constant folding rules for floating-point addition, fixing #21227 (closed).

  • Manual worker-wrapper for GHC.Float.rationalToDouble. This is intended to prevent the compiler's WW on this function from interfering with constant-folding. This change means that we now avoid allocating a box for the result of a realToFrac call in T10359.

  • Combine floatDecodeOp and doubleDecodeOp. This change also fixes a bug in doubleDecodeOp wherein it would incorrectly produce an Int# instead of an Int64# literal for the mantissa component with 64-bit targets.

  • Use Float/Double for assembly immediates, and update the X86 and PowerPC backends to properly handle special values such as NaN and infinity.

  • Allow rational_to to handle zero denominators, fixing a TODO in GHC.Core.Opt.ConstantFold.

Edited by sheaf

Merge request reports

Loading