From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 70AD0385841E; Thu, 19 Jan 2023 20:24:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70AD0385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674159840; bh=o4wohRGOi7nqdkFQoVnCxwbUM3HVLCv3O84/fiLpUqA=; h=From:To:Subject:Date:From; b=BC70wNqJ/3laFYUS1pM68yKfqq65CuMNgj18+y33/qj0ls/zPg5vp9S37YMtf0hbu q452jNcdfvafpBH+qDFl2ocMJt3RnoZNGI9V0mBruJVhcTIHf3pMS2CvEsCNhRtHvG sceJS+P1dNyNE3+bv8bN0MgJPB5TdDDin9VlbJU4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 495b7c3a3f716a06b4f254d78bf75ad64552a9b9 X-Git-Newrev: 1184c551867f870ce880578153b5d961c4723efb Message-Id: <20230119202400.70AD0385841E@sourceware.org> Date: Thu, 19 Jan 2023 20:24:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1184c551867f870ce880578153b5d961c4723efb commit 1184c551867f870ce880578153b5d961c4723efb Author: Jakub Jelinek Date: Thu Jan 19 21:22:22 2023 +0100 openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459] expand_omp_for_init_counts was using for the case where collapse(2) inner loop has init expression dependent on non-constant multiple of the outer iterator and the condition upper bound expression doesn't depend on the outer iterator fold_unary (NEGATE_EXPR, ...). This will just return NULL if it can't be folded, we need fold_build1 instead. 2023-01-19 Jakub Jelinek PR middle-end/108459 * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather than fold_unary for NEGATE_EXPR. * testsuite/libgomp.c/pr108459.c: New test. (cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88) Diff: --- gcc/ChangeLog.omp | 9 ++++++++ gcc/omp-expand.cc | 4 ++-- libgomp/ChangeLog.omp | 8 +++++++ libgomp/testsuite/libgomp.c/pr108459.c | 41 ++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 917bb606a0f..2d4b7513413 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,12 @@ +2023-01-19 Tobias Burnus + + Backported from master: + 2023-01-19 Jakub Jelinek + + PR middle-end/108459 + * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather + than fold_unary for NEGATE_EXPR. + 2023-01-03 Sandra Loosemore Backported from master: diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index 37c397089b4..afe00069a56 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -2009,8 +2009,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi, t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2), unshare_expr (fd->loops[i].m1)); else if (fd->loops[i].m1) - t = fold_unary (NEGATE_EXPR, itype, - unshare_expr (fd->loops[i].m1)); + t = fold_build1 (NEGATE_EXPR, itype, + unshare_expr (fd->loops[i].m1)); else t = unshare_expr (fd->loops[i].m2); tree m2minusm1 diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index be3c17b4019..629efbc5832 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,11 @@ +2023-01-19 Tobias Burnus + + Backported from master: + 2023-01-19 Jakub Jelinek + + PR middle-end/108459 + * testsuite/libgomp.c/pr108459.c: New test. + 2023-01-13 Andrew Stubbs * usm-allocator.c (ALIGN): Use 128-byte alignment. diff --git a/libgomp/testsuite/libgomp.c/pr108459.c b/libgomp/testsuite/libgomp.c/pr108459.c new file mode 100644 index 00000000000..87ce981e080 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr108459.c @@ -0,0 +1,41 @@ +/* PR middle-end/108459 */ + +char a[17][17]; + +__attribute__((noipa)) void +foo (int x, int y) +{ + #pragma omp for collapse(2) + for (int i = 1; i <= 16; i++) + for (int j = i * x + y; j <= 16; j++) + a[i][j] = 1; +} + +int +main () +{ + #pragma omp parallel + foo (1, 1); + for (int i = 0; i <= 16; i++) + for (int j = 0; j <= 16; j++) + if (i >= 1 && j >= i + 1) + { + if (a[i][j] != 1) + __builtin_abort (); + a[i][j] = 0; + } + else if (a[i][j]) + __builtin_abort (); + #pragma omp parallel + foo (2, -2); + for (int i = 0; i <= 16; i++) + for (int j = 0; j <= 16; j++) + if (i >= 1 && j >= 2 * i - 2) + { + if (a[i][j] != 1) + __builtin_abort (); + } + else if (a[i][j]) + __builtin_abort (); + return 0; +}