Skip to content

Commit aeb933c

Browse files
authored
Merge pull request #39036 from JuliaLang/kf/compilerroundup
Round up and rebase approved compiler PRs
2 parents ad7e59a + 8a2ccf2 commit aeb933c

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

base/compiler/ssair/passes.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
290290
else
291291
def = compact[leaf]
292292
end
293-
if is_tuple_call(compact, def) && isa(field, Int) && 1 <= field < length(def.args)
293+
if is_tuple_call(compact, def) && 1 <= field < length(def.args)
294294
lifted = def.args[1+field]
295295
if is_old(compact, leaf) && isa(lifted, SSAValue)
296296
lifted = OldSSAValue(lifted.id)
@@ -309,8 +309,6 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
309309
end
310310
(isa(typ, DataType) && (!typ.abstract)) || return nothing
311311
@assert !typ.mutable
312-
field = try_compute_fieldidx_expr(typ, stmt)
313-
field === nothing && return nothing
314312
if length(def.args) < 1 + field
315313
ftyp = fieldtype(typ, field)
316314
if !isbitstype(ftyp)
@@ -325,7 +323,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
325323
compact[leaf] = nothing
326324
for i = (length(def.args) + 1):(1+field)
327325
ftyp = fieldtype(typ, i - 1)
328-
isbits(ftyp) || return nothing
326+
isbitstype(ftyp) || return nothing
329327
push!(def.args, insert_node!(compact, leaf, result_t, Expr(:new, ftyp)))
330328
end
331329
compact[leaf] = def
@@ -344,22 +342,22 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
344342
else
345343
typ = compact_exprtype(compact, leaf)
346344
if !isa(typ, Const)
345+
# Disabled since #27126
346+
return nothing
347347
# If the leaf is an old ssa value, insert a getfield here
348348
# We will revisit this getfield later when compaction gets
349349
# to the appropriate point.
350350
# N.B.: This can be a bit dangerous because it can lead to
351351
# infinite loops if we accidentally insert a node just ahead
352352
# of where we are
353-
if is_old(compact, leaf) && (isa(field, Int) || isa(field, Symbol))
353+
if is_old(compact, leaf)
354354
(isa(typ, DataType) && (!typ.abstract)) || return nothing
355355
@assert !typ.mutable
356356
# If there's the potential for an undefref error on access, we cannot insert a getfield
357-
if field > typ.ninitialized && !isbits(fieldtype(typ, field))
358-
return nothing
357+
if field > typ.ninitialized && !isbitstype(fieldtype(typ, field))
359358
lifted_leaves[leaf] = RefValue{Any}(insert_node!(compact, leaf, make_MaybeUndef(result_t), Expr(:call, :unchecked_getfield, SSAValue(leaf.id), field), true))
360359
maybe_undef = true
361360
else
362-
return nothing
363361
lifted_leaves[leaf] = RefValue{Any}(insert_node!(compact, leaf, result_t, Expr(:call, getfield, SSAValue(leaf.id), field), true))
364362
end
365363
continue
@@ -517,8 +515,7 @@ function perform_lifting!(compact::IncrementalCompact,
517515

518516
if stmt_val in keys(lifted_leaves)
519517
stmt_val = lifted_leaves[stmt_val]
520-
else
521-
isa(stmt_val, Union{SSAValue, OldSSAValue}) && stmt_val in keys(reverse_mapping)
518+
elseif isa(stmt_val, Union{NewSSAValue, SSAValue, OldSSAValue}) && stmt_val in keys(reverse_mapping)
522519
stmt_val = RefValue{Any}(lifted_phis[reverse_mapping[stmt_val]].ssa)
523520
end
524521

@@ -673,7 +670,7 @@ function getfield_elim_pass!(ir::IRCode)
673670

674671
isempty(leaves) && continue
675672

676-
field = try_compute_fieldidx_expr(struct_typ, stmt)
673+
field = try_compute_fieldidx(struct_typ, field)
677674
field === nothing && continue
678675

679676
r = lift_leaves(compact, stmt, result_t, field, leaves)
@@ -808,7 +805,7 @@ function getfield_elim_pass!(ir::IRCode)
808805
for stmt in du.uses
809806
ir[SSAValue(stmt)] = compute_value_for_use(ir, domtree, allblocks, du, phinodes, fidx, stmt)
810807
end
811-
if !isbitstype(fieldtype(typ, fidx))
808+
if !isbitstype(ftyp)
812809
for (use, list) in preserve_uses
813810
push!(list, compute_value_for_use(ir, domtree, allblocks, du, phinodes, fidx, use))
814811
end

base/compiler/tfuncs.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ function try_compute_fieldidx(typ::DataType, @nospecialize(field))
695695
if isa(field, Symbol)
696696
field = fieldindex(typ, field, false)
697697
field == 0 && return nothing
698-
elseif isa(field, Integer)
698+
elseif isa(field, Int)
699+
# Numerical field name can only be of type `Int`
699700
max_fields = fieldcount_noerror(typ)
700701
max_fields === nothing && return nothing
701702
(1 <= field <= max_fields) || return nothing
@@ -742,7 +743,8 @@ function getfield_nothrow(@nospecialize(s00), @nospecialize(name), @nospecialize
742743
return false
743744
end
744745

745-
s = unwrap_unionall(widenconst(s00))
746+
s0 = widenconst(s00)
747+
s = unwrap_unionall(s0)
746748
if isa(s, Union)
747749
return getfield_nothrow(rewrap(s.a, s00), name, inbounds) &&
748750
getfield_nothrow(rewrap(s.b, s00), name, inbounds)
@@ -759,6 +761,8 @@ function getfield_nothrow(@nospecialize(s00), @nospecialize(name), @nospecialize
759761
field = try_compute_fieldidx(s, name.val)
760762
field === nothing && return false
761763
field <= s.ninitialized && return true
764+
# `try_compute_fieldidx` already check for field index bound.
765+
!isvatuple(s) && isbitstype(fieldtype(s0, field)) && return true
762766
end
763767

764768
return false

test/compiler/irpasses.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ let K = rand(2,2)
315315
@test test_29253(K) == 2
316316
end
317317

318+
function no_op_refint(r)
319+
r[]
320+
return
321+
end
322+
let code = code_typed(no_op_refint,Tuple{Base.RefValue{Int}})[1].first.code
323+
@test length(code) == 1
324+
@test isa(code[1], Core.ReturnNode)
325+
@test code[1].val === nothing
326+
end
327+
318328
# check getfield elim handling of GlobalRef
319329
const _some_coeffs = (1,[2],3,4)
320330
splat_from_globalref(x) = (x, _some_coeffs...,)

0 commit comments

Comments
 (0)