diff options
author | Sebastian Pop <sebastian.pop@amd.com> | 2010-05-28 18:42:15 +0000 |
---|---|---|
committer | Sebastian Pop <spop@gcc.gnu.org> | 2010-05-28 18:42:15 +0000 |
commit | 0a74c7586cbf24b875c05507e6861070e74ffb69 (patch) | |
tree | fd9dab29f46e485b9afc38a2e968d2b4f9bb77eb | |
parent | e7cb8957bf8709677b85ba17fa3f9231633aaede (diff) | |
download | gcc-0a74c7586cbf24b875c05507e6861070e74ffb69.zip gcc-0a74c7586cbf24b875c05507e6861070e74ffb69.tar.gz gcc-0a74c7586cbf24b875c05507e6861070e74ffb69.tar.bz2 |
When niter may be zero, return a COND_EXPR with the may_be_zero condition.
2010-05-28 Sebastian Pop <sebastian.pop@amd.com>
* tree-scalar-evolution.c (set_nb_iterations_in_loop): Inlined in the
only place it was called from.
(number_of_latch_executions): Do not return chrec_dont_know when the
may_be_zero is a runtime condition: instead, return a COND_EXPR
including the may_be_zero condition.
* cfgloop.h (struct loop): Add a note on COND_EXPRs to the comment
of nb_iterations.
* tree-ssa-loop-ivopts.c (contains_abnormal_ssa_name_p): Handle
COND_EXPRs.
* gcc.dg/vect/vect-outer-fir-lb.c: Un-XFAIL-ed.
From-SVN: r159992
-rw-r--r-- | gcc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/cfgloop.h | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-outer-fir-lb.c | 14 | ||||
-rw-r--r-- | gcc/tree-scalar-evolution.c | 70 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ivopts.c | 5 |
6 files changed, 70 insertions, 49 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d2d4f2d..5b083fd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,17 @@ 2010-05-28 Sebastian Pop <sebastian.pop@amd.com> + * tree-scalar-evolution.c (set_nb_iterations_in_loop): Inlined in the + only place it was called from. + (number_of_latch_executions): Do not return chrec_dont_know when the + may_be_zero is a runtime condition: instead, return a COND_EXPR + including the may_be_zero condition. + * cfgloop.h (struct loop): Add a note on COND_EXPRs to the comment + of nb_iterations. + * tree-ssa-loop-ivopts.c (contains_abnormal_ssa_name_p): Handle + COND_EXPRs. + +2010-05-28 Sebastian Pop <sebastian.pop@amd.com> + * tree-if-conv.c (replace_phi_with_cond_gimple_assign_stmt): Don't generate COND_EXPRs for degenerate_phi_result. diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 96911c6..3821ee6 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -134,11 +134,13 @@ struct GTY ((chain_next ("%h.next"))) loop { /* Auxiliary info specific to a pass. */ PTR GTY ((skip (""))) aux; - /* The number of times the latch of the loop is executed. - This is an INTEGER_CST or an expression containing symbolic - names. Don't access this field directly: - number_of_latch_executions computes and caches the computed - information in this field. */ + /* The number of times the latch of the loop is executed. This can be an + INTEGER_CST, or a symbolic expression representing the number of + iterations like "N - 1", or a COND_EXPR containing the runtime + conditions under which the number of iterations is non zero. + + Don't access this field directly: number_of_latch_executions + computes and caches the computed information in this field. */ tree nb_iterations; /* An integer guaranteed to bound the number of iterations of the loop diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b41e4be..c5b13d6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-05-28 Sebastian Pop <sebastian.pop@amd.com> + + * gcc.dg/vect/vect-outer-fir-lb.c: Un-XFAIL-ed. + 2010-05-28 Mike Stump <mikestump@comcast.net> PR objc/44125 @@ -40,7 +44,7 @@ * obj-c++.dg/torture/tls/thr-init-2.mm: Ditto. * obj-c++.dg/torture/tls/thr-init-3.mm: Ditto. * obj-c++.dg/torture/trivial.mm: Ditto. - + 2010-05-27 Jack Howarth <howarth@bromo.med.uc.edu> * g++.dg/lto/20100302_0.C: Skip on darwin. diff --git a/gcc/testsuite/gcc.dg/vect/vect-outer-fir-lb.c b/gcc/testsuite/gcc.dg/vect/vect-outer-fir-lb.c index bdc07f9..3c1a362 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-outer-fir-lb.c +++ b/gcc/testsuite/gcc.dg/vect/vect-outer-fir-lb.c @@ -10,10 +10,7 @@ float coeff[M]; float out[N]; float fir_out[N]; -/* Should be vectorized. Fixed misaligment in the inner-loop. */ -/* Currently not vectorized because the loop-count for the inner-loop - has a maybe_zero component. Will be fixed when we incorporate the - "cond_expr in rhs" patch. */ +/* Vectorized. Fixed misaligment in the inner-loop. */ __attribute__ ((noinline)) void foo (){ int i,j,k; @@ -30,7 +27,7 @@ void foo (){ do { diff += in[j+i]*coeff[j]; - j+=4; + j+=4; } while (j < M); out[i] += diff; @@ -39,7 +36,7 @@ void foo (){ } -/* Vectorized. Changing misalignment in the inner-loop. */ +/* Vectorized. Changing misalignment in the inner-loop. */ __attribute__ ((noinline)) void fir (){ int i,j,k; @@ -68,7 +65,7 @@ int main (void) foo (); fir (); - + for (i = 0; i < N; i++) { if (out[i] != fir_out[i]) abort (); @@ -77,6 +74,5 @@ int main (void) return 0; } -/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 2 "vect" { xfail *-*-* } } } */ -/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 1 "vect" { xfail vect_no_align } } } */ +/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 2 "vect" { xfail vect_no_align } } } */ /* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index e2ed1f5..d50eac9 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -900,23 +900,6 @@ add_to_evolution (unsigned loop_nb, tree chrec_before, enum tree_code code, return res; } -/* Helper function. */ - -static inline tree -set_nb_iterations_in_loop (struct loop *loop, - tree res) -{ - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, " (set_nb_iterations_in_loop = "); - print_generic_expr (dump_file, res, 0); - fprintf (dump_file, "))\n"); - } - - loop->nb_iterations = res; - return res; -} - /* This section selects the loops that will be good candidates for the @@ -2685,8 +2668,11 @@ resolve_mixers (struct loop *loop, tree chrec) /* Entry point for the analysis of the number of iterations pass. This function tries to safely approximate the number of iterations the loop will run. When this property is not decidable at compile - time, the result is chrec_dont_know. Otherwise the result is - a scalar or a symbolic parameter. + time, the result is chrec_dont_know. Otherwise the result is a + scalar or a symbolic parameter. When the number of iterations may + be equal to zero and the property cannot be determined at compile + time, the result is a COND_EXPR that represents in a symbolic form + the conditions under which the number of iterations is not zero. Example of analysis: suppose that the loop has an exit condition: @@ -2705,37 +2691,53 @@ resolve_mixers (struct loop *loop, tree chrec) tree number_of_latch_executions (struct loop *loop) { - tree res, type; edge exit; struct tree_niter_desc niter_desc; + tree may_be_zero; + tree res; - /* Determine whether the number_of_iterations_in_loop has already + /* Determine whether the number of iterations in loop has already been computed. */ res = loop->nb_iterations; if (res) return res; - res = chrec_dont_know; + + may_be_zero = NULL_TREE; if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "(number_of_iterations_in_loop\n"); + fprintf (dump_file, "(number_of_iterations_in_loop = \n"); + res = chrec_dont_know; exit = single_exit (loop); - if (!exit) - goto end; - if (!number_of_iterations_exit (loop, exit, &niter_desc, false)) - goto end; + if (exit && number_of_iterations_exit (loop, exit, &niter_desc, false)) + { + may_be_zero = niter_desc.may_be_zero; + res = niter_desc.niter; + } + + if (res == chrec_dont_know + || !may_be_zero + || integer_zerop (may_be_zero)) + ; + else if (integer_nonzerop (may_be_zero)) + res = build_int_cst (TREE_TYPE (res), 0); - type = TREE_TYPE (niter_desc.niter); - if (integer_nonzerop (niter_desc.may_be_zero)) - res = build_int_cst (type, 0); - else if (integer_zerop (niter_desc.may_be_zero)) - res = niter_desc.niter; + else if (COMPARISON_CLASS_P (may_be_zero)) + res = fold_build3 (COND_EXPR, TREE_TYPE (res), may_be_zero, + build_int_cst (TREE_TYPE (res), 0), res); else res = chrec_dont_know; -end: - return set_nb_iterations_in_loop (loop, res); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, " (set_nb_iterations_in_loop = "); + print_generic_expr (dump_file, res, 0); + fprintf (dump_file, "))\n"); + } + + loop->nb_iterations = res; + return res; } /* Returns the number of executions of the exit condition of LOOP, diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 9592832..bda640f 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -681,6 +681,11 @@ contains_abnormal_ssa_name_p (tree expr) idx_contains_abnormal_ssa_name_p, NULL); + if (code == COND_EXPR) + return contains_abnormal_ssa_name_p (TREE_OPERAND (expr, 0)) + || contains_abnormal_ssa_name_p (TREE_OPERAND (expr, 1)) + || contains_abnormal_ssa_name_p (TREE_OPERAND (expr, 2)); + switch (codeclass) { case tcc_binary: |