[GHC] #14827: Recognize when inlining would create a join point

GHC ghc-devs at haskell.org
Thu Aug 2 10:39:47 UTC 2018


#14827: Recognize when inlining would create a join point
-------------------------------------+-------------------------------------
        Reporter:  ersetzen          |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:  JoinPoints
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:                    |
-------------------------------------+-------------------------------------

Comment (by ersetzen):

 Posting into this issue feels somewhat like necromancy but I found a
 similar issue and the cause is actually quite simple:


 {{{
 main :: IO ()
 main = print foo
 {-# INLINE[1] foo #-}
 foo :: Int
 foo = bar 3
 {-# INLINE[~1] bar #-}
 bar :: Int -> Int
 bar i = i + 1
 }}}

 We inline bar into foo but not into the unfolding of foo:


 {{{
 -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
 foo [InlPrag=INLINE[1] (sat-args=0)] :: Int
 [LclId,
  Unf=Unf{Src=InlineStable, TopLvl=True, Value=False, ConLike=False,
          WorkFree=False, Expandable=False,
          Guidance=ALWAYS_IF(arity=0,unsat_ok=False,boring_ok=False)
          Tmpl= bar (GHC.Types.I# 3#)}]
 foo = GHC.Types.I# 4#
 }}}

 Laterwe inline the unfolding of foo which still references bar - but the
 phase for inling bar is over.


 {{{
  main _s26f=
    ...
     case bar (GHC.Types.I# 3#) of { GHC.Types.I# ww3_a26u ->
    ...
 }}}

 So bar never gets inlined at the use side even though everything along the
 way had inline pragmas. There isn't really a single decision that was
 wrong but the result is very unintuitive and can break fusion. A compiler
 warning for this type of phase collision might be worthwhile if it is
 easily doable?

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


More information about the ghc-tickets mailing list