https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108418
Bug ID: 108418
Summary: gcc does not optimize trivial code
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/s3j8jK6ca
```
#include <stdint.h>
int firewall1(const uint8_t *restrict data) {
const uint8_t ip_proto = *data;
const uint16_t dst_port = *((const uint16_t *)data + 32);
const uint16_t qwe = *((const uint16_t *)data + 64);
if (ip_proto == 17 && dst_port == 17 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 23 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 45 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 63 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 0 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 2 && qwe == 42) return 1;
if (ip_proto == 17 && dst_port == 3 && qwe == 42) return 1;
return 0;
}
int firewall2(const uint8_t *restrict data) {
const uint8_t ip_proto = *data;
const uint16_t dst_port = *((const uint16_t *)data + 32);
const uint16_t qwe = *((const uint16_t *)data + 64);
if (ip_proto == 17 && dst_port == 17) return 1;
if (ip_proto == 17 && dst_port == 23) return 1;
if (ip_proto == 17 && dst_port == 45) return 1;
if (ip_proto == 17 && dst_port == 63) return 1;
if (ip_proto == 17 && dst_port == 0) return 1;
if (ip_proto == 17 && dst_port == 2) return 1;
if (ip_proto == 17 && dst_port == 3) return 1;
return 0;
}
```
It can't understand common condition (ip_proto == 17 && qwe == 42).
But it can for simpler case in firewall2.
See godbolt assembler output.