[Git][ghc/ghc][wip/andreask/spec_lits] Allow SpecConstr to specialize for unboxed literals

Andreas Klebinger (@AndreasK) gitlab at gitlab.haskell.org
Tue Jan 17 11:39:17 UTC 2023



Andreas Klebinger pushed to branch wip/andreask/spec_lits at Glasgow Haskell Compiler / GHC


Commits:
86ff89b2 by Andreas Klebinger at 2023-01-17T12:37:23+01:00
Allow SpecConstr to specialize for unboxed literals

- - - - -


1 changed file:

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


Changes:

=====================================
compiler/GHC/Core/Opt/SpecConstr.hs
=====================================
@@ -1533,6 +1533,9 @@ scExpr' env (Case scrut b ty alts)
                                   | not (single_alt && all deadArgOcc arg_occs)
                                   -> -- pprTrace "sc_alt1" (ppr b' $$ ppr con $$ ppr bs $$ ppr arg_occs) $
                                      ScrutOcc (unitUFM dc arg_occs)
+                               LitAlt _
+                                  | not (single_alt)
+                                  -> ScrutOcc (emptyUFM)
                                _  -> -- pprTrace "sc_alt1" (ppr b' $$ ppr con $$ ppr bs $$ ppr arg_occs) $
                                      UnkOcc
           ; return (usg', b_occ `combineOcc` scrut_occ, Alt con bs2 rhs') }
@@ -2632,6 +2635,11 @@ argToPat in_scope val_env arg arg_occ
   -- Check for a constructor application
   -- NB: this *precedes* the Var case, so that we catch nullary constrs
 argToPat1 env in_scope val_env arg arg_occ _arg_str
+  | Just (ConVal (LitAlt lit) _args) <- isValue val_env arg
+  , mb_scrut_lit
+  = do {
+       ; return (True, Lit lit , []) }
+
   | Just (ConVal (DataAlt dc) args) <- isValue val_env arg
   , not (ignoreDataCon env dc)        -- See Note [NoSpecConstr]
   , Just arg_occs <- mb_scrut dc
@@ -2661,6 +2669,13 @@ argToPat1 env in_scope val_env arg arg_occ _arg_str
                             -> Just (repeat UnkOcc)
                             | otherwise
                             -> Nothing
+    mb_scrut_lit = case arg_occ of
+                ScrutOcc _  -> True
+                _other      | sc_force env || sc_keen (sc_opts env)
+                            -> True
+                            | otherwise
+                            -> False
+
     match_vals bangs (arg:args)
       | isTypeArg arg
       = NotMarkedStrict : match_vals bangs args



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/86ff89b2edf48978aaf7743c75220dbc6ff236e9
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/20230117/1d307151/attachment-0001.html>


More information about the ghc-commits mailing list