------- Comment #17 from changpeng dot fang at amd dot com  2010-03-17 00:18 
-------
(In reply to comment #8)
> And
> 
> int foo (int b, int j)
> {
>   if (b)
>     {
>       int i;
>       for (i = 0; i<1000; ++i)
>         ;
>       j = b;
>     }
>   return j;
> }
> 

With "j=b", "b" is not folded as a phi argument: 

<bb 5>:
  # i_2 = PHI <0(3), i_6(4)>
  if (i_2 <= 999)
    goto <bb 4>;
  else
    goto <bb 6>;

<bb 6>:
  j_7 = b_3(D);

<bb 7>:
  # j_1 = PHI <j_4(D)(2), j_7(6)>

However, if "j=0", it is:
<bb 6>:
  j_7 = 0;

<bb 7>:
  # j_1 = PHI <j_4(D)(2), 0(6)>
  j_8 = j_1;
  return j_8;

Then copy propagation will remove "j_7 = 0" (and thus <bb 6>) because it has no
user.

So, one possible solution is "do not remove trival dead code" in
copy_propagation pass. Any dce pass will remove such code.

Of course, if we follow Steven's suggestion not use constants as phi arguments,
"j_7=0" will not be removed by constant propagation, and we are all fine.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42906

Reply via email to