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

            Bug ID: 39654
           Summary: On x86-64, RAX is unnecessarily preserved when
                    returning member of struct containing couple of floats
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: s.h...@oisyn.nl
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

Compiler Explorer link: https://godbolt.org/z/9-TCNN

Consider the following code:
====================
using type = float;

struct Data
{
    type a, b;
};

type _a, _b;
__attribute__((noinline)) Data GetData() { return {_a, _b}; }

auto FirstMember()
{
    return GetData().a;
}
====================

For FirstMember(), this will generate (with -O):
  push rax
  call GetData()
  pop rax
  ret

If you change 'type' to 'double', this will just turn into a tail call:
  jmp GetData() # TAILCALL

When changing 'type' to 'double' AND returning 'b' rather than 'a', we see the
preservation of RAX again:
  push rax
  call GetData()
  movaps xmm0, xmm1
  pop rax
  ret

I suspect it has to do with the rule that a function should return a pointer to
the returned struct according to the x86-64 ABI, but I don't think that applies
here as the struct is returned fully in SSE registers.

Note that it does NOT try to preserve RAX when compiling without optimizations.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to