summaryrefslogtreecommitdiff
path: root/compiler/GHC/Core/Opt/Simplify.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-04-16 15:11:43 +0100
committerBen Gamari <ben@smart-cactus.org>2021-11-23 20:59:53 -0500
commitb71da5fe871f0236b4033c7cac523fe776a56b29 (patch)
tree1c07bb1bcbd639c402bf0e910292e55683441eda /compiler/GHC/Core/Opt/Simplify.hs
parent9dcb2ad15df54e209cfae3dd1f51cf8e8d6c69d5 (diff)
downloadhaskell-wip/T3781.tar.gz
Make UnfoldingGuidance account for free variableswip/T3781
For over a decade (#3781) I've wondered whether GHC's UnfoldingGuidance should take account of free variables. For example: f x = let g y = case x of .... in ...(case x of ....g e....)... If we inline the call to g in the body of the case x, we can save re-evaluating (and case analysis of) x. This very similar to the "discounts" we give for arguments. All we need is to do it for free variables. It turned out to be rather easy. * Beef up GHC.Core.Unfold.sizeExpr to accumulate discounts for free variables. * Beef up GHC.Core.Unfold.callSiteInline to compute those discounts, based on info in the InScopeSet Fixes #3781 Also fixes #19643 (which reminded me of this issue)
Diffstat (limited to 'compiler/GHC/Core/Opt/Simplify.hs')
-rw-r--r--compiler/GHC/Core/Opt/Simplify.hs3
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/GHC/Core/Opt/Simplify.hs b/compiler/GHC/Core/Opt/Simplify.hs
index 1398bfd6e7..d046e44a11 100644
--- a/compiler/GHC/Core/Opt/Simplify.hs
+++ b/compiler/GHC/Core/Opt/Simplify.hs
@@ -2008,7 +2008,7 @@ simplIdF env var cont
completeCall :: SimplEnv -> OutId -> SimplCont -> SimplM (SimplFloats, OutExpr)
completeCall env var cont
- | Just expr <- callSiteInline logger uf_opts case_depth var active_unf
+ | Just expr <- callSiteInline logger uf_opts in_scope case_depth var active_unf
lone_variable arg_infos interesting_cont
-- Inline the variable's RHS
= do { checkedTick (UnfoldingDone var)
@@ -2027,6 +2027,7 @@ completeCall env var cont
where
uf_opts = seUnfoldingOpts env
case_depth = seCaseDepth env
+ in_scope = seInScope env
logger = seLogger env
(lone_variable, arg_infos, call_cont) = contArgs cont
n_val_args = length arg_infos