-
Notifications
You must be signed in to change notification settings - Fork 15.9k
[AMDGPU] Add legalization rules for atomic ops #175253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264 changes: 264 additions & 0 deletions
264
llvm/test/CodeGen/AMDGPU/GlobalISel/atomicrmw-add-sub.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1200 < %s | FileCheck -check-prefixes=GFX12 %s | ||
|
|
||
| ; Test atomicrmw add and sub operations for different address spaces | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw add - global address space (addrspace 1) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_add_i32_global(ptr addrspace(1) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i32_global: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_add_u32 v0, v[0:1], v2, off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr addrspace(1) %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_add_i64_global(ptr addrspace(1) %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i64_global: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_add_u64 v[0:1], v[0:1], v[2:3], off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr addrspace(1) %ptr, i64 %val seq_cst | ||
| ret i64 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw add - local address space (addrspace 3) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_add_i32_local(ptr addrspace(3) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i32_local: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: ds_add_rtn_u32 v0, v0, v1 | ||
| ; GFX12-NEXT: s_wait_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SE | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr addrspace(3) %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_add_i64_local(ptr addrspace(3) %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i64_local: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: ds_add_rtn_u64 v[0:1], v0, v[1:2] | ||
| ; GFX12-NEXT: s_wait_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SE | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr addrspace(3) %ptr, i64 %val seq_cst | ||
| ret i64 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw sub - local address space (addrspace 3) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_sub_i32_local(ptr addrspace(3) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i32_local: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: ds_sub_rtn_u32 v0, v0, v1 | ||
| ; GFX12-NEXT: s_wait_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SE | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(3) %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_sub_i64_local(ptr addrspace(3) %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i64_local: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: ds_sub_rtn_u64 v[0:1], v0, v[1:2] | ||
| ; GFX12-NEXT: s_wait_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SE | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(3) %ptr, i64 %val seq_cst | ||
| ret i64 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw add - flat address space (addrspace 0) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_add_i32_flat(ptr %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i32_flat: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: flat_atomic_add_u32 v0, v[0:1], v2 th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_add_i64_flat(ptr %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_add_i64_flat: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: flat_atomic_add_u64 v[0:1], v[0:1], v[2:3] th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr %ptr, i64 %val seq_cst, !noalias.addrspace !1 | ||
| ret i64 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw add - VGPR inputs (loaded from memory) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_add_i32_global_vgpr(ptr addrspace(1) %ptr, ptr addrspace(1) %val_ptr) { | ||
| ; GFX12-LABEL: atomicrmw_add_i32_global_vgpr: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_load_b32 v2, v[2:3], off | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_add_u32 v0, v[0:1], v2, off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %val = load i32, ptr addrspace(1) %val_ptr | ||
| %result = atomicrmw add ptr addrspace(1) %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw sub with metadata - global address space (no expansion) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_sub_i32_global_no_remote_memory(ptr addrspace(1) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i32_global_no_remote_memory: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_sub_u32 v0, v[0:1], v2, off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(1) %ptr, i32 %val seq_cst, !amdgpu.no.remote.memory !0 | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_sub_i64_global_no_remote_memory(ptr addrspace(1) %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i64_global_no_remote_memory: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_sub_u64 v[0:1], v[0:1], v[2:3], off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(1) %ptr, i64 %val seq_cst, !amdgpu.no.remote.memory !0 | ||
| ret i64 %result | ||
| } | ||
|
|
||
| define i32 @atomicrmw_sub_i32_global_no_fine_grained_memory(ptr addrspace(1) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i32_global_no_fine_grained_memory: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_sub_u32 v0, v[0:1], v2, off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(1) %ptr, i32 %val seq_cst, !amdgpu.no.fine.grained.memory !0 | ||
| ret i32 %result | ||
| } | ||
|
|
||
| define i64 @atomicrmw_sub_i64_global_no_fine_grained_memory(ptr addrspace(1) %ptr, i64 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_i64_global_no_fine_grained_memory: | ||
| ; GFX12: ; %bb.0: | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: s_wait_expcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_samplecnt 0x0 | ||
| ; GFX12-NEXT: s_wait_bvhcnt 0x0 | ||
| ; GFX12-NEXT: s_wait_kmcnt 0x0 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_sub_u64 v[0:1], v[0:1], v[2:3], off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(1) %ptr, i64 %val seq_cst, !amdgpu.no.fine.grained.memory !0 | ||
| ret i64 %result | ||
| } | ||
|
|
||
| !0 = !{} | ||
| !1 = !{i32 5, i32 6} ; Exclude private address space (5) to prevent expansion |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.