[LLVMbugs] [Bug 11197] New: varargs is unnecessarily inefficient

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Oct 20 12:42:48 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=11197

           Summary: varargs is unnecessarily inefficient
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: pickensd at synopsys.com
                CC: llvmbugs at cs.uiuc.edu


The way LLVM implements varargs is unnecessarily inefficient. It seems to force
the "va_list" variable into memory when it could easily be mapped to a
register.  Is there a way to circumvent this behavior? 

Consider the following test case:

#include <stdarg.h>
void foo(int *p, ...){
    va_list ap;
    va_start(ap,p);
    while(1){
        *p = va_arg(ap,int);
    if (*p == 0) break;
    p++;
    }
}


The ARM target compiles this (at -O3) such that the loop code is quite strange:

.LBB0_3:
        ldr     r2, [sp]          <--- Unnecessary
        add     r0, r0, #4
        add     r1, r2, #4
        str     r1, [sp]          <---- Unnecessary
        ldr     r2, [r2]
        str     r2, [r0]         
        cmp     r2, #0
        bne     .LBB0_3


By contrast, GCC produces a loop that is half the size without the silly load
and store of the va_list variable:

.L3:
        ldr     r0, [r1, #4]!
        cmp     r0, #0
        str     r0, [r2, #4]!
        bne     .L3

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list