[llvm] [MISched] Apply debug filters before starting a block (PR #222270)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 01:52:58 PDT 2026


https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/222270

Apply the `misched-only-func` and `misched-only-block` filters before calling `startBlock`. This avoids entering a target scheduling strategy for a filtered block without a matching `finishBlock`/`leaveMBB` call.

Add a SystemZ post-RA scheduler regression that checks a filtered block does not contribute hazard-recognizer state.

Split from #221984 in response to review.

>From e7c23f35b41c7507d4185d300863def085b5b7f2 Mon Sep 17 00:00:00 2001
From: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: Wed, 9 Sep 2026 16:46:43 +0800
Subject: [PATCH] [MISched] Apply debug filters before starting a block

Apply the misched-only function and block filters before calling
startBlock. This avoids opening scheduler state for blocks that will not
be visited.

Assisted-by: TRAE CLI (GPT-5.6)
Co-authored-by: TRAE CLI <traecli at bytedance.com>
---
 llvm/lib/CodeGen/MachineScheduler.cpp         |  5 ++---
 .../CodeGen/SystemZ/postra-sched-filter.mir   | 21 +++++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/SystemZ/postra-sched-filter.mir

diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 960c75d8050b1..8d0130973b81b 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -815,9 +815,6 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
   // loop tree. Then we can optionally compute global RegPressure.
   for (MachineFunction::iterator MBB = MF->begin(), MBBEnd = MF->end();
        MBB != MBBEnd; ++MBB) {
-
-    Scheduler.startBlock(&*MBB);
-
 #ifndef NDEBUG
     if (SchedOnlyFunc.getNumOccurrences() && SchedOnlyFunc != MF->getName())
       continue;
@@ -826,6 +823,8 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
       continue;
 #endif
 
+    Scheduler.startBlock(&*MBB);
+
     // Break the block into scheduling regions [I, RegionEnd). RegionEnd
     // points to the scheduling boundary at the bottom of the region. The DAG
     // does not include RegionEnd, but the region does (i.e. the next
diff --git a/llvm/test/CodeGen/SystemZ/postra-sched-filter.mir b/llvm/test/CodeGen/SystemZ/postra-sched-filter.mir
new file mode 100644
index 0000000000000..01e0dadde5465
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/postra-sched-filter.mir
@@ -0,0 +1,21 @@
+# REQUIRES: asserts
+# RUN: llc -mtriple=s390x-linux-gnu -mcpu=z13 -run-pass=postmisched \
+# RUN:   -misched-only-block=1 -debug-only=machine-scheduler -o /dev/null %s \
+# RUN:   2>&1 | FileCheck %s
+
+# CHECK-NOT: ** Entering %bb.0
+# CHECK: ** Entering %bb.1:
+
+---
+name:            test
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    successors: %bb.1(0x80000000)
+
+    J %bb.1
+
+  bb.1:
+    $r2l = LHI 0
+    Return implicit killed $r2l
+...



More information about the llvm-commits mailing list