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

            Bug ID: 116512
           Summary: Wrong vzeroupper at the function epilogue
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stlim0727 at gmail dot com
  Target Milestone: ---

Code:
#include <immintrin.h>

struct B {
    union {
        __m512 f;
        __m512i s;
    };
};

auto foo(int n) {
    B res;
    res.s = _mm512_set1_epi32(n);

    return res;
}

auto bar(int n) {
    B res;
    res.s = _mm512_set1_epi32(n);

    return res.s;
}

Compiled with:
g++ -O2 -std=c++2a -march=skylake-avx512 test.cpp

Result:
foo(int):
        vpbroadcastd    zmm0, edi
        vzeroupper
        ret
bar(int):
        vpbroadcastd    zmm0, edi
        ret


Unlike bar(), foo() has wrong vzeroupper which clears upper bits of zmm0 except
the lower 128-bits.

Reply via email to