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

            Bug ID: 128047
           Summary: `x != CST1 ? x + CST2 : CST3` match pattern could
                    handle the case where the `x+CST2` is `((convert)x) +
                    CST2`
           Product: gcc
           Version: 17.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: ---

The current pattern:
```
(for cnd (cond vec_cond)
 (simplify
  (cnd (ne @0 uniform_integer_cst_p@1)
       (plus@2 @0 uniform_integer_cst_p@3)
       uniform_integer_cst_p@4)
```

Does not handle:
```
unsigned f(signed a)
{
  return a ? ((unsigned)a) + 1 : 1;
}

signed f2(signed a)
{
  return a ? ((signed)a) + 1 : 1;
}

unsigned f1(signed a)
{
  if (a == 0)
    return 1;
  unsigned b = a;
  return b + 1;
}

```

Instead value_replacement handles these cases.

Reply via email to