From patchwork Tue Sep 28 16:49:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 65999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id AB26BB7154 for ; Wed, 29 Sep 2010 02:49:25 +1000 (EST) Received: (qmail 29468 invoked by alias); 28 Sep 2010 16:49:23 -0000 Received: (qmail 29303 invoked by uid 22791); 28 Sep 2010 16:49:21 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 28 Sep 2010 16:49:15 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id CF3039ACE6C; Tue, 28 Sep 2010 18:49:13 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id C9DF0564124; Tue, 28 Sep 2010 18:49:13 +0200 (CEST) Date: Tue, 28 Sep 2010 18:49:13 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Teach CCP to do devirtualization Message-ID: <20100928164913.GB22494@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, with recent folding improvements, we now work hard enough to make statement fold to look into the virtual tables and work out function to be called. Still we don't devirtualize the call because we never actually substitute the operand of OBJ_TYPE_REF because there is a NOP_EXPR in a way. This patch makes ccp_fold_stmt to do the replacement. I am not 100% sure if we should not do some type checking and mark call statement uninlinable on mismatch, but in general C++ should not let us to make mismatches. I've bootstrapped/regtested the patch on x86_64 and tested on Mozilla. There it devirutalize about 900 calls during late ccp and also couple hundred calls before inlining. I am not attaching a testcase, since I inspected some and think they should be handled by the type based mahcinery too, but they are not, so I filled in PR for that. Once this is settled we can decide what has to be handled the busy way. OK? * tree-ssa-ccp.c (ccp_fold_stmt): Fold OBJ_TYPE_REF away when destination is known. Index: tree-ssa-ccp.c =================================================================== --- tree-ssa-ccp.c (revision 164689) +++ tree-ssa-ccp.c (working copy) @@ -2307,6 +2307,17 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi changed = true; } } + if (TREE_CODE (gimple_call_fn (stmt)) == OBJ_TYPE_REF) + { + tree expr = OBJ_TYPE_REF_EXPR (gimple_call_fn (stmt)); + expr = valueize_op (expr); + if (TREE_CODE (expr) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL) + { + gimple_call_set_fndecl (stmt, TREE_OPERAND (expr, 0)); + changed = true; + } + } return changed; }