-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[NVPTX] Improve modeling of inline PTX #130675
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 3 commits into
llvm:main
from
AlexMaclean:dev/amaclean/upstream/better-inline-asm
Mar 25, 2025
Merged
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py | ||
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output < %s | FileCheck %s | ||
|
||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
define void @test1() { | ||
; CHECK-LABEL: 'test1' | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call double asm "rsqrt.approx.ftz.f64 $0, $1;", "=d,d"(double 1.000000e+00) | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %2 = call { i32, i32 } asm "{\0A\09mad.lo.cc.u32 $0, $2, $3, $4;\0A\09madc.hi.u32 $1, $2, $3, 0;\0A\09}", "=r,=r,r,r,r"(i32 2, i32 3, i32 3) | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %3 = call i32 asm sideeffect "{ \0A\09.reg .pred \09%p1; \0A\09setp.ne.u32 \09%p1, $1, 0; \0A\09vote.ballot.b32 \09$0, %p1; \0A\09}", "=r,r"(i32 0) | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %4 = call i32 asm sideeffect "{ \0A\09.reg .pred \09%p1; \0A\09setp.ne.u32 \09%p1, $1, 0; \0A\09@%p1 exit; \0A\09}", "=r,r"(i32 0) | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void asm sideeffect ".pragma \22nounroll\22;\0A\09", "~{memory}"() | ||
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void | ||
; | ||
%1 = call double asm "rsqrt.approx.ftz.f64 $0, $1;", "=d,d"(double 1.0) | ||
%2 = call { i32, i32 } asm "{\0A\09mad.lo.cc.u32 $0, $2, $3, $4;\0A\09madc.hi.u32 $1, $2, $3, 0;\0A\09}", "=r,=r,r,r,r"(i32 2, i32 3, i32 3) | ||
%3 = call i32 asm sideeffect "{ \0A\09.reg .pred \09%p1; \0A\09setp.ne.u32 \09%p1, $1, 0; \0A\09vote.ballot.b32 \09$0, %p1; \0A\09}", "=r,r"(i32 0) | ||
%4 = call i32 asm sideeffect "{ \0A\09.reg .pred \09%p1; \0A\09setp.ne.u32 \09%p1, $1, 0; \0A\09@%p1 exit; \0A\09}", "=r,r"(i32 0) | ||
call void asm sideeffect ".pragma \22nounroll\22;\0A\09", "~{memory}"() | ||
ret void | ||
} |
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,2 @@ | ||
if not "NVPTX" in config.root.targets: | ||
config.unsupported = True |
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,47 @@ | ||
; RUN: opt -passes=aa-eval -aa-pipeline=nvptx-aa,basic-aa -print-all-alias-modref-info < %s -disable-output 2>&1 \ | ||
; RUN: | FileCheck %s --check-prefixes CHECK-ALIAS | ||
|
||
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64" | ||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
;;CHECK-ALIAS-LABEL: Function: test_sideeffect | ||
;;CHECK-ALIAS: Both ModRef: Ptr: i32* %0 <-> call | ||
define void @test_sideeffect(ptr %out) { | ||
entry: | ||
%0 = addrspacecast ptr %out to ptr addrspace(1) | ||
call void asm sideeffect "membar.gl;", ""() | ||
store i32 5, ptr addrspace(1) %0, align 4 | ||
ret void | ||
} | ||
|
||
;;CHECK-ALIAS-LABEL: Function: test_indirect | ||
;;CHECK-ALIAS: Both ModRef: Ptr: i32* %0 <-> %1 = call | ||
define i32 @test_indirect(ptr %out) { | ||
entry: | ||
%0 = addrspacecast ptr %out to ptr addrspace(1) | ||
store i32 0, ptr addrspace(1) %0, align 4 | ||
%1 = call i32 asm "ld.global.u32 $0, [$1];", "=r,*m"(ptr addrspace(1) elementtype(i32) %0) | ||
store i32 0, ptr addrspace(1) %0, align 4 | ||
ret i32 %1 | ||
} | ||
|
||
;;CHECK-ALIAS-LABEL: Function: test_memory | ||
;;CHECK-ALIAS: Both ModRef: Ptr: i32* %0 <-> %1 = call | ||
define i32 @test_memory(ptr %out) { | ||
entry: | ||
%0 = addrspacecast ptr %out to ptr addrspace(1) | ||
store i32 0, ptr addrspace(1) %0, align 4 | ||
%1 = call i32 asm "ld.global.u32 $0, [$1];", "=r,l,~{memory}"(ptr addrspace(1) %0) | ||
store i32 0, ptr addrspace(1) %0, align 4 | ||
ret i32 %1 | ||
} | ||
|
||
;;CHECK-ALIAS-LABEL: Function: test_no_sideeffect | ||
;;CHECK-ALIAS: NoModRef: Ptr: i32* %0 <-> %1 = call | ||
define void @test_no_sideeffect(ptr %in, ptr %out) { | ||
entry: | ||
%0 = addrspacecast ptr %out to ptr addrspace(1) | ||
%1 = call i32 asm "cvt.u32.u64 $0, $1;", "=r,l"(ptr %in) | ||
store i32 %1, ptr addrspace(1) %0, 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.