[Git][ghc/ghc][wip/spj-unf-size] Small updates

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Sat Nov 11 23:58:04 UTC 2023



Simon Peyton Jones pushed to branch wip/spj-unf-size at Glasgow Haskell Compiler / GHC


Commits:
3c0c2664 by Simon Peyton Jones at 2023-11-11T23:57:24+00:00
Small updates

* Reduce unfolding-use-threshold to 80
* Make dfun applications look like value args

- - - - -


2 changed files:

- compiler/GHC/Core/Opt/Simplify/Inline.hs
- compiler/GHC/Core/Unfold.hs


Changes:

=====================================
compiler/GHC/Core/Opt/Simplify/Inline.hs
=====================================
@@ -606,8 +606,14 @@ exprDigest env e = go env e []
       | let env' = env `addNewInScopeIds` bindersOf b
       = go env' e as
 
-{-
-    -- Look through single-branch case-expressions; like lets
+{-  -- Look through single-branch case-expressions; like lets
+    -- This is a bit aggressive, because we might have
+    --     f (case x of (a,b) -> (b,a))
+    -- where   f p = Just (case p of (a,b) -> a)
+    -- So f is lazy, and we won't get cancellation of the case in the body.
+    --
+    -- If f is strict and we don't inline, we'll float the case out, so we don't
+    -- need to be clever here.
     go env (Case _ b _ alts) as
       | [Alt _ bs e] <- alts
       , let env' = env `addNewInScopeIds` (b:bs)
@@ -645,8 +651,13 @@ exprDigest env e = go env e []
       = ArgIsCon (DataAlt con) (map (exprDigest env) val_args)
 
       | DFunUnfolding {} <- unfolding
-      = ArgNonTriv   -- Says "this is a data con" without saying which
-                     -- Will also return this for ($df d1 .. dn)
+      = ArgIsNot []  -- We (slightly hackily) use ArgIsNot [] for dfun applications
+                     -- ($df d1 .. dn).  This is very important to encourage inlining
+                     -- of overloaded functions.  Example. GHC.Base.liftM2. It has
+                     -- three uses of its dict arg, each of which attracts a ScrutOf
+                     -- discount.  But the ArgDigest had better be good enough to
+                     -- attract that ScrutOf discount!  We want liftM2 to be inlined
+                     -- in its use in the liftA2 method of instance Applicative (ST s)
 
       | Just rhs <- expandUnfolding_maybe unfolding
       = go (zapSubstEnv env) rhs val_args


=====================================
compiler/GHC/Core/Unfold.hs
=====================================
@@ -206,8 +206,12 @@ defaultUnfoldingOpts = UnfoldingOpts
       -- inline into Csg.calc (The unfolding for sqr never makes it
       -- into the interface file.)
 
-   , unfoldingUseThreshold   = 90
-      -- Last adjusted upwards in #18282, when I reduced
+   , unfoldingUseThreshold   = 80
+      -- Adjusted 90 -> 80 when adding discounts for free variables which
+      -- generally make things more likely to inline.  Reducing the threshold
+      -- eliminates some undesirable compile-time regressions (e.g. T10412a)
+      --
+      -- Previously: adjusted upwards in #18282, when I reduced
       -- the result discount for constructors.
 
    , unfoldingFunAppDiscount = 60



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3c0c266472359c041ef41adc30a6af66638d17d4

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3c0c266472359c041ef41adc30a6af66638d17d4
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20231111/8c8f734f/attachment-0001.html>


More information about the ghc-commits mailing list