From patchwork Tue Feb 18 09:11:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1239860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519709-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=xLB1CKiL; dkim-atps=neutral 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 48MFTn18n8z9sRG for ; Tue, 18 Feb 2020 20:11:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=LEW+sQSXT5UQI5htE6CmhRE5xtDCpQxJmqOjxPQyV0pKi4KUwwckB JgwdUET7+ZfaPMXOEJgr4DCJs4+t1eJr9VHL2Y7S1UcZp7QoU0bI7lSB8Tvz9mei VcOUWopKwEg9dkhe4NhvACKiFIPm8pdHdgQnsA/1sBGCmnUwIMLSJc= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=/XYEWS15U8on5ufXeg75tOCNFdU=; b=xLB1CKiLJxST94891fGf n3wAzRf+evWrKjJ+VxbTubh3E6ukS0PMgfuJmh03qSCXhAypnpbFgb1Z9PtlG+q3 umNn+uxnlxIuG//LHWdLwkiUSf1UCv5jOqvlfAwPVnepTwRdDjLKNIM0LGNqQOdZ nba87P4hScF51VfZV6URE0o= Received: (qmail 121575 invoked by alias); 18 Feb 2020 09:11:30 -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 121565 invoked by uid 89); 18 Feb 2020 09:11:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy=treatment, oep, OEP X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Feb 2020 09:11:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D1BD130E for ; Tue, 18 Feb 2020 01:11:26 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7891D3F703 for ; Tue, 18 Feb 2020 01:11:26 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [RFA] Two backports to gcc-9 Date: Tue, 18 Feb 2020 09:11:25 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Tested on aarch64-linux-gnu, armeb-eabi and x86_64-linux-gnu. OK for gcc-9? Richard From 31c4d04fe12bbc92fb8491a3e9d2da402a0963dc Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 5 Dec 2019 14:20:38 +0000 Subject: [PATCH 2/2] Check for bitwise identity when encoding VECTOR_CSTs [PR92768] This PR shows that we weren't checking for bitwise-identical values when trying to encode a VECTOR_CST, so -0.0 was treated the same as 0.0 for -fno-signed-zeros. The patch adds a new OEP flag to select that behaviour. 2020-02-18 Richard Sandiford gcc/ Backport from mainline 2019-12-05 Richard Sandiford PR middle-end/92768 * tree-core.h (OEP_BITWISE): New flag. * fold-const.c (operand_compare::operand_equal_p): Handle it. * tree-vector-builder.h (tree_vector_builder::equal_p): Pass it. gcc/testsuite/ PR middle-end/92768 * gcc.dg/pr92768.c: New test. --- gcc/fold-const.c | 17 ++++++++++++++--- gcc/testsuite/gcc.dg/pr92768.c | 7 +++++++ gcc/tree-core.h | 3 ++- gcc/tree-vector-builder.h | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr92768.c diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9feaea9fde5..c717f24501e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2932,6 +2932,11 @@ combine_comparisons (location_t loc, If OEP_LEXICOGRAPHIC is set, then also handle expressions with side-effects such as MODIFY_EXPR, RETURN_EXPR, as well as STATEMENT_LISTs. + If OEP_BITWISE is set, then require the values to be bitwise identical + rather than simply numerically equal. Do not take advantage of things + like math-related flags or undefined behavior; only return true for + values that are provably bitwise identical in all circumstances. + Unless OEP_MATCH_SIDE_EFFECTS is set, the function returns false on any operand with side effect. This is unnecesarily conservative in the case we know that arg0 and arg1 are in disjoint code paths (such as in @@ -2978,6 +2983,11 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1)) return 0; + /* Bitwise identity makes no sense if the values have different layouts. */ + if ((flags & OEP_BITWISE) + && !tree_nop_conversion_p (TREE_TYPE (arg0), TREE_TYPE (arg1))) + return 0; + /* We cannot consider pointers to different address space equal. */ if (POINTER_TYPE_P (TREE_TYPE (arg0)) && POINTER_TYPE_P (TREE_TYPE (arg1)) @@ -3110,8 +3120,7 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) if (real_identical (&TREE_REAL_CST (arg0), &TREE_REAL_CST (arg1))) return 1; - - if (!HONOR_SIGNED_ZEROS (arg0)) + if (!(flags & OEP_BITWISE) && !HONOR_SIGNED_ZEROS (arg0)) { /* If we do not distinguish between signed and unsigned zero, consider them equal. */ @@ -3163,7 +3172,9 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) break; } - if (flags & OEP_ONLY_CONST) + /* Don't handle more cases for OEP_BITWISE, since we can't guarantee that + two instances of undefined behavior will give identical results. */ + if (flags & (OEP_ONLY_CONST | OEP_BITWISE)) return 0; /* Define macros to test an operand from arg0 and arg1 for equality and a diff --git a/gcc/testsuite/gcc.dg/pr92768.c b/gcc/testsuite/gcc.dg/pr92768.c new file mode 100644 index 00000000000..e2a3f9ccacc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr92768.c @@ -0,0 +1,7 @@ +/* PR tree-optimization/92768 */ +/* { dg-options "-O2 -fno-signed-zeros -fdump-tree-optimized -w -Wno-psabi" } */ + +typedef float v4sf __attribute__((vector_size(16))); +v4sf f () { return (v4sf) { 0.0, -0.0, 0.0, -0.0 }; } + +/* { dg-final { scan-tree-dump {{ 0\.0, -0\.0, 0\.0, -0\.0 }} "optimized" } } */ diff --git a/gcc/tree-core.h b/gcc/tree-core.h index fbed0c379b2..41d05294936 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -851,7 +851,8 @@ enum operand_equal_flag { /* Internal within inchash::add_expr: */ OEP_HASH_CHECK = 32, /* Makes operand_equal_p handle more expressions: */ - OEP_LEXICOGRAPHIC = 64 + OEP_LEXICOGRAPHIC = 64, + OEP_BITWISE = 128 }; /* Enum and arrays used for tree allocation stats. diff --git a/gcc/tree-vector-builder.h b/gcc/tree-vector-builder.h index 0e36cd17139..13af74ad834 100644 --- a/gcc/tree-vector-builder.h +++ b/gcc/tree-vector-builder.h @@ -82,7 +82,7 @@ tree_vector_builder::new_vector (tree type, unsigned int npatterns, inline bool tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const { - return operand_equal_p (elt1, elt2, 0); + return operand_equal_p (elt1, elt2, OEP_BITWISE); } /* Return true if a stepped representation is OK. We don't allow -- 2.17.1