https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128099
Bug ID: 128099
Summary: `((x & 1) == 0) && (x != CST)` where `CST&1 != 0` is
not simplified to just `((x & 1) == 0)`
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
Target Milestone: ---
Take:
```
#define C 3
int f(int x)
{
return ((x & 1) == 0) && (x != C);
}
int f1(int x)
{
return (x != C) && ((x & 1) == 0);
}
int f2(int x)
{
return (x != C) & ((x & 1) == 0);
}
int f3(int x)
{
return ((x & 1) == 0) & (x != C);
}
```
These all should be optimized to `((x & 1) == 0)` like f is currently.
Note the IOR case is: `(x == C) | ((x & 1) != 0)`. which should be handled too.
Note this is related to https://github.com/llvm/llvm-project/issues/234717 (but
LLVM gets the odd one while the llvm linked issue is about the even). Note
also for aarch64 (and targets which have condition compares), using the ccmp
form is better.