summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-06-24 09:54:33 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-06-27 14:57:39 -0400
commitb92479f9e367413cd69ff0877579033ab86cde36 (patch)
tree1f0e2378e1573f2f8cc4269642f822ea1388930a
parente69d070b85a4e911b1245e733e4b95d7d7cd9224 (diff)
downloadhaskell-b92479f9e367413cd69ff0877579033ab86cde36.tar.gz
Inliner: Regard LitRubbish as TrivArg and not ConLike
Part of fixing #19766 required the emission of `LitRubbish` as absent filler in places where we used `absentError` before. In WWRec we have the situation that such bindings occur in the argument to functions. With `LitRubbish` we inlined those functions, because 1. The absent binding was regarded as ConLike. So I fixed `exprIsHNFLike` to respond `False` to `LitRubbish`. 2. The other source of inlining was that after inlining such an absent binding, `LitRubbish` itself was regarded `ValueArg` by `interestingArg`, leading to more inlining. It now responds `TrivArg` to `LitRubbish`. Fixes #20035. There's one slight 1.6% ghc/alloc regression left in T15164 that is due to an additional specialisation `$s$cget`. I've no idea why that happens; the Core output before is identical and has the call site that we specialise for. Metric Decrease: WWRec
-rw-r--r--compiler/GHC/Core/Opt/Simplify/Utils.hs5
-rw-r--r--compiler/GHC/Core/Utils.hs4
2 files changed, 7 insertions, 2 deletions
diff --git a/compiler/GHC/Core/Opt/Simplify/Utils.hs b/compiler/GHC/Core/Opt/Simplify/Utils.hs
index 15cccfd55b..549ee2365f 100644
--- a/compiler/GHC/Core/Opt/Simplify/Utils.hs
+++ b/compiler/GHC/Core/Opt/Simplify/Utils.hs
@@ -42,6 +42,7 @@ import GHC.Prelude
import GHC.Driver.Session
import GHC.Core
+import GHC.Types.Literal ( isLitRubbish )
import GHC.Core.Opt.Simplify.Env
import GHC.Core.Opt.Monad ( SimplMode(..), Tick(..) )
import qualified GHC.Core.Subst
@@ -819,7 +820,9 @@ interestingArg env e = go env 0 e
DoneEx e _ -> go (zapSubstEnv env) n e
ContEx tvs cvs ids e -> go (setSubstEnv env tvs cvs ids) n e
- go _ _ (Lit {}) = ValueArg
+ go _ _ (Lit l)
+ | isLitRubbish l = TrivArg -- Leads to unproductive inlining in WWRec, #20035
+ | otherwise = ValueArg
go _ _ (Type _) = TrivArg
go _ _ (Coercion _) = TrivArg
go env n (App fn (Type _)) = go env n fn
diff --git a/compiler/GHC/Core/Utils.hs b/compiler/GHC/Core/Utils.hs
index a120bed3b0..12efdddcd4 100644
--- a/compiler/GHC/Core/Utils.hs
+++ b/compiler/GHC/Core/Utils.hs
@@ -1907,7 +1907,9 @@ exprIsHNFlike is_con is_con_unf = is_hnf_like
-- but otherwise I worry that if an Id's unfolding is just itself,
-- we could get an infinite loop
- is_hnf_like (Lit _) = True
+ is_hnf_like (Lit l) = not (isLitRubbish l)
+ -- Regarding a LitRubbish as ConLike leads to unproductive inlining in
+ -- WWRec, see #20035
is_hnf_like (Type _) = True -- Types are honorary Values;
-- we don't mind copying them
is_hnf_like (Coercion _) = True -- Same for coercions