Commit 89a613b
authored
optimizer: eliminate more
Follows up #44708 -- in that PR I missed the most obvious optimization
opportunity, i.e. we can safely eliminate `isdefined` checks when all
fields are defined at allocation site.
This change allows us to eliminate capturing closure constructions when
the body and callsite of capture closure is available within a optimized
frame, e.g.:
```julia
function abmult(r::Int, x0)
if r < 0
r = -r
end
f = x -> x * r
return @inline f(x0)
end
```
```diff
diff --git a/_master.jl b/_pr.jl
index ea06d865b75..c38f221090f 100644
--- a/_master.jl
+++ b/_pr.jl
@@ -1,24 +1,19 @@
julia> @code_typed abmult(-3, 3)
CodeInfo(
-1 ── %1 = Core.Box::Type{Core.Box}
-│ %2 = %new(%1, r@_2)::Core.Box
-│ %3 = Core.isdefined(%2, :contents)::Bool
-└─── goto #3 if not %3
+1 ── goto #3 if not true
2 ── goto #4
3 ── $(Expr(:throw_undef_if_not, :r, false))::Any
-4 ┄─ %7 = (r@_2 < 0)::Any
-└─── goto #9 if not %7
-5 ── %9 = Core.isdefined(%2, :contents)::Bool
-└─── goto #7 if not %9
+4 ┄─ %4 = (r@_2 < 0)::Any
+└─── goto #9 if not %4
+5 ── goto #7 if not true
6 ── goto #8
7 ── $(Expr(:throw_undef_if_not, :r, false))::Any
-8 ┄─ %13 = -r@_2::Any
-9 ┄─ %14 = φ (#4 => r@_2, #8 => %13)::Any
-│ %15 = Core.isdefined(%2, :contents)::Bool
-└─── goto #11 if not %15
+8 ┄─ %9 = -r@_2::Any
+9 ┄─ %10 = φ (#4 => r@_2, #8 => %9)::Any
+└─── goto #11 if not true
10 ─ goto #12
11 ─ $(Expr(:throw_undef_if_not, :r, false))::Any
-12 ┄ %19 = (x0 * %14)::Any
+12 ┄ %14 = (x0 * %10)::Any
└─── goto #13
-13 ─ return %19
+13 ─ return %14
) => Any
```isdefined checks (#44755)1 parent b297cc4 commit 89a613b
2 files changed
+35
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 375 | + | |
379 | 376 | | |
380 | 377 | | |
381 | 378 | | |
| |||
786 | 783 | | |
787 | 784 | | |
788 | 785 | | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
| 786 | + | |
793 | 787 | | |
794 | 788 | | |
795 | 789 | | |
| |||
948 | 942 | | |
949 | 943 | | |
950 | 944 | | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
| 945 | + | |
955 | 946 | | |
956 | 947 | | |
957 | 948 | | |
| |||
1023 | 1014 | | |
1024 | 1015 | | |
1025 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
1026 | 1024 | | |
1027 | 1025 | | |
1028 | 1026 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
496 | 521 | | |
497 | 522 | | |
498 | 523 | | |
| |||
0 commit comments