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

            Bug ID: 101703
           Summary: (bool0 + bool1) & 1 and (bool0 + bool1) == 1 can be
                    optimized to bool0 ^ bool1
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
bool f(bool a, bool b)
{
    int t = a;
    int t1 = b;
    return (t + t1) & 1;
}
bool fa(bool a, bool b)
{
    int t = a;
    int t1 = b;
    return (t + t1)==1;
}
bool fb(bool a, bool b)
{
    return a!=b;
}
bool fc(bool a, bool b)
{
    return a^b;
}

These three should produce the same code gen.  Right now fb and fc do but f and
fa needs to handled.

the for fa, == 1 can be converted into & 1 as the range is [0,2]:
  # RANGE [0, 2] NONZERO 3
  _1 = t_3 + t1_5;
  _6 = _1 == 1;

and only 1 can be if & 1 is true. And the rest just follows through.

Reply via email to