[llvm] [MISched] Fix off-by-one error with -misched-cutoff=<n> flag (PR #137988)
Cullen Rhodes via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 23:43:07 PDT 2025
https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/137988
>From a7147f14d6353b338b39e594c01a18ca9ef58e7f Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Wed, 30 Apr 2025 16:24:43 +0000
Subject: [PATCH 1/2] [MISched] Fix off-by-one error with -misched-cutoff=<n>
flag
This flag instructs the scheduler to stop scheduling after N
instructions, but it currently schedules N+1 instructions, e.g.
$ llc -misched-cutoff=10 -debug-only=machine-scheduler \
example.ll 2>&1 | grep "^Scheduling SU" | wc -l
11
---
llvm/lib/CodeGen/MachineScheduler.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 97f27277aface..18dcb81142628 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -965,7 +965,7 @@ void ScheduleDAGMI::moveInstruction(
bool ScheduleDAGMI::checkSchedLimit() {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
- if (NumInstrsScheduled == MISchedCutoff && MISchedCutoff != ~0U) {
+ if ((NumInstrsScheduled + 1) == MISchedCutoff && MISchedCutoff != ~0U) {
CurrentTop = CurrentBottom;
return false;
}
>From 0b1319cce60a069c4da683e49693a3e31e165256 Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Thu, 1 May 2025 06:37:20 +0000
Subject: [PATCH 2/2] address comments
---
llvm/lib/CodeGen/MachineScheduler.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 18dcb81142628..77cf46178aabd 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -965,7 +965,7 @@ void ScheduleDAGMI::moveInstruction(
bool ScheduleDAGMI::checkSchedLimit() {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
- if ((NumInstrsScheduled + 1) == MISchedCutoff && MISchedCutoff != ~0U) {
+ if (NumInstrsScheduled == MISchedCutoff && MISchedCutoff != ~0U) {
CurrentTop = CurrentBottom;
return false;
}
@@ -1003,13 +1003,14 @@ void ScheduleDAGMI::schedule() {
bool IsTopNode = false;
while (true) {
+ if (!checkSchedLimit())
+ break;
+
LLVM_DEBUG(dbgs() << "** ScheduleDAGMI::schedule picking next node\n");
SUnit *SU = SchedImpl->pickNode(IsTopNode);
if (!SU) break;
assert(!SU->isScheduled && "Node already scheduled");
- if (!checkSchedLimit())
- break;
MachineInstr *MI = SU->getInstr();
if (IsTopNode) {
@@ -1637,13 +1638,14 @@ void ScheduleDAGMILive::schedule() {
bool IsTopNode = false;
while (true) {
+ if (!checkSchedLimit())
+ break;
+
LLVM_DEBUG(dbgs() << "** ScheduleDAGMILive::schedule picking next node\n");
SUnit *SU = SchedImpl->pickNode(IsTopNode);
if (!SU) break;
assert(!SU->isScheduled && "Node already scheduled");
- if (!checkSchedLimit())
- break;
scheduleMI(SU, IsTopNode);
More information about the llvm-commits
mailing list