<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 - Failure to use condition to simplify branch"
href="https://bugs.llvm.org/show_bug.cgi?id=39225">39225</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to use condition to simplify branch
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>andrea.dibiagio@gmail.com, filcab@gmail.com, llvm-bugs@lists.llvm.org, llvm-bugzilla@jfbastien.com
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/I7HTBx">https://godbolt.org/z/I7HTBx</a>
void test(int &v, int i) {
if (v == i)
v = i;
}
clang -O3 -march=btver2
_Z4testRii: # @_Z4testRii
cmpl %esi, (%rdi)
jne .LBB0_2
movl %esi, (%rdi)
.LBB0_2:
retq
How come we couldn't remove this store and just return?
More complicated could also avoid some work:
void test1(int &v, int i, bool replace) {
if (replace || v == i)
v = i;
}
_Z5test1Riib: # @_Z5test1Riib
cmpl %esi, (%rdi)
je .LBB1_2
testb %dl, %dl
jne .LBB1_2
retq
.LBB1_2:
movl %esi, (%rdi)
retq
How come we couldn't just store based on the test?
int test3(int &v, int i, bool replace) {
if (replace || v == i) {
v = i;
return 1;
}
return 0;
}
_Z5test3Riib: # @_Z5test3Riib
cmpl %esi, (%rdi)
je .LBB2_2
xorl %eax, %eax
testb %dl, %dl
jne .LBB2_2
retq
.LBB2_2:
movl $1, %eax
movl %esi, (%rdi)
retq
Trickier, but we could avoid the store and just set the returncode:
_Z5test3Riib: # @_Z5test3Riib
cmpl %esi, (%rdi)
je .LBB2_3
xorl %eax, %eax
testb %dl, %dl
jne .LBB2_2
retq
.LBB2_2:
movl %esi, (%rdi)
.LBB2_3:
movl $1, %eax
retq</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>