[patch] tree-ssa-dom.c: Fix tree-optimization/18694.

Jeffrey A Law law@redhat.com
Mon Dec 13 20:12:00 GMT 2004


On Thu, 2004-12-09 at 20:43 -0500, Kazu Hirata wrote:
> Hi,
> 
> Attached is a patch to fix PR 18694.
[ ... ]
Attached is the patch I actually checked in to fix PR18694.

As I mentioned Friday, there's a nice simple solution to this problem 
which doesn't hinder jump threading significantly.

Specifically we simply refuse to thread jumps if we have a PHI argument
which is set from a PHI_RESULT in the same block and the PHI argument is
not identical to the PHI result.

This is different from Kazu's patch in two significant ways.

First, Kazu's patch avoided creating equivalences and recording new
definitions.  It still tried to thread through the block with the
problematical PHI dependencies.  My patch disables threading through
such blocks.

Second, my match contains a better test to detect the problematical
PHIs and thus avoid over-pessimizing in cases where we have PHIs for
loop invariants.  ie  x_2 = phi (0, x_1, x_2);   Kazu's original
patch would flag the 3rd alternative as problematical when in fact
it causes no problems at all.

I'll also check in Kazu's reduced testcase momentarily.

Bootstrapped and regression tested on i686-pc-linux-gnu.


-------------- next part --------------
	* tree-ssa-dom.c (thread_across_edge): Do not thread jumps if a
	PHI argument is set from a PHI_RESULT in the same block and the
	PHI argument is not the same as the PHI result.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.74
diff -c -p -r2.74 tree-ssa-dom.c
*** tree-ssa-dom.c	10 Dec 2004 17:58:07 -0000	2.74
--- tree-ssa-dom.c	13 Dec 2004 19:59:26 -0000
*************** thread_across_edge (struct dom_walk_data
*** 550,555 ****
--- 550,565 ----
      {
        tree src = PHI_ARG_DEF_FROM_EDGE (phi, e);
        tree dst = PHI_RESULT (phi);
+ 
+       /* If the desired argument is not the same as this PHI's result 
+ 	 and it is set by a PHI in this block, then we can not thread
+ 	 through this block.  */
+       if (src != dst
+ 	  && TREE_CODE (src) == SSA_NAME
+ 	  && TREE_CODE (SSA_NAME_DEF_STMT (src)) == PHI_NODE
+ 	  && bb_for_stmt (SSA_NAME_DEF_STMT (src)) == e->dest)
+ 	return;
+ 
        record_const_or_copy (dst, src);
        register_new_def (dst, &block_defs_stack);
      }


More information about the Gcc-patches mailing list