summaryrefslogtreecommitdiff
path: root/testsuite/tests/eyeball/spec-constr1.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/eyeball/spec-constr1.hs')
-rw-r--r--testsuite/tests/eyeball/spec-constr1.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/testsuite/tests/eyeball/spec-constr1.hs b/testsuite/tests/eyeball/spec-constr1.hs
new file mode 100644
index 0000000000..a14442035b
--- /dev/null
+++ b/testsuite/tests/eyeball/spec-constr1.hs
@@ -0,0 +1,36 @@
+{-# OPTIONS_GHC -O2 -ddump-simpl #-}
+module Roman where
+
+{- From: Roman Leshchinskiy [mailto:rl@cse.unsw.edu.au]
+ Sent: 07 February 2008 03:34
+ Subject: Quadratic SpecConstr
+
+Here is a program which makes SpecConstr generate a quadratic number of
+iterations:
+-}
+
+
+bar :: Int -> Int -> Int
+bar m n = foo n (n,n) (n,n) (n,n) (n,n)
+ where
+ foo :: Int -> (Int,Int) -> (Int,Int) -> (Int,Int) -> (Int,Int) -> Int
+ foo n p q r s
+ | n == 0 = m
+ | n > 3000 = case p of { (p1,p2) -> foo (n-1) (p2,p1) q r s }
+ | n > 2000 = case q of { (q1,q2) -> foo (n-1) p (q2,q1) r s }
+ | n > 1000 = case r of { (r1,r2) -> foo (n-1) p q (r2,r1) s }
+ | otherwise = case s of { (s1,s2) -> foo (n-1) p q r (s2,s1) }
+
+{- For this particular function, I get 14 specialisations, one for each
+ possible combination of arguments.
+
+ However, since we can see all the call sites outside the loop, we could
+ use that to 'seed' the specialisation, and get just one specialisation.
+-}
+
+
+-- Eyeball guidance:
+-- There should be just one specialisation for foo
+-- Indeed, the original function should disappear,
+-- since it isn't used
+