<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64007>64007</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Optimization Comparison (Clang15 vs Clang16)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following two functions:
```c
int foo(int a)
{
return (a - a * a) ? -a : -a * a ;
}
int bar(int a)
{
return (a * a - a) ? -a : -a * a ;
}
```
Clang15 generates the following for these functions:
```asm
foo(int): # @foo(int)
mov eax, edi
neg eax
ret
bar(int): # @bar(int)
mov eax, edi
neg eax
ret
```
However, Clang16 (and trunk) generates the following:
```asm
foo(int): # @foo(int)
mov eax, 1
mov ecx, 1
sub ecx, edi
imul ecx, edi
test ecx, ecx
cmove eax, edi
imul eax, edi
neg eax
ret
bar(int): # @bar(int)
lea eax, [rdi - 1]
imul eax, edi
test eax, eax
mov eax, 1
cmove eax, edi
imul eax, edi
neg eax
ret
```
https://godbolt.org/z/jvMvhhndW
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2PozgQ_TXFxUpkio-EA4d8CO1ltcc9G6gQdxs7sg2Z6V8_AhKmO5NOd8aKZIeHq169ZxfCOdloohySLST7QHT-aGz-uhDWmrMLSlP_zHdGO1mTZf5I7GCUMmepG-bPhh06XXlptINoA3wPfAMpn37V9F9qzw7GAK6HlQDMLu-tttOCMcYs-c5qBrgWbMEEA9yMrzKICrYQDKLNOA2PGUTba4j9ZTFnKoX9fqYp3OKpTNfq3ifeKaGbMGENabLCk7sR6mBG6Rw9kku4dnoyizUUEI2kHw3AiEHMP-yaqx1Ga_pxJvEDcMeolh9xTc2MT4AlP61mNZ-i8mHXH1S-T-MyZjZ3tf_HnKknO4ScbEhHb3XNvO306-DsJ7Y8YcGzGod3yq7uIa4rp33VfVFk26m7uCfn3wPVjWhVa3p6YPoc-Bb_2obbQ_Gl64rEe3Eg2dpasgULIdl_k9Vc7gW4JfdY_78W49Oj-fhMHr0_jTccC8CiMXVplF8a2wAWb4DFS_9vfzzq-v-gzqM6izIRUB6m6yyLMcFVcMzLLExEGCVJVpaIacQTHqWIKS-jtCK-CmSOHCO-wjBEXMerZXSIS87Xh7KOKT4Qh5hTK6RaKtW3Q-5AOtdRnsacrwIlSlJubPqIms5sBAFx-AbYfNizKLvGQcyVdN79juKlV5T_d_KylW9i6GVsZ9qTsNKZsa1em2HvrhcSMAs6q_IbWaQ_duWyMi1gMYS_TIuTNS9UecBiJOUAi5H0rwAAAP__WUHFxw">