From patchwork Wed Feb 1 15:33:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 138950 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 60EE5B6EF1 for ; Thu, 2 Feb 2012 02:33:40 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1328715221; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Content-Type: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=nVrKvSyqNvCFHKPlHcyxqvzvPKs=; b=sT9q/JxHvMPOydo Uc1TQ8XRmEIsq/OuHR6s9R8TNLdH8AsuOOdWIXjYAveTq6RqEM0NMwrQG4uBGR3v H486exHdysHpXoMyUbgTO0gP8dayv1H/WBqIMdIneeVPyRrErr4JwTZbTvzG9GAl 2ef+TrCKbVOXn2+BAANIPEy4TaAE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:X-System-Of-Record:Content-Type:Content-Transfer-Encoding:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=B8eKHQST89+SYDEb5VKEiqybq1Jyc/6kOwq6xja9bbC4VzodY28AvweGIba6lD dtPoEUUtvf2PDjGtX7eboRaAubX9aIieHtzhxNIPKASVXrgIiJ+tXKCqXp0gcIKM Gh+7AcVi7LUg5pRZ+1T7GDS9dgB2ZTrKhxoHX9nENgGbo=; Received: (qmail 31413 invoked by alias); 1 Feb 2012 15:33:36 -0000 Received: (qmail 31404 invoked by uid 22791); 1 Feb 2012 15:33:34 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Feb 2012 15:33:21 +0000 Received: by iaby12 with SMTP id y12so1932967iab.20 for ; Wed, 01 Feb 2012 07:33:20 -0800 (PST) Received: by 10.42.168.197 with SMTP id x5mr22021683icy.6.1328110400494; Wed, 01 Feb 2012 07:33:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.168.197 with SMTP id x5mr22021665icy.6.1328110400361; Wed, 01 Feb 2012 07:33:20 -0800 (PST) Received: by 10.50.216.194 with HTTP; Wed, 1 Feb 2012 07:33:20 -0800 (PST) In-Reply-To: <20cf300fb1ef70ad4104b7c8d7e8@google.com> References: <20cf300fb1ef70ad4104b7c8d7e8@google.com> Date: Wed, 1 Feb 2012 07:33:20 -0800 Message-ID: Subject: Re: Static branch prediction: compare IV to loop bound variable (issue 5504086) From: Dehao Chen To: dehao@google.com, davidxl@google.com, gcc-patches@gcc.gnu.org, reply@codereview-hr.appspotmail.com X-System-Of-Record: true X-IsSubscribed: yes 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 There are still some minor bugs in the current implementation, which is fixed by the attached patch: passed bootstrap/regression tests for both google-4_6 and google-main branch. ok for google branch? Thanks, Dehao gcc/ChangeLog.google-4_6 2012-01-31 Dehao Chen * predict.c (predict_iv_comparison): Add new parameter, ensure that the loop_iv_base and compare_base are identical. On Mon, Jan 30, 2012 at 5:25 PM, wrote: > Ok for google branches for now. > > thanks, > > David > > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c > File gcc/predict.c (right): > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode958 > gcc/predict.c:958: find_qualified_ssa_name (tree t1, tree t2) > Better change the name into 'strips_small_constant' > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode991 > gcc/predict.c:991: Return NULL if T does not satisfy IV_COMPARE > condition.  */ > Fix comment -- there is no IV_COMPARE used here. > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode995 > gcc/predict.c:995: { > Better change the name into 'get_base_value (tree t)' because the method > basically strips the constant 'offset' away. > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1102 > gcc/predict.c:1102: a similar variable.  */ > Fix the comments. Returns true if T1 and T2 are value coherent. > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1106 > gcc/predict.c:1106: { > May be changing the name to > > expr_coherent_p (tree t1, tree t2) > > http://codereview.appspot.com/5504086/diff/1004/gcc/predict.c#newcode1206 > gcc/predict.c:1206: && (compare_code == LT_EXPR || compare_code == > LE_EXPR)) > Fix indentation. > > http://codereview.appspot.com/5504086/ Index: gcc/predict.c =================================================================== --- gcc/predict.c (revision 183783) +++ gcc/predict.c (working copy) @@ -1126,8 +1126,8 @@ } /* Predict branch probability of BB when BB contains a branch that compares - an induction variable in LOOP to LOOP_BOUND_VAR. The loop exit is - compared using LOOP_BOUND_CODE, with step of LOOP_BOUND_STEP. + an induction variable with LOOP_IV_BASE_VAR in LOOP to LOOP_BOUND_VAR. The + loop exit is compared using LOOP_BOUND_CODE, with step of LOOP_BOUND_STEP. E.g. for (int i = 0; i < bound; i++) { @@ -1142,6 +1142,7 @@ static void predict_iv_comparison (struct loop *loop, basic_block bb, tree loop_bound_var, + tree loop_iv_base_var, enum tree_code loop_bound_code, int loop_bound_step) { @@ -1184,7 +1185,8 @@ return; } - if (!expr_coherent_p (loop_bound_var, compare_var)) + if (!expr_coherent_p (loop_bound_var, compare_var) + || loop_iv_base_var != compare_base) return; /* If loop bound, base and compare bound are all constents, we can @@ -1213,13 +1215,17 @@ compare_count ++; if (loop_bound_code == LE_EXPR || loop_bound_code == GE_EXPR) loop_count ++; + if (compare_count < 0) + compare_count = 0; + if (loop_count < 0) + loop_count = 0; if (loop_count == 0) probability = 0; else if (compare_count > loop_count) - probability = 1; + probability = REG_BR_PROB_BASE; else - probability = REG_BR_PROB_BASE * compare_count / loop_count; + probability = (double) REG_BR_PROB_BASE * compare_count / loop_count; predict_edge (then_edge, PRED_LOOP_IV_COMPARE, probability); return; } @@ -1405,7 +1411,7 @@ predict_edge (e, PRED_LOOP_EXIT, probability); } if (loop_bound_var) - predict_iv_comparison (loop, bb, loop_bound_var, + predict_iv_comparison (loop, bb, loop_bound_var, loop_iv_base, loop_bound_code, loop_bound_step); }