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

    <tr>
        <th>Summary</th>
        <td>
            aarch64: Failure to handle PSTATE.SM & ZA for tlsdesc calls
        </td>
    </tr>

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

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

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

<pre>
    Turns out LLVM has the same issue as GCC here (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121415).
For:
```
extern __thread int x;
int f() __arm_streaming_compatible { return x; }
```
compiled with -O2 -fPIC, we get:
```
f(): // @f()
        .cfi_startproc
// %bb.0:
        stp     x29, x30, [sp, #-16]!           // 16-byte Folded Spill
        .cfi_def_cfa_offset 16
        mov     x29, sp
        .cfi_def_cfa w29, 16
 .cfi_offset w30, -8
        .cfi_offset w29, -16
        adrp    x0, :tlsdesc:x
        ldr     x1, [x0, :tlsdesc_lo12:x]
        add     x0, x0, :tlsdesc_lo12:x
        .tlsdesccall x
        blr     x1
        mrs x8, TPIDR_EL0
        ldr     w0, [x8, x0]
        .cfi_def_cfa wsp, 16
        ldp     x29, x30, [sp], #16             // 16-byte Folded Reload
        .cfi_def_cfa_offset 0
        .cfi_restore w30
 .cfi_restore w29
        ret
```
which fails to force non-streaming mode around the call.  A function with ZA or ZT0 state would also need to handle that.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVEuPozgQ_jXOpRRkzCPkwIHuDKuRerSt6dYe5oIMLoN3HRzZpsnsr1_xSHeSndYgJCOq6quvHv64c6rtEXOSPJDksOGD74zNT6p3_yi-qY34mb8OtndgBg9PT399g4478B2C40cE5dyAwB388fgIHVoEwrLO-5MjUUFYSVjZNk3Q9kNgbEtYWQ_tv0prTljpOjNW9dAGTatIVCpBokPIwjhMCNsHhBalsRMKLUhK15cWePZoe6gq31nkAlTv4UyiB0KL6VMSlhG2h6ri9lg5b5EfVd9WjTmeuFe1RiC7B7DoB9vPgUB2h7sck7PSKGBUvoPtnwy28vnrI2GPMCK06P9Pa81LogKWsoHE9PKTFrA-QSNV5Ty3_mRNM2Gsziyp64AuuBdn50_zeWb7KfU5otNBkgd3mj9YtA1TkhwIC-HjWRHDdFv_9Ail0QIFvJyU1vdEBMqqkbwyUjr0EKZXDkfzdp3cnT4JhnFxWIJnywo3Lny32X3kxb4Ebm_ScmHnos9LrVHhtRPoGhIV5ys3LezCLlxbcu9faROyOSg53MAL-ID_POiK8WpruNZwbaj1O4WrrlkH52xCfX3-evhefXmiv2A9Xga5uJ7pLcnb9i7DvmmSFp8vxrQO826EKcBv1-I7asPFb_aC3tstOm8szhO-DP39382-W_R3F2XsVNOB5Eo78AaksQ1Cb_rt-12FoxEI3JqhF7PSTK0PAAqQQ994ZfrlXv4owFj48UrBee4RRjNoAVw7Az2imNA73guN4DvuJ0HZiDwS-2jPN5iHuySOabaj6abLs1CyMKI1y5iUIpP7LJTIk1oKGe12TbxROaMsoRlNwiROaBrE-zAWEU84jxBrpCSmeORKB1q_HSet28zSmIcJC9Nko3mN2s0qy1iP4yKchLFJdG0-BW3roXUkplo57z5gvPIac85t06XxJC8lV3qweFXe88tr8folePkGhKVTW6SxsK7t3Dy3GazO72RZ-W6og8YcCSunbOuxPVnzNzaesHLm6Agr1yLecvZfAAAA__-AA8SZ">