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 *-O3 and -Ofast* optimization level, while the results of both were the same when using other levels of optimization such as *-O0*, *-O1*, *-O2, **-Os*. Please help me to explain why this is, thank you.
command line: *gcc file.c -O3 -lm -I $CSMITH_HOME/include && ./a.out* *gcc file.c -Ofast -lm -I $CSMITH_HOME/include && ./a.out* version: gcc 12.2.0 os: ubuntu 22.04
#include "csmith.h" static int32_t g_a75[4]; static int32_t g_b75[4]; struct S0 { uint32_t f0; const uint16_t f1; volatile int32_t f2; uint16_t f3; int64_t f4; }; struct S1 { int32_t f0; const uint32_t f1; uint32_t f2; }; struct S2 { const int64_t f0; int32_t f1; volatile int64_t f2; int8_t f3; volatile struct S0 f4; }; static int8_t g_11 = (-6L); static int32_t g_13 = 0xC869B7D6L; static int32_t *g_12[2][3][1] = {{{&g_13}, {&g_13}, {&g_13}}, {{&g_13}, {&g_13}, {&g_13}}}; static volatile uint8_t g_27 = 2UL; static struct S1 g_237 = {0xD8430CE5L, 0x74A446EAL, 0UL}; static struct S1 g_239 = {9L, 0UL, 18446744073709551615UL}; static int64_t func_1(void); static int64_t func_1(void) { int32_t **l_488 = &g_12[1][1][0]; int i, j, k; for (i = 0; i < 1; i++) { int ii_1; // fusion in max execTimes for (j = 0, ii_1 = 0; j < 2; j++, ii_1++) { for (k = 0; k < 1; k++) { g_a75[ii_1] = g_237.f0 * g_11 - g_27; } } int jj_1; for (jj_1 = 0; jj_1 < 4; jj_1++) { g_b75[jj_1] = g_239.f0 * g_a75[jj_1] - g_13; } } return (**l_488); } int main(void) { int i, j, k; int print_hash_value = 0; platform_main_begin(); crc32_gentab(); func_1(); transparent_crc(g_11, "g_11", print_hash_value); transparent_crc(g_13, "g_13", print_hash_value); transparent_crc(g_27, "g_27", print_hash_value); transparent_crc(g_237.f0, "g_237.f0", print_hash_value); transparent_crc(g_237.f1, "g_237.f1", print_hash_value); transparent_crc(g_237.f2, "g_237.f2", print_hash_value); transparent_crc(g_239.f0, "g_239.f0", print_hash_value); transparent_crc(g_239.f1, "g_239.f1", print_hash_value); transparent_crc(g_239.f2, "g_239.f2", print_hash_value); for (i = 0; i < 4; i++) { transparent_crc(g_a75[i], "g_a75[i]", print_hash_value); } for (i = 0; i < 4; i++) { transparent_crc(g_b75[i], "g_b75[i]", print_hash_value); } platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value); return 0; }
#include "csmith.h" static int32_t g_a75[4]; static int32_t g_b75[4]; struct S0 { uint32_t f0; const uint16_t f1; volatile int32_t f2; uint16_t f3; int64_t f4; }; struct S1 { int32_t f0; const uint32_t f1; uint32_t f2; }; struct S2 { const int64_t f0; int32_t f1; volatile int64_t f2; int8_t f3; volatile struct S0 f4; }; static int8_t g_11 = (-6L); static int32_t g_13 = 0xC869B7D6L; static int32_t *g_12[2][3][1] = {{{&g_13}, {&g_13}, {&g_13}}, {{&g_13}, {&g_13}, {&g_13}}}; static volatile uint8_t g_27 = 2UL; static struct S1 g_237 = {0xD8430CE5L, 0x74A446EAL, 0UL}; static struct S1 g_239 = {9L, 0UL, 18446744073709551615UL}; static int64_t func_1(void); static int64_t func_1(void) { int32_t **l_488 = &g_12[1][1][0]; int i, j, k; for (i = 0; i < 1; i++) { int ii_1; int jj_1; int ij_1; // fusion in max execTimes for (j = 0, ii_1 = 0, jj_1 = 0, ij_1 = 0; ij_1 <= 4; ij_1++) { if (ij_1 <= 2 && j < 2) { for (k = 0; k < 1; k++) { g_a75[ii_1] = g_237.f0 * g_11 - g_27; } j++; ii_1++; } if (ij_1 <= 4 && jj_1 < 4) { g_b75[jj_1] = g_239.f0 * g_a75[jj_1] - g_13; jj_1++; } } } return (**l_488); } int main(void) { int i, j, k; int print_hash_value = 0; platform_main_begin(); crc32_gentab(); func_1(); transparent_crc(g_11, "g_11", print_hash_value); transparent_crc(g_13, "g_13", print_hash_value); transparent_crc(g_27, "g_27", print_hash_value); transparent_crc(g_237.f0, "g_237.f0", print_hash_value); transparent_crc(g_237.f1, "g_237.f1", print_hash_value); transparent_crc(g_237.f2, "g_237.f2", print_hash_value); transparent_crc(g_239.f0, "g_239.f0", print_hash_value); transparent_crc(g_239.f1, "g_239.f1", print_hash_value); transparent_crc(g_239.f2, "g_239.f2", print_hash_value); for (i = 0; i < 4; i++) { transparent_crc(g_a75[i], "g_a75[i]", print_hash_value); } for (i = 0; i < 4; i++) { transparent_crc(g_b75[i], "g_b75[i]", print_hash_value); } platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value); return 0; }