https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/205709

>From 092318c9bb1a5ba87ff9be1e32272f109387a5f9 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Wed, 24 Jun 2026 20:41:30 -0500
Subject: [PATCH] [libclc] Replace NVPTX libdevice calls with clang builtins
 for sqrt, rsqrt, isinf

---
 libclc/clc/lib/nvptx/math/clc_rsqrt.cl       | 11 ++++---
 libclc/clc/lib/nvptx/math/clc_sqrt.cl        |  7 ++---
 libclc/clc/lib/nvptx/relational/clc_isinf.cl | 33 --------------------
 3 files changed, 8 insertions(+), 43 deletions(-)
 delete mode 100644 libclc/clc/lib/nvptx/relational/clc_isinf.cl

diff --git a/libclc/clc/lib/nvptx/math/clc_rsqrt.cl 
b/libclc/clc/lib/nvptx/math/clc_rsqrt.cl
index 97f18ad1224d1..89f6f6bb01f87 100644
--- a/libclc/clc/lib/nvptx/math/clc_rsqrt.cl
+++ b/libclc/clc/lib/nvptx/math/clc_rsqrt.cl
@@ -8,15 +8,16 @@
 
 #include "clc/math/clc_rsqrt.h"
 
-float __nv_rsqrtf(float);
-double __nv_rsqrt(double);
-
-_CLC_OVERLOAD _CLC_DEF float __clc_rsqrt(float x) { return __nv_rsqrtf(x); }
+_CLC_OVERLOAD _CLC_DEF float __clc_rsqrt(float x) {
+  return __nvvm_rsqrt_approx_f(x);
+}
 
 #ifdef cl_khr_fp64
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
-_CLC_OVERLOAD _CLC_DEF double __clc_rsqrt(double x) { return __nv_rsqrt(x); }
+_CLC_OVERLOAD _CLC_DEF double __clc_rsqrt(double x) {
+  return __nvvm_rsqrt_approx_d(x);
+}
 
 #endif
 
diff --git a/libclc/clc/lib/nvptx/math/clc_sqrt.cl 
b/libclc/clc/lib/nvptx/math/clc_sqrt.cl
index f84045eabfec0..79a41e90e7b18 100644
--- a/libclc/clc/lib/nvptx/math/clc_sqrt.cl
+++ b/libclc/clc/lib/nvptx/math/clc_sqrt.cl
@@ -8,15 +8,12 @@
 
 #include "clc/math/clc_sqrt.h"
 
-float __nv_sqrtf(float);
-double __nv_sqrt(double);
-
-_CLC_OVERLOAD _CLC_DEF float __clc_sqrt(float x) { return __nv_sqrtf(x); }
+_CLC_OVERLOAD _CLC_DEF float __clc_sqrt(float x) { return __builtin_sqrtf(x); }
 
 #ifdef cl_khr_fp64
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
-_CLC_OVERLOAD _CLC_DEF double __clc_sqrt(double x) { return __nv_sqrt(x); }
+_CLC_OVERLOAD _CLC_DEF double __clc_sqrt(double x) { return __builtin_sqrt(x); 
}
 
 #endif
 
diff --git a/libclc/clc/lib/nvptx/relational/clc_isinf.cl 
b/libclc/clc/lib/nvptx/relational/clc_isinf.cl
deleted file mode 100644
index 3b0055e995aaf..0000000000000
--- a/libclc/clc/lib/nvptx/relational/clc_isinf.cl
+++ /dev/null
@@ -1,33 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "clc/relational/clc_isinf.h"
-
-int __nv_isinff(float);
-int __nv_isinfd(double);
-
-_CLC_OVERLOAD _CLC_DEF int __clc_isinf(float x) { return __nv_isinff(x); }
-
-#ifdef cl_khr_fp64
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-
-_CLC_OVERLOAD _CLC_DEF int __clc_isinf(double x) { return __nv_isinfd(x); }
-
-#endif
-
-#ifdef cl_khr_fp16
-#pragma OPENCL EXTENSION cl_khr_fp16 : enable
-
-_CLC_OVERLOAD _CLC_DEF int __clc_isinf(half x) { return __clc_isinf((float)x); 
}
-
-#endif
-
-#define __CLC_FUNCTION __clc_isinf
-#define __CLC_BODY "clc/shared/unary_def_scalarize.inc"
-#define __CLC_RET_TYPE __CLC_BIT_INT
-#include "clc/math/gentype.inc"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to