From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69874 invoked by alias); 23 Jul 2015 11:16:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 69861 invoked by uid 89); 23 Jul 2015 11:16:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 23 Jul 2015 11:16:24 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 92B4DAAD1; Thu, 23 Jul 2015 11:16:19 +0000 (UTC) Date: Thu, 23 Jul 2015 11:19:00 -0000 From: Richard Biener To: Kyrill Tkachov cc: GCC Patches Subject: Re: [PATCH][match.pd] PR middle-end/66915 Restrict A - B -> A + (-B) to non-fixed-point types In-Reply-To: <55B0AC26.6010501@arm.com> Message-ID: References: <55AD0572.3010200@arm.com> <55AE0E00.7060507@arm.com> <55B0AC26.6010501@arm.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-07/txt/msg01926.txt.bz2 On Thu, 23 Jul 2015, Kyrill Tkachov wrote: > > 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. Hmm. The code already pretty much matches the one in fold-const.c. So what's the actual issue with fixed-point types and -(A + B) -> -B - A iff negate_expr_p says that B can be safely negated? That is, can you add a testcase that fails without the patch? Thanks Richard.