From patchwork Fri Jun 20 10:41:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Preud'homme X-Patchwork-Id: 362150 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 7AB3B140088 for ; Fri, 20 Jun 2014 20:42:05 +1000 (EST) 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:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=B89PEJBE1gEDyK/uOH1vwj0q0VRY8GtA7QK1tmsuTA7Psvm/leLTt 5BzdZkqS0Z1Y4m29LycVZIY4vatC5XPePbB6a/uU/Nm3yPtAQnpknosblyYIxV5e DE7OhSac8lD1aSLCJIQLLpXHCVScTbiyS3vdOPTYNvc3JLCQL/pDpI= 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:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=Z/KeL8SN0UN52steMNZXL6IQUbg=; b=ANpBLV2UtAVBco5mrUrdU/cGu7Gt v9A4d7GRQJcxjC+nLMtdTA1pOEe0gyIkUYYTvk9vIDpwbFyscheMFe3YLPQl5kk4 IfmMe8jMPyLxoNfzabjXNhBqaEqof2PVoPOdWkHiQ6HRoJAa6j/N96b/CG+rFQRa kfdCYWxRXI2W5S0= Received: (qmail 26862 invoked by alias); 20 Jun 2014 10:41:58 -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 26720 invoked by uid 89); 20 Jun 2014 10:41:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jun 2014 10:41:56 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 20 Jun 2014 11:41:53 +0100 Received: from SHAWIN202 ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 20 Jun 2014 11:41:43 +0100 From: "Thomas Preud'homme" To: "'Richard Biener'" Cc: "GCC Patches" References: <002c01cf8453$e32b4710$a981d530$@arm.com> In-Reply-To: Subject: RE: [PATCH] Fix PR61375: cancel bswap optimization when value doesn't fit in a HOST_WIDE_INT Date: Fri, 20 Jun 2014 18:41:41 +0800 Message-ID: <002301cf8c74$3a934a20$afb9de60$@arm.com> MIME-Version: 1.0 X-MC-Unique: 114062011415308501 X-IsSubscribed: yes > From: Richard Biener [mailto:richard.guenther@gmail.com] > Sent: Tuesday, June 10, 2014 5:05 PM > > Backports are welcome - please post a patch. > Sorry for the delay. Here you are: Ok for GCC 4.8 and GCC 4.9 branches? Best regards, Thomas diff --git a/gcc/testsuite/gcc.c-torture/execute/pr61375.c b/gcc/testsuite/gcc.c-torture/execute/pr61375.c new file mode 100644 index 0000000..d3b54a8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr61375.c @@ -0,0 +1,35 @@ +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ uint64_t; +#else +typedef unsigned long long uint64_t; +#endif + +#ifndef __SIZEOF_INT128__ +#define __int128 long long +#endif + +/* Some version of bswap optimization would ICE when analyzing a mask constant + too big for an HOST_WIDE_INT (PR61375). */ + +__attribute__ ((noinline, noclone)) uint64_t +uint128_central_bitsi_ior (unsigned __int128 in1, uint64_t in2) +{ + __int128 mask = (__int128)0xffff << 56; + return ((in1 & mask) >> 56) | in2; +} + +int +main (int argc) +{ + __int128 in = 1; +#ifdef __SIZEOF_INT128__ + in <<= 64; +#endif + if (sizeof (uint64_t) * __CHAR_BIT__ != 64) + return 0; + if (sizeof (unsigned __int128) * __CHAR_BIT__ != 128) + return 0; + if (uint128_central_bitsi_ior (in, 2) != 0x102) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 9ff857c..9d64205 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1741,6 +1741,8 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit) if (n->size % BITS_PER_UNIT != 0) return NULL_TREE; n->size /= BITS_PER_UNIT; + if (n->size > (int)sizeof (unsigned HOST_WIDEST_INT)) + return NULL_TREE; n->n = (sizeof (HOST_WIDEST_INT) < 8 ? 0 : (unsigned HOST_WIDEST_INT)0x08070605 << 32 | 0x04030201); @@ -1781,6 +1783,8 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit) type_size = TYPE_PRECISION (gimple_expr_type (stmt)); if (type_size % BITS_PER_UNIT != 0) return NULL_TREE; + if (type_size > (int)HOST_BITS_PER_WIDEST_INT) + return NULL_TREE; if (type_size / BITS_PER_UNIT < (int)(sizeof (HOST_WIDEST_INT))) {