From patchwork Thu Feb 2 09:00:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 64138 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51ABD3858423 for ; Thu, 2 Feb 2023 09:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51ABD3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675328495; bh=KfGaYCOUH2Is09EbvlUKiON2cwuL+lV8mdbBrSVpOsY=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=WCHgD2+K3ins2IxaXuisTHIQKmfYLFYuIEuUeIEE7eiMx87N/YfG3ZxWhXZDg4XKD 8yGsmGMXthVh6nvniB9csInahVXoej3BOyE1ijVSHERDuhJRq7lEhoUwH5ztMP0Oz4 nVba9GNhyyvl9rzGpp4R2xwvD8YAhkOTM3MzZKYE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C40703858C30 for ; Thu, 2 Feb 2023 09:00:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C40703858C30 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-173-XzlfEGouMoexPIpDHTujtg-1; Thu, 02 Feb 2023 04:00:58 -0500 X-MC-Unique: XzlfEGouMoexPIpDHTujtg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A98AF811E6E; Thu, 2 Feb 2023 09:00:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E780404CD80; Thu, 2 Feb 2023 09:00:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31290rlh1318815 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 2 Feb 2023 10:00:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31290q311318814; Thu, 2 Feb 2023 10:00:52 +0100 Date: Thu, 2 Feb 2023 10:00:52 +0100 To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] nested, openmp: Wrap OMP_CLAUSE_*_GIMPLE_SEQ into GIMPLE_BIND for declare_vars [PR108435] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! When gimplifying OMP_CLAUSE_{LASTPRIVATE,LINEAR}_STMT, we wrap it always into a GIMPLE_BIND, but when putting statements directly into OMP_CLAUSE_{LASTPRIVATE,LINEAR}_GIMPLE_SEQ, we do it only if needed (there are any temporaries that need to be declared in the sequence). convert_nonlocal_omp_clauses was relying on the GIMPLE_BIND to be there always because it called declare_vars on it. The following patch wraps it into GIMPLE_BIND in tree-nested if we need to declare_vars on it on demand. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-02-02 Jakub Jelinek PR middle-end/108435 * tree-nested.cc (convert_nonlocal_omp_clauses) : If info->new_local_var_chain and *seq is not a GIMPLE_BIND, wrap the sequence into a new GIMPLE_BIND before calling declare_vars. (convert_nonlocal_omp_clauses) : Merge with the OMP_CLAUSE_LASTPRIVATE handling except for whether seq is initialized to &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause) or &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause). * gcc.dg/gomp/pr108435.c: New test. Jakub --- gcc/tree-nested.cc.jj 2023-01-02 09:32:40.110029184 +0100 +++ gcc/tree-nested.cc 2023-02-01 16:22:33.272248502 +0100 @@ -1566,29 +1566,29 @@ convert_nonlocal_omp_clauses (tree *pcla break; case OMP_CLAUSE_LASTPRIVATE: - { - tree save_local_var_chain = info->new_local_var_chain; - info->new_local_var_chain = NULL; - gimple_seq *seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause); - walk_body (convert_nonlocal_reference_stmt, - convert_nonlocal_reference_op, info, seq); - if (info->new_local_var_chain) - declare_vars (info->new_local_var_chain, - gimple_seq_first_stmt (*seq), false); - info->new_local_var_chain = save_local_var_chain; - } - break; - case OMP_CLAUSE_LINEAR: { tree save_local_var_chain = info->new_local_var_chain; info->new_local_var_chain = NULL; - gimple_seq *seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause); + gimple_seq *seq; + if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LASTPRIVATE) + seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause); + else + seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause); walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op, info, seq); if (info->new_local_var_chain) - declare_vars (info->new_local_var_chain, - gimple_seq_first_stmt (*seq), false); + { + gimple *g = gimple_seq_first_stmt (*seq); + if (gimple_code (g) != GIMPLE_BIND) + { + g = gimple_build_bind (NULL_TREE, *seq, NULL_TREE); + *seq = NULL; + gimple_seq_add_stmt_without_update (seq, g); + } + declare_vars (info->new_local_var_chain, + gimple_seq_first_stmt (*seq), false); + } info->new_local_var_chain = save_local_var_chain; } break; --- gcc/testsuite/gcc.dg/gomp/pr108435.c.jj 2023-02-01 16:24:56.180152165 +0100 +++ gcc/testsuite/gcc.dg/gomp/pr108435.c 2023-02-01 16:24:36.150445983 +0100 @@ -0,0 +1,18 @@ +/* PR middle-end/108435 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fopenmp" } */ + +int +main () +{ + int i, j; + void + bar (void) + { + #pragma omp for simd collapse(2) + for (i = 1; i <= 16; i++) + for (j = 1; j <= 16; j++) + ; + } + bar (); +}