Skip to content

Commit 15e295d

Browse files
authored
[MachineScheduler][AMDGPU] Allow scheduling of single-MI regions (#128739)
The MI scheduler skips regions containing a single MI during scheduling. This can prevent targets that perform multi-stage scheduling and move MIs between regions during some stages to reason correctly about the entire IR, since some MIs will not be assigned to a region at the beginning. This makes the machine scheduler no longer skip single-MI regions. Only a few unit tests are affected (mainly those which check for the scheduler's debug output).
1 parent c0b5451 commit 15e295d

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,11 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
779779
// it. Perhaps it still needs to be bundled.
780780
Scheduler.enterRegion(&*MBB, I, RegionEnd, NumRegionInstrs);
781781

782-
// Skip empty scheduling regions (0 or 1 schedulable instructions).
783-
if (I == RegionEnd || I == std::prev(RegionEnd)) {
782+
// Skip empty scheduling regions but include single-MI regions; we want
783+
// those to be scheduled so that backends which move MIs across regions
784+
// during scheduling can reason about and schedule those regions
785+
// correctly.
786+
if (I == RegionEnd) {
784787
// Close the current region. Bundle the terminator if needed.
785788
// This invalidates 'RegionEnd' and 'I'.
786789
Scheduler.exitRegion();

llvm/test/CodeGen/AMDGPU/debug-value-scheduler-liveins.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx908 -passes=machine-scheduler %s -o - -debug-only=machine-scheduler 2>&1 | FileCheck %s
33
# REQUIRES: asserts
44

5+
# CHECK: ********** MI Scheduling **********
6+
# CHECK-NEXT: test_get_liveins:%bb.0
57
# CHECK: ********** MI Scheduling **********
68
# CHECK-NEXT: test_get_liveins:%bb.1
79
# CHECK: Region live-in pressure: VGPRs: 1 AGPRs: 0, SGPRs: 0, LVGPR WT: 0, LSGPR WT: 0

llvm/test/CodeGen/ARM/misched-branch-targets.mir

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# RUN: llc -o - -run-pass=machine-scheduler -misched=shuffle %s | FileCheck %s
2-
# RUN: llc -o - -passes=machine-scheduler -misched=shuffle %s | FileCheck %s
3-
# RUN: llc -o - -run-pass=postmisched %s | FileCheck %s
4-
# RUN: llc -o - -passes=postmisched %s | FileCheck %s
1+
# RUN: llc -o - -run-pass=machine-scheduler -misched=shuffle %s | FileCheck -check-prefixes=CHECK,CHECK-MISCHED %s
2+
# RUN: llc -o - -passes=machine-scheduler -misched=shuffle %s | FileCheck -check-prefixes=CHECK,CHECK-MISCHED %s
3+
# RUN: llc -o - -run-pass=postmisched %s | FileCheck -check-prefixes=CHECK,CHECK-POSTMISCHED %s
4+
# RUN: llc -o - -passes=postmisched %s | FileCheck -check-prefixes=CHECK,CHECK-POSTMISCHED %s
55

66
# REQUIRES: asserts
77
# -misched=shuffle is only available with assertions enabled
@@ -147,7 +147,8 @@ body: |
147147

148148
# CHECK-LABEL: name: foo_setjmp
149149
# CHECK: body:
150-
# CHECK: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def $r0
150+
# CHECK-MISCHED: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit $r0, implicit-def $sp, implicit-def $r0
151+
# CHECK-POSTMISCHED: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def $r0
151152
# CHECK-NEXT: t2BTI
152153

153154
---

llvm/test/CodeGen/PowerPC/pr47155-47156.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
; RUN: -stop-after=postmisched -debug-only=machine-scheduler 2>&1 >/dev/null | FileCheck %s
55

66
define void @pr47155() {
7+
; CHECK-LABEL: Machine code for function pr47155
78
; CHECK: *** Final schedule for %bb.0 ***
89
; CHECK: ********** MI Scheduling **********
910
; CHECK-NEXT: pr47155:%bb.0 entry
@@ -23,6 +24,7 @@ entry:
2324
}
2425

2526
define void @pr47156(ptr %fn) {
27+
; CHECK-LABEL: Machine code for function pr47156
2628
; CHECK: *** Final schedule for %bb.0 ***
2729
; CHECK: ********** MI Scheduling **********
2830
; CHECK-NEXT: pr47156:%bb.0 entry

llvm/test/CodeGen/X86/fake-use-scheduler.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#
1010
# CHECK: ********** MI Scheduling **********
1111
# CHECK-NEXT: foo:%bb.0 entry
12+
# CHECK-NEXT: From: $rax = COPY %5:gr64
13+
# CHECK-NEXT: To: RET 0, killed $rax
14+
# CHECK-NEXT: RegionInstrs: 1
15+
#
16+
# CHECK: ********** MI Scheduling **********
17+
# CHECK-NEXT: foo:%bb.0 entry
1218
# CHECK-NEXT: From: %0:gr64 = COPY $rdi
1319
# CHECK-NEXT: To: FAKE_USE %5:gr64
1420
# CHECK-NEXT: RegionInstrs: 7

0 commit comments

Comments
 (0)