From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 528683858C53; Thu, 24 Aug 2023 11:55:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 528683858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692878104; bh=vvV4jsdcPgyXamf+yQIhjJ7fMNJ/OMbzYc7tSJPE19c=; h=From:To:Subject:Date:From; b=CTj0REXCixAHRs5esu/i4FFfTX5vhRgi6VqFtFJEzpdZEmwD2Sk5u56aiCWl5ozRe Yw6fyteBf53c97u1pfnpCw0Ab6pix/UtSYkK7Pi5UJ58QaHLr8oE5Ceb3KQ4O7WUH8 8QTZ4RDkcpY0i9Zah5QZpk4eIAUbI1BjxIEL7tww= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7756] omp-expand.cc: Fix wrong code with non-rectangular loop nest [PR111017] X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: ad42dcf501e41713047cf6c47cbb1dd9f01088a4 X-Git-Newrev: d4648a00df7a6950f7e1d12743e17a8583af0e5f Message-Id: <20230824115504.528683858C53@sourceware.org> Date: Thu, 24 Aug 2023 11:55:04 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d4648a00df7a6950f7e1d12743e17a8583af0e5f commit r13-7756-gd4648a00df7a6950f7e1d12743e17a8583af0e5f Author: Tobias Burnus Date: Sat Aug 19 07:49:06 2023 +0200 omp-expand.cc: Fix wrong code with non-rectangular loop nest [PR111017] Before commit r12-5295-g47de0b56ee455e, all gimple_build_cond in expand_omp_for_* were inserted with gsi_insert_before (gsi_p, cond_stmt, GSI_SAME_STMT); except the one dealing with the multiplicative factor that was gsi_insert_after (gsi, cond_stmt, GSI_CONTINUE_LINKING); That commit for PR103208 fixed the issue of some missing regimplify of operands of GIMPLE_CONDs by moving the condition handling to the new function expand_omp_build_cond. While that function has an 'bool after = false' argument to switch between the two variants. However, all callers ommited this argument. This commit reinstates the prior behavior by passing 'true' for the factor != 0 condition, fixing the included testcase. PR middle-end/111017 gcc/ * omp-expand.cc (expand_omp_for_init_vars): Pass after=true to expand_omp_build_cond for 'factor != 0' condition, resulting in pre-r12-5295-g47de0b56ee455e code for the gimple insert. libgomp/ * testsuite/libgomp.c-c++-common/non-rect-loop-1.c: New test. (cherry picked from commit 1dc65003b66e5a97200f454eeddcccfce34416b3) Diff: --- gcc/omp-expand.cc | 3 +- .../libgomp.c-c++-common/non-rect-loop-1.c | 72 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index 1ccee29c52a2..285d3eae1881 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -2561,7 +2561,8 @@ expand_omp_for_init_vars (struct omp_for_data *fd, gimple_stmt_iterator *gsi, tree factor = fd->factor; gcond *cond_stmt = expand_omp_build_cond (gsi, NE_EXPR, factor, - build_zero_cst (TREE_TYPE (factor))); + build_zero_cst (TREE_TYPE (factor)), + true); edge e = split_block (gsi_bb (*gsi), cond_stmt); basic_block bb0 = e->src; e->flags = EDGE_TRUE_VALUE; diff --git a/libgomp/testsuite/libgomp.c-c++-common/non-rect-loop-1.c b/libgomp/testsuite/libgomp.c-c++-common/non-rect-loop-1.c new file mode 100644 index 000000000000..fbd462b36831 --- /dev/null +++ b/libgomp/testsuite/libgomp.c-c++-common/non-rect-loop-1.c @@ -0,0 +1,72 @@ +/* PR middle-end/111017 */ + +#include + +#define DIM 32 +#define N (DIM*DIM) + +int +main () +{ + int a[N], b[N], c[N]; + int dim = DIM; + + for (int i = 0; i < N; i++) + { + a[i] = 3*i; + b[i] = 7*i; + c[i] = 42; + } + + #pragma omp parallel for collapse(2) + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + c[j] = a[j] + b[j]; + + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + if (c[j] != a[j] + b[j] || c[j] != 3*j +7*j) + __builtin_abort (); + for (int i = 0; i < N; i++) + c[i] = 42; + + #pragma omp parallel for collapse(2) + for (int i = 0; i < dim; i++) + for (int j = (i*dim); j < (i*dim + dim); j++) + c[j] = a[j] + b[j]; + + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + if (c[j] != a[j] + b[j] || c[j] != 3*j +7*j) + __builtin_abort (); + for (int i = 0; i < N; i++) + c[i] = 42; + + for (int dev = 0; dev <= omp_get_num_devices(); dev++) + { + #pragma omp target teams loop device(dev) map(to:a,b) map(from:c) + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + c[j] = a[j] + b[j]; + + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + if (c[j] != a[j] + b[j] || c[j] != 3*j +7*j) + __builtin_abort (); + for (int i = 0; i < N; i++) + c[i] = 42; + + #pragma omp target teams loop device(dev) map(to:a,b) map(from:c) + for (int i = 0; i < dim; i++) + for (int j = (i*dim); j < (i*dim + dim); j++) + c[j] = a[j] + b[j]; + + for (int i = 0; i < DIM; i++) + for (int j = (i*DIM); j < (i*DIM + DIM); j++) + if (c[j] != a[j] + b[j] || c[j] != 3*j +7*j) + __builtin_abort (); + for (int i = 0; i < N; i++) + c[i] = 42; + } + return 0; +}