From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25448 invoked by alias); 18 Mar 2013 08:54:04 -0000 Received: (qmail 25423 invoked by uid 22791); 18 Mar 2013 08:54:02 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Mar 2013 08:53:54 +0000 Received: by mail-wg0-f41.google.com with SMTP id ds1so2247830wgb.4 for ; Mon, 18 Mar 2013 01:53:53 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.181.13.175 with SMTP id ez15mr14695778wid.8.1363596833592; Mon, 18 Mar 2013 01:53:53 -0700 (PDT) Received: by 10.194.56.100 with HTTP; Mon, 18 Mar 2013 01:53:53 -0700 (PDT) In-Reply-To: References: Date: Mon, 18 Mar 2013 08:54:00 -0000 Message-ID: Subject: Re: [PATCH] Fix PR3713 From: Richard Biener To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Jan Hubicka Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00636.txt.bz2 On Wed, Jan 16, 2013 at 4:57 PM, Richard Biener 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 > > 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" } }