Skip to content

Commit 856caae

Browse files
Artem Gindinsonagrabezh
authored andcommitted
Add "loop unrolling upperbound" patch for LLVM 14-15
Port the patch from version 11 to address performance regressions. Co-authored-by: Andrey Grabezhnoy <[email protected]> Co-authored-by: Artem Gindinson <[email protected]> (cherry picked from commit 9da9a8c)
1 parent 16ed156 commit 856caae

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2021-2023 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
/*========================== begin_copyright_notice ============================
10+
11+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
See https://llvm.org/LICENSE.txt for license information.
13+
SPDX-License-Identifier: Apache-2.0 with LLVM-exception
14+
15+
============================= end_copyright_notice ===========================*/
16+
17+
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
18+
index 9beb2281c..a3cc73ca5 100644
19+
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
20+
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
21+
@@ -968,7 +968,7 @@ bool llvm::computeUnrollCount(
22+
// cost of exact full unrolling. As such, if we have an exact count and
23+
// found it unprofitable, we'll never chose to bounded unroll.
24+
if (!TripCount && MaxTripCount && (UP.UpperBound || MaxOrZero) &&
25+
- MaxTripCount <= UnrollMaxUpperBound) {
26+
+ MaxTripCount < std::max(16U, UnrollMaxUpperBound.getValue())) {
27+
UP.Count = MaxTripCount;
28+
if (auto UnrollFactor = shouldFullUnroll(L, TTI, DT, SE, EphValues,
29+
MaxTripCount, UCE, UP)) {
30+
@@ -1042,7 +1042,8 @@ bool llvm::computeUnrollCount(
31+
}
32+
33+
// Don't unroll a small upper bound loop unless user or TTI asked to do so.
34+
- if (MaxTripCount && !UP.Force && MaxTripCount < UnrollMaxUpperBound) {
35+
+ if (MaxTripCount && !UP.Force &&
36+
+ MaxTripCount < std::max(16U, UnrollMaxUpperBound.getValue())) {
37+
UP.Count = 0;
38+
return false;
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2021-2023 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
/*========================== begin_copyright_notice ============================
10+
11+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
See https://llvm.org/LICENSE.txt for license information.
13+
SPDX-License-Identifier: Apache-2.0 with LLVM-exception
14+
15+
============================= end_copyright_notice ===========================*/
16+
17+
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
18+
index de5833f60..77505e00b 100644
19+
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
20+
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
21+
@@ -967,7 +967,7 @@ bool llvm::computeUnrollCount(
22+
// cost of exact full unrolling. As such, if we have an exact count and
23+
// found it unprofitable, we'll never chose to bounded unroll.
24+
if (!TripCount && MaxTripCount && (UP.UpperBound || MaxOrZero) &&
25+
- MaxTripCount <= UnrollMaxUpperBound) {
26+
+ MaxTripCount < std::max(16U, UnrollMaxUpperBound.getValue())) {
27+
UP.Count = MaxTripCount;
28+
if (auto UnrollFactor = shouldFullUnroll(L, TTI, DT, SE, EphValues,
29+
MaxTripCount, UCE, UP)) {
30+
@@ -1041,7 +1041,8 @@ bool llvm::computeUnrollCount(
31+
}
32+
33+
// Don't unroll a small upper bound loop unless user or TTI asked to do so.
34+
- if (MaxTripCount && !UP.Force && MaxTripCount < UnrollMaxUpperBound) {
35+
+ if (MaxTripCount && !UP.Force &&
36+
+ MaxTripCount < std::max(16U, UnrollMaxUpperBound.getValue())) {
37+
UP.Count = 0;
38+
return false;
39+
}
40+

0 commit comments

Comments
 (0)