diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -677,7 +677,7 @@ LPM1.addPass(LoopInstSimplifyPass()); LPM1.addPass(LoopSimplifyCFGPass()); - // Rotate Loop - disable header duplication at -Oz + // Disable header duplication in loop rotation at -Oz. LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz)); // TODO: Investigate promotion cap for O1. LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap)); @@ -833,8 +833,9 @@ MPM.addPass(PGOInstrumentationGen(IsCS)); FunctionPassManager FPM; + // Disable header duplication in loop rotation at -Oz. FPM.addPass(createFunctionToLoopPassAdaptor( - LoopRotatePass(), EnableMSSALoopDependency, + LoopRotatePass(Level != OptimizationLevel::Oz), EnableMSSALoopDependency, /*UseBlockFrequencyInfo=*/false, DebugLogging)); MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); @@ -1164,8 +1165,9 @@ C(OptimizePM, Level); // First rotate loops that may have been un-rotated by prior passes. + // Disable header duplication at -Oz. OptimizePM.addPass(createFunctionToLoopPassAdaptor( - LoopRotatePass(), EnableMSSALoopDependency, + LoopRotatePass(Level != OptimizationLevel::Oz), EnableMSSALoopDependency, /*UseBlockFrequencyInfo=*/false, DebugLogging)); // Distribute loops to allow partial vectorization. I.e. isolate dependences diff --git a/llvm/test/Transforms/LoopRotate/oz-disable.ll b/llvm/test/Transforms/LoopRotate/oz-disable.ll --- a/llvm/test/Transforms/LoopRotate/oz-disable.ll +++ b/llvm/test/Transforms/LoopRotate/oz-disable.ll @@ -1,6 +1,8 @@ ; REQUIRES: asserts ; RUN: opt < %s -S -Os -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OS ; RUN: opt < %s -S -Oz -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OZ +; RUN: opt < %s -S -passes='default' -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OS +; RUN: opt < %s -S -passes='default' -debug -debug-only=loop-rotate 2>&1 | FileCheck %s -check-prefix=OZ ; Loop should be rotated for -Os but not for -Oz. ; OS: rotating Loop at depth 1