From patchwork Tue Jul 31 03:17:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 174136 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 3D2272C0083 for ; Tue, 31 Jul 2012 13:18:12 +1000 (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=1344309493; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=rKPAfay rqVvmpP89hUKindgc9MU=; b=YRJroKy+XYSg0gQKeayeZVqRDV+a3xoeIrttYbG vfcSuGvwvhmfTozkthb4pPo/sQVCP/U7rvhpTQbbtgDE9i6RzBcwpKM3Rf7Hl1gw FhUSSoBISyooEtCfD8kYPx9YldaziJaigBTNswQhierse49r0Cw5i6qIOIEZPbp5 Stxs= 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:X-Google-DKIM-Signature:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=VYysuGiAAwRWVv06NBelPqrgwM0OvVwp7B23phJqkoL5aMOeKeCDW8zWzny0Xo i/34KddpR7nXvd0tM7HMNnLWPFeJjXSGx80vTU9NjtdTNGHw3jxaHk+HEtlgXmnX e9lRuw8M5mJ8Gpu+ZEwDaJOyUHEsT3hRQs0PFO/fZD9IA=; Received: (qmail 25104 invoked by alias); 31 Jul 2012 03:18:04 -0000 Received: (qmail 25084 invoked by uid 22791); 31 Jul 2012 03:18:03 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-gh0-f175.google.com (HELO mail-gh0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 Jul 2012 03:17:40 +0000 Received: by ghbz2 with SMTP id z2so5630128ghb.20 for ; Mon, 30 Jul 2012 20:17:40 -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:cc:content-type :x-system-of-record:x-gm-message-state; bh=xP0GunNuJDzjZW7d/EwFpSze0cORbVCrqH04N70Ay2g=; b=LajYsmZEbeb3MlbmUFpAo/BRXhsddKPporWmaWmNdAECee4ykRxlPe0iaCYA2ffZQK HLnPzPWrd1U014PIQFSEOCZzgGf+FlNvZ7i/tMWpFQFhhGh2uMyjBq0s5mdS74AgbrKE EKFarnU2Te1JR4MF/i60PpPQ7qVz8HNyWVefj4epCWlAiQZguYpYsTvu66jH3jFarqDl ZmwNBfszRQIGxHlqaYRS9te6eBX/cmzH8Ofmc276o7a89SLrN7nTzHLCj1uwzW5XOggP DYENXKJml8F46mlLGAywH0yGIM/xBtgP6hkAssQRoQAWT0YDWmB/zvMChEhX+mjsPQ6Y ebGA== Received: by 10.66.74.195 with SMTP id w3mr28936073pav.64.1343704659559; Mon, 30 Jul 2012 20:17:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.74.195 with SMTP id w3mr28936062pav.64.1343704659406; Mon, 30 Jul 2012 20:17:39 -0700 (PDT) Received: by 10.68.49.231 with HTTP; Mon, 30 Jul 2012 20:17:39 -0700 (PDT) Date: Tue, 31 Jul 2012 11:17:39 +0800 Message-ID: Subject: [PATCH] Fix the LOOP_BRANCH prediction From: Dehao Chen To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka , David Li X-System-Of-Record: true X-Gm-Message-State: ALoCoQla0OM3i9bJ4sgAKYDBu2Mw73+Wdtn/6LmQDVWRxlIwvE6VpJ3Bg4UpNnuEDJ0CCmM9OjuGPxcQk9L2lcifACTzhc8yqpWEG9pgDxF8dH9WlzVueQTVy+q0alT1vfGuA6gbEJbKkdJZi2wNQfud3yX05qUMeEkZAYpkKWE7wIXucjWCLuHKrtUKsaiNcXkhCvG/QrhE 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 Hi, This patch fixed the problem when a LOOP_EXIT edge for the inner loop happened to target at the LOOP_LATCH of the outer loop. As the outer loop is processed first, the LOOP_BRANCH heuristic is honored (first_match), thus the inner loop's trip count is 0. (The attached unittest demonstrates this). Bootstrapped and passed gcc regression test. Is it ok for trunk? Thanks, Dehao gcc/ChangeLog 2012-07-30 Dehao Chen * predict.c (predict_loops): Fix the prediction of LOOP_BRANCH. gcc/testsuite/ChangeLog 2012-07-31 Dehao Chen * gcc.dg/predict-7.c: New test. Index: gcc/testsuite/gcc.dg/predict-7.c =================================================================== --- gcc/testsuite/gcc.dg/predict-7.c (revision 0) +++ gcc/testsuite/gcc.dg/predict-7.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-profile_estimate" } */ + +extern int global; + +int bar (int); + +void foo (int base) +{ + int i; + while (global < 10) + for (i = base; i < 10; i++) + bar (i); +} + +/* { dg-final { scan-tree-dump-times "loop branch heuristics" 0 "profile_estimate"} } */ +/* { dg-final { cleanup-tree-dump "profile_estimate" } } */ Index: gcc/predict.c =================================================================== --- gcc/predict.c (revision 189835) +++ gcc/predict.c (working copy) @@ -1404,7 +1404,7 @@ /* Loop branch heuristics - predict an edge back to a loop's head as taken. */ - if (bb == loop->latch) + if (bb == loop->latch && bb->loop_father == loop) { e = find_edge (loop->latch, loop->header); if (e)