Ticket #4101 (new bug)

Opened 3 years ago

Last modified 4 weeks ago

Primitive constant unfolding

Reported by: malosh Owned by:
Priority: low Milestone: 7.6.2
Component: Compiler Version: 6.12.2
Keywords: Cc: alexey.skladnoy@…, bjornbm, anton.nik@…, carter.schonwald@…
Operating System: Unknown/Multiple Architecture: x86
Type of failure: Runtime performance bug Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

Examining the core generated by ghc with -O2 on a numerical code, I saw things like :

case GHC.Prim.<## x_aB9 (GHC.Prim.**## 2.0 -1021.0) of _  {...

This code being executed each time my code performs an addition ! GHC does not seem to unfold the constants right with at least **##. By the way, it should definitely be possible to specify a Double# constant in hexadecimal.

Change History

  Changed 3 years ago by igloo

  • description modified (diff)

  Changed 3 years ago by igloo

  • milestone set to 6.16.1

Test case:

module Q where

foo x = x < (2 ** (-1021) :: Double)

follow-up: ↓ 4   Changed 3 years ago by simonmar

There are quite a few floating-point operations that we don't constant fold currently - all the trig functions, **, log, sqrt, and so on. One trickiness with implementing this is that the internal representation for Float/Double in the compiler is Rational, and that doesn't support these operations. We'd have to cast down to Double to do the operation and back to Rational again, and only do it when not cross-compiling.

in reply to: ↑ 3   Changed 3 years ago by Khudyakov

Replying to simonmar:

There is one more problem. Floats and Doubles have special values +∞, -∞ and NaN. They could be represented as Rational (1%0, -1%0, 0%0) but Data.Ratio doesn't allow to construct such values.

  Changed 3 years ago by Khudyakov

  • cc alexey.skladnoy@… added

  Changed 2 years ago by bjornbm

  • cc bjornbm added

  Changed 2 years ago by lelf

  • cc anton.nik@… added

  Changed 15 months ago by igloo

  • priority changed from normal to low
  • milestone changed from 7.4.1 to 7.6.1

  Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

  Changed 4 weeks ago by carter

  • cc carter.schonwald@… added
Note: See TracTickets for help on using tickets.