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

            Bug ID: 117222
           Summary: [15 regression] Missed optimization with with
                    std::vector resize in loop
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

Created attachment 59391
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59391&action=edit
test.cxx

Noticed this when looking at PR80641.

At -O3, we do so much better in GCC 14.2 than we do on trunk
(https://godbolt.org/z/6jeoxKxTq).

With 14, we have which is optimal:
```
;; Function main (main, funcdef_no=1275, decl_uid=24945, cgraph_uid=152,
symbol_order=168) (executed once)

int main ()
{
  int * _53;

  <bb 2> [local count: 114863531]:
  _53 = operator new (16);
  MEM <uint128_t> [(char * {ref-all})_53] = 0x30000000200000001;
  operator delete (_53, 16);
  return 0;

}
```

With trunk, we have:
```

;; Function main (main, funcdef_no=1267, decl_uid=24700, cgraph_uid=153,
symbol_order=169) (executed once)

int main ()
{
  void * D.28023;
  int * _1;
  long int _10;
  int pretmp_17;
  void * _26;
  int * _48;
  int * _53;
  int * _61;
  long unsigned int _149;
  long unsigned int _156;

  <bb 2> [local count: 114863530]:
  _53 = operator new (16);
  MEM <uint128_t> [(char * {ref-all})_53] = 0x30000000200000001;
  _48 = _53 + 16;
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 906139990]:
  pretmp_17 = MEM[(value_type &)_61 + 18446744073709551612];
  if (pretmp_17 == 0)
    goto <bb 4>; [93.80%]
  else
    goto <bb 7>; [6.20%]

  <bb 4> [local count: 958878295]:
  # _1 = PHI <_61(3), _48(2)>
  _10 = _1 - _53;
  if (_10 == 0)
    goto <bb 5>; [33.00%]
  else
    goto <bb 6>; [67.00%]

  <bb 5> [local count: 316429836]:
  std::__throw_length_error ("vector::_M_default_append");

  <bb 6> [local count: 958878296]:
  _156 = (long unsigned int) _10;
  _149 = _156 + 18446744073709551612;
  _61 = _53 + _149;
  if (_53 != _61)
    goto <bb 3>; [94.50%]
  else
    goto <bb 7>; [5.50%]

  <bb 7> [local count: 114863531]:
  operator delete (_53, 16);
  return 0;

  <bb 8> [count: 0]:
<L12>:
  operator delete (_53, 16);
  _26 = __builtin_eh_pointer (6);
  __builtin_unwind_resume (_26);

}
```

Reply via email to