> 2018-11-07 Martin Liska <mliska@xxxxxxx> > > * common.opt: Add -fipa-stack-alignment flag. > * doc/invoke.texi: Document it. > * final.c (rest_of_clean_state): Guard stack > shrinking with flag. OK > gcc/ChangeLog: > > 2018-11-07 Martin Liska <mliska@xxxxxxx> > > * cgraph.h (ipa_discover_readonly_nonaddressable_vars): Rename > to ... > (ipa_discover_nonaddressable_vars): ... this. > * common.opt: Come up with new flag -fipa-reference-addressable. > * doc/invoke.texi: Document it. > * ipa-reference.c (propagate): Call the renamed fn. > * ipa-visibility.c (whole_program_function_and_variable_visibility): > Likewise. > * ipa.c (ipa_discover_readonly_nonaddressable_vars): Renamed to > ... > (ipa_discover_nonaddressable_vars): ... this. Discove > non-addressable variables only with the newly added flag. > * opts.c: Enable the newly added flag with -O1 and higher > optimization level. > > gcc/testsuite/ChangeLog: > > 2018-11-07 Martin Liska <mliska@xxxxxxx> > > * gcc.dg/tree-ssa/writeonly-2.c: New test. > --- > gcc/cgraph.h | 2 +- > gcc/common.opt | 6 +++++- > gcc/doc/invoke.texi | 10 ++++++++-- > gcc/ipa-reference.c | 2 +- > gcc/ipa-visibility.c | 2 +- > gcc/ipa.c | 11 +++++++---- > gcc/opts.c | 1 + > gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c | 20 ++++++++++++++++++++ > 8 files changed, 44 insertions(+), 10 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c > > diff --git a/gcc/cgraph.h b/gcc/cgraph.h > index c13d79850fa..bf65d426cda 100644 > --- a/gcc/cgraph.h > +++ b/gcc/cgraph.h > @@ -2403,7 +2403,7 @@ void record_references_in_initializer (tree, bool); > > /* In ipa.c */ > void cgraph_build_static_cdtor (char which, tree body, int priority); > -bool ipa_discover_readonly_nonaddressable_vars (void); > +bool ipa_discover_nonaddressable_vars (void); I guess ipa_discover_variable_flags :) > > /* In varpool.c */ > tree ctor_for_folding (tree); > diff --git a/gcc/common.opt b/gcc/common.opt > index 2971dc21b1f..6a64b0e27d5 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -1718,7 +1718,11 @@ Perform Identical Code Folding for variables. > > fipa-reference > Common Report Var(flag_ipa_reference) Init(0) Optimization > -Discover readonly and non addressable static variables. > +Discover read-only and non addressable static variables. > + > +fipa-reference-addressable > +Common Report Var(flag_ipa_reference_addressable) Init(0) Optimization > +Discover read-only and write-only addressable variables. I guess this should say Discover read-only, write-only and non-addressable static variables OK with that change. Honza > > fipa-matrix-reorg > Common Ignore > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > index ae260c6ac6d..82c6fa913e8 100644 > --- a/gcc/doc/invoke.texi > +++ b/gcc/doc/invoke.texi > @@ -412,8 +412,8 @@ Objective-C and Objective-C++ Dialects}. > -finline-functions -finline-functions-called-once -finline-limit=@var{n} @gol > -finline-small-functions -fipa-cp -fipa-cp-clone @gol > -fipa-bit-cp -fipa-vrp @gol > --fipa-pta -fipa-profile -fipa-pure-const -fipa-reference -fipa-icf @gol > --fira-algorithm=@var{algorithm} @gol > +-fipa-pta -fipa-profile -fipa-pure-const -fipa-reference -fipa-reference-addressable @gol > +-fipa-icf -fira-algorithm=@var{algorithm} @gol > -fira-region=@var{region} -fira-hoist-pressure @gol > -fira-loop-pressure -fno-ira-share-save-slots @gol > -fno-ira-share-spill-slots @gol > @@ -7866,6 +7866,7 @@ compilation time. > -fipa-pure-const @gol > -fipa-profile @gol > -fipa-reference @gol > +-fipa-reference-addressable @gol > -fmerge-constants @gol > -fmove-loop-invariants @gol > -fomit-frame-pointer @gol > @@ -8895,6 +8896,11 @@ Discover which static variables do not escape the > compilation unit. > Enabled by default at @option{-O} and higher. > > +@item -fipa-reference-addressable > +@opindex fipa-reference-addressable > +Discover read-only and write-only addressable variables. > +Enabled by default at @option{-O} and higher. > + > @item -fipa-pta > @opindex fipa-pta > Perform interprocedural pointer analysis and interprocedural modification > diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c > index 43bbdae5d66..2cdce3cbfa6 100644 > --- a/gcc/ipa-reference.c > +++ b/gcc/ipa-reference.c > @@ -705,7 +705,7 @@ propagate (void) > if (dump_file) > cgraph_node::dump_cgraph (dump_file); > > - remove_p = ipa_discover_readonly_nonaddressable_vars (); > + remove_p = ipa_discover_nonaddressable_vars (); > generate_summary (); > > /* Propagate the local information through the call graph to produce > diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c > index 000207fa31b..1da594111f8 100644 > --- a/gcc/ipa-visibility.c > +++ b/gcc/ipa-visibility.c > @@ -911,7 +911,7 @@ whole_program_function_and_variable_visibility (void) > { > function_and_variable_visibility (flag_whole_program); > if (optimize || in_lto_p) > - ipa_discover_readonly_nonaddressable_vars (); > + ipa_discover_nonaddressable_vars (); > return 0; > } > > diff --git a/gcc/ipa.c b/gcc/ipa.c > index 3b6b5e5c8d4..eb53e7dcd06 100644 > --- a/gcc/ipa.c > +++ b/gcc/ipa.c > @@ -752,10 +752,10 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) > return false; > } > > -/* Discover variables that have no longer address taken or that are read only > - and update their flags. > +/* Discover variables that have no longer address taken, are read-only or > + write-only and update their flags. > > - Return true when unreachable symbol removan should be done. > + Return true when unreachable symbol removal should be done. > > FIXME: This can not be done in between gimplify and omp_expand since > readonly flag plays role on what is shared and what is not. Currently we do > @@ -764,8 +764,11 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) > make sense to do it before early optimizations. */ > > bool > -ipa_discover_readonly_nonaddressable_vars (void) > +ipa_discover_nonaddressable_vars (void) > { > + if (!flag_ipa_reference_addressable) > + return false; > + > bool remove_p = false; > varpool_node *vnode; > if (dump_file) > diff --git a/gcc/opts.c b/gcc/opts.c > index 34c283dd765..9b9018c6c48 100644 > --- a/gcc/opts.c > +++ b/gcc/opts.c > @@ -451,6 +451,7 @@ static const struct default_options default_options_table[] = > { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 }, > { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, > { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, > + { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 }, > { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, > { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, > { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 }, > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c b/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c > new file mode 100644 > index 00000000000..2272d15b171 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c > @@ -0,0 +1,20 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fdump-tree-optimized -fno-ipa-reference-addressable" } */ > +static struct a {int magic1,b;} a; > +volatile int magic2; > +static struct b {int a,b,c,d,e,f;} magic3; > + > +struct b foo(); > + > +void > +t() > +{ > + a.magic1 = 1; > + magic2 = 1; > + magic3 = foo(); > +} > +/* { dg-final { scan-tree-dump "magic1" "optimized"} } */ > +/* { dg-final { scan-tree-dump "magic3" "optimized"} } */ > +/* { dg-final { scan-tree-dump "magic2" "optimized"} } */ > +/* { dg-final { scan-tree-dump "foo" "optimized"} } */ > + > -- > 2.19.1 >