[llvm] [SPIR-V] Emit FuncParamAttr Zext/Sext for return type attributes (PR #223724)

Arseniy Obolenskiy via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 07:47:20 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/223724

None

>From a9403cb7805c4030ebf9dbc6153ce8d34ad931d7 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Tue, 15 Sep 2026 16:46:51 +0200
Subject: [PATCH] [SPIR-V] Emit FuncParamAttr Zext/Sext for return type
 attributes

---
 llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp       | 15 +++++++++++++++
 .../CodeGen/SPIRV/transcoding/func_param_attr.ll  | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index 0fe4451d50ad7..279c32ca004b8 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -394,6 +394,21 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
     GR->addGlobalObject(&Arg, &MIRBuilder.getMF(), ArgReg);
     i++;
   }
+  if (!ST->isShader()) {
+    if (F.hasRetAttribute(Attribute::ZExt)) {
+      auto Attr =
+          static_cast<unsigned>(SPIRV::FunctionParameterAttribute::Zext);
+      buildOpDecorate(FuncVReg, MIRBuilder, SPIRV::Decoration::FuncParamAttr,
+                      {Attr});
+    }
+    if (F.hasRetAttribute(Attribute::SExt)) {
+      auto Attr =
+          static_cast<unsigned>(SPIRV::FunctionParameterAttribute::Sext);
+      buildOpDecorate(FuncVReg, MIRBuilder, SPIRV::Decoration::FuncParamAttr,
+                      {Attr});
+    }
+  }
+
   // Name the function.
   if (F.hasName())
     buildOpName(FuncVReg, F.getName(), MIRBuilder);
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/func_param_attr.ll b/llvm/test/CodeGen/SPIRV/transcoding/func_param_attr.ll
index e158477a3627c..dc76c54d34a6a 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/func_param_attr.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/func_param_attr.ll
@@ -7,6 +7,8 @@
 ; CHECK-SPIRV-DAG: OpDecorate %[[#NOALIAS:]] FuncParamAttr NoAlias
 ; CHECK-SPIRV-DAG: OpDecorate %[[#BYVAL:]] FuncParamAttr ByVal
 ; CHECK-SPIRV-DAG: OpDecorate %[[#SRET:]] FuncParamAttr Sret
+; CHECK-SPIRV-DAG: OpDecorate %[[#RET_ZEXT:]] FuncParamAttr Zext
+; CHECK-SPIRV-DAG: OpDecorate %[[#RET_SEXT:]] FuncParamAttr Sext
 
 ; CHECK-SPIRV: %[[#ZEXT]] = OpFunctionParameter %[[#]]
 define spir_func void @test_zext(i8 zeroext %arg) {
@@ -43,3 +45,15 @@ define spir_func void @test_sret(ptr sret(i32) %arg) {
 entry:
   ret void
 }
+
+; CHECK-SPIRV: %[[#RET_ZEXT]] = OpFunction %[[#]]
+define spir_func zeroext i8 @test_ret_zext() {
+entry:
+  ret i8 0
+}
+
+; CHECK-SPIRV: %[[#RET_SEXT]] = OpFunction %[[#]]
+define spir_func signext i8 @test_ret_sext() {
+entry:
+  ret i8 0
+}



More information about the llvm-commits mailing list