Skip to content

Commit 55759af

Browse files
committed
fix bug related to block renaming for DCE
1 parent 4f17558 commit 55759af

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

base/compiler/ssair/ir.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,14 @@ end
10011001

10021002
function finish_current_bb!(compact, active_bb, old_result_idx=compact.result_idx, unreachable=false)
10031003
if compact.active_result_bb > length(compact.result_bbs)
1004-
#@assert compact.bb_rename[active_bb] == 0
1004+
#@assert compact.bb_rename[active_bb] == -1
10051005
return true
10061006
end
10071007
bb = compact.result_bbs[compact.active_result_bb]
10081008
# If this was the last statement in the BB and we decided to skip it, insert a
10091009
# dummy `nothing` node, to prevent changing the structure of the CFG
10101010
skipped = false
1011-
if !compact.cfg_transforms_enabled || active_bb == 0 || active_bb > length(compact.bb_rename_succ) || compact.bb_rename_succ[active_bb] != 0
1011+
if !compact.cfg_transforms_enabled || active_bb == 0 || active_bb > length(compact.bb_rename_succ) || compact.bb_rename_succ[active_bb] != -1
10121012
if compact.result_idx == first(bb.stmts)
10131013
length(compact.result) < old_result_idx && resize!(compact, old_result_idx)
10141014
if unreachable

test/compiler/ssair.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,34 @@ function f32579(x::Int, b::Bool)
132132
end
133133
@test f32579(0, true) === true
134134
@test f32579(0, false) === false
135+
136+
# Test for bug caused by renaming blocks improperly, related to PR #32145
137+
using Base.Meta
138+
let ci = (Meta.@lower 1 + 1).args[1]
139+
ci.code = [
140+
# block 1
141+
Core.Compiler.GotoIfNot(Expr(:boundscheck), 6),
142+
# block 2
143+
Expr(:call, GlobalRef(Base, :size), Core.Compiler.Argument(3)),
144+
Core.Compiler.ReturnNode(),
145+
# block 3
146+
Core.PhiNode(),
147+
Core.Compiler.ReturnNode(),
148+
# block 4
149+
Expr(:call,
150+
GlobalRef(Main, :something),
151+
GlobalRef(Main, :somethingelse)),
152+
Core.Compiler.GotoIfNot(Core.SSAValue(6), 9),
153+
# block 5
154+
Core.Compiler.ReturnNode(Core.SSAValue(6)),
155+
# block 6
156+
Core.Compiler.ReturnNode(Core.SSAValue(6))
157+
]
158+
nstmts = length(ci.code)
159+
ci.ssavaluetypes = nstmts
160+
ci.codelocs = fill(Int32(1), nstmts)
161+
ci.ssaflags = fill(Int32(0), nstmts)
162+
ir = Core.Compiler.inflate_ir(ci)
163+
ir = Core.Compiler.compact!(ir, true)
164+
@test Core.Compiler.verify_ir(ir) == nothing
165+
end

0 commit comments

Comments
 (0)