Skip to content

Commit 8f108c3

Browse files
committed
Revert "[SLP] Optionally preserve MemorySSA"
This reverts commit 1cfa986. See llvm/llvm-project#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.
1 parent 078b546 commit 8f108c3

File tree

2 files changed

+7
-87
lines changed

2 files changed

+7
-87
lines changed

llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class InsertElementInst;
3737
class InsertValueInst;
3838
class Instruction;
3939
class LoopInfo;
40-
class MemorySSA;
4140
class OptimizationRemarkEmitter;
4241
class PHINode;
4342
class ScalarEvolution;
@@ -68,7 +67,6 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
6867
DominatorTree *DT = nullptr;
6968
AssumptionCache *AC = nullptr;
7069
DemandedBits *DB = nullptr;
71-
MemorySSA *MSSA = nullptr; // nullable, currently preserved, but not used
7270
const DataLayout *DL = nullptr;
7371

7472
public:
@@ -78,7 +76,7 @@ struct SLPVectorizerPass : public PassInfoMixin<SLPVectorizerPass> {
7876
bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_,
7977
TargetLibraryInfo *TLI_, AAResults *AA_, LoopInfo *LI_,
8078
DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_,
81-
MemorySSA *MSSA_, OptimizationRemarkEmitter *ORE_);
79+
OptimizationRemarkEmitter *ORE_);
8280

8381
private:
8482
/// Collect store and getelementptr instructions and organize them

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include "llvm/Analysis/LoopAccessAnalysis.h"
4242
#include "llvm/Analysis/LoopInfo.h"
4343
#include "llvm/Analysis/MemoryLocation.h"
44-
#include "llvm/Analysis/MemorySSA.h"
45-
#include "llvm/Analysis/MemorySSAUpdater.h"
4644
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
4745
#include "llvm/Analysis/ScalarEvolution.h"
4846
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
@@ -168,10 +166,6 @@ static cl::opt<bool>
168166
ViewSLPTree("view-slp-tree", cl::Hidden,
169167
cl::desc("Display the SLP trees with Graphviz"));
170168

171-
static cl::opt<bool> EnableMSSAInSLPVectorizer(
172-
"enable-mssa-in-slp-vectorizer", cl::Hidden, cl::init(false),
173-
cl::desc("Enable MemorySSA for SLPVectorizer in new pass manager"));
174-
175169
// Limit the number of alias checks. The limit is chosen so that
176170
// it has no negative effect on the llvm benchmarks.
177171
static const unsigned AliasedCheckLimit = 10;
@@ -846,10 +840,9 @@ class BoUpSLP {
846840
BoUpSLP(Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti,
847841
TargetLibraryInfo *TLi, AAResults *Aa, LoopInfo *Li,
848842
DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB,
849-
MemorySSA *MSSA, const DataLayout *DL, OptimizationRemarkEmitter *ORE)
843+
const DataLayout *DL, OptimizationRemarkEmitter *ORE)
850844
: BatchAA(*Aa), F(Func), SE(Se), TTI(Tti), TLI(TLi), LI(Li),
851-
DT(Dt), AC(AC), DB(DB), MSSA(MSSA), DL(DL), ORE(ORE),
852-
Builder(Se->getContext()) {
845+
DT(Dt), AC(AC), DB(DB), DL(DL), ORE(ORE), Builder(Se->getContext()) {
853846
CodeMetrics::collectEphemeralValues(F, AC, EphValues);
854847
// Use the vector register size specified by the target unless overridden
855848
// by a command-line option.
@@ -3057,7 +3050,6 @@ class BoUpSLP {
30573050
DominatorTree *DT;
30583051
AssumptionCache *AC;
30593052
DemandedBits *DB;
3060-
MemorySSA *MSSA;
30613053
const DataLayout *DL;
30623054
OptimizationRemarkEmitter *ORE;
30633055

@@ -3170,13 +3162,6 @@ template <> struct DOTGraphTraits<BoUpSLP *> : public DefaultDOTGraphTraits {
31703162
} // end namespace llvm
31713163

31723164
BoUpSLP::~BoUpSLP() {
3173-
if (MSSA) {
3174-
MemorySSAUpdater MSSAU(MSSA);
3175-
for (const auto &Pair : DeletedInstructions) {
3176-
if (auto *Access = MSSA->getMemoryAccess(Pair.first))
3177-
MSSAU.removeMemoryAccess(Access);
3178-
}
3179-
}
31803165
for (const auto &Pair : DeletedInstructions) {
31813166
// Replace operands of ignored instructions with Undefs in case if they were
31823167
// marked for deletion.
@@ -6919,15 +6904,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
69196904
auto *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace());
69206905
Value *Ptr = Builder.CreateBitCast(LI->getOperand(0), PtrTy);
69216906
LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlign());
6922-
if (MSSA) {
6923-
MemorySSAUpdater MSSAU(MSSA);
6924-
auto *Access = MSSA->getMemoryAccess(LI);
6925-
assert(Access);
6926-
MemoryUseOrDef *NewAccess =
6927-
MSSAU.createMemoryAccessBefore(V, Access->getDefiningAccess(),
6928-
Access);
6929-
MSSAU.insertUse(cast<MemoryUse>(NewAccess), true);
6930-
}
69316907
Value *NewV = propagateMetadata(V, E->Scalars);
69326908
ShuffleBuilder.addInversedMask(E->ReorderIndices);
69336909
ShuffleBuilder.addMask(E->ReuseShuffleIndices);
@@ -7177,17 +7153,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
71777153
commonAlignment(CommonAlignment, cast<LoadInst>(V)->getAlign());
71787154
NewLI = Builder.CreateMaskedGather(VecTy, VecPtr, CommonAlignment);
71797155
}
7180-
7181-
if (MSSA) {
7182-
MemorySSAUpdater MSSAU(MSSA);
7183-
auto *Access = MSSA->getMemoryAccess(LI);
7184-
assert(Access);
7185-
MemoryUseOrDef *NewAccess =
7186-
MSSAU.createMemoryAccessAfter(NewLI, Access->getDefiningAccess(),
7187-
Access);
7188-
MSSAU.insertUse(cast<MemoryUse>(NewAccess), true);
7189-
}
7190-
71917156
Value *V = propagateMetadata(NewLI, E->Scalars);
71927157

71937158
ShuffleBuilder.addInversedMask(E->ReorderIndices);
@@ -7213,16 +7178,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
72137178
StoreInst *ST =
72147179
Builder.CreateAlignedStore(VecValue, VecPtr, SI->getAlign());
72157180

7216-
if (MSSA) {
7217-
MemorySSAUpdater MSSAU(MSSA);
7218-
auto *Access = MSSA->getMemoryAccess(SI);
7219-
assert(Access);
7220-
MemoryUseOrDef *NewAccess =
7221-
MSSAU.createMemoryAccessAfter(ST, Access->getDefiningAccess(),
7222-
Access);
7223-
MSSAU.insertDef(cast<MemoryDef>(NewAccess), true);
7224-
}
7225-
72267181
// The pointer operand uses an in-tree scalar, so add the new BitCast or
72277182
// StoreInst to ExternalUses to make sure that an extract will be
72287183
// generated in the future.
@@ -8205,15 +8160,6 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) {
82058160
BS->initialFillReadyList(ReadyInsts);
82068161

82078162
Instruction *LastScheduledInst = BS->ScheduleEnd;
8208-
MemoryAccess *MemInsertPt = nullptr;
8209-
if (MSSA) {
8210-
for (auto I = LastScheduledInst->getIterator(); I != BS->BB->end(); I++) {
8211-
if (auto *Access = MSSA->getMemoryAccess(&*I)) {
8212-
MemInsertPt = Access;
8213-
break;
8214-
}
8215-
}
8216-
}
82178163

82188164
// Do the "real" scheduling.
82198165
while (!ReadyInsts.empty()) {
@@ -8225,24 +8171,9 @@ void BoUpSLP::scheduleBlock(BlockScheduling *BS) {
82258171
for (ScheduleData *BundleMember = picked; BundleMember;
82268172
BundleMember = BundleMember->NextInBundle) {
82278173
Instruction *pickedInst = BundleMember->Inst;
8228-
if (pickedInst->getNextNode() != LastScheduledInst) {
8174+
if (pickedInst->getNextNode() != LastScheduledInst)
82298175
pickedInst->moveBefore(LastScheduledInst);
8230-
if (MSSA) {
8231-
MemorySSAUpdater MSSAU(MSSA);
8232-
if (auto *Access = MSSA->getMemoryAccess(pickedInst)) {
8233-
if (MemInsertPt)
8234-
MSSAU.moveBefore(Access, cast<MemoryUseOrDef>(MemInsertPt));
8235-
else
8236-
MSSAU.moveToPlace(Access, BS->BB,
8237-
MemorySSA::InsertionPlace::End);
8238-
}
8239-
}
8240-
}
8241-
82428176
LastScheduledInst = pickedInst;
8243-
if (MSSA)
8244-
if (auto *Access = MSSA->getMemoryAccess(LastScheduledInst))
8245-
MemInsertPt = Access;
82468177
}
82478178

82488179
BS->schedule(picked, ReadyInsts);
@@ -8588,7 +8519,7 @@ struct SLPVectorizer : public FunctionPass {
85888519
auto *DB = &getAnalysis<DemandedBitsWrapperPass>().getDemandedBits();
85898520
auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
85908521

8591-
return Impl.runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, /*MSSA*/nullptr, ORE);
8522+
return Impl.runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, ORE);
85928523
}
85938524

85948525
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -8622,21 +8553,13 @@ PreservedAnalyses SLPVectorizerPass::run(Function &F, FunctionAnalysisManager &A
86228553
auto *AC = &AM.getResult<AssumptionAnalysis>(F);
86238554
auto *DB = &AM.getResult<DemandedBitsAnalysis>(F);
86248555
auto *ORE = &AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
8625-
auto *MSSA = EnableMSSAInSLPVectorizer ?
8626-
&AM.getResult<MemorySSAAnalysis>(F).getMSSA() : (MemorySSA*)nullptr;
86278556

8628-
bool Changed = runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, MSSA, ORE);
8557+
bool Changed = runImpl(F, SE, TTI, TLI, AA, LI, DT, AC, DB, ORE);
86298558
if (!Changed)
86308559
return PreservedAnalyses::all();
86318560

86328561
PreservedAnalyses PA;
86338562
PA.preserveSet<CFGAnalyses>();
8634-
if (MSSA) {
8635-
#ifdef EXPENSIVE_CHECKS
8636-
MSSA->verifyMemorySSA();
8637-
#endif
8638-
PA.preserve<MemorySSAAnalysis>();
8639-
}
86408563
return PA;
86418564
}
86428565

@@ -8645,7 +8568,6 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
86458568
TargetLibraryInfo *TLI_, AAResults *AA_,
86468569
LoopInfo *LI_, DominatorTree *DT_,
86478570
AssumptionCache *AC_, DemandedBits *DB_,
8648-
MemorySSA *MSSA,
86498571
OptimizationRemarkEmitter *ORE_) {
86508572
if (!RunSLPVectorization)
86518573
return false;
@@ -8679,7 +8601,7 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
86798601

86808602
// Use the bottom up slp vectorizer to construct chains that start with
86818603
// store instructions.
8682-
BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB, MSSA, DL, ORE_);
8604+
BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB, DL, ORE_);
86838605

86848606
// A general note: the vectorizer must use BoUpSLP::eraseInstruction() to
86858607
// delete instructions.

0 commit comments

Comments
 (0)