Skip to content

Commit 715eb1d

Browse files
authored
reland "Inlining: Remove outdated code path for GlobalRef movement (JuliaLang#46880)" (JuliaLang#56382)
From the description of the original PR: > We used to not allow `GlobalRef` in `PhiNode` at all (because they > could have side effects). However, we then change the IR to make > side-effecting `GlobalRef`s illegal in statement position in general, > so now `PhiNode`s values are just regular value position, so there's > no reason any more to try to move `GlobalRef`s out to statement > position in inlining. Moreover, doing so introduces a bunch of > unnecessary `GlobalRef`s that weren't being moved back. We could fix > that separately by setting appropriate flags, but it's simpler to just > get rid of this special case entirely. This change itself does not sound to have any issues, and in fact, it is very useful for keeping the IR slim, especially in code generated by Cassette-like systems, so I would like to reland it. However, the original PR was reverted in JuliaLang#46951 due to bugs like JuliaLang#46940 and JuliaLang#46943. I could not reproduce these bugs on my end (maybe they have been fixed on some GC-side fixes?), so I believe relanding the original PR’s changes would not cause any issues, but it is necessary to confirm that similar problems do not arise before merging this PR.
1 parent 9d1cedb commit 715eb1d

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -665,18 +665,6 @@ function batch_inline!(ir::IRCode, todo::Vector{Pair{Int,Any}}, propagate_inboun
665665
compact.active_result_bb -= 1
666666
refinish = true
667667
end
668-
# It is possible for GlobalRefs and Exprs to be in argument position
669-
# at this point in the IR, though in that case they are required
670-
# to be effect-free. However, we must still move them out of argument
671-
# position, since `Argument` is allowed in PhiNodes, but `GlobalRef`
672-
# and `Expr` are not, so a substitution could anger the verifier.
673-
for aidx in 1:length(argexprs)
674-
aexpr = argexprs[aidx]
675-
if isa(aexpr, Expr) || isa(aexpr, GlobalRef)
676-
ninst = removable_if_unused(NewInstruction(aexpr, argextype(aexpr, compact), compact.result[idx][:line]))
677-
argexprs[aidx] = insert_node_here!(compact, ninst)
678-
end
679-
end
680668
if isa(item, InliningTodo)
681669
compact.ssa_rename[old_idx] = ir_inline_item!(compact, idx, argexprs, item, boundscheck, state.todo_bbs)
682670
elseif isa(item, UnionSplit)

test/compiler/EscapeAnalysis/EscapeAnalysis.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ end
671671
@test has_all_escape(result.state[Argument(3)]) # b
672672
end
673673
let result = @eval EATModule() begin
674-
const Rx = SafeRef{String}("Rx")
675-
$code_escapes((String,)) do s
674+
const Rx = SafeRef(Ref(""))
675+
$code_escapes((Base.RefValue{String},)) do s
676676
Rx[] = s
677677
Core.sizeof(Rx[])
678678
end

test/compiler/inline.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,3 +2282,10 @@ let;Base.Experimental.@force_compile
22822282
f_EA_finalizer(42000)
22832283
@test foreign_buffer_checker.finalized
22842284
end
2285+
2286+
# Test that inlining doesn't unnecessarily move things to statement position
2287+
@noinline f_noinline_invoke(x::Union{Symbol,Nothing}=nothing) = Core.donotdelete(x)
2288+
g_noinline_invoke(x) = f_noinline_invoke(x)
2289+
let src = code_typed1(g_noinline_invoke, (Union{Symbol,Nothing},))
2290+
@test !any(@nospecialize(x)->isa(x,GlobalRef), src.code)
2291+
end

0 commit comments

Comments
 (0)