Skip to content

Commit 7fc8646

Browse files
authored
Extend ifelse lifting to regular SROA (#50403)
* Extend ifelse lifting to regular SROA * Fix oracle violation This is a pre-existing bug, but was exposed by my improvements to SROA.
1 parent 02272f0 commit 7fc8646

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

β€Žbase/compiler/ssair/ir.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,9 @@ function insert_node!(compact::IncrementalCompact, @nospecialize(before), newins
879879
return os
880880
end
881881
elseif isa(before, NewSSAValue)
882+
# As above, new_new_nodes must get counted. We don't visit them during our compact,
883+
# so they're immediately considered reified.
884+
count_added_node!(compact, newinst.stmt)
882885
# TODO: This is incorrect and does not maintain ordering among the new nodes
883886
before_entry = compact.new_new_nodes.info[-before.id]
884887
newline = something(newinst.line, compact.new_new_nodes.stmts[-before.id][:line])

β€Žbase/compiler/ssair/passes.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ function lift_comparison!(::typeof(isdefined), compact::IncrementalCompact,
563563
lift_comparison_leaves!(isdefined_tfunc, compact, val, cmp, lifting_cache, idx, 𝕃ₒ)
564564
end
565565

566+
function phi_or_ifelse_predecessors(@nospecialize(def), compact::IncrementalCompact)
567+
isa(def, PhiNode) && return def.values
568+
is_known_call(def, Core.ifelse, compact) && return def.args[3:4]
569+
return nothing
570+
end
571+
566572
function lift_comparison_leaves!(@specialize(tfunc),
567573
compact::IncrementalCompact, @nospecialize(val), @nospecialize(cmp),
568574
lifting_cache::IdDict{Pair{AnySSAValue, Any}, AnySSAValue}, idx::Int,
@@ -573,12 +579,8 @@ function lift_comparison_leaves!(@specialize(tfunc),
573579
end
574580
isa(typeconstraint, Union) || return # bail out if there won't be a good chance for lifting
575581

576-
predecessors = function (@nospecialize(def), compact::IncrementalCompact)
577-
isa(def, PhiNode) && return def.values
578-
is_known_call(def, Core.ifelse, compact) && return def.args[3:4]
579-
return nothing
580-
end
581-
leaves, visited_philikes = collect_leaves(compact, val, typeconstraint, 𝕃ₒ, predecessors)
582+
583+
leaves, visited_philikes = collect_leaves(compact, val, typeconstraint, 𝕃ₒ, phi_or_ifelse_predecessors)
582584
length(leaves) ≀ 1 && return # bail out if we don't have multiple leaves
583585

584586
# check if we can evaluate the comparison for each one of the leaves
@@ -1093,11 +1095,10 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
10931095
end
10941096

10951097
# perform SROA on immutable structs here on
1096-
10971098
field = try_compute_fieldidx_stmt(compact, stmt, struct_typ)
10981099
field === nothing && continue
10991100

1100-
leaves, visited_philikes = collect_leaves(compact, val, struct_typ, 𝕃ₒ)
1101+
leaves, visited_philikes = collect_leaves(compact, val, struct_typ, 𝕃ₒ, phi_or_ifelse_predecessors)
11011102
isempty(leaves) && continue
11021103

11031104
lifted_result = lift_leaves(compact, field, leaves, 𝕃ₒ)

0 commit comments

Comments
Β (0)