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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-08-21
                 CC|                            |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Similar "bad" code for using 'unsigned int'.  With 'int' the reassoc
pass combines the repetitive checks to

  <bb 3> [local count: 840525100]:
  _8 = (unsigned int) _9;
  _15 = _8 <= 7;
  if (_15 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 532808861]:
  iftmp.1_6 = &in_3(D)->a;

  <bb 5> [local count: 1073741824]:
  # _1 = PHI <iftmp.1_6(4), 0B(2), 0B(3)>
  return _1;

with char or unsigned int it fails to do that which is because we are
testing different vars:


  <bb 3> [local count: 840525100]:
  i_36 = (int) _9;
  if (i_36 == 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 4> [local count: 420262550]:
  if (_9 == 0)
    goto <bb 5>; [71.00%]
  else
    goto <bb 19>; [29.00%]

  <bb 5> [local count: 532808861]:
  iftmp.1_6 = &in_3(D)->a;
  goto <bb 19>; [100.00%]

  <bb 6> [local count: 303654184]:
  if (i_36 == 1)
    goto <bb 7>; [67.33%]
  else
    goto <bb 8>; [32.67%]

  <bb 7> [local count: 182536110]:
  if (_9 == 1)
    goto <bb 5>; [43.66%]
  else
    goto <bb 19>; [56.34%]

same for char.  We're somehow not seeing the equivalence

  _9 = MEM[(unsigned int *)in_3(D) + 4B];
  i_36 = (int) _9;

when we know either is of a specific value.  Jump threading and/or CSE
should do this job.  Btw, the initial code is quite convoluted and needs
lot of threading to get to the above "nice" state.  EVRP figures out
the equivalencies but is confused by the initial

  <bb 2> :
  _24 = MEM[(unsigned int *)in_5(D) + 4B];
  if (_24 != 4294967295)
    goto <bb 3>; [78.28%]
  else
    goto <bb 4>; [21.72%]

  <bb 3> :
  iftmp.0_20 = (long long unsigned int) _24;

  <bb 4> :
  # iftmp.0_18 = PHI <18446744073709551615(2), iftmp.0_20(3)>
  i_7 = (int) iftmp.0_18;

which has to be jump-threaded away first with later

  <bb 35> :
  if (_24 != 4294967295)
    goto <bb 36>; [78.28%]
  else
    goto <bb 38>; [21.72%]

  <bb 36> :
  if (_24 == 6)
    goto <bb 37>; [55.78%]
  else
    goto <bb 38>; [44.22%]

  <bb 37> :

or alternatively the initial sequence needs to be phi-opted earlier.

In the end it appears to be a pass-ordering issue.

Reply via email to