https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127915
Bug ID: 127915
Summary: When `a <= b` and `b <= CST` then `b - a` is known to
have a range of [0, CST] (for unsigned)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 85316, 127913
Target Milestone: ---
Take:
```
tyepdef unsigned U;
void f(U first, U last)
{
if (first > last || last > 100)
__builtin_unreachable();
U t = last - first;
if (t > 100)
__builtin_trap ();
}
```
The range of t should be [0, 100] also. But we don't currently get that range:
# RANGE [irange] U [0, 100][4294967196, +INF]
t_6 = last_5(D) - first_4(D);
Also the `[0, 100][4294967196, +INF]` range is only picked up by DOM2 and not
by evrp.
Oh and it seems like we don't get `[0, 100]` range for first either.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127913
[Bug 127913] Unnecessary 128-bit arithmetic in ranges::lower_bound over a
bounded iota_view