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 3 4; RUN: opt -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_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM,CHECK_DISABLED,NOT_CGSCC_NPM_DISABLED,NOT_CGSCC_OPM_DISABLED,NOT_TUNIT_NPM_DISABLED,IS__TUNIT_____DISABLED,IS________OPM_DISABLED,IS__TUNIT_OPM_DISABLED 5; 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,CHECK_DISABLED,NOT_CGSCC_OPM_DISABLED,NOT_CGSCC_NPM_DISABLED,NOT_TUNIT_OPM_DISABLED,IS__TUNIT_____DISABLED,IS________NPM_DISABLED,IS__TUNIT_NPM_DISABLED 6 7; Deep Wrapper enabled 8 9; RUN: opt -attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -attributor-allow-deep-wrappers -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM,CHECK_ENABLED,NOT_CGSCC_NPM_ENABLED,NOT_CGSCC_OPM_ENABLED,NOT_TUNIT_NPM_ENABLED,IS__TUNIT_____ENABLED,IS________OPM_ENABLED,IS__TUNIT_OPM_ENABLED 10; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -attributor-allow-deep-wrappers -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM,CHECK_ENABLED,NOT_CGSCC_OPM_ENABLED,NOT_CGSCC_NPM_ENABLED,NOT_TUNIT_OPM_ENABLED,IS__TUNIT_____ENABLED,IS________NPM_ENABLED,IS__TUNIT_NPM_ENABLED 11 12; TEST 1: This function is of linkage `linkonce`, we cannot internalize this 13; function and use information derived from it 14; 15; CHECK-NOT: inner1.internalized 16define linkonce i32 @inner1(i32 %a, i32 %b) { 17; CHECK-LABEL: define {{[^@]+}}@inner1 18; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { 19; CHECK-NEXT: entry: 20; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]] 21; CHECK-NEXT: ret i32 [[C]] 22; 23entry: 24 %c = add i32 %a, %b 25 ret i32 %c 26} 27 28; TEST 2: This function is of linkage `weak`, we cannot internalize this function and 29; use information derived from it 30; 31; CHECK-NOT: inner2.internalized 32define weak i32 @inner2(i32 %a, i32 %b) { 33; CHECK-LABEL: define {{[^@]+}}@inner2 34; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { 35; CHECK-NEXT: entry: 36; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]] 37; CHECK-NEXT: ret i32 [[C]] 38; 39entry: 40 %c = add i32 %a, %b 41 ret i32 %c 42} 43 44; TEST 3: This function is of linkage `linkonce_odr`, which can be internalized using the 45; deep wrapper, and the IP information derived from this function can be used 46; 47define linkonce_odr i32 @inner3(i32 %a, i32 %b) { 48; CHECK_DISABLED-LABEL: define {{[^@]+}}@inner3 49; CHECK_DISABLED-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { 50; CHECK_DISABLED-NEXT: entry: 51; CHECK_DISABLED-NEXT: [[C:%.*]] = add i32 [[A]], [[B]] 52; CHECK_DISABLED-NEXT: ret i32 [[C]] 53; 54entry: 55 %c = add i32 %a, %b 56 ret i32 %c 57} 58 59; TEST 4: This function is of linkage `weak_odr`, which can be internalized using the deep 60; wrapper 61; 62define weak_odr i32 @inner4(i32 %a, i32 %b) { 63; CHECK_DISABLED-LABEL: define {{[^@]+}}@inner4 64; CHECK_DISABLED-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { 65; CHECK_DISABLED-NEXT: entry: 66; CHECK_DISABLED-NEXT: [[C:%.*]] = add i32 [[A]], [[B]] 67; CHECK_DISABLED-NEXT: ret i32 [[C]] 68; 69entry: 70 %c = add i32 %a, %b 71 ret i32 %c 72} 73 74; TEST 5: This function has linkage `linkonce_odr` but is never called (num of use = 0), so there 75; is no need to internalize this 76; 77; CHECK-NOT: inner5.internalized 78define linkonce_odr i32 @inner5(i32 %a, i32 %b) { 79; CHECK-LABEL: define {{[^@]+}}@inner5 80; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) { 81; CHECK-NEXT: entry: 82; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]] 83; CHECK-NEXT: ret i32 [[C]] 84; 85entry: 86 %c = add i32 %a, %b 87 ret i32 %c 88} 89 90; Since the inner1 cannot be internalized, there should be no change to its callsite 91; Since the inner2 cannot be internalized, there should be no change to its callsite 92; Since the inner3 is internalized, the use of the original function should be replaced by the 93; copied one 94; 95define i32 @outer1() { 96; CHECK_DISABLED: Function Attrs: norecurse 97; CHECK_DISABLED-LABEL: define {{[^@]+}}@outer1 98; CHECK_DISABLED-SAME: () #[[ATTR0:[0-9]+]] { 99; CHECK_DISABLED-NEXT: entry: 100; CHECK_DISABLED-NEXT: [[RET1:%.*]] = call i32 @inner1(i32 noundef 1, i32 noundef 2) 101; CHECK_DISABLED-NEXT: [[RET2:%.*]] = call i32 @inner2(i32 noundef 1, i32 noundef 2) 102; CHECK_DISABLED-NEXT: [[RET3:%.*]] = call i32 @inner3(i32 [[RET1]], i32 [[RET2]]) 103; CHECK_DISABLED-NEXT: [[RET4:%.*]] = call i32 @inner4(i32 [[RET3]], i32 [[RET3]]) 104; CHECK_DISABLED-NEXT: ret i32 [[RET4]] 105; 106; CHECK_ENABLED: Function Attrs: norecurse 107; CHECK_ENABLED-LABEL: define {{[^@]+}}@outer1 108; CHECK_ENABLED-SAME: () #[[ATTR1:[0-9]+]] { 109; CHECK_ENABLED-NEXT: entry: 110; CHECK_ENABLED-NEXT: [[RET1:%.*]] = call i32 @inner1(i32 noundef 1, i32 noundef 2) 111; CHECK_ENABLED-NEXT: [[RET2:%.*]] = call i32 @inner2(i32 noundef 1, i32 noundef 2) 112; CHECK_ENABLED-NEXT: [[RET3:%.*]] = call i32 @inner3.internalized(i32 [[RET1]], i32 [[RET2]]) 113; CHECK_ENABLED-NEXT: [[RET4:%.*]] = call i32 @inner4.internalized(i32 [[RET3]], i32 [[RET3]]) 114; CHECK_ENABLED-NEXT: ret i32 [[RET4]] 115; 116entry: 117 %ret1 = call i32 @inner1(i32 1, i32 2) 118 %ret2 = call i32 @inner2(i32 1, i32 2) 119 %ret3 = call i32 @inner3(i32 %ret1, i32 %ret2) 120 %ret4 = call i32 @inner4(i32 %ret3, i32 %ret3) 121 ret i32 %ret4 122} 123 124 125define linkonce_odr void @unused_arg(i8) { 126; CHECK_DISABLED-LABEL: define {{[^@]+}}@unused_arg 127; CHECK_DISABLED-SAME: (i8 [[TMP0:%.*]]) { 128; CHECK_DISABLED-NEXT: unreachable 129; 130 unreachable 131} 132 133define void @unused_arg_caller() { 134; CHECK_DISABLED: Function Attrs: norecurse 135; CHECK_DISABLED-LABEL: define {{[^@]+}}@unused_arg_caller 136; CHECK_DISABLED-SAME: () #[[ATTR0]] { 137; CHECK_DISABLED-NEXT: call void @unused_arg(i8 noundef 0) 138; CHECK_DISABLED-NEXT: ret void 139; 140; CHECK_ENABLED: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 141; CHECK_ENABLED-LABEL: define {{[^@]+}}@unused_arg_caller 142; CHECK_ENABLED-SAME: () #[[ATTR0:[0-9]+]] { 143; CHECK_ENABLED-NEXT: unreachable 144; 145; IS__CGSCC_____ENABLED: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn 146; IS__CGSCC_____ENABLED-LABEL: define {{[^@]+}}@unused_arg_caller 147; IS__CGSCC_____ENABLED-SAME: () #[[ATTR2:[0-9]+]] { 148; IS__CGSCC_____ENABLED-NEXT: unreachable 149 call void @unused_arg(i8 0) 150 ret void 151} 152 153; Don't crash on linkonce_odr hidden functions 154define linkonce_odr hidden void @__clang_call_terminate() { 155; CHECK_DISABLED-LABEL: define {{[^@]+}}@__clang_call_terminate() { 156; CHECK_DISABLED-NEXT: call void @__clang_call_terminate() 157; CHECK_DISABLED-NEXT: unreachable 158; 159 call void @__clang_call_terminate() 160 unreachable 161} 162 163; IS__CGSCC_____ENABLED: attributes #[[ATTR0:[0-9]+]] = { nofree nosync nounwind readnone willreturn } 164; IS__CGSCC_____ENABLED: attributes #[[ATTR1:[0-9]+]] = { nofree noreturn nosync nounwind readnone willreturn } 165; IS__CGSCC_____ENABLED: attributes #[[ATTR2]] = { nofree norecurse noreturn nosync nounwind readnone willreturn } 166;. 167; CHECK_DISABLED: attributes #[[ATTR0]] = { norecurse } 168;. 169; CHECK_ENABLED: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } 170; CHECK_ENABLED: attributes #[[ATTR1]] = { norecurse } 171; CHECK_ENABLED: attributes #[[ATTR2:[0-9]+]] = { nounwind readnone } 172;. 173