From patchwork Sun Mar 15 00:30:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1254890 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=2620:52:3:1:0:246e:9693:128c; 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=alnu3Qkw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 48g0j4593Bz9sSV for ; Sun, 15 Mar 2020 11:31:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F3B1394D839; Sun, 15 Mar 2020 00:30:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F3B1394D839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584232257; bh=lf9L1NNG7qo01G7xXkxwRXCJPJ7fKAhZrye4f5hwhXI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=alnu3Qkwqk4+BGg+VNe5a4SDSXBJLLXuATAiOAwEcTxY7hTId2gRxXuLpquZ/GS+w ALxaOUnNYJXQ2Lzwy0mDbiqRtTHtJGbkubQZlXOc09swhXbJclq2tfhEwFdJVv59wA 3YpPfpUTwmkTKBnQ9T4a5988+iGeihiKRMEo56+8= 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 781D539450F3 for ; Sun, 15 Mar 2020 00:30:54 +0000 (GMT) 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-210-hCNWIm3FM6yAEYfxLMaZ9Q-1; Sat, 14 Mar 2020 20:30:52 -0400 X-MC-Unique: hCNWIm3FM6yAEYfxLMaZ9Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6780189F760 for ; Sun, 15 Mar 2020 00:30:50 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 607D473864 for ; Sun, 15 Mar 2020 00:30:50 +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 02F0Ulmw013745 for ; Sun, 15 Mar 2020 01:30:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 02F0Ukg2013744 for gcc-patches@gcc.gnu.org; Sun, 15 Mar 2020 01:30:46 +0100 Date: Sun, 15 Mar 2020 01:30:46 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] tree-nested: Fix handling of *reduction clauses with C array sections [PR93566] Message-ID: <20200315003046.GG2156@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-10.2 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS 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: "Li, Pan2 via Gcc-patches" Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! tree-nested.c didn't handle C array sections in {,task_,in_}reduction clauses. The following patch implements that, bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far. 2020-03-14 Jakub Jelinek PR middle-end/93566 * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Handle {,in_,task_}reduction clauses with C/C++ array sections. * testsuite/libgomp.c/pr93566.c: New test. Jakub --- gcc/tree-nested.c.jj 2020-03-13 11:23:23.593724452 +0100 +++ gcc/tree-nested.c 2020-03-14 09:54:53.319358556 +0100 @@ -1188,7 +1188,7 @@ convert_nonlocal_omp_clauses (tree *pcla { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_chain = false, need_stmts = false; - tree clause, decl; + tree clause, decl, *pdecl; int dummy; bitmap new_suppress; @@ -1197,6 +1197,7 @@ convert_nonlocal_omp_clauses (tree *pcla for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { case OMP_CLAUSE_REDUCTION: @@ -1204,6 +1205,15 @@ convert_nonlocal_omp_clauses (tree *pcla case OMP_CLAUSE_TASK_REDUCTION: if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause)) need_stmts = true; + if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF) + { + pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0); + if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + if (TREE_CODE (*pdecl) == INDIRECT_REF + || TREE_CODE (*pdecl) == ADDR_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + } goto do_decl_clause; case OMP_CLAUSE_LASTPRIVATE: @@ -1230,7 +1240,9 @@ convert_nonlocal_omp_clauses (tree *pcla case OMP_CLAUSE_USE_DEVICE_ADDR: case OMP_CLAUSE_IS_DEVICE_PTR: do_decl_clause: - decl = OMP_CLAUSE_DECL (clause); + if (pdecl == NULL) + pdecl = &OMP_CLAUSE_DECL (clause); + decl = *pdecl; if (VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) break; @@ -1239,7 +1251,7 @@ convert_nonlocal_omp_clauses (tree *pcla if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED) OMP_CLAUSE_SHARED_READONLY (clause) = 0; bitmap_set_bit (new_suppress, DECL_UID (decl)); - OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl); + *pdecl = get_nonlocal_debug_decl (info, decl); if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE) need_chain = true; } @@ -1909,7 +1921,7 @@ convert_local_omp_clauses (tree *pclause { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_frame = false, need_stmts = false; - tree clause, decl; + tree clause, decl, *pdecl; int dummy; bitmap new_suppress; @@ -1918,6 +1930,7 @@ convert_local_omp_clauses (tree *pclause for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { case OMP_CLAUSE_REDUCTION: @@ -1925,6 +1938,15 @@ convert_local_omp_clauses (tree *pclause case OMP_CLAUSE_TASK_REDUCTION: if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause)) need_stmts = true; + if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF) + { + pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0); + if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + if (TREE_CODE (*pdecl) == INDIRECT_REF + || TREE_CODE (*pdecl) == ADDR_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + } goto do_decl_clause; case OMP_CLAUSE_LASTPRIVATE: @@ -1951,7 +1973,9 @@ convert_local_omp_clauses (tree *pclause case OMP_CLAUSE_USE_DEVICE_ADDR: case OMP_CLAUSE_IS_DEVICE_PTR: do_decl_clause: - decl = OMP_CLAUSE_DECL (clause); + if (pdecl == NULL) + pdecl = &OMP_CLAUSE_DECL (clause); + decl = *pdecl; if (VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) break; @@ -1964,8 +1988,7 @@ convert_local_omp_clauses (tree *pclause if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED) OMP_CLAUSE_SHARED_READONLY (clause) = 0; bitmap_set_bit (new_suppress, DECL_UID (decl)); - OMP_CLAUSE_DECL (clause) - = get_local_debug_decl (info, decl, field); + *pdecl = get_local_debug_decl (info, decl, field); need_frame = true; } } --- libgomp/testsuite/libgomp.c/pr93566.c.jj 2020-03-13 12:53:56.247508784 +0100 +++ libgomp/testsuite/libgomp.c/pr93566.c 2020-03-13 12:39:42.994132358 +0100 @@ -0,0 +1,113 @@ +/* PR middle-end/93566 */ +/* { dg-additional-options "-std=c99" } */ + +extern void abort (void); + +void +foo (int *x) +{ + void nest (void) { + #pragma omp parallel for reduction(+:x[:10]) + for (int i = 0; i < 1024; i++) + for (int j = 0; j < 10; j++) + x[j] += j * i; + } + nest (); + for (int i = 0; i < 10; i++) + if (x[i] != 1023 * 1024 / 2 * i) + abort (); +} + +void +bar (void) +{ + int x[10] = {}; + void nest (void) { + #pragma omp parallel for reduction(+:x[:10]) + for (int i = 0; i < 1024; i++) + for (int j = 0; j < 10; j++) + x[j] += j * i; + } + nest (); + for (int i = 0; i < 10; i++) + if (x[i] != 1023 * 1024 / 2 * i) + abort (); +} + +void +baz (void) +{ + int x[10] = {}; + void nest (void) { + #pragma omp parallel for reduction(+:x[2:5]) + for (int i = 0; i < 1024; i++) + for (int j = 2; j < 7; j++) + x[j] += j * i; + } + nest (); + for (int i = 2; i < 7; i++) + if (x[i] != 1023 * 1024 / 2 * i) + abort (); +} + +void +qux (int *x) +{ + void nest (void) { x++; } + nest (); + #pragma omp parallel for reduction(+:x[:9]) + for (int i = 0; i < 1024; i++) + for (int j = 0; j < 9; j++) + x[j] += j * i; + nest (); + for (int i = 0; i < 9; i++) + if (x[i - 1] != 1023 * 1024 / 2 * i) + abort (); +} + +void +quux (void) +{ + int x[10]; + void nest (void) { for (int i = 0; i < 10; i++) x[i] = 0; } + int nest2 (int i) { return x[i]; } + nest (); + #pragma omp parallel for reduction(+:x[:7]) + for (int i = 0; i < 1024; i++) + for (int j = 0; j < 7; j++) + x[j] += j * i; + for (int i = 0; i < 7; i++) + if (nest2 (i) != 1023 * 1024 / 2 * i) + abort (); +} + +void +corge (void) +{ + int x[10]; + void nest (void) { for (int i = 0; i < 10; i++) x[i] = 0; } + int nest2 (int i) { return x[i]; } + nest (); + #pragma omp parallel for reduction(+:x[2:4]) + for (int i = 0; i < 1024; i++) + for (int j = 2; j < 6; j++) + x[j] += j * i; + for (int i = 2; i < 6; i++) + if (nest2 (i) != 1023 * 1024 / 2 * i) + abort (); +} + +int +main () +{ + int a[10] = {}; + foo (a); + bar (); + baz (); + for (int i = 0; i < 10; i++) + a[i] = 0; + qux (a); + quux (); + corge (); + return 0; +}