[llvm] 8f108c3 - Revert "[SLP] Optionally preserve MemorySSA"

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 10:46:06 PDT 2022


Author: Philip Reames
Date: 2022-03-18T10:45:59-07:00
New Revision: 8f108c32bcd52cb03d3fb36d09f5aa78d35ec6c2

URL: https://github.com/llvm/llvm-project/commit/8f108c32bcd52cb03d3fb36d09f5aa78d35ec6c2
DIFF: https://github.com/llvm/llvm-project/commit/8f108c32bcd52cb03d3fb36d09f5aa78d35ec6c2.diff

LOG: Revert "[SLP] Optionally preserve MemorySSA"

This reverts commit 1cfa986d68e2f04854ef30c432b8aa28e13a9706.  See https://github.com/llvm/llvm-project/issues/54256 for why I'm discontinuing the project.

Seperately, it turns out that while this patch does correctly preserve MSSA, it's correct only at the end of the pass; not between vectorization attempts.  Even if we decide to resurrect this, we'll need to fix that before reapplying.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
index e79b4174c1745..1792b241bd92a 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h
@@ -37,7 +37,6 @@ class InsertElementInst;
 class InsertValueInst;
 class Instruction;
 class LoopInfo;
-class MemorySSA;
 class OptimizationRemarkEmitter;
 class PHINode;
 class ScalarEvolution;
@@ -68,7 +67,6 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
   DominatorTree *DT = nullptr;
   AssumptionCache *AC = nullptr;
   DemandedBits *DB = nullptr;
-  MemorySSA *MSSA = nullptr; // nullable, currently preserved, but not used
   const DataLayout *DL = nullptr;
 
 public:
@@ -78,7 +76,7 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
   bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_,
                TargetLibraryInfo *TLI_, AAResults *AA_, LoopInfo *LI_,
                DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_,
-               MemorySSA *MSSA_, OptimizationRemarkEmitter *ORE_);
+               OptimizationRemarkEmitter *ORE_);
 
 private:
   /// Collect store and getelementptr instructions and organize them

diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 9ab31198adaab..16bcb613a6247 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -41,8 +41,6 @@
 #include "llvm/Analysis/LoopAccessAnalysis.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/MemoryLocation.h"
-#include "llvm/Analysis/MemorySSA.h"
-#include "llvm/Analysis/MemorySSAUpdater.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
@@ -168,10 +166,6 @@ static cl::opt<bool>
     ViewSLPTree("view-slp-tree", cl::Hidden,
                 cl::desc("Display the SLP trees with Graphviz"));
 
-static cl::opt<bool> EnableMSSAInSLPVectorizer(
-    "enable-mssa-in-slp-vectorizer", cl::Hidden, cl::init(false),
-    cl::desc("Enable MemorySSA for SLPVectorizer in new pass manager"));
-
 // Limit the number of alias checks. The limit is chosen so that
 // it has no negative effect on the llvm benchmarks.
 static const unsigned AliasedCheckLimit = 10;
@@ -846,10 +840,9 @@ class BoUpSLP {
   BoUpSLP(Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti,
           TargetLibraryInfo *TLi, AAResults *Aa, LoopInfo *Li,
           DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB,
-          MemorySSA *MSSA, const DataLayout *DL, OptimizationRemarkEmitter *ORE)
+          const DataLayout *DL, OptimizationRemarkEmitter *ORE)
       : BatchAA(*Aa), F(Func), SE(Se), TTI(Tti), TLI(TLi), LI(Li),
-        DT(Dt), AC(AC), DB(DB), MSSA(MSSA), DL(DL), ORE(ORE),
-        Builder(Se->getContext()) {
+        DT(Dt), AC(AC), DB(DB), DL(DL), ORE(ORE), Builder(Se->getContext()) {
     CodeMetrics::collectEphemeralValues(F, AC, EphValues);
     // Use the vector register size specified by the target unless overridden
     // by a command-line option.
@@ -3057,7 +3050,6 @@ class BoUpSLP {
   DominatorTree *DT;
   AssumptionCache *AC;
   DemandedBits *DB;
-  MemorySSA *MSSA;
   const DataLayout *DL;
   OptimizationRemarkEmitter *ORE;
 
@@ -3170,13 +3162,6 @@ template <> struct DOTGraphTraits<BoUpSLP *> : public DefaultDOTGraphTraits {
 } // end namespace llvm
 
 BoUpSLP::~BoUpSLP() {
-  if (MSSA) {
-    MemorySSAUpdater MSSAU(MSSA);
-    for (const auto &Pair : DeletedInstructions) {
-      if (auto *Access = MSSA->getMemoryAccess(Pair.first))
-        MSSAU.removeMemoryAccess(Access);
-    }
-  }
   for (const auto &Pair : DeletedInstructions) {
     // Replace operands of ignored instructions with Undefs in case if they were
     // marked for deletion.
@@ -6919,15 +6904,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
       auto *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace());
       Value *Ptr = Builder.CreateBitCast(LI->getOperand(0), PtrTy);
       LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlign());
-      if (MSSA) {
-        MemorySSAUpdater MSSAU(MSSA);
-        auto *Access = MSSA->getMemoryAccess(LI);
-        assert(Access);
-        MemoryUseOrDef *NewAccess =
-          MSSAU.createMemoryAccessBefore(V, Access->getDefiningAccess(),
-                                         Access);
-        MSSAU.insertUse(cast<MemoryUse>(NewAccess), true);
-      }
       Value *NewV = propagateMetadata(V, E->Scalars);
       ShuffleBuilder.addInversedMask(E->ReorderIndices);
       ShuffleBuilder.addMask(E->ReuseShuffleIndices);
@@ -7177,17 +7153,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
               commonAlignment(CommonAlignment, cast<LoadInst>(V)->getAlign());
         NewLI = Builder.CreateMaskedGather(VecTy, VecPtr, CommonAlignment);
       }
-
-      if (MSSA) {
-        MemorySSAUpdater MSSAU(MSSA);
-        auto *Access = MSSA->getMemoryAccess(LI);
-        assert(Access);
-        MemoryUseOrDef *NewAccess =
-          MSSAU.createMemoryAccessAfter(NewLI, Access->getDefiningAccess(),
-                                        Access);
-        MSSAU.insertUse(cast<MemoryUse>(NewAccess), true);
-      }
-
       Value *V = propagateMetadata(NewLI, E->Scalars);
 
       ShuffleBuilder.addInversedMask(E->ReorderIndices);
@@ -7213,16 +7178,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
       StoreInst *ST =
           Builder.CreateAlignedStore(VecValue, VecPtr, SI->getAlign());
 
-      if (MSSA) {
-        MemorySSAUpdater MSSAU(MSSA);
-        auto *Access = MSSA->getMemoryAccess(SI);
-        assert(Access);
-        MemoryUseOrDef *NewAccess =
-          MSSAU.createMemoryAccessAfter(ST, Access->getDefiningAccess(),
-                                        Access);
-        MSSAU.insertDef(cast<MemoryDef>(NewAccess), true);
-      }
-
       // The pointer operand uses an in-tree scalar, so add the new BitCast or
       // StoreInst to ExternalUses to make sure that an extract will be
       // generated in the future.
@@ -8205,15 +8160,6 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) {
   BS->initialFillReadyList(ReadyInsts);
 
   Instruction *LastScheduledInst = BS->ScheduleEnd;
-  MemoryAccess *MemInsertPt = nullptr;
-  if (MSSA) {
-    for (auto I = LastScheduledInst->getIterator(); I != BS->BB->end(); I++) {
-      if (auto *Access = MSSA->getMemoryAccess(&*I)) {
-        MemInsertPt = Access;
-        break;
-      }
-    }
-  }
 
   // Do the "real" scheduling.
   while (!ReadyInsts.empty()) {
@@ -8225,24 +8171,9 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) {
     for (ScheduleData *BundleMember = picked; BundleMember;
          BundleMember = BundleMember->NextInBundle) {
       Instruction *pickedInst = BundleMember->Inst;
-      if (pickedInst->getNextNode() != LastScheduledInst) {
+      if (pickedInst->getNextNode() != LastScheduledInst)
         pickedInst->moveBefore(LastScheduledInst);
-        if (MSSA) {
-          MemorySSAUpdater MSSAU(MSSA);
-          if (auto *Access = MSSA->getMemoryAccess(pickedInst)) {
-            if (MemInsertPt)
-              MSSAU.moveBefore(Access, cast<MemoryUseOrDef>(MemInsertPt));
-            else
-              MSSAU.moveToPlace(Access, BS->BB,
-                                MemorySSA::InsertionPlace::End);
-          }
-        }
-      }
-
       LastScheduledInst = pickedInst;
-      if (MSSA)
-        if (auto *Access = MSSA->getMemoryAccess(LastScheduledInst))
-          MemInsertPt = Access;
     }
 
     BS->schedule(picked, ReadyInsts);
@@ -8588,7 +8519,7 @@ struct SLPVectorizer : public FunctionPass {
     auto *DB = &getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
     auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
 
-    return Impl.runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, /*MSSA*/nullptr, ORE);
+    return Impl.runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, ORE);
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -8622,21 +8553,13 @@ PreservedAnalyses SLPVectorizerPass::run(Function &F, FunctionAnalysisManager &A
   auto *AC = &AM.getResult<AssumptionAnalysis>(F);
   auto *DB = &AM.getResult<DemandedBitsAnalysis>(F);
   auto *ORE = &AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
-  auto *MSSA = EnableMSSAInSLPVectorizer ?
-    &AM.getResult<MemorySSAAnalysis>(F).getMSSA() : (MemorySSA*)nullptr;
 
-  bool Changed = runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, MSSA, ORE);
+  bool Changed = runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, ORE);
   if (!Changed)
     return PreservedAnalyses::all();
 
   PreservedAnalyses PA;
   PA.preserveSet<CFGAnalyses>();
-  if (MSSA) {
-#ifdef EXPENSIVE_CHECKS
-    MSSA->verifyMemorySSA();
-#endif
-    PA.preserve<MemorySSAAnalysis>();
-  }
   return PA;
 }
 
@@ -8645,7 +8568,6 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
                                 TargetLibraryInfo *TLI_, AAResults *AA_,
                                 LoopInfo *LI_, DominatorTree *DT_,
                                 AssumptionCache *AC_, DemandedBits *DB_,
-                                MemorySSA *MSSA,
                                 OptimizationRemarkEmitter *ORE_) {
   if (!RunSLPVectorization)
     return false;
@@ -8679,7 +8601,7 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
 
   // Use the bottom up slp vectorizer to construct chains that start with
   // store instructions.
-  BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB, MSSA, DL, ORE_);
+  BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB, DL, ORE_);
 
   // A general note: the vectorizer must use BoUpSLP::eraseInstruction() to
   // delete instructions.


        


More information about the llvm-commits mailing list