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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the missed optimization was there in GCC 12, just the diagnostic was not.

We have:
```
  _4 = MEM[(const unsigned char * const &)current_frame__2(D) + 24];
  _7 = MEM[(const unsigned char * const &)current_frame__2(D) + 16];
  if (_4 == _7)
    goto <bb 3>; [17.43%]
  else
    goto <bb 6>; [82.57%]

  <bb 3> [local count: 187153200]:
...
  MEM <vector(2) long unsigned int> [(unsigned char * *)_5(D) + 16B] = { 0, 0
};
  MEM[(struct _Vector_base *)_5(D) + 16B]._M_impl.D.21112._M_end_of_storage =
0B;
  _21 = MEM[(const unsigned char * const &)current_frame__2(D) + 24];
  _22 = MEM[(const unsigned char * const &)current_frame__2(D) + 16];
  _Num_23 = _21 - _22;
```

But based on the original condition (and the stores to offset of _5 [which
technically cannot alias current_frame__2]), _Num_23 will be 0.

What g:822a11a1e642e0abe92a996e7033a5066905a447 does is just add an extra if
statement where we get:
```
  if (_Num_24 > 1)
    goto <bb 4>; [90.00%]
  else
    goto <bb 5>; [10.00%]

  <bb 4> [local count: 156478790]:
  _Num.5_28 = (long unsigned int) _Num_24;
  __builtin_memmove (0B, _22, _Num.5_28);
  goto <bb 7>; [100.00%]

  <bb 5> [local count: 17386533]:
  if (_Num_24 == 1)
    goto <bb 6>; [34.00%]
  else
    goto <bb 7>; [66.00%]

  <bb 6> [local count: 5911421]:
  MEM[(unsigned char *)0B] ={v} 0; /// <<<<<< This is causing the warning
  __builtin_trap ();
```

Instead of just:
```
  if (_Num_23 != 0)
    goto <bb 4>; [33.00%]
  else
    goto <bb 5>; [67.00%]

  <bb 4> [local count: 57375556]:
  _Num.4_24 = (long unsigned int) _Num_23;
  __builtin_memmove (0B, _22, _Num.4_24);

```

Reply via email to