[SimpleLoopUnswitch] remove a chain of dead blocks at once

Recent change to deleteDeadBlocksFromLoop was not enough to
fix all the problems related to dead blocks after nontrivial
unswitching of switches.

We need to delete all the dead blocks that were created during
unswitching, otherwise we will keep having problems with phi's
or dead blocks.

This change removes all the dead blocks that are reachable from the loop,
not trying to track whether these blocks are newly created by unswitching
or not. While not completely correct, we are unlikely to get loose but
reachable dead blocks that do not belong to our loop nest.

It does fix all the failures currently known, in particular PR38778.

Reviewed By: asbirlea
Differential Revision: https://reviews.llvm.org/D51519

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fedor Sergeev
2018-09-04 20:19:41 +00:00
parent 46d216b8ef
commit ff4ee4df90
2 changed files with 75 additions and 19 deletions
@@ -43,3 +43,59 @@ get_out:
get_out2:
unreachable
}
;
; This comes from PR38778
; CHECK-LABEL: @Test2
define void @Test2(i32) {
header:
br label %loop
loop:
switch i32 %0, label %continue [
i32 -2147483648, label %check
i32 98, label %guarded1
i32 99, label %guarded2
]
; CHECK-NOT: {{^}}guarded1:
guarded1:
br i1 undef, label %continue, label %leave
guarded2:
br label %continue
check:
%val = add i32 0, 1
br i1 undef, label %continue, label %leave
continue:
br label %loop
leave:
%local = phi i32 [ 0, %guarded1 ], [ %val, %check ]
ret void
}
;
; Yet another test from PR38778
;
; CHECK-LABEL: @Test3
define void @Test3(i32) {
header:
br label %outer
outer:
%bad_input.i = icmp eq i32 %0, -2147483648
br label %inner
inner:
br i1 %bad_input.i, label %overflow, label %switchme
overflow:
br label %continue
switchme:
switch i32 %0, label %continue [
i32 88, label %go_out
i32 99, label %case2
]
; CHECK-NOT: {{^}}case2:
case2:
br label %continue
continue:
%local_11_92 = phi i32 [ 0, %switchme ], [ 18, %case2 ], [ 0, %overflow ]
br i1 undef, label %outer, label %inner
go_out:
unreachable
}