Skip to content

Commit 2ef4791

Browse files
author
Sjoerd Meijer
committed
[LoopFlatten] Run it earlier, just before IndVarSimplify
This is a prep step for widening induction variables in LoopFlatten if this is posssible (D90640), to avoid having to perform certain overflow checks. Since IndVarSimplify may already widen induction variables, we want to run LoopFlatten just before IndVarSimplify. This is a minor reshuffle as both passes were already close after each other. Differential Revision: https://reviews.llvm.org/D90402
1 parent 07f1047 commit 2ef4791

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,16 @@ PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
535535
// TODO: Investigate promotion cap for O1.
536536
LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
537537
LPM1.addPass(SimpleLoopUnswitchPass());
538+
539+
if (EnableLoopFlatten)
540+
FPM.addPass(LoopFlattenPass());
538541
LPM2.addPass(IndVarSimplifyPass());
539542
LPM2.addPass(LoopIdiomRecognizePass());
540543

541544
for (auto &C : LateLoopOptimizationsEPCallbacks)
542545
C(LPM2, Level);
543546

544547
LPM2.addPass(LoopDeletionPass());
545-
if (EnableLoopFlatten)
546-
FPM.addPass(LoopFlattenPass());
547548
// Do not enable unrolling in PreLinkThinLTO phase during sample PGO
548549
// because it changes IR to makes profile annotation in back compile
549550
// inaccurate. The normal unroller doesn't pay attention to forced full unroll

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,17 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
441441
MPM.add(createCFGSimplificationPass());
442442
MPM.add(createInstructionCombiningPass());
443443
// We resume loop passes creating a second loop pipeline here.
444+
if (EnableLoopFlatten) {
445+
MPM.add(createLoopFlattenPass()); // Flatten loops
446+
MPM.add(createLoopSimplifyCFGPass());
447+
}
444448
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
445449
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
446450
addExtensionsToPM(EP_LateLoopOptimizations, MPM);
447451
MPM.add(createLoopDeletionPass()); // Delete dead loops
448452

449453
if (EnableLoopInterchange)
450454
MPM.add(createLoopInterchangePass()); // Interchange loops
451-
if (EnableLoopFlatten) {
452-
MPM.add(createLoopFlattenPass()); // Flatten loops
453-
MPM.add(createLoopSimplifyCFGPass());
454-
}
455455

456456
// Unroll small loops
457457
MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
@@ -1045,12 +1045,12 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
10451045
PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
10461046

10471047
// More loops are countable; try to optimize them.
1048+
if (EnableLoopFlatten)
1049+
PM.add(createLoopFlattenPass());
10481050
PM.add(createIndVarSimplifyPass());
10491051
PM.add(createLoopDeletionPass());
10501052
if (EnableLoopInterchange)
10511053
PM.add(createLoopInterchangePass());
1052-
if (EnableLoopFlatten)
1053-
PM.add(createLoopFlattenPass());
10541054

10551055
// Unroll small loops
10561056
PM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,

0 commit comments

Comments
 (0)