public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/108847] New: unnecessary bitwise AND on boolean types
@ 2023-02-19 13:37 lh_mouse at 126 dot com
  2023-02-20 18:43 ` [Bug middle-end/108847] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: lh_mouse at 126 dot com @ 2023-02-19 13:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108847

            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 |= value >> 31;
  }
```

This code shifts a `uint32` to the right by 31 bits, so the result will only 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
```

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-08-01  9:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 13:37 [Bug middle-end/108847] New: unnecessary bitwise AND on boolean types lh_mouse at 126 dot com
2023-02-20 18:43 ` [Bug middle-end/108847] " pinskia at gcc dot gnu.org
2023-05-20  1:14 ` [Bug middle-end/108847] unnecessary bitwise AND on boolean types and shifting of the "sign" bit pinskia at gcc dot gnu.org
2023-05-20 23:31 ` pinskia at gcc dot gnu.org
2023-05-20 23:34 ` [Bug middle-end/108847] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-05-20 23:34 ` pinskia at gcc dot gnu.org
2023-05-20 23:36 ` pinskia at gcc dot gnu.org
2023-05-27  6:50 ` pinskia at gcc dot gnu.org
2023-05-27  7:02 ` pinskia at gcc dot gnu.org
2023-09-17  1:49 ` [Bug middle-end/108847] [11/12/13/14 " pinskia at gcc dot gnu.org
2024-03-08 15:38 ` law at gcc dot gnu.org
2024-05-07  7:40 ` [Bug middle-end/108847] [11/12/13/14/15 " rguenth at gcc dot gnu.org
2024-08-01  9:31 ` [Bug middle-end/108847] [12/13/14/15 " jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).