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

--- Comment #6 from Jeevitha <jeevitha at gcc dot gnu.org> ---
The following dot_product function gets vectorized with the latest GCC trunk
and gcc 15.1.0:

#include <cstdint>
#include <cstddef>
extern float dot_product(const int16_t *v1, const int16_t *v2, size_t len);
float dot_product(const int16_t *v1, const int16_t *v2, size_t len)
{
    int64_t d = 0;
    for (size_t i = 0; i < len; i++)
        d += int32_t(v1[i]) * int32_t(v2[i]);
    return static_cast<float>(d);
}


I observed that -O2 was used during compilation. However, for GCC versions
earlier than 15, vectorization of this loop requires -O3. Since they are using
the -O2 flag, GCC 15 necessary in this case.

Reply via email to