<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 on redundant condition"
href="https://bugs.llvm.org/show_bug.cgi?id=51265">51265</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization on redundant condition
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zhongyunde@tom.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Missed optimization on redundant condition.
a) test base on gcc 7.3, it will generate same assemble with O3 if change
condtion
if (nex_group) into if (1)
b) while with the clang 12.0.1, even with the newest trunk version (commit
79fbbeb4), use if (1) will generate more smarter code.
For example in x86-x64 clang (<a href="https://godbolt.org/z/zzWa1d4x1">https://godbolt.org/z/zzWa1d4x1</a>), use `test r10`
to check whether or not r10 is equal zero is redundant.
exclusion(int, int, int*): # @exclusion(int, int, int*)
mov r10d, dword ptr [rip + nex_group]
xor eax, eax
test r10, r10
je .LBB0_11
test r10d, r10d
jle .LBB0_11
movsxd r11, esi
Example code built with clang test.c -S -O3
// ===== test.c =========
int nex_group;
int *ex1_bit,*ex2_bit;
int exclusion(int i, int j, int *mask) {
int m;
// we can see that condition nex_group already guard in statement for
if (nex_group) { // generate smarter assemble with if (1)
for (m = 0; m < nex_group; m++) {
if (mask[i] & ex1_bit[m] && mask[j] & ex2_bit[m]) return 1;
if (mask[i] & ex2_bit[m] && mask[j] & ex1_bit[m]) return 1;
}
}
return 0;
}</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>