Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#7507 closed bug (fixed)

loop fusion not working for Int32, Int64 as it does for Int ?

Reported by: j.waldmann Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case: perf/should_run/T7507
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

here is some code that works for Int, but gives me Stack Overflow for arguments 18 .. 24, and Out of memory for 25. (Just change the
type annotation in main.)

import Data.Int
import System.Environment

bitcount x = if x > 0 
    then let (d,m) = divMod x 2 in  bitcount d + m
    else 0

main = do
    [ arg ]  <- getArgs
    print $ sum  $ map bitcount
          [ 0 :: Int64 .. 2^read arg - 1 ]

https://github.com/haskell-distributed/distributed-process/issues/91#issuecomment-11468092

Not sure whether it's a bug, but it's annoying. There is no conceptual difference between these numerical types, so I shouldn't have to rewrite my program when switching between them.

Change History (3)

comment:1 Changed 2 years ago by j.waldmann

perhaps this is helpful: I was running ghc with -ddump-rule-firings, and the differences are:

diff rules.Int rules.Int64

4d3
< Rule fired: SPEC Data.List.sum
13a13,15
> Rule fired: Class op fromInteger
> Rule fired: Class op fromInteger
> Rule fired: Class op fromInteger
67a70,72
> Rule fired: integerToInt
> Rule fired: integerToInt
> Rule fired: integerToInt
69,70c74
<     SPEC GHC.Real.^ [GHC.Types.Int, GHC.Integer.Type.Integer]
< Rule fired: fold/build
---
>     SPEC GHC.Real.^ [GHC.Int.Int64, GHC.Integer.Type.Integer]
73,75c77
< Rule fired: >#
< Rule fired: <#
< Rule fired: >#
---
> Rule fired: mapList

comment:2 Changed 2 years ago by simonpj

  • difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to perf/should_run/T7507

See also #4321. Fixed by this patch to base:

commit 06e36c63fce9aef5d3d8d9efeab14263333d48bf
Author: Simon Peyton Jones <[email protected]>
Date:   Mon Dec 24 14:44:31 2012 +0000

    Make sum and product INLINABLE
    
    This was causing the bad behaviour in Trac #7507,
    because 'sum' wasn't getting specialised to Int64.
    
    It also deals with Trac #4321, which had the same cause.
    
    This has a big effect on some nofib programs too:
    
    --------------------------------------------------------------------------------
            Program           Allocs   Runtime   Elapsed  TotalMem
    ------------------------------------------------------------------------
         bernouilli            -2.6%     -2.0%     -2.0%     +0.0%
               fft2           -23.8%      0.09      0.09    -16.7%
              fluid            -4.4%      0.01      0.01     +0.0%
             hidden            -3.2%     +2.1%     +1.8%     +0.0%
          integrate           -38.0%    -47.7%    -47.7%     -1.0%
               x2n1           -30.2%      0.01      0.01    -50.0%
    ------------------------------------------------------------------------
                Min           -38.0%    -47.7%    -47.7%    -50.0%
                Max            +0.4%    +11.2%    +11.8%     +6.9%
     Geometric Mean            -1.3%     +0.2%     +0.2%     -0.8%

 Data/List.hs |    5 +++++
 1 file changed, 5 insertions(+)

comment:3 Changed 2 years ago by simonmar

How does it affect code size?

Note: See TracTickets for help on using tickets.