From patchwork Tue Oct 9 09:36:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 190249 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 40CDA2C00DA for ; Tue, 9 Oct 2012 20:37:17 +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=1350380238; 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=bI05qfD3alJM4tkf9S7a axLlWrc=; b=L7E4VLLD/OcYlow3aLp5RP7S2wcdvMvrrE4k5r1FNR6zQzWxeE86 vvRJDddNTdxXhmwse3a8LZfFoB1cI+47iYrmppRQB8LphHWmPqVFOXECMjgNap4O l2WuxJUrNkXb1VtwBAWUucdBu3RUI8htjfPUein2V70KBsF1Inzq84I= 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=HDxh79BJ0gz36DbvSe1xUsc0PCTLf8m2wj/Ioh8MB501Xuj06izRzy50RMqj5e pOTpO7+rHZ8VX91CsmmDd+V34Wp+TU3EfXaG7hAqIpyA30du1tfMXeX6wP7YW/k9 4wAbZm1MWO2FY4vE9lVWGKiqaCO0wSYaExi+pRC5iS1hA=; Received: (qmail 2793 invoked by alias); 9 Oct 2012 09:37:10 -0000 Received: (qmail 2583 invoked by uid 22791); 9 Oct 2012 09:37:06 -0000 X-SWARE-Spam-Status: No, hits=-4.9 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; Tue, 09 Oct 2012 09:37:01 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id D0B3E5435BF; Tue, 9 Oct 2012 11:36:59 +0200 (CEST) Date: Tue, 9 Oct 2012 11:36:59 +0200 From: Jan Hubicka To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: Re: Fix my change to unroll_loop_constant_iterations Message-ID: <20121009093659.GA14364@kam.mff.cuni.cz> References: <20121009083115.GA32592@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20121009083115.GA32592@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 > H, > I hope this change is responsible for today misoptimizations of SPEC at -O3. > While updating unroll_loop_constant_iterations and fighting with double_int > operations I made two trivial mistakes. > > I am bootstrapping/regtesting the following and will commit it as obvious if > it passes. > > Honza > > * loop-unroll.c (unroll_loop_constant_iterations): Fix previous patch. Unforutnately there is one other case where one has to be extra cureful about overflows. This is in fact latent bug in the unroller, but it now reproduce with -O3 -fpeel-loops bootstrap because estimates tends to be close to maximum of the integer types. I am re-starting testing with the following patch and will commit if passes (but i will be till 2pm on bus). My apologizes for the breakage. Honza Index: loop-unroll.c =================================================================== --- loop-unroll.c (revision 192240) +++ loop-unroll.c (working copy) @@ -740,6 +740,7 @@ unroll_loop_constant_iterations (struct apply_opt_in_copies (opt_info, exit_mod + 1, false, false); desc->niter -= exit_mod + 1; + loop->nb_iterations_upper_bound -= double_int::from_uhwi (exit_mod + 1); if (loop->any_estimate && double_int::from_uhwi (exit_mod + 1).ule (loop->nb_iterations_estimate)) @@ -795,12 +796,12 @@ unroll_loop_constant_iterations (struct desc->niter /= max_unroll + 1; loop->nb_iterations_upper_bound - = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (exit_mod + = loop->nb_iterations_upper_bound.udiv (double_int::from_uhwi (max_unroll + 1), FLOOR_DIV_EXPR); if (loop->any_estimate) loop->nb_iterations_estimate - = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (exit_mod + = loop->nb_iterations_estimate.udiv (double_int::from_uhwi (max_unroll + 1), FLOOR_DIV_EXPR); desc->niter_expr = GEN_INT (desc->niter); @@ -879,8 +880,7 @@ decide_unroll_runtime_iterations (struct /* If we have profile feedback, check whether the loop rolls. */ if ((estimated_loop_iterations (loop, &iterations) || max_loop_iterations (loop, &iterations)) - && iterations.fits_shwi () - && iterations.to_shwi () <= 2 * nunroll) + && iterations.ule (double_int::from_shwi (2 * nunroll))) { if (dump_file) fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n"); @@ -1280,8 +1280,7 @@ decide_peel_simple (struct loop *loop, i /* If we have realistic estimate on number of iterations, use it. */ if (estimated_loop_iterations (loop, &iterations)) { - if (!iterations.fits_shwi () - || iterations.to_shwi () + 1 > npeel) + if (double_int::from_shwi (npeel).ule (iterations)) { if (dump_file) { @@ -1298,8 +1297,7 @@ decide_peel_simple (struct loop *loop, i /* If we have small enough bound on iterations, we can still peel (completely unroll). */ else if (max_loop_iterations (loop, &iterations) - && iterations.fits_shwi () - && iterations.to_shwi () + 1 <= npeel) + && iterations.ult (double_int::from_shwi (npeel))) npeel = iterations.to_shwi () + 1; else { @@ -1449,8 +1447,7 @@ decide_unroll_stupid (struct loop *loop, /* If we have profile feedback, check whether the loop rolls. */ if ((estimated_loop_iterations (loop, &iterations) || max_loop_iterations (loop, &iterations)) - && iterations.fits_shwi () - && iterations.to_shwi () <= 2 * nunroll) + && iterations.ule (double_int::from_shwi (2 * nunroll))) { if (dump_file) fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");