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

            Bug ID: 111487
           Summary: (a OP CST1) & (a == CST0) could be simplified down to
                    (CST OP CST1) & (a == CST0)
           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: ---

This is an extension of PR 111431 .

Take:
```
int g(int a)
{
        int b = a + 4;
        return (a == 0) & b;
}
```
This could be optimized down to just `return (a == 0);` as `(0+4)&1` is 1.
This can work with almost every binary (and even unary) operation that contains
a constant.

Reply via email to