https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110287
Jan Hubicka <hubicka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2023-11-21 --- Comment #10 from Jan Hubicka <hubicka at gcc dot gnu.org> --- We now produce reasonable code for _M_check_len and propagate value range of the return value. This helps us to notice that later allocator call will not throw exception on invalid size, so we are down from 3 throw calls to one. Current code is: size_type std::vector<pair_t>::_M_check_len (const struct vector * const this, size_type __n, const char * __s) { const size_type __len; long unsigned int _1; long unsigned int __n.3_2; size_type iftmp.4_3; long unsigned int _4; long unsigned int _7; long unsigned int _8; long int _9; long int _11; struct pair_t * _12; struct pair_t * _13; <bb 2> [local count: 1073741824]: _13 = this_6(D)->D.26060._M_impl.D.25361._M_finish; _12 = this_6(D)->D.26060._M_impl.D.25361._M_start; _11 = _13 - _12; _9 = _11 /[ex] 8; _7 = (long unsigned int) _9; _1 = 1152921504606846975 - _7; __n.3_2 = __n; if (_1 < __n.3_2) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: std::__throw_length_error (__s_14(D)); <bb 4> [local count: 1073741824]: _8 = MAX_EXPR <__n.3_2, _7>; __len_10 = _7 + _8; if (_7 > __len_10) goto <bb 6>; [35.00%] else goto <bb 5>; [65.00%] <bb 5> [local count: 697932184]: _4 = MIN_EXPR <__len_10, 1152921504606846975>; <bb 6> [local count: 1073741824]: # iftmp.4_3 = PHI <1152921504606846975(4), _4(5)> return iftmp.4_3; } I still think we could play games with the 2^63 being too large for the standard allocator and turn __throw_length_error into __builtin_unreachable for that case. This would help early inliner to inline this function and save some throw calls in real code.