From 6be5c241bbf8f3b6cec45f0b1074156822a96359 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 24 Aug 2015 13:14:17 +0000 Subject: [PATCH] Optimize expand_omp_for_static_chunk for chunk_size one 2015-08-24 Tom de Vries PR tree-optimization/65468 * omp-low.c (expand_omp_for_static_chunk): Remove inner loop if chunk_size is one. * gcc.dg/gomp/static-chunk-size-one.c: New test. * testsuite/libgomp.c/static-chunk-size-one.c: New test. From-SVN: r227124 --- gcc/ChangeLog | 6 +++++ gcc/omp-low.c | 11 ++++++--- gcc/testsuite/ChangeLog | 5 ++++ .../gcc.dg/gomp/static-chunk-size-one.c | 18 +++++++++++++++ libgomp/ChangeLog | 5 ++++ .../libgomp.c/static-chunk-size-one.c | 23 +++++++++++++++++++ 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c create mode 100644 libgomp/testsuite/libgomp.c/static-chunk-size-one.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d25402cb22..d1a9e3a5b13 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-08-24 Tom de Vries + + PR tree-optimization/65468 + * omp-low.c (expand_omp_for_static_chunk): Remove inner loop if + chunk_size is one. + 2015-08-24 Nathan Sidwell * config/nvptx/nvptx.c (walk_args_for_param): Revert previous diff --git a/gcc/omp-low.c b/gcc/omp-low.c index d181101d6cf..19f34ec4f07 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -7204,9 +7204,14 @@ expand_omp_for_static_chunk (struct omp_region *region, assign_stmt = gimple_build_assign (vback, t); gsi_insert_before (&gsi, assign_stmt, GSI_SAME_STMT); - t = build2 (fd->loop.cond_code, boolean_type_node, - DECL_P (vback) && TREE_ADDRESSABLE (vback) - ? t : vback, e); + if (tree_int_cst_equal (fd->chunk_size, integer_one_node)) + t = build2 (EQ_EXPR, boolean_type_node, + build_int_cst (itype, 0), + build_int_cst (itype, 1)); + else + t = build2 (fd->loop.cond_code, boolean_type_node, + DECL_P (vback) && TREE_ADDRESSABLE (vback) + ? t : vback, e); gsi_insert_before (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6235844f534..36fc88ffa9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-08-24 Tom de Vries + + PR tree-optimization/65468 + * gcc.dg/gomp/static-chunk-size-one.c: New test. + 2015-08-23 Francois-Xavier Coudert PR libfortran/54572 diff --git a/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c b/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c new file mode 100644 index 00000000000..e82de772deb --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -O2 -fdump-tree-optimized -fno-tree-pre" } */ + +int +bar () +{ + int a = 0, i; + +#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1) + for (i = 0; i < 10; i++) + a += i; + + return a; +} + +/* Two phis for reduction, one in loop header, one in loop exit. One phi for iv + in loop header. */ +/* { dg-final { scan-tree-dump-times "PHI" 3 "optimized" } } */ diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index bd9111b86a9..43aaa524c2a 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,8 @@ +2015-08-24 Tom de Vries + + PR tree-optimization/65468 + * testsuite/libgomp.c/static-chunk-size-one.c: New test. + 2015-08-24 Joost VandeVondele PR libgomp/66761 diff --git a/libgomp/testsuite/libgomp.c/static-chunk-size-one.c b/libgomp/testsuite/libgomp.c/static-chunk-size-one.c new file mode 100644 index 00000000000..9ed7b83625a --- /dev/null +++ b/libgomp/testsuite/libgomp.c/static-chunk-size-one.c @@ -0,0 +1,23 @@ +extern void abort (); + +int +bar () +{ + int a = 0, i; + +#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1) + for (i = 0; i < 10; i++) + a += i; + + return a; +} + +int +main (void) +{ + int res; + res = bar (); + if (res != 45) + abort (); + return 0; +} -- 2.30.2