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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, the same reproduces with r_imin_imax as ptrdiff_t but the IL is a bit
more obvious:

<bb 2> [local count: 1073741824]:
_27 ={v} signed_value_source;
_4 = (unsigned long) _27;
_8 = _4 + 2147483648;
if (_8 > 4294967295)
  goto <bb 8>; [50.00%]
else
  goto <bb 3>; [50.00%]

<bb 3> [local count: 536870913]:
_30 = _27 + 1;
_28 = (sizetype) _30;
if (_4 <= 4611686018427387900)
  goto <bb 4>; [50.00%]
else
  goto <bb 5>; [50.00%]

<bb 5> [local count: 268435458]:
_12 = operator new [] (18446744073709551615);
__builtin_memcpy (_12, &MEM <const char[37]> [(void
*)"0123456789abcdefghijklmnopqrstuvwxyz" + 35B], 2);
sink (_12);
if (_28 <= 4611686018427387900)
  goto <bb 9>; [100.00%]
else
  goto <bb 7>; [0.00%]

<bb 9> [local count: 0]:
iftmp.2_37 = _28 * 2;
_39 = operator new [] (iftmp.2_37);
__builtin_memcpy (_39, &MEM <const char[37]> [(void
*)"0123456789abcdefghijklmnopqrstuvwxyz" + 34B], 3);

so we have (unsigned long)[int_min, int_max] > 4611686018427387900
&& (unsigned long)[int_min+1, int_max+1] <= 4611686018427387900 to
constrain _4.  I don't see how we can arrive at [0,0] for iftmp.2_37.

In fact if I put this into a separate testcase like

void __attribute__((noipa))
foo (long signed_value_source)
{
  unsigned long temu = signed_value_source;
  if (temu + 2147483648 > 4294967295)
    ;
  else
    {
     long tems = signed_value_source + 1;
     unsigned long temu2 = tems;
     if (temu > 4611686018427387900)
       if (temu2 <= 4611686018427387900)
         {
           unsigned long iftmp = temu2 * 2;
           if (iftmp == 0)
             __builtin_abort ();
         }
    }
}

then we optimize this to

  <bb 2> [local count: 1073741824]:
  temu_3 = (long unsigned int) signed_value_source_2(D);
  _1 = temu_3 + 2147483648;
  if (_1 > 4294967295)
    goto <bb 5>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870913]:
  if (signed_value_source_2(D) == -1)
    goto <bb 4>; [0.00%]
  else
    goto <bb 5>; [100.00%]

  <bb 4> [count: 0]:
  __builtin_abort ();

and the outer if doesn't change the inner range result.

Reply via email to