xref: /llvm-project/llvm/test/tools/llvm-reduce/reduce-invoke.ll (revision a455c91601a87c2452a3199a0df8390130a28e90)
1; Test the invoke reduction standalone, dead blocks are not removed
2; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=invokes --test FileCheck --test-arg --check-prefixes=CHECK,INTERESTING --test-arg %s --test-arg --input-file %s -o %t.0
3; RUN: FileCheck --check-prefixes=CHECK,RESULT,RESULT-SINGLE %s < %t.0
4
5; Test the full reduction pipeline, which cleans up unreachable blocks
6; RUN: llvm-reduce --abort-on-invalid-reduction --test FileCheck --test-arg --check-prefixes=CHECK,INTERESTING --test-arg %s --test-arg --input-file %s -o %t.1
7; RUN: FileCheck --check-prefixes=CHECK,RESULT,RESULT-FULL %s < %t.1
8
9
10define i32 @maybe_throwing_callee(i32 %arg) {
11  call void @thrown()
12  ret i32 %arg
13}
14
15declare void @did_not_throw(i32)
16
17declare void @thrown()
18
19; CHECK-LABEL: define void @invoke_keep_landingpad_block(i32 %arg) personality ptr @__gxx_personality_v0 {
20; INTERESTING: i32 @maybe_throwing_callee(
21
22; RESULT-SINGLE: %i0 = call i32 @maybe_throwing_callee(i32 %arg), !some.metadata !0
23; RESULT-SINGLE-NEXT: br label %bb3
24
25; RESULT-FULL: %i0 = call i32 @maybe_throwing_callee()
26; RESULT-FULL-NEXT: br label %bb4
27
28
29; RESULT-SINGLE: bb1:  ; No predecessors!
30; RESULT-SINGLE-NEXT: %landing = landingpad { ptr, i32 }
31; RESULT-SINGLE-NEXT: catch ptr null
32; RESULT-SINGLE-NEXT: call void @thrown()
33define void @invoke_keep_landingpad_block(i32 %arg) personality ptr @__gxx_personality_v0 {
34bb:
35  %i0 = invoke i32 @maybe_throwing_callee(i32 %arg)
36          to label %bb3 unwind label %bb1, !some.metadata !0
37
38bb1:                                              ; preds = %bb
39  %landing = landingpad { ptr, i32 }
40          catch ptr null
41  ; INTERESTING: call void @thrown()
42  call void @thrown()
43  br label %bb4
44
45bb3:                                              ; preds = %bb
46  call void @did_not_throw(i32 %i0)
47  br label %bb4
48
49bb4:                                              ; preds = %bb3, %bb1
50  ret void
51}
52
53; CHECK-LABEL: define void @invoke_drop_landingpad_block(i32 %arg) personality ptr @__gxx_personality_v0 {
54; INTERESTING: i32 @maybe_throwing_callee(
55
56; RESULT-SINGLE: %i0 = call i32 @maybe_throwing_callee(i32 %arg), !some.metadata !0
57; RESULT-SINGLE-NEXT: br label %bb3
58
59; RESULT-SINGLE: bb1:  ; No predecessors!
60; RESULT-SINGLE-NEXT: %landing = landingpad { ptr, i32 }
61
62; RESULT-SINGLE: bb3:
63; RESULT-SINGLE-NEXT: call void @did_not_throw(i32 %i0)
64
65; RESULT-FULL: %i0 = call i32 @maybe_throwing_callee()
66; RESULT-FULL-NEXT: call void @did_not_throw()
67; RESULT-FULL-NEXT: ret void
68define void @invoke_drop_landingpad_block(i32 %arg) personality ptr @__gxx_personality_v0 {
69bb:
70  %i0 = invoke i32 @maybe_throwing_callee(i32 %arg)
71          to label %bb3 unwind label %bb1, !some.metadata !0
72
73bb1:                                              ; preds = %bb
74  %landing = landingpad { ptr, i32 }
75          catch ptr null
76  call void @thrown()
77  br label %bb4
78
79bb3:                                              ; preds = %bb
80  ; INTERESTING: call void @did_not_throw(
81  call void @did_not_throw(i32 %i0)
82  br label %bb4
83
84bb4:                                              ; preds = %bb3, %bb1
85  ret void
86}
87
88declare i32 @another_maybe_throwing_callee(i32 %arg)
89
90; Test the same landing pad block is used by multiple invokes
91; CHECK-LABEL: define i32 @multi_invoke_caller(i32 %arg) personality ptr @__gxx_personality_v0 {
92define i32 @multi_invoke_caller(i32 %arg) personality ptr @__gxx_personality_v0 {
93bb:
94  %i0 = invoke i32 @maybe_throwing_callee(i32 %arg)
95          to label %bb3 unwind label %bb1, !some.metadata !0
96
97; RESULT: bb1:                                              ; preds = %bb4
98; RESULT-NEXT: %landing = landingpad { ptr, i32 }
99; RESULT-NEXT:   catch ptr null
100bb1:                                              ; preds = %bb
101  %landing = landingpad { ptr, i32 }
102          catch ptr null
103  ; INTERESTING: call void @thrown()
104  call void @thrown()
105  br label %bb4
106
107bb3:                                              ; preds = %bb
108  call void @did_not_throw(i32 %i0)
109  br label %bb4
110
111bb4:                                              ; preds = %bb3, %bb1
112  ; INTERESTING: invoke i32 @another_maybe_throwing_callee(
113
114  ; RESULT-SINGLE:   %i1 = invoke i32 @another_maybe_throwing_callee(i32 %arg)
115  ; RESULT-SINGLE-NEXT: to label %bb5 unwind label %bb1, !some.metadata !1
116
117  ; RESULT-FULL:   %i1 = invoke i32 @another_maybe_throwing_callee(i32 0)
118  ; RESULT-FULL-NEXT: to label %bb5 unwind label %bb1{{$}}
119  %i1 = invoke i32 @another_maybe_throwing_callee(i32 %arg)
120          to label %bb5 unwind label %bb1, !some.metadata !1
121
122bb5:
123  ret i32 %i1
124}
125
126declare i32 @__gxx_personality_v0(...)
127
128!0 = !{!"arst"}
129!1 = !{!"arstarst"}
130