[clang] 85232b0 - HIP: Directly call isfinite builtins
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 19 05:48:53 PDT 2023
Author: Matt Arsenault
Date: 2023-06-19T08:48:48-04:00
New Revision: 85232b0ecbf817bc1d70ae602cf44cf6ea03c0e6
URL: https://github.com/llvm/llvm-project/commit/85232b0ecbf817bc1d70ae602cf44cf6ea03c0e6
DIFF: https://github.com/llvm/llvm-project/commit/85232b0ecbf817bc1d70ae602cf44cf6ea03c0e6.diff
LOG: HIP: Directly call isfinite builtins
Added:
Modified:
clang/lib/Headers/__clang_hip_math.h
clang/test/Headers/__clang_hip_math.hip
Removed:
################################################################################
diff --git a/clang/lib/Headers/__clang_hip_math.h b/clang/lib/Headers/__clang_hip_math.h
index c19e32bd29364..f7949f30dfbae 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -268,7 +268,7 @@ __DEVICE__
int ilogbf(float __x) { return __ocml_ilogb_f32(__x); }
__DEVICE__
-__RETURN_TYPE __finitef(float __x) { return __ocml_isfinite_f32(__x); }
+__RETURN_TYPE __finitef(float __x) { return __builtin_isfinite(__x); }
__DEVICE__
__RETURN_TYPE __isinff(float __x) { return __builtin_isinf(__x); }
@@ -817,7 +817,7 @@ __DEVICE__
int ilogb(double __x) { return __ocml_ilogb_f64(__x); }
__DEVICE__
-__RETURN_TYPE __finite(double __x) { return __ocml_isfinite_f64(__x); }
+__RETURN_TYPE __finite(double __x) { return __builtin_isfinite(__x); }
__DEVICE__
__RETURN_TYPE __isinf(double __x) { return __builtin_isinf(__x); }
diff --git a/clang/test/Headers/__clang_hip_math.hip b/clang/test/Headers/__clang_hip_math.hip
index 7169614112d18..bb96aeaa1ab9b 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -1155,17 +1155,14 @@ extern "C" __device__ int test_ilogb(double x) {
// DEFAULT-LABEL: @test___finitef(
// DEFAULT-NEXT: entry:
-// DEFAULT-NEXT: [[CALL_I:%.*]] = tail call i32 @__ocml_isfinite_f32(float noundef [[X:%.*]]) #[[ATTR14]]
-// DEFAULT-NEXT: [[TOBOOL_I:%.*]] = icmp ne i32 [[CALL_I]], 0
-// DEFAULT-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL_I]] to i32
+// DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract float @llvm.fabs.f32(float [[X:%.*]]) #[[ATTR17:[0-9]+]]
+// DEFAULT-NEXT: [[CMPINF_I:%.*]] = fcmp contract one float [[TMP0]], 0x7FF0000000000000
+// DEFAULT-NEXT: [[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
// DEFAULT-NEXT: ret i32 [[CONV]]
//
// FINITEONLY-LABEL: @test___finitef(
// FINITEONLY-NEXT: entry:
-// FINITEONLY-NEXT: [[CALL_I:%.*]] = tail call i32 @__ocml_isfinite_f32(float noundef nofpclass(nan inf) [[X:%.*]]) #[[ATTR14]]
-// FINITEONLY-NEXT: [[TOBOOL_I:%.*]] = icmp ne i32 [[CALL_I]], 0
-// FINITEONLY-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL_I]] to i32
-// FINITEONLY-NEXT: ret i32 [[CONV]]
+// FINITEONLY-NEXT: ret i32 1
//
extern "C" __device__ BOOL_TYPE test___finitef(float x) {
return __finitef(x);
@@ -1173,17 +1170,14 @@ extern "C" __device__ BOOL_TYPE test___finitef(float x) {
// DEFAULT-LABEL: @test___finite(
// DEFAULT-NEXT: entry:
-// DEFAULT-NEXT: [[CALL_I:%.*]] = tail call i32 @__ocml_isfinite_f64(double noundef [[X:%.*]]) #[[ATTR14]]
-// DEFAULT-NEXT: [[TOBOOL_I:%.*]] = icmp ne i32 [[CALL_I]], 0
-// DEFAULT-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL_I]] to i32
+// DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract double @llvm.fabs.f64(double [[X:%.*]]) #[[ATTR17]]
+// DEFAULT-NEXT: [[CMPINF_I:%.*]] = fcmp contract one double [[TMP0]], 0x7FF0000000000000
+// DEFAULT-NEXT: [[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
// DEFAULT-NEXT: ret i32 [[CONV]]
//
// FINITEONLY-LABEL: @test___finite(
// FINITEONLY-NEXT: entry:
-// FINITEONLY-NEXT: [[CALL_I:%.*]] = tail call i32 @__ocml_isfinite_f64(double noundef nofpclass(nan inf) [[X:%.*]]) #[[ATTR14]]
-// FINITEONLY-NEXT: [[TOBOOL_I:%.*]] = icmp ne i32 [[CALL_I]], 0
-// FINITEONLY-NEXT: [[CONV:%.*]] = zext i1 [[TOBOOL_I]] to i32
-// FINITEONLY-NEXT: ret i32 [[CONV]]
+// FINITEONLY-NEXT: ret i32 1
//
extern "C" __device__ BOOL_TYPE test___finite(double x) {
return __finite(x);
@@ -1191,7 +1185,7 @@ extern "C" __device__ BOOL_TYPE test___finite(double x) {
// DEFAULT-LABEL: @test___isinff(
// DEFAULT-NEXT: entry:
-// DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract float @llvm.fabs.f32(float [[X:%.*]]) #[[ATTR17:[0-9]+]]
+// DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract float @llvm.fabs.f32(float [[X:%.*]]) #[[ATTR17]]
// DEFAULT-NEXT: [[CMPINF_I:%.*]] = fcmp contract oeq float [[TMP0]], 0x7FF0000000000000
// DEFAULT-NEXT: [[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
// DEFAULT-NEXT: ret i32 [[CONV]]
More information about the cfe-commits
mailing list