Skip to content
systemcoding.dev
Toolchains

Report loops that failed to vectorise with -fopt-info-vec-missed

Find out which loops GCC 14 refused to vectorise with -fopt-info-vec-missed, which prints the loop's location and the reason it gave up.

1 min read
Summarize in AI

When a hot loop is slower than you expected, the first question is whether the vectoriser touched it. -fopt-info-vec-missed prints a note for every loop it looked at and rejected, with the line of the loop.

s.cc
float total(const float *a, int n)
{
    float sum = 0.0f;
    for (int i = 0; i < n; i++)
        sum += a[i];
    return sum;
}
Shell
gcc -O3 -fopt-info-vec-missed -c s.c 2>&1 | grep "couldn't vectorize"
Text
s.c:4:5: missed: couldn't vectorize loop

That line is followed by others that give the reason, and for this loop the reason is that adding floats in a different order changes the result, which -O3 alone is not allowed to do. Adding -fassociative-math together with -fno-signed-zeros and -fno-trapping-math, or -ffast-math, lifts the restriction, at the price of different rounding. The reason lines contain internal names that change between GCC releases, so read them as hints. The variant -fopt-info-vec-optimized reports the loops that did vectorise, and -fopt-info-vec-all both. The flags are documented under Developer Options for GCC 14.2.

Taggedcgcc
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.