<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 after-loop range optimizations"
href="https://bugs.llvm.org/show_bug.cgi?id=42119">42119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed after-loop range optimizations
</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>Clang trunk -g0 -O3 -march=haswell
void g(unsigned x);
unsigned p(unsigned x, unsigned n) {
while (x < n) {
g(x);
x++;
}
// x == n
return x;
}
unsigned p2(unsigned x, unsigned n) {
while (x < n) {
g(x);
x++;
}
return n;
}
Clang somehow did not realize that x == n after this while loop, it is a missed
LLVM IR optimization..
p(unsigned int, unsigned int):
push rbp
push rbx
push rax
mov ebx, edi
cmp edi, esi
jae .LBB0_4
mov ebp, esi // move this instruction above cmp
.LBB0_2:
mov edi, ebx
call g(unsigned int)
inc ebx
cmp ebp, ebx
jne .LBB0_2
mov ebx, ebp // useless
.LBB0_4:
mov eax, ebx // move from ebp
add rsp, 8
pop rbx
pop rbp
ret
for p2, Clang generates better code:
p2(unsigned int, unsigned int):
push rbp
push rbx
push rax
mov ebx, esi
cmp edi, esi
jae .LBB0_3
mov ebp, edi
.LBB0_2:
mov edi, ebp
call g(unsigned int)
inc ebp
cmp ebx, ebp
jne .LBB0_2
.LBB0_3:
mov eax, ebx
add rsp, 8
pop rbx
pop rbp
ret</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>