<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75608>75608</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected output results in fusion using -O2
</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 ECAC2C0 ECAC2C0 97F01309 97F01309 ECAC2C0 97F01309
file2.c ECAC2C0 ECAC2C0 ECAC2C0 97F01309 ECAC2C0 97F01309
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -O2), 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_a138[3];
static uint64_t g_b138[3];
struct S0 {
const volatile uint8_t f0;
uint32_t f1;
volatile int64_t f2;
unsigned f3 : 23;
int32_t f4;
};
union U1 {
const int16_t f0;
const int32_t f1;
int16_t f2;
const volatile unsigned f3 : 22;
int32_t f4;
};
static volatile uint64_t g_2[3][2][3] = {{{0xB6B0E1B1B552BF33LL, 0x82A10AA43B2B74C3LL, 0x82A10AA43B2B74C3LL}, {1UL, 0x82A10AA43B2B74C3LL, 0x1BAB5934215E1ABELL}}, {{0xF21009D434678DC2LL, 0xB6B0E1B1B552BF33LL, 18446744073709551615UL}, {1UL, 1UL, 18446744073709551615UL}}, {{0xB6B0E1B1B552BF33LL, 0xF21009D434678DC2LL, 0x1BAB5934215E1ABELL}, {0x82A10AA43B2B74C3LL, 1UL, 0x82A10AA43B2B74C3LL}}};
static int32_t g_23 = 0x2452A2C7L;
static int32_t *g_22 = &g_23;
static union U1 g_30 = {-4L};
static int32_t **volatile g_100 = &g_22;
static struct S0 g_197 = {0xEFL, 4294967289UL, -1L, 1786, 1L};
static void func_1(void);
static void func_1(void) {
int32_t l_84 = 0x99A90AD7L;
int32_t l_165 = 0x6A74C124L;
int32_t l_168 = 0x782E0D5DL;
uint8_t l_172 = 1UL;
int ii_3;
// fusion
for (g_30.f4 = 0, ii_3 = 0; (g_30.f4 <= 1); g_30.f4 += 1, ii_3++) {
for (l_165 = 0; (l_165 <= 1); l_165 += 1) {
for (l_172 = 0; (l_172 <= 1); l_172 += 1) {
for (l_168 = 0; (l_168 <= 2); l_168 += 1) {
g_a138[ii_3] = (**g_100) * l_84 - g_197.f0;
}
}
}
}
int jj_3;
for (jj_3 = 0; jj_3 < 3; jj_3++) {
g_b138[jj_3] = g_2[1][0][0] * g_a138[jj_3] + g_2[0][1][2];
}
}
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++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 3; k++) {
transparent_crc(g_2[i][j][k], "g_2[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_23, "g_23", print_hash_value);
transparent_crc(g_197.f0, "g_197.f0", print_hash_value);
transparent_crc(g_197.f1, "g_197.f1", print_hash_value);
transparent_crc(g_197.f2, "g_197.f2", print_hash_value);
transparent_crc(g_197.f3, "g_197.f3", print_hash_value);
transparent_crc(g_197.f4, "g_197.f4", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_a138[i], "g_a138[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_b138[i], "g_b138[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int32_t g_a138[3];
static uint64_t g_b138[3];
struct S0 {
const volatile uint8_t f0;
uint32_t f1;
volatile int64_t f2;
unsigned f3 : 23;
int32_t f4;
};
union U1 {
const int16_t f0;
const int32_t f1;
int16_t f2;
const volatile unsigned f3 : 22;
int32_t f4;
};
static volatile uint64_t g_2[3][2][3] = {{{0xB6B0E1B1B552BF33LL, 0x82A10AA43B2B74C3LL, 0x82A10AA43B2B74C3LL}, {1UL, 0x82A10AA43B2B74C3LL, 0x1BAB5934215E1ABELL}}, {{0xF21009D434678DC2LL, 0xB6B0E1B1B552BF33LL, 18446744073709551615UL}, {1UL, 1UL, 18446744073709551615UL}}, {{0xB6B0E1B1B552BF33LL, 0xF21009D434678DC2LL, 0x1BAB5934215E1ABELL}, {0x82A10AA43B2B74C3LL, 1UL, 0x82A10AA43B2B74C3LL}}};
static int32_t g_23 = 0x2452A2C7L;
static int32_t *g_22 = &g_23;
static union U1 g_30 = {-4L};
static int32_t **volatile g_100 = &g_22;
static struct S0 g_197 = {0xEFL, 4294967289UL, -1L, 1786, 1L};
static void func_1(void);
static void func_1(void) {
int32_t l_84 = 0x99A90AD7L;
int32_t l_165 = 0x6A74C124L;
int32_t l_168 = 0x782E0D5DL;
uint8_t l_172 = 1UL;
int ii_3;
int jj_3;
int ij_3;
// fusion
for (g_30.f4 = 0, ii_3 = 0, jj_3 = 0, ij_3 = 0; ij_3 <= 3; ij_3++) {
if (ij_3 <= 2 && (g_30.f4 <= 1)) {
for (l_165 = 0; (l_165 <= 1); l_165 += 1) {
for (l_172 = 0; (l_172 <= 1); l_172 += 1) {
for (l_168 = 0; (l_168 <= 2); l_168 += 1) {
g_a138[ii_3] = (**g_100) * l_84 - g_197.f0;
}
}
}
g_30.f4 += 1;
ii_3++;
}
if (ij_3 <= 3 && jj_3 < 3) {
g_b138[jj_3] = g_2[1][0][0] * g_a138[jj_3] + g_2[0][1][2];
jj_3++;
}
}
}
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++) {
for (j = 0; j < 2; j++) {
for (k = 0; k < 3; k++) {
transparent_crc(g_2[i][j][k], "g_2[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_23, "g_23", print_hash_value);
transparent_crc(g_197.f0, "g_197.f0", print_hash_value);
transparent_crc(g_197.f1, "g_197.f1", print_hash_value);
transparent_crc(g_197.f2, "g_197.f2", print_hash_value);
transparent_crc(g_197.f3, "g_197.f3", print_hash_value);
transparent_crc(g_197.f4, "g_197.f4", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_a138[i], "g_a138[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
transparent_crc(g_b138[i], "g_b138[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/eJzsWluP6jgS_jXmxSKyy7k-8JBw0RypR73SzHmOQnDAdEjYxOnm7K9f2UnIDTg9c3r3YQRChCrX5XNV-VJ0R2Up9hnnC2QFyFrNokoe8mKxTvMPns2Px4_ZNt_9WGzyAssDx0mepvmHyPZYfuQ4xolIeYlgib_hMy-SvDjxnRbk_67Ee5TyTGJZRFmphiIp8gznCU7z_IyTIj9hBD4CX1mhRlwTWOY9NrRsA3_DRZQp4yXX3rVvXPDyzGMp3nn6A1elgrYTScIL5To_S3ES_6kdp_ydpyUWWZxWOyVXG56_kvqLmkbLolMWTFlsyiqnrCQqZTuHP1VoLlEscV7JcyUV_CqVJQJXGNzA8YHHb2V1wu9RWqnIejgqOGI-IitEfGST5q1JPHjNXwmev9IRD0Y0G9HliFZocW2-SUsztF76S1iSq-iY9pwNoYx4E_qhYOcJfurpZx4_4WgcwPrxr5RHJccHnp7xiasC5JdzGokMfxx-TCruXOS7Kua7fp0Nkok_DjxralGthTI68Rul2OZcl5anKkYeouwN_8gro0GrP-P8dIqyHU5FdrcS4jRSBc2WCmIWnbgRI7ZWjBt-2RrP0xOef8MIzOUfv3_787fwt9ff1wg29eLgGIGNwMYGgk1k5JW86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