diff mbox

Teach sccvn about constant vars

Message ID 20100907153609.GA12341@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Sept. 7, 2010, 3:36 p.m. UTC
Hi,
testing the patch together with fortran constructor fix uncovered two typos in the previous version
so newly computed index was not used at all.
Fixed thus.
Bootstrapped/regtested x86_64-linux with the fortran fix. OK?

Honza

> 	* tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound
> 	in string access folding.

Comments

Richard Biener Sept. 7, 2010, 3:45 p.m. UTC | #1
On Tue, 7 Sep 2010, Jan Hubicka wrote:

> Hi,
> testing the patch together with fortran constructor fix uncovered two typos in the previous version
> so newly computed index was not used at all.
> Fixed thus.
> Bootstrapped/regtested x86_64-linux with the fortran fix. OK?

Ok.

Thanks,
Richard.

> Honza
> 
> > 	* tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound
> > 	in string access folding.
> 
> Index: tree-ssa-ccp.c
> ===================================================================
> --- tree-ssa-ccp.c	(revision 163947)
> +++ tree-ssa-ccp.c	(working copy)
> @@ -1398,17 +1398,30 @@ fold_const_aggregate_ref (tree t)
>  	}
>  
>        /* Fold read from constant string.  */
> -      if (TREE_CODE (ctor) == STRING_CST)
> +      if (TREE_CODE (ctor) == STRING_CST
> +	  && TREE_CODE (idx) == INTEGER_CST)
>  	{
> +	  tree low_bound = array_ref_low_bound (t);
> +	  double_int low_bound_cst;
> +	  double_int index_cst;
> +	  double_int length_cst;
> +	  bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
> +
> +	  if (TREE_CODE (low_bound) != INTEGER_CST)
> +	    return NULL_TREE;
> +	  low_bound_cst = tree_to_double_int (low_bound);
> +	  index_cst = tree_to_double_int (idx);
> +	  length_cst = uhwi_to_double_int (TREE_STRING_LENGTH (ctor));
> +	  index_cst = double_int_sub (index_cst, low_bound_cst);
>  	  if ((TYPE_MODE (TREE_TYPE (t))
>  	       == TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
>  	      && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
>  	          == MODE_INT)
>  	      && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == 1
> -	      && compare_tree_int (idx, TREE_STRING_LENGTH (ctor)) < 0)
> +	      && double_int_cmp (index_cst, length_cst, signed_p) < 0)
>  	    return build_int_cst_type (TREE_TYPE (t),
>  				       (TREE_STRING_POINTER (ctor)
> -					[TREE_INT_CST_LOW (idx)]));
> +					[double_int_to_uhwi (index_cst)]));
>  	  return NULL_TREE;
>  	}
>  
> 
>
diff mbox

Patch

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 163947)
+++ tree-ssa-ccp.c	(working copy)
@@ -1398,17 +1398,30 @@  fold_const_aggregate_ref (tree t)
 	}
 
       /* Fold read from constant string.  */
-      if (TREE_CODE (ctor) == STRING_CST)
+      if (TREE_CODE (ctor) == STRING_CST
+	  && TREE_CODE (idx) == INTEGER_CST)
 	{
+	  tree low_bound = array_ref_low_bound (t);
+	  double_int low_bound_cst;
+	  double_int index_cst;
+	  double_int length_cst;
+	  bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
+
+	  if (TREE_CODE (low_bound) != INTEGER_CST)
+	    return NULL_TREE;
+	  low_bound_cst = tree_to_double_int (low_bound);
+	  index_cst = tree_to_double_int (idx);
+	  length_cst = uhwi_to_double_int (TREE_STRING_LENGTH (ctor));
+	  index_cst = double_int_sub (index_cst, low_bound_cst);
 	  if ((TYPE_MODE (TREE_TYPE (t))
 	       == TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
 	      && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
 	          == MODE_INT)
 	      && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == 1
-	      && compare_tree_int (idx, TREE_STRING_LENGTH (ctor)) < 0)
+	      && double_int_cmp (index_cst, length_cst, signed_p) < 0)
 	    return build_int_cst_type (TREE_TYPE (t),
 				       (TREE_STRING_POINTER (ctor)
-					[TREE_INT_CST_LOW (idx)]));
+					[double_int_to_uhwi (index_cst)]));
 	  return NULL_TREE;
 	}