From patchwork Tue Mar 11 06:53:39 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: 328934 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 39E472C0079 for ; Tue, 11 Mar 2014 17:53:49 +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=iTg6moy49FyhlLWZ+v1yRqCfqWXRV MucT0gXtKqsObbgYA0IY2gkWOYZSPGiuuhrwXzc1/UOGf9AEOA8sud0/Y2izQrO+ DChxyaIcPh10r4kE8PgiUshJ+fRHq47z/JrrKSAruVDClWCI4IQJryPrE96AVArE QiUKDt6WbFBg10= 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=21DnVGz1wH4wQ4Y9xjBz0mVZFtg=; b=QUA 0fJCRhLbHRCAYs3lXNi2WswLjMZDrqx6R/Rxfk4Ik2/+fwTk7IEvw0Dgj/jacpke +B2I4INxDCyjnDZRi73WoxG7hw6DTv2MnnMo5PAu7FjzgV0tdpAi2jqyNAgEbVs4 VPAQjovbqU0MlbZ7M6kXrObkAK2WWNo47W6PLT1U= Received: (qmail 17452 invoked by alias); 11 Mar 2014 06:53:41 -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 17437 invoked by uid 89); 11 Mar 2014 06:53:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.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; Tue, 11 Mar 2014 06:53:37 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Tue, 11 Mar 2014 06:53:35 +0000 Received: from SHAWIN202 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 11 Mar 2014 06:53:42 +0000 From: "Thomas Preud'homme" To: References: <000301cf39e8$84eb6910$8ec23b30$@arm.com> <20140307141555.GJ22862@tucnak.redhat.com> In-Reply-To: <20140307141555.GJ22862@tucnak.redhat.com> Subject: RE: [PATCH] Fix incorrect byte swap detection (PR tree-optimization/60454) Date: Tue, 11 Mar 2014 14:53:39 +0800 Message-ID: <000001cf3cf6$a3ef8b00$ebcea100$@arm.com> MIME-Version: 1.0 X-MC-Unique: 114031106533500201 X-IsSubscribed: yes > From: Jakub Jelinek [mailto:jakub@redhat.com] > > n->size = n1.size; > > + for (i = 0, mask = 0xff; i < n->size; i++, mask <<= 8) > > This should be mask <<= BITS_PER_UNIT for consistency. Indeed. > > And, as has been said earlier, the testcase should be a runtime testcase > (in gcc.c-torture/execute/), probably with > __attribute__((noinline, noclone)) on the function, where main calls the > function with a couple of different values, verifies the result and aborts > if it is incorrect. Done as well. This should also solve the problem of aarch64 (and potentially others) missing as the test will be executed by all platform. > > Jakub Since it seems Exchange is unable to keep formatting of patches (or I am unable to configure it correctly), I put the new patch in attachment in addition to reproducing it below. 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..b95b2b3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-03-10 Thomas Preud'homme + + PR tree-optimization/60454 + * gcc.c-torture/execute/pr60454.c (fake_swap32): Testcase to track + regression of PR60454. + 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..e5fbd8f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr60454.c @@ -0,0 +1,25 @@ +#include + +#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. */ + +uint32_t +fake_swap32 (uint32_t in) __attribute__ ((noinline, noclone)) +{ + return __fake_const_swab32 (in); +} + +int main(void) +{ + if (fake_swap32 (0x12345678) != 0x78567E12) + 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))