1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt < %s -passes='simplifycfg<sink-common-insts>' -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
5 declare ptr @foo(ptr %p, i64 %x)
6 declare ptr @foo2(ptr %p, ptr %p2, i64 %x)
7 declare void @side.effect()
9 define ptr @test_sink_no_args_oneside(i1 %c) {
10 ; CHECK-LABEL: define {{[^@]+}}@test_sink_no_args_oneside
11 ; CHECK-SAME: (i1 [[C:%.*]]) {
12 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
14 ; CHECK-NEXT: call void @side.effect()
15 ; CHECK-NEXT: br label [[END]]
17 ; CHECK-NEXT: [[R2:%.*]] = call ptr @foo0()
18 ; CHECK-NEXT: ret ptr [[R2]]
20 br i1 %c, label %if, label %else
22 call void @side.effect()
27 %r2 = call ptr @foo0() readonly
30 %pr = phi ptr [ %r, %if], [%r2, %else]
34 define ptr @test_sink_no_args_oneside_fail(i1 %c) {
35 ; CHECK-LABEL: define {{[^@]+}}@test_sink_no_args_oneside_fail
36 ; CHECK-SAME: (i1 [[C:%.*]]) {
37 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
39 ; CHECK-NEXT: call void @side.effect()
40 ; CHECK-NEXT: [[R:%.*]] = call ptr @foo0()
41 ; CHECK-NEXT: br label [[END:%.*]]
43 ; CHECK-NEXT: [[R2:%.*]] = call ptr @foo0() #[[ATTR0:[0-9]+]]
44 ; CHECK-NEXT: br label [[END]]
46 ; CHECK-NEXT: [[PR:%.*]] = phi ptr [ [[R]], [[IF]] ], [ [[R2]], [[ELSE]] ]
47 ; CHECK-NEXT: ret ptr [[PR]]
49 br i1 %c, label %if, label %else
51 call void @side.effect()
56 %r2 = call ptr @foo0() readonly alwaysinline
59 %pr = phi ptr [ %r, %if], [%r2, %else]
63 define ptr @test_sink_int_attrs(i1 %c, ptr %p, ptr %p2, i64 %x) {
64 ; CHECK-LABEL: define {{[^@]+}}@test_sink_int_attrs
65 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], ptr [[P2:%.*]], i64 [[X:%.*]]) {
66 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
68 ; CHECK-NEXT: call void @side.effect()
69 ; CHECK-NEXT: br label [[END]]
71 ; CHECK-NEXT: [[R2:%.*]] = call ptr @foo2(ptr align 32 dereferenceable_or_null(100) [[P]], ptr align 32 dereferenceable(50) [[P2]], i64 range(i64 10, 100000) [[X]]) #[[ATTR1:[0-9]+]]
72 ; CHECK-NEXT: ret ptr [[R2]]
74 br i1 %c, label %if, label %else
76 call void @side.effect()
77 %r = call ptr @foo2(ptr align 64 dereferenceable_or_null(100) %p, ptr dereferenceable(50) align 64 %p2, i64 range(i64 10, 1000) %x) memory(read)
81 %r2 = call ptr @foo2(ptr align 32 dereferenceable_or_null(200) %p, ptr dereferenceable(100) align 32 %p2, i64 range(i64 10000, 100000) %x) memory(write)
84 %pr = phi ptr [ %r, %if], [%r2, %else]
88 define ptr @test_sink_int_attrs2(i1 %c, ptr %p, i64 %x) {
89 ; CHECK-LABEL: define {{[^@]+}}@test_sink_int_attrs2
90 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
91 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
93 ; CHECK-NEXT: call void @side.effect()
94 ; CHECK-NEXT: br label [[END]]
96 ; CHECK-NEXT: [[R2:%.*]] = call ptr @foo(ptr dereferenceable(50) [[P]], i64 range(i64 10, 1000) [[X]]) #[[ATTR2:[0-9]+]]
97 ; CHECK-NEXT: ret ptr [[R2]]
99 br i1 %c, label %if, label %else
101 call void @side.effect()
102 %r = call ptr @foo(ptr dereferenceable(50) %p, i64 range(i64 10, 1000) %x) memory(read)
106 %r2 = call ptr @foo(ptr dereferenceable(100) align 32 dereferenceable_or_null(200) %p, i64 range(i64 11, 100) %x) memory(none)
109 %pr = phi ptr [ %r, %if], [%r2, %else]
113 define ptr @test_sink_bool_attrs2(i1 %c, ptr %p, i64 %x) {
114 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs2
115 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
116 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
118 ; CHECK-NEXT: call void @side.effect()
119 ; CHECK-NEXT: br label [[END]]
121 ; CHECK-NEXT: [[R2:%.*]] = call noundef ptr @foo(ptr nonnull [[P]], i64 noundef [[X]]) #[[ATTR3:[0-9]+]]
122 ; CHECK-NEXT: ret ptr [[R2]]
124 br i1 %c, label %if, label %else
126 call void @side.effect()
127 %r = call noundef ptr @foo(ptr readnone nonnull noundef %p, i64 noundef %x) cold mustprogress nocallback nofree nosync willreturn
131 %r2 = call noundef nonnull ptr @foo(ptr readonly nonnull %p, i64 noundef %x) mustprogress nocallback nofree willreturn
134 %pr = phi ptr [ %r, %if], [%r2, %else]
138 define ptr @test_sink_bool_attrs3(i1 %c, ptr %p, i64 %x) {
139 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs3
140 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
141 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
143 ; CHECK-NEXT: call void @side.effect()
144 ; CHECK-NEXT: br label [[END]]
146 ; CHECK-NEXT: [[R2:%.*]] = call nonnull ptr @foo(ptr [[P]], i64 noundef [[X]]) #[[ATTR4:[0-9]+]]
147 ; CHECK-NEXT: ret ptr [[R2]]
149 br i1 %c, label %if, label %else
151 call void @side.effect()
152 %r = call nonnull ptr @foo(ptr readonly noundef %p, i64 noundef %x) cold nocallback nofree nosync willreturn alwaysinline
156 %r2 = call noundef nonnull ptr @foo(ptr writeonly nonnull %p, i64 noundef %x) nosync willreturn alwaysinline
159 %pr = phi ptr [ %r, %if], [%r2, %else]
163 define ptr @test_sink_bool_attrs_fail_non_droppable(i1 %c, ptr %p, i64 %x) {
164 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs_fail_non_droppable
165 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
166 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
168 ; CHECK-NEXT: call void @side.effect()
169 ; CHECK-NEXT: [[R:%.*]] = call nonnull ptr @foo(ptr noundef readonly [[P]], i64 noundef [[X]]) #[[ATTR5:[0-9]+]]
170 ; CHECK-NEXT: br label [[END:%.*]]
172 ; CHECK-NEXT: [[R2:%.*]] = call noundef nonnull ptr @foo(ptr nonnull writeonly [[P]], i64 noundef [[X]]) #[[ATTR6:[0-9]+]]
173 ; CHECK-NEXT: br label [[END]]
175 ; CHECK-NEXT: [[PR:%.*]] = phi ptr [ [[R]], [[IF]] ], [ [[R2]], [[ELSE]] ]
176 ; CHECK-NEXT: ret ptr [[PR]]
178 br i1 %c, label %if, label %else
180 call void @side.effect()
181 %r = call nonnull ptr @foo(ptr readonly noundef %p, i64 noundef %x) cold nocallback nofree nosync willreturn alwaysinline
185 %r2 = call noundef nonnull ptr @foo(ptr writeonly nonnull %p, i64 noundef %x) nosync willreturn
188 %pr = phi ptr [ %r, %if], [%r2, %else]
192 define ptr @test_sink_bool_attrs_fail_non_droppable2(i1 %c, ptr %p, i64 %x) {
193 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs_fail_non_droppable2
194 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
195 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
197 ; CHECK-NEXT: call void @side.effect()
198 ; CHECK-NEXT: [[R:%.*]] = call nonnull ptr @foo(ptr noundef readonly [[P]], i64 noundef [[X]]) #[[ATTR7:[0-9]+]]
199 ; CHECK-NEXT: br label [[END:%.*]]
201 ; CHECK-NEXT: [[R2:%.*]] = call noundef nonnull ptr @foo(ptr nonnull writeonly byval(i64) [[P]], i64 noundef [[X]]) #[[ATTR6]]
202 ; CHECK-NEXT: br label [[END]]
204 ; CHECK-NEXT: [[PR:%.*]] = phi ptr [ [[R]], [[IF]] ], [ [[R2]], [[ELSE]] ]
205 ; CHECK-NEXT: ret ptr [[PR]]
207 br i1 %c, label %if, label %else
209 call void @side.effect()
210 %r = call nonnull ptr @foo(ptr readonly noundef %p, i64 noundef %x) cold nocallback nofree nosync willreturn
214 %r2 = call noundef nonnull ptr @foo(ptr byval(i64) writeonly nonnull %p, i64 noundef %x) nosync willreturn
217 %pr = phi ptr [ %r, %if], [%r2, %else]
221 define ptr @test_sink_bool_attrs_fail_non_droppable3(i1 %c, ptr %p, i64 %x) {
222 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs_fail_non_droppable3
223 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
224 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
226 ; CHECK-NEXT: call void @side.effect()
227 ; CHECK-NEXT: [[R:%.*]] = call nonnull ptr @foo(ptr noundef readonly byval(i32) [[P]], i64 noundef [[X]]) #[[ATTR7]]
228 ; CHECK-NEXT: br label [[END:%.*]]
230 ; CHECK-NEXT: [[R2:%.*]] = call noundef nonnull ptr @foo(ptr nonnull writeonly byval(i64) [[P]], i64 noundef [[X]]) #[[ATTR8:[0-9]+]]
231 ; CHECK-NEXT: br label [[END]]
233 ; CHECK-NEXT: [[PR:%.*]] = phi ptr [ [[R]], [[IF]] ], [ [[R2]], [[ELSE]] ]
234 ; CHECK-NEXT: ret ptr [[PR]]
236 br i1 %c, label %if, label %else
238 call void @side.effect()
239 %r = call nonnull ptr @foo(ptr byval(i32) readonly noundef %p, i64 noundef %x) cold nocallback nofree nosync willreturn
243 %r2 = call noundef nonnull ptr @foo(ptr byval(i64) writeonly nonnull %p, i64 noundef %x) nosync
246 %pr = phi ptr [ %r, %if], [%r2, %else]
250 define ptr @test_sink_bool_attrs4(i1 %c, ptr %p, i64 %x) {
251 ; CHECK-LABEL: define {{[^@]+}}@test_sink_bool_attrs4
252 ; CHECK-SAME: (i1 [[C:%.*]], ptr [[P:%.*]], i64 [[X:%.*]]) {
253 ; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[END:%.*]]
255 ; CHECK-NEXT: call void @side.effect()
256 ; CHECK-NEXT: br label [[END]]
258 ; CHECK-NEXT: [[R2:%.*]] = call nonnull ptr @foo(ptr byval(i64) [[P]], i64 noundef [[X]]) #[[ATTR8]]
259 ; CHECK-NEXT: ret ptr [[R2]]
261 br i1 %c, label %if, label %else
263 call void @side.effect()
264 %r = call nonnull ptr @foo(ptr byval(i64) readonly noundef %p, i64 noundef %x) cold nocallback nofree nosync willreturn
268 %r2 = call noundef nonnull ptr @foo(ptr byval(i64) writeonly nonnull %p, i64 noundef %x) nosync
271 %pr = phi ptr [ %r, %if], [%r2, %else]
276 ; CHECK: attributes #[[ATTR0]] = { alwaysinline memory(read) }
277 ; CHECK: attributes #[[ATTR1]] = { memory(readwrite) }
278 ; CHECK: attributes #[[ATTR2]] = { memory(read) }
279 ; CHECK: attributes #[[ATTR3]] = { mustprogress nocallback nofree willreturn }
280 ; CHECK: attributes #[[ATTR4]] = { alwaysinline nosync willreturn }
281 ; CHECK: attributes #[[ATTR5]] = { alwaysinline cold nocallback nofree nosync willreturn }
282 ; CHECK: attributes #[[ATTR6]] = { nosync willreturn }
283 ; CHECK: attributes #[[ATTR7]] = { cold nocallback nofree nosync willreturn }
284 ; CHECK: attributes #[[ATTR8]] = { nosync }