[llvm-commits] Issue with Win64 local area stack offset
Jan Sjodin
jan_sjodin at yahoo.com
Tue Jun 22 10:08:19 PDT 2010
I did a couple of tests with this function:
%structType = type <{ <16 x i32> }>
define i64 @myfun(i64 %arg0, i64 %arg1) nounwind {
entry:
%test.i = alloca %structType, align 64
%conv4.i = ptrtoint %structType* %test.i to i64
%tmp0 = add i64 %conv4.i, %arg0
%tmp1 = add i64 %tmp0, %arg1
ret i64 %tmp1
}
I compiled with:
llc.exe -disable-fp-elim -march=x86-64 -stack-alignment=64
Original llc:
_myfun: # @myfun
# BB#0: # %entry
pushq %rbp
movq %rsp, %rbp
subq $112, %rsp
leaq -80(%rbp,%rcx), %rax
addq %rdx, %rax
addq $112, %rsp
popq %rbp
ret
If %arg0 and %arg1 are 0, and assuming that rsp is 0xB8 at the entry:
%rbp == 0xB0
leaq -80(%rbp, %rcx) == 0x60 (not aligned)
Patched llc:
# BB#0: # %entry
pushq %rbp
movq %rsp, %rbp
subq $112, %rsp
leaq -112(%rbp,%rcx), %rax
addq %rdx, %rax
addq $112, %rsp
popq %rbp
ret
%rbp == 0xB0
leaq -112(%rbp,%rcx) == 0x40 (aligned)
Second test was compiled with:
llc.exe -disable-fp-elim -march=x86-64 -stack-alignment=64
Original llc:
# BB#0: # %entry
subq $120, %rsp
leaq 32(%rsp,%rcx), %rax
addq %rdx, %rax
addq $120, %rsp
ret
at entry: %rsp = 0xB8
after alloc: %rsp == 0x40
leaq 32(%rsp,%rcx) == 0x60 (not aligned)
Patched llc:
# BB#0: # %entry
subq $120, %rsp
leaq (%rsp,%rcx), %rax
addq %rdx, %rax
addq $120, %rsp
ret
at entry: %rsp == 0xB8
after alloc: %rsp == 0x40
leaq (%rsp,%rcx) == 0x40 (aligned)
The code that is handling the shadow space is in X86FastISel.cpp:
// Allocate shadow area for Win64
if (Subtarget->isTargetWin64()) {
CCInfo.AllocateStack(32, 8);
}
This was a patch that I submitted a while back, because it was not handled
in the fast isel. This was perhaps incomplete because the only other place
that i can find is in X86IselLowering::LowerMemOpCallTo:
const unsigned FirstStackArgOffset = (Subtarget->isTargetWin64() ? 32 : 0);
The shadow space allocation should be handled by X86IselLowering::lowerCall imo.
- Jan
----- Original Message ----
> From: Anton Korobeynikov <anton at korobeynikov.info>
> To: Jan Sjodin <jan_sjodin at yahoo.com>
> Cc: llvm-commits at cs.uiuc.edu
> Sent: Mon, June 21, 2010 6:56:17 PM
> Subject: Re: [llvm-commits] Issue with Win64 local area stack offset
>
> Hello, Jan
> I hope this is clear because it is easy to get confused
> and it would be
> nice if someone can confirm this issue. Below is a
> simple patch that fixes the
> problem by not allocating the spill area and
> sets the LAO to 8. The shadow
> area is already handled by the function
> call lowering code.
I might be wrong, but it doesn't seem so. Call lowering
> code only puts
the arguments assuming
that there is a shadow space already
> allocated, but nothing inside
prologue allocates it
(this was what
> "StackSize +=32" used for).
Please verify your observations on:
1.
> Function in case of eliminated FP
2. Function with just 2
> arguments
Thanks!
--
With best regards, Anton
> Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State
> University
More information about the llvm-commits
mailing list