[compiler-rt] [builtins] Use __builtin_clzll for 64-bit types (PR #99874)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 22 07:05:39 PDT 2024
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/99874
>From 56bd4f0bcd9c29208d9034b75723efef977fefb8 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Mon, 22 Jul 2024 16:36:32 +0300
Subject: [PATCH] [builtins] Use __builtin_clzll for 64-bit types
This addresses the issue with __LP64__ not being defined for targets
with 32-bit pointers but 64-bit longs, resulting in worse codegen.
---
compiler-rt/lib/builtins/fp_extend.h | 11 +----------
compiler-rt/lib/builtins/fp_lib.h | 11 +----------
2 files changed, 2 insertions(+), 20 deletions(-)
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