Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6121 closed bug (fixed)

Very poor constant folding

Reported by: augustss Owned by: igloo
Priority: high Milestone: 7.6.1
Component: Compiler Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case: lib/integer/integerConstantFolding
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

GHC seems to lack constant folding for encodeFloat/decodeFloat. For many examples, compile the numeric-limits package on hackage, or just this snippet:

epsilon :: Double
epsilon = r
  where r = 1 - encodeFloat (m-1) e
        (m, e) = decodeFloat (1 `asTypeOf` r)

This has a very simple value, but GHC refuses to compute it at compile time. This in turn inhibits other constant folding that should be going on.

Change History (4)

comment:1 Changed 7 years ago by simonpj

difficulty: Unknown

Would you like to propose the specific constant-folding rules that you believe should be implemented?

comment:2 Changed 7 years ago by simonmar

Milestone: 7.6.1
Owner: set to igloo
Priority: normalhigh

It looks like we should have constant folding for:

encodeFloatInteger :: Integer -> Int# -> Float#
encodeDoubleInteger :: Integer -> Int# -> Double#

decodeDoubleInteger :: Double# -> (# Integer, Int# #)

doubleFromInteger :: Integer -> Double#
floatFromInteger :: Integer -> Float#

which should be easy enough with the new Integer literals. Ian, could you look into that?

comment:3 Changed 7 years ago by igloo

Resolution: fixed
Status: newclosed

This now works in HEAD.

comment:4 Changed 7 years ago by simonpj

Test Case: lib/integer/integerConstantFolding
Note: See TracTickets for help on using tickets.