Issue 75585
Summary unexpected output results in fusion using -O1
Labels new issue
Assignees
Reporter Elowen-jjw
    For the following two c files, I performed the equivalent transformation of loop from **file1.c** to **file2.c**. I ran these two files respectively using different optimization levels including **-O0**, **-O1**, **-O2**, **-O3**, **-Os**, **-Ofast**. The exact output results(i.e. checksum values) are:
```
                     -O0 -O1             -O2             -O3             -Os             -Ofast 
file1.c              BAE78610        25BE175         25BE175 25BE175         25BE175         25BE175      
file2.c BAE78610        BAE78610        25BE175         25BE175         25BE175 25BE175 
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -O1), thank you.

command line:
```
clang <filename.c> <optimization level> -lm -I $CSMITH_HOME/include && ./a.out
```
version: clang+llvm 14.0.0
os: ubuntu 22.04

**file1.c**
```

#include "csmith.h"

static int32_t g_a31[1];
static int64_t g_b31[1];

struct S0 {
  volatile int64_t f0;
  const int64_t f1;
};

static int32_t g_12 = 0x703026D8L;
static int32_t g_42[3][2] = {{(-3L), (-3L)}, {(-3L), (-3L)}, {(-3L), (-3L)}};
static int32_t *g_61 = &g_42[1][1];
static int32_t **volatile g_60 = &g_61;
static volatile struct S0 g_75 = {-1L, 1L};
static volatile struct S0 *volatile g_74 = &g_75;

static void func_1(void);

static void func_1() {
  int i, j, k;
  for (i = 0; i < 2; i++) {
    int ii_4;
    // fusion
    for (j = 0, ii_4 = 0; j < 1; j++, ii_4++) {
      for (k = 0; k < 1; k++) {
 g_a31[ii_4] = g_42[2][0] * g_12 - g_42[2][1];
      }
    }
    int jj_4;
    for (jj_4 = 0; jj_4 < 1; jj_4++) {
      g_b31[jj_4] = (*g_74).f1 * g_a31[jj_4] + (**g_60);
    }
  }
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
 platform_main_begin();
  crc32_gentab();
  func_1();
 transparent_crc(g_12, "g_12", print_hash_value);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 2; j++) {
      transparent_crc(g_42[i][j], "g_42[i][j]", print_hash_value);
    }
  }
 transparent_crc(g_75.f0, "g_75.f0", print_hash_value);
 transparent_crc(g_75.f1, "g_75.f1", print_hash_value);
  for (i = 0; i < 1; i++) {
    transparent_crc(g_a31[i], "g_a31[i]", print_hash_value);
  }
  for (i = 0; i < 1; i++) {
 transparent_crc(g_b31[i], "g_b31[i]", print_hash_value);
  }
 platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
 return 0;
}

```
**file2.c**
```

#include "csmith.h"

static int32_t g_a31[1];
static int64_t g_b31[1];

struct S0 {
  volatile int64_t f0;
  const int64_t f1;
};

static int32_t g_12 = 0x703026D8L;
static int32_t g_42[3][2] = {{(-3L), (-3L)}, {(-3L), (-3L)}, {(-3L), (-3L)}};
static int32_t *g_61 = &g_42[1][1];
static int32_t **volatile g_60 = &g_61;
static volatile struct S0 g_75 = {-1L, 1L};
static volatile struct S0 *volatile g_74 = &g_75;

static void func_1(void);

static void func_1() {
  int i, j, k;
  for (i = 0; i < 2; i++) {
    int ii_4;
    int jj_4;
    int ij_4;
    // fusion
    for (j = 0, ii_4 = 0, jj_4 = 0, ij_4 = 0; ij_4 <= 1; ij_4++) {
      if (ij_4 <= 1 && j < 1) {
        for (k = 0; k < 1; k++) {
 g_a31[ii_4] = g_42[2][0] * g_12 - g_42[2][1];
        }
 j++;
        ii_4++;
      }
      if (ij_4 <= 1 && jj_4 < 1) {
 g_b31[jj_4] = (*g_74).f1 * g_a31[jj_4] + (**g_60);
 jj_4++;
      }
    }
  }
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
  platform_main_begin();
 crc32_gentab();
  func_1();
  transparent_crc(g_12, "g_12", print_hash_value);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 2; j++) {
      transparent_crc(g_42[i][j], "g_42[i][j]", print_hash_value);
    }
  }
  transparent_crc(g_75.f0, "g_75.f0", print_hash_value);
  transparent_crc(g_75.f1, "g_75.f1", print_hash_value);
  for (i = 0; i < 1; i++) {
 transparent_crc(g_a31[i], "g_a31[i]", print_hash_value);
  }
  for (i = 0; i < 1; i++) {
    transparent_crc(g_b31[i], "g_b31[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}

```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to