[llvm] [NVPTX] Pass scalar params wider than 64 bits as byte arrays (PR #226328)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 16:46:29 PDT 2026


https://github.com/iliasabk created https://github.com/llvm/llvm-project/pull/226328

Fixes https://github.com/llvm/llvm-project/issues/226255

Scalar kernel parameters between 65 and 127 bits (e.g. `i96`) crash with `llvm_unreachable("Integer too large")` in `getPTXFundamentalTypeStr`. `shouldPassAsArray` only routes scalars of at least 128 bits through the `.param .align A .b8 name[N]` byte-array form, but PTX fundamental types stop at `.u64`, so i65–i127 fall into a gap where they take the scalar path and die.

This widens the `shouldPassAsArray` threshold to `>64` bits so these parameters use the same byte-array form already used for i128 and wider types. All users of the predicate (formal param emission, call prototypes, return values, `LowerCall`, and `NVPTXPromoteParamAlign`) share it, so callers and callees stay consistent. It also covers other scalar types without a fundamental PTX type (e.g. `x86_fp80`), which hit the same unreachable today.

Regression test covers i65, i96 (the reduced reproducer from the issue), and i127 kernel parameters.

>From f99502a72a72f5c580b2e5ee47683dbbc0580a07 Mon Sep 17 00:00:00 2001
From: Ilias Aberkane <user.name>
Date: Fri, 25 Sep 2026 01:45:48 +0200
Subject: [PATCH] [NVPTX] Pass scalar params wider than 64 bits as byte arrays

Scalar kernel parameters between 65 and 127 bits hit
llvm_unreachable("Integer too large") in getPTXFundamentalTypeStr:
shouldPassAsArray only routes scalars >= 128 bits through the byte-array
form, but PTX fundamental types stop at .u64, leaving i65-i127 in a gap
where they take the scalar path and crash.

Widen the shouldPassAsArray threshold to >64 bits so these parameters
use the same .param .align A .b8 name[N] form already used for i128 and
wider types. All users of the predicate (formal param emission, call
prototypes, return values, LowerCall and NVPTXPromoteParamAlign) share
it, so caller and callee stay consistent.

Fixes https://github.com/llvm/llvm-project/issues/226255
---
 llvm/lib/Target/NVPTX/NVPTXUtilities.h        |  4 +++-
 .../CodeGen/NVPTX/kernel-param-wide-int.ll    | 24 +++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/NVPTX/kernel-param-wide-int.ll

diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.h b/llvm/lib/Target/NVPTX/NVPTXUtilities.h
index ae3692fecafae..296d465447041 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.h
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.h
@@ -69,8 +69,10 @@ inline unsigned promoteScalarArgumentSize(unsigned size) {
 }
 
 inline bool shouldPassAsArray(Type *Ty) {
+  // Scalar types wider than 64 bits have no PTX fundamental type, so they are
+  // passed as byte arrays, same as aggregates and vectors.
   return Ty->isAggregateType() || Ty->isVectorTy() ||
-         Ty->getScalarSizeInBits() >= 128 || Ty->isHalfTy() || Ty->isBFloatTy();
+         Ty->getScalarSizeInBits() > 64 || Ty->isHalfTy() || Ty->isBFloatTy();
 }
 
 namespace NVPTX {
diff --git a/llvm/test/CodeGen/NVPTX/kernel-param-wide-int.ll b/llvm/test/CodeGen/NVPTX/kernel-param-wide-int.ll
new file mode 100644
index 0000000000000..8a4a1f33a935a
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/kernel-param-wide-int.ll
@@ -0,0 +1,24 @@
+; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_80 | FileCheck %s
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_80 | %ptxas-verify %}
+
+; Integer kernel parameters wider than 64 bits have no PTX fundamental type,
+; so they must be passed as byte arrays, same as i128 and wider types.
+; https://github.com/llvm/llvm-project/issues/226255
+
+define ptx_kernel void @kernel_i65(i65 %p) {
+; CHECK-LABEL: .visible .entry kernel_i65(
+; CHECK: .param .align 16 .b8 kernel_i65_param_0[9]
+  ret void
+}
+
+define ptx_kernel void @kernel_i96(i96 %p) {
+; CHECK-LABEL: .visible .entry kernel_i96(
+; CHECK: .param .align 16 .b8 kernel_i96_param_0[12]
+  ret void
+}
+
+define ptx_kernel void @kernel_i127(i127 %p) {
+; CHECK-LABEL: .visible .entry kernel_i127(
+; CHECK: .param .align 16 .b8 kernel_i127_param_0[16]
+  ret void
+}



More information about the llvm-commits mailing list