Skip to content

Commit e69f87d

Browse files
Kenoaviatesk
authored andcommitted
sroa: Lift restriction that all_same optimization must give SSAValue
This restriction has been in there since this code was added in #44557. Unfortunately, I can't tell from the commit history why this restriction was added. It's possible that it was trying to avoid putting things into statement position that were not allowed in the phi block, but we have cleaned that up since (#50308 and related), so let's see if this restriction is still required, since I was seeing some suboptimial optimization results because of this.
1 parent 58c1d51 commit e69f87d

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ function ssa_substitute_op!(insert_node!::Inserter, subst_inst::Instruction, @no
19181918
end
19191919
end
19201920
end
1921-
isa(val, Union{SSAValue, NewSSAValue}) && return val # avoid infinite loop
1921+
isa(val, Union{SSAValue, OldSSAValue, NewSSAValue}) && return val # avoid infinite loop
19221922
urs = userefs(val)
19231923
for op in urs
19241924
op[] = ssa_substitute_op!(insert_node!, subst_inst, op[], ssa_substitute)

base/compiler/ssair/ir.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ struct UndefToken end; const UNDEF_TOKEN = UndefToken()
464464
isdefined(stmt, :val) || return OOB_TOKEN
465465
op == 1 || return OOB_TOKEN
466466
return stmt.val
467-
elseif isa(stmt, Union{SSAValue, NewSSAValue, GlobalRef})
467+
elseif isa(stmt, Union{SSAValue, OldSSAValue, NewSSAValue, GlobalRef})
468468
op == 1 || return OOB_TOKEN
469469
return stmt
470470
elseif isa(stmt, UpsilonNode)
@@ -520,7 +520,7 @@ end
520520
elseif isa(stmt, ReturnNode)
521521
op == 1 || throw(BoundsError())
522522
stmt = typeof(stmt)(v)
523-
elseif isa(stmt, Union{SSAValue, NewSSAValue, GlobalRef})
523+
elseif isa(stmt, Union{SSAValue, OldSSAValue, NewSSAValue, GlobalRef})
524524
op == 1 || throw(BoundsError())
525525
stmt = v
526526
elseif isa(stmt, UpsilonNode)
@@ -550,7 +550,7 @@ end
550550

551551
function userefs(@nospecialize(x))
552552
relevant = (isa(x, Expr) && is_relevant_expr(x)) ||
553-
isa(x, GotoIfNot) || isa(x, ReturnNode) || isa(x, SSAValue) || isa(x, NewSSAValue) ||
553+
isa(x, GotoIfNot) || isa(x, ReturnNode) || isa(x, SSAValue) || isa(x, OldSSAValue) || isa(x, NewSSAValue) ||
554554
isa(x, PiNode) || isa(x, PhiNode) || isa(x, PhiCNode) || isa(x, UpsilonNode) || isa(x, EnterNode)
555555
return UseRefIterator(x, relevant)
556556
end

base/compiler/ssair/passes.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -678,24 +678,28 @@ function perform_lifting!(compact::IncrementalCompact,
678678
end
679679
end
680680

681-
the_leaf_val = isa(the_leaf, LiftedValue) ? the_leaf.val : nothing
682-
if !isa(the_leaf_val, SSAValue)
683-
all_same = false
684-
end
685-
686-
if all_same
681+
if all_same && isa(the_leaf, LiftedValue)
687682
dominates_all = true
688-
if lazydomtree !== nothing
689-
domtree = get!(lazydomtree)
690-
for item in visited_philikes
691-
if !dominates_ssa(compact, domtree, the_leaf_val, item)
692-
dominates_all = false
693-
break
683+
the_leaf_val = the_leaf.val
684+
if isa(the_leaf_val, Union{SSAValue, OldSSAValue})
685+
if lazydomtree === nothing
686+
# Must conservatively assume this
687+
dominates_all = false
688+
else
689+
domtree = get!(lazydomtree)
690+
for item in visited_philikes
691+
if !dominates_ssa(compact, domtree, the_leaf_val, item)
692+
dominates_all = false
693+
break
694+
end
694695
end
695696
end
696-
if dominates_all
697-
return the_leaf
697+
end
698+
if dominates_all
699+
if isa(the_leaf, OldSSAValue)
700+
the_leaf = simple_walk(compact, the_leaf)
698701
end
702+
return the_leaf
699703
end
700704
end
701705

0 commit comments

Comments
 (0)