id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
7292	Optimization works for Word but not Word32 or Word64	zuserm	igloo	"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
}}}
 "	bug	closed	high	7.8.1	Compiler	7.6.1	fixed			Unknown/Multiple	Unknown/Multiple	Runtime performance bug	Unknown				
