[compiler-rt] r324593 - [builtins] Workaround for infinite recursion in c?zdi2
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 03:14:12 PST 2018
Author: jdevlieghere
Date: Thu Feb 8 03:14:11 2018
New Revision: 324593
URL: http://llvm.org/viewvc/llvm-project?rev=324593&view=rev
Log:
[builtins] Workaround for infinite recursion in c?zdi2
gcc resolves `__builtin_c?z` to `__c?zdi2` which leads to infinite
recursion. This problem has been observed for sparc64, mips64 and riscv.
Presumably this happens whenever an arch without dedicated bit counting
instructions is targeted. This patch provides a workaround.
Differential revision: https://reviews.llvm.org/D42902
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=324593&r1=324592&r2=324593&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/clzdi2.c (original)
+++ compiler-rt/trunk/lib/builtins/clzdi2.c Thu Feb 8 03:14:11 2018
@@ -16,6 +16,12 @@
/* 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 */
+#define __builtin_clz(a) __clzsi2(a)
+extern si_int __clzsi2(si_int);
+#endif
+
/* Precondition: a != 0 */
COMPILER_RT_ABI si_int
Modified: compiler-rt/trunk/lib/builtins/ctzdi2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/ctzdi2.c?rev=324593&r1=324592&r2=324593&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/ctzdi2.c (original)
+++ compiler-rt/trunk/lib/builtins/ctzdi2.c Thu Feb 8 03:14:11 2018
@@ -16,6 +16,12 @@
/* 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 */
+#define __builtin_ctz(a) __ctzsi2(a)
+extern si_int __ctzsi2(si_int);
+#endif
+
/* Precondition: a != 0 */
COMPILER_RT_ABI si_int
More information about the llvm-commits
mailing list