Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizer: refactor SROA pass #43232

Merged
merged 1 commit into from
Nov 29, 2021
Merged

optimizer: refactor SROA pass #43232

merged 1 commit into from
Nov 29, 2021

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Nov 26, 2021

  • use BitSet instead of IdSet{Int}
  • reduce # of dynamic allocations
  • separate some computations into individual functions

TTFP improvements:

before (df0080c)

❯ ./usr/bin/julia -e "@time using Plots; @time plot(rand(10,3));"
  4.588537 seconds (9.34 M allocations: 624.761 MiB, 6.73% gc time, 15.28% compilation time)
  2.875475 seconds (3.84 M allocations: 214.448 MiB, 5.90% gc time, 99.77% compilation time)

after (cef9efa)

❯ ./usr/bin/julia -e "@time using Plots; @time plot(rand(10,3));"
  4.543190 seconds (9.24 M allocations: 615.898 MiB, 6.70% gc time, 15.24% compilation time)
  2.823435 seconds (3.78 M allocations: 209.089 MiB, 5.43% gc time, 99.76% compilation time)

@@ -596,17 +596,16 @@ a result of succeeding dead code elimination.
"""
function sroa_pass!(ir::IRCode)
compact = IncrementalCompact(ir)
defuses = IdDict{Int, Tuple{IdSet{Int}, SSADefUse}}()
defuses = nothing # will be initialized once we encounter mutability in order to reduce dynamic allocations
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder: we may want to have some nice support for this sort of optimization?
Like: @delay_alloc defuses = IdDict{Int, Tuple{BitSet, SSADefUse}}()

@Keno
Copy link
Member

Keno commented Nov 26, 2021

BitSet can be dangerous on large functions with high sparsity

@codecov
Copy link

codecov bot commented Nov 26, 2021

Codecov Report

Merging #43232 (df0080c) into master (7107ced) will decrease coverage by 0.10%.
The diff coverage is 93.33%.

❗ Current head df0080c differs from pull request most recent head 6c4e203. Consider uploading reports for the commit 6c4e203 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #43232      +/-   ##
==========================================
- Coverage   89.62%   89.52%   -0.11%     
==========================================
  Files         343      343              
  Lines       80294    80301       +7     
==========================================
- Hits        71961    71886      -75     
- Misses       8333     8415      +82     
Impacted Files Coverage Δ
base/compiler/ssair/ir.jl 79.86% <0.00%> (-0.55%) ⬇️
base/compiler/ssair/passes.jl 91.97% <94.02%> (-1.06%) ⬇️
base/compiler/ssair/show.jl 86.88% <100.00%> (ø)
base/compiler/ssair/slot2ssa.jl 87.72% <100.00%> (+0.02%) ⬆️
base/compiler/stmtinfo.jl 78.57% <0.00%> (-14.29%) ⬇️
stdlib/REPL/src/REPLCompletions.jl 88.76% <0.00%> (-2.72%) ⬇️
base/compiler/abstractinterpretation.jl 87.99% <0.00%> (-2.15%) ⬇️
base/compiler/inferencestate.jl 84.01% <0.00%> (-1.37%) ⬇️
base/compiler/ssair/queries.jl 92.20% <0.00%> (-1.30%) ⬇️
base/compiler/typeutils.jl 82.01% <0.00%> (-1.06%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b1ece9...6c4e203. Read the comment docs.

@aviatesk
Copy link
Member Author

BitSet can be dangerous on large functions with high sparsity

Aha, I see the point. SROA works on IR after inlining, which can be very large sometimes, and program counters analyzed by it are often very sparse.
I made them IdSet{Int} back, also added some note for this choice.

- use `BitSet` instead of `IdSet{Int}`
- reduce # of dynamic allocations
- separate some computations into individual functions
@aviatesk aviatesk merged commit d515f05 into master Nov 29, 2021
@aviatesk aviatesk deleted the avi/sroarefac branch November 29, 2021 02:09
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
- avoid domtree construction when there are no mutables to eliminate
- reduce # of dynamic allocations
- separate some computations into individual functions
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
- avoid domtree construction when there are no mutables to eliminate
- reduce # of dynamic allocations
- separate some computations into individual functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants