<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75605>75605</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected output results in fusion using -O1 and -Os
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Elowen-jjw
</td>
</tr>
</table>
<pre>
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;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltvqzoW_jXOixXkC9eHPCQQdLbUo450zn5GBEzilkAGTNs9v35kczMJabvTrZmtmURVg5fX5VsXX1hKXNd8XzC2AtYGWMEibsShrFbbvHxlxfLp6XWxK9Mfq7CsoDgwmJV5Xr7yYg_FawkTmPGc1YD48Bs8sSorqyNLFSP7Z8Nf4pwVAooqLmo5FQteFrDMYF6WJ5hV5RECsgZkLbVgI2kHUJQamfRkA36DVVxI5TVT1pVtWLH6xBLBX1j-Aza1hJbyLGOVNF2eBD_yf7WGc_bC8hryIsmbVPK1ipePqH2QbvQkfEkilyR6SaovSVlci96Hv2Vo3uJEwLIRp0ZI-E0uakBcbjADJgeWPNfNEb7EeSMj68G4YoCuAQoAWgMbdX9qCLXP8hHB6RjD5SM5o9GzcX02llhhq7xLiprY2t7GC0fhdUDRdk2tD8fvMo52yBU7_fgje-_imw9d-_WPnMU1gweWn-CRydJjb6c85gV8Pfy4qLVTVaZNwlK9wiZphK8HVnRVKFdBHR_ZTBH22ZY5iosUyqrxZMmIQ1w8wx9lY3Sg1f-kPB4lW86Lq6WQ5LGsaOpLpEV8ZEYC6FYSZszTLVzmR7j8BgEx_b_-_Pb3H9Efj39uAQnb1cEgIDYgNjQACWOjbMSs0RdW1bwsAF1DZR-QTZ6_HCE2DWR0PGUtp5tdU4gGEmIgU3dtZv3PWuq56YiPJPWRi4NxAIToTLWIBU8gLwQlkYD7KLY8BKwNBlYA6GbC1PBC2Kbi2s1w9bxVkwj4F4LA2fQLLymLWsCXMo8Fz5lSpMxlaJCGo_oMa9SBSEZDzrnRppDp-o51m7wQ2J6z0VLxLJVo1Bb06E9G30EwxtFVASLA2hBgBRDQQKJCb677IIu2fXAugjsEZ0wFVcLozXQd5G5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