From patchwork Thu Jul 23 08:56:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 499267 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EC6D5140D19 for ; Thu, 23 Jul 2015 18:56:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=QWuboGDv; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=AZgKZOsTB+4Wayn+1 cYvPc65KGJTA6zTWoN8uqVsettEb+SsZhdPLf69at7ZLevR2/g5xKZNy1qe1LW+S P0s0nwL7hPY6lx9PU8CfIceyTxojHCUZ6UWt6kxCnkTVeE0VPo2btq5odUSW0t5E BWFlxJl7De3Z97gwLmPARPFIZc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=rK59xntUw1Mqv+gfrUIdYTh hfG8=; b=QWuboGDvZ/r3EAlS/wpvAp7i0U/tUVzu9oEUOQS7O6RxQcu/u7WIYQ5 evcG3XmVtzOB1Mow6y9MqOxIaBx5aWLVS3HKU0l8CtcNqKwlZYTF4DhDpcVfPvi+ UPNDye4KsXpqegilU4uz2pWEKVAcU4vvkDVlz4ZIB7tzMYKDvdU0= Received: (qmail 29611 invoked by alias); 23 Jul 2015 08:56:14 -0000 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 Received: (qmail 29600 invoked by uid 89); 23 Jul 2015 08:56:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jul 2015 08:56:12 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-33-vrRjiIPyQQWOZtu3PDWXTw-1; Thu, 23 Jul 2015 09:56:06 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 23 Jul 2015 09:56:06 +0100 Message-ID: <55B0AC26.6010501@arm.com> Date: Thu, 23 Jul 2015 09:56:06 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Richard Biener CC: GCC Patches Subject: Re: [PATCH][match.pd] PR middle-end/66915 Restrict A - B -> A + (-B) to non-fixed-point types References: <55AD0572.3010200@arm.com> <55AE0E00.7060507@arm.com> In-Reply-To: X-MC-Unique: vrRjiIPyQQWOZtu3PDWXTw-1 X-IsSubscribed: yes On 21/07/15 11:11, Richard Biener wrote: > On Tue, 21 Jul 2015, Kyrill Tkachov wrote: > >> On 21/07/15 08:24, Richard Biener wrote: >>> On Mon, 20 Jul 2015, Kyrill Tkachov wrote: >>> >>>> Hi all, >>>> >>>> This patch fixes the PR in question which is a miscompilation of >>>> gcc.dg/fixed-point/unary.c on arm. >>>> It just restricts the A - B -> A + (-B) transformation when the type is >>>> fixed-point. >>>> >>>> This fixes the testcase for me. >>>> Is this the right approach? >>>> >>>> Bootstrap and test on arm and x86 running. >>>> >>>> Ok if testing is clean? >>> Ok, but I think the fold-const.c code has the same issue, no: >>> >>> /* A - B -> A + (-B) if B is easily negatable. */ >>> if (negate_expr_p (arg1) >>> && !TYPE_OVERFLOW_SANITIZED (type) >>> && ((FLOAT_TYPE_P (type) >>> /* Avoid this transformation if B is a positive REAL_CST. >>> */ >>> && (TREE_CODE (arg1) != REAL_CST >>> || REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))) >>> || INTEGRAL_TYPE_P (type))) >>> return fold_build2_loc (loc, PLUS_EXPR, type, >>> fold_convert_loc (loc, type, arg0), >>> fold_convert_loc (loc, type, >>> negate_expr (arg1))); >>> >>> ah, no. The above only applies to float-type and integral-types. >>> >>> Thus yes, your patch is ok. Can you double-check the other pattern, >>> >>> /* -(A + B) -> (-B) - A. */ >>> (simplify >>> (negate (plus:c @0 negate_expr_p@1)) >>> (if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)) >>> && !HONOR_SIGNED_ZEROS (element_mode (type))) >>> (minus (negate @1) @0))) >>> >>> ? >> Thanks, committed with r226028. >> I can add (FLOAT_TYPE_P (type) || INTEGRAL_TYPE_P (type)) to the condition. >> That would more closely mirror the original logic, right? >> That passes x86_64 bootstrap and aarch64 testing looks ok. > Yeah, that works for me, too. How about this patch then? Bootstrapped and tested on x86_64 and aarch64. Thanks, Kyrill 2015-07-23 Kyrylo Tkachov * match.pd (-(A + B) -> (-B) - A): Restrict to floating point and integral types. > > Thanks, > Richard. > commit d514c81a7965fd24b9d8c294b12179b2369c8aa4 Author: Kyrylo Tkachov Date: Tue Jul 21 10:18:31 2015 +0100 [match.pd] Restrict -(A + B) -> (-B) - A to integral or float types diff --git a/gcc/match.pd b/gcc/match.pd index 3d7b32e..29367f2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -515,7 +515,8 @@ along with GCC; see the file COPYING3. If not see /* -(A + B) -> (-B) - A. */ (simplify (negate (plus:c @0 negate_expr_p@1)) - (if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)) + (if ((FLOAT_TYPE_P (type) || INTEGRAL_TYPE_P (type)) + && !HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)) && !HONOR_SIGNED_ZEROS (element_mode (type))) (minus (negate @1) @0)))