Richards optCoercion improvement made test cases fail the nice way
[ghc.git] / testsuite / tests / eyeball / dead1.hs
1 {-# OPTIONS -fglasgow-exts -O -ddump-stranal #-}
2
3 module Foo(foo) where
4
5 foo :: Int -> Int
6 foo n = baz (n+1) (bar1 n)
7
8 {-# NOINLINE bar1 #-}
9 bar1 n = 1 + bar n
10
11 bar :: Int -> Int
12 {-# NOINLINE bar #-}
13 {-# RULES
14 "bar/foo" forall n. bar (foo n) = n
15 #-}
16 bar n = n-1
17
18 baz :: Int -> Int -> Int
19 {-# INLINE [0] baz #-}
20 baz m n = m
21
22
23 {- Ronam writes (Feb08)
24
25 Note that bar becomes dead as soon as baz gets inlined. But strangely,
26 the simplifier only deletes it after full laziness and CSE. That is, it
27 is not deleted in the phase in which baz gets inlined. In fact, it is
28 still there after w/w and the subsequent simplifier run. It gets deleted
29 immediately if I comment out the rule.
30
31 I stumbled over this when I removed one simplifier run after SpecConstr
32 (at the moment, it runs twice at the end but I don't think that should
33 be necessary). With this change, the original version of a specialised
34 loop (the one with the rules) is not longer deleted even if it isn't
35 used any more. I'll reenable the second simplifier run for now but
36 should this really be necessary?
37
38 No, it should not be necessary. A refactoring in OccurAnal makes
39 this work right. Look at the simplifier output just before strictness
40 analysis; there should be a binding for 'foo', but for nothing else.
41
42 -}