From patchwork Wed Mar 12 03:45:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Preud'homme X-Patchwork-Id: 329281 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 31F742C00B9 for ; Wed, 12 Mar 2014 14:45:10 +1100 (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:references:in-reply-to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=BsseGTkYhdTVQKmBMWaIsfMhDo79K I5Cmxoao/l5vxkvmeUmv2Hp70PTucai3ykltWhI1GY352ChRWv071p8JHajvzZ7t 0sEhRpDFdZCUhimD8fltEnDnaMjx+n8UZnKCK8oz3v2/A1YTHGV1tn6pUi692Jd6 O3iFQhZoUYoa7Q= 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:references:in-reply-to:subject:date:message-id:mime-version :content-type; s=default; bh=iOuzmxsm/Wp3GYaZiVRG48pflAA=; b=ETR 2A4aoyhj3PmsZ5i+LIhIaW0/ILcSRFedXBgriS1a06QblJaUa+RKS7AtRCI2uvUb 2+XuSqBDpLZjmxEy5PFDS4rIfAsGNLaSXpr1J/NjcKRj7MLYjl3WV7rjj1/+U/Oc NKpBd3HTEgFBD+FfUVvCYmfziVUy60+kVnMSXPss= Received: (qmail 31402 invoked by alias); 12 Mar 2014 03:45:03 -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 31393 invoked by uid 89); 12 Mar 2014 03:45:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 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; Wed, 12 Mar 2014 03:45:01 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Wed, 12 Mar 2014 03:44:58 +0000 Received: from SHAWIN202 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 12 Mar 2014 03:45:05 +0000 From: "Thomas Preud'homme" To: References: <000301cf39e8$84eb6910$8ec23b30$@arm.com> <20140307141555.GJ22862@tucnak.redhat.com> <000001cf3cf6$a3ef8b00$ebcea100$@arm.com> <20140311095417.GY22862@tucnak.redhat.com> <000401cf3d17$76a460a0$63ed21e0$@arm.com> <20140311105900.GA22862@tucnak.redhat.com> In-Reply-To: <20140311105900.GA22862@tucnak.redhat.com> Subject: RE: [PATCH] Fix incorrect byte swap detection (PR tree-optimization/60454) Date: Wed, 12 Mar 2014 11:45:03 +0800 Message-ID: <000501cf3da5$75143330$5f3c9990$@arm.com> MIME-Version: 1.0 X-MC-Unique: 114031203445800201 X-IsSubscribed: yes > From: Jakub Jelinek [mailto:jakub@redhat.com] > > In theory you could have __CHAR_BIT__ different from 8 and what you care > about is that uint32_t has exactly 32 bits, so the check would need to be > if (sizeof (uint32_t) * __CHAR_BIT__ != 32) > return 0; I could go with: In = (0x12 << (__CHAR_BIT__ * 3)) | (0x34 << (__CHAR_BIT__ * 2)) | (0x56 << __CHAR_BIT__) | 0x78; and compare with a similarly constructed out so that I could run the test whenever sizeof (uint32_t) * __CHAR_BIT__ >= 32, isn't it? > > Also, for int16 targets where __UINT32_TYPE__ is supposedly unsigned long, > I think you would need to use: > > if (fake_swap32 (0x12345678UL) != 0x78567E12UL) > __builtin_abort (); > > (the C standard guarantees that unsigned long is at least 32-bit and > unsigned int at least 16-bit). Right. Note to myself: ยง5.2.4.2.1 in C99. I guess so far I've only considered only some kind of architecture heterogeneity. Thanks for catching that. > > Ok with those changes. > > Do you have write access, or will somebody from your coworkers commit it > for > you? Are you covered by ARM GCC Copyright assignment? Yes and yes. > > Jakub Thanks for the review. See attachment and below to check the version you approved. Best regards, Thomas diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 748805e..b6d7d93 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-03-07 Thomas Preud'homme + + PR tree-optimization/60454 + * tree-ssa-math-opts.c (find_bswap_1): Fix bswap detection. + 2014-02-23 David Holsgrove * config/microblaze/microblaze.md: Correct ashrsi_reg / lshrsi_reg names diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f3c0c85..04ce403 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-03-10 Thomas Preud'homme + + PR tree-optimization/60454 + * gcc.c-torture/execute/pr60454.c: New test. + 2014-02-23 David Holsgrove * gcc/testsuite/gcc.target/microblaze/others/mem_reload.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr60454.c b/gcc/testsuite/gcc.c-torture/execute/pr60454.c new file mode 100644 index 0000000..ceec45e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr60454.c @@ -0,0 +1,31 @@ +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ uint32_t; +#else +typedef unsigned uint32_t; +#endif + +#define __fake_const_swab32(x) ((uint32_t)( \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) ) | \ + (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) + +/* Previous version of bswap optimization would detect byte swap when none + happen. This test aims at catching such wrong detection to avoid + regressions. */ + +__attribute__ ((noinline, noclone)) uint32_t +fake_swap32 (uint32_t in) +{ + return __fake_const_swab32 (in); +} + +int main(void) +{ + if (sizeof (uint32_t) * __CHAR_BIT__ != 32) + return 0; + if (fake_swap32 (0x12345678UL) != 0x78567E12UL) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 8e372ed..9ff857c 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1801,7 +1801,9 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit) if (rhs_class == GIMPLE_BINARY_RHS) { + int i; struct symbolic_number n1, n2; + unsigned HOST_WIDEST_INT mask; tree source_expr2; if (code != BIT_IOR_EXPR) @@ -1827,6 +1829,15 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit) return NULL_TREE; n->size = n1.size; + for (i = 0, mask = 0xff; i < n->size; i++, mask <<= BITS_PER_UNIT) + { + unsigned HOST_WIDEST_INT masked1, masked2; + + masked1 = n1.n & mask; + masked2 = n2.n & mask; + if (masked1 && masked2 && masked1 != masked2) + return NULL_TREE; + } n->n = n1.n | n2.n; if (!verify_symbolic_number_p (n, stmt))