Issue 75589
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         5454B4A4        686D5D8F        686D5D8F        686D5D8F 686D5D8F        686D5D8F     
file2.c         5454B4A4 89CD4121        686D5D8F        686D5D8F        686D5D8F        686D5D8F 
```
 
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 int g_a61[1];
static int64_t g_b61[1];

union U0 {
  signed f0 : 26;
  int64_t f1;
 int16_t f2;
};

static int32_t g_3 = 0x5C6F1BF5L;
static int32_t g_37 = 0x2CE6C1CCL;
static int32_t *g_121 = &g_37;
static int32_t g_168 = 0x896B5751L;
static int32_t **volatile g_217 = &g_121;
static const int32_t *g_258[2][2] = {{&g_168, &g_168}, {&g_168, &g_168}};
static int64_t g_290 = 1L;
static union U0 g_300 = {0x9E01EE1CL};
static union U0 *g_302[2][3][2] = {{{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}, {{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}};
static int64_t *g_455 = &g_290;
static int64_t *volatile *g_454 = &g_455;

static void func_1(void);

static void func_1(void) {
  int i, j, k;
 for (i = 0; i < 2; i++) {
    int ii_1;
    // fusion
    for (j = 0, ii_1 = 0; j < 1; j++, ii_1++) {
      for (k = 0; k < 1; k++) {
 g_a61[ii_1] = (*g_302[1][0][0]).f0 * g_37 - (*g_302[1][2][1]).f0;
 }
    }
    int jj_1;
    for (jj_1 = 0; jj_1 < 1; jj_1++) {
 g_b61[jj_1] = (*g_258[1][1]) * g_a61[jj_1] + (**g_454);
    }
  }
 (*g_217) = &g_3;
}

int main(void) {
  int i;
  int print_hash_value = 0;
  platform_main_begin();
  crc32_gentab();
 func_1();
  transparent_crc(g_3, "g_3", print_hash_value);
 transparent_crc(g_37, "g_37", print_hash_value);
 transparent_crc(g_168, "g_168", print_hash_value);
 transparent_crc(g_290, "g_290", print_hash_value);
  for (i = 0; i < 1; i++) {
    transparent_crc(g_a61[i], "g_a61[i]", print_hash_value);
 }
  for (i = 0; i < 1; i++) {
    transparent_crc(g_b61[i], "g_b61[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}

```

**file2.c**
```

#include "csmith.h"

static int g_a61[1];
static int64_t g_b61[1];

union U0 {
  signed f0 : 26;
  int64_t f1;
 int16_t f2;
};

static int32_t g_3 = 0x5C6F1BF5L;
static int32_t g_37 = 0x2CE6C1CCL;
static int32_t *g_121 = &g_37;
static int32_t g_168 = 0x896B5751L;
static int32_t **volatile g_217 = &g_121;
static const int32_t *g_258[2][2] = {{&g_168, &g_168}, {&g_168, &g_168}};
static int64_t g_290 = 1L;
static union U0 g_300 = {0x9E01EE1CL};
static union U0 *g_302[2][3][2] = {{{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}, {{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}};
static int64_t *g_455 = &g_290;
static int64_t *volatile *g_454 = &g_455;

static void func_1(void);

static void func_1(void) {
  int i, j, k;
 for (i = 0; i < 2; i++) {
    int ii_1;
    int jj_1;
    int ij_1;
    // fusion
    for (j = 0, ii_1 = 0, jj_1 = 0, ij_1 = 0; ij_1 <= 1; ij_1++) {
      if (ij_1 <= 1 && j < 1) {
        for (k = 0; k < 1; k++) {
          g_a61[ii_1] = (*g_302[1][0][0]).f0 * g_37 - (*g_302[1][2][1]).f0;
        }
        j++;
        ii_1++;
 }
      if (ij_1 <= 1 && jj_1 < 1) {
        g_b61[jj_1] = (*g_258[1][1]) * g_a61[jj_1] + (**g_454);
        jj_1++;
      }
 }
  }
  (*g_217) = &g_3;
}

int main(void) {
  int i;
 int print_hash_value = 0;
  platform_main_begin();
 crc32_gentab();
  func_1();
  transparent_crc(g_3, "g_3", print_hash_value);
  transparent_crc(g_37, "g_37", print_hash_value);
  transparent_crc(g_168, "g_168", print_hash_value);
  transparent_crc(g_290, "g_290", print_hash_value);
  for (i = 0; i < 1; i++) {
 transparent_crc(g_a61[i], "g_a61[i]", print_hash_value);
  }
  for (i = 0; i < 1; i++) {
    transparent_crc(g_b61[i], "g_b61[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