<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 - Slower sieve computation than gcc"
href="https://bugs.llvm.org/show_bug.cgi?id=47337">47337</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Slower sieve computation than gcc
</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>Linux
</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>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#define Size 819000
static int sieve (int N) {
int i, k, prime, count, n; char flags[Size];
for (n = 0; n < N; n++) {
count = 0;
for (i = 0; i < Size; i++)
flags[i] = 1;
for (i = 0; i < Size; i++)
if (flags[i]) {
prime = i + i + 3;
for (k = i + prime; k < Size; k += prime)
flags[k] = 0;
count++;
}
}
return count;
}
int main (void) {
__builtin_printf ("sieve (100) = %d", sieve (100));
}
gcc -O3:
0m0,392s
gcc -O3 -march=haswell:
0m0,392s
clang -O3:
0m0,404s
clang -O3 -march=haswell:
0m0,393s
So -march=haswell enables loop unrolling which is profitable for this code.
But gcc does not unroll this loop and it is still faster.
Maybe clang's:
mov bl, 1 ***
xor ecx, ecx
mov edx, 3
xor esi, esi
test bl, bl ***
je .LBB0_7
.LBB0_3: # in Loop: Header=BB0_1 Depth=1
lea rdi, [rcx + 2*rcx]
add rdi, 3
cmp rdi, 818999
is slower than gcc's:
add rcx, 3
add rsi, 1
add rdx, 2
cmp rcx, 2457003
je .L12
.L5:
cmp BYTE PTR [rsi], 0
je .L2
cmp rcx, 818999
Godbolt: <a href="https://godbolt.org/z/6ExqE6">https://godbolt.org/z/6ExqE6</a></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>