a14442035b9ee9c122eebf8daa12b265cac7e4b9
[ghc.git] / testsuite / tests / eyeball / spec-constr1.hs
1 {-# OPTIONS_GHC -O2 -ddump-simpl #-}
2 module Roman where
3
4 {- From: Roman Leshchinskiy [mailto:rl@cse.unsw.edu.au]
5 Sent: 07 February 2008 03:34
6 Subject: Quadratic SpecConstr
7
8 Here is a program which makes SpecConstr generate a quadratic number of
9 iterations:
10 -}
11
12
13 bar :: Int -> Int -> Int
14 bar m n = foo n (n,n) (n,n) (n,n) (n,n)
15 where
16 foo :: Int -> (Int,Int) -> (Int,Int) -> (Int,Int) -> (Int,Int) -> Int
17 foo n p q r s
18 | n == 0 = m
19 | n > 3000 = case p of { (p1,p2) -> foo (n-1) (p2,p1) q r s }
20 | n > 2000 = case q of { (q1,q2) -> foo (n-1) p (q2,q1) r s }
21 | n > 1000 = case r of { (r1,r2) -> foo (n-1) p q (r2,r1) s }
22 | otherwise = case s of { (s1,s2) -> foo (n-1) p q r (s2,s1) }
23
24 {- For this particular function, I get 14 specialisations, one for each
25 possible combination of arguments.
26
27 However, since we can see all the call sites outside the loop, we could
28 use that to 'seed' the specialisation, and get just one specialisation.
29 -}
30
31
32 -- Eyeball guidance:
33 -- There should be just one specialisation for foo
34 -- Indeed, the original function should disappear,
35 -- since it isn't used
36