<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66568>66568</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compiling with clang and -O3 produces incorrect code
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rnburn
</td>
</tr>
</table>
<pre>
Compiling the attached files with -O3 produces code that gives the wrong result. I don't see anything wrong with the function and it works when compiling without optimizations and with gcc and full optimizations.
Expected Output (also same result with gcc-12 and any optimization level)
```
root@76535d9143be:/src/bug# clang++-18 -std=c++20 *.cc
root@76535d9143be:/src/bug# ./a.out
2 0 3 0 0 0 3 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 3 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 1 0 0 1 0 3 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 2 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 0 1 1 0 3 3 0 1 1 0 3 0 0 0 0 1 1 1 0 0 0 1 1 2 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 2 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 1 3 1 0 1 3 0 0 0 0 1 3 3 0 1 0 0 0 1 3 0 0 0 1 2 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 1 3 3 0 1 0 0 0 0 0 0 0 0 1 1
252
```
Result with optimizations:
```
root@76535d9143be:/src/bug# clang++-18 -O3 -std=c++20 *.cc
root@76535d9143be:/src/bug# ./a.out
2 0 3 0 0 0 3 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 3 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1600880264
253
no no
```
Here are the details of the version of clang I'm using
```
root@76535d9143be:/src/bug# clang++-18 --version
Ubuntu clang version 18.0.0 (++20230913042131+f3fdc967a87d-1~exp1~20230913042254.1182)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk-P6yYQ_zTkMrJlwCH2IYfdbqO-00pVe64wTGxaAhZ_drM9vM9e-U_2Jdv0qZWeVKmqsOwBZn7zYxjMyBhN7xD3ZPtItk8bmdPgwz64Lge36bx-23_nT6OxxvWQBgSZklQDajgaixFeTRqgeOYwBq-zwgjKa4Q0yAS9ecE4G70G73oIGLNNJXwC7R1huwQREaR7S8OEvijNgJPNMTuVjHcgnQaT4NWH3yK8DuhAvTOatH1O4MdkTuZ3ORnE2WLG6ZWaO8ds7a1OSaonUj0s7-_PI6qEGp5zGnMCwhppo4coT7iyfscrKJshpXu7QQSLL2gJa1dgUa3P3A3eJ1JXO7HlW93SmndI-ANhhxgUYYcu94RxUFa6nrBHwh4L2kARkyb8SS0jrALCHkql_gliSdhBlj6nxYhBBRyquXGgq1TNEr2Sl--1xnW7P_r1mcs8BbZq0SsO9I7lMsL-Bgf6pzX8VWPz6unq-1q-Zkg_sL2HSj-sasK-75_e-L9Eld74vHD50r9I7CY696NF72DcsFs3f8vu5uby_vEqzW9OypRV3y6ln_l_MK3_b_9Oo6KqmqZior5kOF8E58H5ryT7DxgQZMD5otGYpLER_HHuvmCI0__cH5fkhU-E7U6Qo3H9NzwIxepnwfi5yy7l1eGFAW3KqpyOR3M5KoxXLeVVzSinhD0e-VGrVuxks9MF_YznkX6-UmLbuqS0Ye-X0k8y9JgIf4BzI34RdTGqwhqXz0Xv8qoyBJQaTl6jnRRHH815mfrkYpLWon4yYZoi7JBjmFZo3IfAbPSe65a3coN7Ktq6qStKxWbY79qGKUGlVkIeFYqOakmpVi2KpmOt2pj9ugBR1dstFaWoaiV3nCqUtWw5JXWFJ2lsae3LqfSh35gYM-6F2IpmY2WHNs7FDGNryNlU14T9pF90uY-krqyJKX5BSCZZvKpz5p_gshfTVX9T3hinfAio0lzobHKw-yGlMS5bTtihN2nIXan8ibDD5GL9FGPwv6JKhB1mxpGww0z6jwAAAP__eztf6g">