https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107323
Bug ID: 107323 Summary: Problem with GCC optimizition Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fatemetmhr at gmail dot com Target Milestone: --- Created attachment 53732 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53732&action=edit The code Hi! I faced a problem with GCC optimizitions on codeforces.com. I used GNU G++20 11.2.0 (64 bit, winlibs) for my code but the bug can be found in GCC 11.2.0 anywhere else (and even with some other versions of GCC). Here's the compilation command used in Codeforces: g++ -Wall -Wextra -Wconversion -static -DONLINE_JUDGE -Wl,--stack=268435456 -O2 -std=c++20 <source> There's no error or warning while compiling the code. The code has different results while using GCC 11.2.0 and GCC 9.2.0. There's a problem with -ftree-loop-distribute-patterns. The flag made GCC generate a wrong code, including a memset after the `for` part ends, so the variables will be set to 0 at the end of the process. This flag is obviously doing wrong while optimizing the code. And, somehow, it can be fixed while using -ftree-vectorize. Which isn't turned on automatically in -O2 with GCC 11.2.0 . Anyway some other versions of GCC (like 12) seems to still have the problem with -ftree-loop-distribute-patterns, but just because of using -ftree-vectorize, they works correctly. I posted many other codes here, using different optimizitions flags: https://codeforces.com/blog/entry/108168