From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B1D553858C5F; Thu, 29 Feb 2024 16:27:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1D553858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709224020; bh=nMS8IyD4cP7SdJlKloAbBbfdb2aeqJ00/ISwlI02V1o=; h=From:To:Subject:Date:From; b=QidqIZQyCpDOp/l3oEXggKVPE3JXIn9QkTdQ9PJloMnDKmDay1RQkRUPa5QYYlfZA XhKCBRiN+XOn+9hvMhkX6DpY4UOElFBOpw/R7/K4uvyOh6AdfmPVKE5bOG5uuFaRxG YsgRXOlT9jthI1qURyjbpxyq3deei2JVFxyWG+ZA= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/114173] New: miss optimization of redundant load operation, may confused by type conversion Date: Thu, 29 Feb 2024 16:27:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114173 Bug ID: 114173 Summary: miss optimization of redundant load operation, may confused by type conversion Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- Hi, here's the code: ``` typedef signed char int8_t; typedef unsigned char uint8_t; typedef signed short int int16_t; typedef unsigned short int uint16_t; typedef signed int int32_t; typedef unsigned int uint32_t; typedef signed long int int64_t; typedef unsigned long int uint64_t; /* --- Struct/Union Declarations --- */ struct S1 { uint32_t f0; int32_t f1; uint16_t f2; }; /* --- GLOBAL VARIABLES --- */ int32_t g_6 =3D 0xA0CEC519L; int32_t g_63[10] =3D {0x62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x= 62155B98L,0xEEA2DBBAL,0xEEA2DBBAL,0x62155B98L}; struct S1 g_304 =3D {0x917144CEL,-8L,0x6D84L,-2L,0xD005B892436443A6LL,0xF5L,0x7EDC5F4166794133L= L}; /* --- FORWARD DECLARATIONS --- */ void func_1() { int32_t b =3D 1; int32_t c; int8_t d; if (d =3D c =3D (uint16_t)((uint8_t)g_63[4] + b) - b) { uint16_t *e =3D &g_304.f0; *e =3D c; } } ``` compiled with gcc-13.2.0 -O3, generated binary is: https://godbolt.org/z/P9scnWqsa ``` 00000000004015f0 : func_1(): /root/loadtest3/test/output2.c:43 4015f0: cmpb $0x0,0x2ab9(%rip) # 4040b0 4015f7: movzbl 0x2ab2(%rip),%eax # 4040b0 4015fe: je 401607 /root/loadtest3/test/output2.c:45 401600: mov %ax,0x2a79(%rip) # 404080 /root/loadtest3/test/output2.c:47 401607: retq=20=20=20 401608: nopl 0x0(%rax,%rax,1) ``` the compare and load instructions can swap and $eax can be used in the comp= are, instead of a memory access=