https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128896
Bug ID: 128896
Summary: `a * (a + odd)` is always even
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: ---
Take:
```
unsigned f(unsigned a)
{
unsigned c = a*(a+1);
return c&1;
}
```
This should always be false as `a * (a+ODD)` is always an even number.
This helps with say:
```
int f_src(int a)
{
int c = a*(a+1);
return c/2;
}
```
As bit 0 is not set, you can change it to just:
```
int f_src(int a)
{
int c = a*(a+1);
return c>>1;
}
```
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases