[GHC] #1600: Optimisation: CPR the results of IO

GHC ghc-devs at haskell.org
Mon Oct 24 07:25:59 UTC 2016


#1600: Optimisation: CPR the results of IO
-------------------------------------+-------------------------------------
        Reporter:  simonmar          |                Owner:
            Type:  task              |               Status:  new
        Priority:  lowest            |            Milestone:
       Component:  Compiler          |              Version:  6.6.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #8598             |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by akio):

 Regarding `wave4main`, the main problem seems to be destruction of a join
 point.

 The program contains an expression that looks like this:

 {{{
 #!haskell
 runRW#
   (\ s ->
       letrec
         go s1 =
           let ...
           in (# s2, Array a b c #)
       in go s)
 }}}

 After a nested CPR transformation, it becomes:

 {{{#!haskell
 runRW#
   (\ s ->
       letrec
         $wgo s1 =
           let ...
           in (# s2, a, b, c #)
       in case $wgo s of
         (# s3, a', b', c' #) -> (# s3, Array a' b' c' #))
 }}}

 destroying the join-point property of `go`. This is basically the same as
 what @nomeata found 2 years ago.

 I see two ways to move forward:

 1. Wait for SequentCore to be implemented.
 2. Have special cases for `runRW#` in the CPR analyzer and in the
 simplifier, as discussed in
 https://ghc.haskell.org/trac/ghc/ticket/10678#comment:10

 I'm mildly interested in doing (2), but I don't think I fully understand
 the idea. In particular, the above comment mentions an example expression
 `case (runRW e) of BN# farr -> farr` that the simplifier would be able to
 transform. However, since `runRW#` returns an unboxed pair rather than a
 single boxed value, it seems that it would have to spot a much more
 complicated pattern to accomplish this transformation.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/1600#comment:56>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list