[PATCH] D149323: [SCEV] Don't invalidate past dependency-breaking instructions
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 01:16:13 PDT 2023
nikic created this revision.
nikic added reviewers: fhahn, mkazantsev, reames.
Herald added subscribers: StephenFan, javed.absar, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
This is a decent compile-time improvement in some cases: http://llvm-compile-time-tracker.com/compare.php?from=da4fcb0c0b281746067f92d8804c18dbce4269bd&to=3d7d37d4cc0118af994c70037753358868f25147&stat=instructions:u
https://reviews.llvm.org/D149323
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4791,6 +4791,18 @@
}
}
+/// Determine whether a SCEV for this instruction will not depend on the SCEVs
+/// for its operands. We do not have to walk past such instructions when
+/// invalidating.
+static bool isDependencyBreaking(const Instruction *I) {
+ switch (I->getOpcode()) {
+ case Instruction::Load:
+ return true;
+ default:
+ return false;
+ }
+}
+
/// Push users of the given Instruction onto the given Worklist.
static void PushDefUseChildren(Instruction *I,
SmallVectorImpl<Instruction *> &Worklist,
@@ -4798,6 +4810,8 @@
// Push the def-use children onto the Worklist stack.
for (User *U : I->users()) {
auto *UserInsn = cast<Instruction>(U);
+ if (isDependencyBreaking(UserInsn))
+ continue;
if (Visited.insert(UserInsn).second)
Worklist.push_back(UserInsn);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149323.517477.patch
Type: text/x-patch
Size: 1061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230427/ebd74066/attachment.bin>
More information about the llvm-commits
mailing list