<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 - Suboptimal runtime unrolling"
href="https://bugs.llvm.org/show_bug.cgi?id=50105">50105</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Suboptimal runtime unrolling
</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>int p(int x, int *arr) {
int s = 0;
for (int i = 0; i < x && i < 3; ++i) {
s += arr[i];
}
return s;
}
LLVM
p(int, int*): # @p(int, int*)
test edi, edi
jle .LBB0_1
add edi, -1
cmp edi, 2
mov ecx, 2
cmovb ecx, edi
mov eax, dword ptr [rsi]
test ecx, ecx
je .LBB0_5
add eax, dword ptr [rsi + 4]
cmp ecx, 1
je .LBB0_5
add eax, dword ptr [rsi + 8]
.LBB0_5:
ret
.LBB0_1:
xor eax, eax
ret
GCC
p(int, int*):
xor eax, eax
test edi, edi
jle .L1
mov eax, DWORD PTR [rsi]
cmp edi, 1
jle .L1
add eax, DWORD PTR [rsi+4]
cmp edi, 2
jle .L1
add eax, DWORD PTR [rsi+8]
.L1:
ret
We have here some useless code which can be eliminated and then LLVM can match
GCC.
Also with for (int i = 0; i < x && i < 16; ++i) LLVM produces a lot of
(vectorized) asm, GCC just unrolls 16x.
<a href="https://godbolt.org/z/sc59Gv3a9">https://godbolt.org/z/sc59Gv3a9</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>