From patchwork Wed Nov 21 16:25:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 200802 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 526FC2C008F for ; Thu, 22 Nov 2012 03:26:06 +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=1354119966; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=1j01Ey++ErLSiXwscGuf TeZQpsA=; b=NmzLwOioVwdxphoVQ9fiQdxPFxSmqlfUzqCHFC3FGb/KmAelvmV9 rjno+KmXbOV0ZFR70DzxWlqYbdy5yKes2XSRLFZavYhFKmNcC+AvcEZM9xkZqlam bmKg6SKvCt46l3HIWSmNdR9+EHuOLXuCnEPPO28Nzzmk6zVO0LzLzrU= 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:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Ih4rwpG7FeJV2hpihyN75kmi4IQzHN+FCXEh2koBI6Uc8zExypuUC0GMf9KKmt BNZYiPwIfgV4ntCOVf0VRVn/tozVLod3N82pjcwVKbYLYLfsn00LctDwtpud/npJ Gby59/w5bD3ihiZh8DKmoWw+Ly7w1L9XFKcJl3mRaTDOE=; Received: (qmail 8886 invoked by alias); 21 Nov 2012 16:25:56 -0000 Received: (qmail 8868 invoked by uid 22791); 21 Nov 2012 16:25:53 -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, TW_TM 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; Wed, 21 Nov 2012 16:25:40 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id F4097544098; Wed, 21 Nov 2012 17:25:35 +0100 (CET) Date: Wed, 21 Nov 2012 17:25:35 +0100 From: Jan Hubicka To: Jan Hubicka Cc: Eric Botcazou , gcc-patches@gcc.gnu.org, jakub@redhat.com Subject: Re: Reduce complette unrolling & peeling limits Message-ID: <20121121162535.GA32567@kam.mff.cuni.cz> References: <20121114233407.GC12910@kam.mff.cuni.cz> <20121118165230.GC27832@atrey.karlin.mff.cuni.cz> <20121118170852.GA18650@kam.mff.cuni.cz> <3701798.hzb6LFUzXT@polaris> <20121119124644.GA7359@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20121119124644.GA7359@kam.mff.cuni.cz> 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, here is updated patch. It should get the bounds safe enough to not have effect on codegen of complette unrolling. There is IMO no way to cut the walk of loop body w/o affecting codegen in unrolling for size mode. The condition on unroling to happen is unrolled_size * 2 / 3 < original_size The patch makes the function walking body to stop after minimal number of duplicated insns is large (PARAM_MAX_COMPLETELY_PEELED_INSNS). The formula above allows unlimited duplication when loop body is large enough. This is more a bug than feature, so I think it is safe to alter it. Bootstrapped/regtested x86_64-linux, OK? Honza * tree-ssa-loop-ivcanon.c (tree_estimate_loop_size): Add UPPER_BOUND parameter. (try_unroll_loop_completely) Update. Index: tree-ssa-loop-ivcanon.c =================================================================== --- tree-ssa-loop-ivcanon.c (revision 193694) +++ tree-ssa-loop-ivcanon.c (working copy) @@ -1,5 +1,5 @@ -/* Induction variable canonicalization. - Copyright (C) 2004, 2005, 2007, 2008, 2010 +/* Induction variable canonicalization and loop peeling. + Copyright (C) 2004, 2005, 2007, 2008, 2010, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -207,10 +210,12 @@ constant_after_peeling (tree op, gimple iteration of the loop. EDGE_TO_CANCEL (if non-NULL) is an non-exit edge eliminated in the last iteration of loop. - Return results in SIZE, estimate benefits for complete unrolling exiting by EXIT. */ + Return results in SIZE, estimate benefits for complete unrolling exiting by EXIT. + Stop estimating after UPPER_BOUND is met. Return true in this case */ -static void -tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, struct loop_size *size) +static bool +tree_estimate_loop_size (struct loop *loop, edge exit, edge edge_to_cancel, struct loop_size *size, + int upper_bound) { basic_block *body = get_loop_body (loop); gimple_stmt_iterator gsi; @@ -316,6 +321,12 @@ tree_estimate_loop_size (struct loop *lo if (likely_eliminated || likely_eliminated_last) size->last_iteration_eliminated_by_peeling += num; } + if ((size->overall * 3 / 2 - size->eliminated_by_peeling + - size->last_iteration_eliminated_by_peeling) > upper_bound) + { + free (body); + return true; + } } } while (path.length ()) @@ -357,6 +368,7 @@ tree_estimate_loop_size (struct loop *lo size->last_iteration_eliminated_by_peeling); free (body); + return false; } /* Estimate number of insns of completely unrolled loop. @@ -699,12 +711,22 @@ try_unroll_loop_completely (struct loop sbitmap wont_exit; edge e; unsigned i; - vec to_remove = vNULL; + bool large; + vec to_remove = vNULL; if (ul == UL_SINGLE_ITER) return false; - tree_estimate_loop_size (loop, exit, edge_to_cancel, &size); + large = tree_estimate_loop_size + (loop, exit, edge_to_cancel, &size, + PARAM_VALUE (PARAM_MAX_COMPLETELY_PEELED_INSNS)); ninsns = size.overall; + if (large) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Not unrolling loop %d: it is too large.\n", + loop->num); + return false; + } unr_insns = estimated_unrolled_size (&size, n_unroll); if (dump_file && (dump_flags & TDF_DETAILS))