#7292: Optimization works for Word but now Word32 or Word64
-------------------------------------+--------------------------------------
Reporter: zuserm | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 7.6.1 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: Runtime performance bug | Testcase:
Blockedby: | Blocking:
Related: |
-------------------------------------+--------------------------------------
GHC 7.6.1 fails to properly optimize some code when explicitly specifying
word size, that optimizes properly for Word.
I have also tested this in 7.4.2 and it works properly.
An example program:
{{{
import Criterion.Main
import Control.Monad.Writer
import Data.Bits
import Data.List
import Data.Word
bitByBitCopy :: Word -> Word
bitByBitCopy w = foldl' f 0 [0 .. bitSize w - 1]
where f acc n = if w `testBit` n then acc `setBit` n else acc
bitByBitCopy32 :: Word32 -> Word32
bitByBitCopy32 w = foldl' f 0 [0 .. bitSize w - 1]
where f acc n = if w `testBit` n then acc `setBit` n else acc
bitByBitCopy64 :: Word64 -> Word64
bitByBitCopy64 w = foldl' f 0 [0 .. bitSize w - 1]
where f acc n = if w `testBit` n then acc `setBit` n else acc
-- Bench
wbench :: Benchmarkable b => String -> b -> Writer [Benchmark] ()
wbench s b = tell [bench s b]
main = defaultMain . execWriter $ do
wbench "Word" $ nf bitByBitCopy 0
when (bitSize (0::Word) == 32) $
wbench "Word32" $ nf bitByBitCopy32 0
when (bitSize (0::Word) == 64) $
wbench "Word64" $ nf bitByBitCopy64 0
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7292>
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