| Issue |
75602
|
| Summary |
unexpected output results in fusion using -O1
|
| 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 88CB41A7 F0C18576 42F2CD83 42F2CD83 F0C18576 42F2CD83
file2.c 88CB41A7 88CB41A7 42F2CD83 42F2CD83 F0C18576 42F2CD83
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -O1), 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 long __undefined;
static int32_t g_a0[1];
static int64_t g_b0[1];
union U0 {
const volatile uint32_t f0;
volatile uint16_t f1;
};
static int16_t g_6 = 0x3C63L;
static int16_t g_7 = 0L;
static uint16_t g_16 = 0xCF25L;
static int32_t g_28 = 0x9D70CADDL;
static int16_t g_36 = 0xEFEDL;
static volatile uint64_t g_40 = 0x8CBD6CD538770CE4LL;
static uint8_t g_70[2] = {0x13L, 0x13L};
static int32_t g_112 = 0x375EFDD8L;
static int64_t g_143[2] = {0xE94C56F68EFB8CC5LL, 0xE94C56F68EFB8CC5LL};
static int32_t g_144 = 0x7A3D7248L;
static uint16_t g_146[3] = {0xA39AL, 0xA39AL, 0xA39AL};
static int64_t g_284[3][2] = {{0xE1E09E583A3E19EALL, 0xE1E09E583A3E19EALL}, {(-2L), 0xE1E09E583A3E19EALL}, {0xE1E09E583A3E19EALL, (-2L)}};
static int32_t *g_306 = &g_112;
static int32_t **g_305 = &g_306;
static void func_1(void);
static void func_1(void) {
int32_t *l_259 = &g_112;
uint16_t l_317 = 1UL;
uint64_t l_319 = 18446744073709551608UL;
int i, j;
int ii_0;
// fusion
for (i = 0, ii_0 = 0; i < 1; i++, ii_0++) {
g_a0[ii_0] = g_70[0] * g_112 - g_144;
}
int jj_0;
for (jj_0 = 0; jj_0 < 1; jj_0++) {
g_b0[jj_0] = g_143[1] * g_a0[jj_0] + g_7;
}
(**g_305) = (((((g_112 > ((g_284[0][1] &= ((safe_sub_func_uint8_t_u_u((safe_add_func_uint16_t_u_u(((*l_259) || g_146[0]), 0UL)), g_6)) < l_317)) | (*l_259))) | l_319), (*l_259)) & 255UL) ^ g_28);
}
int main(void) {
int i, j;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_6, "g_6", print_hash_value);
transparent_crc(g_7, "g_7", print_hash_value);
transparent_crc(g_16, "g_16", print_hash_value);
transparent_crc(g_28, "g_28", print_hash_value);
transparent_crc(g_36, "g_36", print_hash_value);
transparent_crc(g_40, "g_40", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_70[i], "g_70[i]", print_hash_value);
}
transparent_crc(g_112, "g_112", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_143[i], "g_143[i]", print_hash_value);
}
transparent_crc(g_144, "g_144", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_146[i], "g_146[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
transparent_crc(g_284[i][j], "g_284[i][j]", print_hash_value);
}
}
for (i = 0; i < 1; i++) {
transparent_crc(g_a0[i], "g_a0[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b0[i], "g_b0[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
```
**file2.c**
```
#include "csmith.h"
static long __undefined;
static int32_t g_a0[1];
static int64_t g_b0[1];
union U0 {
const volatile uint32_t f0;
volatile uint16_t f1;
};
static int16_t g_6 = 0x3C63L;
static int16_t g_7 = 0L;
static uint16_t g_16 = 0xCF25L;
static int32_t g_28 = 0x9D70CADDL;
static int16_t g_36 = 0xEFEDL;
static volatile uint64_t g_40 = 0x8CBD6CD538770CE4LL;
static uint8_t g_70[2] = {0x13L, 0x13L};
static int32_t g_112 = 0x375EFDD8L;
static int64_t g_143[2] = {0xE94C56F68EFB8CC5LL, 0xE94C56F68EFB8CC5LL};
static int32_t g_144 = 0x7A3D7248L;
static uint16_t g_146[3] = {0xA39AL, 0xA39AL, 0xA39AL};
static int64_t g_284[3][2] = {{0xE1E09E583A3E19EALL, 0xE1E09E583A3E19EALL}, {(-2L), 0xE1E09E583A3E19EALL}, {0xE1E09E583A3E19EALL, (-2L)}};
static int32_t *g_306 = &g_112;
static int32_t **g_305 = &g_306;
static void func_1(void);
static void func_1(void) {
int32_t *l_259 = &g_112;
uint16_t l_317 = 1UL;
uint64_t l_319 = 18446744073709551608UL;
int i, j;
int ii_0;
int jj_0;
int ij_0;
// fusion
for (i = 0, ii_0 = 0, jj_0 = 0, ij_0 = 0; ij_0 <= 1; ij_0++) {
if (ij_0 <= 1 && i < 1) {
g_a0[ii_0] = g_70[0] * g_112 - g_144;
i++;
ii_0++;
}
if (ij_0 <= 1 && jj_0 < 1) {
g_b0[jj_0] = g_143[1] * g_a0[jj_0] + g_7;
jj_0++;
}
}
(**g_305) = (((((g_112 > ((g_284[0][1] &= ((safe_sub_func_uint8_t_u_u((safe_add_func_uint16_t_u_u(((*l_259) || g_146[0]), 0UL)), g_6)) < l_317)) | (*l_259))) | l_319), (*l_259)) & 255UL) ^ g_28);
}
int main(void) {
int i, j;
int print_hash_value = 0;
platform_main_begin();
crc32_gentab();
func_1();
transparent_crc(g_6, "g_6", print_hash_value);
transparent_crc(g_7, "g_7", print_hash_value);
transparent_crc(g_16, "g_16", print_hash_value);
transparent_crc(g_28, "g_28", print_hash_value);
transparent_crc(g_36, "g_36", print_hash_value);
transparent_crc(g_40, "g_40", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_70[i], "g_70[i]", print_hash_value);
}
transparent_crc(g_112, "g_112", print_hash_value);
for (i = 0; i < 2; i++) {
transparent_crc(g_143[i], "g_143[i]", print_hash_value);
}
transparent_crc(g_144, "g_144", print_hash_value);
for (i = 0; i < 3; i++) {
transparent_crc(g_146[i], "g_146[i]", print_hash_value);
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
transparent_crc(g_284[i][j], "g_284[i][j]", print_hash_value);
}
}
for (i = 0; i < 1; i++) {
transparent_crc(g_a0[i], "g_a0[i]", print_hash_value);
}
for (i = 0; i < 1; i++) {
transparent_crc(g_b0[i], "g_b0[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