[PATCH] D36655: Move SampleProfileLoader pass before all simplification passes.

Dehao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 13 13:12:46 PDT 2017


danielcdh created this revision.
Herald added subscribers: aprantl, sanjoy.

This makes the new PM not matching the legacy PM. But testing shows that it improves performance because simplification passes especially simplify CFG can affect the accuracy of the debug info.


https://reviews.llvm.org/D36655

Files:
  lib/Passes/PassBuilder.cpp
  test/Other/new-pm-pgo.ll


Index: test/Other/new-pm-pgo.ll
===================================================================
--- test/Other/new-pm-pgo.ll
+++ test/Other/new-pm-pgo.ll
@@ -13,11 +13,11 @@
 ; USE: Running pass: PGOInstrumentationUse
 ; SAMPLE_USE_O: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
 ; SAMPLE_USE_PRE_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
-; SAMPLE_USE: Running pass: SimplifyCFGPass
-; SAMPLE_USE: Running pass: SROA
-; SAMPLE_USE: Running pass: EarlyCSEPass
-; SAMPLE_USE: Running pass: LowerExpectIntrinsicPass
-; SAMPLE_USE_POST_LINK: Running pass: InstCombinePass
+; SAMPLE_USE-NOT: Running pass: SimplifyCFGPass
+; SAMPLE_USE-NOT: Running pass: SROA
+; SAMPLE_USE-NOT: Running pass: EarlyCSEPass
+; SAMPLE_USE-NOT: Running pass: LowerExpectIntrinsicPass
+; SAMPLE_USE_POST_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}InstCombinePass{{.*}}>
 ; SAMPLE_USE: Running pass: SampleProfileLoaderPass
 ; SAMPLE_USE_O: Running pass: PGOIndirectCallPromotion
 ; SAMPLE_USE_POST_LINK-NOT: Running pass: GlobalOptPass
Index: lib/Passes/PassBuilder.cpp
===================================================================
--- lib/Passes/PassBuilder.cpp
+++ lib/Passes/PassBuilder.cpp
@@ -533,25 +533,15 @@
   // libraries and other oracles.
   MPM.addPass(InferFunctionAttrsPass());
 
-  // Create an early function pass manager to cleanup the output of the
-  // frontend.
-  FunctionPassManager EarlyFPM(DebugLogging);
-  EarlyFPM.addPass(SimplifyCFGPass());
-  EarlyFPM.addPass(SROA());
-  EarlyFPM.addPass(EarlyCSEPass());
-  EarlyFPM.addPass(LowerExpectIntrinsicPass());
-  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
-  // to convert bitcast to direct calls so that they can be inlined during the
-  // profile annotation prepration step.
-  // More details about SamplePGO design can be found in:
-  // https://research.google.com/pubs/pub45290.html
-  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
-  if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
-      Phase == ThinLTOPhase::PostLink)
-    EarlyFPM.addPass(InstCombinePass());
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
-
   if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
+    // In SamplePGO ThinLTO backend, we need instcombine before profile
+    // annotation to convert bitcast to direct calls so that they can be
+    // inlined during the profile annotation prepration step.
+    // More details about SamplePGO design can be found in:
+    // https://research.google.com/pubs/pub45290.html
+    // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
+    if (Phase == ThinLTOPhase::PostLink)
+      MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
     // Annotate sample profile right after early FPM to ensure freshness of
     // the debug info.
     MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
@@ -566,6 +556,15 @@
                                            true));
   }
 
+  // Create an early function pass manager to cleanup the output of the
+  // frontend.
+  FunctionPassManager EarlyFPM(DebugLogging);
+  EarlyFPM.addPass(SimplifyCFGPass());
+  EarlyFPM.addPass(SROA());
+  EarlyFPM.addPass(EarlyCSEPass());
+  EarlyFPM.addPass(LowerExpectIntrinsicPass());
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
+
   // Interprocedural constant propagation now that basic cleanup has occured
   // and prior to optimizing globals.
   // FIXME: This position in the pipeline hasn't been carefully considered in


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36655.110890.patch
Type: text/x-patch
Size: 3634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170813/9eb2048e/attachment.bin>


More information about the llvm-commits mailing list