| Issue |
75605
|
| Summary |
unexpected output results in fusion using -O1 and -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 E69B9F3 AD30EA35 AD30EA35 AD30EA35 AD30EA35 AD30EA35
file2.c E69B9F3 E69B9F3 AD30EA35 AD30EA35 E69B9F3 AD30EA35
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -O1 and 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_a590[1];
static uint64_t g_b590[1];
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 int8_t g_2[2] = {0x88L, 0x88L};
static volatile int32_t g_3 = 0x48708EF6L;
static volatile int32_t g_7 = 0x6B471DFDL;
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile struct S0 g_64 = {0xC15C487EL, 0x8E1234CD2740D6A5LL, 0x8E70C497A14F8299LL};
static const volatile struct S0 g_84 = {0x1624B3AEL, 0x4CD7CE17D650891FLL, 0x5DEE7F6E9516CEA6LL};
static int32_t g_99 = 0x44D61F69L;
static uint16_t g_215 = 0UL;
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static struct S0 g_388 = {0UL, 0xB2916F400852E206LL, 0L};
static const void func_1(void);
static void func_18(int32_t p_21);
static const void func_1(void) {
int32_t l_385 = 0x5A33D8C8L;
int32_t l_398 = 0L;
int32_t l_397 = 0x4CCD9B15L;
if ((safe_mul_func_uint64_t_u_u((l_385 ^ (safe_lshift_func_uint16_t_u_u((g_215 |= ((safe_div_func_uint32_t_u_u(((safe_mul_func_uint64_t_u_u(g_33[0][1][0], l_397)) && l_398), l_385)) != g_84.f2)), g_350.f2))), 0x40A8940BA3C26A6CLL))) {
} else {
return;
}
func_18(g_2[1]);
}
static void func_18(int32_t p_21) {
int ii_12;
// fusion
for (p_21 = 25, ii_12 = 0; (p_21 == 25); p_21 = safe_add_func_int64_t_s_s(p_21, 4), ii_12++) {
g_a590[ii_12] = g_7 * g_99 - g_3;
}
int jj_12;
for (jj_12 = 0; jj_12 < 1; jj_12++) {
g_b590[jj_12] = g_64.f1 * g_a590[jj_12] + g_388.f2;
}
}
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++) {
transparent_crc(g_2[i], "g_2[i]", print_hash_value);
}
transparent_crc(g_3, "g_3", print_hash_value);
transparent_crc(g_7, "g_7", 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_64.f0, "g_64.f0", print_hash_value);
transparent_crc(g_64.f1, "g_64.f1", print_hash_value);
transparent_crc(g_64.f2, "g_64.f2", print_hash_value);
transparent_crc(g_84.f0, "g_84.f0", print_hash_value);
transparent_crc(g_84.f1, "g_84.f1", print_hash_value);
transparent_crc(g_84.f2, "g_84.f2", print_hash_value);
transparent_crc(g_99, "g_99", print_hash_value);
transparent_crc(g_215, "g_215", 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);
transparent_crc(g_388.f0, "g_388.f0", print_hash_value);
transparent_crc(g_388.f1, "g_388.f1", print_hash_value);
transparent_crc(g_388.f2, "g_388.f2", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_a590[i], "g_a590[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b590[i], "g_b590[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int32_t g_a590[1];
static uint64_t g_b590[1];
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 int8_t g_2[2] = {0x88L, 0x88L};
static volatile int32_t g_3 = 0x48708EF6L;
static volatile int32_t g_7 = 0x6B471DFDL;
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile struct S0 g_64 = {0xC15C487EL, 0x8E1234CD2740D6A5LL, 0x8E70C497A14F8299LL};
static const volatile struct S0 g_84 = {0x1624B3AEL, 0x4CD7CE17D650891FLL, 0x5DEE7F6E9516CEA6LL};
static int32_t g_99 = 0x44D61F69L;
static uint16_t g_215 = 0UL;
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static struct S0 g_388 = {0UL, 0xB2916F400852E206LL, 0L};
static const void func_1(void);
static void func_18(int32_t p_21);
static const void func_1(void) {
int32_t l_385 = 0x5A33D8C8L;
int32_t l_398 = 0L;
int32_t l_397 = 0x4CCD9B15L;
if ((safe_mul_func_uint64_t_u_u((l_385 ^ (safe_lshift_func_uint16_t_u_u((g_215 |= ((safe_div_func_uint32_t_u_u(((safe_mul_func_uint64_t_u_u(g_33[0][1][0], l_397)) && l_398), l_385)) != g_84.f2)), g_350.f2))), 0x40A8940BA3C26A6CLL))) {
} else {
return;
}
func_18(g_2[1]);
}
static void func_18(int32_t p_21) {
int ii_12;
int jj_12;
int ij_12;
// fusion
for (p_21 = 25, ii_12 = 0, jj_12 = 0, ij_12 = 0; ij_12 <= 1; ij_12++) {
if (ij_12 <= 1 && (p_21 == 25)) {
g_a590[ii_12] = g_7 * g_99 - g_3;
p_21 = safe_add_func_int64_t_s_s(p_21, 4);
ii_12++;
}
if (ij_12 <= 1 && jj_12 < 1) {
g_b590[jj_12] = g_64.f1 * g_a590[jj_12] + g_388.f2;
jj_12++;
}
}
}
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++) {
transparent_crc(g_2[i], "g_2[i]", print_hash_value);
}
transparent_crc(g_3, "g_3", print_hash_value);
transparent_crc(g_7, "g_7", 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_64.f0, "g_64.f0", print_hash_value);
transparent_crc(g_64.f1, "g_64.f1", print_hash_value);
transparent_crc(g_64.f2, "g_64.f2", print_hash_value);
transparent_crc(g_84.f0, "g_84.f0", print_hash_value);
transparent_crc(g_84.f1, "g_84.f1", print_hash_value);
transparent_crc(g_84.f2, "g_84.f2", print_hash_value);
transparent_crc(g_99, "g_99", print_hash_value);
transparent_crc(g_215, "g_215", 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);
transparent_crc(g_388.f0, "g_388.f0", print_hash_value);
transparent_crc(g_388.f1, "g_388.f1", print_hash_value);
transparent_crc(g_388.f2, "g_388.f2", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_a590[i], "g_a590[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b590[i], "g_b590[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