diff options
author | Nikita Popov <npopov@redhat.com> | 2022-12-09 15:29:35 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-12-12 09:47:30 +0100 |
commit | 243acd5dcbc637e477062877185ad76d8ff63d9d (patch) | |
tree | 01c4556875b8d8cf63a0a8f90b3448d3384afc69 /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 2f8cdea36d97b78ebc7e6f8d79ec9d69a4c503aa (diff) | |
download | llvm-243acd5dcbc637e477062877185ad76d8ff63d9d.zip llvm-243acd5dcbc637e477062877185ad76d8ff63d9d.tar.gz llvm-243acd5dcbc637e477062877185ad76d8ff63d9d.tar.bz2 |
[BasicAA] Remove support for PhiValues analysis
BasicAA currently has an optional dependency on the PhiValues
analysis. However, at least with our current pipeline setup, we
never actually make use of it. It's possible that this used to work
with the legacy pass manager, but I'm not sure of that either.
Given that this analysis has not actually been in use for a long
time, and nobody noticed or complained, I think we should drop
support for it and focus on one code path. It is worth noting that
analysis quality for the non-PhiValues case has significantly
improved in the meantime.
If we really wanted to make use of PhiValues, the right way would
probably be to pass it in via AAQI in places we want to use it,
rather than using an optional pass manager dependency (which are
an unpredictable PITA and should really only ever be used for
analyses that are only preserved and not used).
Differential Revision: https://reviews.llvm.org/D139719
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 82 |
1 files changed, 28 insertions, 54 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index ec80aa5..f7b0edd 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -24,7 +24,6 @@ #include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/MemoryLocation.h" -#include "llvm/Analysis/PhiValues.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Argument.h" @@ -87,8 +86,7 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA, // may be created without handles to some analyses and in that case don't // depend on them. if (Inv.invalidate<AssumptionAnalysis>(Fn, PA) || - (DT && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA)) || - (PV && Inv.invalidate<PhiValuesAnalysis>(Fn, PA))) + (DT && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA))) return true; // Otherwise this analysis result remains valid. @@ -1339,56 +1337,37 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, return false; }; - if (PV) { - // If we have PhiValues then use it to get the underlying phi values. - const PhiValues::ValueSet &PhiValueSet = PV->getValuesForPhi(PN); - // If we have more phi values than the search depth then return MayAlias - // conservatively to avoid compile time explosion. The worst possible case - // is if both sides are PHI nodes. In which case, this is O(m x n) time - // where 'm' and 'n' are the number of PHI sources. - if (PhiValueSet.size() > MaxLookupSearchDepth) - return AliasResult::MayAlias; - // Add the values to V1Srcs - for (Value *PV1 : PhiValueSet) { - if (CheckForRecPhi(PV1)) - continue; - V1Srcs.push_back(PV1); - } - } else { - // If we don't have PhiInfo then just look at the operands of the phi itself - // FIXME: Remove this once we can guarantee that we have PhiInfo always - SmallPtrSet<Value *, 4> UniqueSrc; - Value *OnePhi = nullptr; - for (Value *PV1 : PN->incoming_values()) { - // Skip the phi itself being the incoming value. - if (PV1 == PN) - continue; + SmallPtrSet<Value *, 4> UniqueSrc; + Value *OnePhi = nullptr; + for (Value *PV1 : PN->incoming_values()) { + // Skip the phi itself being the incoming value. + if (PV1 == PN) + continue; - if (isa<PHINode>(PV1)) { - if (OnePhi && OnePhi != PV1) { - // To control potential compile time explosion, we choose to be - // conserviate when we have more than one Phi input. It is important - // that we handle the single phi case as that lets us handle LCSSA - // phi nodes and (combined with the recursive phi handling) simple - // pointer induction variable patterns. - return AliasResult::MayAlias; - } - OnePhi = PV1; + if (isa<PHINode>(PV1)) { + if (OnePhi && OnePhi != PV1) { + // To control potential compile time explosion, we choose to be + // conserviate when we have more than one Phi input. It is important + // that we handle the single phi case as that lets us handle LCSSA + // phi nodes and (combined with the recursive phi handling) simple + // pointer induction variable patterns. + return AliasResult::MayAlias; } - - if (CheckForRecPhi(PV1)) - continue; - - if (UniqueSrc.insert(PV1).second) - V1Srcs.push_back(PV1); + OnePhi = PV1; } - if (OnePhi && UniqueSrc.size() > 1) - // Out of an abundance of caution, allow only the trivial lcssa and - // recursive phi cases. - return AliasResult::MayAlias; + if (CheckForRecPhi(PV1)) + continue; + + if (UniqueSrc.insert(PV1).second) + V1Srcs.push_back(PV1); } + if (OnePhi && UniqueSrc.size() > 1) + // Out of an abundance of caution, allow only the trivial lcssa and + // recursive phi cases. + return AliasResult::MayAlias; + // If V1Srcs is empty then that means that the phi has no underlying non-phi // value. This should only be possible in blocks unreachable from the entry // block, but return MayAlias just in case. @@ -1776,8 +1755,7 @@ BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) { auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); auto &AC = AM.getResult<AssumptionAnalysis>(F); auto *DT = &AM.getResult<DominatorTreeAnalysis>(F); - auto *PV = AM.getCachedResult<PhiValuesAnalysis>(F); - return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT, PV); + return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT); } BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) { @@ -1793,7 +1771,6 @@ INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basic-aa", INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PhiValuesWrapperPass) INITIALIZE_PASS_END(BasicAAWrapperPass, "basic-aa", "Basic Alias Analysis (stateless AA impl)", true, true) @@ -1805,12 +1782,10 @@ bool BasicAAWrapperPass::runOnFunction(Function &F) { auto &ACT = getAnalysis<AssumptionCacheTracker>(); auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>(); auto &DTWP = getAnalysis<DominatorTreeWrapperPass>(); - auto *PVWP = getAnalysisIfAvailable<PhiValuesWrapperPass>(); Result.reset(new BasicAAResult(F.getParent()->getDataLayout(), F, TLIWP.getTLI(F), ACT.getAssumptionCache(F), - &DTWP.getDomTree(), - PVWP ? &PVWP->getResult() : nullptr)); + &DTWP.getDomTree())); return false; } @@ -1820,7 +1795,6 @@ void BasicAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequiredTransitive<AssumptionCacheTracker>(); AU.addRequiredTransitive<DominatorTreeWrapperPass>(); AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>(); - AU.addUsedIfAvailable<PhiValuesWrapperPass>(); } BasicAAResult llvm::createLegacyPMBasicAAResult(Pass &P, Function &F) { |