From: Jakub Jelinek Date: Wed, 10 Oct 2018 11:04:09 +0000 (+0200) Subject: omp-low.c (lower_rec_input_clauses): Handle VLAs properly. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd0b7d5603f4d598aee82a4e633a61433793c9e;p=thirdparty%2Fgcc.git omp-low.c (lower_rec_input_clauses): Handle VLAs properly. * omp-low.c (lower_rec_input_clauses): Handle VLAs properly. (lower_omp_task_reductions): Likewise. * gimplify.c (enum omp_region_type): Add ORT_TASKGROUP. (gimple_add_tmp_var, omp_firstprivatize_variable, omp_notice_variable, omp_is_private, omp_check_private, gimplify_omp_depend): Handle ORT_TASKGROUP like ORT_WORKSHARE. (omp_add_variable): Don't add private/firstprivate for VLAs in ORT_TASKGROUP. (gimplify_expr) : Move handling into a separate case, make sure to scan omp clauses before gimplifying body. * testsuite/libgomp.c-c++-common/task-reduction-5.c (size_t): New typedef. (bar): Use it instead of __SIZE_TYPE__ directly. (foo): Likewise. Use (~(size_t) 0) instead of __SIZE_MAX__. * testsuite/libgomp.c/task-reduction-1.c: New test. * testsuite/libgomp.c++/task-reduction-7.C: New test. From-SVN: r265013 --- diff --git a/gcc/ChangeLog.gomp b/gcc/ChangeLog.gomp index a5d5e389e1ee..82e5bcc8107d 100644 --- a/gcc/ChangeLog.gomp +++ b/gcc/ChangeLog.gomp @@ -1,3 +1,16 @@ +2018-10-10 Jakub Jelinek + + * omp-low.c (lower_rec_input_clauses): Handle VLAs properly. + (lower_omp_task_reductions): Likewise. + * gimplify.c (enum omp_region_type): Add ORT_TASKGROUP. + (gimple_add_tmp_var, omp_firstprivatize_variable, omp_notice_variable, + omp_is_private, omp_check_private, gimplify_omp_depend): Handle + ORT_TASKGROUP like ORT_WORKSHARE. + (omp_add_variable): Don't add private/firstprivate for VLAs in + ORT_TASKGROUP. + (gimplify_expr) : Move handling into a separate + case, make sure to scan omp clauses before gimplifying body. + 2018-10-09 Jakub Jelinek * omp-low.c (lower_omp_task_reductions): Force TYPE_MAX_VALUE into diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 2d86539bbef8..3f355855bde6 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -122,6 +122,7 @@ enum gimplify_omp_var_data enum omp_region_type { ORT_WORKSHARE = 0x00, + ORT_TASKGROUP = 0x01, ORT_SIMD = 0x04, ORT_PARALLEL = 0x08, @@ -759,6 +760,7 @@ gimple_add_tmp_var (tree tmp) struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; while (ctx && (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC)) ctx = ctx->outer_context; @@ -6674,6 +6676,7 @@ omp_firstprivatize_variable (struct gimplify_omp_ctx *ctx, tree decl) omp_add_variable (ctx, decl, GOVD_MAP | GOVD_MAP_TO_ONLY); } else if (ctx->region_type != ORT_WORKSHARE + && ctx->region_type != ORT_TASKGROUP && ctx->region_type != ORT_SIMD && ctx->region_type != ORT_ACC && !(ctx->region_type & ORT_TARGET_DATA)) @@ -6787,7 +6790,7 @@ omp_add_variable (struct gimplify_omp_ctx *ctx, tree decl, unsigned int flags) replacement is private, else FIRSTPRIVATE since we'll need the address of the original variable either for SHARED, or for the copy into or out of the context. */ - if (!(flags & GOVD_LOCAL)) + if (!(flags & GOVD_LOCAL) && ctx->region_type != ORT_TASKGROUP) { if (flags & GOVD_MAP) nflags = GOVD_MAP | GOVD_MAP_TO_ONLY | GOVD_EXPLICIT; @@ -7316,6 +7319,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) if (n == NULL) { if (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC || (ctx->region_type & ORT_TARGET_DATA) != 0) @@ -7437,6 +7441,7 @@ omp_is_private (struct gimplify_omp_ctx *ctx, tree decl, int simd) } if (ctx->region_type != ORT_WORKSHARE + && ctx->region_type != ORT_TASKGROUP && ctx->region_type != ORT_SIMD && ctx->region_type != ORT_ACC) return false; @@ -7494,6 +7499,7 @@ omp_check_private (struct gimplify_omp_ctx *ctx, tree decl, bool copyprivate) } } while (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC); return false; @@ -7693,6 +7699,7 @@ gimplify_omp_depend (tree *list_p, gimple_seq *pre_p) struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; while (ctx && (ctx->region_type == ORT_WORKSHARE + || ctx->region_type == ORT_TASKGROUP || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_ACC)) ctx = ctx->outer_context; @@ -12831,7 +12838,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case OMP_SECTION: case OMP_MASTER: - case OMP_TASKGROUP: case OMP_ORDERED: case OMP_CRITICAL: { @@ -12847,24 +12853,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case OMP_MASTER: g = gimple_build_omp_master (body); break; - case OMP_TASKGROUP: - { - gimple_seq cleanup = NULL; - tree fn - = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END); - g = gimple_build_call (fn, 0); - gimple_seq_add_stmt (&cleanup, g); - g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY); - body = NULL; - gimple_seq_add_stmt (&body, g); - tree *pclauses = &OMP_TASKGROUP_CLAUSES (*expr_p); - gimplify_scan_omp_clauses (pclauses, pre_p, ORT_WORKSHARE, - OMP_TASKGROUP); - gimplify_adjust_omp_clauses (pre_p, body, pclauses, - OMP_TASKGROUP); - g = gimple_build_omp_taskgroup (body, *pclauses); - } - break; case OMP_ORDERED: g = gimplify_omp_ordered (*expr_p, body); break; @@ -12886,6 +12874,28 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, break; } + case OMP_TASKGROUP: + { + gimple_seq body = NULL; + + tree *pclauses = &OMP_TASKGROUP_CLAUSES (*expr_p); + gimplify_scan_omp_clauses (pclauses, pre_p, ORT_TASKGROUP, + OMP_TASKGROUP); + gimplify_adjust_omp_clauses (pre_p, NULL, pclauses, OMP_TASKGROUP); + gimplify_and_add (OMP_BODY (*expr_p), &body); + gimple_seq cleanup = NULL; + tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKGROUP_END); + gimple *g = gimple_build_call (fn, 0); + gimple_seq_add_stmt (&cleanup, g); + g = gimple_build_try (body, cleanup, GIMPLE_TRY_FINALLY); + body = NULL; + gimple_seq_add_stmt (&body, g); + g = gimple_build_omp_taskgroup (body, *pclauses); + gimplify_seq_add_stmt (pre_p, g); + ret = GS_ALL_DONE; + break; + } + case OMP_ATOMIC: case OMP_ATOMIC_READ: case OMP_ATOMIC_CAPTURE_OLD: diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 292dad611eeb..a42bd1b11b1f 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -3909,7 +3909,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, if (TREE_CODE (orig_var) == INDIRECT_REF) x = build_simple_mem_ref (x); else if (TREE_CODE (orig_var) == ADDR_EXPR) - x = build_fold_addr_expr (x); + { + if (var == TREE_OPERAND (orig_var, 0)) + x = build_fold_addr_expr (x); + } bias = fold_convert (sizetype, bias); x = fold_convert (ptr_type_node, x); x = fold_build2_loc (clause_loc, POINTER_PLUS_EXPR, @@ -6798,6 +6801,7 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses, var = TREE_OPERAND (var, 0); else if (TREE_CODE (var) == INDIRECT_REF) var = TREE_OPERAND (var, 0); + tree orig_var = var; if (is_variable_sized (var)) { gcc_assert (DECL_HAS_VALUE_EXPR_P (var)); @@ -6807,7 +6811,9 @@ lower_omp_task_reductions (omp_context *ctx, enum tree_code code, tree clauses, gcc_assert (DECL_P (var)); } t = ref = maybe_lookup_decl_in_outer_ctx (var, ctx); - if (TREE_CODE (v) == ADDR_EXPR) + if (orig_var != var) + gcc_assert (TREE_CODE (v) == ADDR_EXPR); + else if (TREE_CODE (v) == ADDR_EXPR) t = build_fold_addr_expr (t); else if (TREE_CODE (v) == INDIRECT_REF) t = build_fold_indirect_ref (t); diff --git a/libgomp/ChangeLog.gomp b/libgomp/ChangeLog.gomp index 08f2aadd4d53..fbf0540d8d03 100644 --- a/libgomp/ChangeLog.gomp +++ b/libgomp/ChangeLog.gomp @@ -1,3 +1,12 @@ +2018-10-10 Jakub Jelinek + + * testsuite/libgomp.c-c++-common/task-reduction-5.c (size_t): New + typedef. + (bar): Use it instead of __SIZE_TYPE__ directly. + (foo): Likewise. Use (~(size_t) 0) instead of __SIZE_MAX__. + * testsuite/libgomp.c/task-reduction-1.c: New test. + * testsuite/libgomp.c++/task-reduction-7.C: New test. + 2018-10-09 Jakub Jelinek * testsuite/libgomp.c-c++-common/task-reduction-5.c: Add further test diff --git a/libgomp/testsuite/libgomp.c++/task-reduction-7.C b/libgomp/testsuite/libgomp.c++/task-reduction-7.C new file mode 100644 index 000000000000..2a4d82ef77bb --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/task-reduction-7.C @@ -0,0 +1,145 @@ +typedef __SIZE_TYPE__ size_t; +extern "C" void abort (); + +void +bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], int *f, int *g, size_t n) +{ + #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[:n], g[1:n]) + { + a[0] *= 12; + a[1] *= 13; + b[3] *= 14; + b[4] *= 15; + c[n] *= 16; + c[n + 1] *= 17; + d[0][0] *= 18; + d[0][1] *= 19; + e[0][1] *= 20; + e[0][2] *= 21; + f[0] *= 22; + f[1] *= 23; + g[1] *= 24; + g[2] *= 25; + } +} + +void +foo (size_t n, void *x, void *y) +{ + int a[n], b[n + 3], c[2 * n]; + int (*d)[n] = (int (*)[n]) x; + int (*e)[n * 2] = (int (*)[n * 2]) y; + int fb[n], gb[n * 2]; + int (&f)[n] = fb; + int (&g)[n * 2] = gb; + int i; + for (i = 0; i < n; i++) + { + a[i] = 1; + b[i + 3] = 1; + c[i + n] = 1; + d[0][i] = 1; + e[0][i + 1] = 1; + f[i] = 1; + g[i + 1] = 1; + } + #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n]) + { + bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, &f[0], &g[0], n); + #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n]) + { + a[0] *= 2; + a[1] *= 3; + b[3] *= 4; + b[4] *= 5; + c[n] *= 6; + c[n + 1] *= 7; + d[0][0] *= 8; + d[0][1] *= 9; + e[0][1] *= 10; + e[0][2] *= 11; + f[0] *= 12; + f[1] *= 13; + g[1] *= 14; + g[2] *= 15; + } + n = 0; + } + if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75) + abort (); + if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171) + abort (); + if (e[0][1] != 200 || e[0][2] != 231 || f[0] != 264 || f[1] != 299) + abort (); + if (g[1] != 336 || g[2] != 375) + abort (); +} + +void +baz (size_t n, void *x, void *y) +{ + int a[n], b[n + 3], c[2 * n]; + int (*d)[n] = (int (*)[n]) x; + int (*e)[n * 2] = (int (*)[n * 2]) y; + int fb[n], gb[n * 2]; + int i; + for (i = 0; i < n; i++) + { + a[i] = 1; + b[i + 3] = 1; + c[i + n] = 1; + d[0][i] = 1; + e[0][i + 1] = 1; + fb[i] = 1; + gb[i + 1] = 1; + } + #pragma omp parallel num_threads(2) + #pragma omp master + { + int (&f)[n] = fb; + int (&g)[n * 2] = gb; + #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n]) + { + bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, &f[0], &g[0], n); + #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f, g[1:n]) + { + a[0] *= 2; + a[1] *= 3; + b[3] *= 4; + b[4] *= 5; + c[n] *= 6; + c[n + 1] *= 7; + d[0][0] *= 8; + d[0][1] *= 9; + e[0][1] *= 10; + e[0][2] *= 11; + f[0] *= 12; + f[1] *= 13; + g[1] *= 14; + g[2] *= 15; + } + n = 0; + } + } + if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75) + abort (); + if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171) + abort (); + if (e[0][1] != 200 || e[0][2] != 231 || fb[0] != 264 || fb[1] != 299) + abort (); + if (gb[1] != 336 || gb[2] != 375) + abort (); +} + +int +main () +{ + int d[2], e[4]; + volatile int two; + two = 2; + #pragma omp parallel num_threads (2) + #pragma omp master + foo (two, (void *) d, (void *) e); + baz (two, (void *) d, (void *) e); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c index f3e28cc696a6..018dc4fb28e4 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c +++ b/libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c @@ -1,3 +1,4 @@ +typedef __SIZE_TYPE__ size_t; extern #ifdef __cplusplus "C" @@ -7,7 +8,7 @@ void abort (void); int *q; void -bar (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) +bar (int *p, int *r, int *t, int s, size_t u) { #pragma omp task in_reduction (*: p[0], q[0], r[s - 1], t[0:u + 1]) { @@ -20,7 +21,7 @@ bar (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) } void -foo (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) +foo (int *p, int *r, int *t, int s, size_t u) { int *p2 = p; #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s], t[0:u + 1]) @@ -38,7 +39,7 @@ foo (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) t[0] *= 10; t[1] *= 11; } - u = __SIZE_MAX__ / 4; + u = (~(size_t) 0) / 4; s++; p2 = (int *) 0; q = (int *) 0; diff --git a/libgomp/testsuite/libgomp.c/task-reduction-1.c b/libgomp/testsuite/libgomp.c/task-reduction-1.c new file mode 100644 index 000000000000..224d995bd131 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/task-reduction-1.c @@ -0,0 +1,137 @@ +typedef __SIZE_TYPE__ size_t; +extern void abort (void); + +void +bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], size_t n, int f[1][n], int g[1][n * 2]) +{ + #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n]) + { + a[0] *= 12; + a[1] *= 13; + b[3] *= 14; + b[4] *= 15; + c[n] *= 16; + c[n + 1] *= 17; + d[0][0] *= 18; + d[0][1] *= 19; + e[0][1] *= 20; + e[0][2] *= 21; + f[0][0] *= 22; + f[0][1] *= 23; + g[0][1] *= 24; + g[0][2] *= 25; + } +} + +void +foo (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2]) +{ + int a[n], b[n + 3], c[2 * n]; + int (*d)[n] = (int (*)[n]) x; + int (*e)[n * 2] = (int (*)[n * 2]) y; + int i; + for (i = 0; i < n; i++) + { + a[i] = 1; + b[i + 3] = 1; + c[i + n] = 1; + d[0][i] = 1; + e[0][i + 1] = 1; + f[0][i] = 1; + g[0][i + 1] = 1; + } + #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n]) + { + bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g); + #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n]) + { + a[0] *= 2; + a[1] *= 3; + b[3] *= 4; + b[4] *= 5; + c[n] *= 6; + c[n + 1] *= 7; + d[0][0] *= 8; + d[0][1] *= 9; + e[0][1] *= 10; + e[0][2] *= 11; + f[0][0] *= 12; + f[0][1] *= 13; + g[0][1] *= 14; + g[0][2] *= 15; + } + n = 0; + } + if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75) + abort (); + if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171) + abort (); + if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299) + abort (); + if (g[0][1] != 336 || g[0][2] != 375) + abort (); +} + +void +baz (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2]) +{ + int a[n], b[n + 3], c[2 * n]; + int (*d)[n] = (int (*)[n]) x; + int (*e)[n * 2] = (int (*)[n * 2]) y; + int i; + for (i = 0; i < n; i++) + { + a[i] = 1; + b[i + 3] = 1; + c[i + n] = 1; + d[0][i] = 1; + e[0][i + 1] = 1; + f[0][i] = 1; + g[0][i + 1] = 1; + } + #pragma omp parallel num_threads(2) + #pragma omp master + #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n]) + { + bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g); + #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n]) + { + a[0] *= 2; + a[1] *= 3; + b[3] *= 4; + b[4] *= 5; + c[n] *= 6; + c[n + 1] *= 7; + d[0][0] *= 8; + d[0][1] *= 9; + e[0][1] *= 10; + e[0][2] *= 11; + f[0][0] *= 12; + f[0][1] *= 13; + g[0][1] *= 14; + g[0][2] *= 15; + } + n = 0; + } + if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75) + abort (); + if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171) + abort (); + if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299) + abort (); + if (g[0][1] != 336 || g[0][2] != 375) + abort (); +} + +int +main () +{ + int d[1][2], e[1][4], f[1][2], g[1][4]; + volatile int two; + two = 2; + #pragma omp parallel num_threads (2) + #pragma omp master + foo (two, (void *) d, (void *) e, f, g); + baz (two, (void *) d, (void *) e, f, g); + return 0; +}