Skip to content

Commit f4d1750

Browse files
authored
ir: Consider Argument a useref (#58467)
A common usecase for `userefs` is to replace an embedded `Argument` by something else (e.g. for inlining like operations). This allows this to be written as a single `userefs` loop rather than adding an additional if case for `Argument`.
1 parent bb28ea8 commit f4d1750

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Compiler/src/ssair/ir.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ end
609609
elseif isa(stmt, EnterNode)
610610
op == 1 || throw(BoundsError())
611611
stmt = EnterNode(stmt.catch_dest, v)
612-
elseif isa(stmt, Union{AnySSAValue, GlobalRef})
612+
elseif isa(stmt, Union{AnySSAValue, Argument, GlobalRef})
613613
op == 1 || throw(BoundsError())
614614
stmt = v
615615
elseif isa(stmt, UpsilonNode)
@@ -640,7 +640,7 @@ end
640640
function userefs(@nospecialize(x))
641641
relevant = (isa(x, Expr) && is_relevant_expr(x)) ||
642642
isa(x, GotoIfNot) || isa(x, ReturnNode) || isa(x, SSAValue) || isa(x, OldSSAValue) || isa(x, NewSSAValue) ||
643-
isa(x, PiNode) || isa(x, PhiNode) || isa(x, PhiCNode) || isa(x, UpsilonNode) || isa(x, EnterNode)
643+
isa(x, PiNode) || isa(x, PhiNode) || isa(x, PhiCNode) || isa(x, UpsilonNode) || isa(x, EnterNode) || isa(x, Argument)
644644
return UseRefIterator(x, relevant)
645645
end
646646

Compiler/test/ssair.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ let
459459
@test stmt.cond === v
460460
elseif isa(stmt, ReturnNode) || isa(stmt, UpsilonNode)
461461
@test stmt.val === v
462-
elseif isa(stmt, SSAValue) || isa(stmt, NewSSAValue)
462+
elseif isa(stmt, SSAValue) || isa(stmt, NewSSAValue) || isa(stmt, Argument)
463463
@test stmt === v
464464
elseif isa(stmt, PiNode)
465465
@test stmt.val === v && stmt.typ === typeof(stmt)
@@ -508,6 +508,7 @@ let
508508
GotoNode(5),
509509
SSAValue(7),
510510
NewSSAValue(9),
511+
Argument(1),
511512
ReturnNode(SSAValue(11)),
512513
]
513514

0 commit comments

Comments
 (0)