<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58920>58920</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Failed DCE of inline asm?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nickdesaulniers
</td>
</tr>
</table>
<pre>
Consider the following example:
```c
static unsigned long __fls1 (unsigned long word) {
return (sizeof(word) * 8) - 1 - __builtin_clzl(word);
}
static unsigned long __fls2(unsigned long word) {
asm ("bsr %1,%0"
: "=r" (word)
: "rm" (word));
return word;
}
unsigned long x (unsigned long y) {
__fls1(y); // elimated
__fls2(y); // not eliminated?
return 42;
}
```
clang-16 `-O2` produces:
```
x: # @x
movq %rdi, -8(%rsp)
bsrq -8(%rsp), %rax
movl $42, %eax
retq
```
shouldn't we have eliminated the dead store to `word`? cc @topperc @eefriedman @jyknight
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVNty2yAQ_Rr0wtgD6GLrQQ9OXL_2EzxIYIsEgQMosfP1XZDTxHam7UzN6MLC4cDunqW14tQ8WuOVkA6HXuKd1dq-KbPH8siHg5YoXyGyRmSFKjI93WT7wIPq8AiL90YKrC0s2m532lOM2PJy_M06gViN0eJhWo2hORlGZyLYq3dpd9D5jWMrvIydGabwbrftqHRQZtvpd_2JQ_mZDi3W585fzsb-dDR83_bhKfdDdBIx1noHvZIi9gg_AiN32gJDmoCZoXztIuuXUN6T3g2X5FMK7rDBWQqJ9r8IL3ivVHGZ9-OtSk83Ep30DMDT2VXENvBgqdXAgxRXSHaLNDYktDIJn29u9F-wb2T8UWyT2Wlu9jNaYRiZ_WTwxQdnxdhJf1ufk3mMKfu3WLEco4IcPw8W22BfX6bZ0gkFgsWzZRJx6fwhuniBBmEn9BUGVkWD33LribsA5yeQvAZBdF6-9cz3dtTCILYI-E3inr_KLxFOt5iQXGAfrJM42Bi0JCwgyDe466K3wR4O0qWulDunpBi4idbT6dmofR9wJhtaVUtKFnWRZ6LJRZ3XPAsqaNlsuNKw1_rxB7Y7rIxWRsY6hw2y0emmD-GQUpNEsFehH9t5Z6F8Nlq_fvxmkMQn2QUwlfcjJJNtymXNSNY3otrlS85rvighOJSQgglSF7uqIqItOp5p3krtG1Q-QE0OsF6KmT0EiMM7XH7WxNugXGeqYYQxSimhNa0Jm9Oiq3jLa0HLsqSkihEYwJ15PNHcun3mmnS4dtx7mNTKB_85yX2qGJk2Bn4-ht66xqjuWUjPR22UdD5L_jTJmV-2Lqfo">