[llvm-bugs] [Bug 38849] New: Redundant Restore of $x0 when memcpy always returns the first argument.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 5 14:01:26 PDT 2018


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

            Bug ID: 38849
           Summary: Redundant Restore of $x0 when memcpy always returns
                    the first argument.
           Product: new-bugs
           Version: 7.0
          Hardware: Other
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: hiraditya at msn.com
                CC: llvm-bugs at lists.llvm.org

$ cat test.cpp

struct BigStruct {
  int x[64];
};

void structByValue(BigStruct s);

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


$ ./bin/clang++ -O3 -arch arm64 redundant-reg.cpp -S -o -


        .section        __TEXT,__text,regular,pure_instructions
        .ios_version_min 5, 0
        .globl  __Z17callStructByValueii9BigStruct ; -- Begin function
_Z17callStructByValueii9BigStruct
        .p2align        2
__Z17callStructByValueii9BigStruct:     ; @_Z17callStructByValueii9BigStruct
        .cfi_startproc
; %bb.0:                                ; %entry
        sub     sp, sp, #288            ; =288
        stp     x28, x27, [sp, #256]    ; 8-byte Folded Spill
        stp     x29, x30, [sp, #272]    ; 8-byte Folded Spill
        add     x29, sp, #272           ; =272
        .cfi_def_cfa w29, 16
        .cfi_offset w30, -8
        .cfi_offset w29, -16
        .cfi_offset w27, -24
        .cfi_offset w28, -32
        mov     x8, x2  
        mov     x0, sp <<<<------------------- Copy
        orr     w2, wzr, #0x100
        mov     x1, x8
        bl      _memcpy
        mov     x0, sp <<<<------------------- Copy
        bl      __Z13structByValue9BigStruct
        ldp     x29, x30, [sp, #272]    ; 8-byte Folded Reload
        ldp     x28, x27, [sp, #256]    ; 8-byte Folded Reload
        add     sp, sp, #288            ; =288
        ret
        .cfi_endproc
                                        ; -- End function

.subsections_via_symbols

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

-- 
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/20180905/9da055dd/attachment.html>


More information about the llvm-bugs mailing list