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

            Bug ID: 87323
           Summary: More complicated assembly for sode with custom copy
                    constructor
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugzi...@poradnik-webmastera.com
  Target Milestone: ---

[code]
#include <stdint.h>

typedef int32_t VInt __attribute((vector_size(32)));

class V1
{
    VInt v;
public:
    constexpr V1(const V1& v) = default;
    //constexpr V1(const V1& v) : v(v.v) {}

    constexpr V1(const VInt& v) : v(v) {}

    constexpr V1 operator+(const V1& v2) const
    { return V1(v + v2.v); }

    constexpr V1 operator*(const V1& v2) const
    { return V1(v * v2.v); }

    constexpr operator VInt() const
    { return v; }
};

V1 test1(V1 a, V1 b, V1 c)
{
    return a * c + b * c;
}
[/code]

When code above is compiled, gcc produces following assembly:

[out]
test1(V1, V1, V1):
  vpaddd ymm0, ymm1, ymm0
  vpmulld ymm0, ymm0, ymm2
  ret
[/out]

However when I comment out default copy constructor and uncomment custom one
(which should be equivalent), generated assembly is as follows:

[out]
test1(V1, V1, V1):
  vmovdqa ymm0, YMMWORD PTR [rcx]
  mov rax, rdi
  vpmulld ymm1, ymm0, YMMWORD PTR [rsi]
  vpmulld ymm0, ymm0, YMMWORD PTR [rdx]
  vpaddd ymm0, ymm1, ymm0
  vmovdqa YMMWORD PTR [rdi], ymm0
  vzeroupper
  ret
[/out]

Reply via email to