Skip to content

Commit 9bd2432

Browse files
authored
cfg_simplify: Fix bug in my bugfix (#52337)
The fix in #52323 was not quite correct. Fix that and adjust the test to more accurately reflect the actual issue.
1 parent de525af commit 9bd2432

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

base/compiler/ssair/passes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,9 +2336,9 @@ function cfg_simplify!(ir::IRCode)
23362336
end
23372337
elseif new_edge == -1
23382338
@assert length(phi.edges) == 1
2339-
if isassigned(phi.values, old_index)
2339+
if isassigned(renamed_values, old_index)
23402340
push!(edges, -1)
2341-
push!(values, phi.values[old_index])
2341+
push!(values, renamed_values[old_index])
23422342
end
23432343
elseif new_edge == -3
23442344
# Multiple predecessors, we need to expand out this phi

test/compiler/irpasses.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,17 +1576,21 @@ end
15761576
# Test CFG simplify with single predecessor phi node
15771577
let code = Any[
15781578
# Block 1
1579-
Expr(:call, Base.inferencebarrier, 1),
15801579
GotoNode(3),
15811580
# Block 2
1582-
PhiNode(Int32[1], Any[SSAValue(1)]),
1583-
ReturnNode(SSAValue(3))
1581+
nothing,
1582+
# Block 3
1583+
Expr(:call, Base.inferencebarrier, 1),
1584+
GotoNode(5),
1585+
# Block 4
1586+
PhiNode(Int32[4], Any[SSAValue(3)]),
1587+
ReturnNode(SSAValue(5))
15841588
]
15851589
ir = make_ircode(code)
15861590
ir = Core.Compiler.cfg_simplify!(ir)
15871591
Core.Compiler.verify_ir(ir)
1588-
@test length(ir.cfg.blocks) == 1
1592+
@test length(ir.cfg.blocks) <= 2
15891593
ir = Core.Compiler.compact!(ir)
1590-
@test length(ir.stmts) == 2
1591-
@test (ir[SSAValue(2)][:stmt]::ReturnNode).val == SSAValue(1)
1594+
@test length(ir.stmts) <= 3
1595+
@test (ir[SSAValue(length(ir.stmts))][:stmt]::ReturnNode).val !== nothing
15921596
end

0 commit comments

Comments
 (0)