[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

llvm-svn: 324593
This commit is contained in:
Jonas Devlieghere 2018-02-08 11:14:11 +00:00
parent d4034d24da
commit 1db3ca9ab1
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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