Commit dec7072
Optimizer: Update SROA def-uses after DCE (#57201)
Fixes #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 #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 #3 if not %3
2 ─ goto #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>
(cherry picked from commit fea26dd)1 parent c28dc85 commit dec7072
2 files changed
+16
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1480 | 1480 | | |
1481 | 1481 | | |
1482 | 1482 | | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
1483 | 1487 | | |
1484 | 1488 | | |
1485 | 1489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1841 | 1841 | | |
1842 | 1842 | | |
1843 | 1843 | | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
0 commit comments