Skip to content

Commit a93bf9a

Browse files
authored
Backports for 1.12.5 (#60612)
2 parents 8c145c1 + 4938a3e commit a93bf9a

File tree

72 files changed

+565
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+565
-196
lines changed

Compiler/src/ssair/ir.jl

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,8 +1373,19 @@ function kill_edge!(ir::IRCode, from::Int, to::Int, callback=nothing)
13731373
kill_edge!(ir.cfg.blocks, from, to, callback)
13741374
end
13751375

1376-
# N.B.: from and to are non-renamed indices
1377-
function kill_edge!(compact::IncrementalCompact, active_bb::Int, from::Int, to::Int)
1376+
@inline function compacted_stmt_range(compact::IncrementalCompact, bb::BasicBlock, active_bb::Int, to::Int)
1377+
to == active_bb && return StmtRange(first(bb.stmts), compact.result_idx - 1)
1378+
return bb.stmts
1379+
end
1380+
1381+
"""
1382+
kill_edge_terminator!(compact::IncrementalCompact, active_bb::Int, from::Int, to::Int)
1383+
1384+
Kill a CFG edge while compacting a terminator in `active_bb`. Assumes all PhiNode
1385+
block statements in `to` have already been processed, so the active BB may only
1386+
scan the compacted prefix when `to == active_bb`. `from` and `to` are non-renamed indices.
1387+
"""
1388+
function kill_edge_terminator!(compact::IncrementalCompact, active_bb::Int, from::Int, to::Int)
13781389
# Note: We recursively kill as many edges as are obviously dead.
13791390
(; bb_rename_pred, bb_rename_succ, result_bbs, domtree) = compact.cfg_transform
13801391
preds = result_bbs[bb_rename_succ[to]].preds
@@ -1390,7 +1401,7 @@ function kill_edge!(compact::IncrementalCompact, active_bb::Int, from::Int, to::
13901401
for succ in copy(to_succs)
13911402
new_succ = findfirst(x::Int->x==succ, bb_rename_pred)
13921403
new_succ === nothing && continue
1393-
kill_edge!(compact, active_bb, to, new_succ)
1404+
kill_edge_terminator!(compact, active_bb, to, new_succ)
13941405
end
13951406
empty!(preds)
13961407
empty!(to_succs)
@@ -1412,8 +1423,9 @@ function kill_edge!(compact::IncrementalCompact, active_bb::Int, from::Int, to::
14121423
# Remove this edge from all phi nodes in `to` block
14131424
# NOTE: It is possible for `to` to contain only `nothing` statements,
14141425
# so we must be careful to stop at its last statement
1415-
if to < active_bb
1416-
stmts = result_bbs[bb_rename_succ[to]].stmts
1426+
if to <= active_bb
1427+
bb = result_bbs[bb_rename_succ[to]]
1428+
stmts = compacted_stmt_range(compact, bb, active_bb, to)
14171429
idx = first(stmts)
14181430
while idx <= last(stmts)
14191431
stmt = compact.result[idx][:stmt]
@@ -1493,14 +1505,14 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
14931505
if cond
14941506
ssa_rename[idx] = nothing
14951507
result[result_idx][:stmt] = nothing
1496-
kill_edge!(compact, active_bb, active_bb, stmt.dest)
1508+
kill_edge_terminator!(compact, active_bb, active_bb, stmt.dest)
14971509
# Don't increment result_idx => Drop this statement
14981510
else
14991511
label = bb_rename_succ[stmt.dest]
15001512
@assert label > 0
15011513
ssa_rename[idx] = SSAValue(result_idx)
15021514
result[result_idx][:stmt] = GotoNode(label)
1503-
kill_edge!(compact, active_bb, active_bb, active_bb+1)
1515+
kill_edge_terminator!(compact, active_bb, active_bb, active_bb+1)
15041516
result_idx += 1
15051517
end
15061518
else
@@ -1675,7 +1687,10 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
16751687
stmt = ssa_rename[stmt.id]
16761688
end
16771689
elseif isa(stmt, NewSSAValue)
1678-
stmt = SSAValue(stmt.id)
1690+
if stmt.id > 0
1691+
# Negative ids reference new_new_nodes and must remain NewSSAValue.
1692+
stmt = SSAValue(stmt.id)
1693+
end
16791694
else
16801695
# Constant assign, replace uses of this ssa value with its result
16811696
end

Compiler/src/typeinfer.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ function codeinfo_for_const(interp::AbstractInterpreter, mi::MethodInstance, @no
10521052
tree.ssaflags = [IR_FLAG_NULL]
10531053
tree.rettype = Core.Typeof(val)
10541054
tree.edges = Core.svec()
1055+
tree.nargs = UInt(nargs)
1056+
tree.isva = method.isva
10551057
set_inlineable!(tree, true)
10561058
tree.parent = mi
10571059
return tree

Compiler/src/typeutils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ function _switchtupleunion(𝕃::AbstractLattice, t::Vector{Any}, i::Int, tunion
277277
_switchtupleunion(𝕃, t, i - 1, tunion, origt)
278278
end
279279
t[i] = origti
280-
elseif has_extended_unionsplit(𝕃) && !isa(ti, Const) && !isvarargtype(ti) && isa(widenconst(ti), Union)
281-
for ty in uniontypes(ti)
280+
elseif (has_extended_unionsplit(𝕃) && !isa(ti, Const) && !isvarargtype(ti) &&
281+
(wty = widenconst(ti); isa(wty, Union)))
282+
for ty in uniontypes(wty)
282283
t[i] = ty
283284
_switchtupleunion(𝕃, t, i - 1, tunion, origt)
284285
end

Compiler/test/inference.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,15 @@ end == Integer
25912591
Val(isdefined(xxx.value, :x))
25922592
end == Val{true}
25932593

2594+
# Test union splitting for MustAlias
2595+
struct GetSomethingA; x::Union{Nothing,Int}; end
2596+
struct GetSomethingB; x::Int; end
2597+
getsomethingx(a::GetSomethingA) = something(a.x, 0)
2598+
getsomethingx(b::GetSomethingB) = b.x
2599+
@test Base.infer_return_type((Union{GetSomethingA,GetSomethingB},); interp=MustAliasInterpreter()) do x
2600+
getsomethingx(x)
2601+
end == Int
2602+
25942603
@testset "issue #56913: `BoundsError` in type inference" begin
25952604
R = UnitRange{Int}
25962605
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})

Compiler/test/irpasses.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,3 +2059,19 @@ let src = code_typed1((Vector{Any},)) do xs
20592059
end
20602060
@test count(iscall((src, Core.svec)), src.code) == 1
20612061
end
2062+
2063+
# Negative NewSSAValue ids must be preserved during compaction
2064+
function f_57827(op, init, x)
2065+
v = op(init, x)
2066+
i = 0
2067+
while i < 1
2068+
v = op(v, x)
2069+
i += 1
2070+
end
2071+
return v
2072+
end
2073+
let rf = (acc, x) -> ifelse(x > acc[1], (x,), (acc[1],))
2074+
@test f_57827(rf, (0.0,), 1) === (1,)
2075+
ir = first(only(Base.code_ircode(f_57827, (typeof(rf), Tuple{Float64}, Int64); optimize_until="CC: SROA")))
2076+
@test ir isa Compiler.IRCode
2077+
end

Compiler/test/ssair.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ let cfg = CFG(BasicBlock[
108108
@test length(compact.cfg_transform.result_bbs) == 4 && 0 in compact.cfg_transform.result_bbs[3].preds
109109
end
110110

111+
# Test that removing a self-edge during compaction only scans compacted phi statements.
112+
let code = Any[
113+
# Block 1
114+
Compiler.GotoNode(2),
115+
# Block 2
116+
Core.PhiNode(Int32[1, 3], Any[1, 2]),
117+
Compiler.GotoIfNot(true, 2),
118+
# Block 3
119+
Compiler.ReturnNode(0),
120+
]
121+
ir = make_ircode(code)
122+
ir = Compiler.compact!(ir, true)
123+
@test Compiler.verify_ir(ir) === nothing
124+
end
125+
111126
# Issue #32579 - Optimizer bug involving type constraints
112127
function f32579(x::Int, b::Bool)
113128
if b
@@ -838,3 +853,31 @@ end
838853
let ir = Base.code_ircode(_worker_task57153, (), optimize_until="CC: COMPACT_2")[1].first
839854
@test findfirst(x->x==0, ir.cfg.blocks[1].preds) !== nothing
840855
end
856+
857+
# codeinfo_for_const should set nargs and isva
858+
let
859+
_const_return_func(@nospecialize(x)) = 42
860+
mi = Compiler.specialize_method(only(methods(_const_return_func)), Tuple{typeof(_const_return_func), Int}, Core.svec())
861+
ci = Compiler.codeinfo_for_const(Compiler.NativeInterpreter(), mi, 42)
862+
@test ci.nargs == 2
863+
@test ci.isva == false
864+
# inflate_ir! should succeed now that nargs/isva are set
865+
ir = Compiler.inflate_ir!(ci, mi)
866+
@test ir isa Compiler.IRCode
867+
end
868+
869+
# Tests that CFG edge cleanup during compaction doesn't corrupt iteration codegen.
870+
Trips_60660 = let
871+
Ts = (Float64, Float32)
872+
[(Ta, Tb, Tc) for Ta in Ts for Tb in Ts for Tc in Ts]
873+
end
874+
@test Trips_60660 == [
875+
(Float64, Float64, Float64),
876+
(Float64, Float64, Float32),
877+
(Float64, Float32, Float64),
878+
(Float64, Float32, Float32),
879+
(Float32, Float64, Float64),
880+
(Float32, Float64, Float32),
881+
(Float32, Float32, Float64),
882+
(Float32, Float32, Float32),
883+
]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ default: $(JULIA_BUILD_MODE) # contains either "debug" or "release"
2626
all: debug release
2727

2828
# sort is used to remove potential duplicates
29-
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/stdlib $(build_man1dir))
29+
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_private_libexecdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/stdlib $(build_man1dir))
3030
ifneq ($(BUILDROOT),$(JULIAHOME))
3131
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/clangsa test/embedding test/gcext test/llvmpasses)
3232
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk $(BUILDROOT)/pkgimage.mk

base/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ endif
183183
endef
184184

185185
# libexec executables
186-
symlink_p7zip: $(build_bindir)/7z$(EXE)
186+
symlink_p7zip: $(build_private_libexecdir)/7z$(EXE)
187187

188188
ifneq ($(USE_SYSTEM_P7ZIP),0)
189189
SYMLINK_SYSTEM_LIBRARIES += symlink_p7zip
190190
7Z_PATH := $(shell which 7z$(EXE))
191191
endif
192192

193-
$(build_bindir)/7z$(EXE):
193+
$(build_private_libexecdir)/7z$(EXE):
194194
[ -e "$(7Z_PATH)" ] && \
195195
rm -f "$@" && \
196196
ln -sf "$(7Z_PATH)" "$@"

base/fastmath.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,13 @@ exp10_fast(x::Union{Float32,Float64}) = Base.Math.exp10_fast(x)
297297

298298
# builtins
299299

300-
@inline function pow_fast(x::Float64, y::Integer)
300+
@inline function pow_fast(x::Union{Float32, Float64}, y::Integer)
301301
z = y % Int32
302302
z == y ? pow_fast(x, z) : x^y
303303
end
304-
pow_fast(x::Float32, y::Integer) = x^y
305-
pow_fast(x::Float64, y::Int32) = ccall("llvm.powi.f64.i32", llvmcall, Float64, (Float64, Int32), x, y)
304+
@inline pow_fast(x::Float16, y::Integer) = Float16(pow_fast(Float32(x), y))
305+
pow_fast(x::Float64, y::Int32) = ccall("llvm.powi", llvmcall, Float64, (Float64, Int32), x, y)
306+
pow_fast(x::Float32, y::Int32) = ccall("llvm.powi", llvmcall, Float32, (Float32, Int32), x, y)
306307
pow_fast(x::FloatTypes, ::Val{p}) where {p} = pow_fast(x, p) # inlines already via llvm.powi
307308
@inline pow_fast(x, v::Val) = Base.literal_pow(^, x, v)
308309

base/file.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ struct DirEntry
10591059
end
10601060
function Base.getproperty(obj::DirEntry, p::Symbol)
10611061
if p === :path
1062-
return joinpath(obj.dir, obj.name)
1062+
return joinpath(getfield(obj, :dir), getfield(obj, :name))
10631063
else
10641064
return getfield(obj, p)
10651065
end

0 commit comments

Comments
 (0)