Skip to content

Commit c39500f

Browse files
committed
Revert "[GVN] MemorySSA for GVN: add optional AllowMemorySSA"
This reverts commit eb63cd6. This changes the preservation behavior for MSSA when the new flag is not enabled.
1 parent 5a069ea commit c39500f

File tree

5 files changed

+16
-40
lines changed

5 files changed

+16
-40
lines changed

llvm/include/llvm/Transforms/Scalar/GVN.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct GVNOptions {
7777
std::optional<bool> AllowLoadInLoopPRE;
7878
std::optional<bool> AllowLoadPRESplitBackedge;
7979
std::optional<bool> AllowMemDep;
80-
std::optional<bool> AllowMemorySSA;
8180

8281
GVNOptions() = default;
8382

@@ -109,12 +108,6 @@ struct GVNOptions {
109108
AllowMemDep = MemDep;
110109
return *this;
111110
}
112-
113-
/// Enables or disables use of MemorySSA.
114-
GVNOptions &setMemorySSA(bool MemSSA) {
115-
AllowMemorySSA = MemSSA;
116-
return *this;
117-
}
118111
};
119112

120113
/// The core GVN pass object.
@@ -151,7 +144,6 @@ class GVNPass : public PassInfoMixin<GVNPass> {
151144
bool isLoadInLoopPREEnabled() const;
152145
bool isLoadPRESplitBackedgeEnabled() const;
153146
bool isMemDepEnabled() const;
154-
bool isMemorySSAEnabled() const;
155147

156148
/// This class holds the mapping between values and value numbers. It is used
157149
/// as an efficient mechanism to determine the expression-wise equivalence of
@@ -391,8 +383,9 @@ class GVNPass : public PassInfoMixin<GVNPass> {
391383
void assignBlockRPONumber(Function &F);
392384
};
393385

394-
/// Create a legacy GVN pass.
395-
FunctionPass *createGVNPass();
386+
/// Create a legacy GVN pass. This also allows parameterizing whether or not
387+
/// MemDep is enabled.
388+
FunctionPass *createGVNPass(bool NoMemDepAnalysis = false);
396389

397390
/// A simple and fast domtree-based GVN pass to hoist common expressions
398391
/// from sibling branches.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,6 @@ Expected<GVNOptions> parseGVNOptions(StringRef Params) {
10421042
Result.setLoadPRESplitBackedge(Enable);
10431043
} else if (ParamName == "memdep") {
10441044
Result.setMemDep(Enable);
1045-
} else if (ParamName == "memoryssa") {
1046-
Result.setMemorySSA(Enable);
10471045
} else {
10481046
return make_error<StringError>(
10491047
formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ FUNCTION_PASS_WITH_PARAMS(
526526
"gvn", "GVNPass", [](GVNOptions Opts) { return GVNPass(Opts); },
527527
parseGVNOptions,
528528
"no-pre;pre;no-load-pre;load-pre;no-split-backedge-load-pre;"
529-
"split-backedge-load-pre;no-memdep;memdep;no-memoryssa;memoryssa")
529+
"split-backedge-load-pre;no-memdep;memdep")
530530
FUNCTION_PASS_WITH_PARAMS(
531531
"hardware-loops", "HardwareLoopsPass",
532532
[](HardwareLoopOptions Opts) { return HardwareLoopsPass(Opts); },

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ static cl::opt<bool>
113113
GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
114114
cl::init(false));
115115
static cl::opt<bool> GVNEnableMemDep("enable-gvn-memdep", cl::init(true));
116-
static cl::opt<bool> GVNEnableMemorySSA("enable-gvn-memoryssa",
117-
cl::init(false));
118116

119117
static cl::opt<uint32_t> MaxNumDeps(
120118
"gvn-max-num-deps", cl::Hidden, cl::init(100),
@@ -822,10 +820,6 @@ bool GVNPass::isMemDepEnabled() const {
822820
return Options.AllowMemDep.value_or(GVNEnableMemDep);
823821
}
824822

825-
bool GVNPass::isMemorySSAEnabled() const {
826-
return Options.AllowMemorySSA.value_or(GVNEnableMemorySSA);
827-
}
828-
829823
PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
830824
// FIXME: The order of evaluation of these 'getResult' calls is very
831825
// significant! Re-ordering these variables will cause GVN when run alone to
@@ -838,10 +832,7 @@ PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
838832
auto *MemDep =
839833
isMemDepEnabled() ? &AM.getResult<MemoryDependenceAnalysis>(F) : nullptr;
840834
auto &LI = AM.getResult<LoopAnalysis>(F);
841-
auto *MSSA =
842-
isMemorySSAEnabled() ? &AM.getResult<MemorySSAAnalysis>(F) : nullptr;
843-
assert(!(MemDep && MSSA) &&
844-
"Should not use both MemDep and MemorySSA simultaneously!");
835+
auto *MSSA = AM.getCachedResult<MemorySSAAnalysis>(F);
845836
auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
846837
bool Changed = runImpl(F, AC, DT, TLI, AA, MemDep, LI, &ORE,
847838
MSSA ? &MSSA->getMSSA() : nullptr);
@@ -870,9 +861,7 @@ void GVNPass::printPipeline(
870861
OS << (*Options.AllowLoadPRESplitBackedge ? "" : "no-")
871862
<< "split-backedge-load-pre;";
872863
if (Options.AllowMemDep != std::nullopt)
873-
OS << (*Options.AllowMemDep ? "" : "no-") << "memdep;";
874-
if (Options.AllowMemorySSA != std::nullopt)
875-
OS << (*Options.AllowMemorySSA ? "" : "no-") << "memoryssa";
864+
OS << (*Options.AllowMemDep ? "" : "no-") << "memdep";
876865
OS << '>';
877866
}
878867

@@ -3304,18 +3293,16 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33043293
public:
33053294
static char ID; // Pass identification, replacement for typeid
33063295

3307-
explicit GVNLegacyPass(bool MemDepAnalysis = GVNEnableMemDep,
3308-
bool MemSSAAnalysis = GVNEnableMemorySSA)
3309-
: FunctionPass(ID), Impl(GVNOptions()
3310-
.setMemDep(MemDepAnalysis)
3311-
.setMemorySSA(MemSSAAnalysis)) {
3296+
explicit GVNLegacyPass(bool NoMemDepAnalysis = !GVNEnableMemDep)
3297+
: FunctionPass(ID), Impl(GVNOptions().setMemDep(!NoMemDepAnalysis)) {
33123298
initializeGVNLegacyPassPass(*PassRegistry::getPassRegistry());
33133299
}
33143300

33153301
bool runOnFunction(Function &F) override {
33163302
if (skipFunction(F))
33173303
return false;
33183304

3305+
auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
33193306
return Impl.runImpl(
33203307
F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F),
33213308
getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
@@ -3326,9 +3313,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33263313
: nullptr,
33273314
getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
33283315
&getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(),
3329-
Impl.isMemorySSAEnabled()
3330-
? &getAnalysis<MemorySSAWrapperPass>().getMSSA()
3331-
: nullptr);
3316+
MSSAWP ? &MSSAWP->getMSSA() : nullptr);
33323317
}
33333318

33343319
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -3344,8 +3329,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33443329
AU.addPreserved<TargetLibraryInfoWrapperPass>();
33453330
AU.addPreserved<LoopInfoWrapperPass>();
33463331
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
3347-
if (Impl.isMemorySSAEnabled())
3348-
AU.addRequired<MemorySSAWrapperPass>();
3332+
AU.addPreserved<MemorySSAWrapperPass>();
33493333
}
33503334

33513335
private:
@@ -3357,7 +3341,6 @@ char GVNLegacyPass::ID = 0;
33573341
INITIALIZE_PASS_BEGIN(GVNLegacyPass, "gvn", "Global Value Numbering", false, false)
33583342
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
33593343
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
3360-
INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
33613344
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
33623345
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
33633346
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
@@ -3366,4 +3349,6 @@ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
33663349
INITIALIZE_PASS_END(GVNLegacyPass, "gvn", "Global Value Numbering", false, false)
33673350

33683351
// The public interface to this file...
3369-
FunctionPass *llvm::createGVNPass() { return new GVNLegacyPass(); }
3352+
FunctionPass *llvm::createGVNPass(bool NoMemDepAnalysis) {
3353+
return new GVNLegacyPass(NoMemDepAnalysis);
3354+
}

llvm/test/Other/new-pm-print-pipeline.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop-unroll<>,loop-unroll<partial;peeling;runtime;upperbound;profile-peeling;full-unroll-max=5;O1>,loop-unroll<no-partial;no-peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=7;O1>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-10
3232
; CHECK-10: function(loop-unroll<O2>,loop-unroll<partial;peeling;runtime;upperbound;profile-peeling;full-unroll-max=5;O1>,loop-unroll<no-partial;no-peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=7;O1>)
3333

34-
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(gvn<>,gvn<pre;load-pre;split-backedge-load-pre;memdep;memoryssa>,gvn<no-pre;no-load-pre;no-split-backedge-load-pre;no-memdep;no-memoryssa>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-11
35-
; CHECK-11: function(gvn<>,gvn<pre;load-pre;split-backedge-load-pre;memdep;memoryssa>,gvn<no-pre;no-load-pre;no-split-backedge-load-pre;no-memdep;no-memoryssa>)
34+
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(gvn<>,gvn<pre;load-pre;split-backedge-load-pre;memdep>,gvn<no-pre;no-load-pre;no-split-backedge-load-pre;no-memdep>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-11
35+
; CHECK-11: function(gvn<>,gvn<pre;load-pre;split-backedge-load-pre;memdep>,gvn<no-pre;no-load-pre;no-split-backedge-load-pre;no-memdep>)
3636

3737
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(early-cse<>,early-cse<memssa>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-12
3838
; CHECK-12: function(early-cse<>,early-cse<memssa>)

0 commit comments

Comments
 (0)