From patchwork Fri Oct 11 22:17:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Xu X-Patchwork-Id: 282945 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EBBFF2C0141 for ; Sat, 12 Oct 2013 09:18:00 +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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=cHk1WM33BcIOscU5CI kRikaKU0gs7undx0GXwwIQAtcffhJIZWZTbXreXljwywgv38PmIOFRzR5iA88ZlM +1PGUaEOKGIWREC0NMcjGF/DTtTGCbRN3yk9fKPjbswK0KW8TmR57mUkcyUJCJKk M+Rf2uFW1mt0HtSlR0Om3Aofc= 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:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=TOHuFOKt3lP1/4fcZIz04C4b Cto=; b=M1zNK2r3Cy7Vey1+lT9EOf4Tio5BFJMjlCkLJG7+M0cE/a2XuYlPVdx4 ty3iqNMALcHGp4RxFxsMUHAHUIzI2PCJOnK1uMez0Yl7P0jyZw3jAI0+A6PGkyq7 61Jufj1awJJ/D+ZD9r2eMtEGJ24FjM/z7rbdccTGzCOGAFL/Dz4= Received: (qmail 16558 invoked by alias); 11 Oct 2013 22:17:54 -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 16545 invoked by uid 89); 11 Oct 2013 22:17:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vb0-f46.google.com Received: from mail-vb0-f46.google.com (HELO mail-vb0-f46.google.com) (209.85.212.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 11 Oct 2013 22:17:52 +0000 Received: by mail-vb0-f46.google.com with SMTP id p13so3250445vbe.33 for ; Fri, 11 Oct 2013 15:17:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=F7skByLYKtnt7hWiYsDux8qpB49DG8Awa1ENkgUJeL8=; b=UNp5RjRn2SwzTkU8AcMb/CXiMDFlX7JoLbTVJlTZcg1NR7w0TpIDSwzGgQd7Rz8BCs iXQ1ofDVErt5C023XiMi1TYupS2Jf7+STaI3z75Uhzg+MjvMv+wwSpn2idPvkIAZbPED JQ6HLF5QJ1+2WAuHNjXnbcxjbg63WTjCw3uO4Hj+JNScESzIhyiAjOUcVInJdVmOSYuU MqNcHjHTnrbPaBXUo4UUtl2M+OL6zaAYtBgrDrKcU3EvOg8ZFm6JUDh2Yzwoyexnt0LL XLO+z9Ml54D/NEKTpBlH9LUEWcf4lm0Zd/N73Mol03NGH6O+0P+B/5/qUSnsybjCeYsv idJQ== X-Gm-Message-State: ALoCoQkE0cZVp+rTqe/DdUj43Mgn/XGKriPHqyXh5qcSU/RBKQPcn/KM0ZGBFnoIZ4j+K9DFvvNT2PiSXE0//OJwtCnkLLQ4tf0Xz4Lqj8fs8x9dpS2sxb+X56G5Gacv8c79AyCaEQD6OArW5DrkLu8KDmPWylEPu/Uk7hjQEkfwZsa0u/gMl2WAjppc7F4x2g9tf+Q8aNj+h1/3mHqyUduRnmBCe4ZjeA== MIME-Version: 1.0 X-Received: by 10.220.11.7 with SMTP id r7mr23142688vcr.12.1381529870472; Fri, 11 Oct 2013 15:17:50 -0700 (PDT) Received: by 10.52.107.101 with HTTP; Fri, 11 Oct 2013 15:17:50 -0700 (PDT) In-Reply-To: References: Date: Fri, 11 Oct 2013 15:17:50 -0700 Message-ID: Subject: Re: [google gcc-4_8] increase builtin_expect probability in loop exit test From: Rong Xu To: Xinliang David Li Cc: GCC Patches , Jan Hubicka X-IsSubscribed: yes here is the new patch. Note that the hitrate won't change by this patch for the case of while (__builtin_expect (exp, 0)) On Fri, Oct 11, 2013 at 2:45 PM, Rong Xu wrote: > ok. that makes sense. > > > On Fri, Oct 11, 2013 at 2:41 PM, Xinliang David Li wrote: >> Should it be max + some_delta then? >> >> David >> >> On Fri, Oct 11, 2013 at 2:32 PM, Rong Xu wrote: >>> I want to differentiate the cases w/o and w/ builtin. >>> If I take the max, they will be the same (91%). >>> >>> -Rong >>> >>> On Fri, Oct 11, 2013 at 2:26 PM, Xinliang David Li wrote: >>>> Why this 'percent += 4' instead of taking the max? >>>> >>>> David >>>> >>>> On Fri, Oct 11, 2013 at 2:10 PM, Rong Xu wrote: >>>>> The trunk version of this patch is submitted for review. >>>>> >>>>> David: can we have this patch for google/gcc-4_8 branch first? >>>>> It tested with regression and google internal benchmarks. >>>>> >>>>> Thanks, >>>>> >>>>> -Rong Index: predict.c =================================================================== --- predict.c (revision 203462) +++ predict.c (working copy) @@ -1951,11 +1951,42 @@ tree_predict_by_opcode (basic_block bb) if (val) { int percent = PARAM_VALUE (BUILTIN_EXPECT_PROBABILITY); + int hitrate; gcc_assert (percent >= 0 && percent <= 100); if (integer_zerop (val)) - percent = 100 - percent; - predict_edge (then_edge, PRED_BUILTIN_EXPECT, HITRATE (percent)); + hitrate = HITRATE (100 - percent); + else + { + /* This handles the cases like + while (__builtin_expect (exp, 1)) { ... } + W/o builtin_expect, the default HITRATE is 91%. + It does not make sense to estimate a lower probability of 90% + (current default for builtin_expect) with the annotation. + So here, we bump the probability by a small amount. */ + void **preds = pointer_map_contains (bb_predictions, bb); + + hitrate = HITRATE (percent); + if (preds) + { + struct edge_prediction *pred; + int exit_hitrate = predictor_info [(int) PRED_LOOP_EXIT].hitrate; + + for (pred = (struct edge_prediction *) *preds; pred; + pred = pred->ep_next) + { + if (pred->ep_predictor == PRED_LOOP_EXIT + && exit_hitrate > hitrate) + { + hitrate = exit_hitrate + HITRATE (4); + if (hitrate > REG_BR_PROB_BASE) + hitrate = REG_BR_PROB_BASE; + break; + } + } + } + } + predict_edge (then_edge, PRED_BUILTIN_EXPECT, hitrate); } /* Try "pointer heuristic." A comparison ptr == 0 is predicted as false.