https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127103
Bug ID: 127103
Summary: code from std::vector::push_back can be optimized away
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 85316
Target Milestone: ---
Take:
```
unsigned t1(unsigned a)
{
if (a >= __INT_MAX__)
__builtin_unreachable();
unsigned t = __INT_MAX__ - a;
unsigned t1 = 1;
unsigned ttt = a > 1 ? a : 1;
ttt = ttt < t ? ttt : t;
unsigned tt = ttt + a;
return ((signed)tt) < 0;
}
```
This should be optimized to false but currently is not.
This shows up from std::vector<int>::push_back (-m32 just so it is easier to
see):
```
# RANGE [irange] long unsigned int [0, 2147483647] MASK 0x7fffffff VALUE 0x0
_32 = (long unsigned int) __dif_31;
# RANGE [irange] const size_type [0, 2147483647] MASK 0x7fffffff VALUE 0x0
__room_33 = 2147483647 - _32;
if (__dif_31 == 2147483647)
goto <bb 5>; [0.00%]
else
goto <bb 6>; [100.00%]
<bb 5> [count: 0]:
# USE = nonlocal escaped const-pool
# CLB = nonlocal escaped const-pool
std::__throw_length_error ("vector::_M_realloc_append");
<bb 6> [local count: 187153200]:
# RANGE [irange] long unsigned int [1, 2147483646] MASK 0x7fffffff VALUE 0x0
_34 = MAX_EXPR <_32, 1>;
# RANGE [irange] long unsigned int [1, 2147483646] MASK 0x7fffffff VALUE 0x0
_35 = MIN_EXPR <__room_33, _34>;
# RANGE [irange] long unsigned int [1, 4294967292]
_36 = _32 + _35;
# RANGE [irange] signed int [-INF, -4][1, +INF]
__n.7_40 = (signed int) _36;
if (__n.7_40 < 0)
```
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases