https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114538
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Severity|normal |enhancement
Last reconfirmed| |2024-04-01
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this can be expanded into non-CST even.
```
int unopt(unsigned v, unsigned t) {
unsigned n = v + t;
return (n < t) == (n < v);
}
int opt1(unsigned v, unsigned t) {
return (v + t < t) == (v + t < v);
}
```
Both are not optimized to 1.
In both cases, it is checking if `v+t` wraps (overflows).
Interesting is LLVM is not able to handle the non-CST form either.
That is it is able to handle:
```
int g(unsigned v, unsigned t) {
t = 555;
return (v + t < t) == (v + t < v);
}
```
Note the const form case is related to PR 114539 really which LLVM can handle
both cases.