-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[compiler-rt] Make sure __clzdi2 doesn't call itself recursively on sparc64 #136737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…parc64 On 64-bit platforms, libgcc doesn't ship with __clzsi2, so __builtin_clz gets lowered to __clzdi2. A check already exists for GCC, but as of commit 8210ca0 clang also lowers __builtin_clz to __clzdi2 on sparc64. Update the check so that building __clzdi2 with clang/sparc64 also works.
compiler-rt/lib/builtins/clzdi2.c
Outdated
(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 | ||
// ctz instruction, resolves __builtin_clz resolves to __clzdi2 rather than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ctz instruction, resolves __builtin_clz resolves to __clzdi2 rather than | |
// ctz instruction, `__builtin_clz` resolves to `__clzdi2` rather than |
compiler-rt/lib/builtins/clzdi2.c
Outdated
// __clzsi2, leading to infinite recursion. | ||
// This is because on those platforms, libgcc doesn't ship with __clzsi2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// __clzsi2, leading to infinite recursion. | |
// This is because on those platforms, libgcc doesn't ship with __clzsi2. | |
// `__clzsi2` as libgcc does not ship with `__clzsi2`, leading to infinite recursion. |
// ctz instruction, `__builtin_clz` resolves to `__clzdi2` rather than | ||
// __clzsi2 as libgcc does not ship with `__clzsi2`, leading to infinite | ||
// recursion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't seem to be true on RISC-V/Mips (clang).
https://godbolt.org/z/z8Yd9dr5K
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looking at the respective backends, seems like they are Expand
ing CTTZ instead of lowering it to a LibCall
in absence of native instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could rewrite the check so that the clang check is omitted only if compiling on SPARC, but wouldn't that be too complicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with any solution as long as it doesn't break/pessimize other targets.
I think RISC-V will eventually require the same change, not sure about Mips.
Note that |
Noted, will do another PR for it after this lands. |
On 64-bit platforms, libgcc doesn't ship with __clzsi2, so __builtin_clz gets lowered to __clzdi2. A check already exists for GCC, but as of commit 8210ca0 clang also lowers __builtin_clz to __clzdi2 on sparc64.
Update the check so that building __clzdi2 with clang/sparc64 also works.