https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127223
Bug ID: 127223
Summary: (int)unsigned0+(int)unsigned1 ->
(int)(unsigned0+unsigned1) if unsigned0+unsigned1 does
not overflow
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: ---
Take:
```
unsigned ff2(unsigned f, unsigned m)
{
unsigned char af = f;
unsigned char am = m;
int t = af+am;
return t;
}
```
Right now this produces this mess:
```
int t;
int _1;
int _2;
unsigned int _6;
unsigned int _8;
unsigned int _9;
_8 = f_3(D) & 255;
_1 = (int) _8;
_9 = m_4(D) & 255;
_2 = (int) _9;
t_5 = _1 + _2;
_6 = (unsigned int) t_5;
return _6;
```
But _1+_2 should be done in unsigned without losing any information. as _8+_9
will not overflow.