From patchwork Wed Mar 27 17:22:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 231763 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 "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A309F2C00A5 for ; Thu, 28 Mar 2013 04:23:20 +1100 (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 :to:subject:mime-version:content-type:content-transfer-encoding :message-id:from; q=dns; s=default; b=i7J6rqj5YCRXt7pUfz6PszqCwl S2oRLeOw4Ln9b3gbf7kqBoPtTi63V7PM3o/DdkfL6o7GKD7OvKHHMS9PiqcOaWEQ alN2rMo2Xg/oTdvumNfaSx0Pck/xbR7y1g27sGah8tmn/I9JWtujBLX26V/zI42V SHEwu2t7N8T7NynK4= 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 :to:subject:mime-version:content-type:content-transfer-encoding :message-id:from; s=default; bh=QvIMevnJroSxtqzXlQUg4ZUq9aA=; b= tP29yx9F6erg3P5O8X4LGTbtn2/UuS60k2AikIhB8IMDwLyAIOx/NKdHby3Z30iW va49dkPTlqtZNeCqMI+sYsTGpWABBFUR1niIUiLDdp7Cx4MSfiZweKgHNZiJRoF7 Dov6XbQ9kky+5levfeC5O1kDX1afOKyiMLGmwCpBpzc= Received: (qmail 23558 invoked by alias); 27 Mar 2013 17:22:57 -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 23528 invoked by uid 89); 27 Mar 2013 17:22:45 -0000 X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail-ve0-f201.google.com (HELO mail-ve0-f201.google.com) (209.85.128.201) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 27 Mar 2013 17:22:40 +0000 Received: by mail-ve0-f201.google.com with SMTP id ox1so169438veb.4 for ; Wed, 27 Mar 2013 10:22:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:date:to:subject:user-agent:mime-version:content-type :content-transfer-encoding:message-id:from:x-gm-message-state; bh=GWUzvAWdjOeKCALedrVzkpGZhU0idPMCbAfZ0ptd/1k=; b=mNyorgV6bXdPqgS7KIhutJQQ+UGfPDoSV9qU8K39O+L7Tx6qe1gC2C+Q6xX54wK0Wv hhzWMeWksnjjOWxmgDnirrf9Z0E3r6uf6Ojx3f6aCQ22eFoNRPaq2mzZPSnHMxTLj1wc 5nGg+UlipbBappDnsVrXmWdJ/54ksLBh0gmV/ZBmuokesrNcOTHgLsz19zI8gnyqoY5W 9YHkCZ8TJnAifKh6aVYOH08+vbvLrPj73Ht4reOEEp9oVkIkYBUigyMh82sSp/8/4G1h Nc6wC4ko5EIEZgs9LaeoldG2zHThr00l3D0HUoh/XLLMs9DnyBvb2U51VeitrMupEddL OOZA== X-Received: by 10.224.172.200 with SMTP id m8mr10878664qaz.0.1364404959042; Wed, 27 Mar 2013 10:22:39 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id x1si3431956qci.2.2013.03.27.10.22.39 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 27 Mar 2013 10:22:39 -0700 (PDT) Received: from tjsboxrox.mtv.corp.google.com (tjsboxrox.mtv.corp.google.com [172.17.129.49]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id CD7A95A403C; Wed, 27 Mar 2013 10:22:38 -0700 (PDT) Received: by tjsboxrox.mtv.corp.google.com (Postfix, from userid 147431) id 545EF80580; Wed, 27 Mar 2013 10:22:38 -0700 (PDT) Date: Wed, 27 Mar 2013 10:22:38 -0700 To: gcc-patches@gcc.gnu.org, reply@codereview.appspotmail.com Subject: [patch] Fix node weight updates during ipa-cp (issue7812053) User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Message-Id: <20130327172238.545EF80580@tjsboxrox.mtv.corp.google.com> From: tejohnson@google.com (Teresa Johnson) X-Gm-Message-State: ALoCoQlMSfIwvOM/oW1VeS0JpMEE/Za7t/ugpIxB+KMVHulSb9kgOvjqaywCYGTCqHmBG4QfW47VOewjByN4ioRqCC4vdnMjbjKS077LA9tJS0O+/0vtAUSQWz6akFgJg6y5AC5+sX/nBSz3kD1OOeIavPRD4tCQUq+zUSeV0Z54HKQAtRKW9ctSjjO+uJcIdn7H88/fo9B3 I found that the node weight updates on cloned nodes during ipa-cp were leading to incorrect/insane weights. Both the original and new node weight computations used truncating divides, leading to a loss of total node weight. I have fixed this by making both rounding integer divides. Bootstrapped and tested on x86-64-unknown-linux-gnu. Ok for trunk? 2013-03-27 Teresa Johnson * ipa-cp.c (update_profiling_info): Perform rounding integer division when updating weights instead of truncating. (update_specialized_profile): Ditto. --- This patch is available for review at http://codereview.appspot.com/7812053 Index: ipa-cp.c =================================================================== --- ipa-cp.c (revision 197118) +++ ipa-cp.c (working copy) @@ -2588,14 +2588,18 @@ update_profiling_info (struct cgraph_node *orig_no for (cs = new_node->callees; cs ; cs = cs->next_callee) if (cs->frequency) - cs->count = cs->count * (new_sum * REG_BR_PROB_BASE - / orig_node_count) / REG_BR_PROB_BASE; + cs->count = (cs->count + * ((new_sum * REG_BR_PROB_BASE + orig_node_count/2) + / orig_node_count) + + REG_BR_PROB_BASE/2) / REG_BR_PROB_BASE; else cs->count = 0; for (cs = orig_node->callees; cs ; cs = cs->next_callee) - cs->count = cs->count * (remainder * REG_BR_PROB_BASE - / orig_node_count) / REG_BR_PROB_BASE; + cs->count = (cs->count + * ((remainder * REG_BR_PROB_BASE + orig_node_count/2) + / orig_node_count) + + REG_BR_PROB_BASE/2) / REG_BR_PROB_BASE; if (dump_file) dump_profile_updates (orig_node, new_node); @@ -2627,14 +2631,19 @@ update_specialized_profile (struct cgraph_node *ne for (cs = new_node->callees; cs ; cs = cs->next_callee) if (cs->frequency) - cs->count += cs->count * redirected_sum / new_node_count; + cs->count += (cs->count + * ((redirected_sum * REG_BR_PROB_BASE + + new_node_count/2) / new_node_count) + + REG_BR_PROB_BASE/2) / REG_BR_PROB_BASE; else cs->count = 0; for (cs = orig_node->callees; cs ; cs = cs->next_callee) { - gcov_type dec = cs->count * (redirected_sum * REG_BR_PROB_BASE - / orig_node_count) / REG_BR_PROB_BASE; + gcov_type dec = (cs->count + * ((redirected_sum * REG_BR_PROB_BASE + + orig_node_count/2) / orig_node_count) + + REG_BR_PROB_BASE/2) / REG_BR_PROB_BASE; if (dec < cs->count) cs->count -= dec; else