From patchwork Wed Oct 16 12:56:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 283939 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 41F5C2C0126 for ; Wed, 16 Oct 2013 23:56:22 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=JYPYiv3EVMuim9LlK qp8KDa+Ryvqc0DsgXPyV8HeTRYa8R68FVqDwyfFbn6Jrm7msnvwVlOUB0OUgmsUC iRNJxV3uVWmyr642NJFUzjkzVvkabkDzLg1Pb6KDRbtrSFfxMe67NqnqB785qgb1 gktaKN4bgQ2wq52yaUXttH5UHk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=2nzxF9up0RKKuV0Gy5fd8aM A8B8=; b=Ljg0UXeuoelomMh1O2yx/+KAWSuw+tpvQ2ry4lSjV6AsuMritZeT6/v 6ms4uukmlRj0IbFWw4tpCJfIho/Q0YVU9QSsb73Y//vAYjsaABpfDu6h6+TT6CZv Ur2ekTcEGenKyPJKBFT+xIObc/iXLvurbgRFpnTeiqt4z8uCOFjc= Received: (qmail 7050 invoked by alias); 16 Oct 2013 12:56:16 -0000 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 Received: (qmail 7040 invoked by uid 89); 16 Oct 2013 12:56:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Oct 2013 12:56:14 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9GCuDJC003866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 16 Oct 2013 08:56:13 -0400 Received: from [10.10.57.246] (vpn-57-246.rdu2.redhat.com [10.10.57.246]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9GCuBHp025330; Wed, 16 Oct 2013 08:56:12 -0400 Message-ID: <525E8CEB.9030307@redhat.com> Date: Wed, 16 Oct 2013 08:56:11 -0400 From: Andrew MacLeod User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: Andrew MacLeod CC: gcc-patches , Richard Biener , Jakub Jelinek Subject: Re: [patch] (un)fix loop unswitching. References: <525E804F.6020303@redhat.com> In-Reply-To: <525E804F.6020303@redhat.com> X-IsSubscribed: yes Bah, bounced due to html or something. My latest email client upgrade must have lost the 'plain text only' attribute.. On 10/16/2013 08:02 AM, Andrew MacLeod wrote: > More or less the same patch that I put in bugzilla > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58697 > > I've bootstrapped it and run it through regressions. Jakubs test case > fails again like it did before my changes, so it no longer masks the > problem. > > Loop unswitching was calling estimate_loop_iterations_int, which for > various annoying reasons ended up in cfgloop and called > get_estimate_loop_iterations, so it wasn't doing the calculations. > Hopefully its clearer now. > > The end result now is that cfgloop.c has 4 accessor routines which > just retrieve info: > get_estimated_loop_iterations, get_estimated_loop_iterations_int, > get_max_loop_iterations, and get_max_loop_iterations_int. > > tree-ssa-loop-niter.c has 4 routines which create the information > first, if they can, then retrieve the information. > estimated_loop_iterations, estimated_loop_iterations_int, > max_loop_iterations, and max_loop_iterations_int. > > all the cfg* routines call the 'get_' variety, and all the tree-ssa > routines call the non 'get_' variety to calculate things if need be. > > Bootstraps on x86_64-unknown-linux-gnu and no regressions. OK? I > presume Jakub's test case isn't in the testsuite anywhere then? I > presume it would go in along with a fix to the original problem > > Andrew * cfgloop.c (get_estimated_loop_iterations_int): Rename from estimated_loop_iterations_int. (max_stmt_executions_int): Call get_max_loop_iterations_int. (get_max_loop_iterations_int): New. HWINT version of get_max_loop_iterations. * cfgloop.h: Add prototypes. * loop-iv.c (find_simple_exit): call get_estimated_loop_iterations_int. * loop-unroll.c (decide_peel_once_rolling): Call get_estimated_loop_iterations_int. * tree-ssa-loop-niter.c (estimated_loop_iterations_int): Add back. * tree-ssa-loop-niter.h: Tweak prototypes. Index: cfgloop.c =================================================================== *** cfgloop.c (revision 203625) --- cfgloop.c (working copy) *************** record_niter_bound (struct loop *loop, d *** 1815,1826 **** loop->nb_iterations_estimate = loop->nb_iterations_upper_bound; } ! /* Similar to estimated_loop_iterations, but returns the estimate only if it fits to HOST_WIDE_INT. If this is not the case, or the estimate on the number of iterations of LOOP could not be derived, returns -1. */ HOST_WIDE_INT ! estimated_loop_iterations_int (struct loop *loop) { double_int nit; HOST_WIDE_INT hwi_nit; --- 1815,1826 ---- loop->nb_iterations_estimate = loop->nb_iterations_upper_bound; } ! /* Similar to get_estimated_loop_iterations, but returns the estimate only if it fits to HOST_WIDE_INT. If this is not the case, or the estimate on the number of iterations of LOOP could not be derived, returns -1. */ HOST_WIDE_INT ! get_estimated_loop_iterations_int (struct loop *loop) { double_int nit; HOST_WIDE_INT hwi_nit; *************** estimated_loop_iterations_int (struct lo *** 1842,1848 **** HOST_WIDE_INT max_stmt_executions_int (struct loop *loop) { ! HOST_WIDE_INT nit = max_loop_iterations_int (loop); HOST_WIDE_INT snit; if (nit == -1) --- 1842,1848 ---- HOST_WIDE_INT max_stmt_executions_int (struct loop *loop) { ! HOST_WIDE_INT nit = get_max_loop_iterations_int (loop); HOST_WIDE_INT snit; if (nit == -1) *************** get_max_loop_iterations (struct loop *lo *** 1891,1893 **** --- 1891,1915 ---- *nit = loop->nb_iterations_upper_bound; return true; } + + /* Similar to get_max_loop_iterations, but returns the estimate only + if it fits to HOST_WIDE_INT. If this is not the case, or the estimate + on the number of iterations of LOOP could not be derived, returns -1. */ + + HOST_WIDE_INT + get_max_loop_iterations_int (struct loop *loop) + { + double_int nit; + HOST_WIDE_INT hwi_nit; + + if (!get_max_loop_iterations (loop, &nit)) + return -1; + + if (!nit.fits_shwi ()) + return -1; + hwi_nit = nit.to_shwi (); + + return hwi_nit < 0 ? -1 : hwi_nit; + } + + Index: cfgloop.h =================================================================== *** cfgloop.h (revision 203625) --- cfgloop.h (working copy) *************** loop_outermost (struct loop *loop) *** 740,747 **** } extern void record_niter_bound (struct loop *, double_int, bool, bool); ! extern HOST_WIDE_INT estimated_loop_iterations_int (struct loop *); ! extern HOST_WIDE_INT max_loop_iterations_int (struct loop *); extern bool get_estimated_loop_iterations (struct loop *loop, double_int *nit); extern bool get_max_loop_iterations (struct loop *loop, double_int *nit); --- 740,747 ---- } extern void record_niter_bound (struct loop *, double_int, bool, bool); ! extern HOST_WIDE_INT get_estimated_loop_iterations_int (struct loop *); ! extern HOST_WIDE_INT get_max_loop_iterations_int (struct loop *); extern bool get_estimated_loop_iterations (struct loop *loop, double_int *nit); extern bool get_max_loop_iterations (struct loop *loop, double_int *nit); Index: loop-iv.c =================================================================== *** loop-iv.c (revision 203625) --- loop-iv.c (working copy) *************** find_simple_exit (struct loop *loop, str *** 3001,3009 **** fprintf (dump_file, "\n"); fprintf (dump_file, " upper bound: %li\n", ! (long)max_loop_iterations_int (loop)); fprintf (dump_file, " realistic bound: %li\n", ! (long)estimated_loop_iterations_int (loop)); } else fprintf (dump_file, "Loop %d is not simple.\n", loop->num); --- 3001,3009 ---- fprintf (dump_file, "\n"); fprintf (dump_file, " upper bound: %li\n", ! (long)get_max_loop_iterations_int (loop)); fprintf (dump_file, " realistic bound: %li\n", ! (long)get_estimated_loop_iterations_int (loop)); } else fprintf (dump_file, "Loop %d is not simple.\n", loop->num); Index: loop-unroll.c =================================================================== *** loop-unroll.c (revision 203625) --- loop-unroll.c (working copy) *************** decide_peel_once_rolling (struct loop *l *** 469,475 **** || desc->infinite || !desc->const_iter || (desc->niter != 0 ! && max_loop_iterations_int (loop) != 0)) { if (dump_file) fprintf (dump_file, --- 469,475 ---- || desc->infinite || !desc->const_iter || (desc->niter != 0 ! && get_max_loop_iterations_int (loop) != 0)) { if (dump_file) fprintf (dump_file, Index: loop-unswitch.c =================================================================== *** loop-unswitch.c (revision 203625) --- loop-unswitch.c (working copy) *************** unswitch_single_loop (struct loop *loop, *** 304,310 **** } /* Nor if the loop usually does not roll. */ ! iterations = estimated_loop_iterations_int (loop); if (iterations >= 0 && iterations <= 1) { if (dump_file) --- 304,310 ---- } /* Nor if the loop usually does not roll. */ ! iterations = get_estimated_loop_iterations_int (loop); if (iterations >= 0 && iterations <= 1) { if (dump_file) Index: tree-ssa-loop-niter.c =================================================================== *** tree-ssa-loop-niter.c (revision 203625) --- tree-ssa-loop-niter.c (working copy) *************** estimated_loop_iterations (struct loop * *** 3388,3393 **** --- 3388,3414 ---- return (get_estimated_loop_iterations (loop, nit)); } + /* Similar to estimated_loop_iterations, but returns the estimate only + if it fits to HOST_WIDE_INT. If this is not the case, or the estimate + on the number of iterations of LOOP could not be derived, returns -1. */ + + HOST_WIDE_INT + estimated_loop_iterations_int (struct loop *loop) + { + double_int nit; + HOST_WIDE_INT hwi_nit; + + if (!estimated_loop_iterations (loop, &nit)) + return -1; + + if (!nit.fits_shwi ()) + return -1; + hwi_nit = nit.to_shwi (); + + return hwi_nit < 0 ? -1 : hwi_nit; + } + + /* Sets NIT to an upper bound for the maximum number of executions of the latch of the LOOP. If we have no reliable estimate, the function returns false, otherwise returns true. */ Index: tree-ssa-loop-niter.h =================================================================== *** tree-ssa-loop-niter.h (revision 203625) --- tree-ssa-loop-niter.h (working copy) *************** extern bool finite_loop_p (struct loop * *** 30,36 **** --- 30,38 ---- extern tree loop_niter_by_eval (struct loop *, edge); extern tree find_loop_niter_by_eval (struct loop *, edge *); extern bool estimated_loop_iterations (struct loop *, double_int *); + extern HOST_WIDE_INT estimated_loop_iterations_int (struct loop *); extern bool max_loop_iterations (struct loop *, double_int *); + extern HOST_WIDE_INT max_loop_iterations_int (struct loop *); extern HOST_WIDE_INT max_stmt_executions_int (struct loop *); extern HOST_WIDE_INT estimated_stmt_executions_int (struct loop *); extern bool max_stmt_executions (struct loop *, double_int *);