[llvm] 143ed21 - Revert "[LCSSA] Remove unused ScalarEvolution argument (NFC)"
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 07:45:48 PDT 2023
Author: Nikita Popov
Date: 2023-06-05T16:45:38+02:00
New Revision: 143ed21b26b2c68695e9f74f0ce4632b8a2e000b
URL: https://github.com/llvm/llvm-project/commit/143ed21b26b2c68695e9f74f0ce4632b8a2e000b
DIFF: https://github.com/llvm/llvm-project/commit/143ed21b26b2c68695e9f74f0ce4632b8a2e000b.diff
LOG: Revert "[LCSSA] Remove unused ScalarEvolution argument (NFC)"
This reverts commit 5362a0d859d8e96b3f7c0437b7866e17a818a4f7.
In preparation for reverting a dependent revision.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/lib/Transforms/Utils/LCSSA.cpp
llvm/lib/Transforms/Utils/LoopSimplify.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 1a5dad918896b..c6864124e0bcb 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -81,7 +81,8 @@ bool formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
/// vector.
bool formLCSSAForInstructions(
SmallVectorImpl<Instruction *> &Worklist, const DominatorTree &DT,
- const LoopInfo &LI, SmallVectorImpl<PHINode *> *PHIsToRemove = nullptr,
+ const LoopInfo &LI, ScalarEvolution *SE,
+ SmallVectorImpl<PHINode *> *PHIsToRemove = nullptr,
SmallVectorImpl<PHINode *> *InsertedPHIs = nullptr);
/// Put loop into LCSSA form.
@@ -91,21 +92,25 @@ bool formLCSSAForInstructions(
/// the loop are rewritten to use this node. Sub-loops must be in LCSSA form
/// already.
///
-/// LoopInfo and DominatorTree are required and preserved. ScalarEvolution is
-/// preserved.
+/// LoopInfo and DominatorTree are required and preserved.
+///
+/// If ScalarEvolution is passed in, it will be preserved.
///
/// Returns true if any modifications are made to the loop.
-bool formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI);
+bool formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
+ ScalarEvolution *SE);
/// Put a loop nest into LCSSA form.
///
/// This recursively forms LCSSA for a loop nest.
///
-/// LoopInfo and DominatorTree are required and preserved. ScalarEvolution is
-/// preserved.
+/// LoopInfo and DominatorTree are required and preserved.
+///
+/// If ScalarEvolution is passed in, it will be preserved.
///
/// Returns true if any modifications are made to the loop.
-bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI);
+bool formLCSSARecursively(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
+ ScalarEvolution *SE);
/// Flags controlling how much is checked when sinking or hoisting
/// instructions. The number of memory access in the loop (and whether there
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index b21adc968fef2..6223d97c7679c 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -1530,7 +1530,7 @@ bool LoopConstrainer::run() {
// This function canonicalizes the loop into Loop-Simplify and LCSSA forms.
auto CanonicalizeLoop = [&] (Loop *L, bool IsOriginalLoop) {
- formLCSSARecursively(*L, DT, &LI);
+ formLCSSARecursively(*L, DT, &LI, &SE);
simplifyLoop(L, &DT, &LI, &SE, nullptr, nullptr, true);
// Pre/post loops are slow paths, we do not need to perform any loop
// optimizations on them.
@@ -1759,7 +1759,7 @@ PreservedAnalyses IRCEPass::run(Function &F, FunctionAnalysisManager &AM) {
for (const auto &L : LI) {
CFGChanged |= simplifyLoop(L, &DT, &LI, &SE, nullptr, nullptr,
/*PreserveLCSSA=*/false);
- Changed |= formLCSSARecursively(*L, DT, &LI);
+ Changed |= formLCSSARecursively(*L, DT, &LI, &SE);
}
Changed |= CFGChanged;
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index fa964a8cea006..9bfc0b49cb5c5 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -513,7 +513,7 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AAResults *AA, LoopInfo *LI,
// SSAUpdater strategy during promotion that was LCSSA aware and reformed
// it as it went.
if (Promoted)
- formLCSSARecursively(*L, *DT, LI);
+ formLCSSARecursively(*L, *DT, LI, SE);
Changed |= Promoted;
}
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 9daaaff75b6a9..91286ebcea33a 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -531,7 +531,7 @@ struct LoopInterchange {
LLVM_DEBUG(dbgs() << "Loops interchanged.\n");
LoopsInterchanged++;
- llvm::formLCSSARecursively(*OuterLoop, *DT, LI);
+ llvm::formLCSSARecursively(*OuterLoop, *DT, LI, SE);
return true;
}
};
@@ -1689,7 +1689,7 @@ bool LoopInterchangeTransform::adjustLoopBranches() {
for (Instruction &I :
make_range(OuterLoopHeader->begin(), std::prev(OuterLoopHeader->end())))
MayNeedLCSSAPhis.push_back(&I);
- formLCSSAForInstructions(MayNeedLCSSAPhis, *DT, *LI);
+ formLCSSAForInstructions(MayNeedLCSSAPhis, *DT, *LI, SE);
return true;
}
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index 854bef03481f9..8d59fdff9236f 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -417,7 +417,7 @@ class ConstantTerminatorFoldingImpl {
else
DTU.applyUpdates(DTUpdates);
DTUpdates.clear();
- formLCSSARecursively(*FixLCSSALoop, DT, &LI);
+ formLCSSARecursively(*FixLCSSALoop, DT, &LI, &SE);
SE.forgetBlockAndLoopDispositions();
}
}
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 86aee6ad98dda..f82f4a4ec55f0 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5659,7 +5659,7 @@ void LSRInstance::RewriteForPHI(
}
}
- formLCSSAForInstructions(InsertedNonLCSSAInsts, DT, LI);
+ formLCSSAForInstructions(InsertedNonLCSSAInsts, DT, LI, &SE);
}
/// Emit instructions for the leading candidate expression for this LSRUse (this
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 8ea3a7e8c7b64..70b9ff33c5d55 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -1602,7 +1602,7 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
for (const auto &L : LI) {
Changed |=
simplifyLoop(L, &DT, &LI, &SE, &AC, nullptr, false /* PreserveLCSSA */);
- Changed |= formLCSSARecursively(*L, DT, &LI);
+ Changed |= formLCSSARecursively(*L, DT, &LI, &SE);
}
// Add the loop nests in the reverse order of LoopInfo. See method
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 8356f867aca2d..6034b6b880ce6 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -462,7 +462,7 @@ static void hoistLoopToNewParent(Loop &L, BasicBlock &Preheader,
// Because we just hoisted a loop out of this one, we have essentially
// created new exit paths from it. That means we need to form LCSSA PHI
// nodes for values used in the no-longer-nested loop.
- formLCSSA(*OldContainingL, DT, &LI);
+ formLCSSA(*OldContainingL, DT, &LI, SE);
// We shouldn't need to form dedicated exits because the exit introduced
// here is the (just split by unswitching) preheader. However, after trivial
@@ -2535,7 +2535,7 @@ static void unswitchNontrivialInvariants(
// First build LCSSA for this loop so that we can preserve it when
// forming dedicated exits. We don't want to perturb some other loop's
// LCSSA while doing that CFG edit.
- formLCSSA(UpdateL, DT, &LI);
+ formLCSSA(UpdateL, DT, &LI, SE);
// For loops reached by this loop's original exit blocks we may
// introduced new, non-dedicated exits. At least try to re-form dedicated
diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp
index a6895cc5fe203..5f1c98cd703a7 100644
--- a/llvm/lib/Transforms/Utils/LCSSA.cpp
+++ b/llvm/lib/Transforms/Utils/LCSSA.cpp
@@ -76,6 +76,7 @@ static bool isExitBlock(BasicBlock *BB,
/// rewrite the uses.
bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
const DominatorTree &DT, const LoopInfo &LI,
+ ScalarEvolution *Se,
SmallVectorImpl<PHINode *> *PHIsToRemove,
SmallVectorImpl<PHINode *> *InsertedPHIs) {
SmallVector<Use *, 16> UsesToRewrite;
@@ -333,7 +334,8 @@ static void computeBlocksDominatingExits(
}
}
-bool llvm::formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI) {
+bool llvm::formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI,
+ ScalarEvolution *SE) {
bool Changed = false;
#ifdef EXPENSIVE_CHECKS
@@ -386,7 +388,7 @@ bool llvm::formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI) {
}
}
- Changed = formLCSSAForInstructions(Worklist, DT, *LI);
+ Changed = formLCSSAForInstructions(Worklist, DT, *LI, SE);
assert(L.isLCSSAForm(DT));
@@ -395,22 +397,23 @@ bool llvm::formLCSSA(Loop &L, const DominatorTree &DT, const LoopInfo *LI) {
/// Process a loop nest depth first.
bool llvm::formLCSSARecursively(Loop &L, const DominatorTree &DT,
- const LoopInfo *LI) {
+ const LoopInfo *LI, ScalarEvolution *SE) {
bool Changed = false;
// Recurse depth-first through inner loops.
for (Loop *SubLoop : L.getSubLoops())
- Changed |= formLCSSARecursively(*SubLoop, DT, LI);
+ Changed |= formLCSSARecursively(*SubLoop, DT, LI, SE);
- Changed |= formLCSSA(L, DT, LI);
+ Changed |= formLCSSA(L, DT, LI, SE);
return Changed;
}
/// Process all loops in the function, inner-most out.
-static bool formLCSSAOnAllLoops(const LoopInfo *LI, const DominatorTree &DT) {
+static bool formLCSSAOnAllLoops(const LoopInfo *LI, const DominatorTree &DT,
+ ScalarEvolution *SE) {
bool Changed = false;
for (const auto &L : *LI)
- Changed |= formLCSSARecursively(*L, DT, LI);
+ Changed |= formLCSSARecursively(*L, DT, LI, SE);
return Changed;
}
@@ -424,6 +427,7 @@ struct LCSSAWrapperPass : public FunctionPass {
// Cached analysis information for the current function.
DominatorTree *DT;
LoopInfo *LI;
+ ScalarEvolution *SE;
bool runOnFunction(Function &F) override;
void verifyAnalysis() const override {
@@ -480,13 +484,17 @@ char &llvm::LCSSAID = LCSSAWrapperPass::ID;
bool LCSSAWrapperPass::runOnFunction(Function &F) {
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
- return formLCSSAOnAllLoops(LI, *DT);
+ auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
+ SE = SEWP ? &SEWP->getSE() : nullptr;
+
+ return formLCSSAOnAllLoops(LI, *DT, SE);
}
PreservedAnalyses LCSSAPass::run(Function &F, FunctionAnalysisManager &AM) {
auto &LI = AM.getResult<LoopAnalysis>(F);
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
- if (!formLCSSAOnAllLoops(&LI, DT))
+ auto *SE = AM.getCachedResult<ScalarEvolutionAnalysis>(F);
+ if (!formLCSSAOnAllLoops(&LI, DT, SE))
return PreservedAnalyses::all();
PreservedAnalyses PA;
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index 30a255023698c..3e604fdf2e11a 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -340,7 +340,7 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader,
// We don't need to form LCSSA recursively, because there cannot be uses
// inside a newly created loop of defs from inner loops as those would
// already be a use of an LCSSA phi node.
- formLCSSA(*L, *DT, LI);
+ formLCSSA(*L, *DT, LI, SE);
assert(NewOuter->isRecursivelyLCSSAForm(*DT, *LI) &&
"LCSSA is broken after separating nested loops!");
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 0a128854d970b..29661cd2b638d 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -876,7 +876,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
while (FixLCSSALoop->getParentLoop() != LatchLoop)
FixLCSSALoop = FixLCSSALoop->getParentLoop();
- formLCSSARecursively(*FixLCSSALoop, *DT, LI);
+ formLCSSARecursively(*FixLCSSALoop, *DT, LI, SE);
} else if (PreserveLCSSA) {
assert(OuterL->isLCSSAForm(*DT) &&
"Loops should be in LCSSA form after loop-unroll.");
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 2e644d79421c4..90c9396e11bd6 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -769,7 +769,7 @@ void llvm::breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
// exit blocks. If that happened, we need to rebuild LCSSA on the outermost
// loop which might have a had a block removed.
if (OutermostLoop != L)
- formLCSSARecursively(*OutermostLoop, DT, &LI);
+ formLCSSARecursively(*OutermostLoop, DT, &LI, &SE);
}
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index c999e00390133..ab6cb29fc09c9 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2562,7 +2562,7 @@ Value *SCEVExpander::fixupLCSSAFormFor(Value *V) {
ToUpdate.push_back(DefI);
SmallVector<PHINode *, 16> PHIsToRemove;
SmallVector<PHINode *, 16> InsertedPHIs;
- formLCSSAForInstructions(ToUpdate, SE.DT, SE.LI, &PHIsToRemove,
+ formLCSSAForInstructions(ToUpdate, SE.DT, SE.LI, &SE, &PHIsToRemove,
&InsertedPHIs);
for (PHINode *PN : InsertedPHIs)
rememberInstruction(PN);
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 02e77e1507463..3b09f87817d34 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10549,7 +10549,7 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
// For the inner loops we actually process, form LCSSA to simplify the
// transform.
- Changed |= formLCSSARecursively(*L, *DT, LI);
+ Changed |= formLCSSARecursively(*L, *DT, LI, SE);
Changed |= CFGChanged |= processLoop(L);
More information about the llvm-commits
mailing list