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 is 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 *-O1* optimization level, while the results of both are the same when
using other levels of optimization such as *-O0*, *-O2*, *-O3*, *-Os*,
*-Ofast*.
Please help me to explain why this is, thank you.

command line: *gcc file.c -O1 -lm -I $CSMITH_HOME/include && ./a.out*
version: gcc 12.2.0
os: ubuntu 22.04
#include "csmith.h"

static int32_t g_a368[3];
static int32_t g_b368[3];

union U0 {
  const int32_t f0;
};

union U1 {
  const uint16_t f0;
  const uint64_t f1;
  int32_t f2;
  const signed f3 : 29;
};

union U2 {
  int64_t f0;
  int16_t f1;
};

static union U2 g_13 = {7L};
static uint16_t g_21 = 0x4AB4L;
static uint32_t g_24 = 4294967286UL;
static int64_t g_42[3][3] = {{0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}, {0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}, {0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}};
static int8_t g_43[1][2][1] = {{{0xDCL}, {0xDCL}}};
static int64_t *g_62 = &g_13.f0;
static int64_t **volatile g_61 = &g_62;
static union U0 g_87 = {0xA9ACF304L};
static union U0 *g_89[1][3][2] = {{{&g_87, &g_87}, {&g_87, &g_87}, {&g_87, &g_87}}};
static union U0 **volatile g_88[3][1] = {{&g_89[0][2][1]}, {&g_89[0][2][1]}, {&g_89[0][2][1]}};
static union U1 g_409[1][3][2] = {{{{0xD839L}, {0xD839L}}, {{0xD839L}, {0xD839L}}, {{0xD839L}, {0xD839L}}}};

static void func_1(void);

static void func_1() {
  uint32_t p_5 = 3L;
  int32_t l_34 = 0xFF2FD6B2L;

  for (g_13.f0 = 1; (g_13.f0 >= 0); g_13.f0 -= 1) {
    uint8_t l_19 = 1UL;
    int32_t l_25 = 0x5DB5A26CL;
    uint16_t l_35 = 0x2570L;
    uint8_t l_84 = 1UL;
    if ((safe_unary_minus_func_uint8_t_u((((safe_rshift_func_uint16_t_u_s((safe_lshift_func_uint8_t_u_s(l_19, 4)), 3)) <= ((safe_div_func_int32_t_s_s((+(l_34 == 0x494FL)), l_35)), l_34)) >= 3UL)))) {
      for (p_5 = 0; (p_5 <= 0); p_5 += 1) {
        g_42[2][2] ^= 1L;
      }
      if (((g_43[0][1][0] = 0x3F3A8A1DL) < (((g_42[2][0], g_24), 0x9878FF5FL) ^ 0L))) {
      }
    } else {
      for (l_25 = 0; (l_25 <= 1); l_25 += 1) {
        int ii_9;
        int jj_9;
        int ij_9;
        // fusion in max execTimes
        for (g_21 = 0, ii_9 = 0, jj_9 = 0, ij_9 = 0; ij_9 <= 3; ij_9++) {
          if (ij_9 <= 2 && (g_21 <= 1)) {
            g_a368[ii_9] = g_43[0][1][0] * l_84 - g_409[0][0][0].f2;
            g_21 += 1;
            ii_9++;
          }
          if (ij_9 <= 3 && jj_9 < 3) {
            g_b368[jj_9] = g_409[0][1][1].f0 * g_a368[jj_9] + (*g_89[0][2][0]).f0;
            jj_9++;
          }
        }
      }
    }
  }
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
  platform_main_begin();
  crc32_gentab();
  func_1();
  transparent_crc(g_21, "g_21", print_hash_value);
  transparent_crc(g_24, "g_24", print_hash_value);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      transparent_crc(g_42[i][j], "g_42[i][j]", print_hash_value);
    }
  }
  for (i = 0; i < 1; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 1; k++) {
        transparent_crc(g_43[i][j][k], "g_43[i][j][k]", print_hash_value);
      }
    }
  }
  transparent_crc(g_87.f0, "g_87.f0", print_hash_value);
  for (i = 0; i < 1; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 2; k++) {
        transparent_crc(g_409[i][j][k].f0, "g_409[i][j][k].f0", print_hash_value);
      }
    }
  }
  for (i = 0; i < 3; i++) {
    transparent_crc(g_a368[i], "g_a368[i]", print_hash_value);
  }
  for (i = 0; i < 3; i++) {
    transparent_crc(g_b368[i], "g_b368[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}
#include "csmith.h"

static int32_t g_a368[3];
static int32_t g_b368[3];

union U0 {
  const int32_t f0;
};

union U1 {
  const uint16_t f0;
  const uint64_t f1;
  int32_t f2;
  const signed f3 : 29;
};

union U2 {
  int64_t f0;
  int16_t f1;
};

static union U2 g_13 = {7L};
static uint16_t g_21 = 0x4AB4L;
static uint32_t g_24 = 4294967286UL;
static int64_t g_42[3][3] = {{0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}, {0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}, {0xE9505C00D4B3BEBDLL, 0xCDCEC458AF32651ELL, 0xCDCEC458AF32651ELL}};
static int8_t g_43[1][2][1] = {{{0xDCL}, {0xDCL}}};
static int64_t *g_62 = &g_13.f0;
static int64_t **volatile g_61 = &g_62;
static union U0 g_87 = {0xA9ACF304L};
static union U0 *g_89[1][3][2] = {{{&g_87, &g_87}, {&g_87, &g_87}, {&g_87, &g_87}}};
static union U0 **volatile g_88[3][1] = {{&g_89[0][2][1]}, {&g_89[0][2][1]}, {&g_89[0][2][1]}};
static union U1 g_409[1][3][2] = {{{{0xD839L}, {0xD839L}}, {{0xD839L}, {0xD839L}}, {{0xD839L}, {0xD839L}}}};

static void func_1(void);

static void func_1() {
  uint32_t p_5 = 3L;
  int32_t l_34 = 0xFF2FD6B2L;

  for (g_13.f0 = 1; (g_13.f0 >= 0); g_13.f0 -= 1) {
    uint8_t l_19 = 1UL;
    int32_t l_25 = 0x5DB5A26CL;
    uint16_t l_35 = 0x2570L;
    uint8_t l_84 = 1UL;
    if ((safe_unary_minus_func_uint8_t_u((((safe_rshift_func_uint16_t_u_s((safe_lshift_func_uint8_t_u_s(l_19, 4)), 3)) <= ((safe_div_func_int32_t_s_s((+(l_34 == 0x494FL)), l_35)), l_34)) >= 3UL)))) {
      for (p_5 = 0; (p_5 <= 0); p_5 += 1) {
        g_42[2][2] ^= 1L;
      }
      if (((g_43[0][1][0] = 0x3F3A8A1DL) < (((g_42[2][0], g_24), 0x9878FF5FL) ^ 0L))) {
      }
    } else {
      for (l_25 = 0; (l_25 <= 1); l_25 += 1) {
        int ii_9;
        // fusion in max execTimes
        for (g_21 = 0, ii_9 = 0; (g_21 <= 1); g_21 += 1, ii_9++) {
          g_a368[ii_9] = g_43[0][1][0] * l_84 - g_409[0][0][0].f2;
        }
        int jj_9;
        for (jj_9 = 0; jj_9 < 3; jj_9++) {
          g_b368[jj_9] = g_409[0][1][1].f0 * g_a368[jj_9] + (*g_89[0][2][0]).f0;
        }
      }
    }
  }
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
  platform_main_begin();
  crc32_gentab();
  func_1();
  transparent_crc(g_21, "g_21", print_hash_value);
  transparent_crc(g_24, "g_24", print_hash_value);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      transparent_crc(g_42[i][j], "g_42[i][j]", print_hash_value);
    }
  }
  for (i = 0; i < 1; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 1; k++) {
        transparent_crc(g_43[i][j][k], "g_43[i][j][k]", print_hash_value);
      }
    }
  }
  transparent_crc(g_87.f0, "g_87.f0", print_hash_value);
  for (i = 0; i < 1; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 2; k++) {
        transparent_crc(g_409[i][j][k].f0, "g_409[i][j][k].f0", print_hash_value);
      }
    }
  }
  for (i = 0; i < 3; i++) {
    transparent_crc(g_a368[i], "g_a368[i]", print_hash_value);
  }
  for (i = 0; i < 3; i++) {
    transparent_crc(g_b368[i], "g_b368[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}

Reply via email to