[commit: ghc] master: Add Note [Dead case binders in -O0] (4c8bf63)

git at git.haskell.org git at git.haskell.org
Wed Nov 28 12:32:24 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/4c8bf63b78f2fea56a184ef2a40e616f4b8bc59b/ghc

>---------------------------------------------------------------

commit 4c8bf63b78f2fea56a184ef2a40e616f4b8bc59b
Author: Sebastian Graf <sebastian.graf at kit.edu>
Date:   Wed Nov 28 13:28:29 2018 +0100

    Add Note [Dead case binders in -O0]
    
    After reverting Phab:D5358, Simon (Peyton Jones) asked for a Note
    summarising why we want to keep the dead case binder check in `cgCase`.
    
    Summary from mail conversation:
    
    * Phab:D5324 means that we no longer /recompute/ dead-ness of case-binders in
      STG-land
    
    * But TidyPgm preserves dead-ness info (see CoreTidy.tidyIdBndr)
    
    * And so we can take advantage of it to avoid a redundant load. This load
      would be eliminated by CmmSink, but that only happens with -O


>---------------------------------------------------------------

4c8bf63b78f2fea56a184ef2a40e616f4b8bc59b
 compiler/codeGen/StgCmmExpr.hs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/compiler/codeGen/StgCmmExpr.hs b/compiler/codeGen/StgCmmExpr.hs
index ea64e45..30603ee 100644
--- a/compiler/codeGen/StgCmmExpr.hs
+++ b/compiler/codeGen/StgCmmExpr.hs
@@ -305,7 +305,7 @@ cgCase (StgOpApp (StgPrimOp op) args _) bndr (AlgAlt tycon) alts
   = do { tag_expr <- do_enum_primop op args
 
        -- If the binder is not dead, convert the tag to a constructor
-       -- and assign it.
+       -- and assign it. See Note [Dead case binders in -O0]
        ; unless (isDeadBinder bndr) $ do
             { dflags <- getDynFlags
             ; tmp_reg <- bindArgToReg (NonVoid bndr)
@@ -385,6 +385,18 @@ Now the trouble is that 's' has VoidRep, and we do not bind void
 arguments in the environment; they don't live anywhere.  See the
 calls to nonVoidIds in various places.  So we must not look up
 's' in the environment.  Instead, just evaluate the RHS!  Simple.
+
+Note [Dead case binders in -O0]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Before CmmSink came to eliminate dead assignments, omitting assignment of dead
+case binders was a cheap and worthwhile optimisation. This probably also was the
+reason for occurrence hacks such as in Phab:D5339 to exist, because the
+occurrence information preserved by 'CoreTidy.tidyIdBndr' was insufficient.
+
+Nowadays, with CmmSink there's little reason to complicate the code by checking
+for dead case binders, except that CmmSink won't run with -O0. Since the
+majority of case binders are dead, this optimisation probably still has a great
+benefit-cost ratio and we want to keep it for -O0. See also Phab:D5358.
 -}
 
 cgCase (StgApp v []) _ (PrimAlt _) alts



More information about the ghc-commits mailing list