[GHC] #932: Improve inlining

GHC trac at galois.com
Wed Oct 11 05:10:13 EDT 2006


#932: Improve inlining
-------------------------+--------------------------------------------------
    Reporter:  simonpj   |        Owner:         
        Type:  task      |       Status:  new    
    Priority:  normal    |    Milestone:         
   Component:  Compiler  |      Version:  6.4.2  
    Severity:  normal    |     Keywords:         
          Os:  Unknown   |   Difficulty:  Unknown
Architecture:  Unknown   |  
-------------------------+--------------------------------------------------
Currently the contruct
 {{{
   case (x# ># 0#) of ...
 }}}
 attracts no argument discount for x#, which is silly.

 The comment in CoreUnfold says:
 {{{
           PrimOpId op  -> primOpSize op (valArgCount args)
                           -- foldr addSize (primOpSize op) (map
 arg_discount args)
                           -- At one time I tried giving an arg-discount if
 a primop
                           -- is applied to one of the function's
 arguments, but it's
                           -- not good.  At the moment, any unlifted-type
 arg gets a
                           -- 'True' for 'yes I'm evald', so we collect the
 discount even
                           -- if we know nothing about it.  And just having
 it in a primop
                           -- doesn't help at all if we don't know
 something more.
 }}}
 But the right thing to do seems to be to fix interestingArg in SimplUtils
 so that it only thinks a primitive-typed thing is interesting if it knows
 its value (or some structure).

 Here's the program that triggered this thought:
 {{{
 import GHC.Word
 import GHC.Base
 import GHC.Prim

 a `shiftRLT` b | b >=# 32# = int2Word# 0#
                 | otherwise = a `uncheckedShiftRL#` b

 (W32# x#) `shift` (I# i#) =
 {- we do an actual case analysis on i# to try to give us a discount -}
    case i# of
     {- For some bizzare reason removing the `shiftRLT` 0# makes the
        inlining fail again -}
     0# -> W32# (x# `shiftRLT` 0#)
     _ ->
          if i# >=# 0# then W32# (narrow32Word# (x# `shiftL#` i#))
          else W32# (x# `shiftRLT` negateInt# i#)

 x `shiftR` y = x `shift` (-y)

 shift7 x = x `shiftR` 7
 }}}
 roconnor at theorem.ca initiated the thread

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/932>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list