From patchwork Tue Feb 26 06:46:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 223118 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 AE7E92C0040 for ; Tue, 26 Feb 2013 17:46:42 +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=1362466003; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc: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=Ov8w6MdmaXKdfvoZy9PMkmfREKE=; b=A+eCAoc/SEbyfZDbeLP442kmKKGtKqmN8TzK1wBx4/pPxFXtdtFJ53pKjuoIcv 5jadLS5kb3sMxi7brADeScmMfXj0mMBU5F28LUHhxKJ0bjB0of8zz2Gy4FH4TNE9 sPcbCagyizHqamLP/bO0OlAKIgDmnOwnASXkmgBSgYrQs= 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:Date:From:To:Cc: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=cjU8NuUjSMdYhx5lwcyqF1ALOVhBLOYnoKHRXhnAzYtCRdA9FrnimOsvlO3MaV lgWq7v/n8sDbkEXUUcTOL2FKkEYT2FrBmUUusZg0+sNOYnZ3QiWOgGGfjr87XiKO Jfdf2166lA3c0cV75v0iEwvRdupTCaUgwxAg0dAjXkMAI=; Received: (qmail 14178 invoked by alias); 26 Feb 2013 06:46:37 -0000 Received: (qmail 14167 invoked by uid 22791); 26 Feb 2013 06:46:36 -0000 X-SWARE-Spam-Status: Yes, hits=5.4 required=5.0 tests=AWL, BAYES_00, BOTNET, KHOP_DYNAMIC, RCVD_IN_SORBS_DUL, RDNS_DYNAMIC, TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 195.22.53.1.adsl.nextra.cz (HELO zalov.redhat.com) (195.22.53.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Feb 2013 06:46:29 +0000 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r1Q6kRQM012542; Tue, 26 Feb 2013 07:46:27 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1Q6kR5s012541; Tue, 26 Feb 2013 07:46:27 +0100 Date: Tue, 26 Feb 2013 07:46:27 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up operand_equal_p (PR tree-optimization/56448) Message-ID: <20130226064627.GY1215@tucnak.zalov.cz> 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! On the following testcase, VN during free keeps iterating forever, since the unshare_expr call I've added to fix PR55935. The bug is that when we have volatile int a[1]; and &a[0] expression, if we unshare_expr that expression, it doesn't compare operand_equal_p (exp, unshare_expr (exp), OEP_PURE_SAME). While when looking at ADDR_EXPR we set OEP_CONSTANT_ADDRESS_OF flag, when looking at the ARRAY_REF we see it has TREE_SIDE_EFFECTS set and return 0. For ADDR_EXPR of ARRAY_REF or other reference it really doesn't matter whether the ARRAY_REF itself has side-effects or not though, so we should ignore the side-effects. Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk? 2013-02-26 Jakub Jelinek PR tree-optimization/56448 * fold-const.c (operand_equal_p) : Don't look at TREE_SIDE_EFFECTS if flags contain OEP_CONSTANT_ADDRESS_OF. Clear OEP_CONSTANT_ADDRESS_OF from flags before recursing on second or later operands of the references, or even first operand for INDIRECT_REF, TARGET_MEM_REF or MEM_REF. * gcc.c-torture/compile/pr56448.c: New test. Jakub --- gcc/fold-const.c.jj 2013-02-08 16:05:34.000000000 +0100 +++ gcc/fold-const.c 2013-02-25 23:25:46.676092462 +0100 @@ -2542,19 +2542,25 @@ operand_equal_p (const_tree arg0, const_ case tcc_reference: /* If either of the pointer (or reference) expressions we are - dereferencing contain a side effect, these cannot be equal. */ - if (TREE_SIDE_EFFECTS (arg0) - || TREE_SIDE_EFFECTS (arg1)) + dereferencing contain a side effect, these cannot be equal, + but their addresses can be. */ + if ((flags & OEP_CONSTANT_ADDRESS_OF) == 0 + && (TREE_SIDE_EFFECTS (arg0) + || TREE_SIDE_EFFECTS (arg1))) return 0; switch (TREE_CODE (arg0)) { case INDIRECT_REF: + flags &= ~OEP_CONSTANT_ADDRESS_OF; + return OP_SAME (0); + case REALPART_EXPR: case IMAGPART_EXPR: return OP_SAME (0); case TARGET_MEM_REF: + flags &= ~OEP_CONSTANT_ADDRESS_OF; /* Require equal extra operands and then fall through to MEM_REF handling of the two common operands. */ if (!OP_SAME_WITH_NULL (2) @@ -2563,6 +2569,7 @@ operand_equal_p (const_tree arg0, const_ return 0; /* Fallthru. */ case MEM_REF: + flags &= ~OEP_CONSTANT_ADDRESS_OF; /* Require equal access sizes, and similar pointer types. We can have incomplete types for array references of variable-sized arrays from the Fortran frontent @@ -2581,22 +2588,28 @@ operand_equal_p (const_tree arg0, const_ /* Operands 2 and 3 may be null. Compare the array index by value if it is constant first as we may have different types but same value here. */ - return (OP_SAME (0) - && (tree_int_cst_equal (TREE_OPERAND (arg0, 1), - TREE_OPERAND (arg1, 1)) - || OP_SAME (1)) + if (!OP_SAME (0)) + return 0; + flags &= ~OEP_CONSTANT_ADDRESS_OF; + return ((tree_int_cst_equal (TREE_OPERAND (arg0, 1), + TREE_OPERAND (arg1, 1)) + || OP_SAME (1)) && OP_SAME_WITH_NULL (2) && OP_SAME_WITH_NULL (3)); case COMPONENT_REF: /* Handle operand 2 the same as for ARRAY_REF. Operand 0 may be NULL when we're called to compare MEM_EXPRs. */ - return OP_SAME_WITH_NULL (0) - && OP_SAME (1) - && OP_SAME_WITH_NULL (2); + if (!OP_SAME_WITH_NULL (0)) + return 0; + flags &= ~OEP_CONSTANT_ADDRESS_OF; + return OP_SAME (1) && OP_SAME_WITH_NULL (2); case BIT_FIELD_REF: - return OP_SAME (0) && OP_SAME (1) && OP_SAME (2); + if (!OP_SAME (0)) + return 0; + flags &= ~OEP_CONSTANT_ADDRESS_OF; + return OP_SAME (1) && OP_SAME (2); default: return 0; --- gcc/testsuite/gcc.c-torture/compile/pr56448.c.jj 2013-02-25 23:31:55.266922056 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr56448.c 2013-02-25 23:29:55.000000000 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/56448 */ + +volatile int a[1]; +int b; + +void +foo () +{ + for (;;) + { + int *c[3][6] = { 0, 0, 0, &b, 0, 0, 0, 0, &b, 0, 0, 0, 0, 0, 0, 0, &b, (int *) &a[0] }; + b = *c[2][5]; + } +}