1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 ; Test cases specifically designed for "align" attribute.
8 ; We use FIXME's to indicate problems and missing attributes.
14 ; CHECK: @[[A1:[a-zA-Z0-9_$"\\.-]+]] = common global i8 0, align 8
15 ; CHECK: @[[A2:[a-zA-Z0-9_$"\\.-]+]] = common global i8 0, align 16
16 ; CHECK: @[[CND:[a-zA-Z0-9_$"\\.-]+]] = external global i1
17 ; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = global i8 0, align 32
19 define ptr @test1(ptr align 8 %0) #0 {
20 ; CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
21 ; CHECK-LABEL: define {{[^@]+}}@test1
22 ; CHECK-SAME: (ptr nofree readnone returned align 8 "no-capture-maybe-returned" [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
23 ; CHECK-NEXT: ret ptr [[TMP0]]
29 define ptr @test2(ptr %0) #0 {
30 ; CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
31 ; CHECK-LABEL: define {{[^@]+}}@test2
32 ; CHECK-SAME: (ptr nofree readnone returned "no-capture-maybe-returned" [[TMP0:%.*]]) #[[ATTR0]] {
33 ; CHECK-NEXT: ret ptr [[TMP0]]
39 define ptr @test3(ptr align 8 %0, ptr align 4 %1, i1 %2) #0 {
40 ; CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
41 ; CHECK-LABEL: define {{[^@]+}}@test3
42 ; CHECK-SAME: (ptr nofree readnone align 8 "no-capture-maybe-returned" [[TMP0:%.*]], ptr nofree readnone align 4 "no-capture-maybe-returned" [[TMP1:%.*]], i1 [[TMP2:%.*]]) #[[ATTR0]] {
43 ; CHECK-NEXT: [[RET:%.*]] = select i1 [[TMP2]], ptr [[TMP0]], ptr [[TMP1]]
44 ; CHECK-NEXT: ret ptr [[RET]]
46 %ret = select i1 %2, ptr %0, ptr %1
51 define ptr @test4(ptr align 32 %0, ptr align 32 %1, i1 %2) #0 {
52 ; CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
53 ; CHECK-LABEL: define {{[^@]+}}@test4
54 ; CHECK-SAME: (ptr nofree readnone align 32 "no-capture-maybe-returned" [[TMP0:%.*]], ptr nofree readnone align 32 "no-capture-maybe-returned" [[TMP1:%.*]], i1 [[TMP2:%.*]]) #[[ATTR0]] {
55 ; CHECK-NEXT: [[RET:%.*]] = select i1 [[TMP2]], ptr [[TMP0]], ptr [[TMP1]]
56 ; CHECK-NEXT: ret ptr [[RET]]
58 %ret = select i1 %2, ptr %0, ptr %1
63 declare ptr @unknown()
64 declare align 8 ptr @align8()
67 define ptr @test5_1() {
68 ; CHECK-LABEL: define {{[^@]+}}@test5_1() {
69 ; CHECK-NEXT: [[RET:%.*]] = tail call align 8 ptr @unknown()
70 ; CHECK-NEXT: ret ptr [[RET]]
72 %ret = tail call align 8 ptr @unknown()
76 define ptr @test5_2() {
77 ; CHECK-LABEL: define {{[^@]+}}@test5_2() {
78 ; CHECK-NEXT: [[RET:%.*]] = tail call align 8 ptr @align8()
79 ; CHECK-NEXT: ret ptr [[RET]]
81 %ret = tail call ptr @align8()
87 define ptr @test6_1() #0 {
88 ; TUNIT: Function Attrs: mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable
89 ; TUNIT-LABEL: define {{[^@]+}}@test6_1
90 ; TUNIT-SAME: () #[[ATTR1:[0-9]+]] {
91 ; TUNIT-NEXT: ret ptr undef
93 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
94 ; CGSCC-LABEL: define {{[^@]+}}@test6_1
95 ; CGSCC-SAME: () #[[ATTR0]] {
96 ; CGSCC-NEXT: ret ptr undef
98 %ret = tail call ptr @test6_2()
102 define ptr @test6_2() #0 {
103 ; TUNIT: Function Attrs: mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable
104 ; TUNIT-LABEL: define {{[^@]+}}@test6_2
105 ; TUNIT-SAME: () #[[ATTR1]] {
106 ; TUNIT-NEXT: ret ptr undef
108 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
109 ; CGSCC-LABEL: define {{[^@]+}}@test6_2
110 ; CGSCC-SAME: () #[[ATTR0]] {
111 ; CGSCC-NEXT: ret ptr undef
113 %ret = tail call ptr @test6_1()
118 ; char a1 __attribute__((aligned(8)));
119 ; char a2 __attribute__((aligned(16)));
121 ; char* f1(char* a ){
122 ; return a?a:f2(&a1);
125 ; return a?f1(a):f3(&a2);
129 ; return a?&a1: f1(&a2);
132 @a1 = common global i8 0, align 8
133 @a2 = common global i8 0, align 16
135 ; Function Attrs: nounwind readnone ssp uwtable
136 define internal ptr @f1(ptr readnone %0) local_unnamed_addr #0 {
137 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
138 ; CGSCC-LABEL: define {{[^@]+}}@f1
139 ; CGSCC-SAME: () local_unnamed_addr #[[ATTR0]] {
140 ; CGSCC-NEXT: br label [[TMP2:%.*]]
142 ; CGSCC-NEXT: unreachable
144 ; CGSCC-NEXT: ret ptr @a1
146 %2 = icmp eq ptr %0, null
147 br i1 %2, label %3, label %5
149 ; <label>:3: ; preds = %1
150 %4 = tail call ptr @f2(ptr nonnull @a1)
154 ; <label>:5: ; preds = %1, %3
155 %6 = phi ptr [ %4, %3 ], [ %0, %1 ]
159 ; Function Attrs: nounwind readnone ssp uwtable
160 define ptr @f2(ptr readnone %0) local_unnamed_addr #0 {
161 ; CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
162 ; CHECK-LABEL: define {{[^@]+}}@f2
163 ; CHECK-SAME: (ptr nofree readnone [[TMP0:%.*]]) local_unnamed_addr #[[ATTR0]] {
164 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
165 ; CHECK-NEXT: br i1 [[TMP2]], label [[TMP4:%.*]], label [[TMP3:%.*]]
167 ; CHECK-NEXT: br label [[TMP5:%.*]]
169 ; CHECK-NEXT: br label [[TMP5]]
171 ; CHECK-NEXT: [[TMP6:%.*]] = phi ptr [ [[TMP0]], [[TMP3]] ], [ @a1, [[TMP4]] ]
172 ; CHECK-NEXT: ret ptr [[TMP6]]
174 %2 = icmp eq ptr %0, null
175 br i1 %2, label %5, label %3
177 ; <label>:3: ; preds = %1
179 %4 = tail call ptr @f1(ptr nonnull %0)
182 ; <label>:5: ; preds = %1
183 %6 = tail call ptr @f3(ptr nonnull @a2)
186 ; <label>:7: ; preds = %5, %3
187 %8 = phi ptr [ %4, %3 ], [ %6, %5 ]
191 ; Function Attrs: nounwind readnone ssp uwtable
192 define internal ptr @f3(ptr readnone %0) local_unnamed_addr #0 {
193 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
194 ; CGSCC-LABEL: define {{[^@]+}}@f3
195 ; CGSCC-SAME: () local_unnamed_addr #[[ATTR0]] {
196 ; CGSCC-NEXT: br label [[TMP2:%.*]]
198 ; CGSCC-NEXT: unreachable
200 ; CGSCC-NEXT: ret ptr undef
202 %2 = icmp eq ptr %0, null
203 br i1 %2, label %3, label %5
205 ; <label>:3: ; preds = %1
206 %4 = tail call ptr @f1(ptr nonnull @a2)
209 ; <label>:5: ; preds = %1, %3
210 %6 = phi ptr [ %4, %3 ], [ @a1, %1 ]
215 ; Better than IR information
216 define align 4 ptr @test7() #0 {
217 ; TUNIT: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
218 ; TUNIT-LABEL: define {{[^@]+}}@test7
219 ; TUNIT-SAME: () #[[ATTR0]] {
220 ; TUNIT-NEXT: ret ptr @a1
222 ; CGSCC: Function Attrs: mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable
223 ; CGSCC-LABEL: define {{[^@]+}}@test7
224 ; CGSCC-SAME: () #[[ATTR1:[0-9]+]] {
225 ; CGSCC-NEXT: [[C:%.*]] = tail call noundef nonnull align 8 dereferenceable(1) ptr @f1() #[[ATTR14:[0-9]+]]
226 ; CGSCC-NEXT: ret ptr [[C]]
228 %c = tail call ptr @f1(ptr align 8 dereferenceable(1) @a1)
233 ; Function Attrs: nounwind readnone ssp uwtable
234 define internal ptr @f1b(ptr readnone %0) local_unnamed_addr #0 {
235 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
236 ; CGSCC-LABEL: define {{[^@]+}}@f1b
237 ; CGSCC-SAME: () local_unnamed_addr #[[ATTR0]] {
238 ; CGSCC-NEXT: br label [[TMP2:%.*]]
240 ; CGSCC-NEXT: unreachable
242 ; CGSCC-NEXT: ret ptr undef
244 %2 = icmp eq ptr %0, null
245 br i1 %2, label %3, label %5
247 ; <label>:3: ; preds = %1
248 %4 = tail call ptr @f2b(ptr nonnull @a1)
253 ; <label>:5: ; preds = %1, %3
254 %6 = phi ptr [ %4, %3 ], [ %0, %1 ]
258 ; Function Attrs: nounwind readnone ssp uwtable
259 define internal ptr @f2b(ptr readnone %0) local_unnamed_addr #0 {
261 ; CGSCC: Function Attrs: noinline nounwind uwtable
262 ; CGSCC-LABEL: define {{[^@]+}}@f2b
263 ; CGSCC-SAME: (ptr readnone [[TMP0:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
264 ; CGSCC-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
265 ; CGSCC-NEXT: br i1 [[TMP2]], label [[TMP5:%.*]], label [[TMP3:%.*]]
267 ; CGSCC-NEXT: [[TMP4:%.*]] = tail call ptr @f1b()
268 ; CGSCC-NEXT: br label [[TMP7:%.*]]
270 ; CGSCC-NEXT: [[TMP6:%.*]] = tail call ptr @f3b()
271 ; CGSCC-NEXT: br label [[TMP7]]
273 ; CGSCC-NEXT: [[TMP8:%.*]] = phi ptr [ [[TMP4]], [[TMP3]] ], [ [[TMP6]], [[TMP5]] ]
274 ; CGSCC-NEXT: ret ptr [[TMP8]]
276 %2 = icmp eq ptr %0, null
277 br i1 %2, label %5, label %3
279 ; <label>:3: ; preds = %1
281 %4 = tail call ptr @f1b(ptr nonnull %0)
284 ; <label>:5: ; preds = %1
285 %6 = tail call ptr @f3b(ptr nonnull @a2)
288 ; <label>:7: ; preds = %5, %3
289 %8 = phi ptr [ %4, %3 ], [ %6, %5 ]
293 ; Function Attrs: nounwind readnone ssp uwtable
294 define internal ptr @f3b(ptr readnone %0) local_unnamed_addr #0 {
296 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
297 ; CGSCC-LABEL: define {{[^@]+}}@f3b
298 ; CGSCC-SAME: () local_unnamed_addr #[[ATTR0]] {
299 ; CGSCC-NEXT: br label [[TMP2:%.*]]
301 ; CGSCC-NEXT: unreachable
303 ; CGSCC-NEXT: ret ptr @a1
305 %2 = icmp eq ptr %0, null
306 br i1 %2, label %3, label %5
308 ; <label>:3: ; preds = %1
309 %4 = tail call ptr @f1b(ptr nonnull @a2)
312 ; <label>:5: ; preds = %1, %3
313 %6 = phi ptr [ %4, %3 ], [ @a1, %1 ]
317 define align 4 ptr @test7b(ptr align 32 %p) #0 {
318 ; TUNIT: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable
319 ; TUNIT-LABEL: define {{[^@]+}}@test7b
320 ; TUNIT-SAME: (ptr nofree readnone returned align 32 "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR0]] {
321 ; TUNIT-NEXT: ret ptr [[P]]
323 ; CGSCC: Function Attrs: mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable
324 ; CGSCC-LABEL: define {{[^@]+}}@test7b
325 ; CGSCC-SAME: (ptr nofree readnone returned align 32 "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
326 ; CGSCC-NEXT: ret ptr [[P]]
328 tail call ptr @f1b(ptr align 8 dereferenceable(1) @a1)
333 define void @test8_helper() {
334 ; TUNIT-LABEL: define {{[^@]+}}@test8_helper() {
335 ; TUNIT-NEXT: [[PTR0:%.*]] = tail call ptr @unknown()
336 ; TUNIT-NEXT: [[PTR1:%.*]] = tail call align 4 ptr @unknown()
337 ; TUNIT-NEXT: [[PTR2:%.*]] = tail call align 8 ptr @unknown()
338 ; TUNIT-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone [[PTR0]]) #[[ATTR2:[0-9]+]]
339 ; TUNIT-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 8 [[PTR2]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]]) #[[ATTR2]]
340 ; TUNIT-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 8 [[PTR2]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]]) #[[ATTR2]]
341 ; TUNIT-NEXT: ret void
343 ; CGSCC-LABEL: define {{[^@]+}}@test8_helper() {
344 ; CGSCC-NEXT: [[PTR0:%.*]] = tail call ptr @unknown()
345 ; CGSCC-NEXT: [[PTR1:%.*]] = tail call align 4 ptr @unknown()
346 ; CGSCC-NEXT: [[PTR2:%.*]] = tail call align 8 ptr @unknown()
347 ; CGSCC-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone [[PTR0]]) #[[ATTR3:[0-9]+]]
348 ; CGSCC-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 8 [[PTR2]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]]) #[[ATTR3]]
349 ; CGSCC-NEXT: tail call void @test8(ptr noalias nocapture nofree readnone align 8 [[PTR2]], ptr noalias nocapture nofree readnone align 4 [[PTR1]], ptr noalias nocapture nofree readnone align 4 [[PTR1]]) #[[ATTR3]]
350 ; CGSCC-NEXT: ret void
352 %ptr0 = tail call ptr @unknown()
353 %ptr1 = tail call align 4 ptr @unknown()
354 %ptr2 = tail call align 8 ptr @unknown()
356 tail call void @test8(ptr %ptr1, ptr %ptr1, ptr %ptr0)
357 tail call void @test8(ptr %ptr2, ptr %ptr1, ptr %ptr1)
358 tail call void @test8(ptr %ptr2, ptr %ptr1, ptr %ptr1)
362 declare void @user_i32_ptr(ptr nocapture readnone) nounwind
363 define internal void @test8(ptr %a, ptr %b, ptr %c) {
364 ; TUNIT: Function Attrs: nounwind
365 ; TUNIT-LABEL: define {{[^@]+}}@test8
366 ; TUNIT-SAME: (ptr noalias nocapture nofree readnone align 4 [[A:%.*]], ptr noalias nocapture nofree readnone align 4 [[B:%.*]], ptr noalias nocapture nofree readnone [[C:%.*]]) #[[ATTR2]] {
367 ; TUNIT-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone align 4 [[A]]) #[[ATTR2]]
368 ; TUNIT-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone align 4 [[B]]) #[[ATTR2]]
369 ; TUNIT-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone [[C]]) #[[ATTR2]]
370 ; TUNIT-NEXT: ret void
372 ; CGSCC: Function Attrs: nounwind
373 ; CGSCC-LABEL: define {{[^@]+}}@test8
374 ; CGSCC-SAME: (ptr noalias nocapture nofree readnone align 4 [[A:%.*]], ptr noalias nocapture nofree readnone align 4 [[B:%.*]], ptr noalias nocapture nofree readnone [[C:%.*]]) #[[ATTR3]] {
375 ; CGSCC-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone align 4 [[A]]) #[[ATTR3]]
376 ; CGSCC-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone align 4 [[B]]) #[[ATTR3]]
377 ; CGSCC-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree readnone [[C]]) #[[ATTR3]]
378 ; CGSCC-NEXT: ret void
380 call void @user_i32_ptr(ptr %a)
381 call void @user_i32_ptr(ptr %b)
382 call void @user_i32_ptr(ptr %c)
386 declare void @test9_helper(ptr %A)
387 define void @test9_traversal(i1 %cnd, ptr align 4 %B, ptr align 8 %C) {
388 ; CHECK-LABEL: define {{[^@]+}}@test9_traversal
389 ; CHECK-SAME: (i1 [[CND:%.*]], ptr align 4 [[B:%.*]], ptr align 8 [[C:%.*]]) {
390 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CND]], ptr [[B]], ptr [[C]]
391 ; CHECK-NEXT: call void @test9_helper(ptr align 4 [[SEL]])
392 ; CHECK-NEXT: ret void
394 %sel = select i1 %cnd, ptr %B, ptr %C
395 call void @test9_helper(ptr %sel)
399 ; FIXME: This will work with an upcoming patch (D66618 or similar)
400 ; define align 32 ptr @test10a(ptr align 32 "no-capture-maybe-returned" %p)
401 ; FIXME: This will work with an upcoming patch (D66618 or similar)
402 ; store i32 1, ptr %r, align 32
403 ; FIXME: This will work with an upcoming patch (D66618 or similar)
404 ; store i32 -1, ptr %g1, align 32
405 define ptr @test10a(ptr align 32 %p) {
406 ; TUNIT: Function Attrs: nofree nosync nounwind
407 ; TUNIT-LABEL: define {{[^@]+}}@test10a
408 ; TUNIT-SAME: (ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR3:[0-9]+]] {
409 ; TUNIT-NEXT: [[L:%.*]] = load i32, ptr [[P]], align 32
410 ; TUNIT-NEXT: [[C:%.*]] = icmp eq i32 [[L]], 0
411 ; TUNIT-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
413 ; TUNIT-NEXT: [[R:%.*]] = call align 32 ptr @test10a(ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P]]) #[[ATTR3]]
414 ; TUNIT-NEXT: store i32 1, ptr [[R]], align 32
415 ; TUNIT-NEXT: [[G0:%.*]] = getelementptr i32, ptr [[P]], i32 8
416 ; TUNIT-NEXT: br label [[E:%.*]]
418 ; TUNIT-NEXT: [[G1:%.*]] = getelementptr i32, ptr [[P]], i32 8
419 ; TUNIT-NEXT: store i32 -1, ptr [[G1]], align 32
420 ; TUNIT-NEXT: br label [[E]]
422 ; TUNIT-NEXT: [[PHI:%.*]] = phi ptr [ [[G0]], [[T]] ], [ [[G1]], [[F]] ]
423 ; TUNIT-NEXT: ret ptr [[PHI]]
425 ; CGSCC: Function Attrs: nofree nosync nounwind
426 ; CGSCC-LABEL: define {{[^@]+}}@test10a
427 ; CGSCC-SAME: (ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR4:[0-9]+]] {
428 ; CGSCC-NEXT: [[L:%.*]] = load i32, ptr [[P]], align 32
429 ; CGSCC-NEXT: [[C:%.*]] = icmp eq i32 [[L]], 0
430 ; CGSCC-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
432 ; CGSCC-NEXT: [[R:%.*]] = call align 32 ptr @test10a(ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P]]) #[[ATTR4]]
433 ; CGSCC-NEXT: store i32 1, ptr [[R]], align 32
434 ; CGSCC-NEXT: [[G0:%.*]] = getelementptr i32, ptr [[P]], i32 8
435 ; CGSCC-NEXT: br label [[E:%.*]]
437 ; CGSCC-NEXT: [[G1:%.*]] = getelementptr i32, ptr [[P]], i32 8
438 ; CGSCC-NEXT: store i32 -1, ptr [[G1]], align 32
439 ; CGSCC-NEXT: br label [[E]]
441 ; CGSCC-NEXT: [[PHI:%.*]] = phi ptr [ [[G0]], [[T]] ], [ [[G1]], [[F]] ]
442 ; CGSCC-NEXT: ret ptr [[PHI]]
444 %l = load i32, ptr %p
445 %c = icmp eq i32 %l, 0
446 br i1 %c, label %t, label %f
448 %r = call ptr @test10a(ptr %p)
450 %g0 = getelementptr i32, ptr %p, i32 8
453 %g1 = getelementptr i32, ptr %p, i32 8
454 store i32 -1, ptr %g1
457 %phi = phi ptr [%g0, %t], [%g1, %f]
461 ; FIXME: This will work with an upcoming patch (D66618 or similar)
462 ; define align 32 ptr @test10b(ptr align 32 "no-capture-maybe-returned" %p)
463 ; FIXME: This will work with an upcoming patch (D66618 or similar)
464 ; store i32 1, ptr %r, align 32
465 ; FIXME: This will work with an upcoming patch (D66618 or similar)
466 ; store i32 -1, ptr %g1, align 32
467 define ptr @test10b(ptr align 32 %p) {
468 ; TUNIT: Function Attrs: nofree nosync nounwind
469 ; TUNIT-LABEL: define {{[^@]+}}@test10b
470 ; TUNIT-SAME: (ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR3]] {
471 ; TUNIT-NEXT: [[L:%.*]] = load i32, ptr [[P]], align 32
472 ; TUNIT-NEXT: [[C:%.*]] = icmp eq i32 [[L]], 0
473 ; TUNIT-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
475 ; TUNIT-NEXT: [[R:%.*]] = call align 32 ptr @test10b(ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P]]) #[[ATTR3]]
476 ; TUNIT-NEXT: store i32 1, ptr [[R]], align 32
477 ; TUNIT-NEXT: [[G0:%.*]] = getelementptr i32, ptr [[P]], i32 8
478 ; TUNIT-NEXT: br label [[E:%.*]]
480 ; TUNIT-NEXT: [[G1:%.*]] = getelementptr i32, ptr [[P]], i32 -8
481 ; TUNIT-NEXT: store i32 -1, ptr [[G1]], align 32
482 ; TUNIT-NEXT: br label [[E]]
484 ; TUNIT-NEXT: [[PHI:%.*]] = phi ptr [ [[G0]], [[T]] ], [ [[G1]], [[F]] ]
485 ; TUNIT-NEXT: ret ptr [[PHI]]
487 ; CGSCC: Function Attrs: nofree nosync nounwind
488 ; CGSCC-LABEL: define {{[^@]+}}@test10b
489 ; CGSCC-SAME: (ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR4]] {
490 ; CGSCC-NEXT: [[L:%.*]] = load i32, ptr [[P]], align 32
491 ; CGSCC-NEXT: [[C:%.*]] = icmp eq i32 [[L]], 0
492 ; CGSCC-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
494 ; CGSCC-NEXT: [[R:%.*]] = call align 32 ptr @test10b(ptr nofree noundef nonnull align 32 dereferenceable(4) "no-capture-maybe-returned" [[P]]) #[[ATTR4]]
495 ; CGSCC-NEXT: store i32 1, ptr [[R]], align 32
496 ; CGSCC-NEXT: [[G0:%.*]] = getelementptr i32, ptr [[P]], i32 8
497 ; CGSCC-NEXT: br label [[E:%.*]]
499 ; CGSCC-NEXT: [[G1:%.*]] = getelementptr i32, ptr [[P]], i32 -8
500 ; CGSCC-NEXT: store i32 -1, ptr [[G1]], align 32
501 ; CGSCC-NEXT: br label [[E]]
503 ; CGSCC-NEXT: [[PHI:%.*]] = phi ptr [ [[G0]], [[T]] ], [ [[G1]], [[F]] ]
504 ; CGSCC-NEXT: ret ptr [[PHI]]
506 %l = load i32, ptr %p
507 %c = icmp eq i32 %l, 0
508 br i1 %c, label %t, label %f
510 %r = call ptr @test10b(ptr %p)
512 %g0 = getelementptr i32, ptr %p, i32 8
515 %g1 = getelementptr i32, ptr %p, i32 -8
516 store i32 -1, ptr %g1
519 %phi = phi ptr [%g0, %t], [%g1, %f]
524 define i64 @test11(ptr %p) {
525 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
526 ; TUNIT-LABEL: define {{[^@]+}}@test11
527 ; TUNIT-SAME: (ptr nocapture nofree nonnull readonly align 8 dereferenceable(8) [[P:%.*]]) #[[ATTR4:[0-9]+]] {
528 ; TUNIT-NEXT: [[RET:%.*]] = load i64, ptr [[P]], align 8
529 ; TUNIT-NEXT: ret i64 [[RET]]
531 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
532 ; CGSCC-LABEL: define {{[^@]+}}@test11
533 ; CGSCC-SAME: (ptr nocapture nofree nonnull readonly align 8 dereferenceable(8) [[P:%.*]]) #[[ATTR5:[0-9]+]] {
534 ; CGSCC-NEXT: [[RET:%.*]] = load i64, ptr [[P]], align 8
535 ; CGSCC-NEXT: ret i64 [[RET]]
537 %p-cast = bitcast ptr %p to ptr
538 %ret = load i64, ptr %p-cast, align 8
543 ; Test for deduction using must-be-executed-context and GEP instruction
545 ; FXIME: %p should have nonnull
546 define i64 @test12-1(ptr align 4 %p) {
547 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
548 ; TUNIT-LABEL: define {{[^@]+}}@test12-1
549 ; TUNIT-SAME: (ptr nocapture nofree readonly align 16 [[P:%.*]]) #[[ATTR4]] {
550 ; TUNIT-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
551 ; TUNIT-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
552 ; TUNIT-NEXT: [[RET:%.*]] = load i64, ptr [[ARRAYIDX1]], align 16
553 ; TUNIT-NEXT: ret i64 [[RET]]
555 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
556 ; CGSCC-LABEL: define {{[^@]+}}@test12-1
557 ; CGSCC-SAME: (ptr nocapture nofree readonly align 16 [[P:%.*]]) #[[ATTR5]] {
558 ; CGSCC-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
559 ; CGSCC-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
560 ; CGSCC-NEXT: [[RET:%.*]] = load i64, ptr [[ARRAYIDX1]], align 16
561 ; CGSCC-NEXT: ret i64 [[RET]]
563 %p-cast = bitcast ptr %p to ptr
564 %arrayidx0 = getelementptr i64, ptr %p-cast, i64 1
565 %arrayidx1 = getelementptr i64, ptr %arrayidx0, i64 3
566 %ret = load i64, ptr %arrayidx1, align 16
570 define i64 @test12-2(ptr align 4 %p) {
571 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
572 ; TUNIT-LABEL: define {{[^@]+}}@test12-2
573 ; TUNIT-SAME: (ptr nocapture nofree nonnull readonly align 16 dereferenceable(8) [[P:%.*]]) #[[ATTR4]] {
574 ; TUNIT-NEXT: [[RET:%.*]] = load i64, ptr [[P]], align 16
575 ; TUNIT-NEXT: ret i64 [[RET]]
577 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
578 ; CGSCC-LABEL: define {{[^@]+}}@test12-2
579 ; CGSCC-SAME: (ptr nocapture nofree nonnull readonly align 16 dereferenceable(8) [[P:%.*]]) #[[ATTR5]] {
580 ; CGSCC-NEXT: [[RET:%.*]] = load i64, ptr [[P]], align 16
581 ; CGSCC-NEXT: ret i64 [[RET]]
583 %p-cast = bitcast ptr %p to ptr
584 %ret = load i64, ptr %p-cast, align 16
588 ; FXIME: %p should have nonnull
589 define void @test12-3(ptr align 4 %p) {
590 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
591 ; TUNIT-LABEL: define {{[^@]+}}@test12-3
592 ; TUNIT-SAME: (ptr nocapture nofree writeonly align 16 [[P:%.*]]) #[[ATTR5:[0-9]+]] {
593 ; TUNIT-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
594 ; TUNIT-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
595 ; TUNIT-NEXT: store i64 0, ptr [[ARRAYIDX1]], align 16
596 ; TUNIT-NEXT: ret void
598 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
599 ; CGSCC-LABEL: define {{[^@]+}}@test12-3
600 ; CGSCC-SAME: (ptr nocapture nofree writeonly align 16 [[P:%.*]]) #[[ATTR6:[0-9]+]] {
601 ; CGSCC-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
602 ; CGSCC-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
603 ; CGSCC-NEXT: store i64 0, ptr [[ARRAYIDX1]], align 16
604 ; CGSCC-NEXT: ret void
606 %p-cast = bitcast ptr %p to ptr
607 %arrayidx0 = getelementptr i64, ptr %p-cast, i64 1
608 %arrayidx1 = getelementptr i64, ptr %arrayidx0, i64 3
609 store i64 0, ptr %arrayidx1, align 16
613 define void @test12-4(ptr align 4 %p) {
614 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
615 ; TUNIT-LABEL: define {{[^@]+}}@test12-4
616 ; TUNIT-SAME: (ptr nocapture nofree nonnull writeonly align 16 dereferenceable(8) [[P:%.*]]) #[[ATTR5]] {
617 ; TUNIT-NEXT: store i64 0, ptr [[P]], align 16
618 ; TUNIT-NEXT: ret void
620 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
621 ; CGSCC-LABEL: define {{[^@]+}}@test12-4
622 ; CGSCC-SAME: (ptr nocapture nofree nonnull writeonly align 16 dereferenceable(8) [[P:%.*]]) #[[ATTR6]] {
623 ; CGSCC-NEXT: store i64 0, ptr [[P]], align 16
624 ; CGSCC-NEXT: ret void
626 %p-cast = bitcast ptr %p to ptr
627 store i64 0, ptr %p-cast, align 16
631 declare void @use(ptr) willreturn nounwind
633 define void @test12-5(ptr align 4 %p) {
634 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
635 ; TUNIT-LABEL: define {{[^@]+}}@test12-5
636 ; TUNIT-SAME: (ptr align 16 [[P:%.*]]) #[[ATTR7:[0-9]+]] {
637 ; TUNIT-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
638 ; TUNIT-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
639 ; TUNIT-NEXT: tail call void @use(ptr align 16 [[ARRAYIDX1]]) #[[ATTR6:[0-9]+]]
640 ; TUNIT-NEXT: ret void
642 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
643 ; CGSCC-LABEL: define {{[^@]+}}@test12-5
644 ; CGSCC-SAME: (ptr align 16 [[P:%.*]]) #[[ATTR8:[0-9]+]] {
645 ; CGSCC-NEXT: [[ARRAYIDX0:%.*]] = getelementptr i64, ptr [[P]], i64 1
646 ; CGSCC-NEXT: [[ARRAYIDX1:%.*]] = getelementptr i64, ptr [[ARRAYIDX0]], i64 3
647 ; CGSCC-NEXT: tail call void @use(ptr align 16 [[ARRAYIDX1]]) #[[ATTR7:[0-9]+]]
648 ; CGSCC-NEXT: ret void
650 %p-cast = bitcast ptr %p to ptr
651 %arrayidx0 = getelementptr i64, ptr %p-cast, i64 1
652 %arrayidx1 = getelementptr i64, ptr %arrayidx0, i64 3
653 tail call void @use(ptr align 16 %arrayidx1)
657 define void @test12-6(ptr align 4 %p) {
658 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
659 ; TUNIT-LABEL: define {{[^@]+}}@test12-6
660 ; TUNIT-SAME: (ptr align 16 [[P:%.*]]) #[[ATTR7]] {
661 ; TUNIT-NEXT: tail call void @use(ptr align 16 [[P]]) #[[ATTR6]]
662 ; TUNIT-NEXT: ret void
664 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
665 ; CGSCC-LABEL: define {{[^@]+}}@test12-6
666 ; CGSCC-SAME: (ptr align 16 [[P:%.*]]) #[[ATTR8]] {
667 ; CGSCC-NEXT: tail call void @use(ptr align 16 [[P]]) #[[ATTR7]]
668 ; CGSCC-NEXT: ret void
670 %p-cast = bitcast ptr %p to ptr
671 tail call void @use(ptr align 16 %p-cast)
675 define void @test13(i1 %c, ptr align 32 %dst) #0 {
676 ; TUNIT: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(argmem: write) uwtable
677 ; TUNIT-LABEL: define {{[^@]+}}@test13
678 ; TUNIT-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR8:[0-9]+]] {
679 ; TUNIT-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
681 ; TUNIT-NEXT: br label [[END:%.*]]
683 ; TUNIT-NEXT: br label [[END]]
685 ; TUNIT-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ null, [[FALSEBB]] ]
686 ; TUNIT-NEXT: store i32 0, ptr [[PTR]], align 32
687 ; TUNIT-NEXT: ret void
689 ; CGSCC: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(argmem: write) uwtable
690 ; CGSCC-LABEL: define {{[^@]+}}@test13
691 ; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR9:[0-9]+]] {
692 ; CGSCC-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
694 ; CGSCC-NEXT: br label [[END:%.*]]
696 ; CGSCC-NEXT: br label [[END]]
698 ; CGSCC-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ null, [[FALSEBB]] ]
699 ; CGSCC-NEXT: store i32 0, ptr [[PTR]], align 32
700 ; CGSCC-NEXT: ret void
702 br i1 %c, label %truebb, label %falsebb
708 %ptr = phi ptr [ %dst, %truebb ], [ null, %falsebb ]
709 store i32 0, ptr %ptr
713 define void @test13-1(i1 %c, ptr align 32 %dst) {
714 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
715 ; TUNIT-LABEL: define {{[^@]+}}@test13-1
716 ; TUNIT-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR9:[0-9]+]] {
717 ; TUNIT-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
719 ; TUNIT-NEXT: br label [[END:%.*]]
721 ; TUNIT-NEXT: br label [[END]]
723 ; TUNIT-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 48 to ptr), [[FALSEBB]] ]
724 ; TUNIT-NEXT: store i32 0, ptr [[PTR]], align 16
725 ; TUNIT-NEXT: ret void
727 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
728 ; CGSCC-LABEL: define {{[^@]+}}@test13-1
729 ; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR10:[0-9]+]] {
730 ; CGSCC-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
732 ; CGSCC-NEXT: br label [[END:%.*]]
734 ; CGSCC-NEXT: br label [[END]]
736 ; CGSCC-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 48 to ptr), [[FALSEBB]] ]
737 ; CGSCC-NEXT: store i32 0, ptr [[PTR]], align 16
738 ; CGSCC-NEXT: ret void
740 br i1 %c, label %truebb, label %falsebb
746 %ptr = phi ptr [ %dst, %truebb ], [ inttoptr (i64 48 to ptr), %falsebb ]
747 store i32 0, ptr %ptr
751 define void @test13-2(i1 %c, ptr align 32 %dst) {
752 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
753 ; TUNIT-LABEL: define {{[^@]+}}@test13-2
754 ; TUNIT-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR9]] {
755 ; TUNIT-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
757 ; TUNIT-NEXT: br label [[END:%.*]]
759 ; TUNIT-NEXT: br label [[END]]
761 ; TUNIT-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 160 to ptr), [[FALSEBB]] ]
762 ; TUNIT-NEXT: store i32 0, ptr [[PTR]], align 32
763 ; TUNIT-NEXT: ret void
765 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
766 ; CGSCC-LABEL: define {{[^@]+}}@test13-2
767 ; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR10]] {
768 ; CGSCC-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
770 ; CGSCC-NEXT: br label [[END:%.*]]
772 ; CGSCC-NEXT: br label [[END]]
774 ; CGSCC-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 160 to ptr), [[FALSEBB]] ]
775 ; CGSCC-NEXT: store i32 0, ptr [[PTR]], align 32
776 ; CGSCC-NEXT: ret void
778 br i1 %c, label %truebb, label %falsebb
784 %ptr = phi ptr [ %dst, %truebb ], [ inttoptr (i64 160 to ptr), %falsebb ]
785 store i32 0, ptr %ptr
789 define void @test13-3(i1 %c, ptr align 32 %dst) {
790 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
791 ; TUNIT-LABEL: define {{[^@]+}}@test13-3
792 ; TUNIT-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR9]] {
793 ; TUNIT-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
795 ; TUNIT-NEXT: br label [[END:%.*]]
797 ; TUNIT-NEXT: br label [[END]]
799 ; TUNIT-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 128 to ptr), [[FALSEBB]] ]
800 ; TUNIT-NEXT: store i32 0, ptr [[PTR]], align 32
801 ; TUNIT-NEXT: ret void
803 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
804 ; CGSCC-LABEL: define {{[^@]+}}@test13-3
805 ; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr nocapture nofree writeonly align 32 [[DST:%.*]]) #[[ATTR10]] {
806 ; CGSCC-NEXT: br i1 [[C]], label [[TRUEBB:%.*]], label [[FALSEBB:%.*]]
808 ; CGSCC-NEXT: br label [[END:%.*]]
810 ; CGSCC-NEXT: br label [[END]]
812 ; CGSCC-NEXT: [[PTR:%.*]] = phi ptr [ [[DST]], [[TRUEBB]] ], [ inttoptr (i64 128 to ptr), [[FALSEBB]] ]
813 ; CGSCC-NEXT: store i32 0, ptr [[PTR]], align 32
814 ; CGSCC-NEXT: ret void
816 br i1 %c, label %truebb, label %falsebb
822 %ptr = phi ptr [ %dst, %truebb ], [ inttoptr (i64 128 to ptr), %falsebb ]
823 store i32 0, ptr %ptr
827 ; Don't crash on ptr2int/int2ptr uses.
828 define i64 @ptr2int(ptr %p) {
829 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
830 ; TUNIT-LABEL: define {{[^@]+}}@ptr2int
831 ; TUNIT-SAME: (ptr nofree readnone [[P:%.*]]) #[[ATTR10:[0-9]+]] {
832 ; TUNIT-NEXT: [[P2I:%.*]] = ptrtoint ptr [[P]] to i64
833 ; TUNIT-NEXT: ret i64 [[P2I]]
835 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
836 ; CGSCC-LABEL: define {{[^@]+}}@ptr2int
837 ; CGSCC-SAME: (ptr nofree readnone [[P:%.*]]) #[[ATTR11:[0-9]+]] {
838 ; CGSCC-NEXT: [[P2I:%.*]] = ptrtoint ptr [[P]] to i64
839 ; CGSCC-NEXT: ret i64 [[P2I]]
841 %p2i = ptrtoint ptr %p to i64
844 define ptr @int2ptr(i64 %i) {
845 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
846 ; TUNIT-LABEL: define {{[^@]+}}@int2ptr
847 ; TUNIT-SAME: (i64 [[I:%.*]]) #[[ATTR10]] {
848 ; TUNIT-NEXT: [[I2P:%.*]] = inttoptr i64 [[I]] to ptr
849 ; TUNIT-NEXT: ret ptr [[I2P]]
851 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
852 ; CGSCC-LABEL: define {{[^@]+}}@int2ptr
853 ; CGSCC-SAME: (i64 [[I:%.*]]) #[[ATTR11]] {
854 ; CGSCC-NEXT: [[I2P:%.*]] = inttoptr i64 [[I]] to ptr
855 ; CGSCC-NEXT: ret ptr [[I2P]]
857 %i2p = inttoptr i64 %i to ptr
861 ; Use the store alignment only for the pointer operand.
862 define void @aligned_store(ptr %Value, ptr %Ptr) {
863 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
864 ; TUNIT-LABEL: define {{[^@]+}}@aligned_store
865 ; TUNIT-SAME: (ptr nofree writeonly [[VALUE:%.*]], ptr nocapture nofree noundef nonnull writeonly align 32 dereferenceable(8) [[PTR:%.*]]) #[[ATTR5]] {
866 ; TUNIT-NEXT: store ptr [[VALUE]], ptr [[PTR]], align 32
867 ; TUNIT-NEXT: ret void
869 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
870 ; CGSCC-LABEL: define {{[^@]+}}@aligned_store
871 ; CGSCC-SAME: (ptr nofree writeonly [[VALUE:%.*]], ptr nocapture nofree noundef nonnull writeonly align 32 dereferenceable(8) [[PTR:%.*]]) #[[ATTR6]] {
872 ; CGSCC-NEXT: store ptr [[VALUE]], ptr [[PTR]], align 32
873 ; CGSCC-NEXT: ret void
875 store ptr %Value, ptr %Ptr, align 32
879 declare ptr @some_func(ptr)
880 define void @align_call_op_not_store(ptr align 2048 %arg) {
881 ; CHECK-LABEL: define {{[^@]+}}@align_call_op_not_store
882 ; CHECK-SAME: (ptr align 2048 [[ARG:%.*]]) {
883 ; CHECK-NEXT: [[UNKNOWN:%.*]] = call ptr @some_func(ptr align 2048 [[ARG]])
884 ; CHECK-NEXT: store i8 0, ptr [[UNKNOWN]], align 1
885 ; CHECK-NEXT: ret void
887 %unknown = call ptr @some_func(ptr %arg)
888 store i8 0, ptr %unknown
891 define void @align_store_after_bc(ptr align 2048 %arg) {
893 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
894 ; TUNIT-LABEL: define {{[^@]+}}@align_store_after_bc
895 ; TUNIT-SAME: (ptr nocapture nofree nonnull writeonly align 2048 dereferenceable(1) [[ARG:%.*]]) #[[ATTR5]] {
896 ; TUNIT-NEXT: store i8 0, ptr [[ARG]], align 2048
897 ; TUNIT-NEXT: ret void
899 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
900 ; CGSCC-LABEL: define {{[^@]+}}@align_store_after_bc
901 ; CGSCC-SAME: (ptr nocapture nofree nonnull writeonly align 2048 dereferenceable(1) [[ARG:%.*]]) #[[ATTR6]] {
902 ; CGSCC-NEXT: store i8 0, ptr [[ARG]], align 2048
903 ; CGSCC-NEXT: ret void
905 %bc = bitcast ptr %arg to ptr
910 ; Make sure we do not annotate the callee of a must-tail call with an alignment
911 ; we cannot also put on the caller.
912 @cnd = external global i1
913 define i32 @musttail_callee_1(ptr %p) {
914 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
915 ; TUNIT-LABEL: define {{[^@]+}}@musttail_callee_1
916 ; TUNIT-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(4) [[P:%.*]]) #[[ATTR4]] {
917 ; TUNIT-NEXT: [[V:%.*]] = load i32, ptr [[P]], align 32
918 ; TUNIT-NEXT: ret i32 [[V]]
920 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
921 ; CGSCC-LABEL: define {{[^@]+}}@musttail_callee_1
922 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(4) [[P:%.*]]) #[[ATTR5]] {
923 ; CGSCC-NEXT: [[V:%.*]] = load i32, ptr [[P]], align 32
924 ; CGSCC-NEXT: ret i32 [[V]]
926 %v = load i32, ptr %p, align 32
929 define i32 @musttail_caller_1(ptr %p) {
930 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
931 ; TUNIT-LABEL: define {{[^@]+}}@musttail_caller_1
932 ; TUNIT-SAME: (ptr nocapture nofree readonly [[P:%.*]]) #[[ATTR11:[0-9]+]] {
933 ; TUNIT-NEXT: [[C:%.*]] = load i1, ptr @cnd, align 1
934 ; TUNIT-NEXT: br i1 [[C]], label [[MT:%.*]], label [[EXIT:%.*]]
936 ; TUNIT-NEXT: [[V:%.*]] = musttail call i32 @musttail_callee_1(ptr nocapture nofree noundef readonly [[P]]) #[[ATTR12:[0-9]+]]
937 ; TUNIT-NEXT: ret i32 [[V]]
939 ; TUNIT-NEXT: ret i32 0
941 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read)
942 ; CGSCC-LABEL: define {{[^@]+}}@musttail_caller_1
943 ; CGSCC-SAME: (ptr nocapture nofree readonly [[P:%.*]]) #[[ATTR12:[0-9]+]] {
944 ; CGSCC-NEXT: [[C:%.*]] = load i1, ptr @cnd, align 1
945 ; CGSCC-NEXT: br i1 [[C]], label [[MT:%.*]], label [[EXIT:%.*]]
947 ; CGSCC-NEXT: [[V:%.*]] = musttail call i32 @musttail_callee_1(ptr nocapture nofree noundef nonnull readonly dereferenceable(4) [[P]]) #[[ATTR15:[0-9]+]]
948 ; CGSCC-NEXT: ret i32 [[V]]
950 ; CGSCC-NEXT: ret i32 0
952 %c = load i1, ptr @cnd
953 br i1 %c, label %mt, label %exit
955 %v = musttail call i32 @musttail_callee_1(ptr %p)
961 define ptr @checkAndAdvance(ptr align(16) %p) {
962 ; TUNIT: Function Attrs: nounwind
963 ; TUNIT-LABEL: define {{[^@]+}}@checkAndAdvance
964 ; TUNIT-SAME: (ptr nofree noundef nonnull readonly align 16 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR2]] {
966 ; TUNIT-NEXT: [[TMP0:%.*]] = load i32, ptr [[P]], align 16
967 ; TUNIT-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], 0
968 ; TUNIT-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
970 ; TUNIT-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 4
971 ; TUNIT-NEXT: [[CALL:%.*]] = call ptr @checkAndAdvance(ptr nofree noundef nonnull readonly align 16 "no-capture-maybe-returned" [[ADD_PTR]]) #[[ATTR2]]
972 ; TUNIT-NEXT: br label [[RETURN]]
974 ; TUNIT-NEXT: [[RETVAL_0:%.*]] = phi ptr [ [[ADD_PTR]], [[IF_THEN]] ], [ [[P]], [[ENTRY:%.*]] ]
975 ; TUNIT-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree nonnull readnone align 16 [[RETVAL_0]]) #[[ATTR2]]
976 ; TUNIT-NEXT: ret ptr [[RETVAL_0]]
978 ; CGSCC: Function Attrs: nounwind
979 ; CGSCC-LABEL: define {{[^@]+}}@checkAndAdvance
980 ; CGSCC-SAME: (ptr nofree noundef nonnull readonly align 16 dereferenceable(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR3]] {
982 ; CGSCC-NEXT: [[TMP0:%.*]] = load i32, ptr [[P]], align 16
983 ; CGSCC-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], 0
984 ; CGSCC-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[RETURN:%.*]]
986 ; CGSCC-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 4
987 ; CGSCC-NEXT: [[CALL:%.*]] = call ptr @checkAndAdvance(ptr nofree noundef nonnull readonly align 16 "no-capture-maybe-returned" [[ADD_PTR]]) #[[ATTR3]]
988 ; CGSCC-NEXT: br label [[RETURN]]
990 ; CGSCC-NEXT: [[RETVAL_0:%.*]] = phi ptr [ [[ADD_PTR]], [[IF_THEN]] ], [ [[P]], [[ENTRY:%.*]] ]
991 ; CGSCC-NEXT: call void @user_i32_ptr(ptr noalias nocapture nofree nonnull readnone align 16 [[RETVAL_0]]) #[[ATTR3]]
992 ; CGSCC-NEXT: ret ptr [[RETVAL_0]]
995 %0 = load i32, ptr %p, align 4
996 %cmp = icmp eq i32 %0, 0
997 br i1 %cmp, label %if.then, label %return
999 if.then: ; preds = %entry
1000 %add.ptr = getelementptr inbounds i32, ptr %p, i64 4
1001 %call = call ptr @checkAndAdvance(ptr nonnull %add.ptr)
1004 return: ; preds = %entry, %if.then
1005 %retval.0 = phi ptr [ %call, %if.then ], [ %p, %entry ]
1006 call void @user_i32_ptr(ptr %retval.0)
1010 ; FIXME: align 4 should not be propagated to the caller's p unless there is noundef
1011 define void @align4_caller(ptr %p) {
1012 ; CHECK-LABEL: define {{[^@]+}}@align4_caller
1013 ; CHECK-SAME: (ptr align 4 [[P:%.*]]) {
1014 ; CHECK-NEXT: call void @align4_callee(ptr align 4 [[P]])
1015 ; CHECK-NEXT: ret void
1017 call void @align4_callee(ptr %p)
1021 declare void @align4_callee(ptr align(4) %p)
1023 @G = global i8 0, align 32
1025 define internal ptr @aligned_8_return(ptr %a, i1 %c1, i1 %c2) norecurse {
1026 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1027 ; TUNIT-LABEL: define {{[^@]+}}@aligned_8_return
1028 ; TUNIT-SAME: (ptr noalias nofree readnone align 16 "no-capture-maybe-returned" [[A:%.*]], i1 noundef [[C1:%.*]], i1 [[C2:%.*]]) #[[ATTR10]] {
1029 ; TUNIT-NEXT: [[STACK:%.*]] = alloca ptr, align 8
1030 ; TUNIT-NEXT: br i1 [[C1]], label [[T:%.*]], label [[F:%.*]]
1032 ; TUNIT-NEXT: [[GEP:%.*]] = getelementptr i8, ptr @G, i32 8
1033 ; TUNIT-NEXT: [[SEL:%.*]] = select i1 [[C2]], ptr [[A]], ptr [[GEP]]
1034 ; TUNIT-NEXT: store ptr [[SEL]], ptr [[STACK]], align 8
1035 ; TUNIT-NEXT: br label [[END:%.*]]
1037 ; TUNIT-NEXT: store ptr @G, ptr [[STACK]], align 8
1038 ; TUNIT-NEXT: br label [[END]]
1040 ; TUNIT-NEXT: [[L:%.*]] = load ptr, ptr [[STACK]], align 8
1041 ; TUNIT-NEXT: ret ptr [[L]]
1043 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1044 ; CGSCC-LABEL: define {{[^@]+}}@aligned_8_return
1045 ; CGSCC-SAME: (ptr noalias nofree readnone align 16 "no-capture-maybe-returned" [[A:%.*]], i1 noundef [[C1:%.*]], i1 [[C2:%.*]]) #[[ATTR11]] {
1046 ; CGSCC-NEXT: [[STACK:%.*]] = alloca ptr, align 8
1047 ; CGSCC-NEXT: br i1 [[C1]], label [[T:%.*]], label [[F:%.*]]
1049 ; CGSCC-NEXT: [[GEP:%.*]] = getelementptr i8, ptr @G, i32 8
1050 ; CGSCC-NEXT: [[SEL:%.*]] = select i1 [[C2]], ptr [[A]], ptr [[GEP]]
1051 ; CGSCC-NEXT: store ptr [[SEL]], ptr [[STACK]], align 8
1052 ; CGSCC-NEXT: br label [[END:%.*]]
1054 ; CGSCC-NEXT: store ptr @G, ptr [[STACK]], align 8
1055 ; CGSCC-NEXT: br label [[END]]
1057 ; CGSCC-NEXT: [[L:%.*]] = load ptr, ptr [[STACK]], align 8
1058 ; CGSCC-NEXT: ret ptr [[L]]
1061 br i1 %c1, label %t, label %f
1063 %gep = getelementptr i8, ptr @G, i32 8
1064 %sel = select i1 %c2, ptr %a, ptr %gep
1065 store ptr %sel, ptr %stack
1068 store ptr @G, ptr %stack
1071 %l = load ptr, ptr %stack
1075 define ptr @aligned_8_return_caller(ptr align(16) %a, i1 %c1, i1 %c2) {
1076 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1077 ; TUNIT-LABEL: define {{[^@]+}}@aligned_8_return_caller
1078 ; TUNIT-SAME: (ptr nofree readnone align 16 "no-capture-maybe-returned" [[A:%.*]], i1 [[C1:%.*]], i1 [[C2:%.*]]) #[[ATTR10]] {
1079 ; TUNIT-NEXT: [[R:%.*]] = call align 8 ptr @aligned_8_return(ptr noalias nofree readnone align 16 "no-capture-maybe-returned" [[A]], i1 noundef [[C1]], i1 [[C2]]) #[[ATTR13:[0-9]+]]
1080 ; TUNIT-NEXT: ret ptr [[R]]
1082 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
1083 ; CGSCC-LABEL: define {{[^@]+}}@aligned_8_return_caller
1084 ; CGSCC-SAME: (ptr nofree readnone align 16 [[A:%.*]], i1 noundef [[C1:%.*]], i1 [[C2:%.*]]) #[[ATTR13:[0-9]+]] {
1085 ; CGSCC-NEXT: [[R:%.*]] = call align 8 ptr @aligned_8_return(ptr noalias nofree readnone align 16 [[A]], i1 noundef [[C1]], i1 [[C2]]) #[[ATTR14]]
1086 ; CGSCC-NEXT: ret ptr [[R]]
1088 %r = call ptr @aligned_8_return(ptr %a, i1 %c1, i1 %c2)
1092 define i32 @implicit_cast_caller(ptr %ptr) {
1093 ; CHECK-LABEL: define {{[^@]+}}@implicit_cast_caller
1094 ; CHECK-SAME: (ptr [[PTR:%.*]]) {
1095 ; CHECK-NEXT: entry:
1096 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @implicit_cast_callee(ptr [[PTR]])
1097 ; CHECK-NEXT: ret i32 0
1100 %call = tail call i32 @implicit_cast_callee(ptr %ptr)
1104 declare void @implicit_cast_callee(i64)
1106 attributes #0 = { nounwind uwtable noinline }
1107 attributes #1 = { uwtable noinline }
1108 attributes #2 = { null_pointer_is_valid }
1110 ; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable }
1111 ; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable }
1112 ; TUNIT: attributes #[[ATTR2]] = { nounwind }
1113 ; TUNIT: attributes #[[ATTR3]] = { nofree nosync nounwind }
1114 ; TUNIT: attributes #[[ATTR4]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
1115 ; TUNIT: attributes #[[ATTR5]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
1116 ; TUNIT: attributes #[[ATTR6]] = { nounwind willreturn }
1117 ; TUNIT: attributes #[[ATTR7]] = { mustprogress nounwind willreturn }
1118 ; TUNIT: attributes #[[ATTR8]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(argmem: write) uwtable }
1119 ; TUNIT: attributes #[[ATTR9]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write) }
1120 ; TUNIT: attributes #[[ATTR10]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
1121 ; TUNIT: attributes #[[ATTR11]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read) }
1122 ; TUNIT: attributes #[[ATTR12]] = { nofree nosync nounwind willreturn memory(read) }
1123 ; TUNIT: attributes #[[ATTR13]] = { nofree nosync nounwind willreturn }
1125 ; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(none) uwtable }
1126 ; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree noinline nosync nounwind willreturn memory(none) uwtable }
1127 ; CGSCC: attributes #[[ATTR2]] = { noinline nounwind uwtable }
1128 ; CGSCC: attributes #[[ATTR3]] = { nounwind }
1129 ; CGSCC: attributes #[[ATTR4]] = { nofree nosync nounwind }
1130 ; CGSCC: attributes #[[ATTR5]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
1131 ; CGSCC: attributes #[[ATTR6]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
1132 ; CGSCC: attributes #[[ATTR7]] = { nounwind willreturn }
1133 ; CGSCC: attributes #[[ATTR8]] = { mustprogress nounwind willreturn }
1134 ; CGSCC: attributes #[[ATTR9]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(argmem: write) uwtable }
1135 ; CGSCC: attributes #[[ATTR10]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write) }
1136 ; CGSCC: attributes #[[ATTR11]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
1137 ; CGSCC: attributes #[[ATTR12]] = { mustprogress nofree nosync nounwind willreturn memory(read) }
1138 ; CGSCC: attributes #[[ATTR13]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
1139 ; CGSCC: attributes #[[ATTR14]] = { nofree nosync willreturn }
1140 ; CGSCC: attributes #[[ATTR15]] = { nofree willreturn memory(read) }