From patchwork Mon Oct 31 11:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 13240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2266944wru; Mon, 31 Oct 2022 04:59:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52S9WrMex7oXCrxF5JK7IGTUJRPha4vJ9sRokcEKy2q3O4n/bqF+NxOyFHZgImw6ZmZtt6 X-Received: by 2002:a17:907:1de0:b0:7a7:6a8:1e61 with SMTP id og32-20020a1709071de000b007a706a81e61mr12417013ejc.468.1667217540339; Mon, 31 Oct 2022 04:59:00 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s4-20020a50d484000000b00447dfae6181si7330888edi.235.2022.10.31.04.59.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 04:59:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="dX/X44Qj"; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 305953853816 for ; Mon, 31 Oct 2022 11:58:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305953853816 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667217527; bh=xWzAevfcmxmIehbQ96I1Iiq22u8sQ8kFIWZiKXqtP3A=; h=Date:To:Subject:In-Reply-To:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dX/X44QjXaPzC6cgn8xumoHmmCB4b8ArHyuuL2HjxzzZAtj6n/uf/JGydRMRL4yhj lsFWI/9tXwCy9fiOoMiEoYrugL80ak0DTZw1JItNIROOuNLRn2L2SYz4FHHIktwm0P 19o/P5Q+KjfSBE7yj+/xZJqU69+HbxA6++sBoweQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2089.outbound.protection.outlook.com [40.107.105.89]) by sourceware.org (Postfix) with ESMTPS id 5CBEF3854811 for ; Mon, 31 Oct 2022 11:57:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5CBEF3854811 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=BBTv1a3v5Cj02IEqRATC1iDfyREAHp9E5qRbtM0lkbYcOD2drpvz+UH1RTJ7IcWQhxVHEcK9KOQrDgAKw6bfI61y1r47g6WcGAd+kcvlWFXBrCpNb7xEh4TBGysqssj+hvK5E+hyoIibcoQvp0gvlj3YtnMSIWbbMIexUeiQjxaLowIvi5ZpMJRxZ1dySVtuaDO5fFiuOtruCZeMKZypEADH8HenKU+iAuJt/jFfpQFS8D10VOq3YTzS8AGjUfZ8un4HmAazQkbOldsBDxFcDUc/iDsrEfC3mRFCYg+aecrWRzI9Hfn9O2QPmO4Ax8UW8VdbMGpsemtsPFuffSERig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xWzAevfcmxmIehbQ96I1Iiq22u8sQ8kFIWZiKXqtP3A=; b=KUo/EQeXu8Tdt1GsuxngCK5Y+T+g5L1cXtT6k/p/RvlXY+f+NQ/IZs2FGGv3Vcagjx1/dh2Nz5a6qJQPKjJ2LbnxvA0WF/+jYehSMfa6Jda324AJC9pnroW/e7VoQ7MSpEnc04RF4Ogo6n2RXLEo0TH4ZbJbaHz4TUMw2pVhOWZ8KQxL6C4WeXEi6oMfPAvZmZG+4rygt4xybdL9VUkqlTbomNpcv84P0Mh2jrUFlw9twi+NmPIyz+nNYBe1JstA64tpSpo0ufoVs9vEGAUuvdK2suCd8+zQx0bBAA6AoqZUneeKr7/e6jOG6nQ0/ThxdnrGnO5XuJXks7nWddkbqQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB6PR0802CA0037.eurprd08.prod.outlook.com (2603:10a6:4:a3::23) by GVXPR08MB7703.eurprd08.prod.outlook.com (2603:10a6:150:6b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 11:57:56 +0000 Received: from DBAEUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a3:cafe::d5) by DB6PR0802CA0037.outlook.office365.com (2603:10a6:4:a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19 via Frontend Transport; Mon, 31 Oct 2022 11:57:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT021.mail.protection.outlook.com (100.127.142.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14 via Frontend Transport; Mon, 31 Oct 2022 11:57:55 +0000 Received: ("Tessian outbound 58faf9791229:v130"); Mon, 31 Oct 2022 11:57:55 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6dcb4d70b20071fd X-CR-MTA-TID: 64aa7808 Received: from 3f5959128ad8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3895C469-ADEB-42BB-A8D0-B57348B8FEDD.1; Mon, 31 Oct 2022 11:57:48 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3f5959128ad8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 31 Oct 2022 11:57:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XjwVwANzkYrX++qJaUSKGhKhcPzoOl6kIVq+NGOBF7+w+K3FcI8rp/oW3NrnPD/tUrSUa2iAauzndC/tkx3Zei3tH6BH/EF62IpyaH+6jENPlkEDUAqphD3yqUlnRycKFLlOXIxO+WjatzzLjar3X0papyUny0pJVj58eAPt45BnWAu0sk+Lb1j5OyxwBhgEOpSeOlcpwLJrElqPGXioo6N1X7C8JeSFBoRFBx4Qi8guvqQdc1eoyQiHGmxi8Bggor9+jQVBJ91vy+9XWtnpMwwzz+x0t1K2QE4rH0vx08gDmzvn/VMkFX67NI0JAHB4BjZv5y5TS3IVYUTAstTnOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xWzAevfcmxmIehbQ96I1Iiq22u8sQ8kFIWZiKXqtP3A=; b=RbGsS4UQZD4jyFrqVzQMUY4UU15vLH0oEfhpXyp7NjnWkwmVasHa7pevf+bCnefb9Uc4VfCs5Qve7/mfOAGexkLJrzJI23fEYbRIaEfxPzS20Td4LnAsZCykNSwLpOjxkbsYPw8BXXwH1Y3/lygxUYyv7GD4uDgKL6v0bkyoXm6v+xU2UH4beAxDMhtZ6RgIzSN8o7fr58XemPUIjBErECznetTncJ4qmP6yuQ+WfJXlIwEpOCgOisxlACnxBs3vBPVWLxp/8nThfxEipmJhpf7+7pqIMB1eDnsS8ASnRrNDvq5RzhyWd7Qbr/l25lRGAZbPFXnClD2GJzULhpgetQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by DB9PR08MB8385.eurprd08.prod.outlook.com (2603:10a6:10:3da::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Mon, 31 Oct 2022 11:57:47 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::c57d:50c2:3502:a52]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::c57d:50c2:3502:a52%4]) with mapi id 15.20.5769.019; Mon, 31 Oct 2022 11:57:47 +0000 Date: Mon, 31 Oct 2022 11:57:42 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/8]middle-end: Support extractions of subvectors from arbitrary element position inside a vector Message-ID: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO2P265CA0516.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::23) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|DB9PR08MB8385:EE_|DBAEUR03FT021:EE_|GVXPR08MB7703:EE_ X-MS-Office365-Filtering-Correlation-Id: 94b9cbf5-2d93-4b28-4014-08dabb3725ce x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: UDhc20mtfcYfmTiTnUYBx5uH+d3T5eV14AwjAKzMv7zhZNccdUy7YX05PMh7CO+zpO3yv5xrngwGmmXi9xh75LJ5scWQRrOgSw8DwXr4Gl/iQhb8OJNeTh7EqpIr8eHWERwp9FXXr15uimni2374sK5Z8ic3E9bWiVPHl8voRjE4DA15NpJpY9w/ID5TfziR7veGhH7DCdes5JPdj0PXAtcqpe9AjhuLGP3LCew9VqVcoCGK4ebsdquKJUTwrgw1H5H7Pc+NiNEQW7dg3x06S0JHfVHXoC0afzHTWI4NYdDyo+Jd869d1nomT/bM59gfvO4NnsFin5OCBZfcDeY2KB/BZ8dDn7KDbhd5hIJxqjiwhyPlkiuszCYe0Pol4lx/MFUdNKQWcqttti162aIo3Y4UdMJXz2cBwbwMh6OKryHgdbaCCDH2bDCqrPOoM3R7UH2wtRdfLgwHi2zGQn15WpCjpNQmR3HDnPXspLQQYN9hV3Z+rU1vs/9rw7HsWXxyM99mjiSjptDbFD795OGnHNtlnMz2DCB5vixDzWT9kJ+6im+hEGTi3PN+oF7gHdK11NQB0BGXv4GWvNE4dEZgr6e0AtuHfCybFWxgzqNIo2fM0wjnX26DW0nwryDSyY+yY+ub/rrMaJ2BeWTAEKdMidOXRDLfJNRgA+afntZkP5bghyevYBFcomIVHEmsY08J3flZtfZNEQ9vQk077pQCFQbgifwwdDeRICO97GIeRUJMUFuOPBUinPTQVFklAe4I/8IYxEnEFY763VPa3sUAdJ90AVDP192ewh7DmXiEwdmytxoOgwux4Hh2SOZ9ECf9 X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(346002)(366004)(136003)(396003)(39860400002)(376002)(451199015)(66899015)(36756003)(84970400001)(38100700002)(5660300002)(44832011)(2906002)(235185007)(186003)(86362001)(4326008)(6916009)(4743002)(2616005)(478600001)(6666004)(8676002)(316002)(6486002)(66476007)(66556008)(66946007)(41300700001)(8936002)(26005)(33964004)(6512007)(44144004)(6506007)(67856001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8385 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ca3693d2-cdd0-446c-b5a3-08dabb37207b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aQ+SqH0fOzIP+0WM6SWa09zcWnQGBgKxZl2F7AC+9jcD7yjEtUwOybMdEscrLOrjYRDqwOPxkcFiba/AteCOVnzTNnU0IialYbubpYhwX3IbjQR/UzdF7UR4uhKE/KTh2DEXOPTeOMNbeEIIUYimuv2RQqQ68at7J8I1alIb14XlvFVDgYAfO1ODiqHkrYQseX9aXGj8jyQqWCX3u/McofFST4HmWxGCqMcKNnFouZ378MUtTWhUxe7D+Dn4+2LRKEKF/sHTsP/HUBBOxm7XQWhDTTXFZ+aCGW04ydbm3W7jZoq/ahro7i7qDmHQFAY1y8NN1dJjGo45EPCcxQBxXLhBxW44JBINJK90Vu0MdC+bYRRqaP5vIjUzfK5XxmoGlM2rynlXZ349gU0BlrG06avhunTTOk1sjCN8mvfSJHTZ1Daa02xSCi0tS4lzb93VbesNZeKPzNnNrSUr3xfsWblH7yhOhVsn4kWWMNlg70/HhUQeZ51rByMxqMMt+pp69c16oXXQpJh5jdgMZOGj/gOAJwdJ0S4UbJqWainVBF5++99/5mOe5hxDzrAZRq7QxU2KjzEe29EJ1HjrL5rhaK5ivwIm+DUUbkJH53Kpq2x7OKZDUTLbQUjK4FDawXkl/z20HuhFJbxyREw2I0S49UyCGcw+K+D0qp3mIDA9mTcPnl/dA30FyXCzfvF0N0TQOXb17j1OUzHAzXwS25xreNWG3XocBj9FUHhIN8c3wo81hkkswfsKe93CE03LujCIIEz2SaQdKIu2+agob8kTMZQCasts7fqxpcei3QEDsARsSwagCBk2HaeF/SUiYO8zMcH5Y1CYaMVbcr8yid8BQ464BT/zKtQhbkZkXjGgKGg= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(136003)(39850400004)(396003)(376002)(346002)(451199015)(36840700001)(40470700004)(46966006)(8936002)(84970400001)(44832011)(235185007)(41300700001)(478600001)(82740400003)(40460700003)(5660300002)(316002)(2906002)(66899015)(70206006)(70586007)(4326008)(8676002)(6916009)(47076005)(81166007)(4743002)(6512007)(26005)(6486002)(36860700001)(6506007)(82310400005)(33964004)(44144004)(186003)(40480700001)(356005)(2616005)(336012)(107886003)(86362001)(36756003)(6666004)(67856001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 11:57:55.8059 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94b9cbf5-2d93-4b28-4014-08dabb3725ce X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR08MB7703 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tamar Christina via Gcc-patches From: Tamar Christina Reply-To: Tamar Christina Cc: nd@arm.com, rguenther@suse.de Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748204299672086550?= X-GMAIL-MSGID: =?utf-8?q?1748204299672086550?= Hi All, The current vector extract pattern can only extract from a vector when the position to extract is a multiple of the vector bitsize as a whole. That means extract something like a V2SI from a V4SI vector from position 32 isn't possible as 32 is not a multiple of 64. Ideally this optab should have worked on multiple of the element size, but too many targets rely on this semantic now. So instead add a new case which allows any extraction as long as the bit pos is a multiple of the element size. We use a VEC_PERM to shuffle the elements into the bottom parts of the vector and then use a subreg to extract the values out. This now allows various vector operations that before were being decomposed into very inefficient scalar operations. NOTE: I added 3 testcases, I only fixed the 3rd one. The 1st one missed because we don't optimize VEC_PERM expressions into bitfields. The 2nd one is missed because extract_bit_field only works on vector modes. In this case the intermediate extract is DImode. On targets where the scalar mode is tiable to vector modes the extract should work fine. However I ran out of time to fix the first two and so will do so in GCC 14. For now this catches the case that my pattern now introduces more easily. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * expmed.cc (extract_bit_field_1): Add support for vector element extracts. gcc/testsuite/ChangeLog: * gcc.target/aarch64/ext_1.c: New. --- inline copy of patch -- diff --git a/gcc/expmed.cc b/gcc/expmed.cc index bab020c07222afa38305ef8d7333f271b1965b78..ffdf65210d17580a216477cfe4ac1598941ac9e4 100644 --- diff --git a/gcc/expmed.cc b/gcc/expmed.cc index bab020c07222afa38305ef8d7333f271b1965b78..ffdf65210d17580a216477cfe4ac1598941ac9e4 100644 --- a/gcc/expmed.cc +++ b/gcc/expmed.cc @@ -1718,6 +1718,45 @@ extract_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, return target; } } + else if (!known_eq (bitnum, 0U) + && multiple_p (GET_MODE_UNIT_BITSIZE (tmode), bitnum, &pos)) + { + /* The encoding has a single stepped pattern. */ + poly_uint64 nunits = GET_MODE_NUNITS (new_mode); + int nelts = nunits.to_constant (); + vec_perm_builder sel (nunits, nelts, 1); + int delta = -pos.to_constant (); + for (int i = 0; i < nelts; ++i) + sel.quick_push ((i - delta) % nelts); + vec_perm_indices indices (sel, 1, nunits); + + if (can_vec_perm_const_p (new_mode, new_mode, indices, false)) + { + class expand_operand ops[4]; + machine_mode outermode = new_mode; + machine_mode innermode = tmode; + enum insn_code icode + = direct_optab_handler (vec_perm_optab, outermode); + target = gen_reg_rtx (outermode); + if (icode != CODE_FOR_nothing) + { + rtx sel = vec_perm_indices_to_rtx (outermode, indices); + create_output_operand (&ops[0], target, outermode); + ops[0].target = 1; + create_input_operand (&ops[1], op0, outermode); + create_input_operand (&ops[2], op0, outermode); + create_input_operand (&ops[3], sel, outermode); + if (maybe_expand_insn (icode, 4, ops)) + return simplify_gen_subreg (innermode, target, outermode, 0); + } + else if (targetm.vectorize.vec_perm_const != NULL) + { + if (targetm.vectorize.vec_perm_const (outermode, outermode, + target, op0, op0, indices)) + return simplify_gen_subreg (innermode, target, outermode, 0); + } + } + } } /* See if we can get a better vector mode before extracting. */ diff --git a/gcc/testsuite/gcc.target/aarch64/ext_1.c b/gcc/testsuite/gcc.target/aarch64/ext_1.c new file mode 100644 index 0000000000000000000000000000000000000000..18a10a14f1161584267a8472e571b3bc2ddf887a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ext_1.c @@ -0,0 +1,54 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +#include + +typedef unsigned int v4si __attribute__((vector_size (16))); +typedef unsigned int v2si __attribute__((vector_size (8))); + +/* +** extract: { xfail *-*-* } +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract (v4si x) +{ + v2si res = {x[1], x[2]}; + return res; +} + +/* +** extract1: { xfail *-*-* } +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract1 (v4si x) +{ + v2si res; + memcpy (&res, ((int*)&x)+1, sizeof(res)); + return res; +} + +typedef struct cast { + int a; + v2si b __attribute__((packed)); +} cast_t; + +typedef union Data { + v4si x; + cast_t y; +} data; + +/* +** extract2: +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract2 (v4si x) +{ + data d; + d.x = x; + return d.y.b; +} + --- a/gcc/expmed.cc +++ b/gcc/expmed.cc @@ -1718,6 +1718,45 @@ extract_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, return target; } } + else if (!known_eq (bitnum, 0U) + && multiple_p (GET_MODE_UNIT_BITSIZE (tmode), bitnum, &pos)) + { + /* The encoding has a single stepped pattern. */ + poly_uint64 nunits = GET_MODE_NUNITS (new_mode); + int nelts = nunits.to_constant (); + vec_perm_builder sel (nunits, nelts, 1); + int delta = -pos.to_constant (); + for (int i = 0; i < nelts; ++i) + sel.quick_push ((i - delta) % nelts); + vec_perm_indices indices (sel, 1, nunits); + + if (can_vec_perm_const_p (new_mode, new_mode, indices, false)) + { + class expand_operand ops[4]; + machine_mode outermode = new_mode; + machine_mode innermode = tmode; + enum insn_code icode + = direct_optab_handler (vec_perm_optab, outermode); + target = gen_reg_rtx (outermode); + if (icode != CODE_FOR_nothing) + { + rtx sel = vec_perm_indices_to_rtx (outermode, indices); + create_output_operand (&ops[0], target, outermode); + ops[0].target = 1; + create_input_operand (&ops[1], op0, outermode); + create_input_operand (&ops[2], op0, outermode); + create_input_operand (&ops[3], sel, outermode); + if (maybe_expand_insn (icode, 4, ops)) + return simplify_gen_subreg (innermode, target, outermode, 0); + } + else if (targetm.vectorize.vec_perm_const != NULL) + { + if (targetm.vectorize.vec_perm_const (outermode, outermode, + target, op0, op0, indices)) + return simplify_gen_subreg (innermode, target, outermode, 0); + } + } + } } /* See if we can get a better vector mode before extracting. */ diff --git a/gcc/testsuite/gcc.target/aarch64/ext_1.c b/gcc/testsuite/gcc.target/aarch64/ext_1.c new file mode 100644 index 0000000000000000000000000000000000000000..18a10a14f1161584267a8472e571b3bc2ddf887a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ext_1.c @@ -0,0 +1,54 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +#include + +typedef unsigned int v4si __attribute__((vector_size (16))); +typedef unsigned int v2si __attribute__((vector_size (8))); + +/* +** extract: { xfail *-*-* } +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract (v4si x) +{ + v2si res = {x[1], x[2]}; + return res; +} + +/* +** extract1: { xfail *-*-* } +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract1 (v4si x) +{ + v2si res; + memcpy (&res, ((int*)&x)+1, sizeof(res)); + return res; +} + +typedef struct cast { + int a; + v2si b __attribute__((packed)); +} cast_t; + +typedef union Data { + v4si x; + cast_t y; +} data; + +/* +** extract2: +** ext v0.16b, v0.16b, v0.16b, #4 +** ret +*/ +v2si extract2 (v4si x) +{ + data d; + d.x = x; + return d.y.b; +} +