1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
4 ; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
5 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
8 ; Don't promote arguments of musttail callee
10 %T = type { i32, i32, i32, i32 }
12 define internal i32 @test(%T* %p) {
13 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind readonly willreturn
14 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test
15 ; IS__TUNIT____-SAME: (%T* nocapture nofree readonly [[P:%.*]]) #[[ATTR0:[0-9]+]] {
16 ; IS__TUNIT____-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
17 ; IS__TUNIT____-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
18 ; IS__TUNIT____-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]], align 4
19 ; IS__TUNIT____-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]], align 4
20 ; IS__TUNIT____-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
21 ; IS__TUNIT____-NEXT: ret i32 [[V]]
23 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind readonly willreturn
24 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test
25 ; IS__CGSCC____-SAME: (%T* nocapture nofree readonly [[P:%.*]]) #[[ATTR0:[0-9]+]] {
26 ; IS__CGSCC____-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
27 ; IS__CGSCC____-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
28 ; IS__CGSCC____-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]], align 4
29 ; IS__CGSCC____-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]], align 4
30 ; IS__CGSCC____-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
31 ; IS__CGSCC____-NEXT: ret i32 [[V]]
33 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
34 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
35 %a = load i32, i32* %a.gep
36 %b = load i32, i32* %b.gep
41 define i32 @caller(%T* %p) {
42 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind readonly willreturn
43 ; IS__TUNIT____-LABEL: define {{[^@]+}}@caller
44 ; IS__TUNIT____-SAME: (%T* nocapture nofree readonly [[P:%.*]]) #[[ATTR0]] {
45 ; IS__TUNIT____-NEXT: [[V:%.*]] = musttail call i32 @test(%T* nocapture nofree readonly [[P]]) #[[ATTR4:[0-9]+]]
46 ; IS__TUNIT____-NEXT: ret i32 [[V]]
48 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind readonly willreturn
49 ; IS__CGSCC____-LABEL: define {{[^@]+}}@caller
50 ; IS__CGSCC____-SAME: (%T* nocapture nofree readonly [[P:%.*]]) #[[ATTR0]] {
51 ; IS__CGSCC____-NEXT: [[V:%.*]] = musttail call i32 @test(%T* nocapture nofree readonly [[P]]) #[[ATTR4:[0-9]+]]
52 ; IS__CGSCC____-NEXT: ret i32 [[V]]
54 %v = musttail call i32 @test(%T* %p)
58 ; Don't promote arguments of musttail caller
60 define i32 @foo(%T* %p, i32 %v) {
61 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
62 ; IS__TUNIT____-LABEL: define {{[^@]+}}@foo
63 ; IS__TUNIT____-SAME: (%T* nocapture nofree readnone [[P:%.*]], i32 [[V:%.*]]) #[[ATTR1:[0-9]+]] {
64 ; IS__TUNIT____-NEXT: ret i32 0
66 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
67 ; IS__CGSCC____-LABEL: define {{[^@]+}}@foo
68 ; IS__CGSCC____-SAME: (%T* nocapture nofree readnone [[P:%.*]], i32 [[V:%.*]]) #[[ATTR1:[0-9]+]] {
69 ; IS__CGSCC____-NEXT: ret i32 0
74 define internal i32 @test2(%T* %p, i32 %p2) {
75 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
76 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test2
77 ; IS__CGSCC____-SAME: (%T* noalias nocapture nofree readnone [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR1]] {
78 ; IS__CGSCC____-NEXT: ret i32 undef
80 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
81 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
82 %a = load i32, i32* %a.gep
83 %b = load i32, i32* %b.gep
85 %ca = musttail call i32 @foo(%T* undef, i32 %v)
89 define i32 @caller2(%T* %g) {
90 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
91 ; IS__TUNIT____-LABEL: define {{[^@]+}}@caller2
92 ; IS__TUNIT____-SAME: (%T* nocapture nofree readnone [[G:%.*]]) #[[ATTR1]] {
93 ; IS__TUNIT____-NEXT: ret i32 0
95 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
96 ; IS__CGSCC____-LABEL: define {{[^@]+}}@caller2
97 ; IS__CGSCC____-SAME: (%T* nocapture nofree readnone [[G:%.*]]) #[[ATTR1]] {
98 ; IS__CGSCC____-NEXT: ret i32 0
100 %v = call i32 @test2(%T* %g, i32 0)
104 ; In the version above we can remove the call to foo completely.
105 ; In the version below we keep the call and verify the return value
108 define i32 @bar(%T* %p, i32 %v) {
109 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
110 ; IS__TUNIT____-LABEL: define {{[^@]+}}@bar
111 ; IS__TUNIT____-SAME: (%T* nocapture nofree nonnull writeonly dereferenceable(4) [[P:%.*]], i32 [[V:%.*]]) #[[ATTR2:[0-9]+]] {
112 ; IS__TUNIT____-NEXT: [[I32PTR:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 0
113 ; IS__TUNIT____-NEXT: store i32 [[V]], i32* [[I32PTR]], align 4
114 ; IS__TUNIT____-NEXT: ret i32 0
116 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
117 ; IS__CGSCC____-LABEL: define {{[^@]+}}@bar
118 ; IS__CGSCC____-SAME: (%T* nocapture nofree nonnull writeonly dereferenceable(4) [[P:%.*]], i32 [[V:%.*]]) #[[ATTR2:[0-9]+]] {
119 ; IS__CGSCC____-NEXT: [[I32PTR:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 0
120 ; IS__CGSCC____-NEXT: store i32 [[V]], i32* [[I32PTR]], align 4
121 ; IS__CGSCC____-NEXT: ret i32 0
123 %i32ptr = getelementptr %T, %T* %p, i64 0, i32 0
124 store i32 %v, i32* %i32ptr
128 define internal i32 @test2b(%T* %p, i32 %p2) {
129 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn
130 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test2b
131 ; IS__TUNIT____-SAME: (%T* nocapture nofree readonly [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR3:[0-9]+]] {
132 ; IS__TUNIT____-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
133 ; IS__TUNIT____-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
134 ; IS__TUNIT____-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]], align 4
135 ; IS__TUNIT____-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]], align 4
136 ; IS__TUNIT____-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
137 ; IS__TUNIT____-NEXT: [[CA:%.*]] = musttail call i32 @bar(%T* undef, i32 [[V]]) #[[ATTR5:[0-9]+]]
138 ; IS__TUNIT____-NEXT: ret i32 [[CA]]
140 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn
141 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test2b
142 ; IS__CGSCC____-SAME: (%T* nocapture nofree readonly [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR3:[0-9]+]] {
143 ; IS__CGSCC____-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
144 ; IS__CGSCC____-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
145 ; IS__CGSCC____-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]], align 4
146 ; IS__CGSCC____-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]], align 4
147 ; IS__CGSCC____-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
148 ; IS__CGSCC____-NEXT: [[CA:%.*]] = musttail call i32 @bar(%T* undef, i32 [[V]]) #[[ATTR5:[0-9]+]]
149 ; IS__CGSCC____-NEXT: ret i32 [[CA]]
151 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
152 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
153 %a = load i32, i32* %a.gep
154 %b = load i32, i32* %b.gep
156 %ca = musttail call i32 @bar(%T* undef, i32 %v)
160 define i32 @caller2b(%T* %g) {
161 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn
162 ; IS__TUNIT____-LABEL: define {{[^@]+}}@caller2b
163 ; IS__TUNIT____-SAME: (%T* nocapture nofree readonly [[G:%.*]]) #[[ATTR3]] {
164 ; IS__TUNIT____-NEXT: [[V:%.*]] = call i32 @test2b(%T* nocapture nofree readonly [[G]], i32 undef) #[[ATTR6:[0-9]+]]
165 ; IS__TUNIT____-NEXT: ret i32 0
167 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn
168 ; IS__CGSCC____-LABEL: define {{[^@]+}}@caller2b
169 ; IS__CGSCC____-SAME: (%T* nocapture nofree readonly [[G:%.*]]) #[[ATTR3]] {
170 ; IS__CGSCC____-NEXT: [[V:%.*]] = call i32 @test2b(%T* nocapture nofree readonly [[G]], i32 undef) #[[ATTR6:[0-9]+]]
171 ; IS__CGSCC____-NEXT: ret i32 0
173 %v = call i32 @test2b(%T* %g, i32 0)
177 ; IS__TUNIT____: attributes #[[ATTR0]] = { argmemonly nofree nosync nounwind readonly willreturn }
178 ; IS__TUNIT____: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
179 ; IS__TUNIT____: attributes #[[ATTR2]] = { argmemonly nofree nosync nounwind willreturn writeonly }
180 ; IS__TUNIT____: attributes #[[ATTR3]] = { argmemonly nofree nosync nounwind willreturn }
181 ; IS__TUNIT____: attributes #[[ATTR4]] = { nofree nosync nounwind readonly willreturn }
182 ; IS__TUNIT____: attributes #[[ATTR5]] = { nofree nosync nounwind willreturn writeonly }
183 ; IS__TUNIT____: attributes #[[ATTR6]] = { nofree nosync nounwind willreturn }
185 ; IS__CGSCC____: attributes #[[ATTR0]] = { argmemonly nofree norecurse nosync nounwind readonly willreturn }
186 ; IS__CGSCC____: attributes #[[ATTR1]] = { nofree norecurse nosync nounwind readnone willreturn }
187 ; IS__CGSCC____: attributes #[[ATTR2]] = { argmemonly nofree norecurse nosync nounwind willreturn writeonly }
188 ; IS__CGSCC____: attributes #[[ATTR3]] = { argmemonly nofree norecurse nosync nounwind willreturn }
189 ; IS__CGSCC____: attributes #[[ATTR4]] = { nosync nounwind readonly willreturn }
190 ; IS__CGSCC____: attributes #[[ATTR5]] = { nounwind willreturn writeonly }
191 ; IS__CGSCC____: attributes #[[ATTR6]] = { nosync nounwind willreturn }