Skip to content

Commit a66bbfa

Browse files
committed
inlining: remove ineffective handling for unmatched params (#52092)
The deleted branch was added in #45062, although it had not been tested. I tried the following diff to find cases optimized by that, but I just found the handling proved to be in vain in all cases I tried. ```diff diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index 318b21b..7e42a65aa4 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -1473,6 +1473,14 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig handle_any_const_result!(cases, result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true) fully_covered = handled_all_cases = match.fully_covers + if length(cases) == 1 && fully_covered + println("first case: ", only_method) + elseif length(cases) == 1 + atype = argtypes_to_type(sig.argtypes) + if atype isa DataType && cases[1].sig isa DataType + println("second case: ", only_method) + end + end elseif !handled_all_cases # if we've not seen all candidates, union split is valid only for dispatch tuples filter!(case::InliningCase->isdispatchtuple(case.sig), cases) ```
1 parent 06d5ca1 commit a66bbfa

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,10 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13521352
nunion === nothing && return nothing
13531353
cases = InliningCase[]
13541354
argtypes = sig.argtypes
1355-
local handled_all_cases::Bool = true
1356-
local revisit_idx = local only_method = nothing
1357-
local meth::MethodLookupResult
1355+
local handled_all_cases = local fully_covered = true
1356+
local revisit_idx = nothing
13581357
local all_result_count = 0
1359-
local joint_effects::Effects = EFFECTS_TOTAL
1360-
local fully_covered::Bool = true
1358+
local joint_effects = EFFECTS_TOTAL
13611359
for i = 1:nunion
13621360
meth = getsplit(info, i)
13631361
if meth.ambig
@@ -1368,18 +1366,8 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13681366
# No applicable methods; try next union split
13691367
handled_all_cases = false
13701368
continue
1371-
else
1372-
if length(meth) == 1 && only_method !== missing
1373-
if only_method === nothing
1374-
only_method = meth[1].method
1375-
elseif only_method !== meth[1].method
1376-
only_method = missing
1377-
end
1378-
else
1379-
only_method = missing
1380-
end
13811369
end
1382-
local split_fully_covered::Bool = false
1370+
local split_fully_covered = false
13831371
for (j, match) in enumerate(meth)
13841372
all_result_count += 1
13851373
result = getresult(info, all_result_count)
@@ -1406,33 +1394,17 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
14061394

14071395
(handled_all_cases & fully_covered) || (joint_effects = Effects(joint_effects; nothrow=false))
14081396

1409-
if handled_all_cases && revisit_idx !== nothing
1410-
# we handled everything except one match with unmatched sparams,
1411-
# so try to handle it by bypassing validate_sparams
1412-
(i, j, k) = revisit_idx
1413-
match = getsplit(info, i)[j]
1414-
result = getresult(info, k)
1415-
handled_all_cases &= handle_any_const_result!(cases,
1416-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1417-
elseif length(cases) == 0 && only_method isa Method
1418-
# if the signature is fully covered and there is only one applicable method,
1419-
# we can try to inline it even in the presence of unmatched sparams
1420-
# -- But don't try it if we already tried to handle the match in the revisit_idx
1421-
# case, because that'll (necessarily) be the same method.
1422-
if nsplit(info)::Int > 1
1423-
atype = argtypes_to_type(argtypes)
1424-
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), atype, only_method.sig)::SimpleVector
1425-
match = MethodMatch(metharg, methsp::SimpleVector, only_method, true)
1426-
result = nothing
1427-
else
1428-
@assert length(meth) == 1
1429-
match = meth[1]
1430-
result = getresult(info, 1)
1397+
if handled_all_cases
1398+
if revisit_idx !== nothing
1399+
# we handled everything except one match with unmatched sparams,
1400+
# so try to handle it by bypassing validate_sparams
1401+
(i, j, k) = revisit_idx
1402+
match = getsplit(info, i)[j]
1403+
result = getresult(info, k)
1404+
handled_all_cases &= handle_any_const_result!(cases,
1405+
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
14311406
end
1432-
handle_any_const_result!(cases,
1433-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1434-
fully_covered = handled_all_cases = match.fully_covers
1435-
elseif !handled_all_cases
1407+
elseif !isempty(cases)
14361408
# if we've not seen all candidates, union split is valid only for dispatch tuples
14371409
filter!(case::InliningCase->isdispatchtuple(case.sig), cases)
14381410
end

0 commit comments

Comments
 (0)