https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102622
Bug ID: 102622 Summary: Wrong code with -O3 for skylake-avx512 and icelake-server 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: // func.cpp #include <algorithm> extern int var_20, var_22; extern short arr_32[]; extern char arr_45[]; void test(int a, unsigned b, long long *c) { for (short d = 0; d < 13; d++) { for (int e = 0; e < a; e += 3) var_20 = 0; if (std::max(b, unsigned((short)b))) { arr_32[d] = 0; var_22 = *c; } for (unsigned f = 0; f < 69; f += 4) arr_45[f] = 0; } } driver.cpp #include <stdio.h> unsigned long long int a = 10693271954245845448ULL; unsigned int b = 1144022456U; long long int c = 42; int var_20 = 0; long long int var_22 = 0; unsigned short arr_32 [13]; unsigned char arr_45 [69]; void test(int a, unsigned int b, long long int* c); int main() { test(a, b, &c); printf("%llu\n", var_22); } Error: >$ g++ -O3 -march=skylake-avx512 func.cpp driver.cpp && sde -skx -- ./a.out 0 >$ g++ -O2 -march=skylake-avx512 func.cpp driver.cpp && sde -skx -- ./a.out 42 GCC version: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/testing/gcc/bin/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /testing/gcc/gcc_src/configure --enable-multilib --prefix=/testing/gcc/bin --disable-bootstrap Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20211004 (154fd0896ef22fcf5235e35e2b795394dddd7a33) (GCC)