Skip to content

Commit 07f64c4

Browse files
JeffBezansonKristofferC
authored andcommitted
fix a bug preventing inlining of getindex of const globals (#35239)
1 parent 7b25924 commit 07f64c4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/compiler/optimize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref || is_pure_int
280280
plus_saturate(x::Int, y::Int) = max(x, y, x+y)
281281

282282
# known return type
283-
isknowntype(@nospecialize T) = (T === Union{}) || isconcretetype(T)
283+
isknowntype(@nospecialize T) = (T === Union{}) || isa(T, Const) || isconcretetype(widenconst(T))
284284

285285
function statement_cost(ex::Expr, line::Int, src::CodeInfo, sptypes::Vector{Any}, slottypes::Vector{Any}, params::Params)
286286
head = ex.head

test/compiler/inline.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,9 @@ end
282282
@test ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(@inline function f(x) x end)).source)
283283
@test !ccall(:jl_ast_flag_inlineable, Bool, (Any,), first(methods(function f(x) x end)).source)
284284
end
285+
286+
const _a_global_array = [1]
287+
f_inline_global_getindex() = _a_global_array[1]
288+
let ci = code_typed(f_inline_global_getindex, Tuple{})[1].first
289+
@test any(x->(isexpr(x, :call) && x.args[1] === GlobalRef(Base, :arrayref)), ci.code)
290+
end

0 commit comments

Comments
 (0)