https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125748
Bug ID: 125748
Summary: `MAX<a, a&CST>` -> `a` should happen even if a is a
signed type but 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;
aa++;
int bb = aa & 0xFF;
int t = aa > bb ? aa : bb;
return t;
}
unsigned
g (unsigned short a, unsigned short b) {
unsigned aa = a;
aa++;
unsigned bb = aa & 0xFF;
unsigned t = aa > bb ? aa : bb;
return t;
}
```
This 2 functions should produce the same code but currently does not since the
pattern:
```
(for minmax (min max)
(simplify
(minmax @0 (bit_and@1 @0 INTEGER_CST@2))
(if (TYPE_UNSIGNED(type))
(if (minmax == MIN_EXPR)
@1
@0))))
```
Only checks TYPE_UNSIGNED rather than @0 is nonnegative too.