[llvm] [SPARC] Use lzcnt to implement CTLZ when we have VIS3 (PR #135715)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 07:53:29 PDT 2025
s-barannikov wrote:
There is a special hack in `clzdi2.c`:
```C
#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 int __clzsi2(si_int);
#endif
```
It is for gcc, but it looks like we've discovered the same issue with clang?
Does `__clzdi2` contains some logic apart from calling itself?
https://github.com/llvm/llvm-project/pull/135715
More information about the llvm-commits
mailing list