https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125749
Bug ID: 125749
Summary: `MAX<a,b> == 0` -> (A|B) == 0 should happen for signed
types if a and b are nonnegative
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: easyhack, 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:
```
int
f (unsigned short a, unsigned short b) {
int aa = a;
int bb = b;
int t = aa > bb ? aa : bb;
return t == 0;
}
unsigned
g (unsigned short a, unsigned short b) {
unsigned aa = a;
unsigned bb = b;
unsigned t = aa > bb ? aa : bb;
return t == 0;
}
```
These 2 functions should have the same code produce but currently f is not
optimized because the pattern:
```
(for cmp (eq ne)
(simplify
(cmp (max @0 @1) integer_zerop)
(if (TYPE_UNSIGNED (TREE_TYPE (@0)))
(with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
(cmp (bit_ior (convert:utype @0) (convert:utype @1))
{ build_zero_cst (utype); } )))))
```
Only checks TYPE_UNSIGNED rather than if @0 and @1 are both nonnegative.