From 1f787492c3ac44797941f10c8bd452a1a7eef0f8 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) --- 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 2449cad26d3f1..b1cc75da70942 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -280,7 +280,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 457f3aef07910..245a1ebe293fb 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -282,3 +282,9 @@ end @test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline function f(x) x end)).source) @test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(function f(x) x end)).source) 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