| Issue |
75608
|
| Summary |
unexpected output results in fusion using -O2
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Elowen-jjw
|
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;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs