[GHC] #5731: Bad code for Double literals

GHC cvs-ghc at haskell.org
Fri Dec 30 15:33:10 CET 2011


#5731: Bad code for Double literals
-------------------------------------+--------------------------------------
 Reporter:  rl                       |          Owner:                  
     Type:  bug                      |         Status:  new             
 Priority:  normal                   |      Component:  Compiler        
  Version:  7.3                      |       Keywords:                  
       Os:  Unknown/Multiple         |   Architecture:  Unknown/Multiple
  Failure:  Runtime performance bug  |       Testcase:                  
Blockedby:                           |       Blocking:                  
  Related:                           |  
-------------------------------------+--------------------------------------

Comment(by rl):

 Poking around further, it turns out that inlining `doubleFromInteger`
 doesn't help at all here. This is because `Integer` literals are now
 represented by `LitInteger` rather than the `S#` and `J#` constructors.
 The relevant comment in `Literal.lhs` says:

 {{{
 An Integer literal is represented using, well, an Integer, to make it
 easier to write RULEs for them.

  [...]

  * They only get converted into real Core,
       mkInteger [c1, c2, .., cn]
    during the CorePrep phase.
 }}}

 This means that for literals, we won't see `S#` until `CorePrep` when it's
 too late for anything interesting to happen. So the quickest solution is
 probably to add built-in rules for all conversion functions in `Type.lhs`
 to `builtinIntegerRules` in `PrelRules.lhs`. At the moment, there are only
 rules for `integerToWord` and `integerToInt`. It seems a pity to me that
 these rules can't be implemented in the library, though.

 BTW, `integer-gmp` contains two rules which, I believe, are dead:

 {{{
 {-# RULES "integerToInt" forall i. integerToInt (S# i) = i #-}
 }}}

 {{{
 {-# RULES "gcdInteger/Int" forall a b.
             gcdInteger (S# a) (S# b) = S# (gcdInt a b)
   #-}
 }}}

 I believe neither of these can ever match because the various `NOINLINE`
 pragmas mean that the `S#` constructor won't be exposed to the simplifier.

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



More information about the Glasgow-haskell-bugs mailing list