[GHC] #11372: Loopification does not trigger for IO even if it could

GHC ghc-devs at haskell.org
Thu Jan 7 15:48:12 UTC 2016


#11372: Loopification does not trigger for IO even if it could
-------------------------------------+-------------------------------------
        Reporter:  jscholl           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
  (CodeGen)                          |             Keywords:  cmm,
      Resolution:                    |  loopification, code generation
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by simonpj:

Old description:

> The loopification optimization, as I understand it, allows a self-
> recursive function to jump to a local label instead of the beginning of
> the function, thus skipping a potential stack check. However, I only
> observe it triggering for pure functions while IO functions do not get
> that benefit, even when it would be possible.
>
> I discovered this in #8793 after looking into an unexpected speedup by
> removing the IO context from an otherwise pure loop and while such a loop
> can simply be changed to a pure version (the {{{IOLoop}}} examples),
> other functions can not, but the optimization could be applied to them
> (see {{{MapM.hs}}}).
>
> I tried to benchmark the differences between a naive loop in IO and some
> horrible {{{inlinePerformIO}}} hacks to get the loopification to fire and
> the "optimized" version performs 3-5% faster on my machine.

New description:

 The loopification optimization, as I understand it, allows a self-
 recursive function to jump to a local label instead of the beginning of
 the function, thus skipping a potential stack check. However, I only
 observe it triggering for pure functions while IO functions do not get
 that benefit, even when it would be possible.

 I discovered this in #8793 after looking into an unexpected speedup by
 removing the IO context from an otherwise pure loop and while such a loop
 can simply be changed to a pure version (the {{{IOLoop}}} examples), other
 functions can not, but the optimization could be applied to them (see
 {{{MapM.hs}}}).

 I tried to benchmark the differences between a naive loop in IO and some
 horrible {{{inlinePerformIO}}} hacks to get the loopification to fire and
 the "optimized" version performs 3-5% faster on my machine.

 See [wiki:Commentary/Compiler/Loopification] for details

--

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


More information about the ghc-tickets mailing list