From patchwork Mon Nov 23 11:23:47 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: 547506 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 62B04140273 for ; Mon, 23 Nov 2015 22:24:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=u5Ffcw1b; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=hDBg9V7HBY3FuSxnP eq/Tpwm0tSMMZa7zRcpWnEDbNDbWDFYoW6WiyNUUiDdo6WFFKm0YR+i8XNe7a8gN 5lZjOaOBz+EeCddBqtQfUAytf5Hvo0VLnST0ARmhd4yAQ5766rXIgITKJOs8RRSO JCixUAApZw94cIuzzP2zTSeOG0= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=umX7awj66xrggLreoIL5mF5 M8yI=; b=u5Ffcw1b0ql+dGGu+RueNKSA7nfUJ6aAeBljpWl9f4ml6NvM4Z5443k 6aICIsiW9ayvw1mBIGD+uaClOEEdOIy6w8B1TktdLhQowM5We/r03mwFkdhtyK5F pwlelxQUEHl3cywiExhAYsRWGG3YbpcjPHav52VcrtY/kz+y09Pc= Received: (qmail 16575 invoked by alias); 23 Nov 2015 11:24: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 16554 invoked by uid 89); 23 Nov 2015 11:24:48 -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, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 23 Nov 2015 11:24:47 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40554) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1a0pEi-0004ZS-Ea for gcc-patches@gnu.org; Mon, 23 Nov 2015 06:24:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0pEe-0006eU-Nu for gcc-patches@gnu.org; Mon, 23 Nov 2015 06:24:44 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:54696) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0pEe-0006dv-FI for gcc-patches@gnu.org; Mon, 23 Nov 2015 06:24:40 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1a0pEc-0000Ff-Ef from Tom_deVries@mentor.com ; Mon, 23 Nov 2015 03:24:38 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 23 Nov 2015 11:24:34 +0000 Subject: Re: [PATCH] Don't reapply loops flags if unnecessary in loop_optimizer_init To: Richard Biener References: <5640BD31.2060602@mentor.com> <5640FB07.6010008@mentor.com> <5649C41A.40403@mentor.com> <564DA4CA.3020506@mentor.com> <56524F8D.9090003@mentor.com> CC: "gcc-patches@gnu.org" , Jakub Jelinek From: Tom de Vries Message-ID: <5652F743.4020807@mentor.com> Date: Mon, 23 Nov 2015 12:23:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 23/11/15 11:29, Richard Biener wrote: > On Mon, 23 Nov 2015, Tom de Vries wrote: > >> [ was: Re: [PATCH, 10/16] Add pass_oacc_kernels pass group in passes.def ] >> >> On 20/11/15 11:37, Richard Biener wrote: >>> I'd rather make loop_optimizer_init do nothing >>> if requested flags are already set and no fixup is needed and >>> call the above unconditionally. Thus sth like >>> >>> Index: gcc/loop-init.c >>> =================================================================== >>> --- gcc/loop-init.c (revision 230649) >>> +++ gcc/loop-init.c (working copy) >>> @@ -103,7 +103,11 @@ loop_optimizer_init (unsigned flags) >>> calculate_dominance_info (CDI_DOMINATORS); >>> >>> if (!needs_fixup) >>> - checking_verify_loop_structure (); >>> + { >>> + checking_verify_loop_structure (); >>> + if (loops_state_satisfies_p (flags)) >>> + goto out; >>> + } >>> >>> /* Clear all flags. */ >>> if (recorded_exits) >>> @@ -122,11 +126,12 @@ loop_optimizer_init (unsigned flags) >>> /* Apply flags to loops. */ >>> apply_loop_flags (flags); >>> >>> + checking_verify_loop_structure (); >>> + >>> +out: >>> /* Dump loops. */ >>> flow_loops_dump (dump_file, NULL, 1); >>> >>> - checking_verify_loop_structure (); >>> - >>> timevar_pop (TV_LOOP_INIT); >>> } >> >> This patch implements that approach, but the patch is slightly more >> complicated because of the need to handle LOOPS_MAY_HAVE_MULTIPLE_LATCHES >> differently than the rest of the flags. >> >> Bootstrapped and reg-tested on x86_64. >> >> OK for stage3 trunk? > > Let's revisit this during stage1 if the scev_initialized () thing > SLP vectorization uses works, ok? > OK, I'll give that a try. FTR, attached two patches are an attempt at a cleaner solution for pass_slp_vectorize::execute (in combination with patch "Don't reapply loops flags if unnecessary in loop_optimizer_init"). The first patch introduces a property PROP_scev, set for the duration of the loop pipeline. It allows us to call scev_initialize and scev_finalize unconditionally. Outside the loop pipeline calling the functions has the usual effect. Inside the loop pipeline, calling the functions has no effect. The second patch introduces a property PROP_loops_normal_re_lcssa, set for the duration of the loop pipeline. It allows us (in combination with "Don't reapply loops flags if unnecessary in loop_optimizer_init") to call loop_optimizer_init and loop_optimizer_finalize unconditionally. Outside the loop pipeline, calling the functions has the usual effect. Inside the loop pipeline, calling loop_optimizer_finalize has no effect, and calling loop_optimizer_initialize has no effect unless a fixup or a new loop property is needed. Thanks, - Tom Add PROP_loops_normal_re_lcssa --- gcc/loop-init.c | 13 +++++++++++++ gcc/tree-pass.h | 3 +++ gcc/tree-ssa-loop.c | 4 ++-- gcc/tree-vectorizer.c | 11 ++--------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gcc/loop-init.c b/gcc/loop-init.c index 4b72cab..9ce3e9e 100644 --- a/gcc/loop-init.c +++ b/gcc/loop-init.c @@ -100,6 +100,10 @@ loop_optimizer_init (unsigned flags) bool needs_fixup = loops_state_satisfies_p (LOOPS_NEED_FIXUP); gcc_assert (cfun->curr_properties & PROP_loops); + if (cfun->curr_properties & PROP_loops_normal_re_lcssa) + gcc_assert (loops_state_satisfies_p (LOOPS_NORMAL + | LOOPS_HAVE_RECORDED_EXITS + | LOOP_CLOSED_SSA)); /* Ensure that the dominators are computed, like flow_loops_find does. */ calculate_dominance_info (CDI_DOMINATORS); @@ -151,6 +155,15 @@ loop_optimizer_finalize (struct function *fn) struct loop *loop; basic_block bb; + if (fn->curr_properties & PROP_loops_normal_re_lcssa) + { + gcc_assert (loops_state_satisfies_p (fn, LOOPS_NORMAL + | LOOPS_HAVE_RECORDED_EXITS + | LOOP_CLOSED_SSA)); + gcc_assert (!loops_state_satisfies_p (fn, LOOPS_NEED_FIXUP)); + return; + } + timevar_push (TV_LOOP_FINI); if (loops_state_satisfies_p (fn, LOOPS_HAVE_RECORDED_EXITS)) diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 4e66b2c..c43a5f3 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -228,6 +228,9 @@ protected: current choices have been optimized. */ #define PROP_scev (1 << 16) /* preserve scev info. */ +/* preserve loop structures in LOOPS_NORMAL with recorded exits, and in loop + closed ssa. */ +#define PROP_loops_normal_re_lcssa (1 << 17) #define PROP_trees \ (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp) diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c index 739fda7..73fbb43 100644 --- a/gcc/tree-ssa-loop.c +++ b/gcc/tree-ssa-loop.c @@ -290,7 +290,7 @@ const pass_data pass_data_tree_loop_init = OPTGROUP_LOOP, /* optinfo_flags */ TV_NONE, /* tv_id */ PROP_cfg, /* properties_required */ - PROP_scev, /* properties_provided */ + PROP_loops_normal_re_lcssa | PROP_scev, /* properties_provided */ 0, /* properties_destroyed */ 0, /* todo_flags_start */ 0, /* todo_flags_finish */ @@ -524,7 +524,7 @@ make_pass_iv_optimize (gcc::context *ctxt) static unsigned int tree_ssa_loop_done (void) { - cfun->curr_properties &= ~PROP_scev; + cfun->curr_properties &= ~(PROP_loops_normal_re_lcssa | PROP_scev); free_numbers_of_iterations_estimates (cfun); scev_finalize (); loop_optimizer_finalize (); diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index b06433d..503f227 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -727,11 +727,7 @@ pass_slp_vectorize::execute (function *fun) { basic_block bb; - bool in_loop_pipeline = scev_initialized_p (); - if (!in_loop_pipeline) - { - loop_optimizer_init (LOOPS_NORMAL); - } + loop_optimizer_init (LOOPS_NORMAL); scev_initialize (); /* Mark all stmts as not belonging to the current region and unvisited. */ @@ -758,10 +754,7 @@ pass_slp_vectorize::execute (function *fun) free_stmt_vec_info_vec (); scev_finalize (); - if (!in_loop_pipeline) - { - loop_optimizer_finalize (); - } + loop_optimizer_finalize (); return 0; }