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

            Bug ID: 90204
           Summary: [8 Regression] C code is optimized worse than C++
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the example:


struct v {
    int val[16];
};

struct v test(struct v a, struct v b) {
    struct v res;

    for (int i = 0; i < 16; i++)
        res.val[i] = a.val[i] + b.val[i];

    return res;
}


Compiling that snippet with `g++ -O3 -march=skylake-avx512` gives a short
assembly:
test(v, v):
  push rbp
  mov rax, rdi
  mov rbp, rsp
  vmovdqu32 ymm1, YMMWORD PTR [rbp+16]
  vmovdqu32 ymm2, YMMWORD PTR [rbp+48]
  vpaddd ymm0, ymm1, YMMWORD PTR [rbp+80]
  vmovdqu32 YMMWORD PTR [rdi], ymm0
  vpaddd ymm0, ymm2, YMMWORD PTR [rbp+112]
  vmovdqu32 YMMWORD PTR [rdi+32], ymm0
  vzeroupper
  pop rbp
  ret


Compiling the same sample with the C compiler and same flags produces a ~150
lines of assembly with a lot of jumps and comparisons. The regression appeared
after GCC-7.3

Reply via email to