summaryrefslogtreecommitdiff
path: root/compiler/stranal/DmdAnal.lhs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-04-13 17:38:32 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-04-13 17:38:32 +0100
commitb8ff4448d899f783fc112f3774aab626979a4f22 (patch)
tree2df5cce493374a5c58b145c80b6f584f4563ec88 /compiler/stranal/DmdAnal.lhs
parent5eabdc1675b8b5bc9fcdfb96ab63d14d42ca2d5b (diff)
downloadhaskell-b8ff4448d899f783fc112f3774aab626979a4f22.tar.gz
Fix worker/wrapper for CPR functions
A long-standing and egregious bug in the worker/wrapper code meant that some functions with the CPR property weren't getting a CPR w/w. And that had the effect of making a tail-recursive function not tail recursive. As well as increasing allocation. Fixes Trac #5920, and #5997. Nofib results (highlights): Program Size Allocs Runtime Elapsed TotalMem -------------------------------------------------------------------------------- boyer2 -0.1% -15.3% 0.01 0.01 +0.0% mandel2 -0.0% -8.1% 0.01 0.01 +0.0% para -0.1% -11.8% -7.9% -7.8% +0.0% -------------------------------------------------------------------------------- Min -0.1% -15.3% -7.9% -7.8% -33.3% Max +0.0% +0.2% +6.3% +6.3% +3.7% Geometric Mean -0.0% -0.4% +0.1% +0.1% -0.5% Looks like a clear win. And I have not even recompiled the libraries, so it'll probably be a bit better in the ed.
Diffstat (limited to 'compiler/stranal/DmdAnal.lhs')
-rw-r--r--compiler/stranal/DmdAnal.lhs13
1 files changed, 6 insertions, 7 deletions
diff --git a/compiler/stranal/DmdAnal.lhs b/compiler/stranal/DmdAnal.lhs
index 0bfd025410..167debfb55 100644
--- a/compiler/stranal/DmdAnal.lhs
+++ b/compiler/stranal/DmdAnal.lhs
@@ -592,7 +592,7 @@ mkSigTy top_lvl rec_flag id rhs dmd_ty
maybe_id_dmd = idDemandInfo_maybe id
-- Is Nothing the first time round
- thunk_cpr_ok
+ thunk_cpr_ok -- See Note [CPR for thunks]
| isTopLevel top_lvl = False -- Top level things don't get
-- their demandInfo set at all
| isRec rec_flag = False -- Ditto recursive things
@@ -601,8 +601,8 @@ mkSigTy top_lvl rec_flag id rhs dmd_ty
-- See notes below
\end{code}
-The thunk_cpr_ok stuff [CPR-AND-STRICTNESS]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Note [CPR for thunks]
+~~~~~~~~~~~~~~~~~~~~~
If the rhs is a thunk, we usually forget the CPR info, because
it is presumably shared (else it would have been inlined, and
so we'd lose sharing if w/w'd it into a function). E.g.
@@ -662,8 +662,8 @@ have a CPR in it or not. Simple solution:
NB: strictly_demanded is never true of a top-level Id, or of a recursive Id.
-The Nothing case in thunk_cpr_ok [CPR-AND-STRICTNESS]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Note [Optimistic in the Nothing case]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demand info now has a 'Nothing' state, just like strictness info.
The analysis works from 'dangerous' towards a 'safe' state; so we
start with botSig for 'Nothing' strictness infos, and we start with
@@ -1010,8 +1010,7 @@ extendSigsWithLam :: AnalEnv -> Id -> AnalEnv
extendSigsWithLam env id
= case idDemandInfo_maybe id of
Nothing -> extendAnalEnv NotTopLevel env id cprSig
- -- Optimistic in the Nothing case;
- -- See notes [CPR-AND-STRICTNESS]
+ -- See Note [Optimistic in the Nothing case]
Just (Eval (Prod _)) -> extendAnalEnv NotTopLevel env id cprSig
_ -> env
\end{code}