#7286: GHC doesn't optimise away primitive identity conversions ------------------------------------------+--------------------------------- Reporter: rl | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time performance bug | Testcase: Blockedby: | Blocking: Related: | ------------------------------------------+--------------------------------- Here is a small example:
{{{ import Data.Char (ord) import GHC.Base (unsafeChr) import GHC.Word foo :: Word8 -> Word8 foo = fromIntegral . ord . unsafeChr . fromIntegral bar :: Word8 -> Word8 bar = baz . baz where baz = fromIntegral . (fromIntegral :: Word8 -> Word) }}} GHC produces the following code: {{{ foo = \ (x_arR :: Word8) -> case x_arR of _ { W8# x#_avQ -> W8# (narrow8Word# (int2Word# (ord# (chr# (word2Int# x#_avQ))))) } bar = \ (x_arR :: Word8) -> case x_arR of _ { W8# x#_avQ -> W8# (narrow8Word# (narrow8Word# x#_avQ)) } }}} This could be optimised if GHC knew that: * `ord# (chr# x) = x` * `int2Word# (word2Int# x) = x` * `narrow8Word# (narrow8Word# x) = narrow8Word# x` There are a lot of similar rules so I'm not sure if enumerating them all in base is the way to go. I assume the backend(s) will optimise all of this away but this is quite a lot of unnecessary intermediate code. This is taken from vector-bytestring so it actually happens in the wild. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7286> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs