Skip to content

Commit

Permalink
[PassBuilder][PassManagerBuilder] Run LICM before loop spawning to en…
Browse files Browse the repository at this point in the history
…sure loop-invariant conditions appear outside of the loop. Addresses llvm#66.
  • Loading branch information
neboat committed Feb 24, 2022
1 parent e486ce4 commit 38b4eb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
28 changes: 11 additions & 17 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ PassBuilder::buildTapirLoweringPipeline(OptimizationLevel Level,
// Rotate Loop - disable header duplication at -Oz
LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
LPM2.addPass(IndVarSimplifyPass());
LPM2.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));

FunctionPassManager FPM(DebugLogging);
FPM.addPass(createFunctionToLoopPassAdaptor(
Expand Down Expand Up @@ -1623,27 +1624,15 @@ PassBuilder::buildTapirLoweringPipeline(OptimizationLevel Level,
if (EnableSyntheticCounts)
MPM.addPass(SyntheticCountsPropagation());

// Require the GlobalsAA analysis for the module so we can query it within
// the CGSCC pipeline.
MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());

// Begin a postorder CGSCC pipeline to clean up and perform function inlining
// after Tapir lowering.
InlineParams IP = getInlineParamsFromOptLevel(OptimizationLevel::O0);
ModuleInlinerWrapperPass PostLowerMIWP(IP, DebugLogging,
PerformMandatoryInliningsFirst,
UseInlineAdvisor, MaxDevirtIterations);
MPM.addPass(AlwaysInlinerPass(
/*InsertLifetimeIntrinsics=*/PTO.Coroutines));

// Require the GlobalsAA analysis for the module so we can query it within
// the CGSCC pipeline.
PostLowerMIWP.addRequiredModuleAnalysis<GlobalsAA>();

// Require the ProfileSummaryAnalysis for the module so we can query it within
// the inliner pass.
PostLowerMIWP.addRequiredModuleAnalysis<ProfileSummaryAnalysis>();
MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());

// Now begin the postoder CGSCC pipeline.
CGSCCPassManager &PostLowerCGPipeline = PostLowerMIWP.getPM();
// Begin the postoder CGSCC pipeline.
CGSCCPassManager PostLowerCGPipeline(DebugLogging);

// Now deduce any function attributes based in the current code.
PostLowerCGPipeline.addPass(PostOrderFunctionAttrsPass());
Expand All @@ -1670,6 +1659,11 @@ PassBuilder::buildTapirLoweringPipeline(OptimizationLevel Level,
// Drop bodies of available eternally objects to improve GlobalDCE.
MPM.addPass(EliminateAvailableExternallyPass());

// Do RPO function attribute inference across the module to forward-propagate
// attributes where applicable.
// FIXME: Is this really an optimization rather than a canonicalization?
MPM.addPass(ReversePostOrderFunctionAttrsPass());

// Now that we have optimized the program, discard unreachable functions.
MPM.addPass(GlobalDCEPass());

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ void PassManagerBuilder::populateModulePassManager(
// rotated form due to GVN or other transformations, and loop spawning
// relies on the rotated form. Disable header duplication at -Oz.
MPM.add(createLoopRotatePass(SizeLevel == 2 ? 0 : -1));
MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
// Outline Tapir loops as needed.
MPM.add(createLoopSpawningTIPass());
if (VerifyTapir)
Expand Down

0 comments on commit 38b4eb2

Please sign in to comment.