<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75068>75068</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
unexpected results in optimizations
</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>
First of all, I used csmith tools to generate c files randomly. Meanwhile, the final running result is the checksum for global variables in a c file.
For the following two c files, I performed the equivalent transformation of loop from **file1.c** to **file2.c**. And the two files produced different results (i.e. different checksum values) when using ``` clang file.c -O1 -lm -I $CSMITH_HOME/include && ./a.out```, while the results of both are the same when using other levels of optimization such as **-O0**, **-O2**, **-O3**, **-Os**, **-Ofast**.
Please help me to explain why this is, thank you.
version: clang 14.0.0
os: ubuntu 22.04
**file1.c**
```
#include "csmith.h"
static int g_a105[1];
static int64_t g_b105[1];
union U0 {
signed f0 : 26;
int64_t f1;
int16_t f2;
};
static int32_t g_37 = 0x2CE6C1CCL;
static uint8_t g_206[2] = {0UL, 0UL};
static union U0 g_300 = {0x9E01EE1CL};
static union U0 *g_302[2][3][2] = {{{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}, {{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}};
static union U0 **volatile g_457 = &g_302[0][1][1];
static void func_1(void);
static void func_1(void) {
int i, j;
for (i = 0; i < 1; i++) {
int ii_2;
// fusion
for (j = 0, ii_2 = 0; j < 1; j++, ii_2++) {
g_a105[ii_2] = g_206[0] * g_37 - (**g_457).f0;
}
int jj_2;
for (jj_2 = 0; jj_2 < 1; jj_2++) {
g_b105[jj_2] = (*g_302[0][1][0]).f0 * g_a105[jj_2] - (*g_302[1][2][1]).f1;
}
}
}
int main(void) {
int i;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_37, "g_37", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_206[i], "g_206[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_a105[i], "g_a105[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b105[i], "g_b105[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static int g_a105[1];
static int64_t g_b105[1];
union U0 {
signed f0 : 26;
int64_t f1;
int16_t f2;
};
static int32_t g_37 = 0x2CE6C1CCL;
static uint8_t g_206[2] = {0UL, 0UL};
static union U0 g_300 = {0x9E01EE1CL};
static union U0 *g_302[2][3][2] = {{{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}, {{&g_300, &g_300}, {&g_300, &g_300}, {&g_300, &g_300}}};
static union U0 **volatile g_457 = &g_302[0][1][1];
static void func_1(void);
static void func_1(void) {
int i, j;
for (i = 0; i < 1; i++) {
int ii_2;
int jj_2;
int ij_2;
// fusion
for (j = 0, ii_2 = 0, jj_2 = 0, ij_2 = 0; ij_2 <= 1; ij_2++) {
if (ij_2 <= 1 && j < 1) {
g_a105[ii_2] = g_206[0] * g_37 - (**g_457).f0;
j++;
ii_2++;
}
if (ij_2 <= 1 && jj_2 < 1) {
g_b105[jj_2] = (*g_302[0][1][0]).f0 * g_a105[jj_2] - (*g_302[1][2][1]).f1;
jj_2++;
}
}
}
}
int main(void) {
int i;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_37, "g_37", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_206[i], "g_206[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_a105[i], "g_a105[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b105[i], "g_b105[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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