[llvm-dev] Question on using caller saved register around a library call.
Venkataramanan Kumar via llvm-dev
llvm-dev at lists.llvm.org
Thu Mar 18 23:00:20 PDT 2021
Is that the case, all XMM, YMM and ZMM are caller saved or scratch only ?
As per the ABI, we don't have any Callee saved registers available?
regards,
Venkat.
On Thu, 18 Mar 2021 at 20:37, Venkataramanan Kumar <
venkataramanan.kumar.llvm at gmail.com> wrote:
> Hi,
>
> For the below test case, I see LLVM allocates an XMM1 register for holding
> the variable "t". My understanding is XMM1 is a caller saved register and
> hence it is spilled to stack and restored back around the library call.
>
> Ref: https://godbolt.org/z/Peaczh
>
> --snip--
> #include <math.h>
> double arr[1000000];
> int n;
> double foo()
> {
> double t = 0.0;
> for(int i=0;i<100000;i++)
> t += log(arr[i]);
>
> return t;
> }
> --snip--
>
> Assembly Snip
> ---Snip--
> .LBB0_1: # =>This Inner Loop Header: Depth=
> 1
> #DEBUG_VALUE: foo:t <- 0.000000e+00
> #DEBUG_VALUE: i <- 0
> *vmovupd %ymm1, (%rsp) # 32-byte Spill*
> .Ltmp1:
> .loc 1 8 15 prologue_end # ./example.cpp:8:15
> vmovupd arr+800000(%rbx), %ymm0
> .loc 1 8 11 is_stmt 0 # ./example.cpp:8:11
> callq __svml_log4 at PLT
> .Ltmp2:
> .loc 1 0 11 # ./example.cpp:0:11
> *vmovupd (%rsp), %ymm1 # 32-byte Reload*
> .loc 1 8 8 # ./example.cpp:8:8
> vaddpd %ymm1, %ymm0, %ymm1
> .loc 1 7 26 is_stmt 1 # ./example.cpp:7:26
> addq $32, %rbx
> jne .LBB0_1
> ---Snip---
>
> Why is LLVM not choosing a callee saved register here? It can then avoid
> pushing to the stack and restoring from the stack in the loop.
>
> regards,
> Venkat.
>
>
>
On Thu, 18 Mar 2021 at 20:37, Venkataramanan Kumar <
venkataramanan.kumar.llvm at gmail.com> wrote:
> Hi,
>
> For the below test case, I see LLVM allocates an XMM1 register for holding
> the variable "t". My understanding is XMM1 is a caller saved register and
> hence it is spilled to stack and restored back around the library call.
>
> Ref: https://godbolt.org/z/Peaczh
>
> --snip--
> #include <math.h>
> double arr[1000000];
> int n;
> double foo()
> {
> double t = 0.0;
> for(int i=0;i<100000;i++)
> t += log(arr[i]);
>
> return t;
> }
> --snip--
>
> Assembly Snip
> ---Snip--
> .LBB0_1: # =>This Inner Loop Header: Depth=
> 1
> #DEBUG_VALUE: foo:t <- 0.000000e+00
> #DEBUG_VALUE: i <- 0
> *vmovupd %ymm1, (%rsp) # 32-byte Spill*
> .Ltmp1:
> .loc 1 8 15 prologue_end # ./example.cpp:8:15
> vmovupd arr+800000(%rbx), %ymm0
> .loc 1 8 11 is_stmt 0 # ./example.cpp:8:11
> callq __svml_log4 at PLT
> .Ltmp2:
> .loc 1 0 11 # ./example.cpp:0:11
> *vmovupd (%rsp), %ymm1 # 32-byte Reload*
> .loc 1 8 8 # ./example.cpp:8:8
> vaddpd %ymm1, %ymm0, %ymm1
> .loc 1 7 26 is_stmt 1 # ./example.cpp:7:26
> addq $32, %rbx
> jne .LBB0_1
> ---Snip---
>
> Why is LLVM not choosing a callee saved register here? It can then avoid
> pushing to the stack and restoring from the stack in the loop.
>
> regards,
> Venkat.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210319/e5c594e4/attachment.html>
More information about the llvm-dev
mailing list