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

            Bug ID: 104551
           Summary: Wrong code with -O3 for skylake-avx512,
                    icelake-server, and sapphirerapids
           Product: gcc
           Version: 12.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: ---

Reproducer (I was not able to merge it into a single file):
// func.cpp
extern unsigned var_11, var_178;
extern unsigned char arr_492[];
void test() {
  for (bool a = 0; a < (bool)var_11; a = 2)
    for (unsigned b = 0; b < var_11;
         b += 1)
      var_178 = arr_492[b] ? arr_492[b] : (char) b;
}

// driver.cpp 
unsigned int var_11 = 16U;
unsigned int var_178 = 0;
unsigned char arr_492 [16];

void test();

int main() {
    for (int i = 0; i < 16; ++i)
        arr_492 [i] = (unsigned char)128;
    test();
    __builtin_printf("%u\n", var_178);
    if (var_178 != 128)
        __builtin_abort();
    return 0;
}

Error:
>$ g++ -O0 func.cpp driver.cpp -march=skylake-avx512 && sde -skx -- ./a.out 
128
>$ g++ -O3 func.cpp driver.cpp -march=skylake-avx512 && sde -skx -- ./a.out 
4294967168
Aborted (core dumped)

g++ (git://gcc.gnu.org/git/gcc.git:master
58aeb75d4097010ad9bb72b964265b18ab284f93) 12.0.1 20220213 (experimental)

Reply via email to