From patchwork Fri Mar 17 08:04:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 71124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp207213wrt; Fri, 17 Mar 2023 01:05:06 -0700 (PDT) X-Google-Smtp-Source: AK7set+KPfamIZDBVGAtySZRrUWtKXNuDmWKcj1/AsALsc8PSRicz/oMZaSe3x5W16Wai+FE8ki3 X-Received: by 2002:a17:907:8d1b:b0:889:1eb1:7517 with SMTP id tc27-20020a1709078d1b00b008891eb17517mr13870426ejc.30.1679040306139; Fri, 17 Mar 2023 01:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679040306; cv=none; d=google.com; s=arc-20160816; b=G8OCb1pIzv5d7rRXGusk3NoFN9DAFayteFl0mEA2NJG8j/T/ulZ9LC0wLpDJCYlUKe UsM/h80K3QnRHobgLy/0oo0qm46pMcGb50uPubjozBHmRDMOa4If4rmqmp+5Xr92zvYo GSM/HUAOWA/vcBVQhjlWShxNDvzOCRjQKht27A8NR8+zdbZtn5jXW+YgiMSMEFJ+c+05 /7lxThb1V1qqirLmnN3wn7d8oLfhvN4jCQcg36CEoquhUVcef4z5iuuLOoBgyIPpO85g 2O8boR9dhyBqiNKavi92PJvLbNJ7yZv0TBEzBq08RdWLDEJ345Vni+vwZunmL7BuYz30 Y7eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MJnIonfSYjFT8JW1/y63O+/Qwu2II98fGfhqajz68Rk=; b=jyP+hEE6U5byImqEDP6Q5YkpJeYK+UvmItqHOPeH/i7U0WnpNltb7w6nOhD1C7a+P+ FgiUU+BCAIAF9PZUsLJ22fvYo1R9ca9I14SoFgYPu8pad8xEXa5v985+VNaxqLxkGI5P dpiJfudmr9UOPdrXrHSjwWUt/GVXbl6yQ2+vLGuZGhWNnj7BeuE2HE5kCeQ+jcSzx/pY vmcI8Ct8t9zvFwUPPTtfX2KYCsJXgNeGyd4DcpN08Y8t7nxKVcvk7DIKs2FZ4ouO8X/U iot4/+n4j+R2TSvfNWVgHIlvSkQFF0LRv6yVPfHbrN8Or0CjlzuWLSHuu0r6PwwSrt+c i/QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I8vQs9YJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id oz17-20020a1709077d9100b008c3baa1f86asi1859064ejc.851.2023.03.17.01.05.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 01:05:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I8vQs9YJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B83C3858438 for ; Fri, 17 Mar 2023 08:05:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B83C3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679040305; bh=MJnIonfSYjFT8JW1/y63O+/Qwu2II98fGfhqajz68Rk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=I8vQs9YJspsDtqr1nJ7ksGbL5vUBUzKCTl0poUYzA95BaRofl37h6Qaqmm92V6+wc Bj7ULrGN+nz9XHfHExvbce5UJF0rPzfqWH6+vAuTX9D9Fsals2OvEqwahH671aCFzx faYWwV5pb9tH8oqzrbILMiymayllj0/ziTJ+PYlU= 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 EC8723858423 for ; Fri, 17 Mar 2023 08:04:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC8723858423 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-op431otsOEC3xiz9mGQMHg-1; Fri, 17 Mar 2023 04:04:15 -0400 X-MC-Unique: op431otsOEC3xiz9mGQMHg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 919703813F58; Fri, 17 Mar 2023 08:04:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 113142166B2A; Fri, 17 Mar 2023 08:04:14 +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 32H84CEa901897 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 09:04:13 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32H84Bfv901896; Fri, 17 Mar 2023 09:04:11 +0100 Date: Fri, 17 Mar 2023 09:04:10 +0100 To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Fix up handling of doacross loops with noreturn body in loops [PR108685] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760601368031284789?= X-GMAIL-MSGID: =?utf-8?q?1760601368031284789?= Hi! The following patch fixes an ICE with doacross loops which have a single entry no exit body, at least one of the ordered > collapse loops isn't guaranteed to have at least one iteration and the whole doacross loop is inside some other loop. The OpenMP constructs aren't represented by struct loop until the omp expansions, so for a normal doacross loop which doesn't have a noreturn body the entry_bb with the GOMP_FOR statement and the first bb of the body typically have the same loop_father, and if the doacross loop isn't inside of some other loop and the body is noreturn as well, both are part of loop 0. The problematic case is when the entry_bb is inside of some deeper loop, but the body, because it falls through into EXIT, has loop 0 as loop_father. l0_bb is created by splitting the entry_bb fallthru edge into l1_bb, and because the two basic blocks have different loop_father, a common loop is found for those (which is loop 0). Now, if the doacross loop has collapse == ordered or all the ordered > collapse loops are guaranteed to iterate at least once, all is still fine, because all enter the l1_bb (body), which doesn't return and so doesn't loop further either. But, if one of those loops could loop 0 times, the user written body wouldn't be reached at all, so unlike the expectations the whole construct actually wouldn't be noreturn if entry_bb is encountered and decides to handle at least one iteration. In this case, we need to fix up, move the l0_bb into the same loop as entry_bb (initially) and for the extra added loops put them as children of that same loop, rather than of loop 0. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-03-17 Jakub Jelinek PR middle-end/108685 * omp-expand.cc (expand_omp_for_ordered_loops): Add L0_BB argument, use its loop_father rather than BODY_BB's loop_father. (expand_omp_for_generic): Adjust expand_omp_for_ordered_loops caller. If broken_loop with ordered > collapse and at least one of those extra loops aren't guaranteed to have at least one iteration, change l0_bb's loop_father to entry_bb's loop_father. Set cont_bb's loop_father to l0_bb's loop_father rather than l1_bb's. * c-c++-common/gomp/doacross-8.c: New test. Jakub --- gcc/omp-expand.cc.jj 2023-02-16 10:13:01.000000000 +0100 +++ gcc/omp-expand.cc 2023-03-16 17:19:46.180181287 +0100 @@ -3674,7 +3674,7 @@ expand_omp_ordered_source_sink (struct o static basic_block expand_omp_for_ordered_loops (struct omp_for_data *fd, tree *counts, basic_block cont_bb, basic_block body_bb, - bool ordered_lastprivate) + basic_block l0_bb, bool ordered_lastprivate) { if (fd->ordered == fd->collapse) return cont_bb; @@ -3783,7 +3783,7 @@ expand_omp_for_ordered_loops (struct omp class loop *loop = alloc_loop (); loop->header = new_header; loop->latch = e2->src; - add_loop (loop, body_bb->loop_father); + add_loop (loop, l0_bb->loop_father); } } @@ -4481,9 +4481,15 @@ expand_omp_for_generic (struct omp_regio } if (i < fd->ordered) { + if (entry_bb->loop_father != l0_bb->loop_father) + { + remove_bb_from_loops (l0_bb); + add_bb_to_loop (l0_bb, entry_bb->loop_father); + gcc_assert (single_succ (l0_bb) == l1_bb); + } cont_bb = create_empty_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb); - add_bb_to_loop (cont_bb, l1_bb->loop_father); + add_bb_to_loop (cont_bb, l0_bb->loop_father); gimple_stmt_iterator gsi = gsi_after_labels (cont_bb); gimple *g = gimple_build_omp_continue (fd->loop.v, fd->loop.v); gsi_insert_before (&gsi, g, GSI_SAME_STMT); @@ -4495,7 +4501,7 @@ expand_omp_for_generic (struct omp_regio } expand_omp_ordered_source_sink (region, fd, counts, cont_bb); cont_bb = expand_omp_for_ordered_loops (fd, counts, cont_bb, l1_bb, - ordered_lastprivate); + l0_bb, ordered_lastprivate); if (counts[fd->collapse - 1]) { gcc_assert (fd->collapse == 1); --- gcc/testsuite/c-c++-common/gomp/doacross-8.c.jj 2023-03-16 17:57:32.070167415 +0100 +++ gcc/testsuite/c-c++-common/gomp/doacross-8.c 2023-03-16 17:56:21.313199748 +0100 @@ -0,0 +1,17 @@ +/* PR middle-end/108685 */ +/* { dg-do compile } */ + +void +foo (int a) +{ + for (int m = 0; m < 10; m++) + #pragma omp for collapse(2) ordered(4) + for (int i = 0; i < 2; i++) + for (int j = 0; j < a; j++) + for (int k = 0; k < 2; k++) + for (int l = 0; l < a; l++) + { + #pragma omp ordered depend (source) + __builtin_abort (); + } +}