[PATCH] D71687: Fix full loop unrolling initialization in new pass manager
Eric Christopher via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 13 09:39:47 PDT 2020
echristo updated this revision to Diff 250229.
echristo added a comment.
Fixed the clang test.
Tried to get something that I could reduce down and duplicate with just opt but it's been... difficult. Even the small clang testcase in isolation won't duplicate via something like:
clang -O0 -fexperimental-new-pass-manager foo.cc -S -o - -emit-llvm -mllvm -disable-llvm-optzns | opt -passes='default<O1 <https://reviews.llvm.org/owners/package/1/>>' -transform-warning -pass-remarks-missed=transform-warning -S -o -
Might be holding it wrong, but this isn't very discoverable if so :)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71687/new/
https://reviews.llvm.org/D71687
Files:
clang/test/Misc/loop-opt-setup.c
llvm/lib/Passes/PassBuilder.cpp
Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -497,11 +497,10 @@
// Do not enable unrolling in PreLinkThinLTO phase during sample PGO
// because it changes IR to makes profile annotation in back compile
// inaccurate.
- if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
- PGOOpt->Action != PGOOptions::SampleUse) &&
- PTO.LoopUnrolling)
+ if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
+ PGOOpt->Action != PGOOptions::SampleUse)
LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
- /*OnlyWhenForced=*/false,
+ /*OnlyWhenForced=*/!PTO.LoopUnrolling,
PTO.ForgetAllSCEVInLoopUnroll));
for (auto &C : LoopOptimizerEndEPCallbacks)
Index: clang/test/Misc/loop-opt-setup.c
===================================================================
--- clang/test/Misc/loop-opt-setup.c
+++ clang/test/Misc/loop-opt-setup.c
@@ -1,5 +1,5 @@
-// RUN: %clang -O1 -fexperimental-new-pass-manager -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
-// RUN: %clang -O1 -fno-experimental-new-pass-manager -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
+// RUN: %clang -O1 -fexperimental-new-pass-manager -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s -check-prefix=CHECK-NEWPM
+// RUN: %clang -O1 -fno-experimental-new-pass-manager -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s -check-prefix=CHECK-OLDPM
extern int a[16];
int b = 0;
int foo(void) {
@@ -8,5 +8,34 @@
a[i] = b += 2;
return b;
}
+// Check br i1 to make sure that the loop is fully unrolled
// CHECK-NOT: br i1
+inline void Helper() {
+ const int* nodes[5];
+ int num_active = 5;
+
+ while (num_active) {
+#pragma clang loop unroll(full)
+ for (int i = 0; i < 5; ++i) {
+ if (nodes[i]) {
+ --num_active;
+ }
+ }
+ }
+}
+
+void Run() {
+ Helper();
+}
+
+// Check br i1 to make sure the loop is gone, there will still be a label branch for the infinite loop.
+// CHECK-NEWPM-NOT: br i1
+
+// The old pass manager doesn't remove the loop so check for 5 load i32*.
+// CHECK-OLDPM: Helper
+// CHECK-OLDPM: load i32*
+// CHECK-OLDPM: load i32*
+// CHECK-OLDPM: load i32*
+// CHECK-OLDPM: load i32*
+// CHECK-OLDPM: load i32*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71687.250229.patch
Type: text/x-patch
Size: 2420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200313/8518da0a/attachment-0001.bin>
More information about the cfe-commits
mailing list