1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-attributes --check-globals
2 ; Deep Wrapper disabled
4 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK_DISABLED
8 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -attributor-allow-deep-wrappers -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK_ENABLED
10 ; TEST 1: This function is of linkage `linkonce`, we cannot internalize this
11 ; function and use information derived from it
13 ; CHECK-NOT: inner1.internalized
14 define linkonce i32 @inner1(i32 %a, i32 %b) {
15 ; CHECK-LABEL: define {{[^@]+}}@inner1
16 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
18 ; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
19 ; CHECK-NEXT: ret i32 [[C]]
26 ; TEST 2: This function is of linkage `weak`, we cannot internalize this function and
27 ; use information derived from it
29 ; CHECK-NOT: inner2.internalized
30 define weak i32 @inner2(i32 %a, i32 %b) {
31 ; CHECK-LABEL: define {{[^@]+}}@inner2
32 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
34 ; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
35 ; CHECK-NEXT: ret i32 [[C]]
42 ; TEST 3: This function is of linkage `linkonce_odr`, which can be internalized using the
43 ; deep wrapper, and the IP information derived from this function can be used
45 define linkonce_odr i32 @inner3(i32 %a, i32 %b) {
46 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@inner3
47 ; CHECK_DISABLED-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
48 ; CHECK_DISABLED-NEXT: entry:
49 ; CHECK_DISABLED-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
50 ; CHECK_DISABLED-NEXT: ret i32 [[C]]
57 ; TEST 4: This function is of linkage `weak_odr`, which can be internalized using the deep
60 define weak_odr i32 @inner4(i32 %a, i32 %b) {
61 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@inner4
62 ; CHECK_DISABLED-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
63 ; CHECK_DISABLED-NEXT: entry:
64 ; CHECK_DISABLED-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
65 ; CHECK_DISABLED-NEXT: ret i32 [[C]]
72 ; TEST 5: This function has linkage `linkonce_odr` but is never called (num of use = 0), so there
73 ; is no need to internalize this
75 ; CHECK-NOT: inner5.internalized
76 define linkonce_odr i32 @inner5(i32 %a, i32 %b) {
77 ; CHECK-LABEL: define {{[^@]+}}@inner5
78 ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
80 ; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
81 ; CHECK-NEXT: ret i32 [[C]]
88 ; Since the inner1 cannot be internalized, there should be no change to its callsite
89 ; Since the inner2 cannot be internalized, there should be no change to its callsite
90 ; Since the inner3 is internalized, the use of the original function should be replaced by the
93 define i32 @outer1() {
94 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@outer1() {
95 ; CHECK_DISABLED-NEXT: entry:
96 ; CHECK_DISABLED-NEXT: [[RET1:%.*]] = call i32 @inner1(i32 noundef 1, i32 noundef 2)
97 ; CHECK_DISABLED-NEXT: [[RET2:%.*]] = call i32 @inner2(i32 noundef 1, i32 noundef 2)
98 ; CHECK_DISABLED-NEXT: [[RET3:%.*]] = call i32 @inner3(i32 [[RET1]], i32 [[RET2]])
99 ; CHECK_DISABLED-NEXT: [[RET4:%.*]] = call i32 @inner4(i32 [[RET3]], i32 [[RET3]])
100 ; CHECK_DISABLED-NEXT: ret i32 [[RET4]]
102 ; CHECK_ENABLED-LABEL: define {{[^@]+}}@outer1() {
103 ; CHECK_ENABLED-NEXT: entry:
104 ; CHECK_ENABLED-NEXT: [[RET1:%.*]] = call i32 @inner1(i32 noundef 1, i32 noundef 2)
105 ; CHECK_ENABLED-NEXT: [[RET2:%.*]] = call i32 @inner2(i32 noundef 1, i32 noundef 2)
106 ; CHECK_ENABLED-NEXT: [[RET3:%.*]] = call i32 @inner3.internalized(i32 [[RET1]], i32 [[RET2]])
107 ; CHECK_ENABLED-NEXT: [[RET4:%.*]] = call i32 @inner4.internalized(i32 [[RET3]], i32 [[RET3]])
108 ; CHECK_ENABLED-NEXT: ret i32 [[RET4]]
111 %ret1 = call i32 @inner1(i32 1, i32 2)
112 %ret2 = call i32 @inner2(i32 1, i32 2)
113 %ret3 = call i32 @inner3(i32 %ret1, i32 %ret2)
114 %ret4 = call i32 @inner4(i32 %ret3, i32 %ret3)
119 define linkonce_odr void @unused_arg(i8) {
120 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@unused_arg
121 ; CHECK_DISABLED-SAME: (i8 [[TMP0:%.*]]) {
122 ; CHECK_DISABLED-NEXT: unreachable
127 define void @unused_arg_caller() {
128 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@unused_arg_caller() {
129 ; CHECK_DISABLED-NEXT: call void @unused_arg(i8 noundef 0)
130 ; CHECK_DISABLED-NEXT: ret void
132 ; CHECK_ENABLED: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
133 ; CHECK_ENABLED-LABEL: define {{[^@]+}}@unused_arg_caller
134 ; CHECK_ENABLED-SAME: () #[[ATTR0:[0-9]+]] {
135 ; CHECK_ENABLED-NEXT: unreachable
137 ; CGSCC_ENABLED: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn
138 ; CGSCC_ENABLED-LABEL: define {{[^@]+}}@unused_arg_caller
139 ; CGSCC_ENABLED-SAME: () #[[ATTR2:[0-9]+]] {
140 ; CGSCC_ENABLED-NEXT: unreachable
141 call void @unused_arg(i8 0)
145 ; Don't crash on linkonce_odr hidden functions
146 define linkonce_odr hidden void @__clang_call_terminate() {
147 ; CHECK_DISABLED-LABEL: define {{[^@]+}}@__clang_call_terminate() {
148 ; CHECK_DISABLED-NEXT: call void @__clang_call_terminate()
149 ; CHECK_DISABLED-NEXT: unreachable
151 call void @__clang_call_terminate()
155 ; CGSCC_ENABLED: attributes #[[ATTR0:[0-9]+]] = { nofree nosync nounwind readnone willreturn }
156 ; CGSCC_ENABLED: attributes #[[ATTR1:[0-9]+]] = { nofree noreturn nosync nounwind readnone willreturn }
157 ; CGSCC_ENABLED: attributes #[[ATTR2]] = { nofree norecurse noreturn nosync nounwind readnone willreturn }
159 ; CHECK_ENABLED: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
160 ; CHECK_ENABLED: attributes #[[ATTR1:[0-9]+]] = { nounwind memory(none) }