Skip to content

Commit

Permalink
inlining: remove ineffective handling for unmatched params (#52092)
Browse files Browse the repository at this point in the history
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 318b21b09b..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)
```
  • Loading branch information
aviatesk committed Mar 15, 2024
1 parent 06d5ca1 commit a66bbfa
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,10 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
nunion === nothing && return nothing
cases = InliningCase[]
argtypes = sig.argtypes
local handled_all_cases::Bool = true
local revisit_idx = local only_method = nothing
local meth::MethodLookupResult
local handled_all_cases = local fully_covered = true
local revisit_idx = nothing
local all_result_count = 0
local joint_effects::Effects = EFFECTS_TOTAL
local fully_covered::Bool = true
local joint_effects = EFFECTS_TOTAL
for i = 1:nunion
meth = getsplit(info, i)
if meth.ambig
Expand All @@ -1368,18 +1366,8 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
# No applicable methods; try next union split
handled_all_cases = false
continue
else
if length(meth) == 1 && only_method !== missing
if only_method === nothing
only_method = meth[1].method
elseif only_method !== meth[1].method
only_method = missing
end
else
only_method = missing
end
end
local split_fully_covered::Bool = false
local split_fully_covered = false
for (j, match) in enumerate(meth)
all_result_count += 1
result = getresult(info, all_result_count)
Expand All @@ -1406,33 +1394,17 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig

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

if handled_all_cases && revisit_idx !== nothing
# we handled everything except one match with unmatched sparams,
# so try to handle it by bypassing validate_sparams
(i, j, k) = revisit_idx
match = getsplit(info, i)[j]
result = getresult(info, k)
handled_all_cases &= handle_any_const_result!(cases,
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
elseif length(cases) == 0 && only_method isa Method
# if the signature is fully covered and there is only one applicable method,
# we can try to inline it even in the presence of unmatched sparams
# -- But don't try it if we already tried to handle the match in the revisit_idx
# case, because that'll (necessarily) be the same method.
if nsplit(info)::Int > 1
atype = argtypes_to_type(argtypes)
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), atype, only_method.sig)::SimpleVector
match = MethodMatch(metharg, methsp::SimpleVector, only_method, true)
result = nothing
else
@assert length(meth) == 1
match = meth[1]
result = getresult(info, 1)
if handled_all_cases
if revisit_idx !== nothing
# we handled everything except one match with unmatched sparams,
# so try to handle it by bypassing validate_sparams
(i, j, k) = revisit_idx
match = getsplit(info, i)[j]
result = getresult(info, k)
handled_all_cases &= handle_any_const_result!(cases,
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
end
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
elseif !handled_all_cases
elseif !isempty(cases)
# if we've not seen all candidates, union split is valid only for dispatch tuples
filter!(case::InliningCase->isdispatchtuple(case.sig), cases)
end
Expand Down

0 comments on commit a66bbfa

Please sign in to comment.