<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109718>109718</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Missed optimization: dead store to thread-local not optimized out
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tavianator
</td>
</tr>
</table>
<pre>
For this code
```c
void foo(void **ptr) {
static _Thread_local void *tmp;
tmp = *ptr;
*ptr = 0;
}
```
Clang generates
```asm
foo:
movq (%rdi), %rax
movq %rax, %fs:foo.tmp@TPOFF
movq $0, (%rdi)
retq
```
I think it's an alias analysis issue, because a `_Thread_local int` is optimized out. But even without alias analysis, we know that `tmp` hasn't had its address taken.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8U0FzmzwQ_TXLZScescIGDhyceJj5Dt-0h9wzC5KNGkAOWpymv74jcBsn05ZhQNK-fav3pOUQ3Gm0toLtPWwPCc_S-akSvjgeWfyUNN68VbWfUDoXsPXGgjqA2l-_O7W-7Tq_eGfw6D1QsQyB9kD7s0xAJUJ-v6IQEYOwuBafHrvJsnnqfcs9_sqR4Qz6BizDGUEf8Mp1G1qXlqj6HYD88Gl_t5t-6Hk84cmOdmKx4Y96OAzrShSj9-_14jP4y8tauwDaTsYBlUAPGCf8_Yp9By2La_gYQEfKTVSYqcevX-r6b9yZWpNuaqzIycrLP-T9F49qfEYnQHlAHpF7x3HA_VtwAV0Is43cjW15DhYZYac-noQbBXYKXUB_Fje4H9agn2WDeD8L2osd8dVJ52f5xB55Xy0-j_4VpWOJ1FHsTmHHYQTKBTs26CQgGzPZEFD42Y6bxFTalLrkxFZpTnlKmU4p6ar0mB2zNM9NWha6KLjY6iYvTKkbVlmac-IqUpSpkjSpbJvShrXW2bFRxU5nTWoKyJQd2PWbvr8MGz-dksWDKlVlnhZJz43tw9IDRG28HUAU22GqYsJdM58CZKp3QcI7hTjpl8ZZM7YH_N-FEH1aHWNxfgS9R2PZYBA_WRSPsth8t9o8evlocDJPfdWJnONFAaqB6pOTbm42rR-A6lj9-rs7T_6bbQWoXtQEoPoq6FLRzwAAAP__na4i4Q">