From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47743 invoked by alias); 11 Apr 2018 19:31:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 47668 invoked by uid 89); 11 Apr 2018 19:30:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy=cfg, !$acc, 259227 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Apr 2018 19:30:48 +0000 Received: from svr-orw-mbx-04.mgc.mentorg.com ([147.34.90.204]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1f6LS6-0007PX-BJ from Cesar_Philippidis@mentor.com ; Wed, 11 Apr 2018 12:30:42 -0700 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-MBX-04.mgc.mentorg.com (147.34.90.204) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 11 Apr 2018 12:30:39 -0700 Subject: Re: [PATCH] Handle empty infinite loops in OpenACC for PR84955 To: Richard Biener , Jakub Jelinek CC: "gcc-patches@gcc.gnu.org" References: <20180406141029.GF8577@tucnak> From: Cesar Philippidis Message-ID: Date: Wed, 11 Apr 2018 19:31:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------F73729CCDD01661207F18E9E" X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To SVR-ORW-MBX-04.mgc.mentorg.com (147.34.90.204) X-SW-Source: 2018-04/txt/msg00565.txt.bz2 --------------F73729CCDD01661207F18E9E Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-length: 2749 On 04/09/2018 04:31 AM, Richard Biener wrote: > On Fri, 6 Apr 2018, Jakub Jelinek wrote: > >> On Fri, Apr 06, 2018 at 06:48:52AM -0700, Cesar Philippidis wrote: >>> 2018-04-06 Cesar Philippidis >>> >>> PR middle-end/84955 >>> >>> gcc/ >>> * cfgloop.c (flow_loops_find): Add assert. >>> * omp-expand.c (expand_oacc_for): Add dummy false branch for >>> tiled basic blocks without omp continue statements. >>> * tree-cfg.c (execute_fixup_cfg): Handle calls to internal >>> functions like regular functions. >>> >>> libgomp/ >>> * testsuite/libgomp.oacc-c-c++-common/pr84955.c: New test. >>> * testsuite/libgomp.oacc-fortran/pr84955.f90: New test. >> >> I'd like to defer the cfgloop.c and tree-cfg.c changes to Richard, just want to >> mention that: >> >>> --- a/gcc/tree-cfg.c >>> +++ b/gcc/tree-cfg.c >>> @@ -9586,10 +9586,7 @@ execute_fixup_cfg (void) >>> for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) >>> { >>> gimple *stmt = gsi_stmt (gsi); >>> - tree decl = is_gimple_call (stmt) >>> - ? gimple_call_fndecl (stmt) >>> - : NULL; >>> - if (decl) >>> + if (is_gimple_call (stmt)) >> >> This change doesn't affect just internal functions, but also all indirect >> calls through function pointers with const, pure or noreturn attributes. > > I think the change is desirable nevertheless. The question is if we > want to do it at this point in time. > > The description of the problem sounds more like LTO writing writing out > loops without previously fixing up state. So sth like the following > which I'd prefer at this stage (the above hunk is ok for stage1 then). OK, I'll save that hunk for stage 1. > Index: gcc/lto-streamer-out.c > =================================================================== > --- gcc/lto-streamer-out.c (revision 259227) > +++ gcc/lto-streamer-out.c (working copy) > @@ -2084,6 +2151,9 @@ output_function (struct cgraph_node *nod > /* Set current_function_decl and cfun. */ > push_cfun (fn); > > + /* Fixup loops if required to match discovery done in the reader. */ > + loop_optimizer_init (AVOID_CFG_MODIFICATIONS); > + > /* Make string 0 be a NULL string. */ > streamer_write_char_stream (ob->string_stream, 0); > > @@ -2176,12 +2246,13 @@ output_function (struct cgraph_node *nod > streamer_write_record_start (ob, LTO_null); > > output_cfg (ob, fn); > - > - pop_cfun (); > } > else > streamer_write_uhwi (ob, 0); > > + loop_optimizer_finalize (); > + pop_cfun (); > + > /* Create a section to hold the pickled output of this function. */ > produce_asm (ob, function); That worked. Is this patch OK for trunk, GCC 6 and GCC 7? Thanks, Cesar --------------F73729CCDD01661207F18E9E Content-Type: text/x-patch; name="trunk-pr84955.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="trunk-pr84955.diff" Content-length: 3615 2018-04-11 Cesar Philippidis Richard Biener PR middle-end/84955 gcc/ * cfgloop.c (flow_loops_find): Add assert. * lto-streamer-out.c (output_function): Fix CFG loop state before streaming out. * omp-expand.c (expand_oacc_for): Handle calls to internal functions like regular functions. libgomp/ * testsuite/libgomp.oacc-c-c++-common/pr84955.c: New test. * testsuite/libgomp.oacc-fortran/pr84955.f90: New test. diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index 8af793c6015..6e68639452c 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -462,6 +462,9 @@ flow_loops_find (struct loops *loops) { struct loop *loop; + if (!from_scratch) + gcc_assert (header->loop_father != NULL); + /* The current active loop tree has valid loop-fathers for header blocks. */ if (!from_scratch diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index 1d2ab9757f1..fd6788a69b0 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -2084,6 +2084,9 @@ output_function (struct cgraph_node *node) /* Set current_function_decl and cfun. */ push_cfun (fn); + /* Fixup loops if required to match discovery done in the reader. */ + loop_optimizer_init (AVOID_CFG_MODIFICATIONS); + /* Make string 0 be a NULL string. */ streamer_write_char_stream (ob->string_stream, 0); @@ -2176,12 +2179,13 @@ output_function (struct cgraph_node *node) streamer_write_record_start (ob, LTO_null); output_cfg (ob, fn); - - pop_cfun (); } else streamer_write_uhwi (ob, 0); + loop_optimizer_finalize (); + pop_cfun (); + /* Create a section to hold the pickled output of this function. */ produce_asm (ob, function); diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index bb204906ea6..c7d30ea3964 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -5439,6 +5439,14 @@ expand_oacc_for (struct omp_region *region, struct omp_for_data *fd) split->flags ^= EDGE_FALLTHRU | EDGE_TRUE_VALUE; + /* Add a dummy exit for the tiled block when cont_bb is missing. */ + if (cont_bb == NULL) + { + edge e = make_edge (body_bb, exit_bb, EDGE_FALSE_VALUE); + e->probability = profile_probability::even (); + split->probability = profile_probability::even (); + } + /* Initialize the user's loop vars. */ gsi = gsi_start_bb (elem_body_bb); expand_oacc_collapse_vars (fd, true, &gsi, counts, e_offset); diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr84955.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr84955.c new file mode 100644 index 00000000000..5910b57b68d --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr84955.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +int +main () +{ + int i, j; + +#pragma acc parallel loop tile(2,3) + for (i = 1; i < 10; i++) + for (j = 1; j < 10; j++) + for (;;) + ; + +#pragma acc parallel loop + for (i = 1; i < 10; i++) + for (;;) + ; + + return i + j; +} diff --git a/libgomp/testsuite/libgomp.oacc-fortran/pr84955.f90 b/libgomp/testsuite/libgomp.oacc-fortran/pr84955.f90 new file mode 100644 index 00000000000..878d8a89f41 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/pr84955.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } + +subroutine s + integer :: i, j + !$acc parallel loop tile(2,3) + do i = 1, 10 + do j = 1, 10 + do + end do + end do + end do + !$acc end parallel loop + + !$acc parallel loop + do i = 1, 10 + do + end do + end do + !$acc end parallel loop +end subroutine s --------------F73729CCDD01661207F18E9E--