From patchwork Thu Jun 18 07:25:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 486087 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 AE05A140284 for ; Thu, 18 Jun 2015 17:25:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vxV5TluG; 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=hCUBBU481CLNSQwLL7wHCkIG5XE8cheznhYEtyQto9A AxD4TjnkW+a3CaV6zCW5Ja/l64libhO6pSxQ8HzGa3NU6TSjuitrB0Obmsbwe8es 8+PqpSmz6AY/zljb69aukUFlP20OWbS+Fdd5VDwhgBOIUJ8eXR+0n/SZpZfpws3g = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=lL/WQNYn/givMDRN+EoCj79Yb1E=; b=vxV5TluGBf1ayifaa mVfMXGzus5iJZewkjUorWlcH4H18b5awFxGcKuEsOyIR2ZSU5AODlkDJ0e94D2CT NblF4OnKWn7F60VBCQSUKMFxRUt+fTWNgkkuBFRZVFbL/BdqhaozZVXfHSucQvjE TXQpoFfPJuM2P6QK9cvB3TraMY= Received: (qmail 68383 invoked by alias); 18 Jun 2015 07:25:28 -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 68374 invoked by uid 89); 18 Jun 2015 07:25:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 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; Thu, 18 Jun 2015 07:25:26 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Z5UCP-0002o9-8v from Tom_deVries@mentor.com ; Thu, 18 Jun 2015 00:25:21 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Thu, 18 Jun 2015 08:25:20 +0100 Message-ID: <55827255.60302@mentor.com> Date: Thu, 18 Jun 2015 09:25:09 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: GCC Patches CC: Jakub Jelinek , Richard Biener Subject: [committed, gomp4] Rewrite virtuals into lcssa in transform_to_exit_first_loop_alt Hi, transform_to_exit_first_loop contains the following comment: ... /* Make sure that we have phi nodes on exit for all loop header phis (create_parallel_loop requires that). */ ... I ran into a problem where after transform_to_exit_first_loop_alt this property does not hold for virtuals, and we run into trouble in create_parallel_loop. The patch ensures that the property holds at the start of transform_to_exit_first_loop_alt, which has as effect that: - we simplify transform_to_exit_first_loop_alt a bit, and - since the property is kept by transform_to_exit_first_loop_alt, the property will be valid after transform_to_exit_first_loop_alt. Bootstrapped and reg-tested on x86_64. Committed to gomp-4_0-branch. OK for trunk? Thanks, - Tom Rewrite virtuals into lcssa in transform_to_exit_first_loop_alt 2015-06-18 Tom de Vries * tree-parloops.c (rewrite_virtuals_into_loop_closed_ssa): New function. (transform_to_exit_first_loop_alt): Use rewrite_virtuals_into_loop_closed_ssa. --- gcc/tree-parloops.c | 92 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index 678e458..0661b78 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -1526,6 +1526,74 @@ replace_uses_in_bbs_by (tree name, tree val, bitmap bbs) } } +/* Ensure a virtual phi is present in the exit block, if LOOP contains a vdef. + In other words, ensure loop-closed ssa normal form for virtuals. */ + +static void +rewrite_virtuals_into_loop_closed_ssa (struct loop *loop) +{ + gphi *phi; + edge exit = single_dom_exit (loop); + + phi = NULL; + for (gphi_iterator gsi = gsi_start_phis (loop->header); + !gsi_end_p (gsi); + gsi_next (&gsi)) + { + if (virtual_operand_p (PHI_RESULT (gsi.phi ()))) + { + phi = gsi.phi (); + break; + } + } + + if (phi == NULL) + return; + + tree final_loop = PHI_ARG_DEF_FROM_EDGE (phi, single_succ_edge (loop->latch)); + + phi = NULL; + for (gphi_iterator gsi = gsi_start_phis (exit->dest); + !gsi_end_p (gsi); + gsi_next (&gsi)) + { + if (virtual_operand_p (PHI_RESULT (gsi.phi ()))) + { + phi = gsi.phi (); + break; + } + } + + if (phi != NULL) + { + tree final_exit = PHI_ARG_DEF_FROM_EDGE (phi, exit); + gcc_assert (operand_equal_p (final_loop, final_exit, 0)); + return; + } + + tree res_new = copy_ssa_name (final_loop, NULL); + gphi *nphi = create_phi_node (res_new, exit->dest); + + /* Gather the bbs dominated by the exit block. */ + bitmap exit_dominated = BITMAP_ALLOC (NULL); + bitmap_set_bit (exit_dominated, exit->dest->index); + vec exit_dominated_vec + = get_dominated_by (CDI_DOMINATORS, exit->dest); + + int i; + basic_block dom_bb; + FOR_EACH_VEC_ELT (exit_dominated_vec, i, dom_bb) + bitmap_set_bit (exit_dominated, dom_bb->index); + + exit_dominated_vec.release (); + + replace_uses_in_bbs_by (final_loop, res_new, exit_dominated); + + add_phi_arg (nphi, final_loop, exit, UNKNOWN_LOCATION); + + BITMAP_FREE (exit_dominated); +} + /* Do transformation from: : @@ -1646,18 +1714,11 @@ transform_to_exit_first_loop_alt (struct loop *loop, tree control = gimple_cond_lhs (cond_stmt); edge e; - /* Gather the bbs dominated by the exit block. */ - bitmap exit_dominated = BITMAP_ALLOC (NULL); - bitmap_set_bit (exit_dominated, exit_block->index); - vec exit_dominated_vec - = get_dominated_by (CDI_DOMINATORS, exit_block); - - int i; - basic_block dom_bb; - FOR_EACH_VEC_ELT (exit_dominated_vec, i, dom_bb) - bitmap_set_bit (exit_dominated, dom_bb->index); - - exit_dominated_vec.release (); + /* Rewriting virtuals into loop-closed ssa normal form makes this + transformation simpler. It also ensures that the virtuals are in + loop-closed ssa normal from after the transformation, which is required by + create_parallel_loop. */ + rewrite_virtuals_into_loop_closed_ssa (loop); /* Create the new_header block. */ basic_block new_header = split_block_before_cond_jump (exit->src); @@ -1690,6 +1751,7 @@ transform_to_exit_first_loop_alt (struct loop *loop, vec *v = redirect_edge_var_map_vector (post_inc_edge); edge_var_map *vm; gphi_iterator gsi; + int i; for (gsi = gsi_start_phis (header), i = 0; !gsi_end_p (gsi) && v->iterate (i, &vm); gsi_next (&gsi), i++) @@ -1707,10 +1769,9 @@ transform_to_exit_first_loop_alt (struct loop *loop, /* Replace ivtmp/sum_b with ivtmp/sum_c in header phi. */ add_phi_arg (phi, res_c, post_cond_edge, UNKNOWN_LOCATION); - /* Replace sum_b with sum_c in exit phi. Loop-closed ssa does not hold - for virtuals, so we cannot get away with exit_block only. */ + /* Replace sum_b with sum_c in exit phi. */ tree res_b = redirect_edge_var_map_def (vm); - replace_uses_in_bbs_by (res_b, res_c, exit_dominated); + replace_uses_in_bb_by (res_b, res_c, exit_block); struct reduction_info *red = reduction_phi (reduction_list, phi); gcc_assert (virtual_operand_p (res_a) @@ -1725,7 +1786,6 @@ transform_to_exit_first_loop_alt (struct loop *loop, } } gcc_assert (gsi_end_p (gsi) && !v->iterate (i, &vm)); - BITMAP_FREE (exit_dominated); /* Set the preheader argument of the new phis to ivtmp/sum_init. */ flush_pending_stmts (entry); -- 1.9.1