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

            Bug ID: 126173
           Summary: Fold (X + C) + (Y & ~C) to X + (Y | C)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaelfandrew at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/j4K158bdv

With -O3, src should optimize to tgt:
```
#define C 10

long
src (long X, long Y)
{
  return (X + C) + (Y & ~C);
}

long
tgt (long X, long Y)
{
  return (X + (Y | C));
}
```

Since `Y & ~C` clears all bits set in C, adding C cannot generate carry
through those bits and is equivalent to setting them with `or`.

Reply via email to