public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108215] New: Does not optimize trivial case with bit operations
@ 2022-12-23 18:48 socketpair at gmail dot com
  2022-12-24 20:27 ` [Bug tree-optimization/108215] " pinskia at gcc dot gnu.org
  2023-01-09 13:41 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: socketpair at gmail dot com @ 2022-12-23 18:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108215
           Summary: Does not optimize trivial case with bit operations
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: socketpair at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/5e3eKqPqs

```C
#include <stdint.h>

int firewall3(const uint8_t *restrict data) {
    const uint32_t src = *((const uint32_t *)data);
    if ((src & 0xFFFF0000) == 0x11220000) return 1;
    if ((src & 0xFFFFFF00) == 0x11223300) return 1;
    return 0;
}

int firewall4(const uint8_t *restrict data) {
    const uint32_t src = *((const uint32_t *)data);
    if ((src & 0xFFFFFF00) == 0x11223300) return 1;
    if ((src & 0xFFFF0000) == 0x11220000) return 1;
    return 0;
}
```

```
firewall3:
        movl    (%rdi), %eax
        xorw    %ax, %ax
        cmpl    $287440896, %eax
        sete    %al
        movzbl  %al, %eax
        ret
firewall4:
        movl    (%rdi), %eax
        movl    $1, %edx
        movl    %eax, %ecx
        xorb    %cl, %cl
        cmpl    $287453952, %ecx
        je      .L3
        xorw    %ax, %ax
        xorl    %edx, %edx
        cmpl    $287440896, %eax
        sete    %dl
.L3:
        movl    %edx, %eax
        ret
```

firewall3(): Excellent!
firewall4(): FAIL!

It's obvious that order of comparisons in this example does not matter. So I
think misoptimisation of firewall4() is a bug.

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

* [Bug tree-optimization/108215] Does not optimize trivial case with bit operations
  2022-12-23 18:48 [Bug tree-optimization/108215] New: Does not optimize trivial case with bit operations socketpair at gmail dot com
@ 2022-12-24 20:27 ` pinskia at gcc dot gnu.org
  2023-01-09 13:41 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-24 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2022-12-24

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Note GCC only started to optimize firewall3 in GCC 11 via jump
threading.

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

* [Bug tree-optimization/108215] Does not optimize trivial case with bit operations
  2022-12-23 18:48 [Bug tree-optimization/108215] New: Does not optimize trivial case with bit operations socketpair at gmail dot com
  2022-12-24 20:27 ` [Bug tree-optimization/108215] " pinskia at gcc dot gnu.org
@ 2023-01-09 13:41 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-09 13:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's something for if-conversion / if-combine.  We have

  <bb 2> [local count: 1073741824]:
  src_6 = MEM[(const uint32_t *)data_5(D)];
  _1 = src_6 & 4294967040;
  if (_1 == 287453952)
    goto <bb 5>; [20.97%]
  else
    goto <bb 3>; [79.03%]

  <bb 3> [local count: 848578161]:
  _2 = src_6 & 4294901760;
  if (_2 == 287440896)
    goto <bb 4>; [20.97%]
  else
    goto <bb 5>; [79.03%]

  <bb 4> [local count: 177946843]:

  <bb 5> [local count: 1073741824]:
  # _3 = PHI <1(4), 0(3), 1(2)>

so an effective if-or-if where we fail to handle combining the conditions
(we're going the if-and-if way to the zero return).

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

end of thread, other threads:[~2023-01-09 13:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-23 18:48 [Bug tree-optimization/108215] New: Does not optimize trivial case with bit operations socketpair at gmail dot com
2022-12-24 20:27 ` [Bug tree-optimization/108215] " pinskia at gcc dot gnu.org
2023-01-09 13:41 ` rguenth 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).