[GHC] #9349: excessive inlining with -fpre-inlining

GHC ghc-devs at haskell.org
Thu Jul 24 12:12:42 UTC 2014


#9349: excessive inlining with -fpre-inlining
-------------------------------------+-------------------------------------
              Reporter:  rwbarton    |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:
             Component:  Compiler    |          Version:  7.8.3
            Resolution:              |         Keywords:
      Operating System:              |     Architecture:  Unknown/Multiple
  Unknown/Multiple                   |       Difficulty:  Unknown
       Type of failure:  Runtime     |       Blocked By:
  performance bug                    |  Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by klao):

 Here's a simplified example for this bug:

 {{{
 import Control.Monad
 import Control.Concurrent.MVar

 expensive :: Int -> Int -> Int
 expensive n0 a = go n0 a
   where
     go 0 x = x
     go n x = go (n-1) ((x * 37 + 1973) `rem` 177)

 main :: IO ()
 main = do
   mv <- newMVar (10 :: Int)
   let ex = expensive 100000 3
   replicateM_ 30000 $ do
     x <- readMVar mv
     print $ x + ex
 }}}

 You could probably simplify it further. The important thing is that `ex`
 is the result of some expensive computation that incorrectly gets
 evaluated over and over again. And you have to put some "real" IO into the
 `replicateM_` for the bug to kick in (in the original example it was
 reading from the stdin, here I just read an MVar).

 Unlike the original example, here marking `ex` as `NOINLINE` does make the
 issue disappear. (Otherwise it's the same as the original example: nearly
 instantaneous with `-O0` or `-O -fno-pre-inlining`, but takes a looong
 time with `-O`.)

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


More information about the ghc-tickets mailing list