llvm-project/llvm/test/tools/llvm-reduce/remove-bbs-unreachable.ll
Matt Arsenault 45a91c1521 llvm-reduce: Fix block reduction with unreachable blocks
Previously this would produce many invalid reductions with
"Instruction does not dominate uses" verifier errors.

This fixes issues in cases where the incoming IR
has unreachable blocks, and the resulting reduction
introduced new reachable blocks.

Have basic-blocks skip functions that have unreachable
blocks, Introduce a separate reduction which only
deletes unreachable blocks. Cleanup any newly unreachable
blocks after trimming out the requested deletions.

Includes a variety of meta-reduced tests for llvm-reduce
itself with -abort-on-invalid-reduction that were failing
on different iterations of this patch.

Bugpoint's implementation is much simpler (but currently I don't
understand how it avoids disconnecting interesting blocks from the CFG).
2022-10-28 17:07:26 -07:00

57 lines
1.4 KiB
LLVM

; Check that verification doesn't fail when reducing a function with
; unreachable blocks.
;
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=unreachable-basic-blocks --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
; RUN: FileCheck -check-prefix=UNREACHABLE %s < %t
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
; RUN: FileCheck -check-prefix=REACHABLE %s < %t
; CHECK-INTERESTINGNESS: test0
; CHECK-INTERESTINGNESS: test1
; UNREACHABLE: define void @test0() {
; UNREACHABLE-NEXT: entry:
; UNREACHABLE-NEXT: br label %exit
; UNREACHABLE-NOT: unreachable
; UNREACHABLE: exit:
; UNREACHABLE-NEXT: ret void
; basic-blocks cannot deal with unreachable blocks, leave it behind
; REACHABLE: define void @test0() {
; REACHABLE: entry:
; REACHABLE: unreachable:
; REACHABLE: exit:
define void @test0() {
entry:
br label %exit
unreachable: ; No predecessors!
br label %exit
exit:
ret void
}
; UNREACHABLE: define void @test1() {
; UNREACHABLE-NEXT: entry:
; UNREACHABLE-NEXT: br label %exit
; REACHABLE: define void @test1() {
; REACHABLE: entry:
; REACHABLE: unreachable:
; REACHABLE: exit:
define void @test1() {
entry:
br label %exit
unreachable:
br label %unreachable
exit:
ret void
}