public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org, Jan Hubicka <jh@suse.de>
Subject: Re: [PATCH] Fix PR3713
Date: Mon, 18 Mar 2013 08:54:00 -0000	[thread overview]
Message-ID: <CAFiYyc2oFSqS8710256rnBw9peD6ODPuh0cOJ51EAyHnV7F31Q@mail.gmail.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1301161650070.6889@zhemvz.fhfr.qr>

On Wed, Jan 16, 2013 at 4:57 PM, Richard Biener <rguenther@suse.de> wrote:
>
> This fixes PR3713 by properly propagating ->has_constants in SCCVN.
> With that we are able to simplify (unsigned) Bar & 1 properly.
> Only copyprop later turns the call into a direct one though,
> so I'm testing the important fact - that Bar is inlined and eliminated
> by IPA inlining.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> Unless this is somehow a regression (which I doubt) this has to
> wait for stage1 (even though it's pretty safe and at most exposes
> existing bugs in SCCVN).

Committed as r196771.

Richard.

> Richard.
>
> 2013-01-16  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/3713
>         * tree-ssa-sccvn.c (visit_copy): Simplify.  Always propagate
>         has_constants and expr.
>         (stmt_has_constants): Properly valueize SSA names when deciding
>         whether the stmt has constants.
>
>         * g++.dg/ipa/devirt-11.C: New testcase.
>
> Index: gcc/tree-ssa-sccvn.c
> ===================================================================
> *** gcc/tree-ssa-sccvn.c        (revision 195240)
> --- gcc/tree-ssa-sccvn.c        (working copy)
> *************** static tree valueize_expr (tree expr);
> *** 2653,2670 ****
>   static bool
>   visit_copy (tree lhs, tree rhs)
>   {
> -   /* Follow chains of copies to their destination.  */
> -   while (TREE_CODE (rhs) == SSA_NAME
> -        && SSA_VAL (rhs) != rhs)
> -     rhs = SSA_VAL (rhs);
> -
>     /* The copy may have a more interesting constant filled expression
>        (we don't, since we know our RHS is just an SSA name).  */
> !   if (TREE_CODE (rhs) == SSA_NAME)
> !     {
> !       VN_INFO (lhs)->has_constants = VN_INFO (rhs)->has_constants;
> !       VN_INFO (lhs)->expr = VN_INFO (rhs)->expr;
> !     }
>
>     return set_ssa_val_to (lhs, rhs);
>   }
> --- 2653,2665 ----
>   static bool
>   visit_copy (tree lhs, tree rhs)
>   {
>     /* The copy may have a more interesting constant filled expression
>        (we don't, since we know our RHS is just an SSA name).  */
> !   VN_INFO (lhs)->has_constants = VN_INFO (rhs)->has_constants;
> !   VN_INFO (lhs)->expr = VN_INFO (rhs)->expr;
> !
> !   /* And finally valueize.  */
> !   rhs = SSA_VAL (rhs);
>
>     return set_ssa_val_to (lhs, rhs);
>   }
> *************** expr_has_constants (tree expr)
> *** 3063,3087 ****
>   static bool
>   stmt_has_constants (gimple stmt)
>   {
>     if (gimple_code (stmt) != GIMPLE_ASSIGN)
>       return false;
>
>     switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
>       {
> !     case GIMPLE_UNARY_RHS:
> !       return is_gimple_min_invariant (gimple_assign_rhs1 (stmt));
>
>       case GIMPLE_BINARY_RHS:
> !       return (is_gimple_min_invariant (gimple_assign_rhs1 (stmt))
> !             || is_gimple_min_invariant (gimple_assign_rhs2 (stmt)));
> !     case GIMPLE_TERNARY_RHS:
> !       return (is_gimple_min_invariant (gimple_assign_rhs1 (stmt))
> !             || is_gimple_min_invariant (gimple_assign_rhs2 (stmt))
> !             || is_gimple_min_invariant (gimple_assign_rhs3 (stmt)));
>       case GIMPLE_SINGLE_RHS:
>         /* Constants inside reference ops are rarely interesting, but
>          it can take a lot of looking to find them.  */
> !       return is_gimple_min_invariant (gimple_assign_rhs1 (stmt));
>       default:
>         gcc_unreachable ();
>       }
> --- 3058,3095 ----
>   static bool
>   stmt_has_constants (gimple stmt)
>   {
> +   tree tem;
> +
>     if (gimple_code (stmt) != GIMPLE_ASSIGN)
>       return false;
>
>     switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
>       {
> !     case GIMPLE_TERNARY_RHS:
> !       tem = gimple_assign_rhs3 (stmt);
> !       if (TREE_CODE (tem) == SSA_NAME)
> !       tem = SSA_VAL (tem);
> !       if (is_gimple_min_invariant (tem))
> !       return true;
> !       /* Fallthru.  */
>
>       case GIMPLE_BINARY_RHS:
> !       tem = gimple_assign_rhs2 (stmt);
> !       if (TREE_CODE (tem) == SSA_NAME)
> !       tem = SSA_VAL (tem);
> !       if (is_gimple_min_invariant (tem))
> !       return true;
> !       /* Fallthru.  */
> !
>       case GIMPLE_SINGLE_RHS:
>         /* Constants inside reference ops are rarely interesting, but
>          it can take a lot of looking to find them.  */
> !     case GIMPLE_UNARY_RHS:
> !       tem = gimple_assign_rhs1 (stmt);
> !       if (TREE_CODE (tem) == SSA_NAME)
> !       tem = SSA_VAL (tem);
> !       return is_gimple_min_invariant (tem);
> !
>       default:
>         gcc_unreachable ();
>       }
> Index: gcc/testsuite/g++.dg/ipa/devirt-11.C
> ===================================================================
> *** gcc/testsuite/g++.dg/ipa/devirt-11.C        (revision 0)
> --- gcc/testsuite/g++.dg/ipa/devirt-11.C        (working copy)
> ***************
> *** 0 ****
> --- 1,22 ----
> + // { dg-do compile }
> + // { dg-options "-std=c++11 -O -fdump-ipa-inline" }
> +
> + class Foo
> + {
> + public:
> +   void Bar() const
> +     {
> +       __builtin_puts ("Howdy!");
> +     }
> + };
> +
> + int main()
> + {
> +   Foo x;
> +   auto y = &Foo::Bar;
> +   (x.*y)();
> +   return 0;
> + }
> +
> + // { dg-final { scan-ipa-dump "Inlined 1 calls, eliminated 1 functions" "inline" } }
> + // { dg-final { cleanup-ipa-dump "inline" } }

      reply	other threads:[~2013-03-18  8:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16 15:57 Richard Biener
2013-03-18  8:54 ` Richard Biener [this message]

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=CAFiYyc2oFSqS8710256rnBw9peD6ODPuh0cOJ51EAyHnV7F31Q@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jh@suse.de \
    --cc=rguenther@suse.de \
    /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).