<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJytU8Fu2zAM_Rr5IiyQJSd2Dj5kyzLsUGzACgw9BbJEx1plKbDoFuvXj3aSph2GocBmUJaoRz8-kXIT7c-arcTJDJPvJxNbJjYuIE-xh3YMtF-ZGBJy2mRyxeSa7_cacXDNiLDfE052HAcgaDJ1JnmIzvIQsXPhMAddoWuWlpBpdhMvK884p8dxprYvVbiXDHPEWfLLvT_n-z_RA-A4BIKej1Fuz4tLFU_ubQcceocIlptogfuobWLyA9XQDNBDwNnTwfKEcYDE6VtHgyuOrp98teEd4jHRgskd2SHaJnpcxIH07p5olHffy7wqU37K-jnwgzHcIbcRUmCyxLew3MFa34Xi5tOJZeNTnJW2k6bn8pM0l3iv6TAYL5WYOjzFIp03Hkm4e9LoYpgF8Htn7unAb9HQpY_2622X2szWyq7VWmd6xC4O9ZcW7r91zseQjYOvfyNy2I3NwsSeHO8fLtO74xB_gKHrunMpjUDF3i1VLmTW1avVUltZiRzapTKVkFCVpVW2KVRbQV5lXjfgU82W1H8Z4JHPFLRmy2327wpcLYWUIhdrehVKLVpl86qwhSmUaE1jWCGg184vJp6pRtlQz5TNeEgEepcwXUGdkjsEgFkwKUSHHuobykqX71VTHknr1NO__70rkc2K61nuLxVQO7s>53102</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization with `__attribute__((pure))`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
OfekShilon
</td>
</tr>
</table>
<pre>
```c++
int somefunc(const int&) __attribute__((pure));
void nothing();
int f(int i) {
i = somefunc(i);
i++;
nothing();
i++;
nothing();
i++;
return i;
}
```
The emitted code loads, increments, and stores `i` 3 times : https://godbolt.org/z/7YW7187s1
In gcc it doesn't: https://godbolt.org/z/Ye9aYn4MG
Also, if `somefunc` is made to return void, the optimization does kick in: https://godbolt.org/z/hsEdPThsf
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytUsGO2yAQ_Rp8QY1scOL44EPaNFUPq1bqSlVOEYaxTYMhMuNddb--YyfZpFVV7aHWYBje8ObNQB3Mz4qt0rNpJt5Plm5ZurEeeQw9NKOn_bUOPiKnTSZWTJT8cFCIg61HhMOBcLLTOABBk8kLyVOwhvuAnfXtHHSDblkaQqbZTrysuOCcPsuZ3N6rsPcMc8RF8v3e3_P9n-gBcBw8Qa9lFNvL4trFs_vYAYfeIoLhOhjgLigTmfhAPdQD9OBx9pQ3PGIYIHI6a2lwydH2ky83vEM8RVowsSNrg6mDw0UYSO_uhUax_15k6yJm56yfPW-15ha5CRA9EwW-hWUPpdr7_OHTmWXjYpiVNpOm1_aTNBt5r6gYDNdOTDc8xSLVG04k3L4otMHPAvjR6iMV_BYNXfxovj52sUlMJU0pS5WgRQfVg42Rmvgb-bPFbtL271e4SpNxcNUfmenoWC906Mlx7uk6vTsN4Qdoet87SjgC3c5uKbNUJF2VCQCo85UqDJTZEgoFy1oKrVVZSxKbOFWDixVb0oMRHp75TEFrttwmthKpEGmWlvTLpVw00mTr3OQ6l2mja83yFHpl3WLSMbUkGapZUj22kUBnI8YbqGK0rQeY0xG_GrELQ_WlgeO3zrrgkzl7Nav_BS0uJzY">