diff mbox

[gomp4] Optimize expand_omp_for_static_chunk for chunk_size one

Message ID 53D61631.8090605@mentor.com
State New
Headers show

Commit Message

Tom de Vries July 28, 2014, 9:21 a.m. UTC
Jakub,

we're using expand_omp_for_static_chunk with a chunk_size of one to expand the
openacc loop construct.

This results in an inner and outer loop being generated, with the inner loop
having a trip count of one, which means that the inner loop can be simplified to
just the inner loop body. However, subsequent optimizations do not manage to do
this simplification.

This patch sets the loop exit condition to true if the chunk_size is one, to
ensure that the compiler will optimize away the inner loop.

OK for gomp4 branch?

Thanks,
- Tom

Comments

Jakub Jelinek Aug. 24, 2015, 9:43 a.m. UTC | #1
On Mon, Jul 28, 2014 at 11:21:53AM +0200, Tom de Vries wrote:
> Jakub,
> 
> we're using expand_omp_for_static_chunk with a chunk_size of one to expand the
> openacc loop construct.
> 
> This results in an inner and outer loop being generated, with the inner loop
> having a trip count of one, which means that the inner loop can be simplified to
> just the inner loop body. However, subsequent optimizations do not manage to do
> this simplification.
> 
> This patch sets the loop exit condition to true if the chunk_size is one, to
> ensure that the compiler will optimize away the inner loop.
> 
> OK for gomp4 branch?
> 
> Thanks,
> - Tom

> 2014-07-25  Tom de Vries  <tom@codesourcery.com>
> 
> 	* omp-low.c (expand_omp_for_static_chunk): Remove inner loop if
> 	chunk_size is one.

If that is still the case on the trunk, the patch is ok for trunk after
retesting it.  Please mention the PR tree-optimization/65468 in the
ChangeLog entry and make sure there is some runtime testcase that tests
that code path (both OpenMP and OpenACC one).

> diff --git a/gcc/omp-low.c b/gcc/omp-low.c
> index b188e2d..5a73986 100644
> --- a/gcc/omp-low.c
> +++ b/gcc/omp-low.c
> @@ -7345,9 +7345,14 @@ expand_omp_for_static_chunk (struct omp_region *region,
>  	  stmt = gimple_build_assign (vback, t);
>  	  gsi_insert_before (&gsi, 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);
>  	}
>  


	Jakub
diff mbox

Patch

2014-07-25  Tom de Vries  <tom@codesourcery.com>

	* omp-low.c (expand_omp_for_static_chunk): Remove inner loop if
	chunk_size is one.

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index b188e2d..5a73986 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -7345,9 +7345,14 @@  expand_omp_for_static_chunk (struct omp_region *region,
 	  stmt = gimple_build_assign (vback, t);
 	  gsi_insert_before (&gsi, 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);
 	}