-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NVPTX] Add TTI support for folding isspacep in InferAS #114486
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
AlexMaclean
merged 4 commits into
llvm:main
from
AlexMaclean:dev/amaclean/upstream-isspacep-mso-1
Nov 8, 2024
Merged
Changes from all commits
Commits
Show all changes
4 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
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
144 changes: 144 additions & 0 deletions
144
llvm/test/Transforms/InferAddressSpaces/NVPTX/isspacep.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,144 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -mtriple=nvptx64-nvidia-cuda -passes=infer-address-spaces,bdce %s | FileCheck %s | ||
|
||
target datalayout = "e-p:64:64:64-p3:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" | ||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
declare i1 @llvm.nvvm.isspacep.const(ptr) readnone noinline | ||
declare i1 @llvm.nvvm.isspacep.global(ptr) readnone noinline | ||
declare i1 @llvm.nvvm.isspacep.local(ptr) readnone noinline | ||
declare i1 @llvm.nvvm.isspacep.shared(ptr) readnone noinline | ||
declare i1 @llvm.nvvm.isspacep.cluster.shared(ptr) readnone noinline | ||
|
||
define i1 @test_isspacep_const_true(ptr addrspace(4) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_const_true( | ||
; CHECK-SAME: ptr addrspace(4) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(4) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.const(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_const_false(ptr addrspace(1) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_const_false( | ||
; CHECK-SAME: ptr addrspace(1) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(1) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.const(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_global_true(ptr addrspace(1) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_global_true( | ||
; CHECK-SAME: ptr addrspace(1) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(1) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.global(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_global_false(ptr addrspace(4) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_global_false( | ||
; CHECK-SAME: ptr addrspace(4) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(4) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.global(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_local_true(ptr addrspace(5) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_local_true( | ||
; CHECK-SAME: ptr addrspace(5) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(5) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.local(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_local_false(ptr addrspace(1) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_local_false( | ||
; CHECK-SAME: ptr addrspace(1) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(1) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.local(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_shared_true(ptr addrspace(3) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_shared_true( | ||
; CHECK-SAME: ptr addrspace(3) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(3) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.shared(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_shared_false(ptr addrspace(1) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_shared_false( | ||
; CHECK-SAME: ptr addrspace(1) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(1) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.shared(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_cluster_shared_unsure(ptr addrspace(3) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_cluster_shared_unsure( | ||
; CHECK-SAME: ptr addrspace(3) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[ADDR1:%.*]] = getelementptr i8, ptr addrspace(3) [[ADDR]], i32 10 | ||
; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast ptr addrspace(3) [[ADDR1]] to ptr | ||
; CHECK-NEXT: [[VAL:%.*]] = call i1 @llvm.nvvm.isspacep.shared.cluster(ptr [[TMP0]]) | ||
; CHECK-NEXT: ret i1 [[VAL]] | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(3) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.shared.cluster(ptr %addr1) | ||
ret i1 %val | ||
} | ||
|
||
define i1 @test_isspacep_cluster_shared_false(ptr addrspace(1) %addr) { | ||
; CHECK-LABEL: define i1 @test_isspacep_cluster_shared_false( | ||
; CHECK-SAME: ptr addrspace(1) [[ADDR:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
entry: | ||
%addr0 = addrspacecast ptr addrspace(1) %addr to ptr | ||
%addr1 = getelementptr i8, ptr %addr0, i32 10 | ||
%val = call i1 @llvm.nvvm.isspacep.shared.cluster(ptr %addr1) | ||
ret i1 %val | ||
} |
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.
Do we still need this attempt to peek through the ASC then? If we do manage to see original AS, so would the
infer-address-spaces
pass, and it would have folded the intrinsic into a constant.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.
Yea, I would assume that
infer-address-spaces
would handle all these cases we do ininstcombine
, Though maybe doing it ininstcombine
will allow some cases to happen earlier.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.
Where do we run AS inference pass in the pipeline? If it's early, then I think it would make sense to keep isspacep folding in one place only, and AS inference pass looks like a better place for that.
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.
Looks like it is only run in
llc
. I see AMDGPU runs this pass inopt
so we should maybe consider doing the same, but I'm not sure how we'd make that decision.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.
OK. Add a TODO comment there for now and we'll handle it separately.