Commit ea100f57 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Add a SpecConstr test

parent 30c8fb48
......@@ -37,4 +37,4 @@ The reason was this:
Being an unboxed value, we were treating the argument context of x
as intersting, and hence inlining x in the arg of I#. But then we just
float it out again, giving an infinite loop.
-}
\ No newline at end of file
-}
{-# 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment