From patchwork Fri Jul 24 11:47:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 499708 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 96F4F140B04 for ; Fri, 24 Jul 2015 21:48:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Xs69MwRC; 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:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=u/TQ8FgmgV/uK5VJv t9vYT9hO3BrSKFPPhG40EkOQe/tItxB/ZltauQ9/Jtm3SWzlrHs7gf6eBnoY9T03 tE02YfQ73J7y0DJfDHKpfyVrI6dFU1rXad8L8B6tpt6mIrpKPRk4cS+cPPjpzhYP GcSl/L3mqBuRVceZgVrtV8wHaA= 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:cc:subject:references :in-reply-to:content-type; s=default; bh=3JybCilbciZNK8w3u3pUjMh 9mfA=; b=Xs69MwRC/Jofqszw1fDDyvnho+6MjsRtRbu2J9RguVwIztFKI3WGhQM 3DPys4eH+mXlq2WHudKR4E8uCrcJ3bNg75PqdAK0kL5eXB9znMpAB3acsOFRX6ps IqMNQ0pJ7SGIR3wISRdIuGnlywInhlCnIj2K6XsHWiMjBXaSqcn8= Received: (qmail 71839 invoked by alias); 24 Jul 2015 11:48:09 -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 71825 invoked by uid 89); 24 Jul 2015 11:48:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, MISSING_HEADERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 24 Jul 2015 11:48:07 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34249) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZIbSP-0004Do-DF for gcc-patches@gnu.org; Fri, 24 Jul 2015 07:48:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIbSJ-0003N2-RQ for gcc-patches@gnu.org; Fri, 24 Jul 2015 07:48:04 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:43596) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIbSJ-0003LT-J4 for gcc-patches@gnu.org; Fri, 24 Jul 2015 07:47:59 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-03.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZIbSH-00008z-OF from Tom_deVries@mentor.com for gcc-patches@gnu.org; Fri, 24 Jul 2015 04:47:58 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.3.224.2; Fri, 24 Jul 2015 12:47:56 +0100 Message-ID: <55B225DE.1000006@mentor.com> Date: Fri, 24 Jul 2015 13:47:42 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 CC: "gcc-patches@gnu.org" Subject: [PATCH] Add FIXED_POINT_TYPE_OVERFLOW_WRAPS_P References: <55A6C1DF.1050108@mentor.com> <20150720183141.GB20717@f1.c.bardezibar.internal> <55AD9093.1060206@mentor.com> <55AE5340.2010700@mentor.com> <20150721184249.GA7417@f1.c.bardezibar.internal> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 [ was: [RFC, PR66873] Use graphite for parloops ] On 22/07/15 13:02, Richard Biener wrote: >>+#define FIXED_POINT_TYPE_OVERFLOW_WRAPS_P(TYPE) \ >>+ (NON_SAT_FIXED_POINT_TYPE_P (TYPE)) >> >>somebody with knowledge about fixed-point types needs to review this. In vect_is_simple_reduction_1 I noticed: ... else if (SAT_FIXED_POINT_TYPE_P (type) && check_reduction) { /* Changing the order of operations changes the semantics. */ if (dump_enabled_p ()) report_vect_op (MSG_MISSED_OPTIMIZATION, def_stmt, "reduction: unsafe fixed-point math optimization: "); return NULL; } ... In other words, you can change evaluation order if !SAT_FIXED_POINT_TYPE_P. It is true that for saturating fixed point, you don't want to change evaluation order. But I think that we actually want to test whether the fixed-point type wraps. I tried to find proof that non-saturating fixed point wraps, but that doesn't seem trivial. IMHO, non-trivial enough to define a macro FIXED_POINT_TYPE_OVERFLOW_WRAPS_P, add a lengthy comment and use that instead of !SAT_FIXED_POINT_TYPE_P. The intention of the patch is that it doesn't change behaviour of the compiler. Currently bootstrapping and reg-testing on x86_64. OK for trunk? Thanks, - Tom Add FIXED_POINT_TYPE_OVERFLOW_WRAPS_P 2015-07-24 Tom de Vries * tree.h (FIXED_POINT_TYPE_OVERFLOW_WRAPS_P): Define. * fold-const.c (split_tree): Use FIXED_POINT_TYPE_OVERFLOW_WRAPS_P. * tree-ssa-reassoc.c (can_reassociate_p): Same. * tree-vect-loop.c (vect_is_simple_reduction_1): Same. --- gcc/fold-const.c | 3 ++- gcc/tree-ssa-reassoc.c | 2 +- gcc/tree-vect-loop.c | 4 +++- gcc/tree.h | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 886922f..2de71bb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -808,7 +808,8 @@ split_tree (tree in, enum tree_code code, tree *conp, tree *litp, *litp = in; else if (TREE_CODE (in) == code || ((! FLOAT_TYPE_P (TREE_TYPE (in)) || flag_associative_math) - && ! SAT_FIXED_POINT_TYPE_P (TREE_TYPE (in)) + && (!FIXED_POINT_TYPE_P (TREE_TYPE (in)) + || FIXED_POINT_TYPE_OVERFLOW_WRAPS_P (TREE_TYPE (in))) /* We can associate addition and subtraction together (even though the C standard doesn't say so) for integers because the value is not affected. For reals, the value might be diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index efb813c..2851a13 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -4229,7 +4229,7 @@ can_reassociate_p (tree op) { tree type = TREE_TYPE (op); if ((INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) - || NON_SAT_FIXED_POINT_TYPE_P (type) + || FIXED_POINT_TYPE_OVERFLOW_WRAPS_P (type) || (flag_associative_math && FLOAT_TYPE_P (type))) return true; return false; diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 42ba5f8..0e61a02 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -2635,7 +2635,9 @@ vect_is_simple_reduction_1 (loop_vec_info loop_info, gimple phi, return NULL; } } - else if (SAT_FIXED_POINT_TYPE_P (type) && check_reduction) + else if (FIXED_POINT_TYPE_P (type) && + !FIXED_POINT_TYPE_OVERFLOW_WRAPS_P (type) + && check_reduction) { /* Changing the order of operations changes the semantics. */ if (dump_enabled_p ()) diff --git a/gcc/tree.h b/gcc/tree.h index 360d13e..ab0e537 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -497,6 +497,24 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define SAT_FIXED_POINT_TYPE_P(TYPE) \ (TREE_CODE (TYPE) == FIXED_POINT_TYPE && TYPE_SATURATING (TYPE)) +/* Nonzero if fixed-point type TYPE wraps at overflow. + + Fixed-point types that are explictly saturating do not wrap at overflow. + + The draft technical report (N1169 draft of ISO/IEC DTR 18037) specifies + pragmas to control overflow for a fixed-point type that is not explictly + saturating (FX_FRACT_OVERFLOW and FX_ACCUM_OVERFLOW). The possible states + of the pragmas are SAT and DEFAULT. The default state for the pragmas is + DEFAULT, which means overflow has undefined behaviour. GCC currently does + not support these pragmas. + + The de-facto choice of GCC for fixed-point types that are not explictly + saturating seems to be modular wrap-around (as specified in Annex E.4 Modwrap + overflow). */ + +#define FIXED_POINT_TYPE_OVERFLOW_WRAPS_P(TYPE) \ + (NON_SAT_FIXED_POINT_TYPE_P (TYPE)) + /* Nonzero if TYPE represents a fixed-point type. */ #define FIXED_POINT_TYPE_P(TYPE) (TREE_CODE (TYPE) == FIXED_POINT_TYPE) -- 1.9.1