[PATCH] D60790: [LPM/BPI] Preserve BPI through trivial loop pass pipeline

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 12:29:03 PDT 2019


reames created this revision.
reames added reviewers: chandlerc, fedor.sergeev.
Herald added subscribers: bollu, mcrosier.
Herald added a project: LLVM.

Currently, we do not expose BPI to loop passes at all.  In the old pass manager, we somehow ended up with valid BPI (at least in some circumstances); in the new one, it's invalidated before running any loop pass if either LCSSA or LoopSimplify actually make changes.  If they don't make changes, then BPI is valid and available.

I'm not sure that we're going to be able to push through BPI through all loop passes, and the behaviour of an non-preserved by a loop pass function analysis worries me quite a bit.  However, I think it's worth supporting at least simple cases, which is what these changes do.

Here's the reasoning by which preservation is correct for each:

- LCSSA does not modify the CFG.  BPI only maps terminator instructions to data, so not modifying the CFG ensures data validity.
- LoopSimplify can insert blocks, but it does so only by splitting existing blocks and edges.  This results in the interesting property that all new terminators are unconditional branches.  BPI does not contain entries for such terminators.  All deletions are handled via ValueHandle callbacks w/in BPI.

This avoids an invalidation between the two requires in the following trivial pass pipeline:
opt -passes="requires<branch-prob>,loop(no-op-loop),requires<branch-prob>"


Repository:
  rL LLVM

https://reviews.llvm.org/D60790

Files:
  lib/Transforms/Utils/LCSSA.cpp
  lib/Transforms/Utils/LoopSimplify.cpp
  test/Other/opt-O2-pipeline.ll
  test/Other/opt-O3-pipeline.ll
  test/Other/opt-Os-pipeline.ll


Index: test/Other/opt-Os-pipeline.ll
===================================================================
--- test/Other/opt-Os-pipeline.ll
+++ test/Other/opt-Os-pipeline.ll
@@ -256,7 +256,6 @@
 ; CHECK-NEXT:       Basic Alias Analysis (stateless AA impl)
 ; CHECK-NEXT:       Function Alias Analysis Results
 ; CHECK-NEXT:       Scalar Evolution Analysis
-; CHECK-NEXT:       Branch Probability Analysis
 ; CHECK-NEXT:       Block Frequency Analysis
 ; CHECK-NEXT:       Loop Pass Manager
 ; CHECK-NEXT:         Loop Sink
Index: test/Other/opt-O3-pipeline.ll
===================================================================
--- test/Other/opt-O3-pipeline.ll
+++ test/Other/opt-O3-pipeline.ll
@@ -274,7 +274,6 @@
 ; CHECK-NEXT:       Basic Alias Analysis (stateless AA impl)
 ; CHECK-NEXT:       Function Alias Analysis Results
 ; CHECK-NEXT:       Scalar Evolution Analysis
-; CHECK-NEXT:       Branch Probability Analysis
 ; CHECK-NEXT:       Block Frequency Analysis
 ; CHECK-NEXT:       Loop Pass Manager
 ; CHECK-NEXT:         Loop Sink
Index: test/Other/opt-O2-pipeline.ll
===================================================================
--- test/Other/opt-O2-pipeline.ll
+++ test/Other/opt-O2-pipeline.ll
@@ -269,7 +269,6 @@
 ; CHECK-NEXT:       Basic Alias Analysis (stateless AA impl)
 ; CHECK-NEXT:       Function Alias Analysis Results
 ; CHECK-NEXT:       Scalar Evolution Analysis
-; CHECK-NEXT:       Branch Probability Analysis
 ; CHECK-NEXT:       Block Frequency Analysis
 ; CHECK-NEXT:       Loop Pass Manager
 ; CHECK-NEXT:         Loop Sink
Index: lib/Transforms/Utils/LoopSimplify.cpp
===================================================================
--- lib/Transforms/Utils/LoopSimplify.cpp
+++ lib/Transforms/Utils/LoopSimplify.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
+#include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/InstructionSimplify.h"
@@ -740,6 +741,7 @@
       AU.addPreservedID(LCSSAID);
       AU.addPreserved<DependenceAnalysisWrapperPass>();
       AU.addPreservedID(BreakCriticalEdgesID);  // No critical edges added.
+      AU.addPreserved<BranchProbabilityInfoWrapperPass>();
     }
 
     /// verifyAnalysis() - Verify LoopSimplifyForm's guarantees.
@@ -812,6 +814,7 @@
   PA.preserve<SCEVAA>();
   PA.preserve<ScalarEvolutionAnalysis>();
   PA.preserve<DependenceAnalysis>();
+  PA.preserve<BranchProbabilityAnalysis>();
   return PA;
 }
 
Index: lib/Transforms/Utils/LCSSA.cpp
===================================================================
--- lib/Transforms/Utils/LCSSA.cpp
+++ lib/Transforms/Utils/LCSSA.cpp
@@ -31,6 +31,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
+#include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/ScalarEvolution.h"
@@ -442,6 +443,7 @@
     AU.addPreserved<GlobalsAAWrapperPass>();
     AU.addPreserved<ScalarEvolutionWrapperPass>();
     AU.addPreserved<SCEVAAWrapperPass>();
+    AU.addPreserved<BranchProbabilityInfoWrapperPass>();
 
     // This is needed to perform LCSSA verification inside LPPassManager
     AU.addRequired<LCSSAVerificationPass>();
@@ -485,5 +487,6 @@
   PA.preserve<GlobalsAA>();
   PA.preserve<SCEVAA>();
   PA.preserve<ScalarEvolutionAnalysis>();
+  PA.preserve<BranchProbabilityAnalysis>();
   return PA;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60790.195431.patch
Type: text/x-patch
Size: 3626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/b689f5a7/attachment.bin>


More information about the llvm-commits mailing list