[llvm] 3ddd1ff - [SCEV] Don't invalidate past dependency-breaking instructions
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 05:45:01 PDT 2023
Author: Nikita Popov
Date: 2023-04-28T14:42:08+02:00
New Revision: 3ddd1ffb721dd0ac3faa4a53c76b6904e862b7ab
URL: https://github.com/llvm/llvm-project/commit/3ddd1ffb721dd0ac3faa4a53c76b6904e862b7ab
DIFF: https://github.com/llvm/llvm-project/commit/3ddd1ffb721dd0ac3faa4a53c76b6904e862b7ab.diff
LOG: [SCEV] Don't invalidate past dependency-breaking instructions
When invalidating a value, we walk all users of that value and
invalidate them as well. This can be very expensive for large use
graphs.
However, we only need to invalidate a user U of instruction I if
SCEV(U) can depend on SCEV(I). This is not the case if U is an
instruction that always produces a SCEVUnknown, such as a load.
If the load pointer operand is invalidated, there is no need to
invalidate the load result, which is completely unrelated from a
SCEV perspective.
Differential Revision: https://reviews.llvm.org/D149323
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c3c7c2c2f1f9..9429b2f11a58 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4490,6 +4490,18 @@ void ScalarEvolution::insertValueToMap(Value *V, const SCEV *S) {
}
}
+/// Determine whether this instruction is either not SCEVable or will always
+/// produce a SCEVUnknown. We do not have to walk past such instructions when
+/// invalidating.
+static bool isAlwaysUnknown(const Instruction *I) {
+ switch (I->getOpcode()) {
+ case Instruction::Load:
+ return true;
+ default:
+ return false;
+ }
+}
+
/// Return an existing SCEV if it exists, otherwise analyze the expression and
/// create a new one.
const SCEV *ScalarEvolution::getSCEV(Value *V) {
@@ -4497,7 +4509,11 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) {
if (const SCEV *S = getExistingSCEV(V))
return S;
- return createSCEVIter(V);
+ const SCEV *S = createSCEVIter(V);
+ assert((!isa<Instruction>(V) || !isAlwaysUnknown(cast<Instruction>(V)) ||
+ isa<SCEVUnknown>(S)) &&
+ "isAlwaysUnknown() instruction is not SCEVUnknown");
+ return S;
}
const SCEV *ScalarEvolution::getExistingSCEV(Value *V) {
@@ -4798,6 +4814,8 @@ static void PushDefUseChildren(Instruction *I,
// Push the def-use children onto the Worklist stack.
for (User *U : I->users()) {
auto *UserInsn = cast<Instruction>(U);
+ if (isAlwaysUnknown(UserInsn))
+ continue;
if (Visited.insert(UserInsn).second)
Worklist.push_back(UserInsn);
}
More information about the llvm-commits
mailing list