[Bug tree-optimization/60196] Incorrect compilation with -fwrapv and -ftree-vectorize

dpb at corrigendum dot ru gcc-bugzilla@gcc.gnu.org
Wed Mar 12 14:33:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60196

--- Comment #1 from Роман Донченко <dpb at corrigendum dot ru> ---
Here's another reproducer for what looks like the same problem:

#include <stdio.h>

static const short a[8] = {1,1,1,1,1,1,1,1};
static const unsigned char b[8] = {0,0,0,0,0,0,0,0};

static int foo()
{
    int sum = 0, i;

    for (i = 0; i < 8; ++i)
        sum += a[i] * b[i];

    return sum;
}

int main()
{
    printf("%d\n", foo());
    return 0;
}

The correct result is 0, but compiling with -O1 -ftree-vectorize yields 8. I
looked at the disassembly, and it just sums the elements of a, b is not used at
all.

For this one, adding -fwrapv actually fixes it, but I don't think there are any
overflows here.


More information about the Gcc-bugs mailing list