Skip to content

Commit

Permalink
fix a bug preventing inlining of getindex of const globals (#35239)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1f78749)
  • Loading branch information
JeffBezanson authored and KristofferC committed Apr 4, 2020
1 parent 625be9e commit bc6adcd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc6adcd

Please sign in to comment.