[PATCH] D68535: Fix loop unrolling initialization in the new pass manager
Eric Christopher via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 22:27:57 PDT 2019
echristo created this revision.
echristo added reviewers: chandlerc, hfinkel.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, mcrosier.
Herald added projects: clang, LLVM.
In the new pass manager use PTO.LoopUnrolling to determine when and how
we will unroll loops. Also comment a few occasions where we need to
know whether or not we're forcing the unwinder or not.
Testcase is in clang because it's controlling how the loop optimizer
is being set up and there's no other way to trigger the behavior.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68535
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
@@ -470,8 +470,8 @@
if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
PGOOpt->Action != PGOOptions::SampleUse) &&
PTO.LoopUnrolling)
- LPM2.addPass(
- LoopFullUnrollPass(Level, false, PTO.ForgetAllSCEVInLoopUnroll));
+ LPM2.addPass(LoopFullUnrollPass(Level, /*OnlyWhenForced=*/false,
+ PTO.ForgetAllSCEVInLoopUnroll));
for (auto &C : LoopOptimizerEndEPCallbacks)
C(LPM2, Level);
@@ -950,13 +950,13 @@
// combiner for cleanup here so that the unrolling and LICM can be pipelined
// across the loop nests.
// We do UnrollAndJam in a separate LPM to ensure it happens before unroll
- if (EnableUnrollAndJam) {
+ if (EnableUnrollAndJam && PTO.LoopUnrolling) {
OptimizePM.addPass(
createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level)));
}
- if (PTO.LoopUnrolling)
- OptimizePM.addPass(LoopUnrollPass(
- LoopUnrollOptions(Level, false, PTO.ForgetAllSCEVInLoopUnroll)));
+ OptimizePM.addPass(LoopUnrollPass(
+ LoopUnrollOptions(Level, /*OnlyWhenForced=*/!PTO.LoopUnrolling,
+ PTO.ForgetAllSCEVInLoopUnroll)));
OptimizePM.addPass(WarnMissedTransformationsPass());
OptimizePM.addPass(InstCombinePass());
OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
Index: clang/test/Misc/loop-opt-setup.c
===================================================================
--- /dev/null
+++ clang/test/Misc/loop-opt-setup.c
@@ -0,0 +1,12 @@
+// RUN: %clang -O1 -fexperimental-new-pass-manager -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
+// RUN: %clang -O1 -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
+extern int a[16];
+int b = 0;
+int foo(void) {
+#pragma unroll
+ for (int i = 0; i < 16; ++i)
+ a[i] = b += 2;
+ return b;
+}
+// CHECK-NOT: br i1
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68535.223362.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191005/4913c2ca/attachment.bin>
More information about the cfe-commits
mailing list