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