https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126029
Bug ID: 126029
Summary: `!bool_var + 1`, `2 - bool_var`, `1<<!a` all should
produce the same code
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, 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: ---
```
int f(_Bool a)
{
return !a + 1;
}
int f1(_Bool a)
{
return 1 - a + 1;
}
int f2(_Bool a)
{
return 1<<!a;
}
int f3(_Bool a)
{
return (a?1:2);
}
```
These all should produce the same code. `2 - (int)bool_var` .
Also these two should produce the same code:
```
int g1(_Bool a)
{
return 1 + a;
}
int g2(_Bool a)
{
return 1<<a;
}
```
`1 + a` would be the best