[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 08:07:27 PDT 2021


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/20210318/3c18eb2a/attachment.html>


More information about the llvm-dev mailing list