[GHC] #11677: Dramatic de-optimization with "-O", "-O1", "-O2" options

GHC ghc-devs at haskell.org
Thu Mar 10 22:57:13 UTC 2016


#11677: Dramatic de-optimization with "-O", "-O1", "-O2" options
-------------------------------------+-------------------------------------
        Reporter:  malphunction      |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             Keywords:  optimization
                                     |  deoptimization
Operating System:  Linux             |         Architecture:  x86_64
 Type of failure:  Runtime           |  (amd64)
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 This is another in the long chain of tickets involving the "state hack"
 and `replicateM`. See #1168 for a list and #9388 for ideas.

 Sadly `-fno-state-hack` doesn't make any difference.  Reason: the `fmap`
 for `IO` is begin called, and looks like
 {{{
 fmapIO = \f a s. case a s of
                    (r, s') -> (f r, s')
 }}}
 So if we have `replicateM (fmapIO (g (expensive x)) getLine)`, we'll
 inline `fmapIO` to
 {{{
 replicateM (let f = g (expensive x)
             in \s. case getLine s of
                      (r, s') -> (f r, s'))
 }}}
 Now if that `\s` which come from `fmapIO` is treated as one-shot, we'll
 inline `g (expensive x)` inside; disaster.

 The `-fno-state-hack` doesn't make any difference because Joachim arranged
 to persist one-shot-ness in interface files, so what matters is the
 setting in `GHC.Base` where `fmapIO` was defined.

 Anyway that's the reason, and we have many examples of it.  The right
 solution is sketched in #9388 but it needs someone to pick up the cudgels.

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


More information about the ghc-tickets mailing list