1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

[LoopVectorize] Preserve CFG analyses if CFG wasn't modified

One of transforms the loop vectorizer makes is LCSSA formation. In some cases it
is the only transform it makes. We should not drop CFG analyzes if only LCSSA was
formed and no actual CFG changes was made.

We should think of expanding this logic to other passes as well, and maybe make
it a part of PM framework.

Reviewed By: Florian Hahn
Differential Revision: https://reviews.llvm.org/D78360
This commit is contained in:
Max Kazantsev 2020-04-24 17:02:37 +07:00
parent 48b1234c8a
commit 864078facb
3 changed files with 29 additions and 17 deletions

View File

@ -116,6 +116,15 @@ struct LoopVectorizeOptions {
}
};
/// Storage for information about made changes.
struct LoopVectorizeResult {
bool MadeAnyChange;
bool MadeCFGChange;
LoopVectorizeResult(bool MadeAnyChange, bool MadeCFGChange)
: MadeAnyChange(MadeAnyChange), MadeCFGChange(MadeCFGChange) {}
};
/// The LoopVectorize Pass.
struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
private:
@ -146,12 +155,13 @@ public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
// Shim for old PM.
bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
TargetTransformInfo &TTI_, DominatorTree &DT_,
BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_,
DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
std::function<const LoopAccessInfo &(Loop &)> &GetLAA_,
OptimizationRemarkEmitter &ORE_, ProfileSummaryInfo *PSI_);
LoopVectorizeResult
runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
TargetTransformInfo &TTI_, DominatorTree &DT_,
BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_, DemandedBits &DB_,
AliasAnalysis &AA_, AssumptionCache &AC_,
std::function<const LoopAccessInfo &(Loop &)> &GetLAA_,
OptimizationRemarkEmitter &ORE_, ProfileSummaryInfo *PSI_);
bool processLoop(Loop *L);
};

View File

@ -1632,7 +1632,7 @@ struct LoopVectorize : public FunctionPass {
[&](Loop &L) -> const LoopAccessInfo & { return LAA->getInfo(&L); };
return Impl.runImpl(F, *SE, *LI, *TTI, *DT, *BFI, TLI, *DB, *AA, *AC,
GetLAA, *ORE, PSI);
GetLAA, *ORE, PSI).MadeAnyChange;
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@ -7954,7 +7954,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
return true;
}
bool LoopVectorizePass::runImpl(
LoopVectorizeResult LoopVectorizePass::runImpl(
Function &F, ScalarEvolution &SE_, LoopInfo &LI_, TargetTransformInfo &TTI_,
DominatorTree &DT_, BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_,
DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
@ -7982,9 +7982,9 @@ bool LoopVectorizePass::runImpl(
// interleaving.
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true)) &&
TTI->getMaxInterleaveFactor(1) < 2)
return false;
return LoopVectorizeResult(false, false);
bool Changed = false;
bool Changed = false, CFGChanged = false;
// The vectorizer requires loops to be in simplified form.
// Since simplification may add new inner loops, it has to run before the
@ -7992,7 +7992,7 @@ bool LoopVectorizePass::runImpl(
// will simplify all loops, regardless of whether anything end up being
// vectorized.
for (auto &L : *LI)
Changed |=
Changed |= CFGChanged |=
simplifyLoop(L, DT, LI, SE, AC, nullptr, false /* PreserveLCSSA */);
// Build up a worklist of inner-loops to vectorize. This is necessary as
@ -8013,11 +8013,11 @@ bool LoopVectorizePass::runImpl(
// transform.
Changed |= formLCSSARecursively(*L, *DT, LI, SE);
Changed |= processLoop(L);
Changed |= CFGChanged |= processLoop(L);
}
// Process each loop nest in the function.
return Changed;
return LoopVectorizeResult(Changed, CFGChanged);
}
PreservedAnalyses LoopVectorizePass::run(Function &F,
@ -8046,9 +8046,9 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
AM.getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager();
ProfileSummaryInfo *PSI =
MAM.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
bool Changed =
LoopVectorizeResult Result =
runImpl(F, SE, LI, TTI, DT, BFI, &TLI, DB, AA, AC, GetLAA, ORE, PSI);
if (!Changed)
if (!Result.MadeAnyChange)
return PreservedAnalyses::all();
PreservedAnalyses PA;
@ -8062,5 +8062,7 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
}
PA.preserve<BasicAA>();
PA.preserve<GlobalsAA>();
if (!Result.MadeCFGChange)
PA.preserveSet<CFGAnalyses>();
return PA;
}

View File

@ -11,8 +11,8 @@ define i32 @novect(i32* %p) {
; CHECK: Invalidating all non-preserved analyses for: novect
; CHECK: Clearing all analysis results for: <possibly invalidated loop>
; CHECK: Invalidating analysis: ScalarEvolutionAnalysis on novect
; CHECK: Invalidating analysis: BranchProbabilityAnalysis on novect
; CHECK: Invalidating analysis: BlockFrequencyAnalysis on novect
; CHECK-NOT: Invalidating analysis: BranchProbabilityAnalysis on novect
; CHECK-NOT: Invalidating analysis: BlockFrequencyAnalysis on novect
; CHECK: Invalidating analysis: DemandedBitsAnalysis on novect
; CHECK: Invalidating analysis: MemorySSAAnalysis on novect
; CHECK: Running pass: JumpThreadingPass on novect