aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRazya Ladelsky <razya@il.ibm.com>2011-07-05 13:08:01 +0000
committerRazya Ladelsky <razya@gcc.gnu.org>2011-07-05 13:08:01 +0000
commit12037899ea37255a21d90902bb00c1183fc17fb6 (patch)
tree67135b0c880f731ab81c64aa984089f4ac3e36f2
parent509a31f8e558782f0cdc3c337dc957bb443a4d23 (diff)
downloadgcc-12037899ea37255a21d90902bb00c1183fc17fb6.zip
gcc-12037899ea37255a21d90902bb00c1183fc17fb6.tar.gz
gcc-12037899ea37255a21d90902bb00c1183fc17fb6.tar.bz2
07-05-2011 Razya Ladelsky <razya@il.ibm.com>
* tree-cfg.c (gimple_duplicate_sese_tail): Remove handling of the loop's number of iterations. * tree-parloops.c (transform_to_exit_first_loop): Add the handling of the loop's number of iterations before the call to gimple_duplicate_sese_tail. Insert the stmt caclculating the new rhs of the loop's condition stmt to the preheader instead of iters_bb. * testsuite/gcc.dg/autopar/pr49580.c: New test. From-SVN: r175851
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/autopar/pr49580.c38
-rw-r--r--gcc/tree-cfg.c33
-rw-r--r--gcc/tree-parloops.c34
5 files changed, 89 insertions, 32 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 29eeb64..9a5141e9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2011-07-05 Razya Ladelsky <razya@il.ibm.com>
+
+ PR tree-optimization/49580
+ * tree-cfg.c (gimple_duplicate_sese_tail): Remove handling of
+ the loop's number of iterations.
+ * tree-parloops.c (transform_to_exit_first_loop): Add the
+ handling of the loop's number of iterations before the call
+ to gimple_duplicate_sese_tail.
+ Insert the stmt caclculating the new rhs of the loop's
+ condition stmt to the preheader instead of iters_bb.
+
2011-07-05 H.J. Lu <hongjiu.lu@intel.com>
PR rtl-optimization/47449
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5839b72..87833d3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-05 Razya Ladelsky <razya@il.ibm.com>
+
+ PR tree-optimization/49580
+ * gcc.dg/autopar/pr49580.c: New test.
+
2011-07-05 Richard Guenther <rguenther@suse.de>
PR tree-optimization/49518
diff --git a/gcc/testsuite/gcc.dg/autopar/pr49580.c b/gcc/testsuite/gcc.dg/autopar/pr49580.c
new file mode 100644
index 0000000..e08fd0e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autopar/pr49580.c
@@ -0,0 +1,38 @@
+/* PR debug/49580 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-parallelize-loops=4 -fdump-tree-parloops-details" } */
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#define N 1600
+
+unsigned int ub[N];
+unsigned char reg_has_output_reload[N];
+unsigned int uc[N];
+
+ __attribute__ ((noinline))
+ void main2 (unsigned int regno, unsigned int n_reloads)
+ {
+ unsigned int nr=0;
+
+ if (regno> ub[regno])
+ nr=regno;
+ else
+ nr=ub[nr];
+
+ while (nr-- > 0)
+ if (n_reloads == 0 || reg_has_output_reload[regno + nr] == 0)
+ ub[regno + nr] = 0;
+}
+
+int main (void)
+{
+ main2 (799, 0);
+ return 0;
+}
+
+
+/* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 1 "parloops" } } */
+/* { dg-final { cleanup-tree-dump "parloops" } } */
+
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 349f56e..12d8fb4 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -5411,12 +5411,10 @@ gimple_duplicate_sese_tail (edge entry ATTRIBUTE_UNUSED, edge exit ATTRIBUTE_UNU
int total_freq = 0, exit_freq = 0;
gcov_type total_count = 0, exit_count = 0;
edge exits[2], nexits[2], e;
- gimple_stmt_iterator gsi,gsi1;
+ gimple_stmt_iterator gsi;
gimple cond_stmt;
edge sorig, snew;
basic_block exit_bb;
- basic_block iters_bb;
- tree new_rhs;
gimple_stmt_iterator psi;
gimple phi;
tree def;
@@ -5497,35 +5495,6 @@ gimple_duplicate_sese_tail (edge entry ATTRIBUTE_UNUSED, edge exit ATTRIBUTE_UNU
gcc_assert (gimple_code (cond_stmt) == GIMPLE_COND);
cond_stmt = gimple_copy (cond_stmt);
- /* If the block consisting of the exit condition has the latch as
- successor, then the body of the loop is executed before
- the exit condition is tested. In such case, moving the
- condition to the entry, causes that the loop will iterate
- one less iteration (which is the wanted outcome, since we
- peel out the last iteration). If the body is executed after
- the condition, moving the condition to the entry requires
- decrementing one iteration. */
- if (exits[1]->dest == orig_loop->latch)
- new_rhs = gimple_cond_rhs (cond_stmt);
- else
- {
- new_rhs = fold_build2 (MINUS_EXPR, TREE_TYPE (gimple_cond_rhs (cond_stmt)),
- gimple_cond_rhs (cond_stmt),
- build_int_cst (TREE_TYPE (gimple_cond_rhs (cond_stmt)), 1));
-
- if (TREE_CODE (gimple_cond_rhs (cond_stmt)) == SSA_NAME)
- {
- iters_bb = gimple_bb (SSA_NAME_DEF_STMT (gimple_cond_rhs (cond_stmt)));
- for (gsi1 = gsi_start_bb (iters_bb); !gsi_end_p (gsi1); gsi_next (&gsi1))
- if (gsi_stmt (gsi1) == SSA_NAME_DEF_STMT (gimple_cond_rhs (cond_stmt)))
- break;
-
- new_rhs = force_gimple_operand_gsi (&gsi1, new_rhs, true,
- NULL_TREE,false,GSI_CONTINUE_LINKING);
- }
- }
- gimple_cond_set_rhs (cond_stmt, unshare_expr (new_rhs));
- gimple_cond_set_lhs (cond_stmt, unshare_expr (gimple_cond_lhs (cond_stmt)));
gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT);
sorig = single_succ_edge (switch_bb);
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 921821d..339ddcc 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -1474,6 +1474,8 @@ transform_to_exit_first_loop (struct loop *loop, htab_t reduction_list, tree nit
gimple phi, nphi, cond_stmt, stmt, cond_nit;
gimple_stmt_iterator gsi;
tree nit_1;
+ edge exit_1;
+ tree new_rhs;
split_block_after_labels (loop->header);
orig_header = single_succ (loop->header);
@@ -1502,6 +1504,38 @@ transform_to_exit_first_loop (struct loop *loop, htab_t reduction_list, tree nit
control = t;
}
}
+
+ /* Setting the condition towards peeling the last iteration:
+ If the block consisting of the exit condition has the latch as
+ successor, then the body of the loop is executed before
+ the exit condition is tested. In such case, moving the
+ condition to the entry, causes that the loop will iterate
+ one less iteration (which is the wanted outcome, since we
+ peel out the last iteration). If the body is executed after
+ the condition, moving the condition to the entry requires
+ decrementing one iteration. */
+ exit_1 = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
+ if (exit_1->dest == loop->latch)
+ new_rhs = gimple_cond_rhs (cond_stmt);
+ else
+ {
+ new_rhs = fold_build2 (MINUS_EXPR, TREE_TYPE (gimple_cond_rhs (cond_stmt)),
+ gimple_cond_rhs (cond_stmt),
+ build_int_cst (TREE_TYPE (gimple_cond_rhs (cond_stmt)), 1));
+ if (TREE_CODE (gimple_cond_rhs (cond_stmt)) == SSA_NAME)
+ {
+ basic_block preheader;
+ gimple_stmt_iterator gsi1;
+
+ preheader = loop_preheader_edge(loop)->src;
+ gsi1 = gsi_after_labels (preheader);
+ new_rhs = force_gimple_operand_gsi (&gsi1, new_rhs, true,
+ NULL_TREE,false,GSI_CONTINUE_LINKING);
+ }
+ }
+ gimple_cond_set_rhs (cond_stmt, unshare_expr (new_rhs));
+ gimple_cond_set_lhs (cond_stmt, unshare_expr (gimple_cond_lhs (cond_stmt)));
+
bbs = get_loop_body_in_dom_order (loop);
for (n = 0; bbs[n] != loop->latch; n++)