Float unboxed expressions by boxing
[ghc.git] / testsuite / tests / simplCore / should_compile / T12603.hs
1 -- ghc --make Main.hs -O1; ./Main +RTS -s -RTS
2
3 -- The point here is that we want to see a top-level
4 -- definition like
5 --
6 -- lvl_r5ao :: Int
7 -- lvl_r5ao = case GHC.Real.$wf1 2# 8# of v_B2
8 -- { __DEFAULT -> GHC.Types.I# v_B2 }
9 --
10 -- with the constant (2^8) being floated to top level
11
12 {-# LANGUAGE MagicHash #-}
13
14 module Main( main ) where
15
16 import GHC.Exts
17
18 data Attr = Attr !Int --- the bang is essential
19
20 attrFromInt :: Int -> Attr
21 {-# NOINLINE attrFromInt #-}
22 attrFromInt w = Attr (w + (2 ^ (8 :: Int)))
23
24 fgFromInt :: Int -> Int
25 {-# INLINE fgFromInt #-} -- removing this INLINE makes it many times faster
26 -- just like the manually inlined version
27 -- and NOINLINE lands in between
28 fgFromInt w = w + (2 ^ (8 :: Int))
29
30 attrFromIntINLINE :: Int -> Attr
31 {-# NOINLINE attrFromIntINLINE #-}
32 attrFromIntINLINE w = Attr (fgFromInt w)
33
34 seqFrame2 :: [Int] -> IO ()
35 {-# NOINLINE seqFrame2 #-}
36 seqFrame2 l = do
37 -- let crux = attrFromInt
38 -- Total time 2.052s ( 2.072s elapsed)
39 -- but the following version is many times slower:
40 let crux = attrFromIntINLINE
41 -- Total time 7.896s ( 7.929s elapsed)
42 mapM_ (\a -> crux a `seq` return ()) l
43
44 main :: IO ()
45 main = seqFrame2 $ replicate 100000000 0