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

    <tr>
        <th>Summary</th>
        <td>
            Changing codegen to use llvm.threadlocal.address regressed HHVM
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Writing this mostly as a FYI and wondering if others have observed this or are looking into this too?

We are in the process of upgrading compiler versions and noticed a 0.5% regression in HHVM. This was bisected to the changes in https://reviews.llvm.org/D125291 and https://reviews.llvm.org/D129833 that introduce `llvm.theadlocal.address`.

While I am still in the process of completely classifying (and maybe fixing) things, I believe this shows up as increased CSEing of TLS base addresses and consequently increased spilling activity. We also seem to be unable to rematerialize or fold such accesses further increasing register pressure and hence spills.

Random example of bad codegen pattern:
```
        movq    %fs:0x0, %rcx
 leaq    -0x2540(%rcx), %rcx
        movq    %rcx, -0x68(%rbp)
 movq    %fs:-0x2540, %rcx
        ...
        movq    -0x68(%rbp), %rcx
        movq    (%rcx), %rcx
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2P2zYQ_TXUZbACTckfOuiQ7NbIAs2lCRr0OCLHEluKVEjKa-fXFyM5CfajaAxDgsD3Zt684QymZHtP1Irte7F9KHDOQ4jtR8zf6H3RBXNtv0Sbre8hDzbBGFJ2V8AECMe_HgG9gafgDUWG2BOEPFBMMOCZIHSJ4pnMSg0RMBK4EP5ZsD6H9SCHIKqjkA9CvlufX2iBWg95IJhi0JQShBPMUx_RMF2HcbKOIpwpJht8WqT4kK0mAwiy3Aq1hUh9pMQAjvbhw58fS_jMSZ8wQWcT6cz6wpJID-h7Sowccp6SqN4JdRTqGOls6SmVzp3HMsReqOPDRm1Vs1my_gq4OVQV5AEzFx6DmTWB2MkFlAdC44JGV6IxrFfsZPnMkME6gkfAEVK2zr1hDRviKJO7gnbc1tOVfRLqwBJHvHYEJ3uxvheqYeN9n4S6h0foyFk609qMNISnBPPELbZeR8JEBu4__cbBwgk-__4JOkwEN6W0Gq-DT_R1Js-34ycvTdY5ZqLO9mzztQTurUsBEtHIxncEs8fOEX9EGjFTtOjsN-IbcwrOQJr1AKj1mu40R75j37Nw9Ei9TZkiTCxpjrS2hbymVUJ65uYf6E0YgS7IlnFVHXIJhnryMGHOFD33c-Xs5O2_fMLtN4bzV34LtT1x8-VFsp1CbaO-3KCOcMHcyYva1lKow-1YNa-wr8MuwHsm7w43ajcxdSW8FPAjyduBy7J8O9Pr-P8r7b_LeGHW-ixMW5mmarCgdrPfqI2s640shlZvFDVNLXfVviGldsrU1d5UeNgj1qeNKmyrpKplLSspq6qSJVabrmp0V2-7ShmUopY0onU_pq2wKc3UHvZ1tS8cduTSstuU8vQEy6FQilddbJlz1819ErV0NuWfM1tkmx2197wQ1m2z3o0cYE4Et6mNL8f2-7ohs6yaYo6ufb4cepuHuSt1GIU6cpjb626K4W_SWajjojEJdVxq-DcAAP__eGjIDA">