<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 - Code-size improvement possibilities for loop lowering"
href="https://bugs.llvm.org/show_bug.cgi?id=36539">36539</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Code-size improvement possibilities for loop lowering
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gaborb@inf.u-szeged.hu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>GCC (with -Os) produces smaller code than LLVM (with -Oz) when lowering loops
with indexes known at compile-time.
Examples:
(Note: these have been generated for ARM targets but the same happens when
targeting x86_64)
* Loops that known at compile-time to be only executed once
** GCC eliminates the loop altogether
Source:
void func()
{
for (int i = 9; i < 10; i++) {
putchar(251);
}
}
GCC generated assembly code:
func:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
push {r4, lr}
movs r0, #251
bl putchar
@ sp needed
pop {r4, pc}
LLVM generated assembly code:
func:
.fnstart
.save {r4, r6, r7, lr}
push {r4, r6, r7, lr}
.setfp r7, sp, #8
add r7, sp, #8
movs r4, #1
b .LBB0_2
.LBB0_1:
movs r0, #251
bl putchar
subs r4, r4, #1
.LBB0_2:
cmp r4, #0
bne .LBB0_1
pop {r4, r6, r7, pc}
######################################################
* Loops with condition variables known at compile-time
* (These are guaranteed to be executed at least once)
** GCC can eliminate one jump instruction
Source:
void func()
{
int i = 0;
while (i < 10) {
putchar(251);
i++;
}
}
GCC generated assembly code:
func:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
push {r4, lr}
movs r4, #10
.L2:
movs r0, #251
subs r4, r4, #1
bl putchar
cmp r4, #0
bne .L2
@ sp needed
pop {r4, pc}
LLVM generated assembly code:
func:
.fnstart
.save {r4, r6, r7, lr}
push {r4, r6, r7, lr}
.setfp r7, sp, #8
add r7, sp, #8
movs r4, #10
b .LBB0_2
.LBB0_1:
movs r0, #251
bl putchar
subs r4, r4, #1
.LBB0_2:
cmp r4, #0
bne .LBB0_1
pop {r4, r6, r7, pc}</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>