From patchwork Tue Jul 7 10:17:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 138643 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F0424BA2E1E for ; Tue, 7 Jul 2026 10:19:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F0424BA2E1E Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=DoMz4zmA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=DoMz4zmA X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11011012.outbound.protection.outlook.com [52.101.65.12]) by sourceware.org (Postfix) with ESMTPS id CEF874BA2E20; Tue, 7 Jul 2026 10:18:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEF874BA2E20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CEF874BA2E20 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.101.65.12 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1783419529; cv=pass; b=P5LbcIlB5jpJ+YNj+X+i24uE0Pj2hTuNHGGtrXRdi4uv0nstD8x63HQG8EFHDgSreUvRaBCWpDDkw0aTTnm122YaBuPGOrmwL5jIFoamk2oys8QhVXxbCX8kLLi8MDF5ceuzRRJIms1StZ/+U+mrXZUDFB3veZgGk3h+6V/onzE= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1783419529; c=relaxed/simple; bh=feeU45s9n/WCWZpYf/hp9TEiGWageOhDBoDCEmh8r0M=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=JHFJCTka2Sp1z/eAEvBUB9Xsiw0IcZ0t5j/mO0OtwydWE9hcFdcLCKjLYcgpwElo/9cvFinxcDa1rHUm6ZJyA3WlrnaADN9GsMTEHooYNKvZILrCUoJce3VvvEHXWilmZ6O3bBQfok6TxOZqcBzlbY/J37D7+8q4eVIVReaQxOk= ARC-Authentication-Results: i=3; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=DoMz4zmA; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=selector1 header.b=DoMz4zmA DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEF874BA2E20 ARC-Seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=JomKafr86t4fSqUNHTVlfi4XOuQvJxcW+n5oTthpFkzfd3RWMBWCWlTEezsoJHuQMVaNHbdAJ+mYcOhY1YTYQVFbYtax1QMVrePpydFHUh01srFBMY32t/BkiHPqg+VKKxGELVz7MYgU6fRqTqNLfR/JtSiGlR7b/hoWhzYrR6kvvAnJ/qXZzXx1/OEJy8/4NFCcaT2+4c1d0pGZ9I/FQ6HMglwmheOUZ5mBgLqyxyrKcIy77ke+jRU4TUKUaxNQBu0Dekg0gpcEX0whEpXjejFgwwi85q0Ebzl6gnF7kFYx78onYh0zagBAJM1TTJoHZ/S0YdZCxpXUoEF56K4x8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=EemIJVtWDHXX8KQyWS3ODPtGPloYcSFq4T4PV2y3TmQ=; b=OJMSBYOck9tvlhoIODw9n46DaNMIPPpKCCvKFCl4ARguwfiW7/3Oey/Yl7qU5pzl96F90RhiDQvhwbV92SKJ+yOFLMrhrpenfML93ijw9/v6G/2La2iukEMOzr3rZXxdpq5WVY1eWw52y4PZSR/ywo9m+lSNlCaHh6QrWH+Jc6JV5Wmfcbf1DT6m3g9iE7SMr9t4dc512X1UR3n3L03N+bHHYYXDIjPETazYrZXgGazWBqb6516NAZ+6WtPeOH2wSbGfmHCqqEgXc0oIOKbC1+6ekaT/9TEWAfrpPSXuME/ZrMc49Je5vcSzosjdXOWPJmz1lliSswelYCEQSPdYbQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=quesejoda.com 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=arm.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]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EemIJVtWDHXX8KQyWS3ODPtGPloYcSFq4T4PV2y3TmQ=; b=DoMz4zmAI+8+XITEhZODxqJQc3TwcevLiBLXaFyGkTolJDwFAD8Csoru0lI3YdBfzI9/ljg2JjuCBCI6vp/Lk9MJHNKb2ZLkx+/zJcFD2pZ0viTfhi6o/y+hR9PwNYEwEhbj8puFXNof/pRKDriIuB1txAFCdY0k+95cEPYgJMs= Received: from AS9PR06CA0756.eurprd06.prod.outlook.com (2603:10a6:20b:484::12) by DB9PR08MB7842.eurprd08.prod.outlook.com (2603:10a6:10:39d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.11; Tue, 7 Jul 2026 10:18:41 +0000 Received: from AMS1EPF00000045.eurprd04.prod.outlook.com (2603:10a6:20b:484:cafe::2e) by AS9PR06CA0756.outlook.office365.com (2603:10a6:20b:484::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.13 via Frontend Transport; Tue, 7 Jul 2026 10:18:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 4.158.2.129) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 4.158.2.129 as permitted sender) receiver=protection.outlook.com; client-ip=4.158.2.129; helo=outbound-uk1.az.dlp.m.darktrace.com; pr=C Received: from outbound-uk1.az.dlp.m.darktrace.com (4.158.2.129) by AMS1EPF00000045.mail.protection.outlook.com (10.167.16.42) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 7 Jul 2026 10:18:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=K97fvBMuIGTseqKZ7KZN3mUzTQktqPJww0yZ//5S2o54Q6NwDJQlk+l+jHj/YqKk240JdurA+SRXrggLXMVzjPTwA/NlwpIeNso7oMhCIf9NNwhRqUKXIMozSHGQjhBSF7XR2mWNeUEa7tzxVkS1+z7mbEb8/+N37TtjzOBECdwczqxJD8W40CkJkGWv+mUGNDz0d/zq9rx6p+Z707WBXJWar38oXAwTOqIyEDUcCK5BCrwaviBoVJXhcueqRu5uk9KjmylLsSfgjalM2Xns26ZvL5k/EGOV9OAINEvn01/syBdewHnKVoSP1yTfg6qEmZ7QXFDz/wvQimR9FaKiSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=EemIJVtWDHXX8KQyWS3ODPtGPloYcSFq4T4PV2y3TmQ=; b=SD0GL5UbKI02k16RNKMbgqLR/N63dHCfKibjzKdLv6L0HG1TD6lismCbo2Tb2NvQMEoWRPHit9lUvHTt0YaeyLYCF6MTsJ7CotWdyx46TwalcW2Z6abO3rP7IAndF4PdP8BkmjM3TEhN57YHvYsq4yEigUtuT+2R0OmyZf9TlKsmNpMnN3h1MltvENxXyj2b34iPg8znkaWsnVNoT9WuqKzyyeVmFaVpEqi24Hka94Vbx/RhoK81PBaWgsZ/NcA6qfKpEW/h/7NVhqIzGLjzMH+SseK2cOJ4VOxONL1rTPrTLI3+yNHsV3zpYF0To7OatgjMz2bgJLKZg75fGU298w== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arm.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EemIJVtWDHXX8KQyWS3ODPtGPloYcSFq4T4PV2y3TmQ=; b=DoMz4zmAI+8+XITEhZODxqJQc3TwcevLiBLXaFyGkTolJDwFAD8Csoru0lI3YdBfzI9/ljg2JjuCBCI6vp/Lk9MJHNKb2ZLkx+/zJcFD2pZ0viTfhi6o/y+hR9PwNYEwEhbj8puFXNof/pRKDriIuB1txAFCdY0k+95cEPYgJMs= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI0PR08MB10392.eurprd08.prod.outlook.com (2603:10a6:800:210::10) by DU2PR08MB9961.eurprd08.prod.outlook.com (2603:10a6:10:494::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.11; Tue, 7 Jul 2026 10:17:44 +0000 Received: from VI0PR08MB10392.eurprd08.prod.outlook.com ([fe80::cd7c:e19a:2072:75cc]) by VI0PR08MB10392.eurprd08.prod.outlook.com ([fe80::cd7c:e19a:2072:75cc%4]) with mapi id 15.21.0181.009; Tue, 7 Jul 2026 10:17:44 +0000 Date: Tue, 7 Jul 2026 11:17:42 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, Richard.Earnshaw@arm.com, ktkachov@gcc.gnu.org, alex.coplan@arm.com, andrew.pinski@oss.qualcomm.com, wilco.dijkstra@arm.com, alice.carlotti@arm.com, aldy@quesejoda.com, amacleod@redhat.com Subject: [patch]middle-end: Teach ranger about POLY_INT_CST ranges for VRP. Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO4P123CA0373.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18e::18) To VI0PR08MB10392.eurprd08.prod.outlook.com (2603:10a6:800:210::10) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI0PR08MB10392:EE_|DU2PR08MB9961:EE_|AMS1EPF00000045:EE_|DB9PR08MB7842:EE_ X-MS-Office365-Filtering-Correlation-Id: e95c7f97-8334-4be1-a4b0-08dedc111e02 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; ARA:13230040|366016|376014|23010399003|6049299003|1800799024|4053099003|18002099003|11063799006|56012099006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info-Original: iaCCz7g8gjXYcLJbRMQbmjzg8fB/hKcaabrxyFMZOCkzSkhcSiZtKmc2jHl9zQYNvjfYFKSo9Q2DXyN7BS10CUzBhtsl52nz/n0zGzz4Tvjj5vDdoEh3S0Wp0rSSuFpVLvdmcZY/JT5z61ZZtpd9RsPpPGGebh+5nO4fWRINfv+hw8/1/GCgtW2qDUjzDEz7TK0NF8mW7kRxBa8HT6+VfO8XH2qIZJ0J2uBi56XfuMXjl1ev3bBw93ROfNUkaAnMb8bU9UX/hJGpDqeaXDaJZvVGYfnXv2iePVUmKLuBReJu4mIOncFBJeubuuu8iN8UGYAcwTTOQHHgq6z6F1kINuWCf4ZZ16bNWm2HClNKZtLuR3oddgdSMkFr5vo0eqQMGfBw14etUYlbGTjsGifWvC1r8onNHpuRxE/TbKoIRfiQAi342AAQWy2UB4TPBsc2t2yB/DM7aurVe3Cp/w64WEhNfhsB1W0gGjd3IyVUT2eC3gCakdgTBdBMl+V1fUJkQImCsCKbpNdc+e8256XCvzQvuaL5+Pd13GyE7DIrDFhGrlWgGAY9hJhCA8hzaN4rsn2SYjN5W5wiIWKWJ8jrkbTyHXo3LzhaEcUyr231chzO9PtGNEAu8OvrW/NbZLui X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10392.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(23010399003)(6049299003)(1800799024)(4053099003)(18002099003)(11063799006)(56012099006)(6133799003)(3023799007); DIR:OUT; SFP:1101; X-Exchange-RoutingPolicyChecked: mYUysA92RqIdhw62AHVRkMY993IjOnN3N95dCkcimtkV1irJIPj+pe36TFuZEfUccgvdBPC3Y5vS4lxNedLBgfemuR+GV4EZdKjJAXkw9imNwEtqsQ28Ha3RQntoUeBUg1i5bA8lIuborLgLI172G8QQhYEJI/+hy4m5f1tC8f47v74CkFV464p/OHi9G75RTULLf9WVOhHs2isJ03XOtm7WcT74PFUT2B3ozDMF+cMUhA84/ugJhlrX1ZNQMUI1Q5QBNnyaVRLbBiXjIgChFHbqpDwxpP2Kw+10xBi8wZp/uP+QIsSA/PX7AsqeNuy9yb0ZyKwI43oAmnWfrapcnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB9961 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS1EPF00000045.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b25d152d-9446-4ac5-6035-08dedc10fc3d X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|1800799024|82310400026|376014|23010399003|35042699022|6049299003|14060799003|3023799007|56012099006|11063799006|18002099003|6133799003|13003099007|4053099003; X-Microsoft-Antispam-Message-Info: qPvuUDHRrVAbzmqRCKkm/3Mo0cM+wQGOLOYFlqXyg9zVdbJtBCdXrRZrK4mSNcbmNPc1WEOpXEPhGtCyuonfod2sQBH9Dd26xse8Uk5mJSVfIOB3tSqh2gmr8VCkNtjT48TT4d0MRLmlkPOgT2pzmp79ep5e48NCHDJXFwe8BxUK+ovXWNNcrbbiJ7n7tYO/Tcn2HUEMpLBf8RVUgwbpQcrN6jrxYKAJnk8FFM68NVNEWlqjepIboOVWgV6gy3zHq8ponQNMEI6J6Tjiol6miWVoOUaSaglk5NUbfWbIdUHU1TBAceYyTuO++OUXvpFVq3xaQoxcSfZXZcjum5cbXkB94+tKzWcjeZla1FJ7cTSZGnkYB0XpLC62OrJ+xVn1lOlEI9Tr43/9TNa/iO/nc0UiwC9MhXQgJc3AEJFdVjm0+9mCp9zhDc0WLedeNQ/IanEAeJUjpc7UU/QOOjOdrU2XpZ/u2nDC6KJCU5eo3zkEEQcCkhqWzoaSroT1M1TNF5wM4B9Gb/IDFsdER9sjEj0ewVL+9dJjNcPDb6C0n7eG4DiGIBW5bW8/UYXdJ4e4bU8DrBPqwU8MQBk75fUoASigHKv5zUHqFkRWkhc+RYZHHktlyWqdYOo9MC/maoSpyvLfSQezEA42343jIKfnfmkkU7OgXz+JR66ZnjY5DeM= X-Forefront-Antispam-Report: CIP:4.158.2.129; CTRY:GB; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:outbound-uk1.az.dlp.m.darktrace.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700016)(1800799024)(82310400026)(376014)(23010399003)(35042699022)(6049299003)(14060799003)(3023799007)(56012099006)(11063799006)(18002099003)(6133799003)(13003099007)(4053099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5TRbArJgixSR9jgmy4NgaTcLlz851pxLaIqfJeuS4MmBjhHJdMFJzTc2dts5Ui/Nyk/3LGcGAr6G3R5q73+eiCUUUz+WXmNOan7hXsRw7aIGS1FGBi9i8/aJXVuhZWdMe3spggX2r0WXyqgYPXuIRVkRRjEmmx2YgZmW/DMcfp6TXZHNioSR/CNOzlj76SnqGDFtiLp4p0Hgm1qGyISajOm3mq8I0Tu/s/+S7P7e24jrSAklZCLQ/TgpYIeGZmVGTNF7rIvYYSqU50ZAdMu2nxBRFIwiMod3Tpo5c2LPsbIM642QZEoCQxt92s4pCRSH3+wrRy5/EaMnhTZOK7dswY2HIehax+PsnoKxtoESxI+w07+1bMSiUvebqlti1u8yZl0alkznEUEihD69dYAXEbO1+syoCGDXkhxzFdBxVLSGGoFvIr4Gv948qGptIOrm X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2026 10:18:40.8219 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e95c7f97-8334-4be1-a4b0-08dedc111e02 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[4.158.2.129]; Helo=[outbound-uk1.az.dlp.m.darktrace.com] X-MS-Exchange-CrossTenant-AuthSource: AMS1EPF00000045.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB7842 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hopefully this isn't controversial :) A an area where LLVM generates much better code than GCC today is in optimization of VLA branches guarded by VLA constants. Normally in GIMPLE POLY_INT_CSTs have no upport and lower bound because well, they're poly. However SVE has defined minimum and maximum vector sizes in the architecture[1] and so for us we do have bounds on these constants. [1] https://developer.arm.com/documentation/102476/0101/Introducing-SVE Today LLVM optimizes these simple expressions #include int g (void) { unsigned int vl = svcntb (); return vl < 257; } int h (void) { return svcntw () <= 64; } away to g(): mov w0, #1 ret h(): mov w0, #1 ret which is right because both are always true for any SVE vector length. while GCC generates: g(): cntb x0 cmp w0, 257 cset w0, cc ret h(): cntw x0 cmp x0, 65 cset w0, cc ret This patch extends ranger with a target hook poly_int_cst_value_range which is different from the current costing only hooks used in the vectorizer because those hooks can't be relied upon for correctness. This new hook allows us specify the minimum and maximum bounds of a POLY_INT_CST and have ranger use it in range_query::get_tree_range. This gets GCC to fold away many known true or known false comparisons in codegen today and we generate much simpler loop pre-headers. I have kept the AArch64 parts in this patch to get some extra eyes on it, but will split them out on commit. Bootstrapped Regtested on aarch64-none-linux-gnu, arm-none-linux-gnueabihf, x86_64-pc-linux-gnu -m32, -m64 and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_poly_int_cst_value_range): New. (TARGET_POLY_INT_CST_VALUE_RANGE): Implement hook using it. * target.def (poly_int_cst_value_range): New. * doc/tm.texi.in: Document it. * doc/tm.texi: Regenerate. * targhooks.cc (default_poly_int_cst_value_range): New. * targhooks.h (default_poly_int_cst_value_range): New. * value-query.cc (range_query::get_tree_range): Use it. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/slp_12.c: Update testcases * gcc.target/aarch64/sve/cnt_fold_7.c: New test. * gcc.target/aarch64/sve/cnt_fold_7_run.c: New test. --- -- diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 72822ca621f52afee144bffa76bc75aac28adae1..7e12bb0e2c003b80008dd0f3c9fa304c7273ef39 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -31053,6 +31053,27 @@ aarch64_estimated_poly_value (poly_int64 val, return val.coeffs[0] + val.coeffs[1] * over_128 / 128; } +/* Implement TARGET_POLY_INT_CST_VALUE_RANGE. */ + +static bool +aarch64_poly_int_cst_value_range (poly_int64 val, HOST_WIDE_INT *min_val, + HOST_WIDE_INT *max_val) +{ + unsigned int const_vg; + if (aarch64_sve_vg.is_constant (&const_vg)) + { + *min_val = val.coeffs[0]; + *max_val = *min_val; + return true; + } + + *min_val = val.coeffs[0]; + *max_val = val.coeffs[0] + val.coeffs[1] * 15; + if (*min_val > *max_val) + std::swap (*min_val, *max_val); + return true; +} + /* Return true for types that could be supported as SIMD return or argument types. */ @@ -34370,6 +34391,9 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_ESTIMATED_POLY_VALUE #define TARGET_ESTIMATED_POLY_VALUE aarch64_estimated_poly_value +#undef TARGET_POLY_INT_CST_VALUE_RANGE +#define TARGET_POLY_INT_CST_VALUE_RANGE aarch64_poly_int_cst_value_range + #undef TARGET_ATTRIBUTE_TABLE #define TARGET_ATTRIBUTE_TABLE aarch64_attribute_table diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 6178db74d2fc5d14e8618ee655de05739cb3207c..bfb7e94cf163a75688e6f99473bad4864a57fb24 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -7509,6 +7509,14 @@ the @code{POLY_VALUE_MIN}, @code{POLY_VALUE_MAX} and implementation returns the lowest possible value of @var{val}. @end deftypefn +@deftypefn {Target Hook} bool TARGET_POLY_INT_CST_VALUE_RANGE (poly_int64 @var{val}, HOST_WIDE_INT *@var{min_val}, HOST_WIDE_INT *@var{max_val}) +Return true if the target can give a conservative inclusive range for +the runtime value of @var{val}, storing the lower bound in @var{min_val} +and the upper bound in @var{max_val}. This hook is used for correctness +rather than for costing, so the returned bounds must be safe for all +architecturally-valid runtime values. +@end deftypefn + @deftypefn {Target Hook} bool TARGET_AVOID_STORE_FORWARDING_P (vec, @var{rtx}, @var{int}, @var{bool}) Given a list of stores and a load instruction that reads from the location of the stores, this hook decides if it's profitable to emit additional code diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 0a97b0fa2e44014fa9e27d07a06d407a25e1ecc4..3aae8b2de9a3ecee41803a5dcba8f31b4af55b93 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -4812,6 +4812,8 @@ Define this macro if a non-short-circuit operation produced by @hook TARGET_ESTIMATED_POLY_VALUE +@hook TARGET_POLY_INT_CST_VALUE_RANGE + @hook TARGET_AVOID_STORE_FORWARDING_P @node Scheduling diff --git a/gcc/target.def b/gcc/target.def index 884fe1bd57e17b3ae92cd052a340f02a2559da31..aab20e89bb16fd9bb7d70d1c403268a65990a3e4 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4217,6 +4217,16 @@ implementation returns the lowest possible value of @var{val}.", HOST_WIDE_INT, (poly_int64 val, poly_value_estimate_kind kind), default_estimated_poly_value) +DEFHOOK +(poly_int_cst_value_range, + "Return true if the target can give a conservative inclusive range for\n\ +the runtime value of @var{val}, storing the lower bound in @var{min_val}\n\ +and the upper bound in @var{max_val}. This hook is used for correctness\n\ +rather than for costing, so the returned bounds must be safe for all\n\ +architecturally-valid runtime values.", + bool, (poly_int64 val, HOST_WIDE_INT *min_val, HOST_WIDE_INT *max_val), + default_poly_int_cst_value_range) + /* Permit speculative instructions in delay slots during delayed-branch scheduling. */ DEFHOOK diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc index 388f696c8aa1050edbbc7efbdb01db60d84b4fe0..71f6f769e50298e32434ee94e87a1f3a3dfeef69 100644 --- a/gcc/targhooks.cc +++ b/gcc/targhooks.cc @@ -2164,6 +2164,19 @@ default_estimated_poly_value (poly_int64 x, poly_value_estimate_kind) return x.coeffs[0]; } +/* The default implementation of TARGET_POLY_INT_CST_VALUE_RANGE. */ + +bool +default_poly_int_cst_value_range (poly_int64 x, HOST_WIDE_INT *min_val, + HOST_WIDE_INT *max_val) +{ + if (!x.is_constant (min_val)) + return false; + + *max_val = *min_val; + return true; +} + /* For hooks which use the MOVE_RATIO macro, this gives the legacy default behavior. SPEED_P is true if we are compiling for speed. */ diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 86de6ef8a699d72a36c665c697c89ca58314f3fe..90ebc1f514d47ca736c14a641c69ab94f968bb1b 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -246,6 +246,8 @@ extern int default_frame_allocation_cost (frame_cost_type, extern bool default_slow_unaligned_access (machine_mode, unsigned int); extern HOST_WIDE_INT default_estimated_poly_value (poly_int64, poly_value_estimate_kind); +extern bool default_poly_int_cst_value_range (poly_int64, HOST_WIDE_INT *, + HOST_WIDE_INT *); extern bool default_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT, unsigned int, diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7.c b/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7.c new file mode 100644 index 0000000000000000000000000000000000000000..d64933527da7e3e85f37dc231355eb4cd30a1422 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7.c @@ -0,0 +1,154 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include + +/* +** b_lt_257: +** mov w0, 1 +** ret +*/ +int +b_lt_257 (void) +{ + unsigned int vl = svcntb (); + + return vl < 257; +} + +/* +** h_ge_8: +** mov w0, 1 +** ret +*/ +int +h_ge_8 (void) +{ + return svcnth () >= 8; +} + +/* +** w_le_64: +** mov w0, 1 +** ret +*/ +int +w_le_64 (void) +{ + return svcntw () <= 64; +} + +/* +** d_gt_1: +** mov w0, 1 +** ret +*/ +int +d_gt_1 (void) +{ + return svcntd () > 1; +} + +/* +** b_ne_0: +** mov w0, 1 +** ret +*/ +int +b_ne_0 (void) +{ + return svcntb () != 0; +} + +/* +** b_le_15: +** mov w0, 0 +** ret +*/ +int +b_le_15 (void) +{ + return svcntb () <= 15; +} + +/* +** h_lt_8: +** mov w0, 0 +** ret +*/ +int +h_lt_8 (void) +{ + return svcnth () < 8; +} + +/* +** w_gt_64: +** mov w0, 0 +** ret +*/ +int +w_gt_64 (void) +{ + return svcntw () > 64; +} + +/* +** d_eq_0: +** mov w0, 0 +** ret +*/ +int +d_eq_0 (void) +{ + return svcntd () == 0; +} + +/* +** b_lt_256: +** cntb x0 +** cmp x0, 256 +** cset w0, cc +** ret +*/ +int +b_lt_256 (void) +{ + return svcntb () < 256; +} + +/* +** w_gt_4: +** cntw x0 +** cmp x0, 4 +** cset w0, hi +** ret +*/ +int +w_gt_4 (void) +{ + return svcntw () > 4; +} + +/* +** b_pat_all_lt_257: +** mov w0, 1 +** ret +*/ +int +b_pat_all_lt_257 (void) +{ + return svcntb_pat (SV_ALL) < 257; +} + +/* +** w_pat_all_le_64: +** mov w0, 1 +** ret +*/ +int +w_pat_all_le_64 (void) +{ + return svcntw_pat (SV_ALL) <= 64; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7_run.c b/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7_run.c new file mode 100644 index 0000000000000000000000000000000000000000..59217ab343ec03509bccc6d12098e6264adaa8b1 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_7_run.c @@ -0,0 +1,47 @@ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2" } */ + +#include + +#define CHECK(EXPR) \ + do \ + { \ + if (!(EXPR)) \ + __builtin_abort (); \ + } \ + while (0) + +int +main (void) +{ + unsigned int b = svcntb (); + unsigned int h = svcnth (); + unsigned int w = svcntw (); + unsigned int d = svcntd (); + + CHECK (b >= 16 && b <= 256); + CHECK (h >= 8 && h <= 128); + CHECK (w >= 4 && w <= 64); + CHECK (d >= 2 && d <= 32); + + CHECK (b < 257); + CHECK (h >= 8); + CHECK (w <= 64); + CHECK (d > 1); + CHECK (b != 0); + + CHECK (!(b <= 15)); + CHECK (!(h < 8)); + CHECK (!(w > 64)); + CHECK (!(d == 0)); + + CHECK ((svcntb () < 256) == (b < 256)); + CHECK ((svcntw () > 4) == (w > 4)); + + CHECK (svcntb_pat (SV_ALL) == b); + CHECK (svcntw_pat (SV_ALL) == w); + CHECK (svcntb_pat (SV_ALL) < 257); + CHECK (svcntw_pat (SV_ALL) <= 64); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/slp_12.c b/gcc/testsuite/gcc.target/aarch64/sve/slp_12.c index 0b9f8d9bdfaaf868ba0bd73ae83894c68e1613f8..0b1fef4d23a89b4fa46b45a2662924247eedce17 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/slp_12.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/slp_12.c @@ -47,14 +47,12 @@ TEST_ALL (VEC_PERM) /* We should use WHILEs for all accesses. */ /* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.b} 20 } } */ -/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.h} 20 } } */ -/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.s} 30 } } */ -/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.d} 30 } } */ +/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.h} 18 } } */ +/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.s} 24 } } */ +/* { dg-final { scan-assembler-times {\twhilelo\tp[0-7]\.d} 21 } } */ /* 6 for the 8-bit types and 2 for the 16-bit types. */ /* { dg-final { scan-assembler-times {\tuqdecb\t} 8 } } */ -/* 4 for the 16-bit types and 3 for the 32-bit types. */ -/* { dg-final { scan-assembler-times {\tuqdech\t} 7 } } */ -/* 6 for the 32-bit types and 3 for the 64-bit types. */ -/* { dg-final { scan-assembler-times {\tuqdecw\t} 9 } } */ -/* { dg-final { scan-assembler-times {\tuqdecd\t} 6 } } */ +/* { dg-final { scan-assembler-times {\tuqdech\t} 2 } } */ +/* { dg-final { scan-assembler-times {\tuqdecw\t} 3 } } */ +/* { dg-final { scan-assembler-not {\tuqdecd\t} } } */ diff --git a/gcc/value-query.cc b/gcc/value-query.cc index decf4e4d0ac0eddb2dd6657072bf7c62c2e2ed00..5ce7fac4caeddccd62b587d11b2174a1d0979bac 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "alloc-pool.h" #include "gimple-range.h" #include "value-range-storage.h" +#include "target.h" // range_query default methods. @@ -404,7 +405,20 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt, if (POLY_INT_CST_P (expr)) { unsigned int precision = TYPE_PRECISION (type); - r.set_varying (type); + HOST_WIDE_INT min_val, max_val; + if (tree_fits_poly_int64_p (expr) + && targetm.poly_int_cst_value_range (tree_to_poly_int64 (expr), + &min_val, &max_val)) + { + wide_int min = wi::shwi (min_val, precision); + wide_int max = wi::shwi (max_val, precision); + if (wi::le_p (min, max, TYPE_SIGN (type))) + as_a (r).set (type, min, max); + else + r.set_varying (type); + } + else + r.set_varying (type); r.update_bitmask ({ wi::zero (precision), get_nonzero_bits (expr) }); return true; }