[compiler-rt] 735974e - [builtins] Use __builtin_clzll for 64-bit types (#99874)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 11:29:59 PDT 2024


Author: Sergei Barannikov
Date: 2024-07-22T21:29:56+03:00
New Revision: 735974e550dae84b40bad06cbe8cf5f22d318896

URL: https://github.com/llvm/llvm-project/commit/735974e550dae84b40bad06cbe8cf5f22d318896
DIFF: https://github.com/llvm/llvm-project/commit/735974e550dae84b40bad06cbe8cf5f22d318896.diff

LOG: [builtins] Use __builtin_clzll for 64-bit types (#99874)

This addresses the issue with `__LP64__` not being defined for targets
with 32-bit pointers but 64-bit longs, resulting in worse codegen.

Added: 
    

Modified: 
    compiler-rt/lib/builtins/fp_extend.h
    compiler-rt/lib/builtins/fp_lib.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/fp_extend.h b/compiler-rt/lib/builtins/fp_extend.h
index 7637417649e62..22bf2b2514e57 100644
--- a/compiler-rt/lib/builtins/fp_extend.h
+++ b/compiler-rt/lib/builtins/fp_extend.h
@@ -37,16 +37,7 @@ static const int srcSigFracBits = 52;
 // srcBits - srcSigFracBits - 1
 static const int srcExpBits = 11;
 
-static inline int src_rep_t_clz_impl(src_rep_t a) {
-#if defined __LP64__
-  return __builtin_clzl(a);
-#else
-  if (a & REP_C(0xffffffff00000000))
-    return clzsi(a >> 32);
-  else
-    return 32 + clzsi(a & REP_C(0xffffffff));
-#endif
-}
+static inline int src_rep_t_clz_impl(src_rep_t a) { return __builtin_clzll(a); }
 #define src_rep_t_clz src_rep_t_clz_impl
 
 #elif defined SRC_80

diff  --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index 8404d98c93508..b2a89506135be 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -58,16 +58,7 @@ typedef double fp_t;
 #define REP_C UINT64_C
 #define significandBits 52
 
-static __inline int rep_clz(rep_t a) {
-#if defined __LP64__
-  return __builtin_clzl(a);
-#else
-  if (a & REP_C(0xffffffff00000000))
-    return clzsi(a >> 32);
-  else
-    return 32 + clzsi(a & REP_C(0xffffffff));
-#endif
-}
+static inline int rep_clz(rep_t a) { return __builtin_clzll(a); }
 
 #define loWord(a) (a & 0xffffffffU)
 #define hiWord(a) (a >> 32)


        


More information about the llvm-commits mailing list