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
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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits