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

            Bug ID: 111147
           Summary: bitwise_inverted_equal_p can be used in the `(x | y) &
                    (~x ^ y)` pattern to catch more
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int g(int x, int y)
{
  return (x | y) & (~x ^ y); // x & y
}
int g0(int x, int y)
{
  return (~x | y) & (x ^ y); // ~x & y
}
```

g is correctly optimized to `x & y` but g0 is not optimized to `~x & y` even
though it could be.

If this pattern used bitwise_inverted_equal_p it could be.

Note this could also be used to catch comparisons too.

Filing this not to lose this idea.

Reply via email to