diff --git a/base/compiler/ssair/passes.jl b/base/compiler/ssair/passes.jl index f30860c0324ea..c61527053fe51 100644 --- a/base/compiler/ssair/passes.jl +++ b/base/compiler/ssair/passes.jl @@ -370,6 +370,13 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt), end elseif isa(leaf, QuoteNode) leaf = leaf.value + elseif isa(leaf, GlobalRef) + mod, name = leaf.mod, leaf.name + if isdefined(mod, name) && isconst(mod, name) + leaf = getfield(mod, name) + else + return nothing + end elseif isa(leaf, Union{Argument, Expr}) return nothing end diff --git a/test/compiler/irpasses.jl b/test/compiler/irpasses.jl index 46cc4571b5616..042d91d2ff700 100644 --- a/test/compiler/irpasses.jl +++ b/test/compiler/irpasses.jl @@ -290,3 +290,8 @@ end let K = rand(2,2) @test test_29253(K) == 2 end + +# check getfield elim handling of GlobalRef +const _some_coeffs = (1,[2],3,4) +splat_from_globalref(x) = (x, _some_coeffs...,) +@test splat_from_globalref(0) == (0, 1, [2], 3, 4)