From patchwork Thu May 3 11:45:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 156670 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 96647B6FBE for ; Thu, 3 May 2012 21:46:13 +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=1336650374; 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=BDEIKcY D++ABp/+fkntxvTstruY=; b=aMEpAYWQBxXB3av+85zIrYxTA7LS7ZAu1n7FKSA p/O3Q9gJRivskKoL7SnW/MMbCJK/2Uv0amMDfA8unjWoaPysoTl4/SZAnS+ubqNW IsqB0BWHCz7VxvNNOqwaP2sXAjYwSzU3++eaKQ/QkdRlckCuNtTBFXvqkhNf/AQP nGdE= 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=hEnwJpIngZYg/1uI75BRi+XMtVGRjVIp0C1F9/yX5eSIJFnft6ERTKpYfPfaP9 cknTy3a1CNQGM8w+D9pyNkJGiBVVYOS3V41YnjAa5mCfgsleXzkjVZu47AdkxoYy OvIu7EW30ni+G4NUJiXxGPSm9DT00IzN0cvod3SyHkhVs=; Received: (qmail 11165 invoked by alias); 3 May 2012 11:46:10 -0000 Received: (qmail 11156 invoked by uid 22791); 3 May 2012 11:46:08 -0000 X-SWARE-Spam-Status: No, hits=-4.5 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-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 May 2012 11:45:55 +0000 Received: by yenm3 with SMTP id m3so1822802yen.20 for ; Thu, 03 May 2012 04:45:55 -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=w2G+jGoNvfjXkDUOnt/35sPqormLA9qTupk0txgx3/E=; b=Xz6ZSVXpfoLWSaCOqrJsyfqB2bZVcxHo/O3ZweUD98adXhZ5w3IIgWjL8i/XQ4Fxjj NCmn1zn6MQrDLHu8yFUV85guO5Gyo+BumSosg78W5sccIUkFtKviAK1zYJNFsXn9g3mv FBlJcboVbqIhH6vFg9mUHN0eeNABQE697rO4WPqcZT82rYBUYLtleg+YViLoIDdlkA6W O7k4EJHDFwtFKpdTTy9/Yf+rOmrRqp1lt96e72xtP6fxJKnntDK6kK9l/iBznKMIOHFY L8SfenLCg/y7K4h2WH5EDxo0vUo/mt8Vg4DM+ROhp1yCclqhLLfXlUEwef/qdjI7vqI/ Sj2Q== Received: by 10.50.88.199 with SMTP id bi7mr502800igb.26.1336045554540; Thu, 03 May 2012 04:45:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.88.199 with SMTP id bi7mr502795igb.26.1336045554442; Thu, 03 May 2012 04:45:54 -0700 (PDT) Received: by 10.50.46.132 with HTTP; Thu, 3 May 2012 04:45:54 -0700 (PDT) Date: Thu, 3 May 2012 19:45:54 +0800 Message-ID: Subject: [google] re-enable r185948 From: Dehao Chen To: gcc-patches@gcc.gnu.org Cc: David Li X-System-Of-Record: true X-Gm-Message-State: ALoCoQn9Bf2sLwI4C/BqJ99OZvsYyzA+SEf156hAwycrtTQGnwd+jgqNJplJShFY+KHAbrel2X/j5CSU4+ll0Cx2U+9cjyC+8Sf0dJJ682yuJ/H/dVumfda4Y9cL0lQdgq/wWooAiSYSPeLSSwWEpQ7Qg/Lwef51Sg== 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 was reverted because of performance degradation. However, it turns out to be an innocent performance loss. Thus we want to reenable it in google branches. Passed bootstrap and gcc regression tests and google performance tests. OK for google branch? Thanks, Dehao gcc/ChangeLog.google-4_6 2012-05-03 Dehao Chen * predict.c (predict_iv_comparison): Add the comparison of induction variable against its initial value. (Reenable r185948) gcc/testsuite/ChangeLog.google-4_6 2012-05-03 Dehao Chen * gcc.dg/predict-1.c: Check if LOOP_IV_COMPARE static predict heuristic is working properly. Reenable r185948. * gcc.dg/predict-2.c: Likewise * gcc.dg/predict-3.c: Likewise * gcc.dg/predict-4.c: Likewise * gcc.dg/predict-5.c: Likewise * gcc.dg/predict-6.c: Likewise Index: testsuite/gcc.dg/predict-3.c =================================================================== --- testsuite/gcc.dg/predict-3.c (revision 187013) +++ testsuite/gcc.dg/predict-3.c (working copy) @@ -10,10 +10,16 @@ int i, ret = 0; for (i = 0; i <= bound; i++) { + if (i < bound - 2) + global += bar (i); + if (i <= bound) + global += bar (i); + if (i + 1 < bound) + global += bar (i); if (i != bound) global += bar (i); } } -/* { dg-final { scan-tree-dump "loop iv compare heuristics" "profile_estimate"} } */ +/* { dg-final { scan-tree-dump-times "loop iv compare heuristics: 100.0%" 4 "profile_estimate"} } */ /* { dg-final { cleanup-tree-dump "profile_estimate" } } */ Index: testsuite/gcc.dg/predict-4.c =================================================================== --- testsuite/gcc.dg/predict-4.c (revision 187013) +++ testsuite/gcc.dg/predict-4.c (working copy) @@ -15,5 +15,5 @@ } } -/* { dg-final { scan-tree-dump "loop iv compare heuristics" "profile_estimate"} } */ +/* { dg-final { scan-tree-dump "loop iv compare heuristics: 50.0%" "profile_estimate"} } */ /* { dg-final { cleanup-tree-dump "profile_estimate" } } */ Index: testsuite/gcc.dg/predict-1.c =================================================================== --- testsuite/gcc.dg/predict-1.c (revision 187013) +++ testsuite/gcc.dg/predict-1.c (working copy) @@ -10,10 +10,18 @@ int i, ret = 0; for (i = 0; i < bound; i++) { + if (i > bound) + global += bar (i); + if (i >= bound + 2) + global += bar (i); if (i > bound - 2) global += bar (i); + if (i + 2 > bound) + global += bar (i); + if (i == 10) + global += bar (i); } } -/* { dg-final { scan-tree-dump "loop iv compare heuristics" "profile_estimate"} } */ +/* { dg-final { scan-tree-dump-times "loop iv compare heuristics: 0.0%" 5 "profile_estimate"} } */ /* { dg-final { cleanup-tree-dump "profile_estimate" } } */ Index: testsuite/gcc.dg/predict-2.c =================================================================== --- testsuite/gcc.dg/predict-2.c (revision 187013) +++ testsuite/gcc.dg/predict-2.c (working copy) @@ -5,12 +5,20 @@ int bar(int); -void foo (int bound) +void foo (int base, int bound) { int i, ret = 0; - for (i = 0; i < bound; i++) + for (i = base; i < bound; i++) { - if (i > bound * bound ) + if (i > bound * bound) + global += bar (i); + if (i > bound + 10) + global += bar (i); + if (i <= bound + 10) + global += bar (i); + if (i > base + 10) + global += bar (i); + if (i < base - 10) global += bar (i); } } Index: predict.c =================================================================== --- predict.c (revision 187013) +++ predict.c (working copy) @@ -1070,6 +1070,10 @@ bound = get_base_value (bound); if (!bound) return false; + if (TREE_CODE (base) != INTEGER_CST) + base = get_base_value (base); + if (!base) + return false; *loop_invariant = bound; *compare_code = code; @@ -1185,8 +1189,7 @@ return; } - if (!expr_coherent_p (loop_bound_var, compare_var) - || loop_iv_base_var != compare_base) + if (!expr_coherent_p(loop_iv_base_var, compare_base)) return; /* If loop bound, base and compare bound are all constents, we can @@ -1230,34 +1233,52 @@ return; } - if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR) - && (compare_code == LT_EXPR || compare_code == LE_EXPR)) - predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); - else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR) - && (compare_code == GT_EXPR || compare_code == GE_EXPR)) - predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); - else if (loop_bound_code == NE_EXPR) - { - /* If the loop backedge condition is "(i != bound)", we do - the comparison based on the step of IV: - * step < 0 : backedge condition is like (i > bound) - * step > 0 : backedge condition is like (i < bound) */ - gcc_assert (loop_bound_step != 0); + if (expr_coherent_p (loop_bound_var, compare_var)) + { + if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR) + && (compare_code == LT_EXPR || compare_code == LE_EXPR)) + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); + else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR) + && (compare_code == GT_EXPR || compare_code == GE_EXPR)) + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); + else if (loop_bound_code == NE_EXPR) + { + /* If the loop backedge condition is "(i != bound)", we do + the comparison based on the step of IV: + * step < 0 : backedge condition is like (i > bound) + * step > 0 : backedge condition is like (i < bound) */ + gcc_assert (loop_bound_step != 0); + if (loop_bound_step > 0 + && (compare_code == LT_EXPR + || compare_code == LE_EXPR)) + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); + else if (loop_bound_step < 0 + && (compare_code == GT_EXPR + || compare_code == GE_EXPR)) + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); + else + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN); + } + else + /* The branch is predicted not-taken if loop_bound_code is + opposite with compare_code. */ + predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN); + } + else if (expr_coherent_p (loop_iv_base_var, compare_var)) + { + /* For cases like: + for (i = s; i < h; i++) + if (i > s + 2) .... + The branch should be predicted taken. */ if (loop_bound_step > 0 - && (compare_code == LT_EXPR - || compare_code == LE_EXPR)) + && (compare_code == GT_EXPR || compare_code == GE_EXPR)) predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); else if (loop_bound_step < 0 - && (compare_code == GT_EXPR - || compare_code == GE_EXPR)) + && (compare_code == LT_EXPR || compare_code == LE_EXPR)) predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN); else predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN); } - else - /* The branch is predicted not-taken if loop_bound_code is - opposite with compare_code. */ - predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN); } /* Predict edge probabilities by exploiting loop structure. */