[clang] [llvm] [OpenMP] Fix convention of SPIRV outline functions (PR #192450)
Alex Duran via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 08:33:08 PDT 2026
https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/192450
>From af8b9ab18aae856295f3753ec59b0e1ba7e24cca Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Thu, 16 Apr 2026 06:32:49 -0700
Subject: [PATCH 1/2] [OpenMP] Fix convention of SPIRV outline functions
When creating an outline function for device code we're not setting the
right calling convention when the target is SPIRV.
This results in the calls to the function to be removed by the InstCombine
pass as it thinks is not callable.
---
clang/lib/CodeGen/CGStmtOpenMP.cpp | 6 ++++++
offload/test/offloading/ompx_coords.c | 1 -
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 59d0e6825a975..01de7a410c38f 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -608,6 +608,12 @@ static llvm::Function *emitOutlinedFunctionPrologue(
llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage,
FO.FunctionName, &CGM.getModule());
CGM.SetInternalFunctionAttributes(CD, F, FuncInfo);
+
+ // Adjust the calling convention for SPIR-V targets to avoid mismatches
+ // between callee and caller.
+ if (CGM.getTriple().isSPIRV() && !FO.IsDeviceKernel)
+ F->setCallingConv(llvm::CallingConv::SPIR_FUNC);
+
if (CD->isNothrow())
F->setDoesNotThrow();
F->setDoesNotRecurse();
diff --git a/offload/test/offloading/ompx_coords.c b/offload/test/offloading/ompx_coords.c
index 71979ef2ebe87..7cca784a90905 100644
--- a/offload/test/offloading/ompx_coords.c
+++ b/offload/test/offloading/ompx_coords.c
@@ -1,7 +1,6 @@
// RUN: %libomptarget-compileopt-run-and-check-generic
//
// REQUIRES: gpu
-// XFAIL: intelgpu
#include <omp.h>
#include <ompx.h>
>From d9420b9c9eed8b3d09df5d5890bfc1fddf8b0903 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Thu, 16 Apr 2026 08:32:54 -0700
Subject: [PATCH 2/2] fix test checks
---
clang/test/OpenMP/metadirective_device_arch_codegen.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/clang/test/OpenMP/metadirective_device_arch_codegen.cpp b/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
index 5e5b1539b5c82..33953b4efa6c2 100644
--- a/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
+++ b/clang/test/OpenMP/metadirective_device_arch_codegen.cpp
@@ -53,14 +53,13 @@ int metadirective1() {
// CHECK: ret void
-// CHECK: define internal void @[[METADIRECTIVE]]_omp_outlined
+// CHECK: define internal {{(spir_func )?}}void @[[METADIRECTIVE]]_omp_outlined
// CHECK: entry:
// CHECK: call{{.*}} void @__kmpc_distribute_static_init
// CHECK: omp.loop.exit:
// CHECK: call{{.*}} void @__kmpc_distribute_static_fini
-
-// CHECK: define internal void @[[METADIRECTIVE]]_omp_outlined_omp_outlined
+// CHECK: define internal {{(spir_func )?}}void @[[METADIRECTIVE]]_omp_outlined_omp_outlined
// CHECK: entry:
// CHECK: call{{.*}} void @__kmpc_for_static_init_4
// CHECK: omp.inner.for.body:
More information about the cfe-commits
mailing list