[Bug middle-end/51663] Desirable/undesirable elimination of unused variables & functions at -O0, -O0 -flto and -O0 -fwhole-program
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Mar 17 12:16:29 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51663
--- Comment #14 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #13)
> (In reply to Richard Biener from comment #12)
> > (In reply to Tom de Vries from comment #11)
> > > Cross-referencing PR gdb/25684 - "gdb testing with gcc -flto" (
> > > https://sourceware.org/bugzilla/show_bug.cgi?id=25684 ).
> > >
> > > Ideally there would be a way to enable the lto infrastructure without
> > > actually optimizing, such that when running the gdb testsuite with and
> > > without flto and comparing results, any regression would indicate something
> > > that needs fixing.
> > >
> > > In the current situation, each individual regression needs investigation
> > > whether something needs fixing or whether the failure is just an
> > > optimization artifact. And due to the fact there are optimizations, there
> > > are thousands of such regressions.
> >
> > I suppose we're talking about -O0 -flto here.
>
> Right, and ideally -flto plain, with -O0 implicit.
>
> > What kind of transforms
> > are undesirable? I think at -O0 you'll get
> >
> > - more aggressive unused variable/function removal
> > - promotion of variables from global to local
> >
>
> Right, is there a way to switch these off?
Not at the moment I think. The main unused variable/function removal
is in cgraphunit.c:analyze_functions. I guess the simplest thing would
be to try
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index a9dd288be57..3aa8137efad 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1158,7 +1158,7 @@ analyze_functions (bool first_time)
{
/* Convert COMDAT group designators to IDENTIFIER_NODEs. */
node->get_comdat_group_id ();
- if (node->needed_p ())
+ if (!optimize || node->needed_p ())
{
enqueue_node (node);
if (!changed && symtab->dump_file)
but I'm not sure this is enough since we remove not refered to things
at several points during the compilation (including during partitioning
I think). Another possibility would be to make all nodes force_output
when not optimizing like with
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index aa4cdc95506..b07bf9745d0 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -115,7 +115,7 @@ public:
transparent_alias (false), weakref (false), cpp_implicit_alias (false),
symver (false), analyzed (false), writeonly (false),
refuse_visibility_changes (false), externally_visible (false),
- no_reorder (false), force_output (false), forced_by_abi (false),
+ no_reorder (false), force_output (optimize), forced_by_abi (false),
unique_name (false), implicit_section (false), body_removed (false),
used_from_other_partition (false), in_other_partition (false),
address_taken (false), in_init_priority_hash (false),
or in a more suitable place. That should eventually also avoid
promotion to local.
> > some of the transforms are unavoidable due to partitioning(?) but we could
> > default to 1:1 partitioning at -O0 ...
>
> At this point I'm not interested in defaults yet. I can achieve 1:1
> partition by testing target board unix/-flto/-flto-partition=1to1.
>
> For now I'm interested in a combination of flags that exercises the specific
> type of debug info generation as is done for lto, without actually doing any
> optimizations.
>
> F.i., an open question for me is the following: I'm now using
> -flto-partition=none for testing, but maybe 1to1 should yield better results?
More information about the Gcc-bugs
mailing list