From patchwork Sat Oct 13 16:54:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 191301 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 D23242C0094 for ; Sun, 14 Oct 2012 03:54:24 +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=1350752066; 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=vzYmlF7ZS2IalJuXgPZAl4bCFWM=; b=Xz9wluhWIES1FBs kdUPn99RqF0Bs7ddqXpJJcjRKouR75Iwyd6xNu7BNUv3A84NgIpMvQUzLBBovux4 sAkSu23Qs72OAkBlhIXbgV/QjhuLE1XxjNGhib8T0uaI46ukfhUayQiaJ413QKwl XTPyz8aUXg50deM6qkxP3gzR1gdA= 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=isEzKHH60aaqgJqGbVMrUM9U/uS97hDQWWT2IwpKkyPxeDyvhR/WW50oQvxyCT JLhyBtPkoavbqTqX7XwzPSm9kKeP0aczQ8pdqHwSo6JTLdJd+m9NSGTDxxAXeBs/ HMfT8uwGG/9bnvprdBFeX/9mF7lBpANAWL9veNzZkuYK0=; Received: (qmail 23749 invoked by alias); 13 Oct 2012 16:54:18 -0000 Received: (qmail 23620 invoked by uid 22791); 13 Oct 2012 16:54:17 -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; Sat, 13 Oct 2012 16:54:11 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 8F92A54349E; Sat, 13 Oct 2012 18:54:10 +0200 (CEST) Date: Sat, 13 Oct 2012 18:54:10 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Two obvious loop-iv fixes Message-ID: <20121013165410.GA5237@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, while proofreading loop-iv for possible cause of the miscompilation that turned out to be webizer bug I noticed two minor problems. 1) determine_max_iter has path dealing with AND that is bogus, because constant argument is always canonized to be second. Enabling the path however somethimes leads to worse results, so I improved it a bit by combining both estimates. 2) bounds are recorded as signed values intead of unsigned. This means that values with upper bit set gets promoted to almost infinity for double int. Bootstrapped®tested x86_64-linux, comitted as obvious. Honza * loop-iv.c (determine_max_iter): Fix handling of AND. (iv_number_of_iterations): Record upper bounds as unsigned values. Index: loop-iv.c =================================================================== --- loop-iv.c (revision 192409) +++ loop-iv.c (working copy) @@ -2224,13 +2224,18 @@ determine_max_iter (struct loop *loop, s rtx niter = desc->niter_expr; rtx mmin, mmax, cmp; unsigned HOST_WIDEST_INT nmax, inc; + unsigned HOST_WIDEST_INT andmax = 0; + + /* We used to look for constant operand 0 of AND, + but canonicalization should always make this impossible. */ + gcc_checking_assert (GET_CODE (niter) != AND + || !CONST_INT_P (XEXP (niter, 0))); if (GET_CODE (niter) == AND - && CONST_INT_P (XEXP (niter, 0))) + && CONST_INT_P (XEXP (niter, 1))) { - nmax = INTVAL (XEXP (niter, 0)); - if (!(nmax & (nmax + 1))) - return nmax; + andmax = UINTVAL (XEXP (niter, 1)); + niter = XEXP (niter, 0); } get_mode_bounds (desc->mode, desc->signed_p, desc->mode, &mmin, &mmax); @@ -2258,7 +2263,13 @@ determine_max_iter (struct loop *loop, s if (dump_file) fprintf (dump_file, ";; improved upper bound by one.\n"); } - return nmax / inc; + nmax /= inc; + if (andmax) + nmax = MIN (nmax, andmax); + if (dump_file) + fprintf (dump_file, ";; Determined upper bound "HOST_WIDEST_INT_PRINT_DEC".\n", + nmax); + return nmax; } /* Computes number of iterations of the CONDITION in INSN in LOOP and stores @@ -2563,7 +2574,7 @@ iv_number_of_iterations (struct loop *lo ? iv0.base : mode_mmin); max = (up - down) / inc + 1; - record_niter_bound (loop, double_int::from_shwi (max), + record_niter_bound (loop, double_int::from_uhwi (max), false, true); if (iv0.step == const0_rtx) @@ -2776,14 +2787,14 @@ iv_number_of_iterations (struct loop *lo desc->const_iter = true; desc->niter = val & GET_MODE_MASK (desc->mode); - record_niter_bound (loop, double_int::from_shwi (desc->niter), + record_niter_bound (loop, double_int::from_uhwi (desc->niter), false, true); } else { max = determine_max_iter (loop, desc, old_niter); gcc_assert (max); - record_niter_bound (loop, double_int::from_shwi (max), + record_niter_bound (loop, double_int::from_uhwi (max), false, true); /* simplify_using_initial_values does a copy propagation on the registers