[commit: ghc] wip/T13861: WIP: implement DEFAULT lumping (86248ba)

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


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

On branch  : wip/T13861
Link       : http://ghc.haskell.org/trac/ghc/changeset/86248baf106255cc4e26b24a28fed697038e58f5/ghc

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

commit 86248baf106255cc4e26b24a28fed697038e58f5
Author: Gabor Greif <ggreif at gmail.com>
Date:   Fri Dec 29 12:25:52 2017 +0100

    WIP: implement DEFAULT lumping
    
    and fix note, as we have no guards in STG


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

86248baf106255cc4e26b24a28fed697038e58f5
 compiler/simplStg/StgCse.hs | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/compiler/simplStg/StgCse.hs b/compiler/simplStg/StgCse.hs
index 3d76704..960c254 100644
--- a/compiler/simplStg/StgCse.hs
+++ b/compiler/simplStg/StgCse.hs
@@ -420,11 +420,11 @@ mkStgCase scrut bndr ty alts | all isBndr alts = scrut
     isBndr (_, _, StgApp f []) = f == bndr
     isBndr _                   = False
     -- see Note [Lumping alternatives together]
-    grouped ((DEFAULT, _, _) : alts) | any isBndr alts = pprTrace "mkStgCaseDEFAULT" (ppr alts) Nothing
+    grouped (def@(DEFAULT, _, _) : alts) | isBndr def
+                                         , (binds@(_:_),rest) <- partition isBndr alts
+      = pprTrace "mkStgCaseDEFAULT" (ppr alts) $ Just (def: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
 
@@ -458,10 +458,9 @@ we can.
 Note [Lumping alternatives together]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-When some (>1) alternatives return the binder or a constructor
+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
+and lump those together. 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.



More information about the ghc-commits mailing list