On Mon, 11 Dec 2023, 17:08 Jingwen Wu via Gcc, wrote: > Hello, I'm sorry to bother you. And I have some gcc compiler optimization > questions to ask you. > First of all, I used csmith tools to generate c files randomly. Meanwhile, > the final running result was the checksum for global variables in a c file. > For the two c files in the attachment, I performed the equivalent > transformation of loop from *initial.**c* to *transformed.c*. And the two > files produced different results (i.e. different checksum values) when > using *-O2* optimization level, while the results of both were the same > when using other levels of optimization such as *-O0*, *-O1*, *-O3*, *-Os*, > *-Ofast*. > Please help me to explain why this is, thank you. > Sometimes csmith can generate invalid code that gets miscompiled. It looks like you're compiling with no warnings, which is a terrible idea: > command line: *gcc file.c -O2 -lm -I $CSMITH_HOME/include && ./a.out* > You should **at least** enable warnings and make sure gcc isn't pointing out any problems in the code. You should also try the options suggested at http://gcc.gnu.org/bugs/ which help identify invalid code. version: gcc 12.2.0 > os: ubuntu 22.04 >