-
Notifications
You must be signed in to change notification settings - Fork 16.1k
[AMDGPU] Add legalization rules for G_AMDGPU_BUFFER_ATOMIC_FADD #175258
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
Draft
gandhi56
wants to merge
3
commits into
llvm:main
Choose a base branch
from
gandhi56:globalisel/g_amdgpu_buffer_atomic_fadd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
235 changes: 235 additions & 0 deletions
235
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,235 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -global-isel -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_wait_loadcnt 0x0 | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr addrspace(1) %ptr, i64 %val seq_cst | ||
| ret i64 %result | ||
| } | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw sub - global address space (addrspace 1) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_sub_i32_global(ptr addrspace(1) %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_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_load_b32 v3, v[0:1], off | ||
| ; GFX12-NEXT: s_mov_b32 s0, 0 | ||
| ; GFX12-NEXT: .LBB2_1: ; %atomicrmw.start | ||
| ; GFX12-NEXT: ; =>This Inner Loop Header: Depth=1 | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: v_mov_b32_e32 v4, v3 | ||
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | ||
| ; GFX12-NEXT: v_sub_nc_u32_e32 v3, v4, v2 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: global_atomic_cmpswap_b32 v3, v[0:1], v[3:4], off th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: v_cmp_eq_u32_e32 vcc_lo, v3, v4 | ||
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | ||
| ; GFX12-NEXT: s_or_b32 s0, vcc_lo, s0 | ||
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | ||
| ; GFX12-NEXT: s_and_not1_b32 exec_lo, exec_lo, s0 | ||
| ; GFX12-NEXT: s_cbranch_execnz .LBB2_1 | ||
| ; GFX12-NEXT: ; %bb.2: ; %atomicrmw.end | ||
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s0 | ||
| ; GFX12-NEXT: v_mov_b32_e32 v0, v3 | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr addrspace(1) %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| ; TODO: Add test for atomicrmw_sub_i64_global when G_PHI is supported | ||
|
|
||
| ; ============================================================================= | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; 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_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw add ptr %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| ; TODO: Add test for atomicrmw_add_i64_flat when G_PHI is supported | ||
|
|
||
| ; ============================================================================= | ||
| ; atomicrmw sub - flat address space (addrspace 0) | ||
| ; ============================================================================= | ||
|
|
||
| define i32 @atomicrmw_sub_i32_flat(ptr %ptr, i32 %val) { | ||
| ; GFX12-LABEL: atomicrmw_sub_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: flat_load_b32 v3, v[0:1] | ||
| ; GFX12-NEXT: s_mov_b32 s0, 0 | ||
| ; GFX12-NEXT: .LBB8_1: ; %atomicrmw.start | ||
| ; GFX12-NEXT: ; =>This Inner Loop Header: Depth=1 | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: v_mov_b32_e32 v4, v3 | ||
| ; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | ||
| ; GFX12-NEXT: v_sub_nc_u32_e32 v3, v4, v2 | ||
| ; GFX12-NEXT: global_wb scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_storecnt 0x0 | ||
| ; GFX12-NEXT: flat_atomic_cmpswap_b32 v3, v[0:1], v[3:4] th:TH_ATOMIC_RETURN scope:SCOPE_SYS | ||
| ; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0 | ||
| ; GFX12-NEXT: global_inv scope:SCOPE_SYS | ||
| ; GFX12-NEXT: v_cmp_eq_u32_e32 vcc_lo, v3, v4 | ||
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | ||
| ; GFX12-NEXT: s_or_b32 s0, vcc_lo, s0 | ||
| ; GFX12-NEXT: s_wait_alu depctr_sa_sdst(0) | ||
| ; GFX12-NEXT: s_and_not1_b32 exec_lo, exec_lo, s0 | ||
| ; GFX12-NEXT: s_cbranch_execnz .LBB8_1 | ||
| ; GFX12-NEXT: ; %bb.2: ; %atomicrmw.end | ||
| ; GFX12-NEXT: s_or_b32 exec_lo, exec_lo, s0 | ||
| ; GFX12-NEXT: v_mov_b32_e32 v0, v3 | ||
| ; GFX12-NEXT: s_wait_loadcnt 0x0 | ||
| ; GFX12-NEXT: s_setpc_b64 s[30:31] | ||
| %result = atomicrmw sub ptr %ptr, i32 %val seq_cst | ||
| ret i32 %result | ||
| } | ||
|
|
||
| ; TODO: Add test for atomicrmw_sub_i64_flat when G_ICMP is supported |
10 changes: 5 additions & 5 deletions
10
llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f32-no-rtn.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
8 changes: 4 additions & 4 deletions
8
llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f32-rtn.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
4 changes: 2 additions & 2 deletions
4
llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.f64.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
6 changes: 3 additions & 3 deletions
6
llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.v2f16-no-rtn.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
4 changes: 2 additions & 2 deletions
4
llvm/test/CodeGen/AMDGPU/GlobalISel/buffer-atomic-fadd.v2f16-rtn.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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the buffer case