From 33b30201b365982cf276cfa64e20985f0c81bc78 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebastian.pop@amd.com>
Date: Fri, 21 Dec 2007 16:28:48 +0000
Subject: [PATCH] tree-data-ref.c (signed_type_for_types): New.

2007-12-21  Sebastian Pop  <sebastian.pop@amd.com>

	* tree-data-ref.c (signed_type_for_types): New.
	(affine_fn_op): Use signed_type_for_types and signed_type_for instead
	of long_integer_type_node.
	(analyze_ziv_subscript): Same.
	(analyze_siv_subscript_cst_affine): Same.
	(analyze_miv_subscript): Same.
	(omega_setup_subscript): Same.

From-SVN: r131121
---
 gcc/ChangeLog       | 10 ++++++
 gcc/tree-data-ref.c | 80 +++++++++++++++++++++++++++------------------
 2 files changed, 59 insertions(+), 31 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6cec0bb9c687..fa163e35f6d6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2007-12-21  Sebastian Pop  <sebastian.pop@amd.com>
+
+	* tree-data-ref.c (signed_type_for_types): New.
+	(affine_fn_op): Use signed_type_for_types and signed_type_for instead
+	of long_integer_type_node.
+	(analyze_ziv_subscript): Same.
+	(analyze_siv_subscript_cst_affine): Same.
+	(analyze_miv_subscript): Same.
+	(omega_setup_subscript): Same.
+
 2007-12-21  Richard Sandiford  <rsandifo@nildram.co.uk>
 
 	* config/mips/mips.c (mips_emit_loadgp): Replace gen_* calls with
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 32a3197f8204..07b311a93fd6 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -935,6 +935,18 @@ affine_function_zero_p (affine_fn fn)
 	  && affine_function_constant_p (fn));
 }
 
+/* Returns a signed integer type with the largest precision from TA
+   and TB.  */
+
+static tree
+signed_type_for_types (tree ta, tree tb)
+{
+  if (TYPE_PRECISION (ta) > TYPE_PRECISION (tb))
+    return signed_type_for (ta);
+  else
+    return signed_type_for (tb);
+}
+
 /* Applies operation OP on affine functions FNA and FNB, and returns the
    result.  */
 
@@ -958,18 +970,23 @@ affine_fn_op (enum tree_code op, affine_fn fna, affine_fn fnb)
 
   ret = VEC_alloc (tree, heap, m);
   for (i = 0; i < n; i++)
-    VEC_quick_push (tree, ret,
-		    fold_build2 (op, long_integer_type_node,
-				 VEC_index (tree, fna, i), 
-				 VEC_index (tree, fnb, i)));
+    {
+      tree type = signed_type_for_types (TREE_TYPE (VEC_index (tree, fna, i)),
+					 TREE_TYPE (VEC_index (tree, fnb, i)));
+
+      VEC_quick_push (tree, ret,
+		      fold_build2 (op, type,
+				   VEC_index (tree, fna, i), 
+				   VEC_index (tree, fnb, i)));
+    }
 
   for (; VEC_iterate (tree, fna, i, coef); i++)
     VEC_quick_push (tree, ret,
-		    fold_build2 (op, long_integer_type_node,
+		    fold_build2 (op, signed_type_for (TREE_TYPE (coef)),
 				 coef, integer_zero_node));
   for (; VEC_iterate (tree, fnb, i, coef); i++)
     VEC_quick_push (tree, ret,
-		    fold_build2 (op, long_integer_type_node,
+		    fold_build2 (op, signed_type_for (TREE_TYPE (coef)),
 				 integer_zero_node, coef));
 
   return ret;
@@ -1484,15 +1501,16 @@ analyze_ziv_subscript (tree chrec_a,
 		       conflict_function **overlaps_b, 
 		       tree *last_conflicts)
 {
-  tree difference;
+  tree type, difference;
   dependence_stats.num_ziv++;
   
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "(analyze_ziv_subscript \n");
-  
-  chrec_a = chrec_convert (long_integer_type_node, chrec_a, NULL_TREE);
-  chrec_b = chrec_convert (long_integer_type_node, chrec_b, NULL_TREE);
-  difference = chrec_fold_minus (long_integer_type_node, chrec_a, chrec_b);
+
+  type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b));
+  chrec_a = chrec_convert (type, chrec_a, NULL_TREE);
+  chrec_b = chrec_convert (type, chrec_b, NULL_TREE);
+  difference = chrec_fold_minus (type, chrec_a, chrec_b);
   
   switch (TREE_CODE (difference))
     {
@@ -1618,12 +1636,12 @@ analyze_siv_subscript_cst_affine (tree chrec_a,
 				  tree *last_conflicts)
 {
   bool value0, value1, value2;
-  tree difference, tmp;
+  tree type, difference, tmp;
 
-  chrec_a = chrec_convert (long_integer_type_node, chrec_a, NULL_TREE);
-  chrec_b = chrec_convert (long_integer_type_node, chrec_b, NULL_TREE);
-  difference = chrec_fold_minus 
-    (long_integer_type_node, initial_condition (chrec_b), chrec_a);
+  type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b));
+  chrec_a = chrec_convert (type, chrec_a, NULL_TREE);
+  chrec_b = chrec_convert (type, chrec_b, NULL_TREE);
+  difference = chrec_fold_minus (type, initial_condition (chrec_b), chrec_a);
   
   if (!chrec_is_positive (initial_condition (difference), &value0))
     {
@@ -1666,10 +1684,8 @@ analyze_siv_subscript_cst_affine (tree chrec_a,
 		      struct loop *loop = get_chrec_loop (chrec_b);
 
 		      *overlaps_a = conflict_fn (1, affine_fn_cst (integer_zero_node));
-		      tmp = fold_build2 (EXACT_DIV_EXPR, long_integer_type_node,
-					 fold_build1 (ABS_EXPR,
-						      long_integer_type_node,
-						      difference),
+		      tmp = fold_build2 (EXACT_DIV_EXPR, type,
+					 fold_build1 (ABS_EXPR, type, difference),
 					 CHREC_RIGHT (chrec_b));
 		      *overlaps_b = conflict_fn (1, affine_fn_cst (tmp));
 		      *last_conflicts = integer_one_node;
@@ -1748,8 +1764,7 @@ analyze_siv_subscript_cst_affine (tree chrec_a,
 		      struct loop *loop = get_chrec_loop (chrec_b);
 
 		      *overlaps_a = conflict_fn (1, affine_fn_cst (integer_zero_node));
-		      tmp = fold_build2 (EXACT_DIV_EXPR,
-					 long_integer_type_node, difference, 
+		      tmp = fold_build2 (EXACT_DIV_EXPR, type, difference,
 					 CHREC_RIGHT (chrec_b));
 		      *overlaps_b = conflict_fn (1, affine_fn_cst (tmp));
 		      *last_conflicts = integer_one_node;
@@ -2445,14 +2460,16 @@ analyze_miv_subscript (tree chrec_a,
      variables.  In the MIV case we have to solve a Diophantine
      equation with 2*n variables (if the subscript uses n IVs).
   */
-  tree difference;
+  tree type, difference;
+
   dependence_stats.num_miv++;
   if (dump_file && (dump_flags & TDF_DETAILS))
     fprintf (dump_file, "(analyze_miv_subscript \n");
 
-  chrec_a = chrec_convert (long_integer_type_node, chrec_a, NULL_TREE);
-  chrec_b = chrec_convert (long_integer_type_node, chrec_b, NULL_TREE);
-  difference = chrec_fold_minus (long_integer_type_node, chrec_a, chrec_b);
+  type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b));
+  chrec_a = chrec_convert (type, chrec_a, NULL_TREE);
+  chrec_b = chrec_convert (type, chrec_b, NULL_TREE);
+  difference = chrec_fold_minus (type, chrec_a, chrec_b);
   
   if (eq_evolutions_p (chrec_a, chrec_b))
     {
@@ -3400,9 +3417,11 @@ omega_setup_subscript (tree access_fun_a, tree access_fun_b,
 		       omega_pb pb, bool *maybe_dependent)
 {
   int eq;
-  tree fun_a = chrec_convert (long_integer_type_node, access_fun_a, NULL_TREE);
-  tree fun_b = chrec_convert (long_integer_type_node, access_fun_b, NULL_TREE);
-  tree difference = chrec_fold_minus (long_integer_type_node, fun_a, fun_b);
+  tree type = signed_type_for_types (TREE_TYPE (access_fun_a),
+				     TREE_TYPE (access_fun_b));
+  tree fun_a = chrec_convert (type, access_fun_a, NULL_TREE);
+  tree fun_b = chrec_convert (type, access_fun_b, NULL_TREE);
+  tree difference = chrec_fold_minus (type, fun_a, fun_b);
 
   /* When the fun_a - fun_b is not constant, the dependence is not
      captured by the classic distance vector representation.  */
@@ -3417,8 +3436,7 @@ omega_setup_subscript (tree access_fun_a, tree access_fun_b,
       return true;
     }
 
-  fun_b = chrec_fold_multiply (long_integer_type_node, fun_b, 
-			       integer_minus_one_node);
+  fun_b = chrec_fold_multiply (type, fun_b, integer_minus_one_node);
 
   eq = omega_add_zero_eq (pb, omega_black);
   if (!init_omega_eq_with_af (pb, eq, DDR_NB_LOOPS (ddr), fun_a, ddr)
-- 
GitLab