https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129120
Bug ID: 129120
Summary: `(65*u)&65 == 1 ? x&64 : 64` -> 64
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 85316
Target Milestone: ---
>From https://mastodon.social/@cfbolz/117690623361198717 :
```
unsigned char returns64(unsigned char x) {
unsigned char p = 65u * x;
if ((p & 0x41u) == 1u) // bit 0 is set, bit 6 is clear
return x & 0x40u;
return 0x40u;
}
unsigned char returns0(unsigned char p) {
if ((p & 0x41u) == 1u) // bit 0 is set, bit 6 is clear
return p & 0x40u;
return 0;
}
```
So we can figure out that `p&0x40 == 0` is true on the branch (see returns0),
with that info (that is `(0x41*x)&0x41 == 0x1` or `(0x41*x)&0x40 == 0`), x&0x40
is 0x40.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases