[compiler-rt] r342504 - [builtins] Fix c?zdi2 on sparc64/Linux and ignore riscv32

Kristina Brooks via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 18 11:56:52 PDT 2018


Author: kristina
Date: Tue Sep 18 11:56:52 2018
New Revision: 342504

URL: http://llvm.org/viewvc/llvm-project?rev=342504&view=rev
Log:
[builtins] Fix c?zdi2 on sparc64/Linux and ignore riscv32

On sparc64/Linux, sparc64 isn't defined; the canonical way of
checking for sparc64 is sparc && arch64, which also works on the
BSDs and Solaris. Since this problem does not occur on 32-bit
architectures, riscv32 can be ignored. This fixes and refines rL324593.

Patch by jrtc27 (James Clarke)

Differential Revision: https://reviews.llvm.org/D43146


Modified:
    compiler-rt/trunk/lib/builtins/clzdi2.c
    compiler-rt/trunk/lib/builtins/ctzdi2.c

Modified: compiler-rt/trunk/lib/builtins/clzdi2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/clzdi2.c?rev=342504&r1=342503&r2=342504&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/clzdi2.c (original)
+++ compiler-rt/trunk/lib/builtins/clzdi2.c Tue Sep 18 11:56:52 2018
@@ -16,8 +16,13 @@
 
 /* Returns: the number of leading 0-bits */
 
-#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
-/* gcc resolves __builtin_clz -> __clzdi2 leading to infinite recursion */
+#if !defined(__clang__) &&                                                     \
+    ((defined(__sparc__) && defined(__arch64__)) ||                            \
+     defined(__mips64) ||                                                      \
+     (defined(__riscv) && __SIZEOF_POINTER__ >= 8))
+/* On 64-bit architectures with neither a native clz instruction nor a native
+ * ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
+ * __clzsi2, leading to infinite recursion. */
 #define __builtin_clz(a) __clzsi2(a)
 extern si_int __clzsi2(si_int);
 #endif

Modified: compiler-rt/trunk/lib/builtins/ctzdi2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/ctzdi2.c?rev=342504&r1=342503&r2=342504&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/ctzdi2.c (original)
+++ compiler-rt/trunk/lib/builtins/ctzdi2.c Tue Sep 18 11:56:52 2018
@@ -16,8 +16,13 @@
 
 /* Returns: the number of trailing 0-bits  */
 
-#if !defined(__clang__) && (defined(__sparc64__) || defined(__mips64) || defined(__riscv__))
-/* gcc resolves __builtin_ctz -> __ctzdi2 leading to infinite recursion */
+#if !defined(__clang__) &&                                                     \
+    ((defined(__sparc__) && defined(__arch64__)) ||                            \
+     defined(__mips64) ||                                                      \
+     (defined(__riscv) && __SIZEOF_POINTER__ >= 8))
+/* On 64-bit architectures with neither a native clz instruction nor a native
+ * ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
+ * __ctzsi2, leading to infinite recursion. */
 #define __builtin_ctz(a) __ctzsi2(a)
 extern si_int __ctzsi2(si_int);
 #endif




More information about the llvm-commits mailing list