Skip to content

Inefficient code for passing an alloca as argument to a function #10804

@llvmbot

Description

@llvmbot
Bugzilla Link 10432
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @asl,@lattner,@stoklund

Extended Description

Given

extern bool ToNumberSlow(double *dp);
void Interpret() {
double l, r;
for (;;) {
ToNumberSlow(&l);
ToNumberSlow(&r);
}
}

We produce what is probably the best IL:

define void @​_Z9Interpretv() noreturn nounwind uwtable {
entry:
%l = alloca double, align 8
%r = alloca double, align 8
br label %for.cond
for.cond:
%call = call zeroext i1 @​_Z12ToNumberSlowPd(double* %l) nounwind
%call1 = call zeroext i1 @​_Z12ToNumberSlowPd(double* %r) nounwind
br label %for.cond
}
declare zeroext i1 @​_Z12ToNumberSlowPd(double*)

but that then codegens to:

    pushq   %r14
    pushq   %rbx
    subq    $24, %rsp
    leaq    16(%rsp), %r14
    leaq    8(%rsp), %rbx
    .align  16, 0x90

.LBB0_1:
movq %r14, %rdi
callq _Z12ToNumberSlowPd
movq %rbx, %rdi
callq _Z12ToNumberSlowPd
jmp .LBB0_1

gcc produces

    subq    $24, %rsp

.L2:
movq %rsp, %rdi
call _Z12ToNumberSlowPd
leaq 8(%rsp), %rdi
call _Z12ToNumberSlowPd
jmp .L2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions