[llvm] [ThinLTO] Don't mark calloc function dead (PR #72673)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 01:31:41 PST 2023


eleviant wrote:

Updated test cases

> > The problem arises only when two (or more) libcalls are folded into one (or more) other libcalls.
> 
> The problem here is all allocation functions are not in the RuntimeLibcalls list. All RuntimeLibcalls functions are preserved by LTO process (in general, unless for specific platform they are not available) because they can be produced by backend even if the bitcode object file don't reference them. There is no difference from this case, which `calloc` doesn't get referenced before optimization.

Well, I've done a brief investigation on this and looks like RuntimeLibcalls handling boils up to this snippet of code in lld
```
  if (!ctx.bitcodeFiles.empty())
    for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
      handleLibcall(s);

```
The `handleLibcall` function check if IR symbol representing runtime library function is lazy, and adds its bitcode file to LTO input set if so. This doesn't really help much, because `calloc` (event if added to to RuntimeLibcalls set) is not a lazy symbol. The problem is not that we don't add it but that we explicitly remove it in DCE. I'm starting to beleive that calloc is the unique case (I haven't found anything else of the sort).


https://github.com/llvm/llvm-project/pull/72673


More information about the llvm-commits mailing list