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

            Bug ID: 122489
           Summary: attribute assume prevents vectorization
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manu at gcc dot gnu.org
  Target Milestone: ---

https://godbolt.org/z/G9e9h176K

#include <stdlib.h>
#include <stdint.h>
typedef uint_fast8_t dimension_t;

#ifndef ASSUME
#define ASSUME(x) __attribute__((assume(x)))
#endif
double
get_expected_value(const double * restrict points, dimension_t dim, size_t
npoints,
                   const double * restrict w)
{
    // points >= 0 && w >=0 so max_s_w cannot be < 0.
    double max_s_w = 0;
    for (size_t i = 0; i < npoints; i++) {
        const double * restrict p = points + i * dim;
        double min_ratio = p[0] * w[0];
        for (dimension_t k = 1; k < dim; k++) {
            double ratio = p[k] * w[k];
            ASSUME(ratio >= 0);
            min_ratio = (min_ratio < ratio) ? min_ratio : ratio;
        }
        max_s_w = (max_s_w > min_ratio) ? max_s_w : min_ratio;
    }
    return max_s_w;
}


gcc -O2 -march=x86-64-v3 -fopt-info-vec-missed-optimized -fno-signed-zeros
-ffinite-math-only test.c -o test.o

<source>:14:26: missed: couldn't vectorize loop
<source>:14:26: missed: not vectorized: unsupported control flow in loop.
<source>:17:35: missed: couldn't vectorize loop
<source>:18:29: missed: not vectorized: no vectype for stmt: _9 = *_8;
 scalar_type: const double

gcc -O2 -march=x86-64-v3 -fopt-info-vec-missed-optimized -fno-signed-zeros
-ffinite-math-only -DASSUME(X)=0 test.c -o test.o

<source>:14:26: missed: couldn't vectorize loop
<source>:14:26: missed: not vectorized: unsupported control flow in loop.
<source>:17:35: optimized: loop vectorized using 32 byte vectors and unroll
factor 4


I would have expected the opposite: hinting that ratio >= 0 would make GCC
vectorize even with -fsigned-zeros.

Reply via email to