[llvm-bugs] [Bug 49395] New: Poor codegen with simple varargs

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 2 03:59:59 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49395

            Bug ID: 49395
           Summary: Poor codegen with simple varargs
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: redbeard0531 at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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

https://godbolt.org/z/c19dz9

#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

-- 
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/20210302/58aad6a7/attachment.html>


More information about the llvm-bugs mailing list