Skip to content

Commit d7127b6

Browse files
committed
Update test files as per comments
1 parent 09220c5 commit d7127b6

File tree

6 files changed

+69
-102
lines changed

6 files changed

+69
-102
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,8 @@ static void inferAttrsFromFunctionBodies(const SCCNodeSet &SCCNodes,
20742074
// that is true if any function's address is taken, or if any function
20752075
// has external linkage. This is used to determine the safety of
20762076
// external/library calls.
2077-
static bool hasRecursiveCallee(Function &F,
2078-
bool AnyFunctionsAddressIsTaken = true) {
2077+
static bool mayHaveRecursiveCallee(Function &F,
2078+
bool AnyFunctionsAddressIsTaken = true) {
20792079
for (const auto &BB : F) {
20802080
for (const auto &I : BB.instructionsWithoutDebug()) {
20812081
if (const auto *CB = dyn_cast<CallBase>(&I)) {
@@ -2108,7 +2108,7 @@ static void addNoRecurseAttrs(const SCCNodeSet &SCCNodes,
21082108
Function *F = *SCCNodes.begin();
21092109
if (!F || !F->hasExactDefinition() || F->doesNotRecurse())
21102110
return;
2111-
if (!hasRecursiveCallee(*F)) {
2111+
if (!mayHaveRecursiveCallee(*F)) {
21122112
// Every call was to a non-recursive function other than this function, and
21132113
// we have no indirect recursion as the SCC size is one. This function
21142114
// cannot recurse.
@@ -2456,9 +2456,8 @@ PreservedAnalyses NoRecurseLTOInferencePass::run(Module &M,
24562456
// linkage, there is no path for a callback to any user function.
24572457
bool AnyFunctionsAddressIsTaken = false;
24582458
for (Function &F : M) {
2459-
if (F.isDeclaration() || F.doesNotRecurse()) {
2459+
if (F.isDeclaration() || F.doesNotRecurse())
24602460
continue;
2461-
}
24622461
if (!F.hasLocalLinkage() || F.hasAddressTaken()) {
24632462
AnyFunctionsAddressIsTaken = true;
24642463
break;
@@ -2475,26 +2474,23 @@ PreservedAnalyses NoRecurseLTOInferencePass::run(Module &M,
24752474
// Skip any RefSCC that is part of a call cycle. A RefSCC containing more
24762475
// than one SCC indicates a recursive relationship, which could involve
24772476
// direct or indirect calls.
2478-
if (RC.size() > 1) {
2477+
if (RC.size() > 1)
24792478
continue;
2480-
}
24812479

24822480
// A single-SCC RefSCC could still be a self-loop.
24832481
LazyCallGraph::SCC &S = *RC.begin();
2484-
if (S.size() > 1) {
2482+
if (S.size() > 1)
24852483
continue;
2486-
}
24872484

24882485
// Get the single function from this SCC.
24892486
Function &F = S.begin()->getFunction();
2490-
if (!F.hasExactDefinition() || F.doesNotRecurse()) {
2487+
if (!F.hasExactDefinition() || F.doesNotRecurse())
24912488
continue;
2492-
}
24932489

24942490
// If the analysis confirms that this function has no recursive calls
24952491
// (either direct, indirect, or through external linkages),
24962492
// we can safely apply the norecurse attribute.
2497-
if (!hasRecursiveCallee(F, AnyFunctionsAddressIsTaken)) {
2493+
if (!mayHaveRecursiveCallee(F, AnyFunctionsAddressIsTaken)) {
24982494
F.setDoesNotRecurse();
24992495
++NumNoRecurse;
25002496
Changed = true;
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; RUN: opt < %s -passes=norecurse-lto-inference -S | FileCheck %s
33

44
; This test includes a call to a library function which is not marked as
@@ -7,22 +7,25 @@
77

88
@.str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1
99

10+
;.
11+
; CHECK: @.str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1
12+
;.
1013
define dso_local void @bob() {
1114
; CHECK-LABEL: define dso_local void @bob() {
1215
; CHECK-NEXT: [[ENTRY:.*:]]
13-
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
16+
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str)
1417
; CHECK-NEXT: ret void
1518
;
1619
entry:
17-
%call = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
20+
%call = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str)
1821
ret void
1922
}
2023

21-
declare noundef i32 @printf(ptr noundef readonly captures(none), ...)
24+
declare i32 @printf(ptr readonly captures(none), ...)
2225

23-
define dso_local noundef i32 @main() norecurse {
26+
define dso_local i32 @main() norecurse {
2427
; CHECK: Function Attrs: norecurse
25-
; CHECK-LABEL: define dso_local noundef i32 @main(
28+
; CHECK-LABEL: define dso_local i32 @main(
2629
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
2730
; CHECK-NEXT: [[ENTRY:.*:]]
2831
; CHECK-NEXT: tail call void @bob()
@@ -32,3 +35,6 @@ entry:
3235
tail call void @bob()
3336
ret i32 0
3437
}
38+
;.
39+
; CHECK: attributes #[[ATTR0]] = { norecurse }
40+
;.
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; RUN: opt < %s -passes=norecurse-lto-inference -S | FileCheck %s
33

44
; This test includes a call to a library function which is not marked as
@@ -8,26 +8,29 @@
88
@.str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1
99

1010
; Function Attrs: nofree noinline nounwind uwtable
11+
;.
12+
; CHECK: @.str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1
13+
;.
1114
define internal void @bob() {
1215
; CHECK: Function Attrs: norecurse
1316
; CHECK-LABEL: define internal void @bob(
1417
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
1518
; CHECK-NEXT: [[ENTRY:.*:]]
16-
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
19+
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str)
1720
; CHECK-NEXT: ret void
1821
;
1922
entry:
20-
%call = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
23+
%call = tail call i32 (ptr, ...) @printf(ptr nonnull dereferenceable(1) @.str)
2124
ret void
2225
}
2326

2427
; Function Attrs: nofree nounwind
25-
declare noundef i32 @printf(ptr noundef readonly captures(none), ...)
28+
declare i32 @printf(ptr readonly captures(none), ...)
2629

2730
; Function Attrs: nofree norecurse nounwind uwtable
28-
define dso_local noundef i32 @main() norecurse {
31+
define dso_local i32 @main() norecurse {
2932
; CHECK: Function Attrs: norecurse
30-
; CHECK-LABEL: define dso_local noundef i32 @main(
33+
; CHECK-LABEL: define dso_local i32 @main(
3134
; CHECK-SAME: ) #[[ATTR0]] {
3235
; CHECK-NEXT: [[ENTRY:.*:]]
3336
; CHECK-NEXT: tail call void @bob()
@@ -37,3 +40,6 @@ entry:
3740
tail call void @bob()
3841
ret i32 0
3942
}
43+
;.
44+
; CHECK: attributes #[[ATTR0]] = { norecurse }
45+
;.

llvm/test/Transforms/FunctionAttrs/norecurse_multi_scc_indirect_recursion.ll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; RUN: opt < %s -passes=norecurse-lto-inference -S | FileCheck %s
33

44
; This test includes a call graph with multiple SCCs. The purpose of this is
@@ -36,9 +36,9 @@ entry:
3636
ret void
3737
}
3838

39-
define dso_local noundef i32 @main() norecurse {
39+
define dso_local i32 @main() norecurse {
4040
; CHECK: Function Attrs: norecurse
41-
; CHECK-LABEL: define dso_local noundef i32 @main(
41+
; CHECK-LABEL: define dso_local i32 @main(
4242
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
4343
; CHECK-NEXT: [[ENTRY:.*:]]
4444
; CHECK-NEXT: tail call void @f1()
@@ -136,3 +136,6 @@ entry:
136136
tail call void @fun()
137137
ret void
138138
}
139+
;.
140+
; CHECK: attributes #[[ATTR0]] = { norecurse }
141+
;.

llvm/test/Transforms/FunctionAttrs/norecurse_multi_scc_indirect_recursion1.ll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; RUN: opt < %s -passes=norecurse-lto-inference -S | FileCheck %s
33

44
; This test includes a call graph with multiple SCCs. The purpose of this is
@@ -11,9 +11,9 @@
1111
; chain. but does not call back f1() and hence f1() can be marked as
1212
; norecurse.
1313

14-
define dso_local noundef i32 @main() norecurse {
14+
define dso_local i32 @main() norecurse {
1515
; CHECK: Function Attrs: norecurse
16-
; CHECK-LABEL: define dso_local noundef i32 @main(
16+
; CHECK-LABEL: define dso_local i32 @main(
1717
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
1818
; CHECK-NEXT: [[ENTRY:.*:]]
1919
; CHECK-NEXT: tail call void @f1()
@@ -93,3 +93,6 @@ entry:
9393
tail call void @fun()
9494
ret void
9595
}
96+
;.
97+
; CHECK: attributes #[[ATTR0]] = { norecurse }
98+
;.
Lines changed: 25 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals all --version 5
22
; RUN: opt < %s -passes=norecurse-lto-inference -S | FileCheck %s
33

44
; This test includes a call graph with a self recursive function.
55
; The purpose of this is to check that norecurse is added to functions
66
; which have a self-recursive function in the call-chain.
77
; The call-chain in this test is as follows
8-
; main -> bob -> callee1 -> callee2 -> callee3 -> callee4 -> callee5
9-
; where callee5 is self recursive.
8+
; main -> bob -> callee1 -> callee2
9+
; where callee2 is self recursive.
1010

1111
@x = dso_local global i32 4, align 4
1212
@y = dso_local global i32 2, align 4
1313

14-
define internal void @callee6() {
14+
;.
15+
; CHECK: @x = dso_local global i32 4, align 4
16+
; CHECK: @y = dso_local global i32 2, align 4
17+
;.
18+
define internal void @callee2() {
1519
; CHECK: Function Attrs: norecurse
16-
; CHECK-LABEL: define internal void @callee6(
20+
; CHECK-LABEL: define internal void @callee2(
1721
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
1822
; CHECK-NEXT: [[ENTRY:.*:]]
1923
; CHECK-NEXT: [[TMP0:%.*]] = load volatile i32, ptr @y, align 4
@@ -28,102 +32,48 @@ entry:
2832
ret void
2933
}
3034

31-
define internal void @callee5(i32 noundef %x) {
32-
; CHECK-LABEL: define internal void @callee5(
33-
; CHECK-SAME: i32 noundef [[X:%.*]]) {
35+
define internal void @callee1(i32 %x) {
36+
; CHECK-LABEL: define internal void @callee1(
37+
; CHECK-SAME: i32 [[X:%.*]]) {
3438
; CHECK-NEXT: [[ENTRY:.*:]]
3539
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], 0
3640
; CHECK-NEXT: br i1 [[CMP]], label %[[IF_THEN:.*]], label %[[IF_END:.*]]
3741
; CHECK: [[IF_THEN]]:
38-
; CHECK-NEXT: tail call void @callee5(i32 noundef [[X]])
42+
; CHECK-NEXT: tail call void @callee1(i32 [[X]])
3943
; CHECK-NEXT: br label %[[IF_END]]
4044
; CHECK: [[IF_END]]:
41-
; CHECK-NEXT: tail call void @callee6()
45+
; CHECK-NEXT: tail call void @callee2()
4246
; CHECK-NEXT: ret void
4347
;
4448
entry:
4549
%cmp = icmp sgt i32 %x, 0
4650
br i1 %cmp, label %if.then, label %if.end
4751

4852
if.then: ; preds = %entry
49-
tail call void @callee5(i32 noundef %x)
53+
tail call void @callee1(i32 %x)
5054
br label %if.end
5155

5256
if.end: ; preds = %if.then, %entry
53-
tail call void @callee6()
54-
ret void
55-
}
56-
57-
define internal void @callee4() {
58-
; CHECK: Function Attrs: norecurse
59-
; CHECK-LABEL: define internal void @callee4(
60-
; CHECK-SAME: ) #[[ATTR0]] {
61-
; CHECK-NEXT: [[ENTRY:.*:]]
62-
; CHECK-NEXT: [[TMP0:%.*]] = load volatile i32, ptr @x, align 4
63-
; CHECK-NEXT: tail call void @callee5(i32 noundef [[TMP0]])
64-
; CHECK-NEXT: ret void
65-
;
66-
entry:
67-
%0 = load volatile i32, ptr @x, align 4
68-
tail call void @callee5(i32 noundef %0)
69-
ret void
70-
}
71-
72-
define internal void @callee3() {
73-
; CHECK: Function Attrs: norecurse
74-
; CHECK-LABEL: define internal void @callee3(
75-
; CHECK-SAME: ) #[[ATTR0]] {
76-
; CHECK-NEXT: [[ENTRY:.*:]]
77-
; CHECK-NEXT: tail call void @callee4()
78-
; CHECK-NEXT: ret void
79-
;
80-
entry:
81-
tail call void @callee4()
82-
ret void
83-
}
84-
85-
define internal void @callee2() {
86-
; CHECK: Function Attrs: norecurse
87-
; CHECK-LABEL: define internal void @callee2(
88-
; CHECK-SAME: ) #[[ATTR0]] {
89-
; CHECK-NEXT: [[ENTRY:.*:]]
90-
; CHECK-NEXT: tail call void @callee3()
91-
; CHECK-NEXT: ret void
92-
;
93-
entry:
94-
tail call void @callee3()
95-
ret void
96-
}
97-
98-
define internal void @callee1() {
99-
; CHECK: Function Attrs: norecurse
100-
; CHECK-LABEL: define internal void @callee1(
101-
; CHECK-SAME: ) #[[ATTR0]] {
102-
; CHECK-NEXT: [[ENTRY:.*:]]
103-
; CHECK-NEXT: tail call void @callee2()
104-
; CHECK-NEXT: ret void
105-
;
106-
entry:
10757
tail call void @callee2()
10858
ret void
10959
}
11060

11161
define internal void @bob() {
112-
; CHECK: Function Attrs: norecurse
113-
; CHECK-LABEL: define internal void @bob(
114-
; CHECK-SAME: ) #[[ATTR0]] {
62+
; CHECK-LABEL: define internal void @bob() {
11563
; CHECK-NEXT: [[ENTRY:.*:]]
116-
; CHECK-NEXT: tail call void @callee1()
64+
; CHECK-NEXT: [[TMP0:%.*]] = load volatile i32, ptr @x, align 4
65+
; CHECK-NEXT: tail call void @callee2(i32 [[TMP0]])
11766
; CHECK-NEXT: ret void
11867
;
11968
entry:
120-
tail call void @callee1()
69+
%0 = load volatile i32, ptr @x, align 4
70+
tail call void @callee2(i32 %0)
12171
ret void
12272
}
12373

124-
define dso_local noundef i32 @main() norecurse {
74+
define dso_local i32 @main() norecurse {
12575
; CHECK: Function Attrs: norecurse
126-
; CHECK-LABEL: define dso_local noundef i32 @main(
76+
; CHECK-LABEL: define dso_local i32 @main(
12777
; CHECK-SAME: ) #[[ATTR0]] {
12878
; CHECK-NEXT: [[ENTRY:.*:]]
12979
; CHECK-NEXT: tail call void @bob()
@@ -133,3 +83,6 @@ entry:
13383
tail call void @bob()
13484
ret i32 0
13585
}
86+
;.
87+
; CHECK: attributes #[[ATTR0]] = { norecurse }
88+
;.

0 commit comments

Comments
 (0)