-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: SROA mutable(immutable(...))
case correctly
#43239
Conversation
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
Was that a regression? julia> simple_sroa(s) = broadcast(identity, Ref(s))
simple_sroa (generic function with 1 method)
julia> simple_sroa("compile"); @allocated(simple_sroa("julia"))
0
julia> versioninfo()
Julia Version 1.6.4-pre.2
Commit 1a92e56a4d* (2021-10-09 19:47 UTC) |
b8af9c6
to
b1da35a
Compare
f391fde
to
43ef52d
Compare
Ah, it seems like the entire chunk of julia> code_typed() do
simple_sroa("julia")
end
1-element Vector{Any}:
CodeInfo(
1 ─ goto #3 if not true
2 ─ nothing::Nothing
3 ┄ goto #4
4 ─ goto #5
5 ─ goto #6
6 ─ goto #7
7 ─ goto #8
8 ─ return "julia"
) => String Allocation happens if we use the compiled code of julia> s = "julia"
"julia"
julia> @allocated(simple_sroa(s))
16 but with this PR, no allocation should happen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible to me though, of course this entire bit of code is a bit messy and we may want better abstractions in the future.
b1da35a
to
6c4e203
Compare
43ef52d
to
b33430e
Compare
Our SROA should be able to handle `mutable(immutable(...))` case even without "proper" alias analysis, since we eliminate `immutable` first and then process `mutable` within our iterative approach. It turns out it hasn't worked at all because after the immutable handling we keep the reference count _before_ DCE, but didn't update dead reference count. This commit fixes it and now we should be able to eliminate more allocations, e.g.: ```julia julia> simple_sroa(s) = broadcast(identity, Ref(s)) simple_sroa (generic function with 1 method) julia> simple_sroa("compile"); @allocated(simple_sroa("julia")) 0 ```
b33430e
to
138abf3
Compare
…3239) Our SROA should be able to handle `mutable(immutable(...))` case even without "proper" alias analysis, since we eliminate `immutable` first and then process `mutable` within our iterative approach. It turns out it didn't work because after the immutable handling we keep the reference count _before_ DCE, but didn't update dead reference count. This commit fixes it and now we should be able to eliminate more allocations, e.g.: ```julia julia> simple_sroa(s) = broadcast(identity, Ref(s)) simple_sroa (generic function with 1 method) julia> simple_sroa("compile"); @allocated(simple_sroa("julia")) 0 ```
…3239) Our SROA should be able to handle `mutable(immutable(...))` case even without "proper" alias analysis, since we eliminate `immutable` first and then process `mutable` within our iterative approach. It turns out it didn't work because after the immutable handling we keep the reference count _before_ DCE, but didn't update dead reference count. This commit fixes it and now we should be able to eliminate more allocations, e.g.: ```julia julia> simple_sroa(s) = broadcast(identity, Ref(s)) simple_sroa (generic function with 1 method) julia> simple_sroa("compile"); @allocated(simple_sroa("julia")) 0 ```
Our SROA should be able to handle
mutable(immutable(...))
case evenwithout "proper" alias analysis, since we eliminate
immutable
firstand then process
mutable
within our iterative approach.It turns out it hasn't worked because after the immutable handling,
we keep the reference count before DCE, but don't update dead reference
count. This commit fixes it and now we should be able to eliminate more
allocations, e.g.:
@nanosoldier
runbenchmarks("broadcast" || "sparse" || "array" || "union", vs=":master")
(... and now I lose yet another motivative example for EscapeAnalysis.jl-based SROA :P)