| Issue |
75597
|
| 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 89AC5F9 B5B88DA6 DE789BC0 DE789BC0 DE789BC0 DE789BC0
file2.c 89AC5F9 B5B88DA6 DE789BC0 DE789BC0 B5B88DA6 DE789BC0
```
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 int g_a64[3];
static int64_t g_b64[3];
struct S0 {
int8_t f0;
signed f1 : 29;
const unsigned f2 : 29;
const volatile unsigned f3 : 11;
};
static int32_t g_89[2][3] = {{0x7B1C4CF8L, 0x7B1C4CF8L, 0x7B1C4CF8L}, {(-1L), (-1L), (-1L)}};
static struct S0 g_108[2][1] = {{{0x8AL, 22142, 16805, 22}}, {{0x8AL, 22142, 16805, 22}}};
static struct S0 g_206[3][2][1] = {{{{0x75L, -11328, 1154, 10}}, {{0xF6L, 10438, 22888, 10}}}, {{{0x75L, -11328, 1154, 10}}, {{0x75L, -11328, 1154, 10}}}, {{{0xF6L, 10438, 22888, 10}}, {{0x75L, -11328, 1154, 10}}}};
static const volatile int64_t g_220 = 0xB27021F96459FD89LL;
static void func_1(void);
static void func_1() {
int i;
int ii_1;
// fusion
for (i = 0, ii_1 = 0; i < 2; i++, ii_1++) {
g_a64[ii_1] = g_206[2][1][0].f0 * g_89[0][1] - g_206[2][1][0].f1;
}
int jj_1;
for (jj_1 = 0; jj_1 < 3; jj_1++) {
g_b64[jj_1] = g_108[1][0].f3 * g_a64[jj_1] - g_220;
}
}
int main(void) {
int i, j, k;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
transparent_crc(g_89[i][j], "g_89[i][j]", print_hash_value);
}
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 1; j++) {
transparent_crc(g_108[i][j].f0, "g_108[i][j].f0", print_hash_value);
transparent_crc(g_108[i][j].f1, "g_108[i][j].f1", print_hash_value);
transparent_crc(g_108[i][j].f2, "g_108[i][j].f2", print_hash_value);
transparent_crc(g_108[i][j].f3, "g_108[i][j].f3", print_hash_value);
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_206[i][j][k].f0, "g_206[i][j][k].f0", print_hash_value);
transparent_crc(g_206[i][j][k].f1, "g_206[i][j][k].f1", print_hash_value);
transparent_crc(g_206[i][j][k].f2, "g_206[i][j][k].f2", print_hash_value);
transparent_crc(g_206[i][j][k].f3, "g_206[i][j][k].f3", print_hash_value);
}
}
}
transparent_crc(g_220, "g_220", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_a64[i], "g_a64[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_b64[i], "g_b64[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int g_a64[3];
static int64_t g_b64[3];
struct S0 {
int8_t f0;
signed f1 : 29;
const unsigned f2 : 29;
const volatile unsigned f3 : 11;
};
static int32_t g_89[2][3] = {{0x7B1C4CF8L, 0x7B1C4CF8L, 0x7B1C4CF8L}, {(-1L), (-1L), (-1L)}};
static struct S0 g_108[2][1] = {{{0x8AL, 22142, 16805, 22}}, {{0x8AL, 22142, 16805, 22}}};
static struct S0 g_206[3][2][1] = {{{{0x75L, -11328, 1154, 10}}, {{0xF6L, 10438, 22888, 10}}}, {{{0x75L, -11328, 1154, 10}}, {{0x75L, -11328, 1154, 10}}}, {{{0xF6L, 10438, 22888, 10}}, {{0x75L, -11328, 1154, 10}}}};
static const volatile int64_t g_220 = 0xB27021F96459FD89LL;
static void func_1(void);
static void func_1() {
int i;
int ii_1;
int jj_1;
int ij_1;
// fusion
for (i = 0, ii_1 = 0, jj_1 = 0, ij_1 = 0; ij_1 <= 3; ij_1++) {
if (ij_1 <= 2 && i < 2) {
g_a64[ii_1] = g_206[2][1][0].f0 * g_89[0][1] - g_206[2][1][0].f1;
i++;
ii_1++;
}
if (ij_1 <= 3 && jj_1 < 3) {
g_b64[jj_1] = g_108[1][0].f3 * g_a64[jj_1] - g_220;
jj_1++;
}
}
}
int main(void) {
int i, j, k;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
transparent_crc(g_89[i][j], "g_89[i][j]", print_hash_value);
}
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 1; j++) {
transparent_crc(g_108[i][j].f0, "g_108[i][j].f0", print_hash_value);
transparent_crc(g_108[i][j].f1, "g_108[i][j].f1", print_hash_value);
transparent_crc(g_108[i][j].f2, "g_108[i][j].f2", print_hash_value);
transparent_crc(g_108[i][j].f3, "g_108[i][j].f3", print_hash_value);
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_206[i][j][k].f0, "g_206[i][j][k].f0", print_hash_value);
transparent_crc(g_206[i][j][k].f1, "g_206[i][j][k].f1", print_hash_value);
transparent_crc(g_206[i][j][k].f2, "g_206[i][j][k].f2", print_hash_value);
transparent_crc(g_206[i][j][k].f3, "g_206[i][j][k].f3", print_hash_value);
}
}
}
transparent_crc(g_220, "g_220", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_a64[i], "g_a64[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_b64[i], "g_b64[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