Index: include/llvm/Analysis/MemoryDependenceAnalysis.h =================================================================== --- include/llvm/Analysis/MemoryDependenceAnalysis.h +++ include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -44,6 +44,7 @@ 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 @@ AssumptionCache &AC; 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, Index: lib/Analysis/MemoryDependenceAnalysis.cpp =================================================================== --- lib/Analysis/MemoryDependenceAnalysis.cpp +++ lib/Analysis/MemoryDependenceAnalysis.cpp @@ -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 @@ 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 @@ } } + // 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 @@ auto &AC = AM.getResult(F); auto &TLI = AM.getResult(F); auto &DT = AM.getResult(F); - return MemoryDependenceResults(AA, AC, TLI, DT); + auto &PV = AM.getResult(F); + return MemoryDependenceResults(AA, AC, TLI, DT, PV); } char MemoryDependenceWrapperPass::ID = 0; @@ -1741,6 +1748,7 @@ 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 @@ AU.setPreservesAll(); AU.addRequired(); AU.addRequired(); + AU.addRequired(); AU.addRequiredTransitive(); AU.addRequiredTransitive(); } @@ -1773,7 +1782,8 @@ // Check whether the analyses we depend on became invalid for any reason. if (Inv.invalidate(F, PA) || Inv.invalidate(F, PA) || - Inv.invalidate(F, PA)) + Inv.invalidate(F, PA) || + Inv.invalidate(F, PA)) return true; // Otherwise this analysis result remains valid. @@ -1789,6 +1799,7 @@ auto &AC = getAnalysis().getAssumptionCache(F); auto &TLI = getAnalysis().getTLI(); auto &DT = getAnalysis().getDomTree(); - MemDep.emplace(AA, AC, TLI, DT); + auto &PV = getAnalysis().getResult(); + MemDep.emplace(AA, AC, TLI, DT, PV); return false; } Index: test/Other/new-pm-defaults.ll =================================================================== --- test/Other/new-pm-defaults.ll +++ test/Other/new-pm-defaults.ll @@ -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 Index: test/Other/new-pm-lto-defaults.ll =================================================================== --- test/Other/new-pm-lto-defaults.ll +++ test/Other/new-pm-lto-defaults.ll @@ -80,6 +80,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: ModuleToFunctionPassAdaptor<{{.*}}SimplifyCFGPass> Index: test/Other/new-pm-thinlto-defaults.ll =================================================================== --- test/Other/new-pm-thinlto-defaults.ll +++ test/Other/new-pm-thinlto-defaults.ll @@ -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 Index: test/Other/opt-O2-pipeline.ll =================================================================== --- test/Other/opt-O2-pipeline.ll +++ test/Other/opt-O2-pipeline.ll @@ -122,6 +122,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 @@ -129,6 +130,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 @@ -148,6 +150,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 Index: test/Other/opt-O3-pipeline.ll =================================================================== --- test/Other/opt-O3-pipeline.ll +++ test/Other/opt-O3-pipeline.ll @@ -126,6 +126,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 @@ -133,6 +134,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 @@ -152,6 +154,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 Index: test/Other/opt-Os-pipeline.ll =================================================================== --- test/Other/opt-Os-pipeline.ll +++ test/Other/opt-Os-pipeline.ll @@ -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 Index: test/Transforms/GVN/PRE/pre-after-rle.ll =================================================================== --- test/Transforms/GVN/PRE/pre-after-rle.ll +++ test/Transforms/GVN/PRE/pre-after-rle.ll @@ -63,10 +63,12 @@ %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