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

            Bug ID: 40574
           Summary: Field ordering still causes extra memcpy
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: jmuizel...@mozilla.com
                CC: llvm-bugs@lists.llvm.org

Even with bug 39844 fixed we can still get extra memcpys depending on field
ordering:

#include <stdlib.h>
struct SV {
        size_t capacity;
        size_t disc;
        size_t data[40];

        static SV make() {
                SV ret;
                ret.capacity = 0;
                ret.disc = 0;
                return ret;
        }
};

struct L {
        SV a;
        SV b;
};

template<class T>
struct Allocation {
    T *vec;
    void init(T s) {
        *vec = s;
    }
};

void bar(Allocation<L> a, double g) {
        L s = { SV::make(), SV::make() };
        a.init(s);
}

produces

bar(Allocation<L>, double):                # @bar(Allocation<L>, double)
        subq    $680, %rsp              # imm = 0x2A8
        xorps   %xmm0, %xmm0
        movaps  %xmm0, (%rsp)
        movaps  %xmm0, 336(%rsp)
        movq    %rsp, %rsi
        movl    $672, %edx              # imm = 0x2A0
        callq   memcpy
        addq    $680, %rsp              # imm = 0x2A8
        retq

but moving capacity to the end gives:

bar(Allocation<L>, double):                # @bar(Allocation<L>, double)
        movq    $0, (%rdi)
        xorps   %xmm0, %xmm0
        movups  %xmm0, 328(%rdi)
        movq    $0, 664(%rdi)
        retq

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

Reply via email to