Skip to content

Commit

Permalink
Revert "[GVN] MemorySSA for GVN: add optional AllowMemorySSA"
Browse files Browse the repository at this point in the history
This reverts commit eb63cd6.

This changes the preservation behavior for MSSA when the new flag
is not enabled.
  • Loading branch information
nikic committed Jan 10, 2025
1 parent 5a069ea commit c39500f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 40 deletions.
13 changes: 3 additions & 10 deletions llvm/include/llvm/Transforms/Scalar/GVN.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ struct GVNOptions {
std::optional<bool> AllowLoadInLoopPRE;
std::optional<bool> AllowLoadPRESplitBackedge;
std::optional<bool> AllowMemDep;
std::optional<bool> AllowMemorySSA;

GVNOptions() = default;

Expand Down Expand Up @@ -109,12 +108,6 @@ struct GVNOptions {
AllowMemDep = MemDep;
return *this;
}

/// Enables or disables use of MemorySSA.
GVNOptions &setMemorySSA(bool MemSSA) {
AllowMemorySSA = MemSSA;
return *this;
}
};

/// The core GVN pass object.
Expand Down Expand Up @@ -151,7 +144,6 @@ class GVNPass : public PassInfoMixin<GVNPass> {
bool isLoadInLoopPREEnabled() const;
bool isLoadPRESplitBackedgeEnabled() const;
bool isMemDepEnabled() const;
bool isMemorySSAEnabled() const;

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

/// Create a legacy GVN pass.
FunctionPass *createGVNPass();
/// Create a legacy GVN pass. This also allows parameterizing whether or not
/// MemDep is enabled.
FunctionPass *createGVNPass(bool NoMemDepAnalysis = false);

/// A simple and fast domtree-based GVN pass to hoist common expressions
/// from sibling branches.
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,6 @@ Expected<GVNOptions> parseGVNOptions(StringRef Params) {
Result.setLoadPRESplitBackedge(Enable);
} else if (ParamName == "memdep") {
Result.setMemDep(Enable);
} else if (ParamName == "memoryssa") {
Result.setMemorySSA(Enable);
} else {
return make_error<StringError>(
formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ FUNCTION_PASS_WITH_PARAMS(
"gvn", "GVNPass", [](GVNOptions Opts) { return GVNPass(Opts); },
parseGVNOptions,
"no-pre;pre;no-load-pre;load-pre;no-split-backedge-load-pre;"
"split-backedge-load-pre;no-memdep;memdep;no-memoryssa;memoryssa")
"split-backedge-load-pre;no-memdep;memdep")
FUNCTION_PASS_WITH_PARAMS(
"hardware-loops", "HardwareLoopsPass",
[](HardwareLoopOptions Opts) { return HardwareLoopsPass(Opts); },
Expand Down
35 changes: 10 additions & 25 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ static cl::opt<bool>
GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
cl::init(false));
static cl::opt<bool> GVNEnableMemDep("enable-gvn-memdep", cl::init(true));
static cl::opt<bool> GVNEnableMemorySSA("enable-gvn-memoryssa",
cl::init(false));

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

bool GVNPass::isMemorySSAEnabled() const {
return Options.AllowMemorySSA.value_or(GVNEnableMemorySSA);
}

PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
// FIXME: The order of evaluation of these 'getResult' calls is very
// significant! Re-ordering these variables will cause GVN when run alone to
Expand All @@ -838,10 +832,7 @@ PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
auto *MemDep =
isMemDepEnabled() ? &AM.getResult<MemoryDependenceAnalysis>(F) : nullptr;
auto &LI = AM.getResult<LoopAnalysis>(F);
auto *MSSA =
isMemorySSAEnabled() ? &AM.getResult<MemorySSAAnalysis>(F) : nullptr;
assert(!(MemDep && MSSA) &&
"Should not use both MemDep and MemorySSA simultaneously!");
auto *MSSA = AM.getCachedResult<MemorySSAAnalysis>(F);
auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
bool Changed = runImpl(F, AC, DT, TLI, AA, MemDep, LI, &ORE,
MSSA ? &MSSA->getMSSA() : nullptr);
Expand Down Expand Up @@ -870,9 +861,7 @@ void GVNPass::printPipeline(
OS << (*Options.AllowLoadPRESplitBackedge ? "" : "no-")
<< "split-backedge-load-pre;";
if (Options.AllowMemDep != std::nullopt)
OS << (*Options.AllowMemDep ? "" : "no-") << "memdep;";
if (Options.AllowMemorySSA != std::nullopt)
OS << (*Options.AllowMemorySSA ? "" : "no-") << "memoryssa";
OS << (*Options.AllowMemDep ? "" : "no-") << "memdep";
OS << '>';
}

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

explicit GVNLegacyPass(bool MemDepAnalysis = GVNEnableMemDep,
bool MemSSAAnalysis = GVNEnableMemorySSA)
: FunctionPass(ID), Impl(GVNOptions()
.setMemDep(MemDepAnalysis)
.setMemorySSA(MemSSAAnalysis)) {
explicit GVNLegacyPass(bool NoMemDepAnalysis = !GVNEnableMemDep)
: FunctionPass(ID), Impl(GVNOptions().setMemDep(!NoMemDepAnalysis)) {
initializeGVNLegacyPassPass(*PassRegistry::getPassRegistry());
}

bool runOnFunction(Function &F) override {
if (skipFunction(F))
return false;

auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
return Impl.runImpl(
F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F),
getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
Expand All @@ -3326,9 +3313,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
: nullptr,
getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
&getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(),
Impl.isMemorySSAEnabled()
? &getAnalysis<MemorySSAWrapperPass>().getMSSA()
: nullptr);
MSSAWP ? &MSSAWP->getMSSA() : nullptr);
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
Expand All @@ -3344,8 +3329,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
AU.addPreserved<TargetLibraryInfoWrapperPass>();
AU.addPreserved<LoopInfoWrapperPass>();
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
if (Impl.isMemorySSAEnabled())
AU.addRequired<MemorySSAWrapperPass>();
AU.addPreserved<MemorySSAWrapperPass>();
}

private:
Expand All @@ -3357,7 +3341,6 @@ char GVNLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(GVNLegacyPass, "gvn", "Global Value Numbering", false, false)
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
Expand All @@ -3366,4 +3349,6 @@ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
INITIALIZE_PASS_END(GVNLegacyPass, "gvn", "Global Value Numbering", false, false)

// The public interface to this file...
FunctionPass *llvm::createGVNPass() { return new GVNLegacyPass(); }
FunctionPass *llvm::createGVNPass(bool NoMemDepAnalysis) {
return new GVNLegacyPass(NoMemDepAnalysis);
}
4 changes: 2 additions & 2 deletions llvm/test/Other/new-pm-print-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
; 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
; 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>)

; 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
; 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>)
; 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
; 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>)

; 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
; CHECK-12: function(early-cse<>,early-cse<memssa>)
Expand Down

0 comments on commit c39500f

Please sign in to comment.