Commit fea26dd
Optimizer: Update SROA def-uses after DCE (JuliaLang#57201)
Fixes JuliaLang#57141.
Given the function
```julia
julia> function _f()
ref = Ref{Any}()
ref[] = 3
@Assert isdefined(ref, :x)
inner = Returns(ref)
x = inner()
(x, ref[])
end
_f (generic function with 1 method)
julia> f() = first(_f())
f (generic function with 1 method)
```
Here is before:
```julia
julia> @code_typed f()
CodeInfo(
1 ─ %1 = %new(Base.RefValue{Any})::Base.RefValue{Any}
└── goto mmtk#3
2 ─ unreachable
3 ─ return %1
) => Base.RefValue{Any}
```
Here is after this PR:
```julia
julia> @code_typed f()
CodeInfo(
1 ─ %1 = %new(Base.RefValue{Any})::Base.RefValue{Any}
│ builtin Base.setfield!(%1, :x, 3)::Int64
│ %3 = builtin Main.isdefined(%1, :x)::Bool
└── goto mmtk#3 if not %3
2 ─ goto mmtk#4
3 ─ %6 = invoke Base.AssertionError("isdefined(ref, :x)"::String)::AssertionError
│ builtin Base.throw(%6)::Union{}
└── unreachable
4 ─ return %1
) => Base.RefValue{Any}
```
The elimination of `setfield!` was due to a use still being recorded for
`ref[]` in the def-use data while DCE eliminated this `getindex` call
(by virtue of not using the second tuple element in the result).
---------
Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>1 parent 4bc3206 commit fea26dd
2 files changed
+16
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1511 | 1511 | | |
1512 | 1512 | | |
1513 | 1513 | | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
1514 | 1518 | | |
1515 | 1519 | | |
1516 | 1520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2030 | 2030 | | |
2031 | 2031 | | |
2032 | 2032 | | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
0 commit comments