diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2012-01-13 17:50:00 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2012-01-13 17:50:00 +0000 |
commit | 601c983dd0bada6b49bdadd8f172fd4eacac4b0c (patch) | |
tree | 58c99eb2753958b5a0192ec050a385b9badcc847 /compiler/simplCore/FloatIn.lhs | |
parent | c96022cbfae44ea9180b78e3c37467613ac98cec (diff) | |
download | haskell-601c983dd0bada6b49bdadd8f172fd4eacac4b0c.tar.gz |
Add -faggressive-primops plus refactoring in CoreUtils
I'm experimenting with making GHC a bit more aggressive about
a) dropping case expressions if the result is unused
Simplify.rebuildCase, CaseElim equation
b) floating case expressions inwards
FloatIn.fiExpr, AnnCase
In both cases the new behaviour is gotten with a static (debug)
flag -faggressive-primops. The extra "aggression" is to allow
discarding and floating in for side-effecting operations. See
the new, extensive Note [PrimOp can_fail and has_side_effects]
in PrimoOp.
When discarding a case with unused binders, in the lifted-type
case it's definitely ok if the scrutinee terminates; previously
we were checking exprOkForSpeculation, which is significantly
worse.
So I wanted a new function CoreUtils.exprCertainlyTerminates.
In doing this I ended up with a significant refactoring in
CoreUtils. The new structure has quite a lot of nice sharing:
exprIsCheap = exprIsCheap' isHNFApp
exprIsExpandable = exprIsCheap' isConLikeApp
exprIsHNF = exprIsHNFlike isHNFApp
exprIsConLike = exprIsHNFlike isConLikeApp
exprCertainlyTerminates = exprIsHNFlike isTerminatingApp
Diffstat (limited to 'compiler/simplCore/FloatIn.lhs')
-rw-r--r-- | compiler/simplCore/FloatIn.lhs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/simplCore/FloatIn.lhs b/compiler/simplCore/FloatIn.lhs index 0601d7b7bf..a25ed4037d 100644 --- a/compiler/simplCore/FloatIn.lhs +++ b/compiler/simplCore/FloatIn.lhs @@ -33,6 +33,7 @@ import Type ( isUnLiftedType ) import VarSet import Util ( zipEqual, zipWithEqual, count ) import UniqFM +import StaticFlags ( opt_AggressivePrimOps ) import Outputable \end{code} @@ -357,7 +358,14 @@ alternatives/default [default FVs always {\em first}!]. \begin{code} fiExpr to_drop (_, AnnCase scrut case_bndr _ [(DEFAULT,[],rhs)]) | isUnLiftedType (idType case_bndr) - , exprOkForSideEffects (deAnnotate scrut) + , opt_AggressivePrimOps || exprOkForSideEffects (deAnnotate scrut) +-- It should be ok to float in ANY primop. +-- See Note [PrimOp can_fail and has_side_effects] in PrimOp +-- The AggressIvePrimOps flag lets us recover the earlier +-- more conservative behaviour. See Note [Aggressive PrimOps] in PrimOp +-- +-- It would NOT be ok if a primop evaluated an unlifted +-- argument, but no primop does that. = wrapFloats shared_binds $ fiExpr (case_float : rhs_binds) rhs where |