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

            Bug ID: 107767
           Summary: GCC has some problems in optimizer of trivial case
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: regression
          Assignee: unassigned at gcc dot gnu.org
          Reporter: socketpair at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/rTfTondfP

```
#include <stdint.h>

int firewall(const uint8_t *restrict data) {
    const uint8_t ip_proto = *data;
    const uint16_t dst_port = *((const uint16_t *)data + 32);

    if (ip_proto == 17 && dst_port == 15) return 1;
    if (ip_proto == 17 && dst_port == 23) return 1;
    if (ip_proto == 17 && dst_port == 47) return 1;
    if (ip_proto == 17 && dst_port == 45) return 1;
    if (ip_proto == 17 && dst_port == 42) return 1;
    if (ip_proto == 17 && dst_port == 1) return 1;
    if (ip_proto == 17 && dst_port == 2) return 1;
    if (ip_proto == 17 && dst_port == 3) return 1;

    return 0;
}

int firewall2(const uint8_t *restrict data) {
    const uint16_t dst_port = *((const uint16_t *)data + 32);

    if (dst_port == 15) return 1;
    if (dst_port == 23) return 1;
    if (dst_port == 47) return 1;
    if (dst_port == 45) return 1;
    if (dst_port == 42) return 1;
    if (dst_port == 1) return 1;
    if (dst_port == 2) return 1;
    if (dst_port == 3) return 1;

    return 0;
}
```

Compile with -Os.

Second function IS NOT minimal, obviously. It's a bug. GCC 12.2 does not have
it.

Reply via email to