[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 09:30:59 PDT 2025


https://github.com/c-rhodes created https://github.com/llvm/llvm-project/pull/137988

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

>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] [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;
   }



More information about the llvm-commits mailing list