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

            Bug ID: 116890
           Summary: Heurstic for factoring out convert with one side
                    constant should also handle when it is a CMP
           Product: gcc
           Version: 15.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 f(int a, int b, int c)
{
  int x;
  if (c) x = a == 0;
  else x = 0;
  return x;
}

int f1(int a, int b, int c)
{
  int x;
  return (c != 0) && (a == 0);
}
```

This 2 should produce the same code. But currently we don't because we don't
factor out the convert:
```
  <bb 2> :
  if (c_3(D) != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  _1 = a_5(D) == 0;
  x_6 = (int) _1;

  <bb 4> :
  # x_2 = PHI <x_6(3), 0(2)>
```

This is because right now we only allow:
                  enum tree_code ass_code
                    = gimple_assign_rhs_code (assign);
                  if (ass_code != MAX_EXPR && ass_code != MIN_EXPR)
                    return NULL;

But comparison should be allowed too.

Reply via email to