diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2020-11-24 13:32:51 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-11-28 15:42:13 -0500 |
commit | 22ea9c296906ad3a8fed384bcf6fb35d4b6ca814 (patch) | |
tree | 16a9c751d3f5e6ece678b6052b34671df011d592 /compiler/GHC | |
parent | 625726f988852f5779825a954609d187d9865dc1 (diff) | |
download | haskell-22ea9c296906ad3a8fed384bcf6fb35d4b6ca814.tar.gz |
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%.
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/Cmm/Sink.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/GHC/Cmm/Sink.hs b/compiler/GHC/Cmm/Sink.hs index 8fb4f2462f..87bc2c33ee 100644 --- a/compiler/GHC/Cmm/Sink.hs +++ b/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 |