From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3E04F3858C50; Thu, 9 Feb 2023 11:17:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E04F3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675941459; bh=u+htB+6ScyyV9Srpyu5C7ZrWp0rjsWazLbt0wsvfWlY=; h=From:To:Subject:Date:From; b=YGzZA8mzR7pAE4aEEQn0C8WCD2mbThHvFqNpn/lCZ1Gn1UgoL+F3WJngmDaVeOh2z qKhVM5Ykj9XBTApDSEuJL/DLD/QGQXqsUwDOExWt4HaMX3+NkvJsJpk+8j1uJlryQ1 JclGuWzvCYy47rgWjGdQHwFgC2V96T4LVBJpEplo= From: "jankowski938 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108740] New: two identical functions but the code generated differs. Why? Date: Thu, 09 Feb 2023 11:17:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jankowski938 at gmail dot com 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=3D108740 Bug ID: 108740 Summary: two identical functions but the code generated differs. Why? Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jankowski938 at gmail dot com Target Milestone: --- I know it is UB but I just wonder why two identical functions generate different code: ``` #define OPPOSITE(c) (*((typeof(x) *)&(x))) int foo(volatile int x) { OPPOSITE(x) =3D OPPOSITE(x) + OPPOSITE(x); return x; } int bar(volatile int x) { OPPOSITE(x) =3D OPPOSITE(x) + OPPOSITE(x); return x; } ``` x86-65 gcc 12.2 -Wall -Wextra -Os=20 ``` foo: mov DWORD PTR [rsp-4], edi mov eax, DWORD PTR [rsp-4] mov edx, DWORD PTR [rsp-4] add eax, edx mov DWORD PTR [rsp-4], eax mov eax, DWORD PTR [rsp-4] ret bar: mov DWORD PTR [rsp-4], edi mov eax, DWORD PTR [rsp-4] add eax, eax ret ``` ARM-eabi-none 11.2.1 -Wall -Wextra -O3 (same -|Os) ``` foo: sub sp, sp, #8 str r0, [sp, #4] ldr r3, [sp, #4] ldr r2, [sp, #4] add r3, r3, r2 str r3, [sp, #4] ldr r0, [sp, #4] add sp, sp, #8 bx lr bar: sub sp, sp, #8 str r0, [sp, #4] ldr r0, [sp, #4] lsl r0, r0, #1 add sp, sp, #8 bx lr ``` https://godbolt.org/z/7eMbPcdqs=20 I know that is UB in C11 onwards but I would expect both to be exactly the same.=