From patchwork Thu Oct 14 21:37:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 67869 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 AB8C0B70E6 for ; Fri, 15 Oct 2010 08:37:29 +1100 (EST) Received: (qmail 5480 invoked by alias); 14 Oct 2010 21:37:26 -0000 Received: (qmail 5471 invoked by uid 22791); 14 Oct 2010 21:37:25 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Oct 2010 21:37:20 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9ELbJXr008896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Oct 2010 17:37:19 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9ELbIwj024235 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 14 Oct 2010 17:37:19 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o9ELbH5T026086 for ; Thu, 14 Oct 2010 23:37:18 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o9ELbHiW026084 for gcc-patches@gcc.gnu.org; Thu, 14 Oct 2010 23:37:17 +0200 Date: Thu, 14 Oct 2010 23:37:17 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix *DIV_EXPR folding on 32-bit HWI (PR middle-end/46019) Message-ID: <20101014213717.GB18103@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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! integer_pow2p can return true even for large constants that have TREE_INT_CST_LOW zero, but some bit set in TREE_INT_CST_HIGH (either for 32-bit HWI and long long, or I guess for TImode on 64-bit HWI). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.5/4.4? 2010-10-14 Jakub Jelinek PR middle-end/46019 * fold-const.c (fold_binary_loc): If integer_pow2p has TREE_INT_CST_LOW zero, look at TREE_INT_CST_HIGH. * gcc.c-torture/execute/pr46019.c: New test. Jakub --- gcc/fold-const.c.jj 2010-10-07 19:45:22.000000000 +0200 +++ gcc/fold-const.c 2010-10-14 19:13:37.000000000 +0200 @@ -11611,7 +11611,13 @@ fold_binary_loc (location_t loc, if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0) { tree sh_cnt = TREE_OPERAND (arg1, 1); - unsigned long pow2 = exact_log2 (TREE_INT_CST_LOW (sval)); + unsigned long pow2; + + if (TREE_INT_CST_LOW (sval)) + pow2 = exact_log2 (TREE_INT_CST_LOW (sval)); + else + pow2 = exact_log2 (TREE_INT_CST_HIGH (sval)) + + HOST_BITS_PER_WIDE_INT; if (strict_overflow_p) fold_overflow_warning (("assuming signed overflow does not " --- gcc/testsuite/gcc.c-torture/execute/pr46019.c.jj 2010-10-14 19:18:23.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr46019.c 2010-10-14 18:53:39.000000000 +0200 @@ -0,0 +1,14 @@ +/* PR middle-end/46019 */ + +extern void abort (void); + +int +main (void) +{ + unsigned long long l = 0x40000000000ULL; + int n; + for (n = 0; n < 8; n++) + if (l / (0x200000000ULL << n) != (0x200 >> n)) + abort (); + return 0; +}