diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2017-02-27 17:14:32 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-02-28 10:56:07 -0500 |
commit | c662d41e2006f5a45619d40d2369b24642348f1a (patch) | |
tree | bb7a771b5b21cbc2ca26d3536fce3f92ceaa4cda /compiler/coreSyn | |
parent | d0508ef001e9c93920f6eb066cab5e79041cb886 (diff) | |
download | haskell-c662d41e2006f5a45619d40d2369b24642348f1a.tar.gz |
Small changes to expression sizing in CoreUnfold
The only significant change here is that
case e of {}
should be treated like 'e', rather than like a case expression.
We don't push a return address, for example, since 'e' is sure to
diverge.
I forget why I did this; but it will make these empty-case expressions
(which are only there to satisfy the type checker) cost-free.
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3204
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r-- | compiler/coreSyn/CoreUnfold.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/coreSyn/CoreUnfold.hs b/compiler/coreSyn/CoreUnfold.hs index bae6330e6d..5844eb999a 100644 --- a/compiler/coreSyn/CoreUnfold.hs +++ b/compiler/coreSyn/CoreUnfold.hs @@ -534,6 +534,11 @@ sizeExpr dflags bOMB_OUT_SIZE top_args expr pairs size_up (Case e _ _ alts) + | null alts + = size_up e -- case e of {} never returns, so take size of scrutinee + + size_up (Case e _ _ alts) + -- Now alts is non-empty | Just v <- is_top_arg e -- We are scrutinising an argument variable = let alt_sizes = map size_up_alt alts @@ -558,8 +563,8 @@ sizeExpr dflags bOMB_OUT_SIZE top_args expr alts_size tot_size _ = tot_size in - alts_size (foldr addAltSize sizeZero alt_sizes) - (foldr maxSize sizeZero alt_sizes) + alts_size (foldr1 addAltSize alt_sizes) -- alts is non-empty + (foldr1 maxSize alt_sizes) -- Good to inline if an arg is scrutinised, because -- that may eliminate allocation in the caller -- And it eliminates the case itself @@ -763,6 +768,7 @@ funSize dflags top_args fun n_val_args voids res_discount | idArity fun > n_val_args = ufFunAppDiscount dflags | otherwise = 0 -- If the function is partially applied, show a result discount +-- XXX maybe behave like ConSize for eval'd varaible conSize :: DataCon -> Int -> ExprSize conSize dc n_val_args @@ -774,6 +780,8 @@ conSize dc n_val_args -- See Note [Constructor size and result discount] | otherwise = SizeIs 10 emptyBag (10 * (1 + n_val_args)) +-- XXX still looks to large to me + {- Note [Constructor size and result discount] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |