<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84047>84047</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unexpected codegen for __builtin_elementwise_bitreverse on unsigned char and short
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shafik
</td>
</tr>
</table>
<pre>
Given the following: https://godbolt.org/z/M1hEqs9q5
```cpp
unsigned char f(unsigned char a) {
return __builtin_elementwise_bitreverse(a);
}
unsigned short f(unsigned short a) {
return __builtin_elementwise_bitreverse(a);
}
signed char f3(signed char a) {
return __builtin_elementwise_bitreverse(a);
}
signed short f3(signed short a) {
return __builtin_elementwise_bitreverse(a);
}
```
for the `unsigned char` and `unsigned short` cases it automatically returns `0` w/ any level of optimization e.g.
```llvm
define dso_local noundef zeroext i8 @f(unsigned char)(i8 noundef zeroext %a) local_unnamed_addr {
entry:
tail call void @llvm.dbg.value(metadata i8 %a, metadata !16, metadata !DIExpression())
ret i8 0
}
```
Based on the documentation: https://clang.llvm.org/docs/LanguageExtensions.html
This is not expected behavior.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VM1u2zwQfBrqsohAUZYtHXRIPkcfCrS39mxQ5EpiS5EOSfknT19QShw7KdBeAhgWsORyZvZnuPeqN4g1KR5IsU34FAbraj_wTv1KWivP9f_qgAbCgNBZre1RmZ7k9zCEsPckvyesIazprWytDql1PWHNM2HNt2x4fPLVU0HoltD7l_81XX5iv18ik5kJSBADd9ARVt5GOGEVkM3DchvAYZicgd2unZQOyuxQ44gmHJXHXauCwwM6j4SVMZPkL4lks73mccHwg3XhFnYJfQ7ujdacsPLzpd4KvcL8JJ2vHb7m0Fk3DxBZ05vukjUFbuRNfKYVDwT36EEF4FOwIw9KcK3PLwR9zIkwcCSsAW7OoPGAGmwHdh_UqJ55UNYApn36xwnU-jAuIYmdMgjS2522gmswdjISO3hGZ_EUQJVAVvTDbEb9rFTlh_uEFXNZ59d2kzF8RLnjUrq3SqMJ7hzXZ6l74EpDFAgHq2SEi_xS2fbpgesp1nvEwCUPfKYzI_wHlxhhWbZ-H9l-eTztHXqvrCGsnPlWV42OL9F_6d8D9yjBLi4grZjiRMz1_egEQnPTpzP7xQykFZ6w5is3_cR7fDwFNJGRT4cw6muY74PyoDwYGwBPexQBJbQ48IOyLk1kncsqr3iCdbah1XpN84IlQ00zwZBiwfKK0aoQK16IKpO8rSRdYZYnqmaUrWhOi2yTV1mWtlnRFVlelm0uNlXRkRXFkSt9oZ0o7yesyxVdbRLNW9R-dkjGDB5hPiSMRcN0dcy5a6fex6YpH_zbK0EFjfUPcxEjrMQeDcSF-NuKxXq_80LzurXJ5HT9zoFVGKY2FXYkrJmHe_nc7Z39iSIQ1sy8Yy9mXb8DAAD__8e842Q">