Skip to content

Commit ea9914e

Browse files
authored
add simple test cases for [post-]domination analysis (#46860)
1 parent 45623a8 commit ea9914e

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

test/compiler/ssair.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ using Core.IR
55
const Compiler = Core.Compiler
66
using .Compiler: CFG, BasicBlock, NewSSAValue
77

8+
include(normpath(@__DIR__, "irutils.jl"))
9+
810
make_bb(preds, succs) = BasicBlock(Compiler.StmtRange(0, 0), preds, succs)
911

1012
function make_ci(code)
@@ -417,3 +419,45 @@ let
417419

418420
test_userefs(body)
419421
end
422+
423+
let ir = Base.code_ircode((Bool,Any)) do c, x
424+
println(x, 1) #1
425+
if c
426+
println(x, 2) #2
427+
else
428+
println(x, 3) #3
429+
end
430+
println(x, 4) #4
431+
end |> only |> first
432+
# IR legality check
433+
@test length(ir.cfg.blocks) == 4
434+
for i = 1:4
435+
@test any(ir.cfg.blocks[i].stmts) do j
436+
inst = ir.stmts[j][:inst]
437+
iscall((ir, println), inst) &&
438+
inst.args[3] == i
439+
end
440+
end
441+
# domination analysis
442+
domtree = Core.Compiler.construct_domtree(ir.cfg.blocks)
443+
@test Core.Compiler.dominates(domtree, 1, 2)
444+
@test Core.Compiler.dominates(domtree, 1, 3)
445+
@test Core.Compiler.dominates(domtree, 1, 4)
446+
for i = 2:4
447+
for j = 1:4
448+
i == j && continue
449+
@test !Core.Compiler.dominates(domtree, i, j)
450+
end
451+
end
452+
# post domination analysis
453+
post_domtree = Core.Compiler.construct_postdomtree(ir.cfg.blocks)
454+
@test Core.Compiler.postdominates(post_domtree, 4, 1)
455+
@test Core.Compiler.postdominates(post_domtree, 4, 2)
456+
@test Core.Compiler.postdominates(post_domtree, 4, 3)
457+
for i = 1:3
458+
for j = 1:4
459+
i == j && continue
460+
@test !Core.Compiler.postdominates(post_domtree, i, j)
461+
end
462+
end
463+
end

0 commit comments

Comments
 (0)