> > OK, I see.  Then the only way out I can think of is to stop going up the
> > chain of COMPONENT_REFs as soon as the offset becomes negative.
>
> Yeah, that sounds like a better solution.

Bootstrapped on MIPS/IRIX and regtested on {i586,x86_64}-suse-linux.  OK after 
a full testing cycle?

2012-01-04  Eric Botcazou  <ebotca...@adacore.com>

        PR tree-optimization/51624
        * tree-sra.c (build_ref_for_model): When replicating a chain of
        COMPONENT_REFs, stop as soon as the offset would become negative.


-- 
Eric Botcazou
Index: tree-sra.c
===================================================================
--- tree-sra.c	(revision 182784)
+++ tree-sra.c	(working copy)
@@ -1472,8 +1472,14 @@ build_ref_for_model (location_t loc, tre
 
       do {
 	tree field = TREE_OPERAND (expr, 1);
-	offset -= int_bit_position (field);
+	HOST_WIDE_INT bit_pos = int_bit_position (field);
 
+	/* We can be called with a model different from the one associated
+	   with BASE so we need to avoid going up the chain too far.  */
+	if (offset - bit_pos < 0)
+	  break;
+
+	offset -= bit_pos;
 	VEC_safe_push (tree, stack, cr_stack, expr);
 
 	expr = TREE_OPERAND (expr, 0);

Reply via email to