From patchwork Tue Jan 8 20:05:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 210490 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 1C8CD2C00A4 for ; Wed, 9 Jan 2013 07:06:02 +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=1358280363; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=qiBjBuGkI+1LWD3xYC2d +6dGDLo=; b=rqt0kbpHfOYz2k0JaN6GspsPiJI1KRymIV5lpgSTMSMJdcrsA7vv arN7tSp+/Kydwl7S0HViTOesw+4ck1wFNQxFQf2kjT4S0xFHyYfZtVjqfBn3D+wJ HtE/+bZp+WhlzW28xchksf3wc3jMtgTA8EglotYz+IhO7EBmBpvpLqI= 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:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ql5KW/kqJuw/7tiDYsl/EdFCTGF1mpviibNomDpSprWBD1e50o7QNmk0FjwG0G 8LakjZksmxcTMeY2TVTK2IMv0926hW3ZfrR835rVE3bW9/+tK+uAd8pk7h4tdgZZ FeHMjWFEoj+Tfjtw5mDUFQBxlccqg5vBg8ik5urMe4TKw=; Received: (qmail 32320 invoked by alias); 8 Jan 2013 20:05:58 -0000 Received: (qmail 32311 invoked by uid 22791); 8 Jan 2013 20:05:57 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Jan 2013 20:05:50 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r08K5oO7021563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Jan 2013 15:05:50 -0500 Received: from zalov.redhat.com (vpn1-5-98.ams2.redhat.com [10.36.5.98]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r08K5lVK027366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 8 Jan 2013 15:05:49 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r08K5lXZ031629; Tue, 8 Jan 2013 21:05:47 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r08K5f9s031628; Tue, 8 Jan 2013 21:05:41 +0100 Date: Tue, 8 Jan 2013 21:05:40 +0100 From: Jakub Jelinek To: Richard Biener , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] predict_loop fix (PR tree-optimization/48189) Message-ID: <20130108200540.GO7269@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 is Steven's patch from the PR plus mine hunk, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-08 Steven Bosscher Jakub Jelinek PR tree-optimization/48189 * predict.c (predict_loops): If max is 0, don't call compare_tree_int. If nitercst is 0, don't predict the exit edge. * gcc.dg/pr48189.c: New test. Jakub --- gcc/predict.c.jj 2013-01-04 13:44:35.000000000 +0100 +++ gcc/predict.c 2013-01-08 15:58:15.552884491 +0100 @@ -1434,7 +1434,8 @@ predict_loops (void) if (TREE_CODE (niter) == INTEGER_CST) { if (host_integerp (niter, 1) - && compare_tree_int (niter, max-1) == -1) + && max + && compare_tree_int (niter, max - 1) == -1) nitercst = tree_low_cst (niter, 1) + 1; else nitercst = max; @@ -1456,6 +1457,11 @@ predict_loops (void) else continue; + /* If the prediction for number of iterations is zero, do not + predict the exit edges. */ + if (nitercst == 0) + continue; + probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst); predict_edge (ex, predictor, probability); } --- gcc/testsuite/gcc.dg/pr48189.c.jj 2013-01-08 15:59:38.319433008 +0100 +++ gcc/testsuite/gcc.dg/pr48189.c 2013-01-08 15:52:31.000000000 +0100 @@ -0,0 +1,13 @@ +/* PR tree-optimization/48189 */ +/* { dg-do compile } */ +/* { dg-options "-O --param max-predicted-iterations=0" } */ + +struct S { int s[8]; }; + +void +foo (int *x, struct S *y) +{ + int i; + for (i = 0; y[i].s[i]; i++) + *x++ = y[i].s[i]; +}