1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-globals
2; call site specific analysis is enabled
3
4; RUN: opt -attributor -enable-new-pm=0 -attributor-enable-call-site-specific-deduction=true -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
5
6; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-enable-call-site-specific-deduction=true -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
7
8; RUN: opt -attributor-cgscc -attributor-enable-call-site-specific-deduction=true -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
9
10; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-enable-call-site-specific-deduction=true -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
11
12define i32 @test_range(i32 %unknown) {
13; CHECK-LABEL: define {{[^@]+}}@test_range
14; CHECK-SAME: (i32 [[UNKNOWN:%.*]]) #[[ATTR0:[0-9]+]] {
15; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[UNKNOWN]], 100
16; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 100, i32 0
17; CHECK-NEXT:    ret i32 [[TMP2]]
18;
19  %1 = icmp sgt i32 %unknown, 100
20  %2 = select i1 %1, i32 100, i32 0
21  ret i32 %2
22}
23
24define i32 @test1(i32 %unknown, i32 %b) {
25; CHECK-LABEL: define {{[^@]+}}@test1
26; CHECK-SAME: (i32 [[UNKNOWN:%.*]], i32 [[B:%.*]]) #[[ATTR0]] {
27; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @test_range(i32 [[UNKNOWN]]) #[[ATTR1:[0-9]+]], !range [[RNG0:![0-9]+]]
28; CHECK-NEXT:    [[TMP2:%.*]] = sub nsw i32 [[TMP1]], [[B]]
29; CHECK-NEXT:    ret i32 [[TMP2]]
30;
31  %1 = call i32 @test_range(i32 %unknown)
32  %2 = sub nsw i32 %1, %b
33  ret i32 %2
34}
35
36define i32 @test2(i32 %unknown, i32 %b) {
37; CHECK-LABEL: define {{[^@]+}}@test2
38; CHECK-SAME: (i32 [[UNKNOWN:%.*]], i32 [[B:%.*]]) #[[ATTR0]] {
39; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @test_range(i32 [[UNKNOWN]]) #[[ATTR1]], !range [[RNG0]]
40; CHECK-NEXT:    [[TMP2:%.*]] = add nsw i32 [[TMP1]], [[B]]
41; CHECK-NEXT:    ret i32 [[TMP2]]
42;
43  %1 = call i32 @test_range(i32 %unknown)
44  %2 = add nsw i32 %1, %b
45  ret i32 %2
46}
47
48; Positive checks
49
50; FIXME: AAValueSimplify preserves the context but simplifies to a value in the other function, I think.
51;        Either way, as we settle on the new AAValueSimplifyReturned scheme that replaces AAReturnedValues
52;        we need to look into this again. For the purpose of making some progress we take this regression
53;        for now, call site contexts are not on by default anyway (yet).
54define i32 @test1_pcheck(i32 %unknown) {
55; CHECK-LABEL: define {{[^@]+}}@test1_pcheck
56; CHECK-SAME: (i32 [[UNKNOWN:%.*]]) #[[ATTR0]] {
57; CHECK-NEXT:    ret i32 1
58;
59  %1 = call i32 @test1(i32 %unknown, i32 20)
60  %2 = icmp sle i32 %1, 90
61  %3 = zext i1 %2 to i32
62  ret i32 %3
63}
64
65define i32 @test2_pcheck(i32 %unknown) {
66; CHECK-LABEL: define {{[^@]+}}@test2_pcheck
67; CHECK-SAME: (i32 [[UNKNOWN:%.*]]) #[[ATTR0]] {
68; CHECK-NEXT:    ret i32 1
69;
70  %1 = call i32 @test2(i32 %unknown, i32 20)
71  %2 = icmp sge i32 %1, 20
72  %3 = zext i1 %2 to i32
73  ret i32 %3
74}
75
76; Negative checks
77
78define i32 @test1_ncheck(i32 %unknown) {
79; CHECK-LABEL: define {{[^@]+}}@test1_ncheck
80; CHECK-SAME: (i32 [[UNKNOWN:%.*]]) #[[ATTR0]] {
81; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @test1(i32 [[UNKNOWN]], i32 noundef 20) #[[ATTR1]], !range [[RNG1:![0-9]+]]
82; CHECK-NEXT:    [[TMP2:%.*]] = icmp sle i32 [[TMP1]], 10
83; CHECK-NEXT:    [[TMP3:%.*]] = zext i1 [[TMP2]] to i32
84; CHECK-NEXT:    ret i32 [[TMP3]]
85;
86  %1 = call i32 @test1(i32 %unknown, i32 20)
87  %2 = icmp sle i32 %1, 10
88  %3 = zext i1 %2 to i32
89  ret i32 %3
90}
91
92define i32 @test2_ncheck(i32 %unknown) {
93; CHECK-LABEL: define {{[^@]+}}@test2_ncheck
94; CHECK-SAME: (i32 [[UNKNOWN:%.*]]) #[[ATTR0]] {
95; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @test2(i32 [[UNKNOWN]], i32 noundef 20) #[[ATTR1]], !range [[RNG2:![0-9]+]]
96; CHECK-NEXT:    [[TMP2:%.*]] = icmp sge i32 [[TMP1]], 30
97; CHECK-NEXT:    [[TMP3:%.*]] = zext i1 [[TMP2]] to i32
98; CHECK-NEXT:    ret i32 [[TMP3]]
99;
100  %1 = call i32 @test2(i32 %unknown, i32 20)
101  %2 = icmp sge i32 %1, 30
102  %3 = zext i1 %2 to i32
103  ret i32 %3
104}
105;.
106; IS__TUNIT____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn }
107; IS__TUNIT____: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
108;.
109; IS__CGSCC____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn }
110; IS__CGSCC____: attributes #[[ATTR1]] = { readnone willreturn }
111;.
112; CHECK: [[RNG0]] = !{i32 0, i32 101}
113; CHECK: [[RNG1]] = !{i32 -20, i32 81}
114; CHECK: [[RNG2]] = !{i32 20, i32 121}
115;.
116