From patchwork Thu Jun 23 16:34:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 639767 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 3rb6Wx3gW2z9sXy for ; Fri, 24 Jun 2016 02:35:25 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=p5OU9Qyl; 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:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Sn7f4UIQlu0FRAKi +RAVjwZJovSukgdo3vCKc05dDMQaa0Uj/cmP4UceeILUkvGWbhJhHxlAY6ppefHA tpcF0O9dHE5i4cD54YA7ASFPSczX2vQXYiB0pTQ89i7NxlWVRBiuLMbRoY5RD+YY TYtFN/Huv39ALsolPHLteRKrkv4= 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=AutZ8Dbvavx8c5G9fWzK7O DF2Ts=; b=p5OU9QylR2UzRz62BpQKPQhc4Th8RGOnL4aIMudmLGaeoKC00qG1ny 8feXGB39wYGe8Heu6gyJ8gglkeXbdxSzffcH9pmycRidEwTGrMkgBJ7NNNy5/psk lZWHqs6E3ANnYlPzsFrqi8QbJVK7EULaHInHxQCTrfBc6MUF0vWQg= Received: (qmail 114104 invoked by alias); 23 Jun 2016 16:35:17 -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 114090 invoked by uid 89); 23 Jun 2016 16:35:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=D*arm.com, H*MI:outlook X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jun 2016 16:35:06 +0000 Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3lrp0080.outbound.protection.outlook.com [213.199.154.80]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-51-B0Zz8OAdMJOFm_IW_OJQLg-1; Thu, 23 Jun 2016 17:35:01 +0100 Received: from HE1PR0801MB1482.eurprd08.prod.outlook.com (10.167.190.136) by HE1PR0801MB1484.eurprd08.prod.outlook.com (10.167.190.138) with Microsoft SMTP Server (TLS) id 15.1.523.12; Thu, 23 Jun 2016 16:34:59 +0000 Received: from HE1PR0801MB1482.eurprd08.prod.outlook.com ([10.167.190.136]) by HE1PR0801MB1482.eurprd08.prod.outlook.com ([10.167.190.136]) with mapi id 15.01.0523.019; Thu, 23 Jun 2016 16:34:59 +0000 From: Wilco Dijkstra To: GCC Patches CC: nd Subject: [PATCH] Fix big-endian bswap Date: Thu, 23 Jun 2016 16:34:59 +0000 Message-ID: x-ms-office365-filtering-correlation-id: 8d203b96-47d1-4826-cb2b-08d39b8451cf x-microsoft-exchange-diagnostics: 1; HE1PR0801MB1484; 20:NHxkEbivOh12UN4f73EWJdgpXEJJsYxW74xRVRkqRcq6wvAPufQIeHQepQyTqDTSdxBmVfNZnk/+MHyEnWV8i4QjNK7RhtOI0XrtPgXfKqsEDEkxRiCpZ32Fy2yDyCnzogEhbhtSJaVGiZaxZ4wPGoPCyMblNvYo4YR/3fIGBms= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1484; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:HE1PR0801MB1484; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0801MB1484; x-forefront-prvs: 098291215C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(199003)(54534003)(377424004)(189002)(106356001)(8936002)(3280700002)(105586002)(92566002)(9686002)(74316001)(7846002)(106116001)(33656002)(450100001)(3660700001)(4326007)(2906002)(305945005)(229853001)(10400500002)(7736002)(7696003)(5003600100003)(110136002)(97736004)(68736007)(81166006)(81156014)(5002640100001)(50986999)(8676002)(19580395003)(66066001)(87936001)(19580405001)(54356999)(101416001)(189998001)(575784001)(86362001)(11100500001)(122556002)(2900100001)(77096005)(586003)(76576001)(3846002)(102836003)(6116002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0801MB1484; H:HE1PR0801MB1482.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2016 16:34:59.6469 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1484 X-MC-Unique: B0Zz8OAdMJOFm_IW_OJQLg-1 This patch fixes a bug in the bswap pass. In big-endian BIT_FIELD_REF uses big-endian bit numbering so we need to adjust the bit position. The existing version could potentially generate incorrect code however GCC doesn't emit a BIT_FIELD_REF to access the low byte in a register, so the symbolic number never matches in big-endian. The test gcc.dg/optimize-bswapsi-4.c now passes on AArch64, no other changes. OK for commit? ChangeLog: 2016-06-23 Wilco Dijkstra * gcc/tree-ssa-math-opts.c (find_bswap_or_nop_1): Adjust bitnumbering for big-endian BIT_FIELD_REF. diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 513ef0b3f4eb29a35eae8a0eb14ee8f8c24fcfd9..d31c12fd818a713ca3d251b9464015b147235bbe 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2307,6 +2307,10 @@ find_bswap_or_nop_1 (gimple *stmt, struct symbolic_number *n, int limit) && bitsize % BITS_PER_UNIT == 0 && init_symbolic_number (n, TREE_OPERAND (rhs1, 0))) { + /* Handle big-endian bit numbering in BIT_FIELD_REF. */ + if (BYTES_BIG_ENDIAN) + bitpos = TYPE_PRECISION (n->type) - bitpos - bitsize; + /* Shift. */ if (!do_shift_rotate (RSHIFT_EXPR, n, bitpos)) return NULL;