<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 - Unroll small loops implied by llvm.assume"
href="https://bugs.llvm.org/show_bug.cgi?id=47247">47247</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unroll small loops implied by llvm.assume
</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>#include <cstddef>
unsigned sum_small(unsigned data[], size_t count) {
if ( count > 4) {
__builtin_unreachable();
}
unsigned sum = 0;
for (size_t i = 0; i < count; ++i) {
sum += data[i];
}
return sum;
}
LLVM generates loop:
sum_small(unsigned int*, unsigned long): #
@sum_small(unsigned int*, unsigned long)
test rsi, rsi
je .LBB0_1
xor ecx, ecx
xor eax, eax
.LBB0_4: # =>This Inner Loop Header: Depth=1
add eax, dword ptr [rdi + 4*rcx]
add rcx, 1
cmp rsi, rcx
jne .LBB0_4
ret
.LBB0_1:
xor eax, eax
ret
GCC unrolls loop:
sum_small(unsigned int*, unsigned long):
test rsi, rsi
je .L4
mov eax, DWORD PTR [rdi]
cmp rsi, 1
je .L1
add eax, DWORD PTR [rdi+4]
cmp rsi, 2
je .L1
add eax, DWORD PTR [rdi+8]
cmp rsi, 3
je .L1
add eax, DWORD PTR [rdi+12]
ret
.L4:
xor eax, eax
.L1:
ret
<a href="https://godbolt.org/z/Przjfo">https://godbolt.org/z/Przjfo</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>