From patchwork Mon Aug 26 11:36:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 269865 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 B95162C00A3 for ; Mon, 26 Aug 2013 21:36:29 +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=srprWZuEzWqzghdOdvg1XMnceo5G2yEkGAivA+2DmN/h53e3gGxbP t3XEP8PWUZI+nZ6RzvQWV/wmBjTi0cQyUpy/YdCPkYZcrLlEPQUxnx95trQPMass 7PleWvlcWxn3CNz5EO5e+GjEIYR1SRvGjJZ8uJU7XN4mduRiTphjH8= 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=q8eBmyTo9A56GtLu+pS+ctYbPBw=; b=snOZbHsSzlC4j2nfb7bt WO+bcG5ACDMXz9lOnlcezw4/ZdaLNTMSdgg2RIAfpFqKuo+hQzJOJyfe8mgofyta TfuqcnQlWICQe0e1TctF4DHC6k6ZcnIwV7mfc/rpfngjHHsoquVTyk2PUOARi96g l8EmAzl6smkjUW3ch788XwI= Received: (qmail 14616 invoked by alias); 26 Aug 2013 11:36:23 -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 14604 invoked by uid 89); 26 Aug 2013 11:36:23 -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 11:36:23 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, NO_RELAYS, TO_NO_BRKTS_PCNT autolearn=no version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 26158542DEE; Mon, 26 Aug 2013 13:36:19 +0200 (CEST) Date: Mon, 26 Aug 2013 13:36:18 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix some issues with speculative devirtualization machinery Message-ID: <20130826113618.GA20835@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Hi, by making speculative indirect call machinery to be used by ipa-devirt I put it on wild on firefox converting about 30% of all polymorphic calls in the progrma (30000). This has provoked some issues I missed previously this patch fixes: 1) dumping - we no longer do only indirect calls from other units. 2) Adds sanity check to cgraph_speculative_call_info with explanation comment since it already confused Maritn (Liska). I also noticed that direct/indirect names are swapped that is very confusing 3) I noticed that when we resolve speculation in a way so direct edge wins and the edge is already inline, its frequency increases that ought to rescale all callees of the node. I want to do this as part of edge scaling in ipa-inline-transform, but droped a FIXME. 4) cgraph_redirect_edge_call_stmt_to_callee ICEd when especulation was wrong and dumping was enabled. 5) ipa-inline needs to reset caches more carefuly because of the effect described above: resolving a speculation in the middle of function has cascading effect that eventually lead to sanity check failure. Bootstrapped/regtested x86_64-linux, will commit it shortly. * cgraph.c (cgraph_turn_edge_to_speculative): Fix debug output. (cgraph_speculative_call_info): Fix parameter order and formating; add sanity check. (cgraph_resolve_speculation): Add FIXME about scaling profiles. (cgraph_redirect_edge_call_stmt_to_callee): Fix ICE in debug dump. * ipa-inline.c (heap_edge_removal_hook): Reset node growth cache. (resolve_noninline_speculation): Update callee keys, too. Index: cgraph.c =================================================================== --- cgraph.c (revision 201966) +++ cgraph.c (working copy) @@ -1076,8 +1076,8 @@ cgraph_turn_edge_to_speculative (struct if (dump_file) { - fprintf (dump_file, "Indirect call -> direct call from" - " other module %s/%i => %s/%i\n", + fprintf (dump_file, "Indirect call -> speculative call" + " %s/%i => %s/%i\n", xstrdup (cgraph_node_name (n)), n->symbol.order, xstrdup (cgraph_node_name (n2)), n2->symbol.order); } @@ -1113,8 +1113,8 @@ cgraph_turn_edge_to_speculative (struct void cgraph_speculative_call_info (struct cgraph_edge *e, - struct cgraph_edge *&indirect, struct cgraph_edge *&direct, + struct cgraph_edge *&indirect, struct ipa_ref *&reference) { struct ipa_ref *ref; @@ -1137,16 +1137,18 @@ cgraph_speculative_call_info (struct cgr } else for (e = e->caller->callees; - e2->call_stmt != e->call_stmt || e2->lto_stmt_uid != e->lto_stmt_uid; + e2->call_stmt != e->call_stmt + || e2->lto_stmt_uid != e->lto_stmt_uid; e = e->next_callee) ; } gcc_assert (e->speculative && e2->speculative); - indirect = e; - direct = e2; + direct = e; + indirect = e2; reference = NULL; - for (i = 0; ipa_ref_list_reference_iterate (&e->caller->symbol.ref_list, i, ref); i++) + for (i = 0; ipa_ref_list_reference_iterate (&e->caller->symbol.ref_list, + i, ref); i++) if (ref->speculative && ((ref->stmt && ref->stmt == e->call_stmt) || (ref->lto_stmt_uid == e->lto_stmt_uid))) @@ -1154,6 +1156,11 @@ cgraph_speculative_call_info (struct cgr reference = ref; break; } + + /* Speculative edge always consist of all three components - direct edge, + indirect and reference. */ + + gcc_assert (e && e2 && ref); } /* Redirect callee of E to N. The function does not update underlying @@ -1209,6 +1216,8 @@ cgraph_resolve_speculation (struct cgrap fprintf (dump_file, "Speculative call turned into direct call.\n"); edge = e2; e2 = tmp; + /* FIXME: If EDGE is inlined, we should scale up the frequencies and counts + in the functions inlined through it. */ } edge->count += e2->count; edge->frequency += e2->frequency; @@ -1305,12 +1314,12 @@ cgraph_redirect_edge_call_stmt_to_callee else if (!gimple_check_call_matching_types (e->call_stmt, e->callee->symbol.decl, true)) { - e = cgraph_resolve_speculation (e, NULL); 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); + e = cgraph_resolve_speculation (e, NULL); } /* Expand speculation into GIMPLE code. */ else Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 201966) +++ ipa-inline.c (working copy) @@ -1397,6 +1397,8 @@ add_new_edges_to_heap (fibheap_t heap, v static void heap_edge_removal_hook (struct cgraph_edge *e, void *data) { + if (e->callee) + reset_node_growth_cache (e->callee); if (e->aux) { fibheap_delete_node ((fibheap_t)data, (fibnode_t)e->aux); @@ -1467,12 +1469,12 @@ resolve_noninline_speculation (fibheap_t bitmap updated_nodes = BITMAP_ALLOC (NULL); cgraph_resolve_speculation (edge, NULL); - reset_node_growth_cache (where); reset_edge_caches (where); inline_update_overall_summary (where); update_caller_keys (edge_heap, where, updated_nodes, NULL); - reset_node_growth_cache (where); + update_callee_keys (edge_heap, where, + updated_nodes); BITMAP_FREE (updated_nodes); } }