Skip to content

Commit

Permalink
Merge pull request #32145 from yhls/yhls/fixrenaming
Browse files Browse the repository at this point in the history
fix bug in block renaming for dead code elimination
  • Loading branch information
vchuravy authored Jul 27, 2019
2 parents 20ef262 + 3829e8f commit 89b8057
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 9 additions & 5 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,24 +499,28 @@ mutable struct IncrementalCompact
cur_bb = 1
for i = 1:length(bb_rename)
if i != 1 && length(blocks[i].preds) == 0
bb_rename[i] = 0
bb_rename[i] = -1
else
bb_rename[i] = cur_bb
cur_bb += 1
end
end
for i = 1:length(bb_rename)
bb_rename[i] == 0 && continue
bb_rename[i] == -1 && continue
preds, succs = blocks[i].preds, blocks[i].succs
# Rename preds
for j = 1:length(preds); preds[j] = bb_rename[preds[j]]; end
for j = 1:length(preds)
if preds[j] != 0
preds[j] = bb_rename[preds[j]]
end
end
# Dead blocks get removed from the predecessor list
filter!(x->x !== 0, preds)
filter!(x->x !== -1, preds)
# Rename succs
for j = 1:length(succs); succs[j] = bb_rename[succs[j]]; end
end
let blocks=blocks
result_bbs = BasicBlock[blocks[i] for i = 1:length(blocks) if bb_rename[i] != 0]
result_bbs = BasicBlock[blocks[i] for i = 1:length(blocks) if bb_rename[i] != -1]
end
else
bb_rename = Vector{Int}()
Expand Down
16 changes: 16 additions & 0 deletions test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ let
end
end

# PR #32145
# Make sure IncrementalCompact can handle blocks with predecessors of index 0
# while removing blocks with no predecessors.
let cfg = CFG(BasicBlock[
make_bb([] , [2, 4]),
make_bb([1] , [4, 5]),
make_bb([] , [4] ), # should be removed
make_bb([0, 1, 2] , [5] ), # 0 predecessor should be preserved
make_bb([2, 3] , [] ),
], Int[])
code = Compiler.IRCode(
[], [], Int32[], UInt8[], cfg, LineInfoNode[], [], [], [])
compact = Compiler.IncrementalCompact(code, true)
@test length(compact.result_bbs) == 4 && 0 in compact.result_bbs[3].preds
end

# Issue #32579 - Optimizer bug involving type constraints
function f32579(x::Int, b::Bool)
if b
Expand Down

2 comments on commit 89b8057

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.