From patchwork Mon Aug 26 15:36:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 269912 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9DD7C2C00B3 for ; Tue, 27 Aug 2013 01:36:50 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=wp0DAREe/KF+V6KYwiuRsWqxjBn2ZvuOJgG3lg9Gkhcs9kTpk0RiG 1cN+QydNVnTJuyBJci6IWVZ4ZwIguoUlosMyc1VCdYIgg2WyBvZ4Fu32SvnSkrQX i1kae6oYS7DXsCqJ8wfugYhUj4ernboOoOP6NC08dwHY4LhvzFTKfk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=LZYzt/fdh3GqMUiVr8bVyh64haA=; b=xk89x9jj53Ftw4NDB2g9 EJ+wUh741O+Qd5c8HJELc3R70wDZJgVI5mhbdghAYwg9Y1neZojgtwxcy/2KYnuK ZYojHSYtT9KvmQSxQ3OWzKESAAZyo37MZzFmHFEgRRpcq6Os/bB0Na/hJqi092Kg KQJ7sam3aRx5riR5Mi0U/v8= Received: (qmail 8732 invoked by alias); 26 Aug 2013 15:36:44 -0000 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 Received: (qmail 8720 invoked by uid 89); 26 Aug 2013 15:36:43 -0000 Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 26 Aug 2013 15:36:43 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 472CA543B46; Mon, 26 Aug 2013 17:36:40 +0200 (CEST) Date: Mon, 26 Aug 2013 17:36:40 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix cgraph_redirect_edge_call_stmt_to_callee Message-ID: <20130826153640.GC25893@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Hi, this patch fixes interesting problem in cgraph_redirect_edge_call_stmt_to_callee. Before expanding the speculative call we do type checking ensuring that type of callee is compatible with a call. This fails when ipa-cp decides to redirect the call and change function signature, because the call type is not updated yet. We need to compare with type of function we have in reference (that is original function before ipa-cp change). This allows us to do 400 more speculative calls on firefox. Still 10 of them fail for reasons I do not quite understand and will try to debug next. Bootstrapped/regtested x86_64-linux, comitted. Honza Index: ChangeLog =================================================================== --- ChangeLog (revision 201998) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2013-08-26 Jan Hubicka + * cgraph.c (cgraph_redirect_edge_call_stmt_to_callee): Fix formatting; + fix edge count/frequency when speculation failed; fix type check + for the direct call. + +2013-08-26 Jan Hubicka + * ipa-prop.c (ipa_print_node_params): Do not ICE during WPA. 2013-08-26 Jan Hubicka Index: cgraph.c =================================================================== --- cgraph.c (revision 201996) +++ cgraph.c (working copy) @@ -1306,29 +1306,44 @@ cgraph_redirect_edge_call_stmt_to_callee struct ipa_ref *ref; cgraph_speculative_call_info (e, e, e2, ref); - /* If there already is an direct call (i.e. as a result of inliner's substitution), - forget about speculating. */ + /* If there already is an direct call (i.e. as a result of inliner's + substitution), forget about speculating. */ if (decl) e = cgraph_resolve_speculation (e, decl); - /* If types do not match, speculation was likely wrong. */ - else if (!gimple_check_call_matching_types (e->call_stmt, e->callee->symbol.decl, + /* If types do not match, speculation was likely wrong. + The direct edge was posisbly redirected to the clone with a different + signature. We did not update the call statement yet, so compare it + with the reference that still points to the proper type. */ + else if (!gimple_check_call_matching_types (e->call_stmt, + ref->referred->symbol.decl, true)) { if (dump_file) fprintf (dump_file, "Not expanding speculative call of %s/%i -> %s/%i\n" "Type mismatch.\n", - xstrdup (cgraph_node_name (e->caller)), e->caller->symbol.order, - xstrdup (cgraph_node_name (e->callee)), e->callee->symbol.order); + xstrdup (cgraph_node_name (e->caller)), + e->caller->symbol.order, + xstrdup (cgraph_node_name (e->callee)), + e->callee->symbol.order); e = cgraph_resolve_speculation (e, NULL); + /* We are producing the final function body and will throw away the + callgraph edges really soon. Reset the counts/frequencies to + keep verifier happy in the case of roundoff errors. */ + e->count = gimple_bb (e->call_stmt)->count; + e->frequency = compute_call_stmt_bb_frequency + (e->caller->symbol.decl, gimple_bb (e->call_stmt)); } /* Expand speculation into GIMPLE code. */ else { if (dump_file) - fprintf (dump_file, "Expanding speculative call of %s/%i -> %s/%i count:" + fprintf (dump_file, + "Expanding speculative call of %s/%i -> %s/%i count:" HOST_WIDEST_INT_PRINT_DEC"\n", - xstrdup (cgraph_node_name (e->caller)), e->caller->symbol.order, - xstrdup (cgraph_node_name (e->callee)), e->callee->symbol.order, + xstrdup (cgraph_node_name (e->caller)), + e->caller->symbol.order, + xstrdup (cgraph_node_name (e->callee)), + e->callee->symbol.order, (HOST_WIDEST_INT)e->count); gcc_assert (e2->speculative); push_cfun (DECL_STRUCT_FUNCTION (e->caller->symbol.decl)); @@ -1342,11 +1357,12 @@ cgraph_redirect_edge_call_stmt_to_callee : REG_BR_PROB_BASE / 2, e->count, e->count + e2->count); e->speculative = false; - cgraph_set_call_stmt_including_clones (e->caller, e->call_stmt, new_stmt, false); - e->frequency = compute_call_stmt_bb_frequency (e->caller->symbol.decl, - gimple_bb (e->call_stmt)); - e2->frequency = compute_call_stmt_bb_frequency (e2->caller->symbol.decl, - gimple_bb (e2->call_stmt)); + cgraph_set_call_stmt_including_clones (e->caller, e->call_stmt, + new_stmt, false); + e->frequency = compute_call_stmt_bb_frequency + (e->caller->symbol.decl, gimple_bb (e->call_stmt)); + e2->frequency = compute_call_stmt_bb_frequency + (e2->caller->symbol.decl, gimple_bb (e2->call_stmt)); e2->speculative = false; ref->speculative = false; ref->stmt = NULL;