[PATCH] D57723: WIP change to address phase ordering issues between loop optimizations, jump threading, and GVN.

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 4 16:18:23 PST 2019


chandlerc created this revision.
Herald added subscribers: llvm-commits, hiraditya, mcrosier, sanjoy.
Herald added a project: LLVM.

This change is not intended to actually submit, just discussing it with folks on IRC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D57723

Files:
  llvm/lib/Passes/PassBuilder.cpp


Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -493,14 +493,53 @@
   // redo DCE, etc.
   FPM.addPass(JumpThreadingPass());
   FPM.addPass(CorrelatedValuePropagationPass());
+  FPM.addPass(SimplifyCFGPass());
   FPM.addPass(DSEPass());
-  FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
+
+  if (Level == O1) {
+    FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), DebugLogging));
+  } else {
+    // Add a late loop simplification pipeline to catch opportunities exposed by redundancy elimination.
+    LoopPassManager LateLPM(DebugLogging);
+    LateLPM.addPass(LoopInstSimplifyPass());
+    LateLPM.addPass(LoopSimplifyCFGPass());
+    LateLPM.addPass(LoopRotatePass(Level != Oz));
+    LateLPM.addPass(LICMPass());
+    LateLPM.addPass(SimpleLoopUnswitchPass());
+    LateLPM.addPass(IndVarSimplifyPass());
+    LateLPM.addPass(LoopIdiomRecognizePass());
+    LateLPM.addPass(LoopDeletionPass());
+    // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
+    // because it changes IR to makes profile annotation in back compile
+    // inaccurate.
+    if (Phase != ThinLTOPhase::PreLink ||
+        !PGOOpt || PGOOpt->SampleProfileFile.empty())
+      LateLPM.addPass(LoopFullUnrollPass(Level));
+    FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LateLPM), DebugLogging));
+
+    // Eliminate redundancies. Only use GVN at O3 due to the cost of running it twice.
+    if (Level == O3) {
+      // These passes add substantial compile time so skip them at O1.
+      FPM.addPass(MergedLoadStoreMotionPass());
+      if (RunNewGVN)
+        FPM.addPass(NewGVNPass());
+      else
+        FPM.addPass(GVN());
+
+      // Combine any opportunities exposed by the second redundancy elimination.
+      FPM.addPass(InstCombinePass());
+    } else {
+      FPM.addPass(EarlyCSEPass());
+    }
+  }
 
   for (auto &C : ScalarOptimizerLateEPCallbacks)
     C(FPM, Level);
 
   // Finally, do an expensive DCE pass to catch all the dead code exposed by
   // the simplifications and basic cleanup after all the simplifications.
+  FPM.addPass(SimplifyCFGPass());
+  FPM.addPass(DSEPass());
   FPM.addPass(ADCEPass());
   FPM.addPass(SimplifyCFGPass());
   FPM.addPass(InstCombinePass());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57723.185183.patch
Type: text/x-patch
Size: 2375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190205/de93aa92/attachment.bin>


More information about the llvm-commits mailing list