From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EE97A3858C83; Sun, 23 Apr 2023 18:26:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE97A3858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682274382; bh=poqzl9H73imH227Zpw7cqIun2FYniv6YwqF9yU5p7Ks=; h=From:To:Subject:Date:From; b=ftiA4YZB8NAb0FdR9QHsm2fg3fAtIRnhxhr1XPKnDNuKGGBluj1tcs9OvdRmsi+xw imDUZZT6QMVKUa99xlspAsmg8r3eoPFQa5pU/LBoKvNtTFuYSOg7z7lGCFKj7YXhQF cAhC7f7Q431VpJ6ePTwFJj9NdF5Tvnt/Ex+aEFF0= From: "67 at mniip dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/109601] New: Useless branch not eliminated when writing to a union Date: Sun, 23 Apr 2023 18:26:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 67 at mniip 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 attachments.created 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=3D109601 Bug ID: 109601 Summary: Useless branch not eliminated when writing to a union Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: 67 at mniip dot com Target Milestone: --- Created attachment 54909 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54909&action=3Dedit Minimal testcase On x86_64-pc-linux-gnu the attached code compiles (with -O3) to rather unsatisfying assembly with a branch that does the same thing whether taken = or not: > 10: 85 c0 test %eax,%eax > 12: 74 04 je 18 > 14: c3 ret > 15: 0f 1f 00 nopl (%rax) > 18: c3 ret I've tested on my machine in GCC 12.2.1, but Compiler Explorer ( https://godbolt.org/z/cW69rfrPc ) shows the same thing happens in a lot of other versions, including trunk (6ab856aa49bef7c04efa6144a5048e129b3a058b). Notably, this doesn't happen in GCC 4.5.3. This seems to happen for a few other targets as well, e.g: arm, riscv32; but not on some others, e.g. aarch64, mips.=