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 void @f() {
8; IS__TUNIT____-LABEL: define {{[^@]+}}@f() {
9; IS__TUNIT____-NEXT:  entry:
10; IS__TUNIT____-NEXT:    call void @g()
11; IS__TUNIT____-NEXT:    ret void
12;
13; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@f() {
14; IS__CGSCC_OPM-NEXT:  entry:
15; IS__CGSCC_OPM-NEXT:    [[A:%.*]] = alloca i32, align 1
16; IS__CGSCC_OPM-NEXT:    call void @g(i32* noalias nocapture nofree noundef nonnull readonly dereferenceable(4) [[A]])
17; IS__CGSCC_OPM-NEXT:    ret void
18;
19; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@f() {
20; IS__CGSCC_NPM-NEXT:  entry:
21; IS__CGSCC_NPM-NEXT:    call void @g(i32 undef)
22; IS__CGSCC_NPM-NEXT:    ret void
23;
24entry:
25  %a = alloca i32, align 1
26  call void @g(i32* %a)
27  ret void
28}
29
30define internal void @g(i32* %a) {
31; IS__TUNIT____-LABEL: define {{[^@]+}}@g() {
32; IS__TUNIT____-NEXT:    call void @z(i32 undef)
33; IS__TUNIT____-NEXT:    ret void
34;
35; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@g
36; IS__CGSCC_OPM-SAME: (i32* noalias nocapture nofree noundef nonnull readonly dereferenceable(4) [[A:%.*]]) {
37; IS__CGSCC_OPM-NEXT:    [[AA:%.*]] = load i32, i32* [[A]], align 1
38; IS__CGSCC_OPM-NEXT:    call void @z(i32 [[AA]])
39; IS__CGSCC_OPM-NEXT:    ret void
40;
41; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@g
42; IS__CGSCC_NPM-SAME: (i32 [[TMP0:%.*]]) {
43; IS__CGSCC_NPM-NEXT:    [[A_PRIV:%.*]] = alloca i32, align 4
44; IS__CGSCC_NPM-NEXT:    store i32 [[TMP0]], i32* [[A_PRIV]], align 4
45; IS__CGSCC_NPM-NEXT:    [[AA:%.*]] = load i32, i32* [[A_PRIV]], align 1
46; IS__CGSCC_NPM-NEXT:    call void @z(i32 [[AA]])
47; IS__CGSCC_NPM-NEXT:    ret void
48;
49  %aa = load i32, i32* %a, align 1
50  call void @z(i32 %aa)
51  ret void
52}
53
54declare void @z(i32)
55
56; Test2
57; Different alignemnt privatizable arguments
58define internal i32 @test(i32* %X, i64* %Y) {
59; IS__CGSCC_OPM: Function Attrs: argmemonly nofree norecurse nosync nounwind readonly willreturn
60; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@test
61; IS__CGSCC_OPM-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[X:%.*]], i64* noalias nocapture nofree noundef nonnull readonly align 8 dereferenceable(8) [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
62; IS__CGSCC_OPM-NEXT:    [[A:%.*]] = load i32, i32* [[X]], align 4
63; IS__CGSCC_OPM-NEXT:    [[B:%.*]] = load i64, i64* [[Y]], align 8
64; IS__CGSCC_OPM-NEXT:    [[C:%.*]] = add i32 [[A]], 1
65; IS__CGSCC_OPM-NEXT:    [[D:%.*]] = add i64 [[B]], 1
66; IS__CGSCC_OPM-NEXT:    [[COND:%.*]] = icmp sgt i64 [[D]], -1
67; IS__CGSCC_OPM-NEXT:    br i1 [[COND]], label [[RETURN1:%.*]], label [[RETURN2:%.*]]
68; IS__CGSCC_OPM:       Return1:
69; IS__CGSCC_OPM-NEXT:    ret i32 [[C]]
70; IS__CGSCC_OPM:       Return2:
71; IS__CGSCC_OPM-NEXT:    ret i32 [[A]]
72;
73; IS__CGSCC_NPM: Function Attrs: argmemonly nofree norecurse nosync nounwind readonly willreturn
74; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@test
75; IS__CGSCC_NPM-SAME: (i32* nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[X:%.*]], i64 [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
76; IS__CGSCC_NPM-NEXT:    [[Y_PRIV:%.*]] = alloca i64, align 8
77; IS__CGSCC_NPM-NEXT:    store i64 [[TMP0]], i64* [[Y_PRIV]], align 4
78; IS__CGSCC_NPM-NEXT:    [[A:%.*]] = load i32, i32* [[X]], align 4
79; IS__CGSCC_NPM-NEXT:    [[B:%.*]] = load i64, i64* [[Y_PRIV]], align 8
80; IS__CGSCC_NPM-NEXT:    [[C:%.*]] = add i32 [[A]], 1
81; IS__CGSCC_NPM-NEXT:    [[D:%.*]] = add i64 [[B]], 1
82; IS__CGSCC_NPM-NEXT:    [[COND:%.*]] = icmp sgt i64 [[D]], -1
83; IS__CGSCC_NPM-NEXT:    br i1 [[COND]], label [[RETURN1:%.*]], label [[RETURN2:%.*]]
84; IS__CGSCC_NPM:       Return1:
85; IS__CGSCC_NPM-NEXT:    ret i32 [[C]]
86; IS__CGSCC_NPM:       Return2:
87; IS__CGSCC_NPM-NEXT:    ret i32 [[A]]
88;
89  %A = load i32, i32* %X
90  %B = load i64, i64* %Y
91  %C = add i32 %A, 1
92  %D = add i64 %B, 1
93  %cond = icmp sgt i64 %D, -1
94  br i1 %cond, label %Return1, label %Return2
95Return1:
96  ret i32 %C
97Return2:
98  ret i32 %A
99}
100
101define internal i32 @caller(i32* %A) {
102; IS__CGSCC_OPM: Function Attrs: argmemonly nofree nosync nounwind willreturn
103; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@caller
104; IS__CGSCC_OPM-SAME: (i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR1:[0-9]+]] {
105; IS__CGSCC_OPM-NEXT:    [[B:%.*]] = alloca i64, align 8
106; IS__CGSCC_OPM-NEXT:    store i64 1, i64* [[B]], align 8
107; IS__CGSCC_OPM-NEXT:    [[C:%.*]] = call i32 @test(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A]], i64* noalias nocapture nofree noundef nonnull readonly align 8 dereferenceable(8) [[B]]) #[[ATTR3:[0-9]+]]
108; IS__CGSCC_OPM-NEXT:    ret i32 [[C]]
109;
110; IS__CGSCC_NPM: Function Attrs: argmemonly nofree nosync nounwind willreturn
111; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@caller
112; IS__CGSCC_NPM-SAME: (i32 [[TMP0:%.*]]) #[[ATTR1:[0-9]+]] {
113; IS__CGSCC_NPM-NEXT:    [[A_PRIV:%.*]] = alloca i32, align 4
114; IS__CGSCC_NPM-NEXT:    store i32 [[TMP0]], i32* [[A_PRIV]], align 4
115; IS__CGSCC_NPM-NEXT:    [[C:%.*]] = call i32 @test(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[A_PRIV]], i64 noundef 1) #[[ATTR3:[0-9]+]]
116; IS__CGSCC_NPM-NEXT:    ret i32 [[C]]
117;
118  %B = alloca i64
119  store i64 1, i64* %B
120  %C = call i32 @test(i32* %A, i64* %B)
121  ret i32 %C
122}
123
124define i32 @callercaller() {
125; IS__TUNIT____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
126; IS__TUNIT____-LABEL: define {{[^@]+}}@callercaller
127; IS__TUNIT____-SAME: () #[[ATTR0:[0-9]+]] {
128; IS__TUNIT____-NEXT:    [[B:%.*]] = alloca i32, align 4
129; IS__TUNIT____-NEXT:    ret i32 3
130;
131; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind readnone willreturn
132; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@callercaller
133; IS__CGSCC_OPM-SAME: () #[[ATTR2:[0-9]+]] {
134; IS__CGSCC_OPM-NEXT:    [[B:%.*]] = alloca i32, align 4
135; IS__CGSCC_OPM-NEXT:    store i32 2, i32* [[B]], align 4
136; IS__CGSCC_OPM-NEXT:    [[X:%.*]] = call i32 @caller(i32* noalias nocapture nofree noundef nonnull readonly align 4 dereferenceable(4) [[B]]) #[[ATTR4:[0-9]+]]
137; IS__CGSCC_OPM-NEXT:    ret i32 [[X]]
138;
139; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind readnone willreturn
140; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@callercaller
141; IS__CGSCC_NPM-SAME: () #[[ATTR2:[0-9]+]] {
142; IS__CGSCC_NPM-NEXT:    [[X:%.*]] = call i32 @caller(i32 noundef 2) #[[ATTR4:[0-9]+]]
143; IS__CGSCC_NPM-NEXT:    ret i32 [[X]]
144;
145  %B = alloca i32
146  store i32 2, i32* %B
147  %X = call i32 @caller(i32* %B)
148  ret i32 %X
149}
150;.
151; IS__TUNIT____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn }
152;.
153; IS__CGSCC____: attributes #[[ATTR0:[0-9]+]] = { argmemonly nofree norecurse nosync nounwind readonly willreturn }
154; IS__CGSCC____: attributes #[[ATTR1:[0-9]+]] = { argmemonly nofree nosync nounwind willreturn }
155; IS__CGSCC____: attributes #[[ATTR2:[0-9]+]] = { nofree nosync nounwind readnone willreturn }
156; IS__CGSCC____: attributes #[[ATTR3:[0-9]+]] = { readonly willreturn }
157; IS__CGSCC____: attributes #[[ATTR4:[0-9]+]] = { nounwind willreturn }
158;.
159