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

            Bug ID: 122271
           Summary: `(b ? nonnull : null) != null` should be converted to
                    just `b`
           Product: gcc
           Version: 16.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(int *a)
{
  int b = *a;
  int *c;
  if (b != 0) c = a; else c = 0;
  return c != 0;
}


_Bool __GIMPLE g(int *a)
{
  int b;
  int *c;
  _Bool tt;

  b = *a;
  c = a;
  tt = b != 0;
  c = tt ? a : _Literal(void*)0;
  tt = c != _Literal(void*)0;
  return tt;
}
```

These 2 should be optimized to just `return *a != 0;` which f does at -O2 (due
to PRE).

Seems like something which phiopt could handle for f case at -O1. For g, maybe
vrp should handle it.

Reply via email to