Commit 9d2f08ab by Richard Sandiford Committed by Richard Sandiford

poly_int: omp_max_vf

This patch makes omp_max_vf return a polynomial vectorization factor.
We then need to be able to stash a polynomial value in
OMP_CLAUSE_SAFELEN_EXPR too:

   /* If max_vf is non-zero, then we can use only a vectorization factor
      up to the max_vf we chose.  So stick it into the safelen clause.  */

For now the cfgloop safelen is still constant though.

2018-01-03  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* omp-general.h (omp_max_vf): Return a poly_uint64 instead of an int.
	* omp-general.c (omp_max_vf): Likewise.
	* omp-expand.c (omp_adjust_chunk_size): Update call to omp_max_vf.
	(expand_omp_simd): Handle polynomial safelen.
	* omp-low.c (omplow_simd_context): Add a default constructor.
	(omplow_simd_context::max_vf): Change from int to poly_uint64.
	(lower_rec_simd_input_clauses): Update accordingly.
	(lower_rec_input_clauses): Likewise.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>

From-SVN: r256129
parent c5126ce8
...@@ -2,6 +2,19 @@ ...@@ -2,6 +2,19 @@
Alan Hayward <alan.hayward@arm.com> Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com> David Sherwood <david.sherwood@arm.com>
* omp-general.h (omp_max_vf): Return a poly_uint64 instead of an int.
* omp-general.c (omp_max_vf): Likewise.
* omp-expand.c (omp_adjust_chunk_size): Update call to omp_max_vf.
(expand_omp_simd): Handle polynomial safelen.
* omp-low.c (omplow_simd_context): Add a default constructor.
(omplow_simd_context::max_vf): Change from int to poly_uint64.
(lower_rec_simd_input_clauses): Update accordingly.
(lower_rec_input_clauses): Likewise.
2018-01-03 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* tree-vectorizer.h (vect_nunits_for_cost): New function. * tree-vectorizer.h (vect_nunits_for_cost): New function.
* tree-vect-loop.c (vect_model_reduction_cost): Use it. * tree-vect-loop.c (vect_model_reduction_cost): Use it.
* tree-vect-slp.c (vect_analyze_slp_cost_1): Likewise. * tree-vect-slp.c (vect_analyze_slp_cost_1): Likewise.
...@@ -205,8 +205,8 @@ omp_adjust_chunk_size (tree chunk_size, bool simd_schedule) ...@@ -205,8 +205,8 @@ omp_adjust_chunk_size (tree chunk_size, bool simd_schedule)
if (!simd_schedule) if (!simd_schedule)
return chunk_size; return chunk_size;
int vf = omp_max_vf (); poly_uint64 vf = omp_max_vf ();
if (vf == 1) if (known_eq (vf, 1U))
return chunk_size; return chunk_size;
tree type = TREE_TYPE (chunk_size); tree type = TREE_TYPE (chunk_size);
...@@ -4368,11 +4368,12 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd) ...@@ -4368,11 +4368,12 @@ expand_omp_simd (struct omp_region *region, struct omp_for_data *fd)
if (safelen) if (safelen)
{ {
poly_uint64 val;
safelen = OMP_CLAUSE_SAFELEN_EXPR (safelen); safelen = OMP_CLAUSE_SAFELEN_EXPR (safelen);
if (TREE_CODE (safelen) != INTEGER_CST) if (!poly_int_tree_p (safelen, &val))
safelen_int = 0; safelen_int = 0;
else if (tree_fits_uhwi_p (safelen) && tree_to_uhwi (safelen) < INT_MAX) else
safelen_int = tree_to_uhwi (safelen); safelen_int = MIN (constant_lower_bound (val), INT_MAX);
if (safelen_int == 1) if (safelen_int == 1)
safelen_int = 0; safelen_int = 0;
} }
......
...@@ -419,7 +419,7 @@ omp_build_barrier (tree lhs) ...@@ -419,7 +419,7 @@ omp_build_barrier (tree lhs)
/* Return maximum possible vectorization factor for the target. */ /* Return maximum possible vectorization factor for the target. */
int poly_uint64
omp_max_vf (void) omp_max_vf (void)
{ {
if (!optimize if (!optimize
......
...@@ -78,7 +78,7 @@ extern tree omp_get_for_step_from_incr (location_t loc, tree incr); ...@@ -78,7 +78,7 @@ extern tree omp_get_for_step_from_incr (location_t loc, tree incr);
extern void omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, extern void omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd,
struct omp_for_data_loop *loops); struct omp_for_data_loop *loops);
extern gimple *omp_build_barrier (tree lhs); extern gimple *omp_build_barrier (tree lhs);
extern int omp_max_vf (void); extern poly_uint64 omp_max_vf (void);
extern int omp_max_simt_vf (void); extern int omp_max_simt_vf (void);
extern tree oacc_launch_pack (unsigned code, tree device, unsigned op); extern tree oacc_launch_pack (unsigned code, tree device, unsigned op);
extern void oacc_replace_fn_attrib (tree fn, tree dims); extern void oacc_replace_fn_attrib (tree fn, tree dims);
......
...@@ -3417,11 +3417,12 @@ omp_clause_aligned_alignment (tree clause) ...@@ -3417,11 +3417,12 @@ omp_clause_aligned_alignment (tree clause)
and lower_rec_input_clauses. */ and lower_rec_input_clauses. */
struct omplow_simd_context { struct omplow_simd_context {
omplow_simd_context () { memset (this, 0, sizeof (*this)); }
tree idx; tree idx;
tree lane; tree lane;
vec<tree, va_heap> simt_eargs; vec<tree, va_heap> simt_eargs;
gimple_seq simt_dlist; gimple_seq simt_dlist;
int max_vf; poly_uint64_pod max_vf;
bool is_simt; bool is_simt;
}; };
...@@ -3432,28 +3433,30 @@ static bool ...@@ -3432,28 +3433,30 @@ static bool
lower_rec_simd_input_clauses (tree new_var, omp_context *ctx, lower_rec_simd_input_clauses (tree new_var, omp_context *ctx,
omplow_simd_context *sctx, tree &ivar, tree &lvar) omplow_simd_context *sctx, tree &ivar, tree &lvar)
{ {
if (sctx->max_vf == 0) if (known_eq (sctx->max_vf, 0U))
{ {
sctx->max_vf = sctx->is_simt ? omp_max_simt_vf () : omp_max_vf (); sctx->max_vf = sctx->is_simt ? omp_max_simt_vf () : omp_max_vf ();
if (sctx->max_vf > 1) if (maybe_gt (sctx->max_vf, 1U))
{ {
tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
OMP_CLAUSE_SAFELEN); OMP_CLAUSE_SAFELEN);
if (c if (c)
&& (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) != INTEGER_CST {
|| tree_int_cst_sgn (OMP_CLAUSE_SAFELEN_EXPR (c)) != 1)) poly_uint64 safe_len;
sctx->max_vf = 1; if (!poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len)
else if (c && compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c), || maybe_lt (safe_len, 1U))
sctx->max_vf) == -1) sctx->max_vf = 1;
sctx->max_vf = tree_to_shwi (OMP_CLAUSE_SAFELEN_EXPR (c)); else
sctx->max_vf = lower_bound (sctx->max_vf, safe_len);
}
} }
if (sctx->max_vf > 1) if (maybe_gt (sctx->max_vf, 1U))
{ {
sctx->idx = create_tmp_var (unsigned_type_node); sctx->idx = create_tmp_var (unsigned_type_node);
sctx->lane = create_tmp_var (unsigned_type_node); sctx->lane = create_tmp_var (unsigned_type_node);
} }
} }
if (sctx->max_vf == 1) if (known_eq (sctx->max_vf, 1U))
return false; return false;
if (sctx->is_simt) if (sctx->is_simt)
...@@ -3567,7 +3570,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, ...@@ -3567,7 +3570,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
} }
/* Add a placeholder for simduid. */ /* Add a placeholder for simduid. */
if (sctx.is_simt && sctx.max_vf != 1) if (sctx.is_simt && maybe_ne (sctx.max_vf, 1U))
sctx.simt_eargs.safe_push (NULL_TREE); sctx.simt_eargs.safe_push (NULL_TREE);
/* Do all the fixed sized types in the first pass, and the variable sized /* Do all the fixed sized types in the first pass, and the variable sized
...@@ -4457,7 +4460,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, ...@@ -4457,7 +4460,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
} }
} }
if (sctx.max_vf == 1) if (known_eq (sctx.max_vf, 1U))
sctx.is_simt = false; sctx.is_simt = false;
if (sctx.lane || sctx.is_simt) if (sctx.lane || sctx.is_simt)
...@@ -4594,14 +4597,14 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, ...@@ -4594,14 +4597,14 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
/* If max_vf is non-zero, then we can use only a vectorization factor /* If max_vf is non-zero, then we can use only a vectorization factor
up to the max_vf we chose. So stick it into the safelen clause. */ up to the max_vf we chose. So stick it into the safelen clause. */
if (sctx.max_vf) if (maybe_ne (sctx.max_vf, 0U))
{ {
tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
OMP_CLAUSE_SAFELEN); OMP_CLAUSE_SAFELEN);
poly_uint64 safe_len;
if (c == NULL_TREE if (c == NULL_TREE
|| (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) == INTEGER_CST || (poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len)
&& compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c), && maybe_gt (safe_len, sctx.max_vf)))
sctx.max_vf) == 1))
{ {
c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN); c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN);
OMP_CLAUSE_SAFELEN_EXPR (c) = build_int_cst (integer_type_node, OMP_CLAUSE_SAFELEN_EXPR (c) = build_int_cst (integer_type_node,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment