<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/134714>134714</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SystemZ] Large compile time regression in `SystemZTTIImpl::adjustInliningThreshold()`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:SystemZ,
            slow-compile
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alexrp
      </td>
    </tr>
</table>

<pre>
    #106058 appears to have caused a large compile time regression in LLVM 20. [zig-bootstrap](https://github.com/ziglang/zig-bootstrap) used to be able to compile and link the `zig` binary for `s390x-linux-(gnu,musl)` in a matter of minutes when we were on LLVM 19. Now on LLVM 20, I decided to cancel the build after it had been running for about an hour.

Some investigation shows that a *lot* of time is being spent in `SystemZTTIImpl::adjustInliningThreshold()`, in particular in this section:

https://github.com/llvm/llvm-project/blob/c1c0d551bae4e4f4ed13fcd9264834a2713fe44b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp#L98-L105

Some thoughts:

* A module can have lots of globals.
    * This doesn't appear to be the problem here, however.
* A global can have lots of users (think common deduplicated/merged constant values).
    * This seems to be the case here, though I couldn't determine exactly how many users we're talking about because I was using a `RelWithDebInfo` build of LLVM where `p M->globals()` was optimized out.
        * Building a `Debug` compiler as I file this to hopefully find out...
* `std::set` seems less than ideal compared to `std::unordered_set` here.
    * I tried changing this to `std::unordered_set` but it didn't seem to have too much of an impact. Still seems desirable to do, though.

In general, all of this seems like a lot of work to be doing on ~every inlining decision.

cc @JonPsson1 @uweigand
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVcuO4zYQ_Br60rAhU_JDBx-8OzHgYDYIsoMEyCXgoyVxhyIFPsbjOeTbg5ZkzwALbJCcbIpSs7qquihiNK1DPLDNJ7Z5WIicOh8OwuJrGBbS6-uB8XJdbIvNHsQwoAgRkod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