llvm-project/llvm/test/tools/llvm-reduce/remove-bb-switch-default.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

65 lines
1.8 KiB
LLVM

; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS0 --test-arg %s --test-arg --input-file %s -o %t.0
; RUN: FileCheck -check-prefix=RESULT0 %s < %t.0
; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS1 --test-arg %s --test-arg --input-file %s -o %t.1
; RUN: FileCheck -check-prefix=RESULT1 %s < %t.1
; CHECK-INTERESTINGNESS0: store i32 1,
; CHECK-INTERESTINGNESS0: store i32 2,
; CHECK-INTERESTINGNESS1: store i32 2,
; RESULT0: bb:
; RESULT0-NEXT: %bb.load = load i32, ptr null, align 4
; RESULT0-NEXT: store i32 0, ptr null, align 4
; RESULT0-NEXT: br i1 %arg0, label %bb1, label %bb2
; RESULT0: bb1:
; RESULT0-NEXT: store i32 1, ptr null, align 4
; RESULT0-NEXT: ret void
; RESULT0: bb2: ; preds = %bb
; RESULT0-NEXT: store i32 2, ptr null, align 4
; RESULT0-NEXT: switch i32 %bb.load, label %bb1 [
; RESULT0-NEXT: i32 0, label %bb1
; RESULT0-NEXT: ]
; RESULT1: bb:
; RESULT1-NEXT: %bb.load = load i32, ptr null, align 4
; RESULT1-NEXT: store i32 0, ptr null, align 4
; RESULT1-NEXT: br label %bb2
; RESULT1: bb2:
; RESULT1-NEXT: store i32 2, ptr null, align 4
; RESULT1-NEXT: ret void
define void @main(i1 %arg0) {
bb:
%bb.load = load i32, ptr null
store i32 0, ptr null
br i1 %arg0, label %bb1, label %bb2
bb1:
%bb1.phi = phi i32 [%bb.load, %bb], [9, %bb3], [%bb2.phi, %bb2]
store i32 1, ptr null
ret void
bb2:
%bb2.phi = phi i32 [%bb.load, %bb], [%bb3.load, %bb3]
store i32 2, ptr null
switch i32 %bb2.phi, label %bb3 [
i32 0, label %bb1
i32 1, label %bb4
]
bb3:
%bb3.load = load i32, ptr null
store i32 3, ptr null
br i1 true, label %bb2, label %bb1
bb4:
store i32 4, ptr null
ret void
}