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

--- Comment #7 from Andrew Macleod <amacleod at redhat dot com> ---
Created attachment 49607
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49607&action=edit
tweak testcase

The fix for PR 93781 changed the order of some evaluations in the testcase.

the problem is that we have
  [-1,-1] >> VARYING
This use to overflow in the cross product code and just return VARYING.
now that its being masked to
 [-1,-1] >> [0,31]

so in the end, the rshift cross product code decides the result is [-1, -1] 
instead of varying.

THis ends up changing the calculations, and we realized certain other parts of
the program are unreachable sooner..
we eventually figure out all the same things, but the problem now is that the
first statement evaluated:
xe_3 = PHI <0(2), xe_11(5)>
which we now dont determine xe_11 is 0 right off the bat like we use to.


THe final IL does look like:
  <bb 2> :
  goto <bb 6>; [INV]

  <bb 3> :
  ui_8 = ~xe_3;
  if (ui_8 == 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :

  <bb 5> :
  # ui_4 = PHI <ui_8(3), -1(4)>

  <bb 6> :
  # xe_3 = PHI <0(2), 0(5)>
  if (xe_3 <= 0)
    goto <bb 3>; [INV]
  else
    goto <bb 7>; [INV]

  <bb 7> :
  # xe_5 = PHI <xe_3(6)>
  return xe_5;

The problem is we now don't fold away the PHI:
# ui_4 = PHI <ui_8(3), -1(4)>
because although the code looks obvious that ui_8 must be 0 on the edge 3->5,
ranger has determined that xe_3 must be 0 feeding into this block, which means
ui_8 must be -1, which means the TRUE edge can never be taken, and therefore
ui_8 is actually undefined  on this edge.
THe stmt fold routine only looks for constant values in phi arguements, and
thus cannot fold away the PHI anymore since there isnt a constant value on the
edge.

All the same things will fold away here, but the undefined bit is preventing it
from happening within EVRP.
THe next pass of CCP does turn this into:
  <bb 2> [local count: 10631108]:

  <bb 3> [local count: 1073741824]:
  goto <bb 3>; [100.00%]


SO for now at least,  I'll just change the testcase to confirm its down to a
single goto by this pass.

Ideally we'd be able to detect the undefined during statement folding and allow
it to  match with any other constants.. much like we do with undefined local
values.

Reply via email to