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

            Bug ID: 107137
           Summary: (unsigned)-(int)(bool_var) should be optimized to
                    -(unsigned)bool_var
           Product: gcc
           Version: 12.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:
```
unsigned f(_Bool a)
{
  int t = a;
  t = -t;
  return t;
}
```

Currently we get:
```
  t_2 = (int) a_1(D);
  t_3 = -t_2;
  _4 = (unsigned int) t_3;
```

But we can do better than that with just:
```
  _ = (unsigned int) a_1(D);
  _4 = -_;
```
Noticed that while looking into
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107131.

Note even bool_var could be an unsigned type or a type which whos size is
bigger than the outer type really.

Reply via email to