Skip to content

Commit a9bd3d3

Browse files
committed
[NewPM] Add ExtraVectorizerPasses support
As it looks like NewPM generally is using SimpleLoopUnswitch instead of LoopUnswitch, this patch also use SimpleLoopUnswitch in the ExtraVectorizerPasses sequence (compared with LegacyPM which use the LoopUnswitch pass). Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D95457
1 parent 5f1d4d4 commit a9bd3d3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
287287
MergeFunctions = false;
288288
UniqueLinkageNames = false;
289289
}
290+
extern cl::opt<bool> ExtraVectorizerPasses;
290291

291292
extern cl::opt<bool> EnableConstraintElimination;
292293
extern cl::opt<bool> EnableGVNHoist;
@@ -1255,6 +1256,28 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
12551256
// Cleanup after the loop optimization passes.
12561257
OptimizePM.addPass(InstCombinePass());
12571258

1259+
if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1260+
// At higher optimization levels, try to clean up any runtime overlap and
1261+
// alignment checks inserted by the vectorizer. We want to track correlated
1262+
// runtime checks for two inner loops in the same outer loop, fold any
1263+
// common computations, hoist loop-invariant aspects out of any outer loop,
1264+
// and unswitch the runtime checks if possible. Once hoisted, we may have
1265+
// dead (or speculatable) control flows or more combining opportunities.
1266+
OptimizePM.addPass(EarlyCSEPass());
1267+
OptimizePM.addPass(CorrelatedValuePropagationPass());
1268+
OptimizePM.addPass(InstCombinePass());
1269+
LoopPassManager LPM(DebugLogging);
1270+
LPM.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
1271+
LPM.addPass(
1272+
SimpleLoopUnswitchPass(/* NonTrivial */ Level == OptimizationLevel::O3));
1273+
OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
1274+
OptimizePM.addPass(createFunctionToLoopPassAdaptor(
1275+
std::move(LPM), EnableMSSALoopDependency, /*UseBlockFrequencyInfo=*/true,
1276+
DebugLogging));
1277+
OptimizePM.addPass(SimplifyCFGPass());
1278+
OptimizePM.addPass(InstCombinePass());
1279+
}
1280+
12581281
// Now that we've formed fast to execute loop structures, we do further
12591282
// optimizations. These are run afterward as they might block doing complex
12601283
// analyses and transforms such as what are needed for loop vectorization.
@@ -1274,8 +1297,12 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
12741297
.sinkCommonInsts(true)));
12751298

12761299
// Optimize parallel scalar instruction chains into SIMD instructions.
1277-
if (PTO.SLPVectorization)
1300+
if (PTO.SLPVectorization) {
12781301
OptimizePM.addPass(SLPVectorizerPass());
1302+
if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1303+
OptimizePM.addPass(EarlyCSEPass());
1304+
}
1305+
}
12791306

12801307
// Enhance/cleanup vector code.
12811308
OptimizePM.addPass(VectorCombinePass());

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ UseGVNAfterVectorization("use-gvn-after-vectorization",
6060
cl::init(false), cl::Hidden,
6161
cl::desc("Run GVN instead of Early CSE after vectorization passes"));
6262

63-
static cl::opt<bool> ExtraVectorizerPasses(
63+
cl::opt<bool> ExtraVectorizerPasses(
6464
"extra-vectorizer-passes", cl::init(false), cl::Hidden,
6565
cl::desc("Run cleanup optimization passes after vectorization."));
6666

llvm/test/Other/opt-pipeline-vector-passes.ll

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
; RUN: opt -enable-new-pm=0 -O2 -vectorize-loops=0 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck %s --check-prefixes=OLDPM_O2_FORCE_OFF
66
; RUN: opt -disable-verify -debug-pass-manager -passes='default<O1>' -S %s 2>&1 | FileCheck %s --check-prefixes=NEWPM_O1
77
; RUN: opt -disable-verify -debug-pass-manager -passes='default<O2>' -S %s 2>&1 | FileCheck %s --check-prefixes=NEWPM_O2
8+
; RUN: opt -disable-verify -debug-pass-manager -passes='default<O2>' -extra-vectorizer-passes -S %s 2>&1 | FileCheck %s --check-prefixes=NEWPM_O2_EXTRA
89

910
; REQUIRES: asserts
1011

@@ -64,6 +65,27 @@
6465
; NEWPM_O2: Running pass: SLPVectorizerPass
6566
; NEWPM_O2: Running pass: VectorCombinePass
6667

67-
define void @f() {
68-
ret void
68+
; NEWPM_O2_EXTRA-LABEL: Running pass: LoopVectorizePass
69+
; NEWPM_O2_EXTRA: Running pass: EarlyCSEPass
70+
; NEWPM_O2_EXTRA: Running pass: CorrelatedValuePropagationPass
71+
; NEWPM_O2_EXTRA: Running pass: InstCombinePass
72+
; NEWPM_O2_EXTRA: Running pass: LICMPass
73+
; NEWPM_O2_EXTRA: Running pass: SimpleLoopUnswitchPass
74+
; NEWPM_O2_EXTRA: Running pass: SimplifyCFGPass
75+
; NEWPM_O2_EXTRA: Running pass: InstCombinePass
76+
; NEWPM_O2_EXTRA: Running pass: SLPVectorizerPass
77+
; NEWPM_O2_EXTRA: Running pass: EarlyCSEPass
78+
; NEWPM_O2_EXTRA: Running pass: VectorCombinePass
79+
80+
define i64 @f(i1 %cond) {
81+
entry:
82+
br label %loop
83+
84+
loop:
85+
%i = phi i64 [ 0, %entry ], [ %inc, %loop ]
86+
%inc = add i64 %i, 1
87+
br i1 %cond, label %loop, label %exit
88+
89+
exit:
90+
ret i64 %i
6991
}

0 commit comments

Comments
 (0)