https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87238

            Bug ID: 87238
           Summary: Redundant Restore of $x0 when memcpy always returns
                    the first argument.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

$ cat test.cpp

struct BigStruct {
  int x[64];
};

void structByValue(BigStruct s);

void callStructByValue(int unused, int unused2, BigStruct s) {
  structByValue(s);
}

$ g++ -O3 -arch arm64 test.cpp -S -o -

callStructByValue(int, int, BigStruct):
  stp x29, x30, [sp, -272]!
  mov x1, x2
  mov x2, 256
  add x29, sp, 0
  add x0, x29, 16 <<-------- 
  bl memcpy
  add x0, x29, 16 <<-------- redundant
  bl structByValue(BigStruct)
  ldp x29, x30, [sp], 272
  ret


We could just do remove the second 'add x0, x29, 16' as memcpy is guaranteed to
return the pointer to desination.
http://man7.org/linux/man-pages/man3/memcpy.3.html


Possibly duplicate of PR82991 but not sure.

Reply via email to