[PATCH] D157917: clang/HIP: Use abs builtins instead of implementing them

Matt Arsenault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 14 14:11:20 PDT 2023


arsenm created this revision.
arsenm added reviewers: yaxunl, AlexVlx, JonChesterfield, jhuber6, doru1004.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

InstCombine already put these back together so there's no visible
change in the -O1 test for the header.


https://reviews.llvm.org/D157917

Files:
  clang/lib/Headers/__clang_hip_math.h


Index: clang/lib/Headers/__clang_hip_math.h
===================================================================
--- clang/lib/Headers/__clang_hip_math.h
+++ clang/lib/Headers/__clang_hip_math.h
@@ -315,18 +315,15 @@
 #if defined(__cplusplus)
 __DEVICE__
 int abs(int __x) {
-  int __sgn = __x >> (sizeof(int) * CHAR_BIT - 1);
-  return (__x ^ __sgn) - __sgn;
+  return __builtin_abs(__x);
 }
 __DEVICE__
 long labs(long __x) {
-  long __sgn = __x >> (sizeof(long) * CHAR_BIT - 1);
-  return (__x ^ __sgn) - __sgn;
+  return __builtin_labs(__x);
 }
 __DEVICE__
 long long llabs(long long __x) {
-  long long __sgn = __x >> (sizeof(long long) * CHAR_BIT - 1);
-  return (__x ^ __sgn) - __sgn;
+  return __builtin_llabs(__x);
 }
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157917.550085.patch
Type: text/x-patch
Size: 736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230814/691eb376/attachment.bin>


More information about the cfe-commits mailing list