[llvm] [NVPTX] Add intrinsics for st.bulk instruction (PR #128856)
Srinivasa Ravi via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 27 20:44:02 PST 2025
https://github.com/Wolfram70 updated https://github.com/llvm/llvm-project/pull/128856
>From 18452f07d219c114a2d50afb23008663c598f2a6 Mon Sep 17 00:00:00 2001
From: Srinivasa Ravi <srinivasar at nvidia.com>
Date: Mon, 24 Feb 2025 19:37:31 +0530
Subject: [PATCH] [NVPTX] Add intrinsics for st.bulk instruction
Adds NVVM intrinsics and NVPTX codegen for the `st.bulk` instruction
introduced in ptx8.6 for sm_100. Tests added in `CodeGen/NVPTX/st_bulk.ll`
and verified through ptxas 12.8.0.
PTX Spec Reference: https://docs.nvidia.com/cuda/parallel-thread-execution/#data-movement-and-conversion-instructions-st-bulk
---
llvm/include/llvm/IR/IntrinsicsNVVM.td | 14 ++++++++
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td | 20 +++++++++++
llvm/test/CodeGen/NVPTX/st_bulk.ll | 46 ++++++++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 llvm/test/CodeGen/NVPTX/st_bulk.ll
diff --git a/llvm/include/llvm/IR/IntrinsicsNVVM.td b/llvm/include/llvm/IR/IntrinsicsNVVM.td
index 72b05bca08940..08ca1e2edbdbc 100644
--- a/llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ b/llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -5261,4 +5261,18 @@ foreach shape = ["16x64b", "16x128b", "16x256b", "32x32b", "16x32bx2"] in {
}
}
+//
+// Bulk store intrinsics
+//
+
+def int_nvvm_st_bulk: Intrinsic<[],
+ [llvm_global_ptr_ty, llvm_i64_ty, llvm_i64_ty],
+ [IntrArgMemOnly, IntrWriteMem,
+ WriteOnly<ArgIndex<0>>, NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<2>>]>;
+
+def int_nvvm_st_bulk_shared_cta : Intrinsic<[],
+ [llvm_shared_ptr_ty, llvm_i64_ty, llvm_i64_ty],
+ [IntrArgMemOnly, IntrWriteMem,
+ WriteOnly<ArgIndex<0>>, NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<2>>]>;
+
} // let TargetPrefix = "nvvm"
diff --git a/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td b/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
index bcb3f05f3f8a8..19f954129f943 100644
--- a/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ b/llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -7816,3 +7816,23 @@ foreach shape = ["16x64b", "16x128b", "16x256b", "32x32b", "16x32bx2"] in {
}
} // isConvergent
+
+// Bulk store instructions
+
+def INT_NVVM_ST_BULK_GENERIC :
+ NVPTXInst<(outs), (ins Int64Regs:$dest_addr, Int64Regs:$size),
+ "st.bulk [$dest_addr], $size, 0;",
+ [(int_nvvm_st_bulk i64:$dest_addr, i64:$size, (i64 0))]>,
+ Requires<[hasSM<100>, hasPTX<86>]>;
+
+def INT_NVVM_ST_BULK_SHARED_CTA:
+ NVPTXInst<(outs), (ins Int64Regs:$dest_addr, Int64Regs:$size),
+ "st.bulk.shared::cta [$dest_addr], $size, 0;",
+ [(int_nvvm_st_bulk_shared_cta i64:$dest_addr, i64:$size, (i64 0))]>,
+ Requires<[hasSM<100>, hasPTX<86>]>;
+
+def INT_NVVM_ST_BULK_SHARED_CTA_SHARED32:
+ NVPTXInst<(outs), (ins Int32Regs:$dest_addr, Int64Regs:$size),
+ "st.bulk.shared::cta [$dest_addr], $size, 0;",
+ [(int_nvvm_st_bulk_shared_cta i32:$dest_addr, i64:$size, (i64 0))]>,
+ Requires<[hasSM<100>, hasPTX<86>]>;
diff --git a/llvm/test/CodeGen/NVPTX/st_bulk.ll b/llvm/test/CodeGen/NVPTX/st_bulk.ll
new file mode 100644
index 0000000000000..085df7f1d8d3f
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/st_bulk.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_100 -mattr=+ptx86 | FileCheck --check-prefixes=CHECK,CHECK-PTX64 %s
+; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_100 -mattr=+ptx86 --nvptx-short-ptr | FileCheck --check-prefixes=CHECK,CHECK-PTX-SHARED32 %s
+; RUN: %if ptxas-12.8 %{ llc < %s -mtriple=nvptx64 -mcpu=sm_100 -mattr=+ptx86 | %ptxas-verify -arch=sm_100 %}
+; RUN: %if ptxas-12.8 %{ llc < %s -mtriple=nvptx64 -mcpu=sm_100 -mattr=+ptx86 --nvptx-short-ptr | %ptxas-verify -arch=sm_100 %}
+
+declare void @llvm.nvvm.st.bulk(ptr addrspace(1), i64, i64)
+define void @st_bulk(ptr addrspace(1) %dest_addr, i64 %size) {
+; CHECK-LABEL: st_bulk(
+; CHECK: {
+; CHECK-NEXT: .reg .b64 %rd<3>;
+; CHECK-EMPTY:
+; CHECK-NEXT: // %bb.0:
+; CHECK-NEXT: ld.param.u64 %rd1, [st_bulk_param_0];
+; CHECK-NEXT: ld.param.u64 %rd2, [st_bulk_param_1];
+; CHECK-NEXT: st.bulk [%rd1], %rd2, 0;
+; CHECK-NEXT: ret;
+ call void @llvm.nvvm.st.bulk(ptr addrspace(1) %dest_addr, i64 %size, i64 0)
+ ret void
+}
+
+declare void @llvm.nvvm.st.bulk.shared.cta(ptr addrspace(3), i64, i64)
+define void @st_bulk_shared_cta(ptr addrspace(3) %dest_addr, i64 %size) {
+; CHECK-PTX64-LABEL: st_bulk_shared_cta(
+; CHECK-PTX64: {
+; CHECK-PTX64-NEXT: .reg .b64 %rd<3>;
+; CHECK-PTX64-EMPTY:
+; CHECK-PTX64-NEXT: // %bb.0:
+; CHECK-PTX64-NEXT: ld.param.u64 %rd1, [st_bulk_shared_cta_param_0];
+; CHECK-PTX64-NEXT: ld.param.u64 %rd2, [st_bulk_shared_cta_param_1];
+; CHECK-PTX64-NEXT: st.bulk.shared::cta [%rd1], %rd2, 0;
+; CHECK-PTX64-NEXT: ret;
+;
+; CHECK-PTX-SHARED32-LABEL: st_bulk_shared_cta(
+; CHECK-PTX-SHARED32: {
+; CHECK-PTX-SHARED32-NEXT: .reg .b32 %r<2>;
+; CHECK-PTX-SHARED32-NEXT: .reg .b64 %rd<2>;
+; CHECK-PTX-SHARED32-EMPTY:
+; CHECK-PTX-SHARED32-NEXT: // %bb.0:
+; CHECK-PTX-SHARED32-NEXT: ld.param.u32 %r1, [st_bulk_shared_cta_param_0];
+; CHECK-PTX-SHARED32-NEXT: ld.param.u64 %rd1, [st_bulk_shared_cta_param_1];
+; CHECK-PTX-SHARED32-NEXT: st.bulk.shared::cta [%r1], %rd1, 0;
+; CHECK-PTX-SHARED32-NEXT: ret;
+ call void @llvm.nvvm.st.bulk.shared.cta(ptr addrspace(3) %dest_addr, i64 %size, i64 0)
+ ret void
+}
More information about the llvm-commits
mailing list