summaryrefslogtreecommitdiff
path: root/compiler/GHC/Core/SimpleOpt.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simon.peytonjones@gmail.com>2022-01-24 00:55:34 +0000
committerSimon Peyton Jones <simon.peytonjones@gmail.com>2022-01-26 09:37:50 +0000
commit9c7a06474175c9633689fa1ff1df7a0754afcee7 (patch)
treeae1bc0d43d0b207585986ca582c890e408906dab /compiler/GHC/Core/SimpleOpt.hs
parent781323a3076781b5db50bdbeb8f64394add43836 (diff)
downloadhaskell-wip/T20988.tar.gz
Better occurrence analysis with castswip/T20988
This patch addresses #20988 by refactoring the way the occurrence analyser deals with lambdas. Previously it used collectBinders to split off a group of binders, and deal with them together. Now I deal with them one at a time in occAnalLam, which allows me to skip casts easily. See Note [Occurrence analysis for lambda binders] about "lambda-groups" This avoidance of splitting out a list of binders has some good consequences. Less code, more efficient, and I think, more clear. The Simplifier needed a similar change, now that lambda-groups can inlude casts. It turned out that I could simplify the code here too, in particular elminating the sm_bndrs field of StrictBind. Simpler, more efficient. Compile-time metrics improve slightly; here are the ones that are +/- 0.5% or greater: Baseline Test Metric value New value Change -------------------------------------------------------------------- T11303b(normal) ghc/alloc 40,736,702 40,543,992 -0.5% T12425(optasm) ghc/alloc 90,443,459 90,034,104 -0.5% T14683(normal) ghc/alloc 2,991,496,696 2,956,277,288 -1.2% T16875(normal) ghc/alloc 34,937,866 34,739,328 -0.6% T17977b(normal) ghc/alloc 37,908,550 37,709,096 -0.5% T20261(normal) ghc/alloc 621,154,237 618,312,480 -0.5% T3064(normal) ghc/alloc 190,832,320 189,952,312 -0.5% T3294(normal) ghc/alloc 1,604,674,178 1,604,608,264 -0.0% T5321FD(normal) ghc/alloc 270,540,489 251,888,480 -6.9% GOOD T5321Fun(normal) ghc/alloc 300,707,814 281,856,200 -6.3% GOOD WWRec(normal) ghc/alloc 588,460,916 585,536,400 -0.5% geo. mean -0.3% Metric Decrease: T5321FD T5321Fun
Diffstat (limited to 'compiler/GHC/Core/SimpleOpt.hs')
-rw-r--r--compiler/GHC/Core/SimpleOpt.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/GHC/Core/SimpleOpt.hs b/compiler/GHC/Core/SimpleOpt.hs
index 720bc895c8..92f1c7987e 100644
--- a/compiler/GHC/Core/SimpleOpt.hs
+++ b/compiler/GHC/Core/SimpleOpt.hs
@@ -28,7 +28,7 @@ import GHC.Core.FVs
import GHC.Core.Unfold
import GHC.Core.Unfold.Make
import GHC.Core.Make ( FloatBind(..) )
-import GHC.Core.Opt.OccurAnal( occurAnalyseExpr, occurAnalysePgm )
+import GHC.Core.Opt.OccurAnal( occurAnalyseExpr, occurAnalysePgm, zapLambdaBndrs )
import GHC.Types.Literal
import GHC.Types.Id
import GHC.Types.Id.Info ( realUnfoldingInfo, setUnfoldingInfo, setRuleInfo, IdInfo (..) )
@@ -332,20 +332,21 @@ simple_app env (App e1 e2) as
= simple_app env e1 ((env, e2) : as)
simple_app env e@(Lam {}) as@(_:_)
- | (bndrs, body) <- collectBinders e
- , let zapped_bndrs = zapLamBndrs (length as) bndrs
+ = do_beta env (zapLambdaBndrs e n_args) as
-- Be careful to zap the lambda binders if necessary
-- c.f. the Lam case of simplExprF1 in GHC.Core.Opt.Simplify
-- Lacking this zap caused #19347, when we had a redex
-- (\ a b. K a b) e1 e2
-- where (as it happens) the eta-expanded K is produced by
-- Note [Typechecking data constructors] in GHC.Tc.Gen.Head
- = do_beta env zapped_bndrs body as
where
- do_beta env (b:bs) body (a:as)
+ n_args = length as
+
+ do_beta env (Lam b body) (a:as)
| (env', mb_pr) <- simple_bind_pair env b Nothing a NotTopLevel
- = wrapLet mb_pr $ do_beta env' bs body as
- do_beta env bs body as = simple_app env (mkLams bs body) as
+ = wrapLet mb_pr $ do_beta env' body as
+ do_beta env body as
+ = simple_app env body as
simple_app env (Tick t e) as
-- Okay to do "(Tick t e) x ==> Tick t (e x)"?