[llvm] 5c9513a - [NVPTX] cap param alignment at 128 (max supported by ptx) (#96117)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 10:04:49 PDT 2024
Author: Alex MacLean
Date: 2024-06-25T10:04:45-07:00
New Revision: 5c9513ac752fe33976a0a16a9e6d188b8200d3ae
URL: https://github.com/llvm/llvm-project/commit/5c9513ac752fe33976a0a16a9e6d188b8200d3ae
DIFF: https://github.com/llvm/llvm-project/commit/5c9513ac752fe33976a0a16a9e6d188b8200d3ae.diff
LOG: [NVPTX] cap param alignment at 128 (max supported by ptx) (#96117)
Cap the alignment to 128 bytes as that is the maximum alignment
supported by PTX. The restriction is mentioned in the parameter passing
section (Note D) of the [PTX Writer's Guide to Interoperability]
(https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/index.html#parameter-passing)
> D. The alignment must be 1, 2, 4, 8, 16, 32, 64, or 128 bytes.
Added:
llvm/test/CodeGen/NVPTX/max-align.ll
Modified:
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index f4ef7c9914f13..982c191875750 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -5038,7 +5038,9 @@ bool NVPTXTargetLowering::getTgtMemIntrinsic(
/// ensures that alignment is 16 or greater.
Align NVPTXTargetLowering::getFunctionParamOptimizedAlign(
const Function *F, Type *ArgTy, const DataLayout &DL) const {
- const uint64_t ABITypeAlign = DL.getABITypeAlign(ArgTy).value();
+ // Capping the alignment to 128 bytes as that is the maximum alignment
+ // supported by PTX.
+ const Align ABITypeAlign = std::min(Align(128), DL.getABITypeAlign(ArgTy));
// If a function has linkage
diff erent from internal or private, we
// must use default ABI alignment as external users rely on it. Same
@@ -5048,10 +5050,10 @@ Align NVPTXTargetLowering::getFunctionParamOptimizedAlign(
/*IgnoreCallbackUses=*/false,
/*IgnoreAssumeLikeCalls=*/true,
/*IgnoreLLVMUsed=*/true))
- return Align(ABITypeAlign);
+ return ABITypeAlign;
assert(!isKernelFunction(*F) && "Expect kernels to have non-local linkage");
- return Align(std::max(uint64_t(16), ABITypeAlign));
+ return std::max(Align(16), ABITypeAlign);
}
/// Helper for computing alignment of a device function byval parameter.
diff --git a/llvm/test/CodeGen/NVPTX/max-align.ll b/llvm/test/CodeGen/NVPTX/max-align.ll
new file mode 100644
index 0000000000000..c8b1cb12dee5f
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/max-align.ll
@@ -0,0 +1,14 @@
+; RUN: llc < %s -march=nvptx64 -O0 | FileCheck %s
+; RUN: %if ptxas %{ llc < %s -march=nvptx64 -O0 | %ptxas-verify %}
+
+
+; CHECK: .visible .func (.param .align 128 .b8 func_retval0[256]) repro()
+define <64 x i32> @repro() {
+
+ ; CHECK: .param .align 128 .b8 retval0[256];
+ %1 = tail call <64 x i32> @test(i32 0)
+ ret <64 x i32> %1
+}
+
+; Function Attrs: nounwind
+declare <64 x i32> @test(i32)
More information about the llvm-commits
mailing list