From bc6adcdad7cac9080afe223a6294876e4bfb8795 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 25 Mar 2020 11:03:34 -0400 Subject: [PATCH] fix a bug preventing inlining of getindex of const globals (#35239) (cherry picked from commit 1f787492c3ac44797941f10c8bd452a1a7eef0f8) --- base/compiler/optimize.jl | 2 +- test/compiler/inline.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base/compiler/optimize.jl b/base/compiler/optimize.jl index 38d8a6ea4b377..f46c5c96243c7 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -275,7 +275,7 @@ intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref || is_pure_int plus_saturate(x::Int, y::Int) = max(x, y, x+y) # known return type -isknowntype(@nospecialize T) = (T === Union{}) || isconcretetype(T) +isknowntype(@nospecialize T) = (T === Union{}) || isa(T, Const) || isconcretetype(widenconst(T)) function statement_cost(ex::Expr, line::Int, src::CodeInfo, sptypes::Vector{Any}, slottypes::Vector{Any}, params::Params) head = ex.head diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index 5dafed1e422f6..db037763631f1 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -275,3 +275,9 @@ let ci = code_typed(f34900, Tuple{Int, Int})[1].first @test length(ci.code) == 1 && isexpr(ci.code[1], :return) && ci.code[1].args[1].id == 2 end + +const _a_global_array = [1] +f_inline_global_getindex() = _a_global_array[1] +let ci = code_typed(f_inline_global_getindex, Tuple{})[1].first + @test any(x->(isexpr(x, :call) && x.args[1] === GlobalRef(Base, :arrayref)), ci.code) +end