Skip to content

Conversation

@epilk
Copy link
Member

@epilk epilk commented Mar 13, 2025

Fixes SWDEV-514946

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Emma Pilkington (epilk)

Changes

Fixes SWDEV-514946


Full diff: https://github.com/llvm/llvm-project/pull/131167.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp (+2)
  • (added) llvm/test/CodeGen/AMDGPU/dbg-value-starts-sched-region.mir (+30)
diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
index c277223de13ac..99a7dfe0ed20c 100644
--- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -873,6 +873,8 @@ void GCNScheduleDAGMILive::computeBlockPressure(unsigned RegionIdx,
       Pressure[CurRegion] = RPTracker.moveMaxPressure();
       if (CurRegion-- == RegionIdx)
         break;
+      auto &Rgn = Regions[CurRegion];
+      NonDbgMI = &*skipDebugInstructionsForward(Rgn.first, Rgn.second);
     }
     RPTracker.advanceToNext();
     RPTracker.advanceBeforeNext();
diff --git a/llvm/test/CodeGen/AMDGPU/dbg-value-starts-sched-region.mir b/llvm/test/CodeGen/AMDGPU/dbg-value-starts-sched-region.mir
new file mode 100644
index 0000000000000..2fb9acf36bb5d
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/dbg-value-starts-sched-region.mir
@@ -0,0 +1,30 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -verify-machineinstrs -run-pass=machine-scheduler -o - %s | FileCheck %s
+
+# Verify we maintain live-ins even if the first instruction in sched region is
+# DBG_.
+
+---
+name:            sched
+tracksRegLiveness: true
+registers:
+- { id: 1, class: sgpr_32, preferred-register: '', flags: [  ] }
+- { id: 2, class: sgpr_32, preferred-register: '', flags: [  ] }
+body:             |
+  bb.0.entry:
+    ; CHECK-LABEL: name: sched
+    ; CHECK: [[DEF:%[0-9]+]]:sgpr_32 = IMPLICIT_DEF
+    ; CHECK-NEXT: S_NOP 0
+    ; CHECK-NEXT: SCHED_BARRIER 0
+    ; CHECK-NEXT: DBG_VALUE
+    ; CHECK-NEXT: dead [[COPY:%[0-9]+]]:sgpr_32 = COPY [[DEF]]
+    ; CHECK-NEXT: S_NOP 0
+    ; CHECK-NEXT: S_ENDPGM 0
+    %1:sgpr_32 = IMPLICIT_DEF
+    S_NOP 0
+    SCHED_BARRIER 0
+    DBG_VALUE
+    dead %2:sgpr_32 = COPY %1
+    S_NOP 0
+    S_ENDPGM 0
+...

Copy link
Collaborator

@JonChesterfield JonChesterfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with test nits

@epilk epilk force-pushed the fix-reg-pressure-unreachable branch from 33cb40c to 22d457f Compare March 19, 2025 02:53
@epilk epilk merged commit 3eddb99 into llvm:main Mar 19, 2025
11 checks passed
rahulc-gh pushed a commit to ROCm/llvm-project that referenced this pull request Sep 11, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Sep 11, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants