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

            Bug ID: 127396
           Summary: Sat_Add/Sat_mult not detected for a*2 if we know that
                    `a >= 0` (using unsigned add/min)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
signed t1(unsigned a)
{
    if (a >= __INT_MAX__)
      __builtin_unreachable();
    unsigned t = a * 2;
    t = t > __INT_MAX__ ? __INT_MAX__ : t;
    return t;
}
```

This is a saturated signed multiply by 2 (or a saturated signed addition by
itself).  Since there is no negative side of "a", you don't need to take into
account saturating to the negative case.

Reply via email to