<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75597>75597</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected output results in fusion using -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 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;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl-TqjoS_zTxpUsqdEDhwQfRse6pmluzVffusxUhaBz-uBCcmf30WwkwoqDjnHt29-FKTQnd6aR_nf4lpHV4WcptJsSMuAFxlyNeqV1ezJ6S_E1k4_3-bbTJo4_ZKi9A7QTEeZLkbzLbgnrLIYRYJqIkuIAfcBBFnBepiIyh-FcljzwRmQJV8KzUTVzJPIM8hiTPDxAXeQoE5wTnehTbCmsBVN5RY6u24AcUPNODl8J4N76hEOVBhEoeRfIBVamhRTKORaFd5wclU_nv2nEijiIpQWZhUkXarh54_ELrBx1Gq7L7KuyrWF9V9lUxL1Ubw596at55qCCv1KFSGn6VqJKgJy1hQbgT4WtZpXDkSaVn1gdeCMLmhC4JnZMJbf6MCOfX-IXC-MW-0OGFzC7k8kLWcKEev8lL0-T584W78j9NAzfwvOV80srLp6nnBwvak6826OvkCb_2dHOkryANT2F9-0cieClgJ5IDpEJTULwfEi4zeNt99Dh3KPKoCkXUZdpZOuFtJ7KGjXo1lDwVA2Rss25o42vOqB3PXuEjr6wGrfkM8zTlWQSJzK5yIUy4pjRbaIgZT4UVEvakFQN-2ROMkxTGP4Cgs_jj9x9__rb-7eX3J4KrenkIIDghOAGL4IpbeaUGnR5FUco8I2wOxj_BIEmOKdiORa3GJi91c7WpMlUBokWdbmgDG8Cgp9aanfBhWKZS7awdQewalYorGYLMFGzXfOIQN2DEXRIWXLZPnLW22fRtWsuiChX8QYFMg3bJyUx5awUx_TQGMHtoBLENOlb0O01hnpUKqqw1wWsmxzzhSiaiY8uMrW2fYE37ENtgGJpgPJ-4AepY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