mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[MemDep] Use PhiValuesAnalysis to improve alias analysis results
This is being done in order to make GVN able to better optimize certain inputs. MemDep doesn't use PhiValues directly, but does need to notifiy it when things get invalidated. Differential Revision: https://reviews.llvm.org/D48489 llvm-svn: 338384
This commit is contained in:
parent
e66d9fb924
commit
96b2d39585
@ -44,6 +44,7 @@ class Instruction;
|
||||
class LoadInst;
|
||||
class PHITransAddr;
|
||||
class TargetLibraryInfo;
|
||||
class PhiValues;
|
||||
class Value;
|
||||
|
||||
/// A memory dependence query can return one of three different answers.
|
||||
@ -360,13 +361,14 @@ private:
|
||||
AssumptionCache ∾
|
||||
const TargetLibraryInfo &TLI;
|
||||
DominatorTree &DT;
|
||||
PhiValues &PV;
|
||||
PredIteratorCache PredCache;
|
||||
|
||||
public:
|
||||
MemoryDependenceResults(AliasAnalysis &AA, AssumptionCache &AC,
|
||||
const TargetLibraryInfo &TLI,
|
||||
DominatorTree &DT)
|
||||
: AA(AA), AC(AC), TLI(TLI), DT(DT) {}
|
||||
DominatorTree &DT, PhiValues &PV)
|
||||
: AA(AA), AC(AC), TLI(TLI), DT(DT), PV(PV) {}
|
||||
|
||||
/// Handle invalidation in the new PM.
|
||||
bool invalidate(Function &F, const PreservedAnalyses &PA,
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "llvm/Analysis/MemoryLocation.h"
|
||||
#include "llvm/Analysis/OrderedBasicBlock.h"
|
||||
#include "llvm/Analysis/PHITransAddr.h"
|
||||
#include "llvm/Analysis/PhiValues.h"
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/IR/Attributes.h"
|
||||
@ -1513,6 +1514,8 @@ void MemoryDependenceResults::invalidateCachedPointerInfo(Value *Ptr) {
|
||||
RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false));
|
||||
// Flush load info for the pointer.
|
||||
RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true));
|
||||
// Invalidate phis that use the pointer.
|
||||
PV.invalidateValue(Ptr);
|
||||
}
|
||||
|
||||
void MemoryDependenceResults::invalidateCachedPredecessors() {
|
||||
@ -1671,6 +1674,9 @@ void MemoryDependenceResults::removeInstruction(Instruction *RemInst) {
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate phis that use the removed instruction.
|
||||
PV.invalidateValue(RemInst);
|
||||
|
||||
assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?");
|
||||
LLVM_DEBUG(verifyRemoved(RemInst));
|
||||
}
|
||||
@ -1730,7 +1736,8 @@ MemoryDependenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
|
||||
auto &AC = AM.getResult<AssumptionAnalysis>(F);
|
||||
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
|
||||
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
||||
return MemoryDependenceResults(AA, AC, TLI, DT);
|
||||
auto &PV = AM.getResult<PhiValuesAnalysis>(F);
|
||||
return MemoryDependenceResults(AA, AC, TLI, DT, PV);
|
||||
}
|
||||
|
||||
char MemoryDependenceWrapperPass::ID = 0;
|
||||
@ -1741,6 +1748,7 @@ INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
||||
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(PhiValuesWrapperPass)
|
||||
INITIALIZE_PASS_END(MemoryDependenceWrapperPass, "memdep",
|
||||
"Memory Dependence Analysis", false, true)
|
||||
|
||||
@ -1758,6 +1766,7 @@ void MemoryDependenceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.setPreservesAll();
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<PhiValuesWrapperPass>();
|
||||
AU.addRequiredTransitive<AAResultsWrapperPass>();
|
||||
AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
|
||||
}
|
||||
@ -1773,7 +1782,8 @@ bool MemoryDependenceResults::invalidate(Function &F, const PreservedAnalyses &P
|
||||
// Check whether the analyses we depend on became invalid for any reason.
|
||||
if (Inv.invalidate<AAManager>(F, PA) ||
|
||||
Inv.invalidate<AssumptionAnalysis>(F, PA) ||
|
||||
Inv.invalidate<DominatorTreeAnalysis>(F, PA))
|
||||
Inv.invalidate<DominatorTreeAnalysis>(F, PA) ||
|
||||
Inv.invalidate<PhiValuesAnalysis>(F, PA))
|
||||
return true;
|
||||
|
||||
// Otherwise this analysis result remains valid.
|
||||
@ -1789,6 +1799,7 @@ bool MemoryDependenceWrapperPass::runOnFunction(Function &F) {
|
||||
auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
|
||||
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
MemDep.emplace(AA, AC, TLI, DT);
|
||||
auto &PV = getAnalysis<PhiValuesWrapperPass>().getResult();
|
||||
MemDep.emplace(AA, AC, TLI, DT, PV);
|
||||
return false;
|
||||
}
|
||||
|
@ -170,17 +170,22 @@
|
||||
; CHECK-Os-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-Os-NEXT: Running pass: GVN
|
||||
; CHECK-Os-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-Os-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-Oz-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-Oz-NEXT: Running pass: GVN
|
||||
; CHECK-Oz-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-Oz-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O2-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-O2-NEXT: Running pass: GVN
|
||||
; CHECK-O2-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O2-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O3-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-O3-NEXT: Running pass: GVN
|
||||
; CHECK-O3-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O3-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O-NEXT: Running pass: MemCpyOptPass
|
||||
; CHECK-O1-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O1-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O-NEXT: Running pass: SCCPPass
|
||||
; CHECK-O-NEXT: Running pass: BDCEPass
|
||||
; CHECK-O-NEXT: Running analysis: DemandedBitsAnalysis
|
||||
|
@ -81,6 +81,7 @@
|
||||
; CHECK-O2-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor<{{.*}}PostOrderFunctionAttrsPass>
|
||||
; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
|
||||
; CHECK-O2-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O2-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O2-NEXT: Running analysis: DemandedBitsAnalysis
|
||||
; CHECK-O2-NEXT: Running pass: CrossDSOCFIPass
|
||||
; CHECK-O2-NEXT: Running pass: LowerTypeTestsPass
|
||||
|
@ -152,17 +152,22 @@
|
||||
; CHECK-Os-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-Os-NEXT: Running pass: GVN
|
||||
; CHECK-Os-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-Os-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-Oz-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-Oz-NEXT: Running pass: GVN
|
||||
; CHECK-Oz-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-Oz-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O2-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-O2-NEXT: Running pass: GVN
|
||||
; CHECK-O2-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O2-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O3-NEXT: Running pass: MergedLoadStoreMotionPass
|
||||
; CHECK-O3-NEXT: Running pass: GVN
|
||||
; CHECK-O3-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O3-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O-NEXT: Running pass: MemCpyOptPass
|
||||
; CHECK-O1-NEXT: Running analysis: MemoryDependenceAnalysis
|
||||
; CHECK-O1-NEXT: Running analysis: PhiValuesAnalysis
|
||||
; CHECK-O-NEXT: Running pass: SCCPPass
|
||||
; CHECK-O-NEXT: Running pass: BDCEPass
|
||||
; CHECK-O-NEXT: Running analysis: DemandedBitsAnalysis
|
||||
|
@ -121,6 +121,7 @@
|
||||
; CHECK-NEXT: Delete dead loops
|
||||
; CHECK-NEXT: Unroll loops
|
||||
; CHECK-NEXT: MergedLoadStoreMotion
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -128,6 +129,7 @@
|
||||
; CHECK-NEXT: Lazy Block Frequency Analysis
|
||||
; CHECK-NEXT: Optimization Remark Emitter
|
||||
; CHECK-NEXT: Global Value Numbering
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -147,6 +149,7 @@
|
||||
; CHECK-NEXT: Value Propagation
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
; CHECK-NEXT: Dead Store Elimination
|
||||
; CHECK-NEXT: Natural Loop Information
|
||||
|
@ -125,6 +125,7 @@
|
||||
; CHECK-NEXT: Delete dead loops
|
||||
; CHECK-NEXT: Unroll loops
|
||||
; CHECK-NEXT: MergedLoadStoreMotion
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -132,6 +133,7 @@
|
||||
; CHECK-NEXT: Lazy Block Frequency Analysis
|
||||
; CHECK-NEXT: Optimization Remark Emitter
|
||||
; CHECK-NEXT: Global Value Numbering
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -151,6 +153,7 @@
|
||||
; CHECK-NEXT: Value Propagation
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
; CHECK-NEXT: Dead Store Elimination
|
||||
; CHECK-NEXT: Natural Loop Information
|
||||
|
@ -108,6 +108,7 @@
|
||||
; CHECK-NEXT: Delete dead loops
|
||||
; CHECK-NEXT: Unroll loops
|
||||
; CHECK-NEXT: MergedLoadStoreMotion
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -115,6 +116,7 @@
|
||||
; CHECK-NEXT: Lazy Block Frequency Analysis
|
||||
; CHECK-NEXT: Optimization Remark Emitter
|
||||
; CHECK-NEXT: Global Value Numbering
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
@ -134,6 +136,7 @@
|
||||
; CHECK-NEXT: Value Propagation
|
||||
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
|
||||
; CHECK-NEXT: Function Alias Analysis Results
|
||||
; CHECK-NEXT: Phi Values Analysis
|
||||
; CHECK-NEXT: Memory Dependence Analysis
|
||||
; CHECK-NEXT: Dead Store Elimination
|
||||
; CHECK-NEXT: Natural Loop Information
|
||||
|
@ -63,10 +63,12 @@ preheader:
|
||||
%cmp = icmp slt i32 1, %h
|
||||
br i1 %cmp, label %body, label %exit
|
||||
|
||||
; Alias analysis currently can't figure out %width doesn't alias %s, so just
|
||||
; check that the redundant load has been removed.
|
||||
; CHECK-LABEL: preheader.body_crit_edge:
|
||||
; CHECK: load i32, i32* %width, align 8
|
||||
|
||||
; CHECK-LABEL: body:
|
||||
; CHECK-NOT: load i32*, i32** %start, align 8
|
||||
; CHECK-NOT: load i32, i32* %width, align 8
|
||||
body:
|
||||
%j = phi i32 [ 0, %preheader ], [ %j.next, %body ]
|
||||
%s = load i32*, i32** %start, align 8
|
||||
|
Loading…
x
Reference in New Issue
Block a user