<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - missed optimization for the sum of two numbers"
href="https://bugs.llvm.org/show_bug.cgi?id=52365">52365</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>missed optimization for the sum of two numbers
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dushistov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>For such simple function:
int32_t f(int32_t & __restrict a, const int32_t & __restrict b) {
a += b + 17;
return a + b;
}
clang (12/13) produces (-O3) such assembly (amd64):
mov eax, dword ptr [rsi]
mov ecx, dword ptr [rdi]
lea edx, [rax + rcx]
add ecx, eax
add ecx, 17
mov dword ptr [rdi], ecx
add eax, edx
add eax, 17
ret
while gcc producues:
mov eax, DWORD PTR [rsi]
mov edx, DWORD PTR [rdi]
lea edx, [rax+17+rdx]
mov DWORD PTR [rdi], edx
add eax, edx
ret
even without benchmark (which show that gcc's variant wins)
you can see that for some reason clang forgot that in "ecx"
has "a + b + 17", so it can just add it to eax and that's all.
But for some reason it recalculate expression again via:
add eax, edx
add eax, 17</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>