<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75604>75604</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected output results in fusion using -Os
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</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 8426F 85545B29 85545B29 85545B29 7FD9E5FE 85545B29
file2.c 8426F 85545B29 85545B29 85545B29 85545B29 85545B29
```
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_a120[2];
static int64_t g_b120[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 int32_t g_17[3] = {0x556123D4L, 0x556123D4L, 0x556123D4L};
static int32_t *g_29 = (void *)0;
static union U1 g_105 = {0xB5B7L};
static union U1 g_272[1] = {{0xB220L}};
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static uint16_t g_352 = 5UL;
static struct S0 g_388 = {0UL, 0xB2916F400852E206LL, 0L};
static const void func_1(void);
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t **p_23);
static const void func_1(void) {
int i, j;
int ii_3;
// fusion
for (i = 0, ii_3 = 0; i < 2; i++, ii_3++) {
for (j = 0; j < 1; j++) {
g_a120[ii_3] = g_17[0] * g_352 - g_272[0].f1;
}
}
int jj_3;
for (jj_3 = 0; jj_3 < 2; jj_3++) {
g_b120[jj_3] = g_105.f1 * g_a120[jj_3] - g_388.f2;
}
for (g_17[1] = 0; (g_17[1] <= 1); g_17[1] += 1) {
}
g_29 = func_18((g_272[0].f0 = g_350.f0), &g_29, &g_29);
}
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t **p_23) {
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 < 3; i++) {
transparent_crc(g_17[i], "g_17[i]", 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_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);
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 < 2; i++) {
transparent_crc(g_a120[i], "g_a120[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_b120[i], "g_b120[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int32_t g_a120[2];
static int64_t g_b120[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 int32_t g_17[3] = {0x556123D4L, 0x556123D4L, 0x556123D4L};
static int32_t *g_29 = (void *)0;
static union U1 g_105 = {0xB5B7L};
static union U1 g_272[1] = {{0xB220L}};
static struct S0 g_350 = {2UL, 18446744073709551615UL, 0x484C2F172B251D2FLL};
static uint16_t g_352 = 5UL;
static struct S0 g_388 = {0UL, 0xB2916F400852E206LL, 0L};
static const void func_1(void);
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t **p_23);
static const void func_1(void) {
int i, j;
int ii_3;
int jj_3;
int ij_3;
// fusion
for (i = 0, ii_3 = 0, jj_3 = 0, ij_3 = 0; ij_3 <= 2; ij_3++) {
if (ij_3 <= 2 && i < 2) {
for (j = 0; j < 1; j++) {
g_a120[ii_3] = g_17[0] * g_352 - g_272[0].f1;
}
i++;
ii_3++;
}
if (ij_3 <= 2 && jj_3 < 2) {
g_b120[jj_3] = g_105.f1 * g_a120[jj_3] - g_388.f2;
jj_3++;
}
}
for (g_17[1] = 0; (g_17[1] <= 1); g_17[1] += 1) {
}
g_29 = func_18((g_272[0].f0 = g_350.f0), &g_29, &g_29);
}
static int32_t *func_18(const int16_t p_19, int32_t **p_20, int32_t **p_23) {
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 < 3; i++) {
transparent_crc(g_17[i], "g_17[i]", 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_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);
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 < 2; i++) {
transparent_crc(g_a120[i], "g_a120[i]", print_hash_value);
}
for (i = 0; i < 2; i++) {
transparent_crc(g_b120[i], "g_b120[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/eJzsWU9vq7oS_zTOxgqyBwiwyCJpEt1KveqT7jlr5IBJ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