From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 148DF3858D20; Sun, 19 Feb 2023 13:37:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 148DF3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676813871; bh=USMvDwem+BwMfXAurac4zHZJNKjrXT4bWqwBEPmsDcM=; h=From:To:Subject:Date:From; b=XEUUo09wd7svjimj8Xmor9XVXNazT0EtouXawk1aeAtFHF1tonwftUrtnXRCjtkQF vFrxQDM+P0tHb22kQNjNXpKE+0/o2e7PPxWU5UuikhTOaQlU4GM+XJec8QYFUbQLBY aIOlh24XLiCcuVZMagwGjZN7eZMCocor3k/lgpgs= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/108847] New: unnecessary bitwise AND on boolean types Date: Sun, 19 Feb 2023 13:37:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 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=3D108847 Bug ID: 108847 Summary: unnecessary bitwise AND on boolean types Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- Godbolt: https://gcc.godbolt.org/z/fsavMzMo7 ``` void set_bool(bool& fl, __UINT32_TYPE__ value) { fl |=3D value >> 31; } ``` This code shifts a `uint32` to the right by 31 bits, so the result will onl= y be 0 or 1. Clang outputs: ``` set_bool(bool&, unsigned int): # @set_bool(bool&, unsigned int) shr esi, 31 or byte ptr [rdi], sil ret ``` but GCC emits an additional unnecessary bitwise AND operation on the destination operand: ``` set_bool(bool&, unsigned int): shr esi, 31 or BYTE PTR [rdi], sil and BYTE PTR [rdi], 1 ret ```=