From patchwork Mon Jun 13 08:57:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 69852 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1435491qgf; Mon, 13 Jun 2016 01:58:11 -0700 (PDT) X-Received: by 10.36.103.4 with SMTP id u4mr16568651itc.45.1465808291737; Mon, 13 Jun 2016 01:58:11 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 186si31166676pfy.175.2016.06.13.01.58.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jun 2016 01:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-429642-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-429642-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-429642-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=bl7B0/2GDxmIExX hlR4QuoKcOQe4vqd4N6vci5Jgm9iMbdxnuoWoWZtWbCraJn2PxsSsJCyDcklzraR OEafK5O3vyzDVwWB5KsA+/2ZBDDURCSROJE8nB5OsUQKy0oRmCXYarD8SiK5/inj JraIaB4H7iPPEHU67htPlDFs4xp0= 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 :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=eMD67neJbPq1MiG0wYYKy VJsPdE=; b=RY2Egi6o483lcme7BddrTf6zUVbUVvrhSdILKQ/mAhZplN/znM4sr 5TXUzrD28Z9d9TDiu3ch1hE7RCuXCg/DIVHEn74hbVy0rUoqBRw0MZcP6QX/MUCg NEq9QKQNNcpudjFywryO3GFuap61KEf4EDsw3ItUluMSmcSQ198SD0= Received: (qmail 27838 invoked by alias); 13 Jun 2016 08:57:58 -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 27824 invoked by uid 89); 13 Jun 2016 08:57:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=82526, sk:dgrequ, sk:dg-requ, UD:aarch64.c X-HELO: mail-io0-f178.google.com Received: from mail-io0-f178.google.com (HELO mail-io0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 13 Jun 2016 08:57:47 +0000 Received: by mail-io0-f178.google.com with SMTP id d2so27206260iof.0 for ; Mon, 13 Jun 2016 01:57:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=eK7/KBevPrT9Ho/2TRiMJrpO7pLirN6SKa4aroqjdBY=; b=O4D+LFaBOgoxE0xdEbuKPSCOnu681eojB0ncEMbsFkrd70qROGo6I80ZVUroQx937f 68+++1yBANyX9YCSddehmperR5V0NUUzNgD+uNcf8LpCnU2ewOzDPUrd7UmbR6oGO2zW Pdu7LSP7ETnz4AtzBfjwK7IKJZP2Tr4Uei95sODSG+uG6xorDnWkt4BOzdlkkVKcSkb5 brEgkTyIC9+X/Hi4KfzbeO0wHiKBYphuNlnLem+iOFMM3/YsOBK9V+jg2pfb0yrzgC6e ZSIe4gYZ97JkjZY+vDiS8IhIY+czgWREkm2dK8WXnusNWsxnrYqdy3eMbIGW7Qn6yFnR YAIw== X-Gm-Message-State: ALyK8tJbk/up2KlBc0C1kX5BsHoxzhqrvOBWbIVaevGUikGfi0DKOCL9TB9zx6KCWBsR+PulCVbzzwhNNJoUUGCw X-Received: by 10.107.159.84 with SMTP id i81mr20118824ioe.29.1465808264737; Mon, 13 Jun 2016 01:57:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.48.133 with HTTP; Mon, 13 Jun 2016 01:57:43 -0700 (PDT) In-Reply-To: References: <20160602150106.GA48112@kam.mff.cuni.cz> <20160603080543.GA78035@kam.mff.cuni.cz> <20160608150855.GB2550@atrey.karlin.mff.cuni.cz> <20160609202322.GB98613@kam.mff.cuni.cz> From: Prathamesh Kulkarni Date: Mon, 13 Jun 2016 14:27:43 +0530 Message-ID: Subject: Re: move increase_alignment from simple to regular ipa pass To: Richard Biener Cc: Jan Hubicka , David Edelsohn , GCC Patches , "William J. Schmidt" , Segher Boessenkool X-IsSubscribed: yes On 10 June 2016 at 16:47, Richard Biener wrote: > On Fri, 10 Jun 2016, Prathamesh Kulkarni wrote: > >> On 10 June 2016 at 01:53, Jan Hubicka wrote: >> >> On 8 June 2016 at 20:38, Jan Hubicka wrote: >> >> >> I think it would be nice to work towards transitioning >> >> >> flag_section_anchors to a flag on varpool nodes, thereby removing >> >> >> the Optimization flag from common.opt:fsection-anchors >> >> >> >> >> >> That would simplify the walk over varpool candidates. >> >> > >> >> > Makes sense to me, too. There are more candidates for sutff that should be >> >> > variable specific in common.opt (such as variable alignment, -fdata-sctions, >> >> > -fmerge-constants) and targets. We may try to do it in an easy to extend way >> >> > so incrementally we can get rid of those global flags, too. >> >> In this version I removed Optimization from fsection-anchors entry in >> >> common.opt, >> >> and gated the increase_alignment pass on flag_section_anchors != 0. >> >> Cross tested on arm*-*-*, aarch64*-*-*. >> >> Does it look OK ? >> > >> > If you go this way you will need to do something sane for LTO. Here one can compile >> > some object files with -fsection-anchors and other without and link with random setting >> > (because in traditional compilation linktime flags does not matter). >> > >> > For global flags we have magic in merge_and_complain that determines flags to pass >> > to the LTO compiler. >> > It is not very robust though. >> >> > >> >> > One thing that needs to be done for LTO is sane merging, I guess in this case >> >> > it is clear that the variable should be anchored when its previaling definition >> >> > is. >> >> Um could we determine during WPA if symbol is a section anchor for merging ? >> >> Seems to me SYMBOL_REF_ANCHOR_P is defined only on DECL_RTL and not at >> >> tree level. >> >> Do we have DECL_RTL info available during WPA ? >> > >> > We don't have anchros computed, but we can decide whether we want to potentially >> > anchor the variable if we can. >> > >> > I would say all you need is to have section_anchor flag in varpool node itself >> > which controls RTL production. At varpool_finalize_decl you will set it >> > according to flag_varpool and stream it to LTO objects. At WPA when doing >> > linking, the section_anchor flag of the previaling decl wins.. >> Thanks for the suggestions. >> IIUC, we want to add new section_anchor flag to varpool_node class >> and set it in varpool_node::finalize_decl and stream it to LTO byte-code, >> and then during WPA set section_anchor_flag during symbol merging if it is set >> for prevailing decl. > > Yes. > >> In the increase_alignment_pass if a vnode has section_anchor flag set, >> we will walk all functions that reference it to check if they have >> -ftree-loop-vectorize set. >> Is that correct ? > > Yes. > >> Could you please elaborate a bit more on "at varpool_finalize_decl you will >> set section_anchor flag according to flag_varpool" ? >> flag_varpool doesn't appear to be defined. > > flag_section_anchors. Hi, I have done the changes in this version In varpool_node::finalize_decl, I just set vnode->section_anchor = flag_section_anchors. Should that be sufficient ? I tried with a couple of test-cases, once with prevailing->section_anchors == 1 and once with entry->section_anchors == 1 and it appears prevailing->section_anchor always took precedence. So I wonder if the change to lto_symtab_merge () in the patch is necessary ? Re-introduced flag_ipa_increase_alignment to gate the pass on, so it runs only for targets supporting section anchors. Cross tested on aarch64*-*-*, arm*-*-*. Thanks, Prathamesh > > Richard. > >> Thanks, >> Prathamesh >> > >> > Honza >> >> >> >> Thanks, >> >> Prathamesh >> >> > >> >> > Honza >> >> >> >> >> >> Richard. >> >> >> >> >> >> > Thanks, >> >> >> > Prathamesh >> >> >> > > >> >> >> > > Honza >> >> >> > >> >> >> >> > >> Richard. >> >> >> > >> >> >> > >> >> >> >> >> >> -- >> >> >> Richard Biener >> >> >> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg) >> > >> >> diff --git a/gcc/common.opt b/gcc/common.opt >> >> index f0d7196..f93f26c 100644 >> >> --- a/gcc/common.opt >> >> +++ b/gcc/common.opt >> >> @@ -2133,7 +2133,7 @@ Common Report Var(flag_sched_dep_count_heuristic) Init(1) Optimization >> >> Enable the dependent count heuristic in the scheduler. >> >> >> >> fsection-anchors >> >> -Common Report Var(flag_section_anchors) Optimization >> >> +Common Report Var(flag_section_anchors) >> >> Access data in the same section from shared anchor points. >> >> >> >> fsee >> >> diff --git a/gcc/passes.def b/gcc/passes.def >> >> index 3647e90..3a8063c 100644 >> >> --- a/gcc/passes.def >> >> +++ b/gcc/passes.def >> >> @@ -138,12 +138,12 @@ along with GCC; see the file COPYING3. If not see >> >> PUSH_INSERT_PASSES_WITHIN (pass_ipa_tree_profile) >> >> NEXT_PASS (pass_feedback_split_functions); >> >> POP_INSERT_PASSES () >> >> - NEXT_PASS (pass_ipa_increase_alignment); >> >> NEXT_PASS (pass_ipa_tm); >> >> NEXT_PASS (pass_ipa_lower_emutls); >> >> TERMINATE_PASS_LIST (all_small_ipa_passes) >> >> >> >> INSERT_PASSES_AFTER (all_regular_ipa_passes) >> >> + NEXT_PASS (pass_ipa_increase_alignment); >> >> NEXT_PASS (pass_ipa_whole_program_visibility); >> >> NEXT_PASS (pass_ipa_profile); >> >> NEXT_PASS (pass_ipa_icf); >> >> diff --git a/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c b/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c >> >> new file mode 100644 >> >> index 0000000..74eaed8 >> >> --- /dev/null >> >> +++ b/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c >> >> @@ -0,0 +1,25 @@ >> >> +/* { dg-do compile } */ >> >> +/* { dg-require-effective-target section_anchors } */ >> >> +/* { dg-require-effective-target vect_int } */ >> >> + >> >> +#define N 32 >> >> + >> >> +/* Clone of section-anchors-vect-70.c with foo() having -fno-tree-loop-vectorize. */ >> >> + >> >> +static struct A { >> >> + int p1, p2; >> >> + int e[N]; >> >> +} a, b, c; >> >> + >> >> +__attribute__((optimize("-fno-tree-loop-vectorize"))) >> >> +int foo(void) >> >> +{ >> >> + for (int i = 0; i < N; i++) >> >> + a.e[i] = b.e[i] + c.e[i]; >> >> + >> >> + return a.e[0]; >> >> +} >> >> + >> >> +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target aarch64*-*-* } } } */ >> >> +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target powerpc64*-*-* } } } */ >> >> +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target arm*-*-* } } } */ >> >> diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h >> >> index 36299a6..d36aa1d 100644 >> >> --- a/gcc/tree-pass.h >> >> +++ b/gcc/tree-pass.h >> >> @@ -483,7 +483,7 @@ extern simple_ipa_opt_pass *make_pass_local_optimization_passes (gcc::context *c >> >> >> >> extern ipa_opt_pass_d *make_pass_ipa_whole_program_visibility (gcc::context >> >> *ctxt); >> >> -extern simple_ipa_opt_pass *make_pass_ipa_increase_alignment (gcc::context >> >> +extern ipa_opt_pass_d *make_pass_ipa_increase_alignment (gcc::context >> >> *ctxt); >> >> extern ipa_opt_pass_d *make_pass_ipa_inline (gcc::context *ctxt); >> >> extern simple_ipa_opt_pass *make_pass_ipa_free_lang_data (gcc::context *ctxt); >> >> diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c >> >> index 2669813..d34e560 100644 >> >> --- a/gcc/tree-vectorizer.c >> >> +++ b/gcc/tree-vectorizer.c >> >> @@ -899,6 +899,34 @@ get_vec_alignment_for_type (tree type) >> >> return (alignment > TYPE_ALIGN (type)) ? alignment : 0; >> >> } >> >> >> >> +/* Return true if alignment should be increased for this vnode. >> >> + This is done if every function that references/referring to vnode >> >> + has flag_tree_loop_vectorize and flag_section_anchors set. */ >> >> + >> >> +static bool >> >> +increase_alignment_p (varpool_node *vnode) >> >> +{ >> >> + ipa_ref *ref; >> >> + >> >> + for (int i = 0; vnode->iterate_reference (i, ref); i++) >> >> + if (cgraph_node *cnode = dyn_cast (ref->referred)) >> >> + { >> >> + struct cl_optimization *opts = opts_for_fn (cnode->decl); >> >> + if (!opts->x_flag_tree_loop_vectorize) >> >> + return false; >> >> + } >> >> + >> >> + for (int i = 0; vnode->iterate_referring (i, ref); i++) >> >> + if (cgraph_node *cnode = dyn_cast (ref->referring)) >> >> + { >> >> + struct cl_optimization *opts = opts_for_fn (cnode->decl); >> >> + if (!opts->x_flag_tree_loop_vectorize) >> >> + return false; >> >> + } >> >> + >> >> + return true; >> >> +} >> >> + >> >> /* Entry point to increase_alignment pass. */ >> >> static unsigned int >> >> increase_alignment (void) >> >> @@ -916,7 +944,8 @@ increase_alignment (void) >> >> >> >> if ((decl_in_symtab_p (decl) >> >> && !symtab_node::get (decl)->can_increase_alignment_p ()) >> >> - || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl)) >> >> + || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl) >> >> + || !increase_alignment_p (vnode)) >> >> continue; >> >> >> >> alignment = get_vec_alignment_for_type (TREE_TYPE (decl)); >> >> @@ -938,7 +967,7 @@ namespace { >> >> >> >> const pass_data pass_data_ipa_increase_alignment = >> >> { >> >> - SIMPLE_IPA_PASS, /* type */ >> >> + IPA_PASS, /* type */ >> >> "increase_alignment", /* name */ >> >> OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ >> >> TV_IPA_OPT, /* tv_id */ >> >> @@ -949,17 +978,26 @@ const pass_data pass_data_ipa_increase_alignment = >> >> 0, /* todo_flags_finish */ >> >> }; >> >> >> >> -class pass_ipa_increase_alignment : public simple_ipa_opt_pass >> >> +class pass_ipa_increase_alignment : public ipa_opt_pass_d >> >> { >> >> public: >> >> pass_ipa_increase_alignment (gcc::context *ctxt) >> >> - : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt) >> >> + : ipa_opt_pass_d (pass_data_ipa_increase_alignment, ctxt, >> >> + NULL, /* generate_summary */ >> >> + NULL, /* write summary */ >> >> + NULL, /* read summary */ >> >> + NULL, /* write optimization summary */ >> >> + NULL, /* read optimization summary */ >> >> + NULL, /* stmt fixup */ >> >> + 0, /* function_transform_todo_flags_start */ >> >> + NULL, /* transform function */ >> >> + NULL )/* variable transform */ >> >> {} >> >> >> >> /* opt_pass methods: */ >> >> virtual bool gate (function *) >> >> { >> >> - return flag_section_anchors && flag_tree_loop_vectorize; >> >> + return flag_section_anchors != 0; >> >> } >> >> >> >> virtual unsigned int execute (function *) { return increase_alignment (); } >> >> @@ -968,7 +1006,7 @@ public: >> >> >> >> } // anon namespace >> >> >> >> -simple_ipa_opt_pass * >> >> +ipa_opt_pass_d * >> >> make_pass_ipa_increase_alignment (gcc::context *ctxt) >> >> { >> >> return new pass_ipa_increase_alignment (ctxt); >> > >> >> > > -- > Richard Biener > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index ecafe63..41ac408 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1874,6 +1874,9 @@ public: if we did not do any inter-procedural code movement. */ unsigned used_by_single_function : 1; + /* Set if -fsection-anchors is set. */ + unsigned section_anchor : 1; + private: /* Assemble thunks and aliases associated to varpool node. */ void assemble_aliases (void); diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 4bfcad7..e75d5c0 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -800,6 +800,9 @@ varpool_node::finalize_decl (tree decl) it is available to notice_global_symbol. */ node->definition = true; notice_global_symbol (decl); + + node->section_anchor = flag_section_anchors; + if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl) /* Traditionally we do not eliminate static variables when not optimizing and when not doing toplevel reoder. */ diff --git a/gcc/common.opt b/gcc/common.opt index f0d7196..e497795 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1590,6 +1590,10 @@ fira-algorithm= Common Joined RejectNegative Enum(ira_algorithm) Var(flag_ira_algorithm) Init(IRA_ALGORITHM_CB) Optimization -fira-algorithm=[CB|priority] Set the used IRA algorithm. +fipa-increase_alignment +Common Report Var(flag_ipa_increase_alignment) Init(0) Optimization +Option to gate increase_alignment ipa pass. + Enum Name(ira_algorithm) Type(enum ira_algorithm) UnknownError(unknown IRA algorithm %qs) @@ -2133,7 +2137,7 @@ Common Report Var(flag_sched_dep_count_heuristic) Init(1) Optimization Enable the dependent count heuristic in the scheduler. fsection-anchors -Common Report Var(flag_section_anchors) Optimization +Common Report Var(flag_section_anchors) Access data in the same section from shared anchor points. fsee diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index a0db3a4..1482566 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -8252,6 +8252,8 @@ aarch64_override_options (void) aarch64_register_fma_steering (); + /* Enable increase_alignment pass. */ + flag_ipa_increase_alignment = 1; } /* Implement targetm.override_options_after_change. */ diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 3503c15..b7f448e 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -3458,6 +3458,9 @@ arm_option_override (void) /* Init initial mode for testing. */ thumb_flipper = TARGET_THUMB; + + /* Enable increase_alignment pass. */ + flag_ipa_increase_alignment = 1; } static void diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 2d7df6b..ed59068 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -5011,6 +5011,9 @@ rs6000_option_override (void) = { pass_analyze_swaps, "cse1", 1, PASS_POS_INSERT_BEFORE }; register_pass (&analyze_swaps_info); + + /* Enable increase_alignment pass. */ + flag_ipa_increase_alignment = 1; } diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index 5cef2ba..289d9c3 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -627,6 +627,7 @@ lto_output_varpool_node (struct lto_simple_output_block *ob, varpool_node *node, bp_pack_value (&bp, node->tls_model, 3); bp_pack_value (&bp, node->used_by_single_function, 1); bp_pack_value (&bp, node->need_bounds_init, 1); + bp_pack_value (&bp, node->section_anchor, 1); streamer_write_bitpack (&bp); group = node->get_comdat_group (); @@ -1401,6 +1402,7 @@ input_varpool_node (struct lto_file_decl_data *file_data, node->tls_model = (enum tls_model)bp_unpack_value (&bp, 3); node->used_by_single_function = (enum tls_model)bp_unpack_value (&bp, 1); node->need_bounds_init = bp_unpack_value (&bp, 1); + node->section_anchor = bp_unpack_value (&bp, 1); group = read_identifier (ib); if (group) { diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index ce9e146..7f09f3a 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -342,6 +342,13 @@ lto_symtab_merge (symtab_node *prevailing, symtab_node *entry) The type compatibility checks or the completing of types has properly dealt with most issues. */ + /* ??? is this assert necessary ? */ + varpool_node *v_prevailing = dyn_cast (prevailing); + varpool_node *v_entry = dyn_cast (entry); + gcc_assert (v_prevailing && v_entry); + /* section_anchor of prevailing_decl wins. */ + v_entry->section_anchor = v_prevailing->section_anchor; + /* The following should all not invoke fatal errors as in non-LTO mode the linker wouldn't complain either. Just emit warnings. */ diff --git a/gcc/passes.def b/gcc/passes.def index 3647e90..3a8063c 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -138,12 +138,12 @@ along with GCC; see the file COPYING3. If not see PUSH_INSERT_PASSES_WITHIN (pass_ipa_tree_profile) NEXT_PASS (pass_feedback_split_functions); POP_INSERT_PASSES () - NEXT_PASS (pass_ipa_increase_alignment); NEXT_PASS (pass_ipa_tm); NEXT_PASS (pass_ipa_lower_emutls); TERMINATE_PASS_LIST (all_small_ipa_passes) INSERT_PASSES_AFTER (all_regular_ipa_passes) + NEXT_PASS (pass_ipa_increase_alignment); NEXT_PASS (pass_ipa_whole_program_visibility); NEXT_PASS (pass_ipa_profile); NEXT_PASS (pass_ipa_icf); diff --git a/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c b/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c new file mode 100644 index 0000000..74eaed8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/aligned-section-anchors-vect-73.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target section_anchors } */ +/* { dg-require-effective-target vect_int } */ + +#define N 32 + +/* Clone of section-anchors-vect-70.c with foo() having -fno-tree-loop-vectorize. */ + +static struct A { + int p1, p2; + int e[N]; +} a, b, c; + +__attribute__((optimize("-fno-tree-loop-vectorize"))) +int foo(void) +{ + for (int i = 0; i < N; i++) + a.e[i] = b.e[i] + c.e[i]; + + return a.e[0]; +} + +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target aarch64*-*-* } } } */ +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target powerpc64*-*-* } } } */ +/* { dg-final { scan-ipa-dump-times "Increasing alignment of decl" 0 "increase_alignment" { target arm*-*-* } } } */ diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 36299a6..d36aa1d 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -483,7 +483,7 @@ extern simple_ipa_opt_pass *make_pass_local_optimization_passes (gcc::context *c extern ipa_opt_pass_d *make_pass_ipa_whole_program_visibility (gcc::context *ctxt); -extern simple_ipa_opt_pass *make_pass_ipa_increase_alignment (gcc::context +extern ipa_opt_pass_d *make_pass_ipa_increase_alignment (gcc::context *ctxt); extern ipa_opt_pass_d *make_pass_ipa_inline (gcc::context *ctxt); extern simple_ipa_opt_pass *make_pass_ipa_free_lang_data (gcc::context *ctxt); diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index 2669813..abd7030 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -899,6 +899,34 @@ get_vec_alignment_for_type (tree type) return (alignment > TYPE_ALIGN (type)) ? alignment : 0; } +/* Return true if alignment should be increased for this vnode. + This is done if every function that references/referring to vnode + has flag_tree_loop_vectorize set. */ + +static bool +increase_alignment_p (varpool_node *vnode) +{ + ipa_ref *ref; + + for (int i = 0; vnode->iterate_reference (i, ref); i++) + if (cgraph_node *cnode = dyn_cast (ref->referred)) + { + struct cl_optimization *opts = opts_for_fn (cnode->decl); + if (!opts->x_flag_tree_loop_vectorize) + return false; + } + + for (int i = 0; vnode->iterate_referring (i, ref); i++) + if (cgraph_node *cnode = dyn_cast (ref->referring)) + { + struct cl_optimization *opts = opts_for_fn (cnode->decl); + if (!opts->x_flag_tree_loop_vectorize) + return false; + } + + return true; +} + /* Entry point to increase_alignment pass. */ static unsigned int increase_alignment (void) @@ -914,9 +942,12 @@ increase_alignment (void) tree decl = vnode->decl; unsigned int alignment; - if ((decl_in_symtab_p (decl) - && !symtab_node::get (decl)->can_increase_alignment_p ()) - || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl)) + if (!vnode->section_anchor + || (decl_in_symtab_p (decl) + && !symtab_node::get (decl)->can_increase_alignment_p ()) + || DECL_USER_ALIGN (decl) + || DECL_ARTIFICIAL (decl) + || !increase_alignment_p (vnode)) continue; alignment = get_vec_alignment_for_type (TREE_TYPE (decl)); @@ -938,7 +969,7 @@ namespace { const pass_data pass_data_ipa_increase_alignment = { - SIMPLE_IPA_PASS, /* type */ + IPA_PASS, /* type */ "increase_alignment", /* name */ OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ TV_IPA_OPT, /* tv_id */ @@ -949,17 +980,26 @@ const pass_data pass_data_ipa_increase_alignment = 0, /* todo_flags_finish */ }; -class pass_ipa_increase_alignment : public simple_ipa_opt_pass +class pass_ipa_increase_alignment : public ipa_opt_pass_d { public: pass_ipa_increase_alignment (gcc::context *ctxt) - : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt) + : ipa_opt_pass_d (pass_data_ipa_increase_alignment, ctxt, + NULL, /* generate_summary */ + NULL, /* write summary */ + NULL, /* read summary */ + NULL, /* write optimization summary */ + NULL, /* read optimization summary */ + NULL, /* stmt fixup */ + 0, /* function_transform_todo_flags_start */ + NULL, /* transform function */ + NULL )/* variable transform */ {} /* opt_pass methods: */ virtual bool gate (function *) { - return flag_section_anchors && flag_tree_loop_vectorize; + return flag_ipa_increase_alignment != 0; } virtual unsigned int execute (function *) { return increase_alignment (); } @@ -968,7 +1008,7 @@ public: } // anon namespace -simple_ipa_opt_pass * +ipa_opt_pass_d * make_pass_ipa_increase_alignment (gcc::context *ctxt) { return new pass_ipa_increase_alignment (ctxt);