Skip to content

[NFC][AMDGPU] New test for untested case in SILowerI1Copies - #186127

Merged
jmmartinez merged 6 commits into
llvm:mainfrom
ambergorzynski:amd-be-test-siloweri1copies
Mar 19, 2026
Merged

jmmartinez merged 6 commits into
llvm:mainfrom
ambergorzynski:amd-be-test-siloweri1copies

Conversation

@ambergorzynski

Copy link
Copy Markdown
Contributor

This line is untested by the existing LLVM test suite (checked using code coverage and by inserting an abort).

We propose a new test that exercises this case. The test is demonstrated by adding an abort to show that it is the only test that fails (the abort is removed before merging).

@github-actions

github-actions Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 132388 tests passed
  • 3009 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 192327 tests passed
  • 4928 tests skipped

✅ The build succeeded and all tests passed.

@ambergorzynski

Copy link
Copy Markdown
Contributor Author

Ours is the only test that fails in the presence of the abort

🐧 Linux x64 Test Results

  • 171172 tests passed
  • 3035 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/AMDGPU/si-lower-i1-copies.ll

Exit Code: 2

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=amdgcn-amd-amdhsa -O1 < /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=amdgcn-amd-amdhsa -O1
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=amdgcn-amd-amdhsa -O1
# | 1.	Running pass 'CallGraph Pass Manager' on module '<stdin>'.
# | 2.	Running pass 'SI Lower i1 Copies' on function '@foo'
# |  #0 0x000000000851b108 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:880:13
# |  #1 0x0000000008518071 llvm::sys::RunSignalHandlers() /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:109:18
# |  #2 0x000000000851bf21 SignalHandler(int, siginfo_t*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38
# |  #3 0x00007986daeb5330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007986daf0eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007986daeb527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007986dae988ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00000000058ef300 setIsKill /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h:524:5
# |  #8 0x00000000058ef300 lowerCopiesToI1 /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp:633:26
# |  #9 0x00000000058ef300 runFixI1Copies(llvm::MachineFunction&, llvm::MachineDominatorTree&, llvm::MachinePostDominatorTree&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/AMDGPU/SILowerI1Copies.cpp:870:21
# | #10 0x00000000071d70d3 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:0:10
# | #11 0x0000000007745f28 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
# | #12 0x0000000006c7a4e5 RunPassOnSCC /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:180:25
# | #13 0x0000000006c7a4e5 RunAllPassesOnSCC /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:469:9
# | #14 0x0000000006c7a4e5 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:534:18
# | #15 0x000000000774699b runOnModule /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1513:27
# | #16 0x000000000774699b llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531:44
# | #17 0x0000000004f2833c compileModule(char**, llvm::SmallVectorImpl<llvm::PassPlugin>&, llvm::LLVMContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:871:17
# | #18 0x0000000004f25603 main /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:459:13
# | #19 0x00007986dae9a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #20 0x00007986dae9a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #21 0x0000000004f21125 _start (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc+0x4f21125)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll
# `-----------------------------
# error: command failed with exit status: 2

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@ambergorzynski ambergorzynski changed the title [WIP][Don't merge] [WIP][Don't merge] New test for untested case in SILowerI1Copies Mar 12, 2026
@mgcarrasco mgcarrasco changed the title [WIP][Don't merge] New test for untested case in SILowerI1Copies [NFC] New test for untested case in SILowerI1Copies Mar 13, 2026
@mgcarrasco
mgcarrasco marked this pull request as ready for review March 13, 2026 10:30
@llvmbot

llvmbot commented Mar 13, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-backend-amdgpu

Author: None (ambergorzynski)

Changes

This line is untested by the existing LLVM test suite (checked using code coverage and by inserting an abort).

We propose a new test that exercises this case. The test is demonstrated by adding an abort to show that it is the only test that fails (the abort is removed before merging).


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

1 Files Affected:

  • (added) llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll (+149)
diff --git a/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll b/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll
new file mode 100644
index 0000000000000..afc2d830e1743
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/si-lower-i1-copies.ll
@@ -0,0 +1,149 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -O1 < %s | FileCheck %s
+
+declare void @bar(ptr captures(none)) #0
+
+define void @foo(i32 %0) #0 {
+; CHECK-LABEL: foo:
+; CHECK:       ; %bb.0: ; %entry
+; CHECK-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; CHECK-NEXT:    s_mov_b32 s16, s33
+; CHECK-NEXT:    s_mov_b32 s33, s32
+; CHECK-NEXT:    s_or_saveexec_b64 s[18:19], -1
+; CHECK-NEXT:    buffer_store_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Spill
+; CHECK-NEXT:    s_mov_b64 exec, s[18:19]
+; CHECK-NEXT:    v_writelane_b32 v42, s16, 20
+; CHECK-NEXT:    s_addk_i32 s32, 0x400
+; CHECK-NEXT:    buffer_store_dword v40, off, s[0:3], s33 offset:4 ; 4-byte Folded Spill
+; CHECK-NEXT:    buffer_store_dword v41, off, s[0:3], s33 ; 4-byte Folded Spill
+; CHECK-NEXT:    v_writelane_b32 v42, s30, 0
+; CHECK-NEXT:    v_writelane_b32 v42, s31, 1
+; CHECK-NEXT:    v_writelane_b32 v42, s34, 2
+; CHECK-NEXT:    v_writelane_b32 v42, s35, 3
+; CHECK-NEXT:    v_writelane_b32 v42, s36, 4
+; CHECK-NEXT:    v_writelane_b32 v42, s37, 5
+; CHECK-NEXT:    v_writelane_b32 v42, s38, 6
+; CHECK-NEXT:    v_writelane_b32 v42, s39, 7
+; CHECK-NEXT:    v_writelane_b32 v42, s48, 8
+; CHECK-NEXT:    v_writelane_b32 v42, s49, 9
+; CHECK-NEXT:    v_writelane_b32 v42, s50, 10
+; CHECK-NEXT:    v_writelane_b32 v42, s51, 11
+; CHECK-NEXT:    v_writelane_b32 v42, s52, 12
+; CHECK-NEXT:    v_writelane_b32 v42, s53, 13
+; CHECK-NEXT:    v_writelane_b32 v42, s54, 14
+; CHECK-NEXT:    v_writelane_b32 v42, s55, 15
+; CHECK-NEXT:    v_writelane_b32 v42, s64, 16
+; CHECK-NEXT:    v_writelane_b32 v42, s65, 17
+; CHECK-NEXT:    v_writelane_b32 v42, s66, 18
+; CHECK-NEXT:    v_writelane_b32 v42, s67, 19
+; CHECK-NEXT:    v_mov_b32_e32 v40, v31
+; CHECK-NEXT:    v_mov_b32_e32 v41, v0
+; CHECK-NEXT:    s_mov_b32 s52, s15
+; CHECK-NEXT:    s_mov_b32 s53, s14
+; CHECK-NEXT:    s_mov_b32 s54, s13
+; CHECK-NEXT:    s_mov_b32 s55, s12
+; CHECK-NEXT:    s_mov_b64 s[34:35], s[10:11]
+; CHECK-NEXT:    s_mov_b64 s[36:37], s[8:9]
+; CHECK-NEXT:    s_mov_b64 s[38:39], s[6:7]
+; CHECK-NEXT:    s_mov_b64 s[48:49], s[4:5]
+; CHECK-NEXT:    s_mov_b64 s[64:65], 0
+; CHECK-NEXT:    v_cmp_gt_i32_e64 s[50:51], 0, v41
+; CHECK-NEXT:    ; implicit-def: $sgpr4_sgpr5
+; CHECK-NEXT:    s_mov_b64 s[6:7], 0
+; CHECK-NEXT:    s_branch .LBB0_2
+; CHECK-NEXT:  .LBB0_1: ; %Flow
+; CHECK-NEXT:    ; in Loop: Header=BB0_2 Depth=1
+; CHECK-NEXT:    s_or_b64 exec, exec, s[66:67]
+; CHECK-NEXT:    s_and_b64 s[4:5], exec, s[6:7]
+; CHECK-NEXT:    s_or_b64 s[64:65], s[4:5], s[64:65]
+; CHECK-NEXT:    ; implicit-def: $sgpr4_sgpr5
+; CHECK-NEXT:    s_mov_b64 s[6:7], 0
+; CHECK-NEXT:    s_andn2_b64 exec, exec, s[64:65]
+; CHECK-NEXT:    s_cbranch_execz .LBB0_5
+; CHECK-NEXT:  .LBB0_2: ; %for.cond
+; CHECK-NEXT:    ; =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:    v_cmp_lt_i32_e32 vcc, -1, v41
+; CHECK-NEXT:    s_andn2_b64 s[4:5], s[4:5], exec
+; CHECK-NEXT:    s_and_b64 s[8:9], s[50:51], exec
+; CHECK-NEXT:    s_or_b64 s[4:5], s[4:5], s[8:9]
+; CHECK-NEXT:    s_or_b64 s[6:7], vcc, s[6:7]
+; CHECK-NEXT:    s_andn2_b64 exec, exec, s[6:7]
+; CHECK-NEXT:    s_cbranch_execnz .LBB0_2
+; CHECK-NEXT:  ; %bb.3: ; %BB
+; CHECK-NEXT:    ; in Loop: Header=BB0_2 Depth=1
+; CHECK-NEXT:    s_or_b64 exec, exec, s[6:7]
+; CHECK-NEXT:    s_mov_b64 s[6:7], -1
+; CHECK-NEXT:    s_and_saveexec_b64 s[66:67], s[4:5]
+; CHECK-NEXT:    s_cbranch_execz .LBB0_1
+; CHECK-NEXT:  ; %bb.4: ; %for.body
+; CHECK-NEXT:    ; in Loop: Header=BB0_2 Depth=1
+; CHECK-NEXT:    s_getpc_b64 s[4:5]
+; CHECK-NEXT:    s_add_u32 s4, s4, bar@gotpcrel32@lo+4
+; CHECK-NEXT:    s_addc_u32 s5, s5, bar@gotpcrel32@hi+12
+; CHECK-NEXT:    s_load_dwordx2 s[16:17], s[4:5], 0x0
+; CHECK-NEXT:    v_mov_b32_e32 v1, 0
+; CHECK-NEXT:    s_mov_b64 s[4:5], s[48:49]
+; CHECK-NEXT:    s_mov_b64 s[6:7], s[38:39]
+; CHECK-NEXT:    s_mov_b64 s[8:9], s[36:37]
+; CHECK-NEXT:    s_mov_b64 s[10:11], s[34:35]
+; CHECK-NEXT:    s_mov_b32 s12, s55
+; CHECK-NEXT:    s_mov_b32 s13, s54
+; CHECK-NEXT:    s_mov_b32 s14, s53
+; CHECK-NEXT:    s_mov_b32 s15, s52
+; CHECK-NEXT:    v_mov_b32_e32 v31, v40
+; CHECK-NEXT:    s_waitcnt lgkmcnt(0)
+; CHECK-NEXT:    s_swappc_b64 s[30:31], s[16:17]
+; CHECK-NEXT:    s_xor_b64 s[6:7], exec, -1
+; CHECK-NEXT:    s_branch .LBB0_1
+; CHECK-NEXT:  .LBB0_5: ; %for.cond.cleanup
+; CHECK-NEXT:    s_or_b64 exec, exec, s[64:65]
+; CHECK-NEXT:    v_readlane_b32 s67, v42, 19
+; CHECK-NEXT:    v_readlane_b32 s66, v42, 18
+; CHECK-NEXT:    v_readlane_b32 s65, v42, 17
+; CHECK-NEXT:    v_readlane_b32 s64, v42, 16
+; CHECK-NEXT:    v_readlane_b32 s55, v42, 15
+; CHECK-NEXT:    v_readlane_b32 s54, v42, 14
+; CHECK-NEXT:    v_readlane_b32 s53, v42, 13
+; CHECK-NEXT:    v_readlane_b32 s52, v42, 12
+; CHECK-NEXT:    v_readlane_b32 s51, v42, 11
+; CHECK-NEXT:    v_readlane_b32 s50, v42, 10
+; CHECK-NEXT:    v_readlane_b32 s49, v42, 9
+; CHECK-NEXT:    v_readlane_b32 s48, v42, 8
+; CHECK-NEXT:    v_readlane_b32 s39, v42, 7
+; CHECK-NEXT:    v_readlane_b32 s38, v42, 6
+; CHECK-NEXT:    v_readlane_b32 s37, v42, 5
+; CHECK-NEXT:    v_readlane_b32 s36, v42, 4
+; CHECK-NEXT:    v_readlane_b32 s35, v42, 3
+; CHECK-NEXT:    v_readlane_b32 s34, v42, 2
+; CHECK-NEXT:    v_readlane_b32 s31, v42, 1
+; CHECK-NEXT:    v_readlane_b32 s30, v42, 0
+; CHECK-NEXT:    buffer_load_dword v41, off, s[0:3], s33 ; 4-byte Folded Reload
+; CHECK-NEXT:    buffer_load_dword v40, off, s[0:3], s33 offset:4 ; 4-byte Folded Reload
+; CHECK-NEXT:    s_mov_b32 s32, s33
+; CHECK-NEXT:    v_readlane_b32 s4, v42, 20
+; CHECK-NEXT:    s_or_saveexec_b64 s[6:7], -1
+; CHECK-NEXT:    buffer_load_dword v42, off, s[0:3], s33 offset:8 ; 4-byte Folded Reload
+; CHECK-NEXT:    s_mov_b64 exec, s[6:7]
+; CHECK-NEXT:    s_mov_b32 s33, s4
+; CHECK-NEXT:    s_waitcnt vmcnt(0)
+; CHECK-NEXT:    s_setpc_b64 s[30:31]
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.body, %for.cond, %entry
+  %cmp1 = icmp slt i32 %0, 0
+  br i1 %cmp1, label %for.cond, label %BB
+
+BB:                                               ; preds = %for.cond
+  br i1 %cmp1, label %for.body, label %for.cond.cleanup
+
+for.cond.cleanup:                                 ; preds = %BB
+  ret void
+
+for.body:                                         ; preds = %BB
+  call void @bar(ptr poison)
+  br label %for.cond
+}
+
+attributes #0 = { nounwind }
+

@ro-i ro-i 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.

LGTM, given that the test is already reduced/minimal

@@ -0,0 +1,149 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=amdgcn-amd-amdhsa -O1 < %s | FileCheck %s

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.

Shouldn't need -O1

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.

Without -O1, the untested case is no longer covered (tested by finding that without -O1, the test no longer fails in the presence of the abort)

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.

si-lower-i1-copies runs regardless of the optimization level, right?

It runs after AMDGPU DAG->DAG Pattern Instruction Selection and SI Fix SGPR copies which also run regardless of the optimization level.

In that case, would it be possible to recover the LLVM-IR just before instruction selection and try compiling that code without -O1?

@jmmartinez jmmartinez Mar 17, 2026 •

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.

Edit: maybe stop before the structurizer and see if that works (pass --stop-before=structurizecfg to llc). Otherwise you'll have to use --start-before= which may be awkward.

@@ -0,0 +1,149 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=amdgcn-amd-amdhsa -O1 < %s | FileCheck %s

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.

Test name is too general, can you add this to an existing test

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.

The existing tests for this pass are in MIR rather than LLVM IR. Do you think it would be better for me to convert this test to MIR also?

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.

Probably yes, especially if it's dependent on -O1

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.

I converted to MIR, renamed, and added to an existing test file for this pass. It now runs just the si-i1-copies pass. The existing test didn't have checks so I added them for the whole file using utils/update_mir_test_checks.py. I checked that the test still works as intended: it fails only if an abort is inserted in the untested case (I can push some evidence of this if you like).

Let me know any other changes I should make.

@ambergorzynski
ambergorzynski requested a review from arsenm March 17, 2026 10:01
@ambergorzynski ambergorzynski changed the title [NFC] New test for untested case in SILowerI1Copies [NFC][AMDGPU] New test for untested case in SILowerI1Copies Mar 17, 2026
@jmmartinez
jmmartinez merged commit c63ce62 into llvm:main Mar 19, 2026
8 checks passed
@ambergorzynski
ambergorzynski deleted the amd-be-test-siloweri1copies branch March 27, 2026 15:05
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.

6 participants