Skip to content

Commit 005fc11

Browse files
sherwin-dcThomas Preud'homme
authored andcommitted
[PGO] Change ThinLTO test for targets with loop unrolling disabled
I am working on a target in a downstream LLVM repo, and it seems that if a target backend chooses to disable loop unrolling this test would fail. A solution would be to modify the test to search for a different string instead. The specific test checks for `if.true.direct_targ` which appears in the output when thinlto is not used (ie samplepgo). The same is true for `if.false.orig_indirect`. However, if a target disables loop unrolling in the backend, the test fails as `if.true.direct_targ` no longer appears, though `if.false.orig_indirect` still does. This can be seen by using a clang pragma to disable loop unrolling in the `unroll()` function. For reference, the following files are the outputs of the last 2 test functions being compiled as the test case does, with and without thinlto, and with and without loop unrolling on the latest x86 clang build. The loop unrolling pragma was used to simulate the loop unrolling being disabled in a backend. ``` // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o out.ll // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o out.ll ``` Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D109234
1 parent 86a58f1 commit 005fc11

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed
Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO
2-
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO
3-
// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO
4-
// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO
5-
// Checks if hot call is inlined by normal compile, but not inlined by
6-
// thinlto compile.
1+
// RUN: %clang_cc1 -mllvm -debug-pass=Structure -O2 -fno-experimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO-OLDPM
2+
// RUN: %clang_cc1 -mllvm -debug-pass=Structure -O2 -fno-experimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO-OLDPM
3+
// RUN: %clang_cc1 -fdebug-pass-manager -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO
4+
// RUN: %clang_cc1 -fdebug-pass-manager -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO
75

86
int baz(int);
97
int g;
@@ -13,34 +11,32 @@ void foo(int n) {
1311
g += baz(i);
1412
}
1513

14+
// Checks that loop unroll and icp are invoked by normal compile, but not thinlto compile.
15+
16+
// SAMPLEPGO: Running pass: PGOIndirectCallPromotion on [module]
17+
// SAMPLEPGO: Running pass: LoopUnrollPass on bar
18+
19+
// SAMPLEPGO-OLDPM: PGOIndirectCallPromotion
20+
// SAMPLEPGO-OLDPM: Unroll loops
21+
// SAMPLEPGO-OLDPM: Unroll loops
22+
23+
// THINLTO-NOT: Running pass: PGOIndirectCallPromotion on [module]
24+
// THINLTO-NOT: Running pass: LoopUnrollPass on bar
25+
26+
// THINLTO-OLDPM-NOT: PGOIndirectCallPromotion
27+
// The first Unroll loop pass is the createSimpleLoopUnrollPass that unrolls and peels
28+
// loops with small constant trip counts. The second one is skipped by ThinLTO.
29+
// THINLTO-OLDPM: Unroll loops
30+
// THINLTO-OLDPM-NOT: Unroll loops
31+
32+
33+
// Checks if hot call is inlined by normal compile, but not inlined by
34+
// thinlto compile.
1635
// SAMPLEPGO-LABEL: define {{(dso_local )?}}void @bar
1736
// THINLTO-LABEL: define {{(dso_local )?}}void @bar
1837
// SAMPLEPGO-NOT: call{{.*}}foo
1938
// THINLTO: call{{.*}}foo
2039
void bar(int n) {
2140
for (int i = 0; i < n; i++)
2241
foo(i);
23-
}
24-
25-
// Checks if loop unroll is invoked by normal compile, but not thinlto compile.
26-
// SAMPLEPGO-LABEL: define {{(dso_local )?}}void @unroll
27-
// THINLTO-LABEL: define {{(dso_local )?}}void @unroll
28-
// SAMPLEPGO: call{{.*}}baz
29-
// SAMPLEPGO: call{{.*}}baz
30-
// THINLTO: call{{.*}}baz
31-
// THINLTO-NOT: call{{.*}}baz
32-
void unroll() {
33-
for (int i = 0; i < 2; i++)
34-
baz(i);
35-
}
36-
37-
// Checks that icp is not invoked for ThinLTO, but invoked for normal samplepgo.
38-
// SAMPLEPGO-LABEL: define {{(dso_local )?}}void @icp
39-
// THINLTO-LABEL: define {{(dso_local )?}}void @icp
40-
// SAMPLEPGO: if.true.direct_targ
41-
// FIXME: the following condition needs to be reversed once
42-
// LTOPreLinkDefaultPipeline is customized.
43-
// THINLTO-NOT: if.true.direct_targ
44-
void icp(void (*p)()) {
45-
p();
46-
}
42+
}

0 commit comments

Comments
 (0)