From c1c544e7f82e579cbcbc554b6d24052c2c7af972 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 9 Jan 2020 04:21:31 -0500 Subject: [PATCH] handle `GlobalRef` in getfield elim pass (#34322) (cherry picked from commit 22817ea28366b17a982c00d405edebe8c9571d5c) --- base/compiler/ssair/passes.jl | 7 +++++++ test/compiler/irpasses.jl | 5 +++++ 2 files changed, 12 insertions(+) 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)