[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 06:45:48 PDT 2024
https://github.com/s-barannikov created https://github.com/llvm/llvm-project/pull/99874
This addresses the issue with __LP64__ not being defined for targets with 32-bit pointers but 64-bit longs, resulting in worse codegen.
>From 50ea81240a441307278c0fa5a73ffcb0db57de85 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 | 9 +--------
compiler-rt/lib/builtins/fp_lib.h | 11 ++---------
2 files changed, 3 insertions(+), 17 deletions(-)
diff --git a/compiler-rt/lib/builtins/fp_extend.h b/compiler-rt/lib/builtins/fp_extend.h
index 7637417649e62..3cde433fca3ea 100644
--- a/compiler-rt/lib/builtins/fp_extend.h
+++ b/compiler-rt/lib/builtins/fp_extend.h
@@ -38,14 +38,7 @@ static const int srcSigFracBits = 52;
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
+ return __builtin_clzll(a);
}
#define src_rep_t_clz src_rep_t_clz_impl
diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h
index 8404d98c93508..17bf9913fe24f 100644
--- a/compiler-rt/lib/builtins/fp_lib.h
+++ b/compiler-rt/lib/builtins/fp_lib.h
@@ -58,15 +58,8 @@ 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)
More information about the llvm-commits
mailing list