From patchwork Tue Sep 29 17:28:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 523964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 11F761402B0 for ; Wed, 30 Sep 2015 03:28:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=r1T+4jkc; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=mrqdYmIVD96BAMgqZ yzGmwysdg4iduTMJS23Y1zRl86+UtDSiCqNkkz5E9CiVaeYdxRhbu0XaYRjKofcj fiG7TbXixtxZq1vqJH63RfBJC58EjitxXI92m2s4J0EeZkc+/Fz3fdKz95JIMlWU MEzBZXfgbNF9wjNP3XkFUU9Hhk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=Z02BgDTA30E/Zv7YMB+Y69+ BmLs=; b=r1T+4jkcAvOvSbbpLXcfB5BhP3QkrU1LvrYPUQvGA9aKv63YW65h2DL WBZtucKxVQJlFfsI8YLr4b3Rv5JpGzDzi/cHM6tUsSdxQn8u6txC/Cr/S+s1LKGo fg4+0dFhjXrLpvKoNGiol6VwOo9UK9lN21/wsPyTcigsjLbaOgvE= Received: (qmail 70209 invoked by alias); 29 Sep 2015 17:28:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 70198 invoked by uid 89); 29 Sep 2015 17:28:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_05, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 29 Sep 2015 17:28:43 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8639CC0B64D8 for ; Tue, 29 Sep 2015 17:28:41 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8THSdc6030759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 29 Sep 2015 13:28:41 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id t8THScea011637 for ; Tue, 29 Sep 2015 19:28:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id t8THSbjQ011635 for gcc-patches@gcc.gnu.org; Tue, 29 Sep 2015 19:28:37 +0200 Date: Tue, 29 Sep 2015 19:28:37 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [gomp4.1] Fixup handling of doacross loops with noreturn body Message-ID: <20150929172837.GL1847@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20150924183210.GI1847@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150924183210.GI1847@tucnak.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Thu, Sep 24, 2015 at 08:32:10PM +0200, Jakub Jelinek wrote: > then there is a bug with ordered loops that have noreturn body (need to add > some edge for that case and condition checking), This patch fixes the above issue, if we have any of the ordered > collapse loops that might have zero iterations, we need to deal with the !cont_bb (aka broken_loop) case, for lastprivate reasons not just as simple checking of the conditions and falling through into the cont_bb case, but have to emit all the loops, and just for the innermost handle the case that there is no fallthru from the body to the cont_bb block; the innermost could have zero iterations and some of the outer ones could have all non-zero iterations, at which point we want lastprivate to contain the initial value of the innermost iterator and last iteration's values of the outer ones. 2015-09-29 Jakub Jelinek * omp-low.c (expand_omp_for_ordered_loops): Handle the case when cont_bb has no predecessors. (expand_omp_for_generic): If any of the ordered loops above collapsed loops could have zero iterations for broken_loop, create a cont_bb and continue as if the loop is not broken. * testsuite/libgomp.c/doacross-1.c (main): Adjust, so that one of the doacross loops has noreturn loop body. Jakub --- gcc/omp-low.c.jj 2015-09-25 18:17:13.000000000 +0200 +++ gcc/omp-low.c 2015-09-29 19:07:25.366494422 +0200 @@ -7345,36 +7345,44 @@ expand_omp_for_ordered_loops (struct omp basic_block new_body = e1->dest; if (body_bb == cont_bb) cont_bb = new_body; - gsi = gsi_last_bb (cont_bb); - if (POINTER_TYPE_P (type)) - t = fold_build_pointer_plus (fd->loops[i].v, - fold_convert (sizetype, - fd->loops[i].step)); - else - t = fold_build2 (PLUS_EXPR, type, fd->loops[i].v, - fold_convert (type, fd->loops[i].step)); - expand_omp_build_assign (&gsi, fd->loops[i].v, t); - if (counts[i]) - { - t = fold_build2 (PLUS_EXPR, fd->iter_type, counts[i], - build_int_cst (fd->iter_type, 1)); - expand_omp_build_assign (&gsi, counts[i], t); - t = counts[i]; - } - else + edge e2 = NULL; + basic_block new_header; + if (EDGE_COUNT (cont_bb->preds) > 0) { - t = fold_build2 (MINUS_EXPR, TREE_TYPE (fd->loops[i].v), - fd->loops[i].v, fd->loops[i].n1); - t = fold_convert (fd->iter_type, t); - t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, - true, GSI_SAME_STMT); + gsi = gsi_last_bb (cont_bb); + if (POINTER_TYPE_P (type)) + t = fold_build_pointer_plus (fd->loops[i].v, + fold_convert (sizetype, + fd->loops[i].step)); + else + t = fold_build2 (PLUS_EXPR, type, fd->loops[i].v, + fold_convert (type, fd->loops[i].step)); + expand_omp_build_assign (&gsi, fd->loops[i].v, t); + if (counts[i]) + { + t = fold_build2 (PLUS_EXPR, fd->iter_type, counts[i], + build_int_cst (fd->iter_type, 1)); + expand_omp_build_assign (&gsi, counts[i], t); + t = counts[i]; + } + else + { + t = fold_build2 (MINUS_EXPR, TREE_TYPE (fd->loops[i].v), + fd->loops[i].v, fd->loops[i].n1); + t = fold_convert (fd->iter_type, t); + t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, + true, GSI_SAME_STMT); + } + aref = build4 (ARRAY_REF, fd->iter_type, counts[fd->ordered], + size_int (i - fd->collapse + 1), + NULL_TREE, NULL_TREE); + expand_omp_build_assign (&gsi, aref, t); + gsi_prev (&gsi); + e2 = split_block (cont_bb, gsi_stmt (gsi)); + new_header = e2->dest; } - aref = build4 (ARRAY_REF, fd->iter_type, counts[fd->ordered], - size_int (i - fd->collapse + 1), NULL_TREE, NULL_TREE); - expand_omp_build_assign (&gsi, aref, t); - gsi_prev (&gsi); - edge e2 = split_block (cont_bb, gsi_stmt (gsi)); - basic_block new_header = e2->dest; + else + new_header = cont_bb; gsi = gsi_after_labels (new_header); tree v = force_gimple_operand_gsi (&gsi, fd->loops[i].v, true, NULL_TREE, true, GSI_SAME_STMT); @@ -7395,10 +7403,13 @@ expand_omp_for_ordered_loops (struct omp set_immediate_dominator (CDI_DOMINATORS, new_header, body_bb); set_immediate_dominator (CDI_DOMINATORS, new_body, new_header); - struct loop *loop = alloc_loop (); - loop->header = new_header; - loop->latch = e2->src; - add_loop (loop, body_bb->loop_father); + if (e2) + { + struct loop *loop = alloc_loop (); + loop->header = new_header; + loop->latch = e2->src; + add_loop (loop, body_bb->loop_father); + } } return cont_bb; } @@ -7943,6 +7954,33 @@ expand_omp_for_generic (struct omp_regio depend(source). */ if (fd->collapse > 1) memmove (counts, counts + 1, (fd->collapse - 1) * sizeof (counts[0])); + if (broken_loop) + { + int i; + for (i = fd->collapse; i < fd->ordered; i++) + { + tree type = TREE_TYPE (fd->loops[i].v); + tree this_cond + = fold_build2 (fd->loops[i].cond_code, boolean_type_node, + fold_convert (type, fd->loops[i].n1), + fold_convert (type, fd->loops[i].n2)); + if (!integer_onep (this_cond)) + break; + } + if (i < fd->ordered) + { + cont_bb + = create_empty_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb); + add_bb_to_loop (cont_bb, l1_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); + make_edge (cont_bb, l3_bb, EDGE_FALLTHRU); + make_edge (cont_bb, l1_bb, 0); + l2_bb = create_empty_bb (cont_bb); + broken_loop = false; + } + } expand_omp_ordered_source_sink (region, fd, counts, cont_bb); cont_bb = expand_omp_for_ordered_loops (fd, counts, cont_bb, l1_bb); if (counts[fd->collapse - 1]) --- libgomp/testsuite/libgomp.c/doacross-1.c.jj 2015-09-25 16:54:47.000000000 +0200 +++ libgomp/testsuite/libgomp.c/doacross-1.c 2015-09-29 16:36:26.131321339 +0200 @@ -144,8 +144,7 @@ main () { #pragma omp ordered depend (source) #pragma omp ordered depend (sink:i - 2, j + 2, k - 2, m) - if (!e) - abort (); + abort (); } #pragma omp single if (i != 1 || j != -1 || k != 2 || m != 0)