#5152: GHC generates poor code for large 64-bit literals
---------------------------------+------------------------------------------
    Reporter:  bos               |        Owner:  igloo                  
        Type:  bug               |       Status:  new                    
    Priority:  normal            |    Milestone:                         
   Component:  Compiler          |      Version:  7.0.3                  
    Keywords:                    |     Testcase:                         
   Blockedby:                    |   Difficulty:                         
          Os:  Unknown/Multiple  |     Blocking:                         
Architecture:  Unknown/Multiple  |      Failure:  Runtime performance bug
---------------------------------+------------------------------------------
Changes (by simonpj):

  * owner:  => igloo


Comment:

 I see.  The reason for this is that, in general
  * An integer literal `k` means `fromInteger (k::Integer)`
  * If the `Integer` `k` is big, then then it is represented using a chain
 of multiplies and adds; see `MkCore.mkIntegerExpr`.

 So the your 64-bit word constant is getting represented as
 {{{
 integerToWord64 (plusInteger (S# blah1) (S# blah2))
 }}}
 where `blah, blah2 :: Int#` are (small) int literals in Core.

 GHC already has a mechanism to short-cut this stuff when we know all the
 types. The short cut is embodied in `TcHsSyn.shortCutLit`:
 {{{
 shortCutLit :: OverLitVal -> TcType -> Maybe (HsExpr TcId)
 shortCutLit (HsIntegral i) ty
   | isIntTy ty && inIntRange i   = Just (HsLit (HsInt i))
   | isWordTy ty && inWordRange i = Just (mkLit wordDataCon (HsWordPrim i))
 ...etc...
 }}}
 All we need to do is to add cases for `Word64` ... and for all the other
 fixed-width types.

 Ian would you like to do that?

 Simon

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to