From fb8cc45e0401322f65acebcda4a39e2f581819b0 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Wed, 21 Oct 2020 22:08:58 -0700 Subject: [PATCH] [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 --- lib/Passes/PassBuilder.cpp | 8 +++++--- test/Transforms/LoopRotate/oz-disable.ll | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 199e459e3d6..ab4b305f250 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -677,7 +677,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, 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 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging, 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 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline( 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/test/Transforms/LoopRotate/oz-disable.ll b/test/Transforms/LoopRotate/oz-disable.ll index 7a6a9bf33a1..5ac7864b33a 100644 --- a/test/Transforms/LoopRotate/oz-disable.ll +++ b/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