[patch] invariant expressions in loop at depth zero
Sebastian Pop
sebpop@gmail.com
Fri Feb 29 18:02:00 GMT 2008
> This doesn't look right. It won't work for loop 0 then. Why does
> flow_bb_inside_loop_p return true for your case? This seems to be
> the place to fix it.
I'm calling expr_invariant_in_loop_p (loop_0, N) and N is defined in
bb_2 in loop0, so flow_bb_inside_loop_p (loop_0, bb_2) is returning true.
> why are you calling expr_invariant_in_loop_p for loop_0?
>
I could fix the problem in the caller, but I still don't understand
why expr_invariant_in_loop_p should not be called with loop_0.
Could I document and add an assert in expr_invariant_in_loop_p for
this case?
Index: tree-scalar-evolution.c
===================================================================
--- tree-scalar-evolution.c (revision 132763)
+++ tree-scalar-evolution.c (working copy)
@@ -1971,6 +1971,7 @@ instantiate_parameters_1 (struct loop *l
/* A parameter (or loop invariant and we do not want to include
evolutions in outer loops), nothing to do. */
if (!def_bb
+ || loop_depth (def_bb->loop_father) == 0
|| (!(flags & INSERT_SUPERLOOP_CHRECS)
&& !flow_bb_inside_loop_p (loop, def_bb)))
return chrec;
Index: tree-chrec.c
===================================================================
--- tree-chrec.c (revision 132763)
+++ tree-chrec.c (working copy)
@@ -948,8 +948,9 @@ evolution_function_is_invariant_rec_p (t
if (evolution_function_is_constant_p (chrec))
return true;
- if (TREE_CODE (chrec) == SSA_NAME
- && expr_invariant_in_loop_p (get_loop (loopnum), chrec))
+ if (TREE_CODE (chrec) == SSA_NAME
+ && (loopnum == 0
+ || expr_invariant_in_loop_p (get_loop (loopnum), chrec)))
return true;
if (TREE_CODE (chrec) == POLYNOMIAL_CHREC)
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c (revision 132763)
+++ tree-ssa-loop-ivopts.c (working copy)
@@ -1254,7 +1254,8 @@ find_interesting_uses_cond (struct ivopt
}
/* Returns true if expression EXPR is obviously invariant in LOOP,
- i.e. if all its operands are defined outside of the LOOP. */
+ i.e. if all its operands are defined outside of the LOOP. LOOP
+ should not be the function body. */
bool
expr_invariant_in_loop_p (struct loop *loop, tree expr)
@@ -1262,6 +1263,8 @@ expr_invariant_in_loop_p (struct loop *l
basic_block def_bb;
unsigned i, len;
+ gcc_assert (loop_depth (loop) > 0);
+
if (is_gimple_min_invariant (expr))
return true;
More information about the Gcc-patches
mailing list