https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125010

            Bug ID: 125010
           Summary: `(a<<1)+2)|1` can be simplified to (a<<1)+3
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          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 f(int a, int b)
{
  a = a<<1;
  a+=2;
  a|=1;
  return a;
}
```

This can be simplified down to just:
```
int f(int a, int b)
{
  a = a<<1;
  a+=3;
  return a;
}
```
As the | is like an addition and there is no carry due to we know the bits are
zero.

I suspect we want this for both gimple and rtl.

Reply via email to