<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75606>75606</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected output results in fusion using -O1
</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 DC3F8ABB DC3F8ABB 40234D37 40234D37 40234D37 40234D37
file2.c DC3F8ABB 40234D37 40234D37 40234D37 40234D37 40234D37
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -O1), 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 int64_t g_a17[6];
static int64_t g_b17[6];
static int64_t g_a580[2];
static int64_t g_b580[2];
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_8[3] = {0x597A61EEL, 0x597A61EEL, 0x597A61EEL};
static int32_t g_10 = 1L;
static int32_t g_15[3] = {7L, 7L, 7L};
static int32_t g_17[3] = {0x556123D4L, 0x556123D4L, 0x556123D4L};
static int32_t *g_29 = (void *)0;
static volatile int32_t g_32[1][3] = {{0x4C46983CL, 0x4C46983CL, 0x4C46983CL}};
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile struct S0 g_64 = {0xC15C487EL, 0x8E1234CD2740D6A5LL, 0x8E70C497A14F8299LL};
static int16_t g_73 = 0L;
static int32_t g_101 = 1L;
static int32_t *volatile g_100 = &g_101;
static union U1 g_105 = {0xB5B7L};
static const volatile struct S0 g_116[1] = {{0xBFC011B9L, 18446744073709551615UL, 0x59B8980116228B08LL}};
static int32_t g_169[2][2][1] = {{{1L}, {0x0E6156E5L}}, {{1L}, {0x0E6156E5L}}};
static int64_t g_234 = 0x4AA72A53C6A8003FLL;
static union U1 g_272[1] = {{0xB220L}};
static union U1 g_299 = {0xE9D8L};
static volatile union U1 g_320 = {1L};
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static uint16_t g_352 = 5UL;
static const void func_1(void);
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t p_21);
static const void func_1(void) {
int i;
int ii_0;
// fusion
for (i = 0, ii_0 = 0; i < 3; i++, ii_0++) {
g_a17[ii_0] = g_64.f2 * g_10 - g_17[2];
}
int jj_0;
for (jj_0 = 0; jj_0 < 6; jj_0++) {
g_b17[jj_0] = g_8[2] * g_a17[jj_0] - g_320.f1;
}
for (g_10 = 0; (g_10 <= 1); g_10 += 1) {
for (g_15[2] = 1; (g_15[2] >= 0); g_15[2] -= 1) {
for (g_17[1] = 0; (g_17[1] <= 1); g_17[1] += 1) {
}
int16_t *l_404[2][2];
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
l_404[i][j] = &g_299.f0;
}
}
}
g_29 = func_18((safe_add_func_int8_t_s_s((safe_lshift_func_int32_t_s_s(((g_32[0][2] | ((((g_105.f0 = (((g_234 ^= g_350.f2) && g_352) ^ g_33[1][0][0])) & g_101), &g_73) != &g_73)) < 0x2DL), 26)), g_10)), &g_29, g_15[2]);
}
g_29 = func_18((g_272[0].f0 = g_350.f0), &g_29, g_2[1]);
}
static int32_t *func_18(const int16_t p_19, int32_t **p_20, 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_a580[ii_12] = g_17[2] * g_272[0].f2 + g_116[0].f2;
}
int jj_12;
for (jj_12 = 0; jj_12 < 2; jj_12++) {
g_b580[jj_12] = g_33[1][0][0] * g_a580[jj_12] + g_169[0][1][0];
}
(*g_100) = ((p_21 <= (g_299.f1 = (safe_lshift_func_uint16_t_u_u((!(safe_lshift_func_int8_t_s_s((((g_234 &= (-1L)), g_234) || g_350.f1), g_32[0][1]))), g_15[1])))) >= 0xA0B92A34L);
return (*p_20);
}
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);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_8[i], "g_8[i]", print_hash_value);
}
transparent_crc(g_10, "g_10", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_15[i], "g_15[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_17[i], "g_17[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
for (j = 0; j < 3; j++) {
transparent_crc(g_32[i][j], "g_32[i][j]", 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_73, "g_73", print_hash_value);
transparent_crc(g_101, "g_101", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_116[i].f0, "g_116[i].f0", print_hash_value);
transparent_crc(g_116[i].f1, "g_116[i].f1", print_hash_value);
transparent_crc(g_116[i].f2, "g_116[i].f2", print_hash_value);
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_169[i][j][k], "g_169[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_234, "g_234", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_272[i].f0, "g_272[i].f0", 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);
transparent_crc(g_352, "g_352", print_hash_value);
for (i = 0; i < 6; i++) {
transparent_crc(g_a17[i], "g_a17[i]", print_hash_value);
}
for (i = 0; i < 6; i++) {
transparent_crc(g_b17[i], "g_b17[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_a580[i], "g_a580[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_b580[i], "g_b580[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int64_t g_a17[6];
static int64_t g_b17[6];
static int64_t g_a580[2];
static int64_t g_b580[2];
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_8[3] = {0x597A61EEL, 0x597A61EEL, 0x597A61EEL};
static int32_t g_10 = 1L;
static int32_t g_15[3] = {7L, 7L, 7L};
static int32_t g_17[3] = {0x556123D4L, 0x556123D4L, 0x556123D4L};
static int32_t *g_29 = (void *)0;
static volatile int32_t g_32[1][3] = {{0x4C46983CL, 0x4C46983CL, 0x4C46983CL}};
static int32_t g_33[2][3][1] = {{{(-7L)}, {(-7L)}, {(-7L)}}, {{(-7L)}, {(-7L)}, {(-7L)}}};
static volatile struct S0 g_64 = {0xC15C487EL, 0x8E1234CD2740D6A5LL, 0x8E70C497A14F8299LL};
static int16_t g_73 = 0L;
static int32_t g_101 = 1L;
static int32_t *volatile g_100 = &g_101;
static union U1 g_105 = {0xB5B7L};
static const volatile struct S0 g_116[1] = {{0xBFC011B9L, 18446744073709551615UL, 0x59B8980116228B08LL}};
static int32_t g_169[2][2][1] = {{{1L}, {0x0E6156E5L}}, {{1L}, {0x0E6156E5L}}};
static int64_t g_234 = 0x4AA72A53C6A8003FLL;
static union U1 g_272[1] = {{0xB220L}};
static union U1 g_299 = {0xE9D8L};
static volatile union U1 g_320 = {1L};
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static uint16_t g_352 = 5UL;
static const void func_1(void);
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t p_21);
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_a17[ii_0] = g_64.f2 * g_10 - g_17[2];
i++;
ii_0++;
}
if (ij_0 <= 6 && jj_0 < 6) {
g_b17[jj_0] = g_8[2] * g_a17[jj_0] - g_320.f1;
jj_0++;
}
}
for (g_10 = 0; (g_10 <= 1); g_10 += 1) {
for (g_15[2] = 1; (g_15[2] >= 0); g_15[2] -= 1) {
for (g_17[1] = 0; (g_17[1] <= 1); g_17[1] += 1) {
}
int16_t *l_404[2][2];
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
l_404[i][j] = &g_299.f0;
}
}
}
g_29 = func_18((safe_add_func_int8_t_s_s((safe_lshift_func_int32_t_s_s(((g_32[0][2] | ((((g_105.f0 = (((g_234 ^= g_350.f2) && g_352) ^ g_33[1][0][0])) & g_101), &g_73) != &g_73)) < 0x2DL), 26)), g_10)), &g_29, g_15[2]);
}
g_29 = func_18((g_272[0].f0 = g_350.f0), &g_29, g_2[1]);
}
static int32_t *func_18(const int16_t p_19, int32_t **p_20, 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 <= 2; ij_12++) {
if (ij_12 <= 1 && (p_21 == 25)) {
g_a580[ii_12] = g_17[2] * g_272[0].f2 + g_116[0].f2;
p_21 = safe_add_func_int64_t_s_s(p_21, 4);
ii_12++;
}
if (ij_12 <= 2 && jj_12 < 2) {
g_b580[jj_12] = g_33[1][0][0] * g_a580[jj_12] + g_169[0][1][0];
jj_12++;
}
}
(*g_100) = ((p_21 <= (g_299.f1 = (safe_lshift_func_uint16_t_u_u((!(safe_lshift_func_int8_t_s_s((((g_234 &= (-1L)), g_234) || g_350.f1), g_32[0][1]))), g_15[1])))) >= 0xA0B92A34L);
return (*p_20);
}
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);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_8[i], "g_8[i]", print_hash_value);
}
transparent_crc(g_10, "g_10", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_15[i], "g_15[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_17[i], "g_17[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
for (j = 0; j < 3; j++) {
transparent_crc(g_32[i][j], "g_32[i][j]", 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_73, "g_73", print_hash_value);
transparent_crc(g_101, "g_101", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_116[i].f0, "g_116[i].f0", print_hash_value);
transparent_crc(g_116[i].f1, "g_116[i].f1", print_hash_value);
transparent_crc(g_116[i].f2, "g_116[i].f2", print_hash_value);
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 1; k++) {
transparent_crc(g_169[i][j][k], "g_169[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_234, "g_234", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_272[i].f0, "g_272[i].f0", 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);
transparent_crc(g_352, "g_352", print_hash_value);
for (i = 0; i < 6; i++) {
transparent_crc(g_a17[i], "g_a17[i]", print_hash_value);
}
for (i = 0; i < 6; i++) {
transparent_crc(g_b17[i], "g_b17[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_a580[i], "g_a580[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_b580[i], "g_b580[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/eJzsXFtvq7ry_zT0xUpkj7k-9CFX7SV1a_2lvdczIsQktATy59J2nU9_ZGODIZCkXV37nCMRVS0ej8c_j8czYzJqUBTxIWXs0bCWhrV-CKrymOWPmyR7Y-ns-fntYZftfz5usxyVR4aiLEmytzg9oPItQyGK4oQVBqzQN3RmeZTlJ7YXjOz_q_g1SFhaojIP0oJ3BWWcpSiLUJJlZxTl2QkZsDBgwaWQeVg3UJlpZFDkOfqG8iDlwgsmZhdzo5wVZxaW8StLfqKq4ND2cRSxnE-dncv4FP-rnjhhrywpUJyGSbXnfLXg2XdcP_BlKBK5JMEliV6SiktSFBSlWsPfXDXvQViirCrPVcnhV0lZGODGczZH4ZGFL0V1Qq9BUnHNeijIm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