[Git][ghc/ghc][wip/T17910] Make floatConsts affects only lvlMFE, and even then not functions

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Thu Aug 10 08:49:41 UTC 2023



Simon Peyton Jones pushed to branch wip/T17910 at Glasgow Haskell Compiler / GHC


Commits:
d1717adc by Simon Peyton Jones at 2023-08-10T09:48:44+01:00
Make floatConsts affects only lvlMFE, and even then not functions

T5237 is a good example

- - - - -


1 changed file:

- compiler/GHC/Core/Opt/SetLevels.hs


Changes:

=====================================
compiler/GHC/Core/Opt/SetLevels.hs
=====================================
@@ -738,7 +738,8 @@ lvlMFE env strict_ctxt ann_expr
 
     -- See Note [Floating to the top]
     saves_alloc =  isTopLvl dest_lvl
-                && floatConsts env
+                && (floatConsts env || is_function)   -- Always float constant lambdas
+                                                      -- T5237 is a good example
                 && (   not strict_ctxt                     -- (a)
                     || exprIsHNF expr                      -- (b)
                     || (is_bot_lam && escapes_value_lam))  -- (c)
@@ -1174,7 +1175,8 @@ lvlBind env (AnnNonRec bndr rhs)
     is_join       = isJoinPoint mb_join_arity
 
 lvlBind env (AnnRec pairs)
-  |  floatTopLvlOnly env && not (isTopLvl dest_lvl)
+  |  pprTrace "lvlBind" (ppr (map fst pairs) $$ ppr dest_lvl $$ ppr (profitableFloat env dest_lvl)) $
+     floatTopLvlOnly env && not (isTopLvl dest_lvl)
          -- Only floating to the top level is allowed.
   || not (profitableFloat env dest_lvl)
   || (isTopLvl dest_lvl && any (mightBeUnliftedType . idType) bndrs)
@@ -1268,7 +1270,9 @@ lvlBind env (AnnRec pairs)
 profitableFloat :: LevelEnv -> Level -> Bool
 profitableFloat env dest_lvl
   =  (dest_lvl `ltMajLvl` le_ctxt_lvl env)  -- Escapes a value lambda
-  || (isTopLvl dest_lvl && floatConsts env) -- Going all the way to top level
+  || (isTopLvl dest_lvl)                    -- Going all the way to top level
+          -- Float to top even if floatConsts=False; this is a
+          -- let-binding anyway, so it doesn't create a new binding
 
 
 ----------------------------------------------------



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d1717adc0c8d0d985b8d32431af554d8f63ee254
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/20230810/dca12909/attachment-0001.html>


More information about the ghc-commits mailing list