summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T8763.hs
blob: 90c4436ce9aab28c4179b02598d9c6b0d3761058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- | The fusion helper for @enumFromThenTo \@Int@ had multiple
-- occurences of @c@, which made the simplifier refuse to inline it.
-- The new implementation for @efdtInt{Up,Dn}FB@ only have a single
-- occurence of @c@ which the simplifier inlines unconditionally.
module Main  (main) where

import Control.Monad (when, forM_)
import GHC.ST

nop :: Monad m => a -> m ()
nop _ = return ()
{-# NOINLINE nop #-}

-- This is the baseline, using @enumFromTo@ which already had only a
-- single occurence of @c@.
f :: Int -> ST s ()
f n =
    do
      forM_ [2..n] $ \p -> do
        let isPrime = p == (p - 1)
        when isPrime $
          forM_ [p + p, p + p + p .. n] $ \k ->  do
            nop k
{-# NOINLINE f #-}

g :: Int -> ST s ()
g n =
    do
      forM_ [2,3..n] $ \p -> do
        -- This do block should be too big to get inlined multiple times.
        -- Pad with @nop@s as necessary if this doesn't reproduce anymore.
        let isPrime = p == (p - 1)
        when isPrime $
          forM_ [p + p, p + p + p .. n] $ \k ->  do
            nop k
{-# NOINLINE g #-}

main :: IO ()
main = do
  -- runST (f 40000000) `seq` return ()
  runST (g 40000000) `seq` return ()