From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 28F493858D33; Tue, 24 Jan 2023 11:01:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28F493858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674558087; bh=+jgJmRRgfn629DkAJX2PeTI3Wft2PE+GWfi1GhD6eoY=; h=From:To:Subject:Date:From; b=thgMlVnt1bnxvqG5Dw1qO/NVhA0720mogyXiXiTbVMQgeg9pOyKSDrwHBafaqPI9E 9/Zu2ig1vpGQ1iyPoMs54O23UYApfBEfc/a/TQ4JHllLFjx8eW2gqKw+L6BZ7YmGAB 4NK2zNXBDNauOkPPK+xAuuLSA0IKaUFMhoVE8BEk= From: "jzwinck at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/108516] New: Useless movzx instruction emitted when loading 8 bits from 24 bit struct Date: Tue, 24 Jan 2023 11:01:25 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jzwinck 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=3D108516 Bug ID: 108516 Summary: Useless movzx instruction emitted when loading 8 bits from 24 bit struct Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jzwinck at gmail dot com Target Milestone: --- This code produces an extra instruction in GCC 11 and 12 (but not 10 or before): #include struct S { uint8_t e1; uint8_t e2; uint8_t e3; }; uint32_t f2(S s) { return s.e2; } The generated code is: mov eax, edi movzx eax, ah movzx eax, al ret The movzx from "al" is useless: it zeros the high 24 bits of eax which are known to be zero after the prior movzx. GCC 10 and earlier do not emit the useless instruction, and neither do GCC 11 or 12 if the struct contains 4 b= ytes instead of 3. Demo: https://godbolt.org/z/Wajo86GfM=