public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jan Hubicka <hubicka@ucw.cz>
Subject: Re: [PATCH, PR 55264] Do not remove as unreachable any virtual methods before inlining
Date: Wed, 16 Jan 2013 10:30:00 -0000	[thread overview]
Message-ID: <CAFiYyc0uVru1=PFZdbrXfTuU1mwzgFfKtPBv_QAh8ee42f_dew@mail.gmail.com> (raw)
In-Reply-To: <20130116100127.GA21071@virgil.suse>

On Wed, Jan 16, 2013 at 11:01 AM, Martin Jambor <mjambor@suse.cz> wrote:
> Hi,
>
> PR 55264 is caused by cgraph machinery thinking it knows all calls to
> a virtual method when that is actually not true.  As discussed with
> Honza, prior to inlining, we should not assume some virtual functions
> (namely those that are neither DECL_COMDAT nor DECL_EXTERNAL) are not
> reachable.

Are they not reachable from the VTABLE which is referenced from all
calls that eventually reach the virtual method?  Thus, isn't the issue that
the VTABLE is not correctly handled by ipa-references code?

> DECL_EXTERNAL however still affects the cgraph_node->local.local flag
> and so in order to avoid some LTO failures, I had to adjust IPA-CP to
> consider such virtual functions non-local so that verification of
> lattice propagation does not complain.  I'm a bit puzzled by the value
> of the flag in this situation but at least it does not seem to cause
> any other problems.
>
> Below is a trunk patch to do all this.  It does not apply to released
> versions which also suffer from the same problem so I'll prepare a
> special version(s) for them once this gets approved.  Bootstrapped and
> tested on x86_64-linux.  OK for trunk?
>
> Thanks,
>
> Martin
>
>
> 2013-01-15  Martin Jambor  <mjambor@suse.cz>
>
>         PR tree-optimizations/55264
>         * ipa-inline-transform.c (can_remove_node_now_p_1): Never return true
>         for virtual methods.
>         * ipa.c (symtab_remove_unreachable_nodes): Never return true for
>         virtual methods before inlining is over.
>         * ipa-cp.c (initialize_node_lattices): Also consider all virtual
>         methods non-local.
>
> testsuite/
>         * g++.dg/ipa/pr55264.C: New test.
>
> Index: src/gcc/ipa-inline-transform.c
> ===================================================================
> --- src.orig/gcc/ipa-inline-transform.c
> +++ src/gcc/ipa-inline-transform.c
> @@ -92,9 +92,7 @@ can_remove_node_now_p_1 (struct cgraph_n
>              those only after all devirtualizable virtual calls are processed.
>              Lacking may edges in callgraph we just preserve them post
>              inlining.  */
> -         && (!DECL_VIRTUAL_P (node->symbol.decl)
> -             || (!DECL_COMDAT (node->symbol.decl)
> -                 && !DECL_EXTERNAL (node->symbol.decl)))
> +         && !DECL_VIRTUAL_P (node->symbol.decl)
>           /* During early inlining some unanalyzed cgraph nodes might be in the
>              callgraph and they might reffer the function in question.  */
>           && !cgraph_new_nodes);
> Index: src/gcc/ipa.c
> ===================================================================
> --- src.orig/gcc/ipa.c
> +++ src/gcc/ipa.c
> @@ -241,8 +241,7 @@ symtab_remove_unreachable_nodes (bool be
>         && (!cgraph_can_remove_if_no_direct_calls_and_refs_p (node)
>             /* Keep around virtual functions for possible devirtualization.  */
>             || (before_inlining_p
> -               && DECL_VIRTUAL_P (node->symbol.decl)
> -               && (DECL_COMDAT (node->symbol.decl) || DECL_EXTERNAL (node->symbol.decl)))))
> +               && DECL_VIRTUAL_P (node->symbol.decl))))
>        {
>          gcc_assert (!node->global.inlined_to);
>         pointer_set_insert (reachable, node);
> Index: src/gcc/testsuite/g++.dg/ipa/pr55264.C
> ===================================================================
> --- /dev/null
> +++ src/gcc/testsuite/g++.dg/ipa/pr55264.C
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-early-inlining -fno-weak"  } */
> +
> +struct S
> +{
> +  S();
> +  virtual inline void foo ()
> +  {
> +    foo();
> +  }
> +};
> +
> +void
> +B ()
> +{
> +  S().foo ();
> +}
> Index: src/gcc/ipa-cp.c
> ===================================================================
> --- src.orig/gcc/ipa-cp.c
> +++ src/gcc/ipa-cp.c
> @@ -699,7 +699,8 @@ initialize_node_lattices (struct cgraph_
>    int i;
>
>    gcc_checking_assert (cgraph_function_with_gimple_body_p (node));
> -  if (!node->local.local)
> +  if (!node->local.local
> +      || DECL_VIRTUAL_P (node->symbol.decl))
>      {
>        /* When cloning is allowed, we can assume that externally visible
>          functions are not called.  We will compensate this by cloning

  reply	other threads:[~2013-01-16 10:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16 10:01 Martin Jambor
2013-01-16 10:30 ` Richard Biener [this message]
2013-01-16 11:21   ` Jan Hubicka
2013-01-16 12:44     ` Jan Hubicka
2013-01-16 18:42       ` Martin Jambor
2013-01-16 21:24         ` Jan Hubicka
2013-01-18 17:46           ` Martin Jambor
2013-01-18 17:48           ` Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc0uVru1=PFZdbrXfTuU1mwzgFfKtPBv_QAh8ee42f_dew@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).