[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 06:36:32 PDT 2026
https://github.com/adurang created https://github.com/llvm/llvm-project/pull/192450
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.
>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] [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>
More information about the cfe-commits
mailing list