[GHC] #8662: GHC does not inline cheap inner loop when used in two places
GHC
ghc-devs at haskell.org
Mon Jan 13 09:45:08 UTC 2014
#8662: GHC does not inline cheap inner loop when used in two places
--------------------------------------------+------------------------------
Reporter: nh2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime performance bug | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets:
--------------------------------------------+------------------------------
Comment (by simonpj):
GHC decides when to inline like this:
* It computes the "size" of the function
* At a call site, it takes the size of the function, subtracts a call-
site "discount", and if the result is less than the "unfolding threshold"
it does the inlining.
* The discount is increased if both (a) an actual argument has some
structure (eg is a constructor application) and (b) that argument is
scrutinised by a case expression in the function body.
* There is also a "result discount" if (a) the function call is consumed
by a `case`, and (b) the function body returns a constructor application
All this is computed in module `CoreUnfold`, so it is nicely separated
from the rest of the compiler.
Do by all means have a go at changing the computation of size or discount.
Then measure (a) the change in code size and complication time vs (b) the
change in allocation and/or run-time. If you can reduce (b) without
increasing (a) you are winning!
But it's easy to mess up. I have spent many happy hours fiddling with
these heuristics.
Simon
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8662#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list