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 @@ -274,6 +274,10 @@ cl::desc("Perform mandatory inlinings module-wide, before performing " "inlining.")); +static cl::opt EnableO3NonTrivialUnswitching( + "enable-npm-O3-nontrivial-unswitch", cl::init(true), cl::Hidden, + cl::ZeroOrMore, cl::desc("Enable non-trivial loop unswitching for -O3")); + PipelineTuningOptions::PipelineTuningOptions() { LoopInterleaving = true; LoopVectorization = true; @@ -726,7 +730,8 @@ // TODO: Investigate promotion cap for O1. LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap)); LPM1.addPass( - SimpleLoopUnswitchPass(/* NonTrivial */ Level == OptimizationLevel::O3)); + SimpleLoopUnswitchPass(/* NonTrivial */ Level == OptimizationLevel::O3 && + EnableO3NonTrivialUnswitching)); LPM2.addPass(LoopIdiomRecognizePass()); LPM2.addPass(IndVarSimplifyPass()); diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll --- a/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll +++ b/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll @@ -1,6 +1,7 @@ ; RUN: opt < %s -S -passes="default" | FileCheck %s -check-prefixes=TRIVIAL,CHECK ; RUN: opt < %s -S -passes="default" | FileCheck %s -check-prefixes=TRIVIAL,CHECK ; RUN: opt < %s -S -passes="default" | FileCheck %s -check-prefixes=NONTRIVIAL,CHECK +; RUN: opt < %s -S -passes="default" -enable-npm-O3-nontrivial-unswitch=0 | FileCheck %s -check-prefixes=TRIVIAL,CHECK ; RUN: opt < %s -S -passes="default" | FileCheck %s -check-prefixes=TRIVIAL,CHECK ; RUN: opt < %s -S -passes="default" | FileCheck %s -check-prefixes=TRIVIAL,CHECK