Skip to content

Commit cb9ca35

Browse files
committed
[LoopRotate][NPM] Disable header duplication under -Oz
It was already disabled under -Oz in buildFunctionSimplificationPipeline(), but not in buildModuleOptimizationPipeline()/addPGOInstrPasses(). Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D89927
1 parent 826997c commit cb9ca35

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
677677
LPM1.addPass(LoopInstSimplifyPass());
678678
LPM1.addPass(LoopSimplifyCFGPass());
679679

680-
// Rotate Loop - disable header duplication at -Oz
680+
// Disable header duplication in loop rotation at -Oz.
681681
LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
682682
// TODO: Investigate promotion cap for O1.
683683
LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
@@ -833,8 +833,9 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
833833
MPM.addPass(PGOInstrumentationGen(IsCS));
834834

835835
FunctionPassManager FPM;
836+
// Disable header duplication in loop rotation at -Oz.
836837
FPM.addPass(createFunctionToLoopPassAdaptor(
837-
LoopRotatePass(), EnableMSSALoopDependency,
838+
LoopRotatePass(Level != OptimizationLevel::Oz), EnableMSSALoopDependency,
838839
/*UseBlockFrequencyInfo=*/false, DebugLogging));
839840
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
840841

@@ -1164,8 +1165,9 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
11641165
C(OptimizePM, Level);
11651166

11661167
// First rotate loops that may have been un-rotated by prior passes.
1168+
// Disable header duplication at -Oz.
11671169
OptimizePM.addPass(createFunctionToLoopPassAdaptor(
1168-
LoopRotatePass(), EnableMSSALoopDependency,
1170+
LoopRotatePass(Level != OptimizationLevel::Oz), EnableMSSALoopDependency,
11691171
/*UseBlockFrequencyInfo=*/false, DebugLogging));
11701172

11711173
// Distribute loops to allow partial vectorization. I.e. isolate dependences

llvm/test/Transforms/LoopRotate/oz-disable.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; REQUIRES: asserts
22
; RUN: opt < %s -S -Os -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OS
33
; RUN: opt < %s -S -Oz -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OZ
4+
; RUN: opt < %s -S -passes='default<Os>' -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OS
5+
; RUN: opt < %s -S -passes='default<Oz>' -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OZ
46

57
; Loop should be rotated for -Os but not for -Oz.
68
; OS: rotating Loop at depth 1

0 commit comments

Comments
 (0)