This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [lno] some cleanups for scev
This fixes some cases of the scev testsuite. Basically this patch
avoids to fail on chrec_top when a variable is defined in a loop that
is not included in the varying loop.
Bootstrapped on amd64-unknown-freebsd5.2
* tree-chrec.c (chrec_apply): Fail on chrec_top when the chrec
contains symbols defined in the inner loop. Otherwise perform
the computation with symbols.
(no_evolution_in_loop_p): Same. Moved from here...
* tree-chrec.h (no_evolution_in_loop_p): ...there. Define it inline.
(chrec_contains_symbols_defined_in_loop): Declare.
* tree-scalar-evolution.c (nb_set_scev, nb_get_scev): New counters.
(set_scalar_evolution, get_scalar_evolution): Count the number of calls.
(chrec_contains_symbols_defined_in_loop): Defined.
(compute_scalar_evolution_after_loop, first_iteration_non_satisfying_1,
analyze_scalar_evolution_in_loop): Initialize boolean values.
(dump_chrecs_stats): Dump the get/set counters.
Index: tree-chrec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-chrec.c,v
retrieving revision 1.1.2.17
diff -d -u -p -r1.1.2.17 tree-chrec.c
--- tree-chrec.c 20 Apr 2004 16:25:58 -0000 1.1.2.17
+++ tree-chrec.c 21 Apr 2004 17:01:36 -0000
@@ -1206,7 +1206,11 @@ chrec_apply (unsigned var,
if (automatically_generated_chrec_p (chrec)
|| automatically_generated_chrec_p (x)
- || chrec_contains_symbols (chrec)
+
+ /* When the symbols are defined in an outer loop, it is possible
+ to symbolically compute the apply, since the symbols are
+ constants with respect to the varying loop. */
+ || chrec_contains_symbols_defined_in_loop (chrec, var)
|| chrec_contains_symbols (x))
return chrec_top;
@@ -1721,27 +1725,6 @@ is_pure_sum_chrec (tree chrec)
return (is_pure_sum_chrec (CHREC_LEFT (chrec))
&& is_pure_sum_chrec (CHREC_RIGHT (chrec)));
- return true;
-}
-
-/* Determines whether CHREC is a loop invariant wrt. LOOP_NUM. Set
- the result in RES and return true when the property can be computed. */
-
-bool
-no_evolution_in_loop_p (tree chrec,
- unsigned loop_num,
- bool *res)
-{
- tree scev;
-
- if (chrec == chrec_not_analyzed_yet
- || chrec == chrec_top
- || chrec_contains_symbols (chrec))
- return false;
-
- scev = hide_evolution_in_other_loops_than_loop (chrec, loop_num);
- *res = (TREE_CODE (scev) != POLYNOMIAL_CHREC
- && TREE_CODE (scev) != EXPONENTIAL_CHREC);
return true;
}
Index: tree-chrec.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-chrec.h,v
retrieving revision 1.1.2.13
diff -d -u -p -r1.1.2.13 tree-chrec.h
--- tree-chrec.h 20 Apr 2004 15:13:15 -0000 1.1.2.13
+++ tree-chrec.h 21 Apr 2004 17:01:36 -0000
@@ -99,9 +99,9 @@ extern tree chrec_fold_automatically_gen
/* Observers. */
extern bool is_multivariate_chrec (tree);
extern bool is_pure_sum_chrec (tree);
-extern bool no_evolution_in_loop_p (tree, unsigned, bool *);
extern bool chrec_is_positive (tree, bool *);
extern bool chrec_contains_symbols (tree);
+extern bool chrec_contains_symbols_defined_in_loop (tree, unsigned);
extern bool chrec_contains_undetermined (tree);
extern bool chrec_contains_intervals (tree);
extern bool tree_contains_chrecs (tree);
@@ -328,6 +328,25 @@ static inline bool
tree_does_not_contain_chrecs (tree expr)
{
return !tree_contains_chrecs (expr);
+}
+
+/* Determines whether CHREC is a loop invariant with respect to LOOP_NUM.
+ Set the result in RES and return true when the property can be computed. */
+
+static inline bool
+no_evolution_in_loop_p (tree chrec, unsigned loop_num, bool *res)
+{
+ tree scev;
+
+ if (chrec == chrec_not_analyzed_yet
+ || chrec == chrec_top
+ || chrec_contains_symbols_defined_in_loop (chrec, loop_num))
+ return false;
+
+ scev = hide_evolution_in_other_loops_than_loop (chrec, loop_num);
+ *res = (TREE_CODE (scev) != POLYNOMIAL_CHREC
+ && TREE_CODE (scev) != EXPONENTIAL_CHREC);
+ return true;
}
#endif /* GCC_TREE_CHREC_H */
Index: tree-scalar-evolution.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-scalar-evolution.c,v
retrieving revision 1.1.2.37
diff -d -u -p -r1.1.2.37 tree-scalar-evolution.c
--- tree-scalar-evolution.c 21 Apr 2004 11:59:12 -0000 1.1.2.37
+++ tree-scalar-evolution.c 21 Apr 2004 17:01:36 -0000
@@ -273,6 +273,10 @@ struct scev_info_str
tree chrec;
};
+/* Counters for the scev database. */
+static unsigned nb_set_scev = 0;
+static unsigned nb_get_scev = 0;
+
/* The following trees are unique elements. Thus the comparison of
another element to these elements should be done on the pointer to
these trees, and not on their value. */
@@ -334,6 +338,60 @@ find_var_scev_info (tree var)
return &res->chrec;
}
+/* Determines whether the chrec contains symbolic names defined in
+ LOOP_NB. */
+
+bool
+chrec_contains_symbols_defined_in_loop (tree chrec, unsigned loop_nb)
+{
+ if (chrec == NULL_TREE)
+ return false;
+
+ if (TREE_CODE (chrec) == VAR_DECL
+ || TREE_CODE (chrec) == PARM_DECL
+ || TREE_CODE (chrec) == FUNCTION_DECL
+ || TREE_CODE (chrec) == LABEL_DECL
+ || TREE_CODE (chrec) == RESULT_DECL
+ || TREE_CODE (chrec) == FIELD_DECL)
+ return true;
+
+ if (TREE_CODE (chrec) == SSA_NAME)
+ {
+ tree def = SSA_NAME_DEF_STMT (chrec);
+ struct loop *def_loop = loop_of_stmt (def);
+ struct loop *loop = loop_from_num (current_loops, loop_nb);
+
+ if (def_loop == NULL)
+ return false;
+
+ if (flow_loop_nested_p (loop, def_loop))
+ return true;
+
+ return false;
+ }
+
+ switch (TREE_CODE_LENGTH (TREE_CODE (chrec)))
+ {
+ case 3:
+ if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (chrec, 2),
+ loop_nb))
+ return true;
+
+ case 2:
+ if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (chrec, 1),
+ loop_nb))
+ return true;
+
+ case 1:
+ if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (chrec, 0),
+ loop_nb))
+ return true;
+
+ default:
+ return false;
+ }
+}
+
/* This section contains the interface to the SSA IR. */
@@ -388,7 +446,7 @@ loop_phi_node_p (tree phi)
static tree
compute_scalar_evolution_after_loop (struct loop *loop, tree evolution_fn)
{
- bool val;
+ bool val = false;
if (evolution_fn == chrec_top)
return chrec_top;
@@ -519,14 +577,19 @@ set_scalar_evolution (tree scalar, tree
{
tree *scalar_info = find_var_scev_info (scalar);
- if (dump_file && (dump_flags & TDF_DETAILS))
+ if (dump_file)
{
- fprintf (dump_file, "(set_scalar_evolution \n");
- fprintf (dump_file, " (scalar = ");
- print_generic_expr (dump_file, scalar, 0);
- fprintf (dump_file, ")\n (scalar_evolution = ");
- print_generic_expr (dump_file, chrec, 0);
- fprintf (dump_file, "))\n");
+ if (dump_flags & TDF_DETAILS)
+ {
+ fprintf (dump_file, "(set_scalar_evolution \n");
+ fprintf (dump_file, " (scalar = ");
+ print_generic_expr (dump_file, scalar, 0);
+ fprintf (dump_file, ")\n (scalar_evolution = ");
+ print_generic_expr (dump_file, chrec, 0);
+ fprintf (dump_file, "))\n");
+ }
+ if (dump_flags & TDF_STATS)
+ nb_set_scev++;
}
*scalar_info = chrec;
@@ -539,12 +602,17 @@ get_scalar_evolution (tree scalar)
{
tree res;
- if (dump_file && (dump_flags & TDF_DETAILS))
+ if (dump_file)
{
- fprintf (dump_file, "(get_scalar_evolution \n");
- fprintf (dump_file, " (scalar = ");
- print_generic_expr (dump_file, scalar, 0);
- fprintf (dump_file, ")\n");
+ if (dump_flags & TDF_DETAILS)
+ {
+ fprintf (dump_file, "(get_scalar_evolution \n");
+ fprintf (dump_file, " (scalar = ");
+ print_generic_expr (dump_file, scalar, 0);
+ fprintf (dump_file, ")\n");
+ }
+ if (dump_flags & TDF_STATS)
+ nb_get_scev++;
}
switch (TREE_CODE (scalar))
@@ -1558,7 +1626,7 @@ first_iteration_non_satisfying_1 (enum t
tree chrec0,
tree chrec1)
{
- bool val;
+ bool val = false;
tree res, other_evs;
if (automatically_generated_chrec_p (chrec0)
@@ -2750,7 +2818,7 @@ tree
analyze_scalar_evolution_in_loop (struct loop *wrto_loop, struct loop *use_loop,
tree version)
{
- bool val;
+ bool val = false;
tree ev = version;
while (1)
@@ -3136,6 +3204,8 @@ dump_chrecs_stats (FILE *file, struct ch
fprintf (file, "-----------------------------------------\n");
fprintf (file, "%d\tchrecs in the scev database\n",
(int) VARRAY_ACTIVE_SIZE (scalar_evolution_info));
+ fprintf (file, "%d\tsets in the scev database\n", nb_set_scev);
+ fprintf (file, "%d\tgets in the scev database\n", nb_get_scev);
fprintf (file, "-----------------------------------------\n");
fprintf (file, ")\n\n");
}