From patchwork Mon Oct 22 15:26:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 193179 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 6FA432C008A for ; Tue, 23 Oct 2012 02:26:35 +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=1351524395; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID: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=NPns1w2lcXbBerkUPDF4sCsewdE=; b=sy7eQFxjT/Lf1DO qg/L7YRqQoUUwf0dEyta7VZJyQoLArDHZq/6sLdzvJbYmK9K8hz7tOMn2MiknUEc 3WyHx2BkYrr0PaxUQJWi7QoPQQG3ZO/wU0FePP+CG9GZmsLu7Nhyuz5fSWcvR5Lz QefP0hJk8DKSDBHYXD/SIXmghVzE= 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:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=GVdziy1ESIbimwik0ibt9NZ/B6nTJuVjX4XqeNsJUpFkW8yCGKEnIVN7RXAPm4 08n9/yPj/uddHAj7AjBNHc8kkvh8Uq7g+dEYidXO0rL9yEQm8PaNIwisp5AKXrpd qEfPHz9oE9oxyfNjGTqt0CHSeO6yFhIz+sij+BhkG2Qf0=; Received: (qmail 15762 invoked by alias); 22 Oct 2012 15:26:31 -0000 Received: (qmail 15753 invoked by uid 22791); 22 Oct 2012 15:26:30 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 22 Oct 2012 15:26:26 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 64B37543A16; Mon, 22 Oct 2012 17:26:25 +0200 (CEST) Date: Mon, 22 Oct 2012 17:26:25 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Minor record_upper_bound tweek Message-ID: <20121022152625.GA18262@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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, with profile feedback we may misupdate the profile and start to believe that loops iterate more times than they do. This patch makes at least nb_iterations_estimate no greater than nb_iterations_upper_bound. This makes the unrolling/peeling/unswitching heuristics to behave more consistently. Bootstrapped/regtested x86_64-linux, OK? Honza * tree-sssa-loop-niter.c (record_niter_bound): Be sure that realistic estimate is not bigger than upper bound. Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 192632) +++ tree-ssa-loop-niter.c (working copy) @@ -2506,13 +2506,20 @@ record_niter_bound (struct loop *loop, d { loop->any_upper_bound = true; loop->nb_iterations_upper_bound = i_bound; + if (loop->any_estimate + && i_bound.ult (loop->nb_iterations_estimate)) + loop->nb_iterations_estimate = i_bound; } if (realistic && (!loop->any_estimate || i_bound.ult (loop->nb_iterations_estimate))) { loop->any_estimate = true; - loop->nb_iterations_estimate = i_bound; + if (loop->nb_iterations_upper_bound.ult (i_bound) + && loop->any_upper_bound) + loop->nb_iterations_estimate = loop->nb_iterations_upper_bound; + else + loop->nb_iterations_estimate = i_bound; } /* If an upper bound is smaller than the realistic estimate of the