summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/should_run/simplrun003.hs
blob: 45aa73578ed3c165e0c391980bd5a14f1e975bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{-# LANGUAGE UnboxedTuples #-}

-- O2 to get CSE

module Main where

f :: Int -> (# Int, Int #)
f 0 = (# 1,2 #)
f n = f (n-1)

{-# NOINLINE g #-}
g x = case f x of 
	(# a,b #) -> if a>0 
		     then f x 	-- CSE opportunity
		     else (# b,a #)

-- GHC 6.2 wrongly optimised g to:
--	case f x of t 
--	  (# a,b #) -> if a>0 then
--			  t	-- WRONG
--			else (# b,a #)

main = case g 2 of (# a,b #) -> print a