[llvm-bugs] [Bug 42119] New: Missed after-loop range optimizations
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jun 3 13:35:44 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42119
Bug ID: 42119
Summary: Missed after-loop range optimizations
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Loop Optimizer
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190603/1accc679/attachment.html>
More information about the llvm-bugs
mailing list