From patchwork Thu Feb 23 18:42:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 142695 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 01581B6EEE for ; Fri, 24 Feb 2012 05:43:26 +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=1330627407; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: 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=mtv7OXUPbIc/FF0FnMJX d7nzoIs=; b=W5J1R9ZgWTwGuLBYZ7joxKW47uoF12xZju5WZ8/8cA7j48sCR2o6 GYoa6HVTJwKRc0htqCIPoBgEZL+pcHVg/g9fHtQFzruRW9h5BLJcoteQc51x9sWP VSFHh7LY+xUR7qHKQ9BS9qcPedr1DD0PeCzUfhuHXVJhv89U3+URFdE= 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:Received:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=qeVscIvHT/iqqPrZ264cFdkkToohb/ATIj6h+Q+0Rwa/i1Oj/3VfzGBLkZhSOJ M19iLrDrLl0mHeWNVj0+R+Cuz4uC6WpGo7eIM3us7mF2xyxMF7/PBXiH5TeVgSGm etyy+c6t65OcQK+cg2y6y66g5/qUMPIkiwjQ+EjMIFBoQ=; Received: (qmail 3239 invoked by alias); 23 Feb 2012 18:43:20 -0000 Received: (qmail 3216 invoked by uid 22791); 23 Feb 2012 18:43:18 -0000 X-SWARE-Spam-Status: No, hits=-6.7 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, 23 Feb 2012 18:43:00 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1NIgxl9020000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 23 Feb 2012 13:42:59 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1NIgwNX017294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 23 Feb 2012 13:42:59 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id q1NIgwEc008426 for ; Thu, 23 Feb 2012 19:42:58 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id q1NIgvZe008424 for gcc-patches@gcc.gnu.org; Thu, 23 Feb 2012 19:42:57 +0100 Date: Thu, 23 Feb 2012 19:42:57 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: Backport a patch to 4.6 branch Message-ID: <20120223184257.GV18768@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! I've backported this to 4.6 branch, after bootstrapping/regtesting it on x86_64-linux and i686-linux. 2012-02-23 Jakub Jelinek Backported from trunk 2012-02-20 Georg-Johann Lay * gcc.c-torture/execute/pr52286.c: Fix FAIL on 16-bit int platforms. 2012-02-20 Jakub Jelinek PR tree-optimization/52286 * fold-const.c (fold_binary_loc): For (X & C1) | C2 optimization use double_int_to_tree instead of build_int_cst_wide, rewrite to use double_int vars. * gcc.c-torture/execute/pr52286.c: New test. Jakub --- gcc/fold-const.c (revision 184390) +++ gcc/fold-const.c (revision 184391) @@ -10959,66 +10959,50 @@ fold_binary_loc (location_t loc, && TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) { - unsigned HOST_WIDE_INT hi1, lo1, hi2, lo2, hi3, lo3, mlo, mhi; + double_int c1, c2, c3, msk; int width = TYPE_PRECISION (type), w; - hi1 = TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)); - lo1 = TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)); - hi2 = TREE_INT_CST_HIGH (arg1); - lo2 = TREE_INT_CST_LOW (arg1); + c1 = tree_to_double_int (TREE_OPERAND (arg0, 1)); + c2 = tree_to_double_int (arg1); /* If (C1&C2) == C1, then (X&C1)|C2 becomes (X,C2). */ - if ((hi1 & hi2) == hi1 && (lo1 & lo2) == lo1) + if (double_int_equal_p (double_int_and (c1, c2), c1)) return omit_one_operand_loc (loc, type, arg1, - TREE_OPERAND (arg0, 0)); + TREE_OPERAND (arg0, 0)); - if (width > HOST_BITS_PER_WIDE_INT) - { - mhi = (unsigned HOST_WIDE_INT) -1 - >> (2 * HOST_BITS_PER_WIDE_INT - width); - mlo = -1; - } - else - { - mhi = 0; - mlo = (unsigned HOST_WIDE_INT) -1 - >> (HOST_BITS_PER_WIDE_INT - width); - } + msk = double_int_mask (width); /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */ - if ((~(hi1 | hi2) & mhi) == 0 && (~(lo1 | lo2) & mlo) == 0) + if (double_int_zero_p (double_int_and_not (msk, + double_int_ior (c1, c2)))) return fold_build2_loc (loc, BIT_IOR_EXPR, type, - TREE_OPERAND (arg0, 0), arg1); + TREE_OPERAND (arg0, 0), arg1); /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2, unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some mode which allows further optimizations. */ - hi1 &= mhi; - lo1 &= mlo; - hi2 &= mhi; - lo2 &= mlo; - hi3 = hi1 & ~hi2; - lo3 = lo1 & ~lo2; + c1 = double_int_and (c1, msk); + c2 = double_int_and (c2, msk); + c3 = double_int_and_not (c1, c2); for (w = BITS_PER_UNIT; w <= width && w <= HOST_BITS_PER_WIDE_INT; w <<= 1) { unsigned HOST_WIDE_INT mask = (unsigned HOST_WIDE_INT) -1 >> (HOST_BITS_PER_WIDE_INT - w); - if (((lo1 | lo2) & mask) == mask - && (lo1 & ~mask) == 0 && hi1 == 0) + if (((c1.low | c2.low) & mask) == mask + && (c1.low & ~mask) == 0 && c1.high == 0) { - hi3 = 0; - lo3 = mask; + c3 = uhwi_to_double_int (mask); break; } } - if (hi3 != hi1 || lo3 != lo1) + if (!double_int_equal_p (c3, c1)) return fold_build2_loc (loc, BIT_IOR_EXPR, type, - fold_build2_loc (loc, BIT_AND_EXPR, type, - TREE_OPERAND (arg0, 0), - build_int_cst_wide (type, - lo3, hi3)), - arg1); + fold_build2_loc (loc, BIT_AND_EXPR, type, + TREE_OPERAND (arg0, 0), + double_int_to_tree (type, + c3)), + arg1); } /* (X & Y) | Y is (X, Y). */ --- gcc/testsuite/gcc.c-torture/execute/pr52286.c (revision 0) +++ gcc/testsuite/gcc.c-torture/execute/pr52286.c (revision 184394) @@ -0,0 +1,20 @@ +/* PR tree-optimization/52286 */ + +extern void abort (void); + +int +main () +{ +#if __SIZEOF_INT__ > 2 + int a, b; + asm ("" : "=r" (a) : "0" (0)); + b = (~a | 1) & -2038094497; +#else + long a, b; + asm ("" : "=r" (a) : "0" (0)); + b = (~a | 1) & -2038094497L; +#endif + if (b >= 0) + abort (); + return 0; +}