From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E4DEA3858D37; Thu, 28 Dec 2023 02:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4DEA3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703732333; bh=XoscyUlA6cXImalSfh3bQxkN2GBn6uo0LGum6Xp8yb8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Rny574m/bMibFM0yP4iTXns4T543l3GLWZZrE11uvHMQIpTmjKgwaEz/B7llhzLQy MYs2lEz4gKzSW8kJg4RizfN7165/Jv/Iw2sT0IkHaHRMNpCMIKIAvcBee6ro4zdNWf W+QiJp9UNNbmZf7N8tCqAtTvWrPqb2RQMygaQHSo= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/81456] [11/12/13/14 Regression] x86-64 optimizer makes wrong decision when optimizing for size Date: Thu, 28 Dec 2023 02:58:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 8.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: 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=3D81456 LIU Hao changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lh_mouse at 126 dot com --- Comment #12 from LIU Hao --- Is this the same issue? https://gcc.godbolt.org/z/sTs3E9EP1 ``` struct stack { void** base; unsigned int top, cap; }; struct context { void* data; stack* st; }; int clear_stack(context& ctx) { ctx.st->top =3D 0; return 0; } ``` GCC reuses RAX for `ctx.st` and the return value, so an extra XOR is genera= ted: ``` clear_stack(context&): mov rax,QWORD PTR [rdi+0x8] xor edx,edx <-- this would be unnecessary if `xor eax, eax` was lifted here mov DWORD PTR [rax+0x8],edx xor eax,eax ret ``` as in ``` clear_stack_2(context&): mov rcx,QWORD PTR [rdi+0x8] # 48 8b 4f 08 xor eax,eax # 31 c0 mov DWORD PTR [rcx+0x8],eax # 89 41 08 ret # c3 ```=