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 ; musttail call result can't be replaced with a constant, unless the call can be removed
7 declare i32 @external()
9 define ptr @start(i8 %v) {
11 ; TUNIT-LABEL: define {{[^@]+}}@start
12 ; TUNIT-SAME: (i8 [[V:%.*]]) {
13 ; TUNIT-NEXT: [[C1:%.*]] = icmp eq i8 [[V]], 0
14 ; TUNIT-NEXT: br i1 [[C1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
16 ; TUNIT-NEXT: [[CA:%.*]] = musttail call noalias noundef align 4294967296 ptr @side_effects(i8 [[V]])
17 ; TUNIT-NEXT: ret ptr [[CA]]
19 ; TUNIT-NEXT: [[C2:%.*]] = icmp eq i8 [[V]], 1
20 ; TUNIT-NEXT: br i1 [[C2]], label [[C2_TRUE:%.*]], label [[C2_FALSE:%.*]]
22 ; TUNIT-NEXT: ret ptr null
24 ; TUNIT-NEXT: [[CA2:%.*]] = musttail call noalias noundef align 4294967296 ptr @dont_zap_me(i8 undef)
25 ; TUNIT-NEXT: ret ptr [[CA2]]
27 ; CGSCC-LABEL: define {{[^@]+}}@start
28 ; CGSCC-SAME: (i8 [[V:%.*]]) {
29 ; CGSCC-NEXT: [[C1:%.*]] = icmp eq i8 [[V]], 0
30 ; CGSCC-NEXT: br i1 [[C1]], label [[TRUE:%.*]], label [[FALSE:%.*]]
32 ; CGSCC-NEXT: [[CA:%.*]] = musttail call noalias noundef align 4294967296 ptr @side_effects(i8 [[V]])
33 ; CGSCC-NEXT: ret ptr [[CA]]
35 ; CGSCC-NEXT: [[C2:%.*]] = icmp eq i8 [[V]], 1
36 ; CGSCC-NEXT: br i1 [[C2]], label [[C2_TRUE:%.*]], label [[C2_FALSE:%.*]]
38 ; CGSCC-NEXT: [[CA1:%.*]] = musttail call noalias noundef align 4294967296 ptr @no_side_effects(i8 [[V]])
39 ; CGSCC-NEXT: ret ptr [[CA1]]
41 ; CGSCC-NEXT: [[CA2:%.*]] = musttail call noalias noundef align 4294967296 ptr @dont_zap_me(i8 [[V]])
42 ; CGSCC-NEXT: ret ptr [[CA2]]
44 %c1 = icmp eq i8 %v, 0
45 br i1 %c1, label %true, label %false
47 ; FIXME: propagate the value information for %v
48 %ca = musttail call ptr @side_effects(i8 %v)
51 %c2 = icmp eq i8 %v, 1
52 br i1 %c2, label %c2_true, label %c2_false
54 %ca1 = musttail call ptr @no_side_effects(i8 %v)
57 %ca2 = musttail call ptr @dont_zap_me(i8 %v)
61 define internal ptr @side_effects(i8 %v) {
62 ; CHECK-LABEL: define {{[^@]+}}@side_effects
63 ; CHECK-SAME: (i8 [[V:%.*]]) {
64 ; CHECK-NEXT: [[I1:%.*]] = call i32 @external()
65 ; CHECK-NEXT: [[CA:%.*]] = musttail call noalias noundef align 4294967296 ptr @start(i8 0)
66 ; CHECK-NEXT: ret ptr [[CA]]
68 %i1 = call i32 @external()
70 ; since this goes back to `start` the SCPP should be see that the return value
72 ; The call can't be removed due to `external` call above, though.
74 %ca = musttail call ptr @start(i8 %v)
76 ; Thus the result must be returned anyway
80 define internal ptr @no_side_effects(i8 %v) readonly nounwind {
81 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
82 ; CGSCC-LABEL: define {{[^@]+}}@no_side_effects
83 ; CGSCC-SAME: (i8 [[V:%.*]]) #[[ATTR0:[0-9]+]] {
84 ; CGSCC-NEXT: ret ptr null
89 define internal ptr @dont_zap_me(i8 %v) {
90 ; CHECK-LABEL: define {{[^@]+}}@dont_zap_me
91 ; CHECK-SAME: (i8 [[V:%.*]]) {
92 ; CHECK-NEXT: [[I1:%.*]] = call i32 @external()
93 ; CHECK-NEXT: ret ptr null
95 %i1 = call i32 @external()
99 ; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }