LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 36318 - Merge r324593 into the 6.0 branch : [builtins] Workaround for infinite recursion in c?zdi2
Summary: Merge r324593 into the 6.0 branch : [builtins] Workaround for infinite recurs...
Status: NEW
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: 6.0
Hardware: All All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-6.0.1
  Show dependency tree
 
Reported: 2018-02-09 03:30 PST by Jonas Devlieghere
Modified: 2018-05-30 20:38 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s): r324593


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Devlieghere 2018-02-09 03:30:34 PST
Is it OK to merge the following revision(s) to the 6.0 branch?
Comment 1 Jonas Devlieghere 2018-02-09 03:30:39 PST
https://reviews.llvm.org/rL324593
Comment 2 Jonas Devlieghere 2018-02-09 14:40:13 PST
Let's put this on hold until https://reviews.llvm.org/D43146 has been landed.
Comment 3 Hans Wennborg 2018-02-19 07:46:18 PST
Can you provide more context on what this is fixing?

It needs to get committed soon if it's to make the 6.0 release.
Comment 4 Jessica Clarke 2018-02-19 11:52:45 PST
__builtin_clz is int -> int, and often implemented using a native clz (or similar) instruction. However, on 64-bit architecture which don't have such an instruction, rather than calling the __clzsi2 function (as one would expect, given SI is the GCC internal name for int), it instead uses __clzdi2, the 64-bit (DI) version. Since compiler-rt's implementation of __clzdi2 uses a divide-and-conquer approach of calling __builtin_clz on each half of the 64-bit value, on these architectures, the __builtin_clz ends up calling __clzdi2 itself, thus leading to non-terminating recursion, whereas the intention is that, if there's no clz instruction, __clzdi2 ends up calling compiler-rt's __clzsi2. Thus the patch simply identifies these problematic platforms and re-defines __builtin_clz to be __clzsi2 itself. The same is true for __builtin_ctz and __ctz{d,s}i2 (which will also make use of a ctz OR clz (clz(x & (~x+1)) is 31 - ctz(x)) instruction if available).
Comment 5 Hans Wennborg 2018-02-20 01:09:42 PST
Is this a regression from 5.0.0?

I'm nervous about merging this to 6.0.0 since we're late in the process, and it's not a completely straight-forward fix. Unless it's really fixing a regression from the previous release, it might have to wait until 6.0.1.
Comment 6 Jonas Devlieghere 2018-02-20 03:44:43 PST
I agree, this is not a regression and should go in 6.0.1, assuming D43146 has landed by then. I see no point in getting only a partial workaround in 6.0.