Skip to content

[AMDGPU][NFC] Pre-commit tests for soft waitcnt requests lost at a loop header - #244686

Merged
reble merged 2 commits into
mainfrom
users/reble/amdgpu-soft-waitcnt-loop-header-tests
Nov 21, 2026
Merged

reble merged 2 commits into
mainfrom
users/reble/amdgpu-soft-waitcnt-loop-header-tests

Conversation

@reble

@reble reble commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Two cases where a soft waitcnt at a loop header loses its lgkmcnt(0). On the first visit to the header no LDS operation is pending yet, so the soft waitcnt's lgkmcnt is simplified away, while a vmcnt keeps the instruction alive. That vmcnt comes either from the soft waitcnt itself or from a preceding hard vmcnt(0) that it is merged into. The DS write at the end of the loop is then not waited for before the S_BARRIER on the next iteration.

The checks show the current, incorrect output (S_WAITCNT .Vmcnt_0 before S_BARRIER).

Assisted-by: Claude Opus 5.5

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Pablo Reble (reble)

Changes

Two cases where a soft waitcnt at a loop header loses its lgkmcnt(0). On the first visit to the header no LDS operation is pending yet, so the soft waitcnt's lgkmcnt is simplified away, while a vmcnt keeps the instruction alive. That vmcnt comes either from the soft waitcnt itself or from a preceding hard vmcnt(0) that it is merged into. The DS write at the end of the loop is then not waited for before the S_BARRIER on the next iteration.

The checks show the current, incorrect output (S_WAITCNT .Vmcnt_0 before S_BARRIER).

Assisted-by: Claude Opus 5.5


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

1 Files Affected:

  • (modified) llvm/test/CodeGen/AMDGPU/waitcnt-loop-carried-fence-drain.mir (+110)
diff --git a/llvm/test/CodeGen/AMDGPU/waitcnt-loop-carried-fence-drain.mir b/llvm/test/CodeGen/AMDGPU/waitcnt-loop-carried-fence-drain.mir
index 8268f21bb7b8e..cf6870d2f815a 100644
--- a/llvm/test/CodeGen/AMDGPU/waitcnt-loop-carried-fence-drain.mir
+++ b/llvm/test/CodeGen/AMDGPU/waitcnt-loop-carried-fence-drain.mir
@@ -52,3 +52,113 @@ body: |
   bb.2:
     S_ENDPGM 0
 ...
+
+# The soft wait at the loop header is kept on the first visit because of its
+# vmcnt (the global store in bb.0), but its lgkmcnt is simplified away because
+# no LDS operation is pending yet. The revisit through the back edge must still
+# see the original lgkmcnt(0) request for the DS write in bb.1.
+---
+name: soft_wait_partially_simplified_loop_header
+tracksRegLiveness: true
+body: |
+  ; CHECK-LABEL: name: soft_wait_partially_simplified_loop_header
+  ; CHECK: bb.0:
+  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
+  ; CHECK-NEXT:   liveins: $vgpr1, $vgpr2, $vgpr4_vgpr5, $vgpr6, $sgpr0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   S_WAITCNT .Vmcnt_0_Expcnt_0_Lgkmcnt_0
+  ; CHECK-NEXT:   GLOBAL_STORE_DWORD $vgpr4_vgpr5, $vgpr6, 0, 0, implicit $exec :: (store (s32), addrspace 1)
+  ; CHECK-NEXT:   S_BRANCH %bb.1
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT:   liveins: $vgpr1, $vgpr2, $sgpr0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   S_WAITCNT .Vmcnt_0
+  ; CHECK-NEXT:   S_BARRIER
+  ; CHECK-NEXT:   S_WAITCNT .Lgkmcnt_0
+  ; CHECK-NEXT:   renamable $vgpr3 = DS_READ_B32_gfx9 $vgpr2, 0, 0, implicit $exec :: (load (s32) from `ptr addrspace(3) poison`, addrspace 3)
+  ; CHECK-NEXT:   S_WAITCNT .Lgkmcnt_0
+  ; CHECK-NEXT:   DS_WRITE_B32_gfx9 $vgpr1, $vgpr3, 0, 0, implicit $exec :: (store (s32) into `ptr addrspace(3) poison`, addrspace 3)
+  ; CHECK-NEXT:   S_CMP_EQ_U32 $sgpr0, 0, implicit-def $scc
+  ; CHECK-NEXT:   S_CBRANCH_SCC1 %bb.1, implicit $scc
+  ; CHECK-NEXT:   S_BRANCH %bb.2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2:
+  ; CHECK-NEXT:   S_ENDPGM 0
+  bb.0:
+    successors: %bb.1
+    liveins: $vgpr1, $vgpr2, $vgpr4_vgpr5, $vgpr6, $sgpr0
+
+    GLOBAL_STORE_DWORD $vgpr4_vgpr5, $vgpr6, 0, 0, implicit $exec :: (store (s32), addrspace 1)
+    S_BRANCH %bb.1
+
+  bb.1:
+    successors: %bb.1, %bb.2
+    liveins: $vgpr1, $vgpr2, $sgpr0
+
+    S_WAITCNT_soft 112
+    S_BARRIER
+    S_WAITCNT_soft 49279
+    renamable $vgpr3 = DS_READ_B32_gfx9 $vgpr2, 0, 0, implicit $exec :: (load (s32) from `ptr addrspace(3) poison`, addrspace 3)
+    DS_WRITE_B32_gfx9 $vgpr1, $vgpr3, 0, 0, implicit $exec :: (store (s32) into `ptr addrspace(3) poison`, addrspace 3)
+    S_CMP_EQ_U32 $sgpr0, 0, implicit-def $scc
+    S_CBRANCH_SCC1 %bb.1, implicit $scc
+    S_BRANCH %bb.2
+
+  bb.2:
+    S_ENDPGM 0
+...
+
+# Same, but the soft lgkmcnt(0) is merged into a preceding hard vmcnt(0).
+---
+name: soft_wait_merged_into_hard_wait_loop_header
+tracksRegLiveness: true
+body: |
+  ; CHECK-LABEL: name: soft_wait_merged_into_hard_wait_loop_header
+  ; CHECK: bb.0:
+  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
+  ; CHECK-NEXT:   liveins: $vgpr1, $vgpr2, $sgpr0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   S_WAITCNT .Vmcnt_0_Expcnt_0_Lgkmcnt_0
+  ; CHECK-NEXT:   S_BRANCH %bb.1
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT:   liveins: $vgpr1, $vgpr2, $sgpr0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   S_WAITCNT .Vmcnt_0
+  ; CHECK-NEXT:   S_BARRIER
+  ; CHECK-NEXT:   S_WAITCNT .Lgkmcnt_0
+  ; CHECK-NEXT:   renamable $vgpr3 = DS_READ_B32_gfx9 $vgpr2, 0, 0, implicit $exec :: (load (s32) from `ptr addrspace(3) poison`, addrspace 3)
+  ; CHECK-NEXT:   S_WAITCNT .Lgkmcnt_0
+  ; CHECK-NEXT:   DS_WRITE_B32_gfx9 $vgpr1, $vgpr3, 0, 0, implicit $exec :: (store (s32) into `ptr addrspace(3) poison`, addrspace 3)
+  ; CHECK-NEXT:   S_CMP_EQ_U32 $sgpr0, 0, implicit-def $scc
+  ; CHECK-NEXT:   S_CBRANCH_SCC1 %bb.1, implicit $scc
+  ; CHECK-NEXT:   S_BRANCH %bb.2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2:
+  ; CHECK-NEXT:   S_ENDPGM 0
+  bb.0:
+    successors: %bb.1
+    liveins: $vgpr1, $vgpr2, $sgpr0
+
+    S_BRANCH %bb.1
+
+  bb.1:
+    successors: %bb.1, %bb.2
+    liveins: $vgpr1, $vgpr2, $sgpr0
+
+    S_WAITCNT 3952
+    S_WAITCNT_soft 49279
+    S_BARRIER
+    S_WAITCNT_soft 49279
+    renamable $vgpr3 = DS_READ_B32_gfx9 $vgpr2, 0, 0, implicit $exec :: (load (s32) from `ptr addrspace(3) poison`, addrspace 3)
+    DS_WRITE_B32_gfx9 $vgpr1, $vgpr3, 0, 0, implicit $exec :: (store (s32) into `ptr addrspace(3) poison`, addrspace 3)
+    S_CMP_EQ_U32 $sgpr0, 0, implicit-def $scc
+    S_CBRANCH_SCC1 %bb.1, implicit $scc
+    S_BRANCH %bb.2
+
+  bb.2:
+    S_ENDPGM 0
+...

S_WAITCNT_soft 49279
S_BARRIER
S_WAITCNT_soft 49279
renamable $vgpr3 = DS_READ_B32_gfx9 $vgpr2, 0, 0, implicit $exec :: (load (s32) from `ptr addrspace(3) poison`, addrspace 3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can drop the poison value references

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, thanks.

@reble
reble force-pushed the users/reble/amdgpu-soft-waitcnt-loop-header-tests branch from e806d4c to 7318793 Compare November 20, 2026 20:38

@krzysz00 krzysz00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, that sure is a bug, approved

reble and others added 2 commits November 21, 2026 07:37
…ader (NFC)

Two cases where a soft waitcnt at a loop header loses its lgkmcnt(0)
request: on the first visit no LDS operation is pending, so lgkmcnt is
simplified away while vmcnt keeps the instruction alive (either the soft
waitcnt's own vmcnt, or a preceding hard vmcnt(0) it is merged into).
The DS write in the loop is then not waited for before the S_BARRIER on
the next iteration. The checks show the current, incorrect output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reble
reble force-pushed the users/reble/amdgpu-soft-waitcnt-loop-header-tests branch from 35cf9d3 to fe79300 Compare November 21, 2026 13:37
@reble
reble merged commit 1f7e300 into main Nov 21, 2026
11 checks passed
@reble
reble deleted the users/reble/amdgpu-soft-waitcnt-loop-header-tests branch November 21, 2026 19:47
@llvm-ci

llvm-ci commented Nov 21, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-android running on sanitizer-buildbot2 while building llvm at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/4671

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[1954/1962] Building CXX object libcxx/src/CMakeFiles/cxx_static.dir/algorithm.cpp.o
[1955/1962] Building CXX object libcxxabi/src/CMakeFiles/cxxabi_static_objects.dir/cxa_demangle.cpp.o
[1956/1962] Linking CXX static library lib/libc++abi.a
[1957/1962] Building CXX object libcxx/src/CMakeFiles/cxx_experimental.dir/experimental/tzdb.cpp.o
[1958/1962] Building CXX object libcxx/src/CMakeFiles/cxx_experimental.dir/experimental/time_zone.cpp.o
[1959/1962] Building CXX object libcxx/src/CMakeFiles/cxx_static.dir/locale.cpp.o
[1960/1962] Linking CXX static library lib/libc++.a
[1961/1962] Linking CXX static library lib/libc++experimental.a
[577/609] Linking CXX executable lib/asan/tests/AsanTest
[578/609] Installing libcxx_fuzzer_aarch64...
[0/2] Re-checking globbed directories...
[0/2] Install the project...
-- Install configuration: "Release"
[580/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtFunctionsDlsym.cpp.o
[581/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtFunctionsWindows.cpp.o
[582/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtraCountersWindows.cpp.o
[583/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerIOWindows.cpp.o
[584/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtraCountersDarwin.cpp.o
[585/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtraCounters.cpp.o
[586/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtilDarwin.cpp.o
[587/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtilFuchsia.cpp.o
[588/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtilWindows.cpp.o
[589/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer_interceptors.aarch64.dir/FuzzerInterceptors.cpp.o
[590/609] Linking CXX static library /home/b/sanitizer-x86_64-linux-android/build/llvm_build64/lib/clang/24/lib/linux/libclang_rt.fuzzer_interceptors-aarch64-android.a
[591/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerExtFunctionsWeak.cpp.o
[592/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer_main.aarch64.dir/FuzzerMain.cpp.o
[593/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerSHA1.cpp.o
[594/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerIOPosix.cpp.o
[595/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerCrossOver.cpp.o
[596/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtilLinux.cpp.o
[597/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtilPosix.cpp.o
[598/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerUtil.cpp.o
[599/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerIO.cpp.o
[600/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerMutate.cpp.o
[601/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerTracePC.cpp.o
[602/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerDataFlowTrace.cpp.o
[603/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerLoop.cpp.o
[604/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerFork.cpp.o
[605/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerDriver.cpp.o
[606/609] Building CXX object lib/fuzzer/CMakeFiles/RTfuzzer.aarch64.dir/FuzzerMerge.cpp.o
[607/609] Linking CXX static library lib/fuzzer/tests/libRTFuzzerTest.aarch64.a
[608/609] Linking CXX static library /home/b/sanitizer-x86_64-linux-android/build/llvm_build64/lib/clang/24/lib/linux/libclang_rt.fuzzer_no_main-aarch64-android.a
[609/609] Linking CXX static library /home/b/sanitizer-x86_64-linux-android/build/llvm_build64/lib/clang/24/lib/linux/libclang_rt.fuzzer-aarch64-android.a

@@@BUILD_STEP cleanup@@@
29M	./llvm_venv
2.3G	./android_ndk
6.8G	./llvm_build0
7.2G	./llvm-project
12G	./android_cvd
Step 39 (run instrumented asan tests [x86_64/aosp_cf_x86_64_only_phone-userdebug/CP2A.260605.016]) failure: run instrumented asan tests [x86_64/aosp_cf_x86_64_only_phone-userdebug/CP2A.260605.016] (failure)
...
[ RUN      ] AddressSanitizer.StrNCatOOBTest
[       OK ] AddressSanitizer.StrNCatOOBTest (358 ms)
[ RUN      ] AddressSanitizer.StrArgsOverlapTest
[       OK ] AddressSanitizer.StrArgsOverlapTest (1088 ms)
[ RUN      ] AddressSanitizer.AtoiAndFriendsOOBTest
[       OK ] AddressSanitizer.AtoiAndFriendsOOBTest (1363 ms)
[ RUN      ] AddressSanitizer.StrtollOOBTest
[       OK ] AddressSanitizer.StrtollOOBTest (485 ms)
[ RUN      ] AddressSanitizer.StrtolOOBTest
[       OK ] AddressSanitizer.StrtolOOBTest (522 ms)
[ RUN      ] AddressSanitizer.StrtolOverflow
[       OK ] AddressSanitizer.StrtolOverflow (0 ms)
[ RUN      ] AddressSanitizer.HasFeatureAddressSanitizerTest
[       OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN      ] AddressSanitizer.SimpleDeathTest
[       OK ] AddressSanitizer.SimpleDeathTest (28 ms)
[ RUN      ] AddressSanitizer.VariousMallocsTest
[       OK ] AddressSanitizer.VariousMallocsTest (0 ms)
[ RUN      ] AddressSanitizer.CallocTest
[       OK ] AddressSanitizer.CallocTest (0 ms)
[ RUN      ] AddressSanitizer.CallocReturnsZeroMem
[       OK ] AddressSanitizer.CallocReturnsZeroMem (10 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.UAF_char
[       OK ] AddressSanitizer.UAF_char (367 ms)
[ RUN      ] AddressSanitizer.UAF_long_double
[       OK ] AddressSanitizer.UAF_long_double (147 ms)
[ RUN      ] AddressSanitizer.UAF_Packed5
[       OK ] AddressSanitizer.UAF_Packed5 (139 ms)
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.BitFieldPositiveTest
[       OK ] AddressSanitizer.BitFieldPositiveTest (292 ms)
[ RUN      ] AddressSanitizer.BitFieldNegativeTest
[       OK ] AddressSanitizer.BitFieldNegativeTest (0 ms)
[ RUN      ] AddressSanitizer.WildAddressTest
[       OK ] AddressSanitizer.WildAddressTest (78 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (170 ms)
[ RUN      ] AddressSanitizer.LargeMallocTest
[       OK ] AddressSanitizer.LargeMallocTest (1718 ms)
[ RUN      ] AddressSanitizer.HugeMallocTest
[       OK ] AddressSanitizer.HugeMallocTest (70 ms)
[ RUN      ] AddressSanitizer.ManyThreadsTest
Segmentation fault

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

Building for Android API level 34


aaupov pushed a commit to aaupov/llvm-project that referenced this pull request Nov 22, 2026
…op header (llvm#244686)

Two cases where a soft waitcnt at a loop header loses its `lgkmcnt(0)`.
On the first visit to the header no LDS operation is pending yet, so the
soft waitcnt's `lgkmcnt` is simplified away, while a `vmcnt` keeps the
instruction alive. That `vmcnt` comes either from the soft waitcnt
itself or from a preceding hard `vmcnt(0)` that it is merged into. The
DS write at the end of the loop is then not waited for before the
`S_BARRIER` on the next iteration.

The checks show the current, incorrect output (`S_WAITCNT .Vmcnt_0`
before `S_BARRIER`).

Assisted-by: Claude Opus 5.5

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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