From patchwork Fri Sep 23 11:42:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 1413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp171810wrt; Fri, 23 Sep 2022 04:43:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6pMp5JsZcnJSyYUQeAU7UpwaiaDhsG3CTQq5suSLuqzPmRzODjszUZVCUjEs6/JQZkvtnh X-Received: by 2002:a17:907:2c41:b0:77d:8aed:cf7c with SMTP id hf1-20020a1709072c4100b0077d8aedcf7cmr6715430ejc.447.1663933406377; Fri, 23 Sep 2022 04:43:26 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n14-20020a05640206ce00b00456d9c1b0e0si401252edy.567.2022.09.23.04.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 04:43:26 -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=hsoaOblG; 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 CD4DA385743A for ; Fri, 23 Sep 2022 11:43:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD4DA385743A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663933404; bh=1s5KgygkdGhQdpuVxwCnVPj8ombvlB4Tu2srkRhjVuE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hsoaOblGlN4Rg/76LTmibHc/05Ko7umZRCddp76IArkQyBUihlSpx9q/jgy2ZOaA3 hvCqHmr5oQI4LRh5FQ5E5Jv8AY5OF3+ApQvWM6vJoQv0vTDUQXk90WxyViK85msfhg oNqNgXG+WfzoRpdHbDjYJG9qt2589DZbyEgUneuA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2088.outbound.protection.outlook.com [40.107.20.88]) by sourceware.org (Postfix) with ESMTPS id ABE553858C52 for ; Fri, 23 Sep 2022 11:42:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ABE553858C52 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=kT2+JRUTFWUTLrsPM2ACHlCj3HrNp3AzBk5/r6c5GykWax50eYWmXJ7I5cwhJtVXEgZQHG38fA9+mJN3O2462UCz763C1L5nIkyAErAbmBWmOCPT+Sk6ZCbr1M8wenjAsgGMdf8GPMZ8tokQqEsqGcw8c0fWp5Ghugt5qFGN91LShb3/HVb0pySfScUX6fZdOtKXGgdmy/+564Qt1vQw4dbFe0UActxVQ0zNJSUxgLMm1s/XWJFo2IjTnXjzIvXem+ko9PwirHTZGIONxtvmxRULbw6VwUkOJ8CKU+w7qbqQ9QmKP24YoPooSDAFZN3J3goZnL1bRYJE8UCXGIXzQA== 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=1s5KgygkdGhQdpuVxwCnVPj8ombvlB4Tu2srkRhjVuE=; b=XnANI7gu7L+QlBLiUCpZjOAtof5LltJioIX7HHK9bCORQN7sE0WSl5U6xfhrqOmDNGl3ccOTkdvUtQUmeDtd6xbZUIOPGSKa2ZsKRgBKQmxnBFknVd5f5G5jkHi/IJ2KLlunaj6hJyUFclEiD3B2Kuw6DL8c45AEsh4Bqf2J09g+3lmku3lL2GJ0k58YelprCuq/3pkmY/809JYJIjBVnBIlUFvJwyzQQucp3ko2q9M7r53q6UKKly1f7wjTyO0nx1WvLRjS1I0dBpu3c9B7V3fYs21FnbA3DVcweADv4y3SSOYPHh5A6AGXmh2u9jynZlA/H4KnUpT5L0N7GuSZ6A== 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 FR3P281CA0136.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::9) by GV1PR08MB7802.eurprd08.prod.outlook.com (2603:10a6:150:59::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.18; Fri, 23 Sep 2022 11:42:30 +0000 Received: from VE1EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:95:cafe::92) by FR3P281CA0136.outlook.office365.com (2603:10a6:d10:95::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.7 via Frontend Transport; Fri, 23 Sep 2022 11:42:30 +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 VE1EUR03FT059.mail.protection.outlook.com (10.152.19.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 11:42:30 +0000 Received: ("Tessian outbound 88978e6d60db:v124"); Fri, 23 Sep 2022 11:42:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0d61a997da7cd853 X-CR-MTA-TID: 64aa7808 Received: from aff847d2372a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 1084B5D2-B003-4127-BFDE-DF74A83D1C08.1; Fri, 23 Sep 2022 11:42:23 +0000 Received: from EUR02-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id aff847d2372a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Sep 2022 11:42:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FF+XJzgRnAUSr1M5E9ACMGaVOmlfdpoqWg3IYIW5Se/IMtqrRcqhdcysstVNalaDy1jyg7x3eGMu9JJ3egaTGOA1MhrczIF4NeiTMbq6K/0ZlbdJW9PaWXZKW+sjfGrXMrKd1Q7KxHYdvwGXjHlcxfJNjwdOBWjDnUar52jKJP9r2hICmGF+fjKRWT5s5aad6vwQihiLL7J7oO7wg1C4OMDgD96HWPXbh/XUJbJ1MY1Qlusmtw95302HDrBJ8002YZD5bQMQZfYU2I1g2dmGBFdj8gxrojmhmj7LL2lA9+RT+ju1tV6X5QGd1+6aU4fbij9dez5vHaRtq3RJgR2g+w== 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=1s5KgygkdGhQdpuVxwCnVPj8ombvlB4Tu2srkRhjVuE=; b=WozsUmQkAnaDgh+Q2EttlvL/sYNhqgHDCuCdWCmzCym4gmQwbbBmO2bKtWMPY5EB6yvqfzIuvCUJesbW974dvxowqMZ1jo8oobrlGmSzvFrz4+ybifU2BC1jmLFZc8UzWg48Ue9b7x9hg5tdCzB9wldBy0dUJUWNq0SeDJrWuYADoDPgiAr1WkdmtVDbYEYeeEBuZPkxOq/daivmtUzwDxDSGFnpGXBJ1l+OkmFoZPQ0n0QbV7QDoTvfMESO0Py7MkH7jvdnwYLEuNhCGNl0WRo1e5gbcO7cMc9ai5wm087mYvuMuQc+UFTt49wpxM5++cpZPE867rNmH+Gu2RxppA== 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 PAVPR08MB9580.eurprd08.prod.outlook.com (2603:10a6:102:31b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20; Fri, 23 Sep 2022 11:42:21 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::6529:66e5:e7d4:1a40]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::6529:66e5:e7d4:1a40%4]) with mapi id 15.20.5632.021; Fri, 23 Sep 2022 11:42:21 +0000 Date: Fri, 23 Sep 2022 12:42:12 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2]middle-end Fold BIT_FIELD_REF and Shifts into BIT_FIELD_REFs alone Message-ID: Content-Disposition: inline X-ClientProxiedBy: SA9PR13CA0055.namprd13.prod.outlook.com (2603:10b6:806:22::30) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|PAVPR08MB9580:EE_|VE1EUR03FT059:EE_|GV1PR08MB7802:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a4c0986-cdc6-49db-79ae-08da9d58b2a5 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: Rx3k7gbmWKQ/9HNDkEFcGJZj6LCDae34mVJF583JACoTR7yBcVh2Xp60TYdahZPgszZFXT4bfRUDmkxMszjPsC3kjxrBrXptysFG9PQlTEXzrjei0+OVZ0OEO74NxCPO03haftFWzbYLcPGpEqUxcYGgFTfeWqkgjrvDapf+609YhlvWwWahQM2WQwlQLZmF7JCDoMM5jRf/20RPqifXAJ685/caXo7BJ6eJD+LIgNy15qJrcGdfvrfRUEW9NZH6HJykn6FDyYLk7aIEMyqpZrM/1baqAgDcy7kk72+dCZWXlq9akv+qo8YoX3S0PfHZkd8JtG0UwWFn7lOeaDzSaIsdoGP6+4p2LB2CIxOekrKtL/BvibcO+R/qzmzPddRhC/NK+EoMXGMP/rBxw0SCP7bfGQw6q2rQnJYuZtJcY8rjBZebd5rsCBIV+UrSoVA/VNPlzlN4X0wLkagptuA6JutFDpA/c99k030PXrPM9S/1XnJWhL5/Rrq4QkT/uRmwFEJyz1uA6zuIKxRFkjxUmZQaliIf6oX7HUX/XvtFfGiMnXP7eAosXKsNa29HqFRfEaDqYgBErjClg7nez04qViS6P3TynEGg+LmQzLrgJwyYafImMLZB1R8FnOzP85i3s7X/aShbuC7LMPFHqfucNs5mp9GNkSqcH8BilqZ2wcodKu2RUsfsekvCLW0e11dDfX/HmYFvV2CQuUYq8FZX2uwFMm5+yf8TC2aw5AwjjTfMEaNb6jqobNRrRrPXK/ahO8qf48vzZJa3FoLME52cx+MTB5ZXJ/skAMFt5fU8wFU= 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)(366004)(376002)(396003)(136003)(39860400002)(346002)(451199015)(44144004)(186003)(6506007)(38100700002)(316002)(5660300002)(33964004)(235185007)(4326008)(8676002)(8936002)(6666004)(86362001)(36756003)(478600001)(6486002)(2616005)(44832011)(6512007)(66476007)(2906002)(4743002)(66556008)(66946007)(26005)(6916009)(83380400001)(41300700001)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9580 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: VE1EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: df52b505-89f6-4cba-b8f1-08da9d58acd7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JEioLRE7h+0JR+Qi4vRZiOCXCRHJUEIPoKDtNlFQ3NQvYTl7EeHg2TL7I2mT1dpZsa8ipOoPSiU//I0H1vXAAFuSaBI8bQR9VgMJrc9eUntaVtcgkcb8uQnrO3FJmAeerr6xR3dhZpyNUHBtn//BoruVz97NBHa9Yzf2OYuRA50qyLxDhZuA2yyoS2NybPoporHOk+g9kfXU6v2z+USif6nINGEADO/nubIGtOUEqJ+6Z3VuqI6LxDwx1QLq4xxqM+DGRAb5aQtGKN7JR0RkZqa77HqHhce8qs8xJAn4vRWlC1UOtN3hXEFNOz5rRnHRu8/N+G9OEgbhPhwLFJF2eGrpVKmr8S+P61CgN/ggY05ZxcaD9nmhEk3n65iIdNgfKfRN3GkXwrawyw4p8eO97rtSQZ9s2fBgq8+6r9I2ik9AcNgWtRV+nVaLFRSns7SvWh9buuOQLiAkzlHBBYsheSErdoXQ5M0cT5m2N2MaWJcDp9Kn+mJkPWnp0s0qKMYjGsJs5c1scs290pOwldoDMdl3HuYbDDnmfbq5VQUX/sYQUnTdYqMY9ucEXEQgY2KgOybuvuyMN5fSgo/Tv8wY4G0EU6hWasOA6JjLKDFWfM3rotjuPO98VngOh9y/GTKg2fXJKjVxylCfbpQ0l6zheopnTkz0vYP6vgsdcxh4WaZ6LZvQ66wteeTmRAVE/AwnhJhbQFUeqCGGBTO2SkRSf3nq3+DiKGsaqyMH2jTXsB9ZMXKlyXB/KSyBsikvIWLUzA2L6Yq/2hSmRqAMseQle+wlJxfq97KL1W5og67mUOfyAuRbtDaoWFNYTqAaeBi5uCC4zUPbhUkk26hcZ3gwqw== 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)(346002)(376002)(39860400002)(396003)(451199015)(40470700004)(46966006)(36840700001)(40460700003)(356005)(36756003)(33964004)(86362001)(82740400003)(81166007)(316002)(6916009)(8676002)(70586007)(70206006)(235185007)(5660300002)(2906002)(82310400005)(8936002)(4326008)(47076005)(83380400001)(36860700001)(6486002)(41300700001)(107886003)(40480700001)(6666004)(26005)(44144004)(44832011)(2616005)(6506007)(478600001)(6512007)(4743002)(336012)(186003)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2022 11:42:30.4968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a4c0986-cdc6-49db-79ae-08da9d58b2a5 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: VE1EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7802 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, 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?1744760635683005487?= X-GMAIL-MSGID: =?utf-8?q?1744760635683005487?= Hi All, This adds a match.pd rule that can fold right shifts and bit_field_refs of integers into just a bit_field_ref by adjusting the offset and the size of the extract and adds an extend to the previous size. Concretely turns: #include unsigned int foor (uint32x4_t x) { return x[1] >> 16; } which used to generate: _1 = BIT_FIELD_REF ; _3 = _1 >> 16; into _4 = BIT_FIELD_REF ; _2 = (unsigned int) _4; I currently limit the rewrite to only doing it if the resulting extract is in a mode the target supports. i.e. it won't rewrite it to extract say 13-bits because I worry that for targets that won't have a bitfield extract instruction this may be a de-optimization. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues. Testcase are added in patch 2/2. Ok for master? Thanks, Tamar gcc/ChangeLog: * match.pd: Add bitfield and shift folding. --- inline copy of patch -- diff --git a/gcc/match.pd b/gcc/match.pd index 1d407414bee278c64c00d425d9f025c1c58d853d..b225d36dc758f1581502c8d03761544bfd499c01 100644 Signed-off-by: Andrew Pinski --- diff --git a/gcc/match.pd b/gcc/match.pd index 1d407414bee278c64c00d425d9f025c1c58d853d..b225d36dc758f1581502c8d03761544bfd499c01 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7245,6 +7245,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && ANY_INTEGRAL_TYPE_P (type) && ANY_INTEGRAL_TYPE_P (TREE_TYPE(@0))) (IFN_REDUC_PLUS_WIDEN @0))) +/* Canonicalize BIT_FIELD_REFS and shifts to BIT_FIELD_REFS. */ +(for shift (rshift) + op (plus) + (simplify + (shift (BIT_FIELD_REF @0 @1 @2) integer_pow2p@3) + (if (INTEGRAL_TYPE_P (type)) + (with { /* Can't use wide-int here as the precision differs between + @1 and @3. */ + unsigned HOST_WIDE_INT size = tree_to_uhwi (@1); + unsigned HOST_WIDE_INT shiftc = tree_to_uhwi (@3); + unsigned HOST_WIDE_INT newsize = size - shiftc; + tree nsize = wide_int_to_tree (bitsizetype, newsize); + tree ntype + = build_nonstandard_integer_type (newsize, 1); } + (if (ntype) + (convert:type (BIT_FIELD_REF:ntype @0 { nsize; } (op @2 @3)))))))) + (simplify (BIT_FIELD_REF (BIT_FIELD_REF @0 @1 @2) @3 @4) (BIT_FIELD_REF @0 @3 { const_binop (PLUS_EXPR, bitsizetype, @2, @4); })) --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7245,6 +7245,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && ANY_INTEGRAL_TYPE_P (type) && ANY_INTEGRAL_TYPE_P (TREE_TYPE(@0))) (IFN_REDUC_PLUS_WIDEN @0))) +/* Canonicalize BIT_FIELD_REFS and shifts to BIT_FIELD_REFS. */ +(for shift (rshift) + op (plus) + (simplify + (shift (BIT_FIELD_REF @0 @1 @2) integer_pow2p@3) + (if (INTEGRAL_TYPE_P (type)) + (with { /* Can't use wide-int here as the precision differs between + @1 and @3. */ + unsigned HOST_WIDE_INT size = tree_to_uhwi (@1); + unsigned HOST_WIDE_INT shiftc = tree_to_uhwi (@3); + unsigned HOST_WIDE_INT newsize = size - shiftc; + tree nsize = wide_int_to_tree (bitsizetype, newsize); + tree ntype + = build_nonstandard_integer_type (newsize, 1); } + (if (ntype) + (convert:type (BIT_FIELD_REF:ntype @0 { nsize; } (op @2 @3)))))))) + (simplify (BIT_FIELD_REF (BIT_FIELD_REF @0 @1 @2) @3 @4) (BIT_FIELD_REF @0 @3 { const_binop (PLUS_EXPR, bitsizetype, @2, @4); }))