https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115224
Bug ID: 115224
Summary: (a ^ 1) & (a ^ ~1) is not optimized to 0 at the
gimplelevel
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: missed-optimization, TREE
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int f1(int a)
{
return (a ^ -2) & (a ^ 1);
}
int f2(int a, int b)
{
b = 1;
return (a ^ b) & (a ^ ~b);
}
int f3(int a, int b)
{
b = 1;
int t = a ^b;
int t1 = a ^ ~b;
return t & t1;
}
```
These all should be the same, GCC does optimize all to 0 but f1 and f3 is only
done on the RTL level.
This can be solved by improving bitwise_inverted_equal_p to see that `(a ^
CST)` and `(a ^ (~CST))` are inverse of each other.