-
Notifications
You must be signed in to change notification settings - Fork 14.3k
LiveRangeShrink: Early exit when encountering a code motion barrier. #136806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LiveRangeShrink: Early exit when encountering a code motion barrier. #136806
Conversation
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
@llvm/pr-subscribers-llvm-regalloc Author: Peter Collingbourne (pcc) ChangesWithout this, we end up with quadratic behavior affecting functions with Full diff: https://github.com/llvm/llvm-project/pull/136806.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/LiveRangeShrink.cpp b/llvm/lib/CodeGen/LiveRangeShrink.cpp
index dae7e14e54aae..46e837c086c5d 100644
--- a/llvm/lib/CodeGen/LiveRangeShrink.cpp
+++ b/llvm/lib/CodeGen/LiveRangeShrink.cpp
@@ -95,14 +95,24 @@ static MachineInstr *FindDominatedInstruction(MachineInstr &New,
return Old;
}
+static bool isCodeMotionBarrier(MachineInstr &MI) {
+ return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
+}
+
/// Builds Instruction to its dominating order number map \p M by traversing
/// from instruction \p Start.
static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
InstOrderMap &M) {
M.clear();
unsigned i = 0;
- for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
+ bool SawStore = false;
+ for (MachineInstr &I : make_range(Start, Start->getParent()->end())) {
+ if (I.mayStore())
+ SawStore = true;
+ if (!I.isSafeToMove(SawStore) && isCodeMotionBarrier(I))
+ break;
M[&I] = i++;
+ }
}
bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
@@ -166,8 +176,7 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
// If MI has side effects, it should become a barrier for code motion.
// IOM is rebuild from the next instruction to prevent later
// instructions from being moved before this MI.
- if (MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe() &&
- Next != MBB.end()) {
+ if (isCodeMotionBarrier(MI) && Next != MBB.end()) {
BuildInstOrderMap(Next, IOM);
SawStore = false;
}
|
static bool isCodeMotionBarrier(MachineInstr &MI) { | ||
return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document this? What is the exact problematic condition? We have several different barrier concepts already spread in MachineInstr and TargetInstrInfo, can we use one of those
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment that describes the situation to the best of my understanding. I don't think the existing ones can be used because the condition is specific to what this pass is doing.
llvm/lib/CodeGen/LiveRangeShrink.cpp
Outdated
for (MachineInstr &I : make_range(Start, Start->getParent()->end())) { | ||
if (I.mayStore()) | ||
SawStore = true; | ||
if (!I.isSafeToMove(SawStore) && isCodeMotionBarrier(I)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MI.hasUnmodeledSideEffects() is redundant with the isSafeToMove check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, updated this code to only call one.
While reading the code I observed that the code to update SawStore in this pass is redundant with what isSafeToMove is doing, so I removed it.
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
…n barrier. Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: llvm/llvm-project#136806
Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: llvm#136806
Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: llvm#136806
Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: llvm#136806
Without this, we end up with quadratic behavior affecting functions with large numbers of code motion barriers, such as CFI jump tables. As a drive-by cleanup, remove a redundant store to SawStore in this pass as it is also done by isSafeToMove. Reviewers: arsenm Reviewed By: arsenm Pull Request: llvm#136806
Without this, we end up with quadratic behavior affecting functions with
large numbers of code motion barriers, such as CFI jump tables.
As a drive-by cleanup, remove a redundant store to SawStore in this
pass as it is also done by isSafeToMove.