[Git][ghc/ghc][master] Small optimization to CmmSink.
Marge Bot
gitlab at gitlab.haskell.org
Sat Nov 28 20:42:21 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
22ea9c29 by Andreas Klebinger at 2020-11-28T15:42:13-05:00
Small optimization to CmmSink.
Inside `regsUsedIn` we can avoid some thunks by specializing the
recursion. In particular we avoid the thunk for `(f e z)` in the
MachOp/Load branches, where we know this will evaluate to z.
Reduces allocations for T3294 by ~1%.
- - - - -
1 changed file:
- compiler/GHC/Cmm/Sink.hs
Changes:
=====================================
compiler/GHC/Cmm/Sink.hs
=====================================
@@ -449,6 +449,7 @@ tryToInline platform live node assigs = go usages node emptyLRegSet assigs
|| l `elemLRegSet` skipped
|| not (okToInline platform rhs node)
+ -- How often is l used in the current node.
l_usages = lookupUFM usages l
l_live = l `elemRegSet` live
@@ -554,10 +555,16 @@ addUsage m r = addToUFM_C (+) m r 1
regsUsedIn :: LRegSet -> CmmExpr -> Bool
regsUsedIn ls _ | nullLRegSet ls = False
-regsUsedIn ls e = wrapRecExpf f e False
- where f (CmmReg (CmmLocal l)) _ | l `elemLRegSet` ls = True
- f (CmmRegOff (CmmLocal l) _) _ | l `elemLRegSet` ls = True
- f _ z = z
+regsUsedIn ls e = go ls e False
+ where use :: LRegSet -> CmmExpr -> Bool -> Bool
+ use ls (CmmReg (CmmLocal l)) _ | l `elemLRegSet` ls = True
+ use ls (CmmRegOff (CmmLocal l) _) _ | l `elemLRegSet` ls = True
+ use _ls _ z = z
+
+ go :: LRegSet -> CmmExpr -> Bool -> Bool
+ go ls (CmmMachOp _ es) z = foldr (go ls) z es
+ go ls (CmmLoad addr _) z = go ls addr z
+ go ls e z = use ls e z
-- we don't inline into CmmUnsafeForeignCall if the expression refers
-- to global registers. This is a HACK to avoid global registers
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/22ea9c296906ad3a8fed384bcf6fb35d4b6ca814
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/22ea9c296906ad3a8fed384bcf6fb35d4b6ca814
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/20201128/74eaa44d/attachment-0001.html>
More information about the ghc-commits
mailing list