[llvm-bugs] [Bug 46126] New: Failure to optimize tail call to jump when a pointer to a variable that dies before the tail call is passed to an external function

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 28 13:10:02 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46126

            Bug ID: 46126
           Summary: Failure to optimize tail call to jump when a pointer
                    to a variable that dies before the tail call is passed
                    to an external function
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

void external_function();
void takes_ptr(int *);

void f()
{
    {
        int x;
        takes_ptr(&x);
    }

    external_function();
}

With -O3, LLVM produces this :

f(): # @f()
  push rax
  lea rdi, [rsp + 4]
  call takes_ptr(int*)
  call external_function()
  pop rax
  ret

GCC produces this :

f():
  sub rsp, 24
  lea rdi, [rsp+12]
  call takes_ptr(int*)
  add rsp, 24
  jmp external_function()

Since `x` dies before `external_function` is called, there is no possibility
that `external_function` may depend on `x` still being alive (which I presume
is why GCC does not do this optimization when `x` is still alive by the time
`external_function` is called)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200528/2d28a6f7/attachment.html>


More information about the llvm-bugs mailing list