-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[AMDGPU] Fix edge case of buffer OOB handling #115479
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 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9099a05
[AMDGPU] Add target feature require-naturally-aligned-buffer-access
piotrAMD b78e15b
Rename function.
piotrAMD adbd8b3
Simplify test
piotrAMD 52b3d95
Add codegen test for problems with underaligned memory accesses
piotrAMD 13201b5
Handle globalisel in codegen test
piotrAMD f8feeab
Add more description
piotrAMD a031e09
Merge remote-tracking branch 'origin/main' into NATURALLY_ALIGNED
piotrAMD 26d046b
Invert target feature
piotrAMD 88346fb
Remove stray whitespace
piotrAMD 166dc3a
Improve comment
piotrAMD 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
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
80 changes: 80 additions & 0 deletions
80
llvm/test/Transforms/LoadStoreVectorizer/AMDGPU/unaligned-buffer.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,80 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -mtriple=amdgcn--amdpal -passes=load-store-vectorizer -mattr=+require-naturally-aligned-buffer-access -S -o - %s | FileCheck --check-prefix=ALIGNED %s | ||
| ; RUN: opt -mtriple=amdgcn--amdpal -passes=load-store-vectorizer -S -o - %s | FileCheck --check-prefixes=UNALIGNED %s | ||
|
|
||
| ; The test checks that require-naturally-aligned-buffer-access target feature prevents merging loads if the target load would not be naturally aligned. | ||
|
|
||
| define amdgpu_kernel void @merge_align_4(ptr addrspace(7) nocapture %p, ptr addrspace(7) nocapture %p2) #0 { | ||
| ; | ||
| ; ALIGNED-LABEL: define amdgpu_kernel void @merge_align_4( | ||
| ; ALIGNED-SAME: ptr addrspace(7) nocapture [[P:%.*]], ptr addrspace(7) nocapture [[P2:%.*]]) #[[ATTR0:[0-9]+]] { | ||
| ; ALIGNED-NEXT: [[ENTRY:.*:]] | ||
| ; ALIGNED-NEXT: [[GEP_M8:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 -8 | ||
| ; ALIGNED-NEXT: [[LD_M8:%.*]] = load i32, ptr addrspace(7) [[GEP_M8]], align 4 | ||
| ; ALIGNED-NEXT: [[GEP_M4:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 -4 | ||
| ; ALIGNED-NEXT: [[LD_M4:%.*]] = load i32, ptr addrspace(7) [[GEP_M4]], align 4 | ||
| ; ALIGNED-NEXT: [[GEP_0:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 0 | ||
| ; ALIGNED-NEXT: [[LD_0:%.*]] = load i32, ptr addrspace(7) [[GEP_0]], align 4 | ||
| ; ALIGNED-NEXT: [[GEP_4:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i64 4 | ||
| ; ALIGNED-NEXT: [[LD_4:%.*]] = load i32, ptr addrspace(7) [[GEP_4]], align 4 | ||
| ; ALIGNED-NEXT: ret void | ||
| ; | ||
| ; UNALIGNED-LABEL: define amdgpu_kernel void @merge_align_4( | ||
| ; UNALIGNED-SAME: ptr addrspace(7) nocapture [[P:%.*]], ptr addrspace(7) nocapture [[P2:%.*]]) { | ||
| ; UNALIGNED-NEXT: [[ENTRY:.*:]] | ||
| ; UNALIGNED-NEXT: [[GEP_M8:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 -8 | ||
| ; UNALIGNED-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr addrspace(7) [[GEP_M8]], align 4 | ||
| ; UNALIGNED-NEXT: [[LD_M81:%.*]] = extractelement <4 x i32> [[TMP0]], i32 0 | ||
| ; UNALIGNED-NEXT: [[LD_M42:%.*]] = extractelement <4 x i32> [[TMP0]], i32 1 | ||
| ; UNALIGNED-NEXT: [[LD_03:%.*]] = extractelement <4 x i32> [[TMP0]], i32 2 | ||
| ; UNALIGNED-NEXT: [[LD_44:%.*]] = extractelement <4 x i32> [[TMP0]], i32 3 | ||
| ; UNALIGNED-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %gep_m8 = getelementptr i8, ptr addrspace(7) %p, i32 -8 | ||
| %ld_m8 = load i32, ptr addrspace(7) %gep_m8, align 4 | ||
| %gep_m4 = getelementptr i8, ptr addrspace(7) %p, i32 -4 | ||
| %ld_m4 = load i32, ptr addrspace(7) %gep_m4, align 4 | ||
| %gep_0 = getelementptr i8, ptr addrspace(7) %p, i32 0 | ||
| %ld_0 = load i32, ptr addrspace(7) %gep_0, align 4 | ||
| %gep_4 = getelementptr i8, ptr addrspace(7) %p, i64 4 | ||
| %ld_4 = load i32, ptr addrspace(7) %gep_4, align 4 | ||
| ret void | ||
| } | ||
|
|
||
| ; The test checks that require-naturally-aligned-buffer-access target feature does not prevent merging loads if the target load would be naturally aligned. | ||
|
|
||
| define amdgpu_kernel void @merge_align_16(ptr addrspace(7) nocapture %p, ptr addrspace(7) nocapture %p2) #0 { | ||
| ; ALIGNED-LABEL: define amdgpu_kernel void @merge_align_16( | ||
| ; ALIGNED-SAME: ptr addrspace(7) nocapture [[P:%.*]], ptr addrspace(7) nocapture [[P2:%.*]]) #[[ATTR0]] { | ||
| ; ALIGNED-NEXT: [[ENTRY:.*:]] | ||
| ; ALIGNED-NEXT: [[GEP_M8:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 -8 | ||
| ; ALIGNED-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr addrspace(7) [[GEP_M8]], align 16 | ||
| ; ALIGNED-NEXT: [[LD_M81:%.*]] = extractelement <4 x i32> [[TMP0]], i32 0 | ||
| ; ALIGNED-NEXT: [[LD_M42:%.*]] = extractelement <4 x i32> [[TMP0]], i32 1 | ||
| ; ALIGNED-NEXT: [[LD_03:%.*]] = extractelement <4 x i32> [[TMP0]], i32 2 | ||
| ; ALIGNED-NEXT: [[LD_44:%.*]] = extractelement <4 x i32> [[TMP0]], i32 3 | ||
| ; ALIGNED-NEXT: ret void | ||
| ; | ||
| ; UNALIGNED-LABEL: define amdgpu_kernel void @merge_align_16( | ||
| ; UNALIGNED-SAME: ptr addrspace(7) nocapture [[P:%.*]], ptr addrspace(7) nocapture [[P2:%.*]]) { | ||
| ; UNALIGNED-NEXT: [[ENTRY:.*:]] | ||
| ; UNALIGNED-NEXT: [[GEP_M8:%.*]] = getelementptr i8, ptr addrspace(7) [[P]], i32 -8 | ||
| ; UNALIGNED-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr addrspace(7) [[GEP_M8]], align 16 | ||
| ; UNALIGNED-NEXT: [[LD_M81:%.*]] = extractelement <4 x i32> [[TMP0]], i32 0 | ||
| ; UNALIGNED-NEXT: [[LD_M42:%.*]] = extractelement <4 x i32> [[TMP0]], i32 1 | ||
| ; UNALIGNED-NEXT: [[LD_03:%.*]] = extractelement <4 x i32> [[TMP0]], i32 2 | ||
| ; UNALIGNED-NEXT: [[LD_44:%.*]] = extractelement <4 x i32> [[TMP0]], i32 3 | ||
| ; UNALIGNED-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %gep_m8 = getelementptr i8, ptr addrspace(7) %p, i32 -8 | ||
| %ld_m8 = load i32, ptr addrspace(7) %gep_m8, align 16 | ||
| %gep_m4 = getelementptr i8, ptr addrspace(7) %p, i32 -4 | ||
| %ld_m4 = load i32, ptr addrspace(7) %gep_m4, align 4 | ||
| %gep_0 = getelementptr i8, ptr addrspace(7) %p, i32 0 | ||
| %ld_0 = load i32, ptr addrspace(7) %gep_0, align 8 | ||
| %gep_4 = getelementptr i8, ptr addrspace(7) %p, i64 4 | ||
| %ld_4 = load i32, ptr addrspace(7) %gep_4, align 4 | ||
| ret void | ||
| } |
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.