From patchwork Sat Oct 20 15:53:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 192924 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 30AB42C008D for ; Sun, 21 Oct 2012 02:54:22 +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=1351353277; 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=quYjYk0UBUVJmy0IQlFt1I6nKwM=; b=weYjLSg+bpjJ4T+ SSntz2Asm1Xxi0FhpILhizp+DkNLYgIJ4iTCW6TywRYHOT61dfF7q9BspEKZG1wh x/zoM9zbezhm+/1beUhb1evE9iLlYOMzOJQXcbTy4NWBRzsT0jNIr0vO+xZLSsE+ 0jpCGCtm/kG9pofJ9t536mGt0kC4= 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=O//C9uR5m8vz970ijMQLeVgcgxEaytxjNGZCAvRVsOf3L7a2i2AGn3msi2jvAt VpQhekQw4WIWnw1t+IiyNh1vf9SE0wK2yL+qKyJJvk8TuuA2OZYCS4R9e5xBXusj ZoPCp2PRd87i7KiRkA5sU+OFiNLpe28qAl/WAMXjZFqJ4=; Received: (qmail 11291 invoked by alias); 20 Oct 2012 15:54:16 -0000 Received: (qmail 11261 invoked by uid 22791); 20 Oct 2012 15:54:13 -0000 X-SWARE-Spam-Status: No, hits=-4.0 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; Sat, 20 Oct 2012 15:53:25 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id AFB115438DF; Sat, 20 Oct 2012 17:53:23 +0200 (CEST) Date: Sat, 20 Oct 2012 17:53:23 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: loop-unroll.c TLC 2/4 Message-ID: <20121020155323.GA4688@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, this patch fixes heuristic on decide_unroll_constant_iterations to take into account the profile: even when the loop is known to have constant loop iteration bound, it doesn't need to really iterate many times. So use profile and loop_max to double check that this is the case. Bootstrapped/regtested x86_64-linux, comitted. Honza * loop-unroll.c (decide_unroll_constant_iterations): Don't perform unrolling for loops with low iterations bounds or estimates. Index: loop-unroll.c =================================================================== --- loop-unroll.c (revision 192632) +++ loop-unroll.c (working copy) @@ -519,6 +519,7 @@ decide_unroll_constant_iterations (struc { unsigned nunroll, nunroll_by_av, best_copies, best_unroll = 0, n_copies, i; struct niter_desc *desc; + double_int iterations; if (!(flags & UAP_UNROLL)) { @@ -561,8 +562,14 @@ decide_unroll_constant_iterations (struc return; } - /* Check whether the loop rolls enough to consider. */ - if (desc->niter < 2 * nunroll) + /* Check whether the loop rolls enough to consider. + Consult also loop bounds and profile; in the case the loop has more + than one exit it may well loop less than determined maximal number + of iterations. */ + if (desc->niter < 2 * nunroll + || ((estimated_loop_iterations (loop, &iterations) + || max_loop_iterations (loop, &iterations)) + && iterations.ult (double_int::from_shwi (2 * nunroll)))) { if (dump_file) fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n"); Index: testsuite/gcc.dg/tree-prof/unroll-1.c =================================================================== --- testsuite/gcc.dg/tree-prof/unroll-1.c (revision 0) +++ testsuite/gcc.dg/tree-prof/unroll-1.c (revision 0) @@ -0,0 +1,24 @@ +/* { dg-options "-O3 -fdump-rtl-loop2_unroll -funroll-loops -fno-peel-loops" } */ +void abort (); + +int a[1000]; +int +__attribute__ ((noinline)) +t() +{ + int i; + for (i=0;i<1000;i++) + if (!a[i]) + return 1; + abort (); +} +main() +{ + int i; + for (i=0;i<1000;i++) + t(); + return 0; +} +/* { dg-final-use { scan-rtl-dump "Considering unrolling loop with constant number of iterations" "loop2_unroll" } } */ +/* { dg-final-use { cleanup-rtl-dump "Not unrolling loop, doesn't roll" } } */ +/* { dg-options "-O3 -fdump-rtl-loop2_unroll -funroll-loops -fno-peel-loops" } */