https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110287

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
With patch in PR110289 to optimize the std::max int MAX_EXPR and the throw
commented out I get:

size_type std::vector<std::pair<unsigned int, unsigned int> >::_M_check_len
(const struct vector * const this, size_type __n, const char * __s)
{
  const size_type __len;
  size_type iftmp.2_1;
  long unsigned int _2;
  long unsigned int _5;
  long unsigned int _7;
  struct pair * _8;
  struct pair * _9;
  long int _10;
  long int _11;
  long unsigned int _12;

  <bb 2> [local count: 1073741824]:
  _8 = this_4(D)->D.26707._M_impl.D.26014._M_finish;
  _9 = this_4(D)->D.26707._M_impl.D.26014._M_start;
  _10 = _8 - _9;
  _11 = _10 /[ex] 8;
  _12 = (long unsigned int) _11;
  _7 = __n;
  _5 = MAX_EXPR <_7, _12>;
  __len_6 = _5 + _12;
  if (__len_6 < _12)
    goto <bb 4>; [35.00%]
  else
    goto <bb 3>; [65.00%]

  <bb 3> [local count: 697932185]:
  _2 = MIN_EXPR <__len_6, 1152921504606846975>;

  <bb 4> [local count: 1073741824]:
  # iftmp.2_1 = PHI <1152921504606846975(2), _2(3)>
  return iftmp.2_1;

}

which fits early inlining limits. So modifying libstdc++ to avoid the throw
would be great.

Again optimized _M_check_len could avoid:
  <bb 3> [local count: 697932185]:
  _2 = MIN_EXPR <__len_6, 1152921504606846975>;

  <bb 4> [local count: 1073741824]:
  # iftmp.2_1 = PHI <1152921504606846975(2), _2(3)>
  return iftmp.2_1;

since __len can not get that large without running out of memory. Which would
help further inlining.

Testcase from PR109849 now runs in 0.39s while without these two changes it
runs in 0.528s, clang's build runs in 0.057s, so still a long way to go.

Reply via email to