1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Revert "[MemCpyOpt] Enable memcpy optimizations unconditionally."

This reverts commit 2c98298a7559dfe4a264ef1adaad0921526768cc which breaks
sanitizers.
This commit is contained in:
Artem Belevich 2021-07-19 14:27:41 -07:00
parent 0c7127a873
commit 33f436abed
2 changed files with 22 additions and 6 deletions

View File

@ -41,6 +41,7 @@ class Value;
class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
MemoryDependenceResults *MD = nullptr;
TargetLibraryInfo *TLI = nullptr;
AAResults *AA = nullptr;
AssumptionCache *AC = nullptr;
DominatorTree *DT = nullptr;
@ -53,8 +54,9 @@ public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
// Glue for the old PM.
bool runImpl(Function &F, MemoryDependenceResults *MD, AAResults *AA,
AssumptionCache *AC, DominatorTree *DT, MemorySSA *MSSA);
bool runImpl(Function &F, MemoryDependenceResults *MD, TargetLibraryInfo *TLI,
AAResults *AA, AssumptionCache *AC, DominatorTree *DT,
MemorySSA *MSSA);
private:
// Helper functions

View File

@ -26,6 +26,7 @@
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
@ -280,6 +281,7 @@ private:
AU.addRequired<DominatorTreeWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
AU.addRequired<TargetLibraryInfoWrapperPass>();
if (!EnableMemorySSA)
AU.addRequired<MemoryDependenceWrapperPass>();
AU.addPreserved<MemoryDependenceWrapperPass>();
@ -1546,6 +1548,9 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
/// Transforms memmove calls to memcpy calls when the src/dst are guaranteed
/// not to alias.
bool MemCpyOptPass::processMemMove(MemMoveInst *M) {
if (!TLI->has(LibFunc_memmove))
return false;
// See if the pointers alias.
if (!AA->isNoAlias(MemoryLocation::getForDest(M),
MemoryLocation::getForSource(M)))
@ -1715,6 +1720,7 @@ bool MemCpyOptPass::iterateOnFunction(Function &F) {
PreservedAnalyses MemCpyOptPass::run(Function &F, FunctionAnalysisManager &AM) {
auto *MD = !EnableMemorySSA ? &AM.getResult<MemoryDependenceAnalysis>(F)
: AM.getCachedResult<MemoryDependenceAnalysis>(F);
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
auto *AA = &AM.getResult<AAManager>(F);
auto *AC = &AM.getResult<AssumptionAnalysis>(F);
auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
@ -1722,7 +1728,7 @@ PreservedAnalyses MemCpyOptPass::run(Function &F, FunctionAnalysisManager &AM) {
: AM.getCachedResult<MemorySSAAnalysis>(F);
bool MadeChange =
runImpl(F, MD, AA, AC, DT, MSSA ? &MSSA->getMSSA() : nullptr);
runImpl(F, MD, &TLI, AA, AC, DT, MSSA ? &MSSA->getMSSA() : nullptr);
if (!MadeChange)
return PreservedAnalyses::all();
@ -1736,16 +1742,23 @@ PreservedAnalyses MemCpyOptPass::run(Function &F, FunctionAnalysisManager &AM) {
}
bool MemCpyOptPass::runImpl(Function &F, MemoryDependenceResults *MD_,
AliasAnalysis *AA_, AssumptionCache *AC_,
DominatorTree *DT_, MemorySSA *MSSA_) {
TargetLibraryInfo *TLI_, AliasAnalysis *AA_,
AssumptionCache *AC_, DominatorTree *DT_,
MemorySSA *MSSA_) {
bool MadeChange = false;
MD = MD_;
TLI = TLI_;
AA = AA_;
AC = AC_;
DT = DT_;
MSSA = MSSA_;
MemorySSAUpdater MSSAU_(MSSA_);
MSSAU = MSSA_ ? &MSSAU_ : nullptr;
// If we don't have at least memset and memcpy, there is little point of doing
// anything here. These are required by a freestanding implementation, so if
// even they are disabled, there is no point in trying hard.
if (!TLI->has(LibFunc_memset) || !TLI->has(LibFunc_memcpy))
return false;
while (true) {
if (!iterateOnFunction(F))
@ -1768,6 +1781,7 @@ bool MemCpyOptLegacyPass::runOnFunction(Function &F) {
auto *MDWP = !EnableMemorySSA
? &getAnalysis<MemoryDependenceWrapperPass>()
: getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
auto *TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
auto *AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
@ -1775,6 +1789,6 @@ bool MemCpyOptLegacyPass::runOnFunction(Function &F) {
? &getAnalysis<MemorySSAWrapperPass>()
: getAnalysisIfAvailable<MemorySSAWrapperPass>();
return Impl.runImpl(F, MDWP ? &MDWP->getMemDep() : nullptr, AA, AC, DT,
return Impl.runImpl(F, MDWP ? & MDWP->getMemDep() : nullptr, TLI, AA, AC, DT,
MSSAWP ? &MSSAWP->getMSSA() : nullptr);
}