[GHC] #10012: Cheap-to-compute values aren't pushed into case branches inducing unnecessary register pressure

GHC ghc-devs at haskell.org
Mon May 2 08:40:33 UTC 2016


#10012: Cheap-to-compute values aren't pushed into case branches inducing
unnecessary register pressure
-------------------------------------+-------------------------------------
        Reporter:  bgamari           |                Owner:  bgamari
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.8.4
      Resolution:                    |             Keywords:
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 bgamari):

 Here's a very bare-bones example,
 {{{#!hs
 {-# LANGUAGE BangPatterns #-}
 {-# LANGUAGE RankNTypes #-}
 module TestCase3 where

 data Buffer = Buffer
 data BufferRange = BufferRange Buffer Int
 data BuildSignal a = BufferFull (BuildStep a)
                    | Done a
 type BuildStep a = BufferRange -> IO (BuildSignal a)
 newtype Builder = Builder (forall r. BuildStep r -> BuildStep r)

 write16Bytes :: Int -> Int -> Builder
 write16Bytes a b = Builder $ \cont rng@(BufferRange Buffer rem) ->
     let !fa = f a
         !fb = f b
         -- doWrite :: BufferRange -> IO (BuildSignal r)
         doWrite rng' = writeInt fa >> writeInt fb >> cont rng'
     in if rem < 16
          then return $ BufferFull doWrite
          else doWrite rng
   where
     f x = x + 42


 writeInt :: Int -> IO ()
 writeInt = print
 {-# NOINLINE writeInt #-}
 }}}

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


More information about the ghc-tickets mailing list