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.0as 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 arealToFraccall in T10359. -
Combine
floatDecodeOpanddoubleDecodeOp. This change also fixes a bug indoubleDecodeOpwherein it would incorrectly produce anInt#instead of anInt64#literal for the mantissa component with 64-bit targets. -
Use
Float/Doublefor assembly immediates, and update the X86 and PowerPC backends to properly handle special values such as NaN and infinity. -
Allow
rational_toto handle zero denominators, fixing a TODO inGHC.Core.Opt.ConstantFold.