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

--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> ---
I figured running ranger as VRP2 would fix this... but alas, there is some
interference :-)

After fre5:
  <bb 4> [local count: 118111600]:
  # prephitmp_24 = PHI <1(3), 4(2)>
  d.5_16 = d;
  if (d.5_16 <= 0)
    goto <bb 5>; [89.00%]
  else
    goto <bb 6>; [11.00%]

  <bb 5> [local count: 955630225]:
  d = 1;

  <bb 6> [local count: 118111600]:
  # e_4 = PHI <prephitmp_24(5), e_17(D)(4)>
  if (e_4 == 0)
    goto <bb 7>; [33.00%]
  else
    goto <bb 8>; [67.00%]

  <bb 7> [local count: 38976828]:
  foo ();

We know prephitmp_24 is [1,1] [4,4], and e_17 is undefined on 4->6, so ranger
will evaluate that PHI as [1,1], [4,4] and fold the condition as never true.

Unfortuntely, the next opass is threasd2 and its decides to thread this,
producing:

 <bb 4> [local count: 118111600]:
  # prephitmp_24 = PHI <1(3), 4(2)>
  d.5_16 = d;
  if (d.5_16 <= 0)
    goto <bb 5>; [89.00%]
  else
    goto <bb 6>; [11.00%]

  <bb 5> [local count: 105119324]:
  d = 1;
  goto <bb 8>; [100.00%]

  <bb 6> [local count: 12992276]:
  # e_4 = PHI <e_17(D)(4)>
  if (e_4 == 0)
    goto <bb 7>; [66.33%]
  else
    goto <bb 8>; [33.67%]

  <bb 7> [local count: 38976828]:
  foo ();

  <bb 8> [local count: 118111600]:
  return 0;

now we have a condition if (e_4 == 0) and e_4 is UNDEFINED, and so ranger
leaves it alone.

Is there any pass that examines branches using undefined values and decides
which way to fold it is most profitable?  probably not.  

Running this with --param=vrp1-mode=ranger resolves the problem because we
don't introduce this situation before it's taken care of,a nd we fold the
condition based on the PHI.

Reply via email to