From: Jingwen Wu <elowen.jjw@gmail.com>
To: gcc@gcc.gnu.org
Subject: issue: unexpected results in optimizations
Date: Tue, 12 Dec 2023 01:14:00 +0800 [thread overview]
Message-ID: <CAJAwgAxMAAY6AvVwSjUvJ2cPkFi9fqj8Nii1qaaHxER5ChEjzw@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 768 bytes --]
Hello, I'm sorry to bother you. And I have some gcc compiler optimization
questions to ask you.
First of all, I used csmith tools to generate c files randomly. Meanwhile,
the final running result was the checksum for global variables in a c file.
For the two c files in the attachment, I performed the equivalent
transformation of loop from *initial.**c* to *transformed.c*. And the two
files produced different results (i.e. different checksum values) when
using *-Os* optimization level, while the results of both were the same
when using other levels of optimization such as *-O0*, -O1, -O2, -O3,
*-Ofast*.
Please help me to explain why this is, thank you.
command line: *gcc file.c -Os -lm -I $CSMITH_HOME/include && ./a.out*
version: gcc 12.2.0
os: ubuntu 22.04
[-- Attachment #2: initial.c --]
[-- Type: application/octet-stream, Size: 2322 bytes --]
#include "csmith.h"
static int32_t g_a83[69];
static int32_t g_b83[69];
static volatile uint16_t g_2[3][2][1] = {{{0x439BL}, {8UL}}, {{8UL}, {0x439BL}}, {{8UL}, {8UL}}};
static int32_t g_3 = 0xB4E1265AL;
static uint8_t g_13 = 0x83L;
static int16_t g_15[1] = {0x4F23L};
static int32_t *g_20 = &g_3;
static int32_t *const *g_53 = &g_20;
static int32_t *const **g_52 = &g_53;
static int32_t *g_92 = &g_3;
static volatile uint8_t g_167 = 8UL;
static int32_t g_258 = 0xDB41F928L;
static volatile uint8_t *volatile g_261 = &g_167;
static volatile int32_t g_267 = 0x9B2E194DL;
static int32_t **volatile g_389 = &g_92;
static void func_1(void);
static void func_1(void) {
int32_t l_14 = 0xDD013D0BL;
if (g_2[1][1][0]) {
uint32_t l_36[1][3];
uint8_t *l_37 = &g_13;
int i, j;
for (i = 0; i < 1; i++) {
for (j = 0; j < 3; j++) {
l_36[i][j] = 0xB839BF5BL;
}
}
if ((~(((***g_52) = l_36[0][1]) ^ (safe_div_func_int64_t_s_s((l_14 || 0x12L), g_15[0]))))) {
int ii_4;
// fusion in max execTimes
for (g_13 = 8, ii_4 = 0; (g_13 <= 44); g_13 = safe_add_func_uint64_t_u_u(g_13, 1), ii_4++) {
g_a83[ii_4] = g_258 * g_13 + (*g_261);
}
int jj_4;
for (jj_4 = 0; jj_4 < 69; jj_4++) {
g_b83[jj_4] = (**g_389) * g_a83[jj_4] - g_267;
}
} else {
uint8_t **l_81 = &l_37;
uint8_t ***l_80 = &l_81;
}
}
}
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 < 1; k++) {
transparent_crc(g_2[i][j][k], "g_2[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_3, "g_3", print_hash_value);
transparent_crc(g_13, "g_13", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_15[i], "g_15[i]", print_hash_value);
}
transparent_crc(g_167, "g_167", print_hash_value);
transparent_crc(g_258, "g_258", print_hash_value);
transparent_crc(g_267, "g_267", print_hash_value);
for (i = 0; i < 69; i++) {
transparent_crc(g_a83[i], "g_a83[i]", print_hash_value);
}
for (i = 0; i < 69; i++) {
transparent_crc(g_b83[i], "g_b83[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
[-- Attachment #3: transformed.c --]
[-- Type: application/octet-stream, Size: 2457 bytes --]
#include "csmith.h"
static int32_t g_a83[69];
static int32_t g_b83[69];
static volatile uint16_t g_2[3][2][1] = {{{0x439BL}, {8UL}}, {{8UL}, {0x439BL}}, {{8UL}, {8UL}}};
static int32_t g_3 = 0xB4E1265AL;
static uint8_t g_13 = 0x83L;
static int16_t g_15[1] = {0x4F23L};
static int32_t *g_20 = &g_3;
static int32_t *const *g_53 = &g_20;
static int32_t *const **g_52 = &g_53;
static int32_t *g_92 = &g_3;
static volatile uint8_t g_167 = 8UL;
static int32_t g_258 = 0xDB41F928L;
static volatile uint8_t *volatile g_261 = &g_167;
static volatile int32_t g_267 = 0x9B2E194DL;
static int32_t **volatile g_389 = &g_92;
static void func_1(void);
static void func_1(void) {
int32_t l_14 = 0xDD013D0BL;
if (g_2[1][1][0]) {
uint32_t l_36[1][3];
uint8_t *l_37 = &g_13;
int i, j;
for (i = 0; i < 1; i++) {
for (j = 0; j < 3; j++) {
l_36[i][j] = 0xB839BF5BL;
}
}
if ((~(((***g_52) = l_36[0][1]) ^ (safe_div_func_int64_t_s_s((l_14 || 0x12L), g_15[0]))))) {
int ii_4;
int jj_4;
int ij_4;
// fusion in max execTimes
for (g_13 = 8, ii_4 = 0, jj_4 = 0, ij_4 = 0; ij_4 <= 69; ij_4++) {
if (ij_4 <= 37 && (g_13 <= 44)) {
g_a83[ii_4] = g_258 * g_13 + (*g_261);
g_13 = safe_add_func_uint64_t_u_u(g_13, 1);
ii_4++;
}
if (ij_4 <= 69 && jj_4 < 69) {
g_b83[jj_4] = (**g_389) * g_a83[jj_4] - g_267;
jj_4++;
}
}
} else {
uint8_t **l_81 = &l_37;
uint8_t ***l_80 = &l_81;
}
}
}
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 < 1; k++) {
transparent_crc(g_2[i][j][k], "g_2[i][j][k]", print_hash_value);
}
}
}
transparent_crc(g_3, "g_3", print_hash_value);
transparent_crc(g_13, "g_13", print_hash_value);
for (i = 0; i < 1; i++) {
transparent_crc(g_15[i], "g_15[i]", print_hash_value);
}
transparent_crc(g_167, "g_167", print_hash_value);
transparent_crc(g_258, "g_258", print_hash_value);
transparent_crc(g_267, "g_267", print_hash_value);
for (i = 0; i < 69; i++) {
transparent_crc(g_a83[i], "g_a83[i]", print_hash_value);
}
for (i = 0; i < 69; i++) {
transparent_crc(g_b83[i], "g_b83[i]", print_hash_value);
}
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
next reply other threads:[~2023-12-11 17:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 17:14 Jingwen Wu [this message]
2023-12-12 8:39 ` David Brown
2023-12-13 18:49 ` James K. Lowden
-- strict thread matches above, loose matches on Subject: below --
2023-12-11 17:07 Jingwen Wu
2023-12-11 17:31 ` Dave Blanchard
2023-12-12 8:29 ` Jonathan Wakely
2023-12-12 9:02 ` Jonathan Wakely
2023-12-12 11:08 ` Alexander Monakov
2023-12-11 17:05 Jingwen Wu
2023-12-11 16:51 Jingwen Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJAwgAxMAAY6AvVwSjUvJ2cPkFi9fqj8Nii1qaaHxER5ChEjzw@mail.gmail.com \
--to=elowen.jjw@gmail.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).