From patchwork Sat Jun 22 00:59:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 253329 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 D38712C0390 for ; Sat, 22 Jun 2013 11:00:03 +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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=YiLYsdwRnRZJe1N8K7vcj6Vpnj91Ltckk0la2yi+CylFSY 2E/tpZcHWSHnsllIzORO7piZmqduiWXY90+QSTwX5EvwoWSoJLBON22CQrEPDM7M 1/cCLqRbcCtTiyltb4LUWFjTCiOPZwVkMvMEzGkDCclyiqykBH3TQ28gsKSF4= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=FAXDCPKX5wO851hr0+iYWu+aMq8=; b=nGjXPhzw08NJ6XONBVwl chu6ZkmpVJGDsfZr2tohi785+kZwBL0rGebQawRr+9Jy7hVJrUFpBtkCoRHqSPKB bJbCXoHFjnSL0ioC+4G1FZUqMwgx4iVfRTcWtQ40wl0/RzJ1YtM7XvIF/ulwCZuc I9afDGkpGtu2uRMEV+sZFzE= Received: (qmail 9220 invoked by alias); 22 Jun 2013 00:59: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 9208 invoked by uid 89); 22 Jun 2013 00:59:56 -0000 X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.1 Received: from mail-ee0-f48.google.com (HELO mail-ee0-f48.google.com) (74.125.83.48) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 22 Jun 2013 00:59:55 +0000 Received: by mail-ee0-f48.google.com with SMTP id b47so4829235eek.21 for ; Fri, 21 Jun 2013 17:59:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=VcX08VsuEXoH7dSmZ9f1BzsInoFLREtSUgu5Nt22n8o=; b=aHXdg7Zgk+AxHFKe7f1jQ8en21Hr5plKMz7RX7ryHLsVwBPIZSkV0Oe9TO/efLjUge pa7Q8aAynHsj/jXOvezVmDP7VEbAGQxa0m+TlwbuN3MQRjT6kb4DuRAov/I2TmDkK/dq RtqEUEJs3diyT/LA5G+Y87RbTPG1Po96eb2Zpz3vpwiFHa4Hq7zuZyg2N3ROwbmsQav1 Dby0Dmu+Fx4JAM7pA4CeI3i6N3B+oOAC6V6e4pEKsBURzii9NtRjEOIJiLakQcJAo/jw fIJ3yfM0B2baF6wZggvX7oH/id4Oqjgkewt7F4ciVoqoA/kKh4LvSBntgXfhejZPv/4H KylA== MIME-Version: 1.0 X-Received: by 10.15.94.142 with SMTP id bb14mr5778793eeb.112.1371862793462; Fri, 21 Jun 2013 17:59:53 -0700 (PDT) Received: by 10.14.210.69 with HTTP; Fri, 21 Jun 2013 17:59:53 -0700 (PDT) Date: Fri, 21 Jun 2013 17:59:53 -0700 Message-ID: Subject: [PATCH] Change the badness computation to ensure no integer-underflow From: Dehao Chen To: GCC Patches X-Gm-Message-State: ALoCoQnzyudRGMMW5Dx+3Qwn0Tv9HY9iUyJKzDTQINiJw3mYILsAeU/geXB9ZvEy3SiXf40Y4mf7Vrq1sN1oV9CJ2dJu4z2nuS4SDjlB9xrkF7qPT0X5JeMD4xGGHjtgGy2vwL4xCUqoSHPFqIZBlZ3pt1WiYd3KdeNr/151FVkxYzS8yPw/0wu6ZdSm7otNwlNrhUCeh38VBtaPhDlrEYnSjNUes91dYg== This patch prevents integer-underflow of badness computation in ipa-inline. Bootstrapped and passed regression tests. OK for trunk? Thanks, Dehao gcc/ChangeLog: 2013-06-21 Dehao Chen * ipa-inline.c (edge_badness): Fix integer underflow. gcc_assert (max_count >= edge->count); Index: gcc/ipa-inline.c =================================================================== --- gcc/ipa-inline.c (revision 200326) +++ gcc/ipa-inline.c (working copy) @@ -888,11 +888,9 @@ edge_badness (struct cgraph_edge *edge, bool dump) else if (max_count) { int relbenefit = relative_time_benefit (callee_info, edge, edge_time); - badness = - ((int) - ((double) edge->count * INT_MIN / 2 / max_count / RELATIVE_TIME_BENEFIT_RANGE) * - relbenefit) / growth; - + badness = ((int)((double) edge->count / max_count + * relbenefit / RELATIVE_TIME_BENEFIT_RANGE * INT_MIN / 2)) / growth; + /* Be sure that insanity of the profile won't lead to increasing counts in the scalling and thus to overflow in the computation above. */