
#8598: IO hack in demand analyzer gets in the way of CPR -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: T8598 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by akio): I have come across an example where adding a new item to the lattice is actually useful: {{{#!hs {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} module Float(fun) where import GHC.Exts import GHC.Integer (decodeDoubleInteger, encodeDoubleInteger) fun :: Double -> Double fun x@(D# x#) | x == 0 = 0 | otherwise = case isDoubleFinite x of I# y# -> case decodeDoubleInteger x# of (# i, j #) -> fun (D# (encodeDoubleInteger i (y# +# j))) foreign import ccall unsafe "isDoubleFinite" isDoubleFinite :: Double -> Int }}} Here `fun` is a tail-recursive function, and I think it can be CPRed just fine. However the current GHC fails to give `fun` a CPR property because it removes too much information in `deferAfterIO`. Specifically: 1. In the first iteration of the fixpoint calculation, the recursive to call to `fun` gets the CPR result of `Diverges`. 2. However, the case expression that scrutinizes `isDoubleFinite x` causes a call to `deferAfterIO`, which turns the CPR result to `Dunno NoCPR`. 3. This in turn means the whole function doesn't get any useful CPR property. If we had `ExitCPR` (or `Exits` to match the current naming convention) in the lattice, then the step (2) would have returned `Exits` instead of `Dunno NoCPR`, and allowed `fun` to get a useful CPR property. I don't know how often this comes up in practice. With nested CPR, this will become a much bigger problem because it essentially means no tail- recursive IO function can get a useful CPR property. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8598#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler