Commit 519fd68
committed
optimizer: simple array SROA
Implements a simple Julia-level array allocation elimination on top of #43888.
```julia
julia> code_typed((String,String)) do s, t
a = Vector{Base.RefValue{String}}(undef, 2)
a[1] = Ref(s)
a[2] = Ref(t)
return a[1][]
end
```
```diff
diff --git a/master b/pr
index 9c8da14380..5b63d08190 100644
--- a/master
+++ b/pr
@@ -1,11 +1,4 @@
1-element Vector{Any}:
CodeInfo(
-1 ─ %1 = $(Expr(:foreigncall, :(:jl_alloc_array_1d), Vector{Base.RefValue{String}}, svec(Any, Int64), 0, :(:ccall), Vector{Base.RefValue{String}}, 2, 2))::Vector{Base.RefValue{String}}
-│ %2 = %new(Base.RefValue{String}, s)::Base.RefValue{String}
-│ Base.arrayset(true, %1, %2, 1)::Vector{Base.RefValue{String}}
-│ %4 = %new(Base.RefValue{String}, t)::Base.RefValue{String}
-│ Base.arrayset(true, %1, %4, 2)::Vector{Base.RefValue{String}}
-│ %6 = Base.arrayref(true, %1, 1)::Base.RefValue{String}
-│ %7 = Base.getfield(%6, :x)::String
-└── return %7
+1 ─ return s
) => String
```
Still this array SROA handle is very limited and able to handle only
trivial examples (though I confirmed this version already eliminates
few array allocations during sysimg build).
For those who interested, I added some discussions on array optimization
[here](https://aviatesk.github.io/EscapeAnalysis.jl/dev/#EA-Array-Analysis).1 parent ae183d8 commit 519fd68
File tree
4 files changed
+505
-166
lines changed- base/compiler
- ssair
- test/compiler
4 files changed
+505
-166
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | | - | |
| 271 | + | |
273 | 272 | | |
274 | 273 | | |
275 | 274 | | |
| |||
295 | 294 | | |
296 | 295 | | |
297 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
298 | 308 | | |
299 | 309 | | |
300 | 310 | | |
| |||
0 commit comments