Issue 75595
Summary unexpected output results in fusion using -Os
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        C20624F         1411B9B7        C20624F         C20624F C20624F         C20624F      
file2.c        C20624F         1411B9B7 C20624F         C20624F         1411B9B7        C20624F 
```
 
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -Os), 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_a0[2];
static uint64_t g_b0[2];

static uint64_t g_9 = 1UL;
static int32_t g_11 = 0x6B471DFDL;
static int8_t g_19 = 0x49L;

static void func_1(void);

static void func_1(void) {
  int32_t l_14 = 0x0E864896L;
  int i;
  int ii_0;
  // fusion
  for (i = 0, ii_0 = 0; i < 1; i++, ii_0++) {
    g_a0[ii_0] = g_19 * l_14 + g_11;
  }
 int jj_0;
  for (jj_0 = 0; jj_0 < 2; jj_0++) {
    g_b0[jj_0] = g_19 * g_a0[jj_0] + g_9;
  }
}

int main(void) {
  int i;
  int print_hash_value = 0;
  platform_main_begin();
  crc32_gentab();
 func_1();
  transparent_crc(g_9, "g_9", print_hash_value);
 transparent_crc(g_11, "g_11", print_hash_value);
  transparent_crc(g_19, "g_19", print_hash_value);
  for (i = 0; i < 2; i++) {
 transparent_crc(g_a0[i], "g_a0[i]", print_hash_value);
  }
  for (i = 0; i < 2; i++) {
    transparent_crc(g_b0[i], "g_b0[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}
```

**file2.c**
```

#include "csmith.h"

static int32_t g_a0[2];
static uint64_t g_b0[2];

static uint64_t g_9 = 1UL;
static int32_t g_11 = 0x6B471DFDL;
static int8_t g_19 = 0x49L;

static void func_1(void);

static void func_1(void) {
  int32_t l_14 = 0x0E864896L;
  int i;
  int ii_0;
  int jj_0;
  int ij_0;
  // fusion
  for (i = 0, ii_0 = 0, jj_0 = 0, ij_0 = 0; ij_0 <= 2; ij_0++) {
    if (ij_0 <= 1 && i < 1) {
      g_a0[ii_0] = g_19 * l_14 + g_11;
      i++;
      ii_0++;
    }
    if (ij_0 <= 2 && jj_0 < 2) {
      g_b0[jj_0] = g_19 * g_a0[jj_0] + g_9;
      jj_0++;
 }
  }
}

int i;
int main(void) {
  int print_hash_value = 0;
  platform_main_begin();
  crc32_gentab();
  func_1();
 transparent_crc(g_9, "g_9", print_hash_value);
  transparent_crc(g_11, "g_11", print_hash_value);
  transparent_crc(g_19, "g_19", print_hash_value);
  for (i = 0; i < 2; i++) {
 transparent_crc(g_a0[i], "g_a0[i]", print_hash_value);
  }
  for (i = 0; i < 2; i++) {
    transparent_crc(g_b0[i], "g_b0[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