<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 - Poor codegen with simple varargs"
href="https://bugs.llvm.org/show_bug.cgi?id=49395">49395</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Poor codegen with simple varargs
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>redbeard0531@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>These two functions should generate the same code, but the varargs version is
much worse. And it is even worser still when you enable
-fstack-protector-strong. While GCC's codegen isn't perfect here, it is a lot
better than clang's
<a href="https://godbolt.org/z/c19dz9">https://godbolt.org/z/c19dz9</a>
#include <stdarg.h>
int test_va(int x, ...) {
int i;
va_list va;
va_start(va, x);
i = va_arg(va, int);
va_end(va);
return i + x;
}
int test_args(int x, int i) {
return i + x;
}
test_args: # @test_args
lea eax, [rdi + rsi]
ret
test_va: # @test_va
sub rsp, 88
mov r10d, eax
mov eax, edi
test r10b, r10b
je .LBB0_2
movaps xmmword ptr [rsp - 48], xmm0
movaps xmmword ptr [rsp - 32], xmm1
movaps xmmword ptr [rsp - 16], xmm2
movaps xmmword ptr [rsp], xmm3
movaps xmmword ptr [rsp + 16], xmm4
movaps xmmword ptr [rsp + 32], xmm5
movaps xmmword ptr [rsp + 48], xmm6
movaps xmmword ptr [rsp + 64], xmm7
.LBB0_2:
mov qword ptr [rsp - 88], rsi
mov qword ptr [rsp - 80], rdx
mov qword ptr [rsp - 72], rcx
mov qword ptr [rsp - 64], r8
mov qword ptr [rsp - 56], r9
lea rcx, [rsp - 96]
mov qword ptr [rsp - 112], rcx
lea rcx, [rsp + 96]
mov qword ptr [rsp - 120], rcx
movabs rcx, 206158430216
mov qword ptr [rsp - 128], rcx
mov edx, 8
cmp rdx, 40
ja .LBB0_4
mov ecx, 8
add rcx, qword ptr [rsp - 112]
add edx, 8
mov dword ptr [rsp - 128], edx
jmp .LBB0_5
.LBB0_4:
mov rcx, qword ptr [rsp - 120]
lea rdx, [rcx + 8]
mov qword ptr [rsp - 120], rdx
.LBB0_5:
add eax, dword ptr [rcx]
add rsp, 88
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>