Index: llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h =================================================================== --- llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h +++ llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h @@ -116,6 +116,15 @@ } }; +/// 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 { private: @@ -146,12 +155,13 @@ 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 &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 &GetLAA_, + OptimizationRemarkEmitter &ORE_, ProfileSummaryInfo *PSI_); bool processLoop(Loop *L); }; Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1625,7 +1625,7 @@ [&](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 { @@ -7944,7 +7944,7 @@ 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_, @@ -7972,9 +7972,9 @@ // 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 @@ -7982,7 +7982,7 @@ // 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 @@ -8003,11 +8003,11 @@ // 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, @@ -8036,9 +8036,9 @@ AM.getResult(F).getManager(); ProfileSummaryInfo *PSI = MAM.getCachedResult(*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; @@ -8052,5 +8052,7 @@ } PA.preserve(); PA.preserve(); + if (!Result.MadeCFGChange) + PA.preserveSet(); return PA; }