[GHC] #1600: Optimisation: CPR the results of IO
GHC
ghc-devs at haskell.org
Mon Nov 18 15:55:29 UTC 2013
#1600: Optimisation: CPR the results of IO
-------------------------------------+-------------------------------------
Reporter: simonmar | Owner:
Type: task | Status: new
Priority: lowest | Milestone: 7.6.2
Component: Compiler | Version: 6.6.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: Runtime | Difficulty: Moderate (less
performance bug | than a day)
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+-------------------------------------
Comment (by nomeata):
Maybe this code is a slightly better example for something where we want
to avoid the allocations:
{{{
facIO :: Int -> IO Int
facIO n = if n < 2 then return 1 else do n' <- facIO (n-1); return $! n*n'
}}}
The worker Core currently (7.6.3) looks as
{{{
FactIO.$wa [Occ=LoopBreaker]
:: GHC.Prim.Int#
-> GHC.Prim.State# GHC.Prim.RealWorld
-> (# GHC.Prim.State# GHC.Prim.RealWorld, GHC.Types.Int #)
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType LL]
FactIO.$wa =
\ (ww_snv :: GHC.Prim.Int#)
(w_snx :: GHC.Prim.State# GHC.Prim.RealWorld) ->
case GHC.Prim.<# ww_snv 2 of _ {
GHC.Types.False ->
case FactIO.$wa (GHC.Prim.-# ww_snv 1) w_snx
of _ { (# ipv_amL, ipv1_amM #) ->
case ipv1_amM of _ { GHC.Types.I# y_amd ->
(# ipv_amL, GHC.Types.I# (GHC.Prim.*# ww_snv y_amd) #)
}
};
GHC.Types.True -> (# w_snx, lvl_roe #)
}
}}}
and there is a very obvious packing/unpacking going on.
A nested CPR should probably first be able to fix this case; and then
venture into detecting cheap-and-total-code (as required for the variant
without `$!`) beyond constructors.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/1600#comment:18>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list