This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tree-ssa] Latent out-of-ssa bug

While working on improvements to the jump threading code I ran across
this latent but in the out-of-ssa code.

If the result of a PHI is unused(*), then no conflicts are created for the
PHI's result in the conflict graph.  This can cause the result of the PHI to
end up in a partition where it conflicts with other members.

You might think that if the PHI is not used then it shouldn't matter
if its conflicts with other members of its partition.  That is not true
since the PHI may still generate code -- if it does generate code then
we clobber the value of the partition with whatever value the PHI had.
Not good.

I haven't seen this without my changes to do more jump threading, but
I strongly believe it would simply be a matter of time before we tripped
over this problem, even without the more aggressive jump threading.

This patch fixes the problem by recording conflicts for such PHIs.

(*) We do not run DCE when the dominator optimizer indicates that we need
to re-rewrite some variables due to jump threading.  This is by far the
most common way to get a PHI with an unused result into the out-of-ssa

	* tree-ssa-live.c (build_tree_conflict_graph): Correctly handle
	case where the result of a PHI is unused.

Index: tree-ssa-live.c
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-live.c,v
retrieving revision
diff -c -p -r1.1.2.33 tree-ssa-live.c
*** tree-ssa-live.c	15 Dec 2003 22:58:35 -0000
--- tree-ssa-live.c	15 Jan 2004 15:01:52 -0000
*************** build_tree_conflict_graph (tree_live_inf
*** 1348,1353 ****
--- 1348,1354 ----
    FOR_EACH_BB (bb)
        block_stmt_iterator bsi;
+       tree phi;
        /* Start with live on exit temporaries.  */
        bitmap_copy (live, live_on_exit (liveinfo, bb));
*************** build_tree_conflict_graph (tree_live_inf
*** 1425,1430 ****
--- 1426,1445 ----
  		  set_if_valid (map, live, *var_p);
+ 	}
+       /* If result of a PHI is unused, then the loops over the statements
+ 	 will not record any conflicts.  However, since the PHI node is 
+ 	 going to be translated out of SSA form we must record a conflict
+ 	 between the result of the PHI and any variables with are live. 
+ 	 Otherwise the out-of-ssa translation may create incorrect code.  */
+       for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+ 	{
+ 	  tree result = PHI_RESULT (phi);
+ 	  int p = var_to_partition (map, result);
+ 	  if (p != NO_PARTITION && ! bitmap_bit_p (live, p))
+ 	    add_conflicts_if_valid (tpa, graph, map, live, result);
        /* Anything which is still live at this point interferes.  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]