[Bug tree-optimization/14627] [4.0/4.1 regression] extra assignment inserted on the tree level

amacleod at redhat dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 21 15:57:00 GMT 2005

------- Additional Comments From amacleod at redhat dot com  2005-03-21 15:52 -------
Well, I dont think there is anything out of ssa should do here. a_1 and a_2 are
2 distinct live ranges, and should therefore be generated that way.  There isnt
much choice about the 2 assignments either. 

Perhaps the best thing would be a pass before out of ssa which does the opposite
of that DOM optimization. It goes through the program looking for these
equivilences, and replaces the constant with the variable its equivilent to.

  if (a_2 != 0) goto <L1>; else goto <L2>;
  # a_1 = PHI <0(1), 3(0)>;
  #   b_4 = V_MUST_DEF <b_3>;
  b = a_1;

the PHI could then be turned into:
  # a_1 = PHI <a_2(1), 3(0)>

which would result in code closer to what you are looking for. It would undo
anything that wasn't profitable, and we're likely to get better code in general
I would think. It would also take care of when that assignment to zero was
explcitly made instead of implicit. Simply disabling/handcuffing DOM or other
optimizations to prevent the situation wouldn't help then.

It would also get the original case:

  if (one_valid_9 == 0) goto <L4>; else goto <L6>; <L4>:;

  if (D.1132_16 != 0) goto <L6>; else goto <L23>; <L23>:;

  # one_valid_21 = PHI <one_valid_9(3), 0(5), 1(4)>;

It can tell that one_valid_9 is implicitly 0 from block 5, and change this back to :
  if (one_valid_9 == 0) goto <L4>; else goto <L6>; <L4>:;

  if (D.1132_16 != 0) goto <L6>; else goto <L23>; <L23>:;

  # one_valid_21 = PHI <one_valid_9(3), one_valid_9(5), 1(4)>;

Just what we need, more DOM eh :-) This is kinda anti-DOM :-)

We would simply be focusing on constants in the PHI arguments and looking to 
replace them, when possible, with an implicit value of an ssa version of the PHI
result.  There isnt much point to changing it to a different variable since you
will still get an assignment.  There also may not be much point in using an SSA
version which isnt already in the argument list of the PHI sometimes. You might
create a new overlapping live range, which could cause even more havoc.  So its
pretty specialized.  I would think it would be fairly quick.

Your other choice would be a post-ssa pass which works with memory variables and
tries to propagate copies around. It should be pretty trivial to replace the
output from your sample program to get:

<bb 0>:
  if (a != 0) goto <L3>; else goto <L2>;
  b = 3;
  goto <bb 2> (<L1>);
  b = 0;

It would, however, miss the original test cases problem.



More information about the Gcc-bugs mailing list