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=2 -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=2 -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
6
7define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
8; IS__TUNIT____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
9; IS__TUNIT____-LABEL: define {{[^@]+}}@visible
10; IS__TUNIT____-SAME: (i32* noalias nocapture nofree readonly align 4 [[A:%.*]], i32* noalias nocapture nofree readonly align 4 [[B:%.*]]) #[[ATTR0:[0-9]+]] {
11; IS__TUNIT____-NEXT:  entry:
12; IS__TUNIT____-NEXT:    [[CALL1:%.*]] = call i32 @noalias_args(i32* noalias nocapture nofree readonly align 4 [[A]], i32* noalias nocapture nofree readonly align 4 [[B]]) #[[ATTR3:[0-9]+]]
13; IS__TUNIT____-NEXT:    [[CALL2:%.*]] = call i32 @noalias_args_argmem(i32* noalias nocapture nofree readonly align 4 [[A]], i32* noalias nocapture nofree readonly align 4 [[B]]) #[[ATTR3]]
14; IS__TUNIT____-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]
15; IS__TUNIT____-NEXT:    ret i32 [[ADD]]
16;
17; IS__CGSCC____: Function Attrs: argmemonly nofree noinline nosync nounwind readonly willreturn uwtable
18; IS__CGSCC____-LABEL: define {{[^@]+}}@visible
19; IS__CGSCC____-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR0:[0-9]+]] {
20; IS__CGSCC____-NEXT:  entry:
21; IS__CGSCC____-NEXT:    [[CALL1:%.*]] = call i32 @noalias_args(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR5:[0-9]+]]
22; IS__CGSCC____-NEXT:    [[CALL2:%.*]] = call i32 @noalias_args_argmem(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR5]]
23; IS__CGSCC____-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]
24; IS__CGSCC____-NEXT:    ret i32 [[ADD]]
25;
26entry:
27  %call1 = call i32 @noalias_args(i32* %A, i32* %B)
28  %call2 = call i32 @noalias_args_argmem(i32* %A, i32* %B)
29  %add = add nsw i32 %call1, %call2
30  ret i32 %add
31}
32
33define private i32 @noalias_args(i32* %A, i32* %B) #0 {
34; IS__TUNIT____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
35; IS__TUNIT____-LABEL: define {{[^@]+}}@noalias_args
36; IS__TUNIT____-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR0]] {
37; IS__TUNIT____-NEXT:  entry:
38; IS__TUNIT____-NEXT:    [[TMP0:%.*]] = load i32, i32* [[A]], align 4
39; IS__TUNIT____-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B]], align 4
40; IS__TUNIT____-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
41; IS__TUNIT____-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem(i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR3]]
42; IS__TUNIT____-NEXT:    [[ADD2:%.*]] = add nsw i32 [[ADD]], [[CALL]]
43; IS__TUNIT____-NEXT:    ret i32 [[ADD2]]
44;
45; IS__CGSCC____: Function Attrs: argmemonly nofree noinline nosync nounwind readonly willreturn uwtable
46; IS__CGSCC____-LABEL: define {{[^@]+}}@noalias_args
47; IS__CGSCC____-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR0]] {
48; IS__CGSCC____-NEXT:  entry:
49; IS__CGSCC____-NEXT:    [[TMP0:%.*]] = load i32, i32* [[A]], align 4
50; IS__CGSCC____-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B]], align 4
51; IS__CGSCC____-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
52; IS__CGSCC____-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem(i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR5]]
53; IS__CGSCC____-NEXT:    [[ADD2:%.*]] = add nsw i32 [[ADD]], [[CALL]]
54; IS__CGSCC____-NEXT:    ret i32 [[ADD2]]
55;
56entry:
57  %0 = load i32, i32* %A, align 4
58  %1 = load i32, i32* %B, align 4
59  %add = add nsw i32 %0, %1
60  %call = call i32 @noalias_args_argmem(i32* %A, i32* %B)
61  %add2 = add nsw i32 %add, %call
62  ret i32 %add2
63}
64
65
66define internal i32 @noalias_args_argmem(i32* %A, i32* %B) #1 {
67; IS__TUNIT____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
68; IS__TUNIT____-LABEL: define {{[^@]+}}@noalias_args_argmem
69; IS__TUNIT____-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR0]] {
70; IS__TUNIT____-NEXT:  entry:
71; IS__TUNIT____-NEXT:    [[TMP0:%.*]] = load i32, i32* [[A]], align 4
72; IS__TUNIT____-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B]], align 4
73; IS__TUNIT____-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
74; IS__TUNIT____-NEXT:    ret i32 [[ADD]]
75;
76; IS__CGSCC____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
77; IS__CGSCC____-LABEL: define {{[^@]+}}@noalias_args_argmem
78; IS__CGSCC____-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR1:[0-9]+]] {
79; IS__CGSCC____-NEXT:  entry:
80; IS__CGSCC____-NEXT:    [[TMP0:%.*]] = load i32, i32* [[A]], align 4
81; IS__CGSCC____-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B]], align 4
82; IS__CGSCC____-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP1]]
83; IS__CGSCC____-NEXT:    ret i32 [[ADD]]
84;
85entry:
86  %0 = load i32, i32* %A, align 4
87  %1 = load i32, i32* %B, align 4
88  %add = add nsw i32 %0, %1
89  ret i32 %add
90}
91
92define dso_local i32 @visible_local(i32* %A) #0 {
93; IS__TUNIT____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind willreturn uwtable
94; IS__TUNIT____-LABEL: define {{[^@]+}}@visible_local
95; IS__TUNIT____-SAME: (i32* nocapture nofree readonly [[A:%.*]]) #[[ATTR1:[0-9]+]] {
96; IS__TUNIT____-NEXT:  entry:
97; IS__TUNIT____-NEXT:    [[B:%.*]] = alloca i32, align 4
98; IS__TUNIT____-NEXT:    store i32 5, i32* [[B]], align 4
99; IS__TUNIT____-NEXT:    [[CALL1:%.*]] = call i32 @noalias_args(i32* nocapture nofree readonly align 4 [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR3]]
100; IS__TUNIT____-NEXT:    [[CALL2:%.*]] = call i32 @noalias_args_argmem(i32* nocapture nofree readonly align 4 [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR3]]
101; IS__TUNIT____-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]
102; IS__TUNIT____-NEXT:    ret i32 [[ADD]]
103;
104; IS__CGSCC____: Function Attrs: argmemonly nofree noinline nosync nounwind willreturn uwtable
105; IS__CGSCC____-LABEL: define {{[^@]+}}@visible_local
106; IS__CGSCC____-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR2:[0-9]+]] {
107; IS__CGSCC____-NEXT:  entry:
108; IS__CGSCC____-NEXT:    [[B:%.*]] = alloca i32, align 4
109; IS__CGSCC____-NEXT:    store i32 5, i32* [[B]], align 4
110; IS__CGSCC____-NEXT:    [[CALL1:%.*]] = call i32 @noalias_args(i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR5]]
111; IS__CGSCC____-NEXT:    [[CALL2:%.*]] = call i32 @noalias_args_argmem(i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]])
112; IS__CGSCC____-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]
113; IS__CGSCC____-NEXT:    ret i32 [[ADD]]
114;
115entry:
116  %B = alloca i32, align 4
117  store i32 5, i32* %B, align 4
118  %call1 = call i32 @noalias_args(i32* %A, i32* nonnull %B)
119  %call2 = call i32 @noalias_args_argmem(i32* %A, i32* nonnull %B)
120  %add = add nsw i32 %call1, %call2
121  ret i32 %add
122}
123
124define internal i32 @noalias_args_argmem_ro(i32* %A, i32* %B) #1 {
125; IS__CGSCC_OPM: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
126; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@noalias_args_argmem_ro
127; IS__CGSCC_OPM-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR1]] {
128; IS__CGSCC_OPM-NEXT:    [[T0:%.*]] = load i32, i32* [[A]], align 4
129; IS__CGSCC_OPM-NEXT:    [[T1:%.*]] = load i32, i32* [[B]], align 4
130; IS__CGSCC_OPM-NEXT:    [[ADD:%.*]] = add nsw i32 [[T0]], [[T1]]
131; IS__CGSCC_OPM-NEXT:    ret i32 [[ADD]]
132;
133; IS__CGSCC_NPM: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable
134; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@noalias_args_argmem_ro
135; IS__CGSCC_NPM-SAME: (i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR1]] {
136; IS__CGSCC_NPM-NEXT:    [[B_PRIV:%.*]] = alloca i32, align 4
137; IS__CGSCC_NPM-NEXT:    store i32 [[TMP1]], i32* [[B_PRIV]], align 4
138; IS__CGSCC_NPM-NEXT:    [[A_PRIV:%.*]] = alloca i32, align 4
139; IS__CGSCC_NPM-NEXT:    store i32 [[TMP0]], i32* [[A_PRIV]], align 4
140; IS__CGSCC_NPM-NEXT:    [[T0:%.*]] = load i32, i32* [[A_PRIV]], align 4
141; IS__CGSCC_NPM-NEXT:    [[T1:%.*]] = load i32, i32* [[B_PRIV]], align 4
142; IS__CGSCC_NPM-NEXT:    [[ADD:%.*]] = add nsw i32 [[T0]], [[T1]]
143; IS__CGSCC_NPM-NEXT:    ret i32 [[ADD]]
144;
145  %t0 = load i32, i32* %A, align 4
146  %t1 = load i32, i32* %B, align 4
147  %add = add nsw i32 %t0, %t1
148  ret i32 %add
149}
150
151define i32 @visible_local_2() {
152; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
153; IS__TUNIT____-LABEL: define {{[^@]+}}@visible_local_2
154; IS__TUNIT____-SAME: () #[[ATTR2:[0-9]+]] {
155; IS__TUNIT____-NEXT:    [[B:%.*]] = alloca i32, align 4
156; IS__TUNIT____-NEXT:    ret i32 10
157;
158; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn
159; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@visible_local_2
160; IS__CGSCC_OPM-SAME: () #[[ATTR3:[0-9]+]] {
161; IS__CGSCC_OPM-NEXT:    [[B:%.*]] = alloca i32, align 4
162; IS__CGSCC_OPM-NEXT:    store i32 5, i32* [[B]], align 4
163; IS__CGSCC_OPM-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem_ro(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]], i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR6:[0-9]+]]
164; IS__CGSCC_OPM-NEXT:    ret i32 [[CALL]]
165;
166; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn
167; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@visible_local_2
168; IS__CGSCC_NPM-SAME: () #[[ATTR3:[0-9]+]] {
169; IS__CGSCC_NPM-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem_ro(i32 noundef 5, i32 noundef 5) #[[ATTR6:[0-9]+]]
170; IS__CGSCC_NPM-NEXT:    ret i32 [[CALL]]
171;
172  %B = alloca i32, align 4
173  store i32 5, i32* %B, align 4
174  %call = call i32 @noalias_args_argmem_ro(i32* %B, i32* %B)
175  ret i32 %call
176}
177
178define internal i32 @noalias_args_argmem_rn(i32* %A, i32* %B) #1 {
179; IS__TUNIT____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind willreturn uwtable
180; IS__TUNIT____-LABEL: define {{[^@]+}}@noalias_args_argmem_rn
181; IS__TUNIT____-SAME: (i32* noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR1]] {
182; IS__TUNIT____-NEXT:    [[T0:%.*]] = load i32, i32* [[B]], align 4
183; IS__TUNIT____-NEXT:    ret i32 [[T0]]
184;
185; IS__CGSCC____: Function Attrs: argmemonly nofree noinline norecurse nosync nounwind willreturn uwtable
186; IS__CGSCC____-LABEL: define {{[^@]+}}@noalias_args_argmem_rn
187; IS__CGSCC____-SAME: (i32* noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR4:[0-9]+]] {
188; IS__CGSCC____-NEXT:    [[T0:%.*]] = load i32, i32* [[B]], align 4
189; IS__CGSCC____-NEXT:    store i32 0, i32* [[B]], align 4
190; IS__CGSCC____-NEXT:    ret i32 [[T0]]
191;
192  %t0 = load i32, i32* %B, align 4
193  store i32 0, i32* %B
194  ret i32 %t0
195}
196
197define i32 @visible_local_3() {
198; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
199; IS__TUNIT____-LABEL: define {{[^@]+}}@visible_local_3
200; IS__TUNIT____-SAME: () #[[ATTR2]] {
201; IS__TUNIT____-NEXT:    [[B:%.*]] = alloca i32, align 4
202; IS__TUNIT____-NEXT:    store i32 5, i32* [[B]], align 4
203; IS__TUNIT____-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem_rn(i32* noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[B]]) #[[ATTR4:[0-9]+]]
204; IS__TUNIT____-NEXT:    ret i32 [[CALL]]
205;
206; IS__CGSCC____: Function Attrs: nofree nosync nounwind readnone willreturn
207; IS__CGSCC____-LABEL: define {{[^@]+}}@visible_local_3
208; IS__CGSCC____-SAME: () #[[ATTR3:[0-9]+]] {
209; IS__CGSCC____-NEXT:    [[B:%.*]] = alloca i32, align 4
210; IS__CGSCC____-NEXT:    store i32 5, i32* [[B]], align 4
211; IS__CGSCC____-NEXT:    [[CALL:%.*]] = call i32 @noalias_args_argmem_rn(i32* noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[B]]) #[[ATTR7:[0-9]+]]
212; IS__CGSCC____-NEXT:    ret i32 [[CALL]]
213;
214  %B = alloca i32, align 4
215  store i32 5, i32* %B, align 4
216  %call = call i32 @noalias_args_argmem_rn(i32* %B, i32* %B)
217  ret i32 %call
218}
219
220attributes #0 = { noinline nounwind uwtable willreturn }
221attributes #1 = { argmemonly noinline nounwind uwtable willreturn}
222;.
223; IS__TUNIT____: attributes #[[ATTR0]] = { argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable }
224; IS__TUNIT____: attributes #[[ATTR1]] = { argmemonly nofree noinline norecurse nosync nounwind willreturn uwtable }
225; IS__TUNIT____: attributes #[[ATTR2]] = { nofree norecurse nosync nounwind readnone willreturn }
226; IS__TUNIT____: attributes #[[ATTR3]] = { nofree nosync nounwind readonly }
227; IS__TUNIT____: attributes #[[ATTR4]] = { nofree nosync nounwind willreturn }
228;.
229; IS__CGSCC____: attributes #[[ATTR0]] = { argmemonly nofree noinline nosync nounwind readonly willreturn uwtable }
230; IS__CGSCC____: attributes #[[ATTR1]] = { argmemonly nofree noinline norecurse nosync nounwind readonly willreturn uwtable }
231; IS__CGSCC____: attributes #[[ATTR2]] = { argmemonly nofree noinline nosync nounwind willreturn uwtable }
232; IS__CGSCC____: attributes #[[ATTR3]] = { nofree nosync nounwind readnone willreturn }
233; IS__CGSCC____: attributes #[[ATTR4]] = { argmemonly nofree noinline norecurse nosync nounwind willreturn uwtable }
234; IS__CGSCC____: attributes #[[ATTR5]] = { readonly }
235; IS__CGSCC____: attributes #[[ATTR6:[0-9]+]] = { readonly willreturn }
236; IS__CGSCC____: attributes #[[ATTR7]] = { nounwind willreturn }
237;.
238