From patchwork Wed Aug 5 09:00:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1341144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DrptnhBv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BM5FL4yHXz9sRN for ; Wed, 5 Aug 2020 19:00:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C7F1387085F; Wed, 5 Aug 2020 09:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C7F1387085F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596618051; bh=PxE0+X3Twnaz1OrA+wPiQN/0Gk9v6xsz9lUL/1iILZY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DrptnhBvQKJqW7Pu6zvRh27tTRR/HkBqg4/twh83KS8KBJZ6z24L4V7bqYbdSsGMW Ft/rfw3VHI7nlOgKiWTCXbwTHhg7QMBKcFkfWX8tlDh4fJPiFRZ4WxeMHEOBbBrr44 c0xAmivj6zsoTfThqARgbrE3PZj2vbYUNuG20UKk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 465F93851C3C for ; Wed, 5 Aug 2020 09:00:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 465F93851C3C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-YgUoJUqYNAi6y2hcHIO1Hw-1; Wed, 05 Aug 2020 05:00:46 -0400 X-MC-Unique: YgUoJUqYNAi6y2hcHIO1Hw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8EFC100CCC0 for ; Wed, 5 Aug 2020 09:00:45 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-174.ams2.redhat.com [10.36.113.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D31D8AC00 for ; Wed, 5 Aug 2020 09:00:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 07590g6I028778 for ; Wed, 5 Aug 2020 11:00:42 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 07590g6Q028777 for gcc-patches@gcc.gnu.org; Wed, 5 Aug 2020 11:00:42 +0200 Date: Wed, 5 Aug 2020 11:00:42 +0200 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Handle even some combined non-rectangular loops Message-ID: <20200805090042.GS2375@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! The number of loops computation and logical iteration -> actual iterator values computations can now be done separately even on composite constructs (though for triangular loops it would still be more efficient to propagate a few values through, will handle that incrementally). simd and taskloop are still unhandled. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2020-08-05 Jakub Jelinek * omp-expand.c (expand_omp_for): Don't disallow combined non-rectangular loops. * testsuite/libgomp.c/loop-22.c: New test. * testsuite/libgomp.c/loop-23.c: New test. Jakub --- gcc/omp-expand.c.jj 2020-08-04 13:05:18.522759444 +0200 +++ gcc/omp-expand.c 2020-08-04 16:58:53.834538817 +0200 @@ -7640,11 +7640,6 @@ expand_omp_for (struct omp_region *regio else if (fd.sched_kind == OMP_CLAUSE_SCHEDULE_STATIC && !fd.have_ordered) { - if (fd.non_rect - && (gimple_omp_for_combined_into_p (fd.for_stmt) - || gimple_omp_for_combined_p (fd.for_stmt))) - sorry_at (gimple_location (fd.for_stmt), - "non-rectangular OpenMP loops not supported yet"); if (fd.chunk_size == NULL) expand_omp_for_static_nochunk (region, &fd, inner_stmt); else --- libgomp/testsuite/libgomp.c/loop-22.c.jj 2020-08-04 16:04:03.471418037 +0200 +++ libgomp/testsuite/libgomp.c/loop-22.c 2020-08-04 16:08:06.827891401 +0200 @@ -0,0 +1,189 @@ +/* { dg-do run } */ + +extern void abort (void); + +signed char v[5][7][9][21][4][42][3]; +volatile int zero = 0, one = 1, two = 2, three = 3; +volatile int five = 5, seven = 7, nine = 9, eleven = 11; + +int +main () +{ + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + v[i][j][k][l][m - 7][n][o] = 1; + + int niters = 0; + #pragma omp teams reduction(+:niters) + #pragma omp distribute collapse(7) + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + { + niters++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || k < 0 || k >= 9 + || l < 2 * j || l >= 3 * j + || m < 7 || m >= 11 + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][k][l][m - 7][n][o] != 1) + abort (); + v[i][j][k][l][m - 7][n][o]++; + } + + if (niters != 117180) + abort (); + + int niters2 = 0; + #pragma omp teams reduction(+:niters2) + #pragma omp distribute collapse(7) + for (int i = zero; i < five; i += one) + for (int j = seven - one; j >= zero; j -= one) + for (int k = nine - one; k >= zero; k += -one) + for (int l = two * j + zero; l < three * j; l += one) + for (int m = eleven - one; m >= seven; m -= one) + for (int n = two * l - one; n > one * l - one; n -= one) + for (int o = zero; o < three; o += one) + { + niters2++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || k < 0 || k >= 9 + || l < 2 * j || l >= 3 * j + || m < 7 || m >= 11 + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][k][l][m - 7][n][o] != 2) + abort (); + v[i][j][k][l][m - 7][n][o]++; + } + + if (niters2 != 117180) + abort (); + + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + if (v[i][j][k][l][m - 7][n][o] != 3) + abort (); + + int niters3 = 0; + #pragma omp teams reduction(+:niters3) + #pragma omp distribute collapse(5) + for (int i = 4; i >= 0; i--) + for (int j = 6; j >= 0; --j) + for (int l = 3 * j - 1; l >= 2 * j; l--) + for (int n = 2 * l + -1; n > l - 1; --n) + for (int o = 2; o >= 0; o--) + { + niters3++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][0][l][0][n][o] != 3) + abort (); + v[i][j][0][l][0][n][o]++; + } + + if (niters3 != 3255) + abort (); + + int niters4 = 0; + #pragma omp teams reduction(+:niters4) + #pragma omp distribute collapse(5) + for (int i = zero; i < five; i += one) + for (int j = zero; j <= seven - one; j += one) + for (int l = j * two; l < three * j + zero; l += one) + for (int n = one * l; n <= l * two - one; n += one) + for (int o = zero; o < three; o += one) + { + niters4++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][0][l][0][n][o] != 4) + abort (); + v[i][j][0][l][0][n][o]++; + } + + if (niters4 != 3255) + abort (); + + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int l = 2 * j; l < 3 * j; l++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + if (v[i][j][0][l][0][n][o] != 5) + abort (); + + int niters5 = 0; + #pragma omp teams reduction(+:niters5) + #pragma omp distribute collapse(3) + for (int j = 6; j >= 0; --j) + for (int l = 2 * j; l <= 3 * j - 1; l++) + for (int n = 2 * l + -1; n > l - 1; --n) + { + niters5++; + if (j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l) + abort (); + if (v[0][j][0][l][0][n][0] != 5) + abort (); + v[0][j][0][l][0][n][0]++; + } + + if (niters5 != 217) + abort (); + + int niters6 = 0; + #pragma omp teams reduction(+:niters6) + #pragma omp distribute collapse(3) + for (int j = seven - one; j > - one; j -= one) + for (int l = j * three - one; l >= j * two + zero; l += -one) + for (int n = two * l - one; n > l - one; n -= one) + { + niters6++; + if (j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l) + abort (); + if (v[0][j][0][l][0][n][0] != 6) + abort (); + v[0][j][0][l][0][n][0]++; + } + + if (niters6 != 217) + abort (); + + for (int j = 0; j < 7; j++) + for (int l = 2 * j; l < 3 * j; l++) + for (int n = l; n < 2 * l; n++) + if (v[0][j][0][l][0][n][0] != 7) + abort (); + return 0; +} --- libgomp/testsuite/libgomp.c/loop-23.c.jj 2020-08-04 16:33:11.738932371 +0200 +++ libgomp/testsuite/libgomp.c/loop-23.c 2020-08-04 16:32:04.378910450 +0200 @@ -0,0 +1,189 @@ +/* { dg-do run } */ + +extern void abort (void); + +signed char v[5][7][9][21][4][42][3]; +volatile int zero = 0, one = 1, two = 2, three = 3; +volatile int five = 5, seven = 7, nine = 9, eleven = 11; + +int +main () +{ + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + v[i][j][k][l][m - 7][n][o] = 1; + + int niters = 0; + #pragma omp teams reduction(+:niters) + #pragma omp distribute parallel for collapse(7) reduction(+:niters) + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + { + niters++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || k < 0 || k >= 9 + || l < 2 * j || l >= 3 * j + || m < 7 || m >= 11 + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][k][l][m - 7][n][o] != 1) + abort (); + v[i][j][k][l][m - 7][n][o]++; + } + + if (niters != 117180) + abort (); + + int niters2 = 0; + #pragma omp teams reduction(+:niters2) + #pragma omp distribute parallel for collapse(7) reduction(+:niters2) + for (int i = zero; i < five; i += one) + for (int j = seven - one; j >= zero; j -= one) + for (int k = nine - one; k >= zero; k += -one) + for (int l = two * j + zero; l < three * j; l += one) + for (int m = eleven - one; m >= seven; m -= one) + for (int n = two * l - one; n > one * l - one; n -= one) + for (int o = zero; o < three; o += one) + { + niters2++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || k < 0 || k >= 9 + || l < 2 * j || l >= 3 * j + || m < 7 || m >= 11 + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][k][l][m - 7][n][o] != 2) + abort (); + v[i][j][k][l][m - 7][n][o]++; + } + + if (niters2 != 117180) + abort (); + + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int k = 0; k < 9; k++) + for (int l = 2 * j; l < 3 * j; l++) + for (int m = 7; m < 11; m++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + if (v[i][j][k][l][m - 7][n][o] != 3) + abort (); + + int niters3 = 0; + #pragma omp teams reduction(+:niters3) + #pragma omp distribute parallel for collapse(5) reduction(+:niters3) + for (int i = 4; i >= 0; i--) + for (int j = 6; j >= 0; --j) + for (int l = 3 * j - 1; l >= 2 * j; l--) + for (int n = 2 * l + -1; n > l - 1; --n) + for (int o = 2; o >= 0; o--) + { + niters3++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][0][l][0][n][o] != 3) + abort (); + v[i][j][0][l][0][n][o]++; + } + + if (niters3 != 3255) + abort (); + + int niters4 = 0; + #pragma omp teams reduction(+:niters4) + #pragma omp distribute parallel for collapse(5) reduction(+:niters4) + for (int i = zero; i < five; i += one) + for (int j = zero; j <= seven - one; j += one) + for (int l = j * two; l < three * j + zero; l += one) + for (int n = one * l; n <= l * two - one; n += one) + for (int o = zero; o < three; o += one) + { + niters4++; + if (i < 0 || i >= 5 + || j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l + || o < 0 || o >= 3) + abort (); + if (v[i][j][0][l][0][n][o] != 4) + abort (); + v[i][j][0][l][0][n][o]++; + } + + if (niters4 != 3255) + abort (); + + for (int i = 0; i < 5; i++) + for (int j = 0; j < 7; j++) + for (int l = 2 * j; l < 3 * j; l++) + for (int n = l; n < 2 * l; n++) + for (int o = 0; o < 3; o++) + if (v[i][j][0][l][0][n][o] != 5) + abort (); + + int niters5 = 0; + #pragma omp teams reduction(+:niters5) + #pragma omp distribute parallel for collapse(3) reduction(+:niters5) + for (int j = 6; j >= 0; --j) + for (int l = 2 * j; l <= 3 * j - 1; l++) + for (int n = 2 * l + -1; n > l - 1; --n) + { + niters5++; + if (j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l) + abort (); + if (v[0][j][0][l][0][n][0] != 5) + abort (); + v[0][j][0][l][0][n][0]++; + } + + if (niters5 != 217) + abort (); + + int niters6 = 0; + #pragma omp teams reduction(+:niters6) + #pragma omp distribute parallel for collapse(3) reduction(+:niters6) + for (int j = seven - one; j > - one; j -= one) + for (int l = j * three - one; l >= j * two + zero; l += -one) + for (int n = two * l - one; n > l - one; n -= one) + { + niters6++; + if (j < 0 || j >= 7 + || l < 2 * j || l >= 3 * j + || n < l || n >= 2 * l) + abort (); + if (v[0][j][0][l][0][n][0] != 6) + abort (); + v[0][j][0][l][0][n][0]++; + } + + if (niters6 != 217) + abort (); + + for (int j = 0; j < 7; j++) + for (int l = 2 * j; l < 3 * j; l++) + for (int n = l; n < 2 * l; n++) + if (v[0][j][0][l][0][n][0] != 7) + abort (); + return 0; +}