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

            Bug ID: 113302
           Summary: `x == 1 ? 1 : (x == -1 ? -1 : 0)` should be optimized
                    to `((unsigned)t) + 1 <= 2 ? 0`
           Product: gcc
           Version: 14.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:
```
int f(int x)
{
  if (x == 1)
    return 1;
  if (x == -1)
    return -1;
  if (x == 0)
    return 0;
  return 0;
}
int g(int x)
{
  if (x == 1)
    return 1;
  if (x == -1)
    return -1;
  return 0;
}
```

These both should produce:
```
int h(int t)
{
  unsigned t1 = t;
  t1+=1;
  return t1<=2 ? t : 0;
}
```

Reply via email to