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

            Bug ID: 111431
           Summary: a & (a == 0) is not optimized to 0
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, xfail
          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
foo (int a)
{
  int b = !a;
  return (a & b);
}
```
The general rule is:
(a == CST) & a
transform into:
(CST & 1) ? (a == CST) : 0

So
(simplify
 (bit_and:c (convert@2 (eq @0 INTEGER_CST@1)) @0)
 (if ((wi::to_wide (@1) & 1) != 0)
  @2
  { build_zero_cst (type); }))

Reply via email to