https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96415
Bug ID: 96415
Summary: GCC produces incorrect code for loops with -O3 for
skylake-avx512 and icelake-server
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: vsevolod.livinskij at frtk dot ru
Target Milestone: ---
Error:
>$ g++ -O0 driver.cpp func.cpp && ./a.out
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
>$ g++ -O3 driver.cpp func.cpp -march=skylake-avx512 && sde -skx -- ./a.out
1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0
Reproducer:
//driver.cpp
#include <stdio.h>
unsigned short var_0 = 14;
unsigned int arr_10 [16];
void test(unsigned short var_0);
int main() {
test(var_0);
for (int i = 0; i < 16; ++i)
printf("%u ", arr_10[i]);
printf("\n");
}
//func.cpp
extern int arr_10[16];
void test(unsigned short a) {
for (unsigned e = 0; e < 16; e += 4)
for (char f = 0; f < 6; f += 4)
for (unsigned g = 0; g < a + 1; g++)
arr_10[g] = 1;
}
GCC version:
11.0.0 (3a4a92598014d33ef2c8b8ec38d8ad917812921a)
I also applied the fix for bug #95396