<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65040>65040</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
single character char stream insertion is worse than using string literal with >= -O1
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
#include <iostream>
void f1()
{
std::cout << "test" << '\n';
}
void f2()
{
std::cout << "test" << "\n";
}
```
`-O0` - https://godbolt.org/z/vrfTf1voh
`-O1` - https://godbolt.org/z/jeeoPdeqr
Passing a single character char to stream insertion leads to worse code than using a single character string literal when optimizing code with >= `-O1`. I would have expected it to be the other way around. Interestingly it also applies to GCC.
According to `llvm-mca` the amount of `uOps` is even higher for the optimized code although it uses less cycles.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykU8FuozAQ_RpzGQWBHQgcOKTJZtVTe9gfcOwhuHIwa4-TTb9-ZZJuo7YrrbQSwpYfnvfezEOGYA4jYseqB1ZtMxlpcL7rjcezPGG2d_rSsbq4PmqaWLFlxZpxYUZlo0ZgYmNcII_yyMS3Gzy_T85o6EvGG8bbG7B6uG4AAAJpJtZMrJWLlOowsQHGOWEgxvn7yYpVmzEt4uGtzPYzEf9_In4l4l8QvbXgnpfVxeIpHcICBqIpJBa-Y3x3cHrvLOXOHxjfvTK-O_n-R1-e3HB3tfy3qy-I7lnjT3_P_ZwmNx5AQlosghqkl4rQzzsgB9ehgBkDejJuBItSh4ScnQ8IymkEGuQI8W-lAvmEWEPopYXzgCO4iczRvKbzucLZ0ABp9GILf2zl8AhnF62GQZ4Q8NeEilCDocS_T7wIjgb0cJYXkN7FUefwOBJ6DJR0XNLH0gYHcpqswVn5980mv2_DWinnddJCLrFbezoujkqmziYKeXRxJHB9AuPTFBJgAuAJRxjMIQnonb_KuRpDffUlLQ0uHoYkIwYMYDEEUBdlMeSZ7oRuRSsz7Mq6FZwL0VTZ0NVty1e8Uo2qlcQK96KqcbUqG6UKRCEz0_GCi6LhTVku2-Uy133ZF8tWFcgbWVcNWxZ4lMbmyUuKQWZCiNjVVbEsMiv3aMP8u3I-4hlmcI7uNvPd7H8fD4EtC2sChfcqZMhi93VaPkXFhFtI7vLxMQx3c188lVn0tvsQZUND3OfKHRnfJR23ZTF594KKGN_N6gPju9nd7wAAAP__oR1nCQ">