[GHC] #9279: Optimisation bug
GHC
ghc-devs at haskell.org
Mon Jul 21 07:49:24 UTC 2014
#9279: Optimisation bug
-------------------------------------+-------------------------------------
Reporter: simonmar | Owner: simonpj
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Differential Revisions: | Operating System: Unknown/Multiple
Architecture: | Type of failure: Runtime
Unknown/Multiple | performance bug
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
Changes (by simonpj):
* cc: nicolas.frisby@… (added)
Comment:
OK I can see what is going on; it is more or less as you say. We have
something like
{{{
let worker = \x. BIG in
let {-# INLINE wrapper #-}
wrapper = \y. ...worker.... in
...map wrapper xs....
}}}
(Technically, the wrapper has a "stable inlining" which I have not written
above, which is a copy of the body of the wrapper.)
Now, GHC is (in general rightly) unhappy about inlining `worker` in
`wrapper`'s rhs, even though there is currently just one textual
occurrence of `worker`, because there might (now or in the future) be many
occurrences of `wrapper`, and the INLINE pragma means we'll make a copy of
`wrapper`'s rhs at each occurrence.
However, in this case, `wrapper` is not inlined because it's not applied
to anything, so nothing is gained. But something is lost.
I can see various possible solutions:
* Lambda-lift local function definitions, late in the pipeline. This is
something Nicolas Frisby was working on, with promising results, but he
sadly he never completed the work. I'm copying him on this ticket.
* Towards the end of the pipeline, forget that wrappers are special by
discarding their INLINE pragmas. This is a bit delicate; I think you
would ''not'' want to do this for things marked INLINE by the programmer.
And certainly not for top-level things either (else you'd defeat the
entire w/w idea).
I wonder how often this happens. Might not be hard to find out; how often
does a local function definition with an INLINE pragma appear in the final
Core?
Simon
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9279#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list