[Git][ghc/ghc][wip/andreask/mkTickUnsafeCoerce] mkTick: Push ticks through unsafeCoerce#.
Andreas Klebinger (@AndreasK)
gitlab at gitlab.haskell.org
Fri Oct 11 23:07:34 UTC 2024
Andreas Klebinger pushed to branch wip/andreask/mkTickUnsafeCoerce at Glasgow Haskell Compiler / GHC
Commits:
b394a664 by Andreas Klebinger at 2024-10-12T00:48:00+02:00
mkTick: Push ticks through unsafeCoerce#.
unsafeCoerce# doesn't exist at runtime so we should treat it like a Cast
for the purpose of mkTick.
This means if we have `{-# SCC foo #-} (unsafeCoerce# trivial_expr))` we
now push the scope part of the cost centre up to `trivial_expr` at which
point we can discard it completely if the expression is trivial enough.
This fixes #25212.
- - - - -
2 changed files:
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Types/Tickish.hs
Changes:
=====================================
compiler/GHC/Core/Utils.hs
=====================================
@@ -318,6 +318,10 @@ mkTick t orig_expr = mkTick' id id orig_expr
-> CoreExpr -- current expression
-> CoreExpr
mkTick' top rest expr = case expr of
+ -- Float ticks into unsafe coerce.
+ Case scrut bndr ty alts@[Alt ac abs _rhs]
+ | Just rhs <- isUnsafeEqualityCase scrut bndr alts
+ -> mkTick' (\e -> Case scrut bndr ty [Alt ac abs e]) rest rhs
-- Cost centre ticks should never be reordered relative to each
-- other. Therefore we can stop whenever two collide.
@@ -1253,7 +1257,7 @@ Note [Tick trivial]
Ticks are only trivial if they are pure annotations. If we treat
"tick<n> x" as trivial, it will be inlined inside lambdas and the
entry count will be skewed, for example. Furthermore "scc<n> x" will
-turn into just "x" in mkTick.
+turn into just "x" in mkTick. At least if `x` is not a function.
Note [Empty case is trivial]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
compiler/GHC/Types/Tickish.hs
=====================================
@@ -295,13 +295,15 @@ tickishCanSplit _ = False
mkNoCount :: GenTickish pass -> GenTickish pass
mkNoCount n | not (tickishCounts n) = n
| not (tickishCanSplit n) = panic "mkNoCount: Cannot split!"
-mkNoCount n at ProfNote{} = n {profNoteCount = False}
+mkNoCount n at ProfNote{} = let n' = n {profNoteCount = False}
+ in assert (profNoteCount n) n'
mkNoCount _ = panic "mkNoCount: Undefined split!"
mkNoScope :: GenTickish pass -> GenTickish pass
mkNoScope n | tickishScoped n == NoScope = n
| not (tickishCanSplit n) = panic "mkNoScope: Cannot split!"
-mkNoScope n at ProfNote{} = n {profNoteScope = False}
+mkNoScope n at ProfNote{} = let n' = n {profNoteScope = False}
+ in assert (profNoteCount n) n'
mkNoScope _ = panic "mkNoScope: Undefined split!"
-- | Return @True@ if this source annotation compiles to some backend
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b394a664a2b9bf7a6ea49af8f781890ae2a3863f
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b394a664a2b9bf7a6ea49af8f781890ae2a3863f
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/20241011/09727626/attachment-0001.html>
More information about the ghc-commits
mailing list