From patchwork Mon Jan 2 14:44:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 133852 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 71C5C1007D2 for ; Tue, 3 Jan 2012 01:44:53 +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=1326120296; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=f1hnMVelSj4wISoSlZJo JXK3pfc=; b=c8wKUq7JXYCeZ1NTc86EAuc4qY05QpQ2rxC8jkbGNe4mCz5GP210 UZcvup3rQ2NfCqi3y/ASEqCRLcT6a7yYK5/aM6XcDkekv+Hv84FJ4/V1WRxA/QBl ncVvYP6Tk5ci/Ly6qfjgVn1yK08Y13DCKOXPAkTr6wGSFo204LxyuYA= 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:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=T7PiU3rIbHiRfZ9UOYMoDpmWDTPWZ/hC0vFuDdCsUay1oIXUlMGT3rNsDp4YhD 3a/7PHibbWG1LDTRkIXZD5IKm30TTLFvjOGOzk5I59qptVBOOVnGQKjBVyamfeRG dwB57HYhYZV631j6tji3zscQ7qhXRfybrspEKOB+wDVdY=; Received: (qmail 13448 invoked by alias); 2 Jan 2012 14:44:46 -0000 Received: (qmail 13433 invoked by uid 22791); 2 Jan 2012 14:44:44 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_LC, TW_XL X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Jan 2012 14:44:32 +0000 Received: from relay1.suse.de (nat.nue.novell.com [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 1FEEA89471 for ; Mon, 2 Jan 2012 15:44:31 +0100 (CET) Date: Mon, 2 Jan 2012 15:44:31 +0100 (CET) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR51730 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 I am testing the following patch to fix PR51730. Richard. 2012-01-02 Richard Guenther PR middle-end/51730 * fold-const.c (fold_comparison): Properly canonicalize tree offset and HOST_WIDE_INT bit position. * gcc.dg/fold-compare-6.c: New testcase. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 182784) +++ gcc/fold-const.c (working copy) @@ -8886,6 +8886,14 @@ fold_comparison (location_t loc, enum tr indirect_base0 = true; } offset0 = TREE_OPERAND (arg0, 1); + if (host_integerp (offset0, 0) + && ((HOST_WIDE_INT) (TREE_INT_CST_LOW (offset0) * BITS_PER_UNIT) + / BITS_PER_UNIT + == (HOST_WIDE_INT) TREE_INT_CST_LOW (offset0))) + { + bitpos0 = TREE_INT_CST_LOW (offset0) * BITS_PER_UNIT; + offset0 = NULL_TREE; + } } base1 = arg1; @@ -8909,6 +8917,14 @@ fold_comparison (location_t loc, enum tr indirect_base1 = true; } offset1 = TREE_OPERAND (arg1, 1); + if (host_integerp (offset1, 0) + && ((HOST_WIDE_INT) (TREE_INT_CST_LOW (offset1) * BITS_PER_UNIT) + / BITS_PER_UNIT + == (HOST_WIDE_INT) TREE_INT_CST_LOW (offset1))) + { + bitpos1 = TREE_INT_CST_LOW (offset1) * BITS_PER_UNIT; + offset1 = NULL_TREE; + } } /* A local variable can never be pointed to by Index: gcc/testsuite/gcc.dg/fold-compare-6.c =================================================================== --- gcc/testsuite/gcc.dg/fold-compare-6.c (revision 0) +++ gcc/testsuite/gcc.dg/fold-compare-6.c (revision 0) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-original" } */ + +char digs[] = "0123456789"; +int foo (void) +{ + int xlcbug = 1 / (&(digs + 5)[-2 + (_Bool) 1] == &digs[4] ? 1 : -1); + return xlcbug; +} + +/* { dg-final { scan-tree-dump "xlcbug = 1;" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */