| Issue |
75607
|
| 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 6F9F6359 77D95726 77D95726 77D95726 6F9F6359 77D95726
file2.c 6F9F6359 77D95726 77D95726 77D95726 77D95726 77D95726
```
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_a30[6];
static int64_t g_b30[6];
struct S0 {
const volatile uint32_t f0;
uint64_t f1;
int64_t f2;
};
union U1 {
int16_t f0;
uint16_t f1;
uint16_t f2;
const struct S0 f3;
};
static volatile int32_t g_7 = 0x6B471DFDL;
static int32_t g_10 = 1L;
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile union U1 g_320 = {1L};
static volatile union U1 *g_319 = &g_320;
static volatile union U1 *volatile *const g_318 = &g_319;
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static const void func_1(void);
static const void func_1(void) {
int i;
int ii_0;
// fusion
for (i = 0, ii_0 = 0; i < 3; i++, ii_0++) {
g_a30[ii_0] = g_7 * g_10 + (**g_318).f1;
}
int jj_0;
for (jj_0 = 0; jj_0 < 6; jj_0++) {
g_b30[jj_0] = g_33[1][1][0] * g_a30[jj_0] + g_350.f2;
}
}
int main(void) {
int i, j, k;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_7, "g_7", print_hash_value);
transparent_crc(g_10, "g_10", print_hash_value);
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_33[i][j][k], "g_33[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_320.f0, "g_320.f0", print_hash_value);
transparent_crc(g_350.f0, "g_350.f0", print_hash_value);
transparent_crc(g_350.f1, "g_350.f1", print_hash_value);
transparent_crc(g_350.f2, "g_350.f2", print_hash_value);
for (i = 0; i < 6; i++) {
transparent_crc(g_a30[i], "g_a30[i]", print_hash_value);
}
for (i = 0; i < 6; i++) {
transparent_crc(g_b30[i], "g_b30[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int32_t g_a30[6];
static int64_t g_b30[6];
struct S0 {
const volatile uint32_t f0;
uint64_t f1;
int64_t f2;
};
union U1 {
int16_t f0;
uint16_t f1;
uint16_t f2;
const struct S0 f3;
};
static volatile int32_t g_7 = 0x6B471DFDL;
static int32_t g_10 = 1L;
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile union U1 g_320 = {1L};
static volatile union U1 *g_319 = &g_320;
static volatile union U1 *volatile *const g_318 = &g_319;
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static const void func_1(void);
static const void func_1(void) {
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 <= 6; ij_0++) {
if (ij_0 <= 3 && i < 3) {
g_a30[ii_0] = g_7 * g_10 + (**g_318).f1;
i++;
ii_0++;
}
if (ij_0 <= 6 && jj_0 < 6) {
g_b30[jj_0] = g_33[1][1][0] * g_a30[jj_0] + g_350.f2;
jj_0++;
}
}
}
int main(void) {
int i, j, k;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_7, "g_7", print_hash_value);
transparent_crc(g_10, "g_10", print_hash_value);
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_33[i][j][k], "g_33[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_320.f0, "g_320.f0", print_hash_value);
transparent_crc(g_350.f0, "g_350.f0", print_hash_value);
transparent_crc(g_350.f1, "g_350.f1", print_hash_value);
transparent_crc(g_350.f2, "g_350.f2", print_hash_value);
for (i = 0; i < 6; i++) {
transparent_crc(g_a30[i], "g_a30[i]", print_hash_value);
}
for (i = 0; i < 6; i++) {
transparent_crc(g_b30[i], "g_b30[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