https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125756
Bug ID: 125756
Summary: nonnegative < (typeof nonnegative)(nonnegative != 0)
is false
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: easyhack, 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:
```
bool f1(unsigned short aa)
{
int a = aa;
bool t = a != 0;
int tu = t;
return a < tu;
}
bool f(unsigned short a)
{
bool t = a != 0;
unsigned short tu = t;
return a < tu;
}
```
These both should just be optimized to 0 but currently is not due to this
pattern:
```
(simplify
(lt:c @0 (convert (ne @0 integer_zerop)))
(if (TYPE_UNSIGNED (TREE_TYPE (@0)))
{ constant_boolean_node (false, type); }))
```
Only checking TYPE_UNSIGNED rather than checking if @0 is nonnegative.