Issue |
120355
|
Summary |
Insufficient Optimization of Variadic Functions for Some Targets
|
Labels |
new issue
|
Assignees |
|
Reporter |
jonathan-gruber-jg
|
Clang insufficiently optimizes variadic functions for some target architectures. I only tested the target architectures aarch64 and riscv64, so I'm unsure about other target architectures.
Below is a minimal test case:
```
#include <stdarg.h>
void yes_ap(int dummy, ...) {
va_list ap;
va_start(ap, dummy);
va_end(ap);
}
void no_ap(int dummy, ...) {
/* Nothing. */
}
```
Host system: Arch Linux, x86_64.
Clang version: official Arch Linux package of clang, version 18.1.8-4.
Command line to reproduce results: clang -c test.c --target=\<arch\> -O\<opt-level\>
aarch64 assembly with -O2, -O3, -Os, or -Oz is along the lines of this:
```
yes_ap:
sub sp, sp, #0xc0
stp x1, x2, [sp, #136]
stp x3, x4, [sp, #152]
stp x5, x6, [sp, #168]
str x7, [sp, #184]
stp q0, q1, [sp]
stp q2, q3, [sp, #32]
stp q4, q5, [sp, #64]
stp q6, q7, [sp, #96]
add sp, sp, #0xc0
ret
no_ap:
sub sp, sp, #0xc0
stp x1, x2, [sp, #136]
stp x3, x4, [sp, #152]
stp x5, x6, [sp, #168]
str x7, [sp, #184]
stp q0, q1, [sp]
stp q2, q3, [sp, #32]
stp q4, q5, [sp, #64]
stp q6, q7, [sp, #96]
add sp, sp, #0xc0
ret
```
riscv64 assembly with -O2, -O3, -Os, or -Oz is along the lines of this:
```
yes_ap:
addi sp,sp,-64
sd a7,56(sp)
sd a6,48(sp)
sd a5,40(sp)
sd a4,32(sp)
sd a3,24(sp)
sd a2,16(sp)
sd a1,8(sp)
addi sp,sp,64
ret
no_ap:
addi sp,sp,-64
sd a7,56(sp)
sd a6,48(sp)
sd a5,40(sp)
sd a4,32(sp)
sd a3,24(sp)
sd a2,16(sp)
sd a1,8(sp)
addi sp,sp,64
ret
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs