[commit: ghc] wip/T13861: WIP: add note (696c056)

git at git.haskell.org git at git.haskell.org
Fri Dec 29 12:28:14 UTC 2017


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

On branch  : wip/T13861
Link       : http://ghc.haskell.org/trac/ghc/changeset/696c05643c035c6046c59db430e1aa536b4b3762/ghc

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

commit 696c05643c035c6046c59db430e1aa536b4b3762
Author: Gabor Greif <ggreif at gmail.com>
Date:   Fri Dec 29 12:16:19 2017 +0100

    WIP: add note


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

696c05643c035c6046c59db430e1aa536b4b3762
 compiler/simplStg/StgCse.hs | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/compiler/simplStg/StgCse.hs b/compiler/simplStg/StgCse.hs
index 7ca74ec..3d76704 100644
--- a/compiler/simplStg/StgCse.hs
+++ b/compiler/simplStg/StgCse.hs
@@ -421,7 +421,11 @@ mkStgCase scrut bndr ty alts | all isBndr alts = scrut
     isBndr _                   = False
     -- see Note [Lumping alternatives together]
     grouped ((DEFAULT, _, _) : alts) | any isBndr alts = pprTrace "mkStgCaseDEFAULT" (ppr alts) Nothing
-    grouped alts | (bs@(_:_:_),rest) <- partition isBndr alts = pprTrace "mkStgCase" (ppr bs) $ Just ((DEFAULT, []{-FIXME-}, StgApp bndr []) : rest)
+    grouped alts | (binds@(_:_:_),rest) <- partition isBndr alts
+                 , null $ concat [gs | (_, gs, _) <- binds]
+                 = Just ((DEFAULT, [], StgApp bndr []) : rest)
+    -- CAVEAT: guards
+    -- TODO: common constr applications: partition, sort, group
     grouped _ = Nothing
 
 -- Utilities
@@ -434,7 +438,7 @@ mkStgLet stgLet (Just binds) body = stgLet binds body
 
 {-
 Note [All alternatives are the binder]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 When all alternatives simply refer to the case binder, then we do not have
 to bother with the case expression at all (#13588). CoreSTG does this as well,
@@ -451,6 +455,17 @@ Core cannot just turn this into
 as this would not be well-typed. But to STG, where MkT is no longer in the way,
 we can.
 
+Note [Lumping alternatives together]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When some (>1) alternatives return the binder or a constructor
+and there is no DEFAULT, then we can establish a new default case
+and lump those together. We need to be careful, that there are no
+guards attached, though. We can even do better if we discover that
+the DEFAULT is present, but returns the same thing. Then we can simply
+drop the lumped-together cases. Ideally we should weight our choices
+by the count of the potentially lumped-together alternatives.
+
 Note [Trivial case scrutinee]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 We want to be able to handle nested reconstruction of constructors as in



More information about the ghc-commits mailing list