From patchwork Tue Sep 17 11:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jovan Vukic X-Patchwork-Id: 1986397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rt-rk.com header.i=@rt-rk.com header.a=rsa-sha256 header.s=s2021 header.b=W72qMDXv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X7KH72WtXz1y1m for ; Tue, 17 Sep 2024 21:26:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DEAF3858C78 for ; Tue, 17 Sep 2024 11:26:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx07-0061a602.pphosted.com (mx07-0061a602.pphosted.com [143.55.144.161]) by sourceware.org (Postfix) with ESMTPS id F33CF3858D26; Tue, 17 Sep 2024 11:26:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F33CF3858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=rt-rk.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rt-rk.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F33CF3858D26 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=143.55.144.161 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1726572366; cv=pass; b=e7apn9czx+Ld8q/ybbbNiE0MvsLvKf5xBFCJ22BYFvo5ssAWZqwzKpG4Dy5YWC7UqfmfTBVI1oXMF3onvFFU8rTL/3JcZ2iE6NKwcBkNAvMvwTEbhFu7klwnWwjKBP0bj+1HByK36a85j6cFXOBf5bkokl0+bee/3J7HAZPPPWo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1726572366; c=relaxed/simple; bh=NTnTUKJ2U4Sh69nC4psxtCzd5/0n8TyukXBBWQTkwvI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=umgHqodWqLqIv8iIhbg0LiPJnUBqbLzBPuzW7jaeoCLvLwMHnnGMO8o7HNsKWTeRH+9ONOtEWFAuCqRlAo77s6o/MNmCE2uzw1ahe2Sb8+uVRRI4HO+r6lQHzQmAWhWf/Jgri9pxjw+q+pfFMLN2NvfYVAMAEqVZAe1Xxvb8jZY= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0278995.ppops.net [127.0.0.1]) by mx07-0061a602.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48H2j2Dk015117; Tue, 17 Sep 2024 11:26:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rt-rk.com; h=cc :content-type:date:from:message-id:mime-version:subject:to; s= s2021; bh=1qVkh7M2TGRLUIgn78BEHSd6BrJ8hx0k6/V3aalbgv4=; b=W72qMD Xv7Vs7gqMLY7GFjL20IlZfLRUGwGwRra+UcIR1zj3oKC9WhPowZ0K1RuPdE10hwV 9lk9m2iUZHw0pWbO6IyS0rLBt8LtKlTkJIgihKzeo9ihVr3mvy7+K9I/x6UJddyC 2Utq48cXTNv04GN+TuT/1HnEvHWrbIGaHs4h00ZzWlpOQZiT0Rd8AjWoJfODswZv 8tJauq3MbzL9ER1puqdXqcK1nBDB4LwjV8mLxT46GvTq7lw1c38ihhw9v5XgtThn EOzz6RvPSfoQQ+JkTV1hFa88ilyUqmDsX+sf0Y8Y9g2U5QKW0Cm8I/W2mndgDuKh H1gvYGeTN1aGdyzw== Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2104.outbound.protection.outlook.com [104.47.17.104]) by mx07-0061a602.pphosted.com (PPS) with ESMTPS id 41mykcm2yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Sep 2024 11:26:02 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gVQ6el/ofnHNr4NGdI/YpTxn52sKplLQeDjizKg7Pl9GHHSaVlOm+vlJJVUEEyMZhgKB9y7TExrW3HLUT2Yd09CRUVzo6flmtb5nyl6rUB+adjXPPO6fTJL2GnHP20LGRjdUUCVYx+xEIRGT92RX1ZQkS94JqQawp80sIjrUcPAX/bGS51E1qxM+5HdT+Qmn7jygI8Z1krUSOWHAuekotI9h53W8i6eE0DYxVJEKKO8HU7uSpwdBWkwgp06vqiGujS0VGu4Q6GD0p9tPAUU8N6oWWr0T3fcNmftggtDBznKyRqzgx//i7kEZwRzNSgTg0QiXTQI/ScHnzCoB6OiuQw== 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=1qVkh7M2TGRLUIgn78BEHSd6BrJ8hx0k6/V3aalbgv4=; b=W0QZqUdSvU4TP5dNi0K4KDQzX5z3JB5IbF6hm8GdViutHd9tUheLUmMwpKzrQXY1e88B8dKYUHS7Dq9SdiiIyUhaWAcyJ1FX0mK5zwH+9lrGOpr69vrgN3e8qR0TNFahtyvsl25x+/JL7mlB7IUqnjDxZ7QdI/XOAh5b//McNKqpwAsDfmeHt5R3QT/1X+Bulds+BGUjIUtxi4GayYZcA2wcXDq/T61q7tni/rxfYEVj6zpOj9leeiwY8+dathSva982hFzbeyRorgJbMZ3cr3ewgLPp65sLybXkH4KlpuXicHA4lQ4+y/rxYk31NobsSNiwOy0S+DrSpaTne0JEaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=rt-rk.com; dmarc=pass action=none header.from=rt-rk.com; dkim=pass header.d=rt-rk.com; arc=none Received: from DB9PR08MB6634.eurprd08.prod.outlook.com (2603:10a6:10:23f::5) by VI1PR08MB5519.eurprd08.prod.outlook.com (2603:10a6:803:133::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Tue, 17 Sep 2024 11:25:57 +0000 Received: from DB9PR08MB6634.eurprd08.prod.outlook.com ([fe80::3b98:f8f6:2fc8:a5a]) by DB9PR08MB6634.eurprd08.prod.outlook.com ([fe80::3b98:f8f6:2fc8:a5a%4]) with mapi id 15.20.7982.012; Tue, 17 Sep 2024 11:25:57 +0000 From: Jovan Vukic To: "gcc-patches@gcc.gnu.org" CC: Mile Davidovic , Dusan Stojkovic , "law@gcc.gnu.org" , "rdapp@gcc.gnu.org" Subject: [PATCH] RISC-V: Improve code generation for select of consecutive constants Thread-Topic: [PATCH] RISC-V: Improve code generation for select of consecutive constants Thread-Index: AQHbCPOkzsETWayIkkCtT1do+QmCpA== Date: Tue, 17 Sep 2024 11:25:56 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DB9PR08MB6634:EE_|VI1PR08MB5519:EE_ x-ms-office365-filtering-correlation-id: cd0bf2fe-f5c3-43a4-6b74-08dcd70b7fd4 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|366016|376014|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?HU5h/EYH6951P1Ll0cST4RFdvw?= =?iso-8859-1?q?7mVERSFUMsmb9Prss9R6QqYOCAGEzCcRW7YFQ9YviVAKksLKfPzfn6sHFCP+?= =?iso-8859-1?q?LikLilqYTmSgmszxv4LDjwNqZu3IFl1C1RDgueD14E55WrM4CfMzPrL4uN9d?= =?iso-8859-1?q?IYF4XONLAfvSixqBU2GgZbeRMvsLB4wk02na0SD2hp0QYQMnoM6YtIRhnQCo?= =?iso-8859-1?q?q8Ert+dbuyy/0tAp2Ni7YXlbmwNSGVfXs9N9VKXtuR/3ebDZxnQ6vytDvatP?= =?iso-8859-1?q?DB3bgll/p3jlge5+J8/xGQwkbi8R2zu9fxdYTnzfd2vxYXveTm1E8OotL7WU?= =?iso-8859-1?q?nNrJEkC2Kv2/GlDOj//0hPs0wmCCT6i7IUx9W2eJCNBnHE8BlPjOhjwgQ+Vm?= =?iso-8859-1?q?rdpaVVfcLl110OF/RCQLWx4At5ZKRbta/ONUp8Wt3sjwXzblymel9oNlKSw5?= =?iso-8859-1?q?sELarEy/UEzYapeuYFYJgGtQhZqgbF7R61ZKeaBZqIIdv2eDnOCdRpPopBwC?= =?iso-8859-1?q?iWG0RPSUH14Od6Pa1WRxH8YLDggs9lAqpfReOpBlLCbHVZaHMl6j2LTCeuRl?= =?iso-8859-1?q?IVla+Aw0DpeI1I4l1VTOB6M+NbIEwvF94IMtRDCXcq2s476z4qzoNH1/W8Ny?= =?iso-8859-1?q?M/4svVfjYnk9dhlaQHzTwTPuOlnGV6kGxswYRXXt4NUVLxQMK5TVhPtLLdrm?= =?iso-8859-1?q?hM6HVD6kjVwRUQbYi5Tkmnsv/QDwgkxPwwmBO2aFDQqUbdhOrvn6c2kpGfAY?= =?iso-8859-1?q?hkJTPPaKIyq9pUfUlpJPHd9Vp8iNSEh4c/PDH/9KbivYvDw1M0zinMgIO26k?= =?iso-8859-1?q?Zis6YzpTuU1qDLmaOnj+ydVQx9xLvhLtgitBLN5wHUi9+XjW3C3eTHvJh4AL?= =?iso-8859-1?q?q09uBoSE9CnMpBXw5/UY2Z9nNBLtB4juG1pQpngYXgCf4+P7anXmXk4SF1Sa?= =?iso-8859-1?q?1QjzZc6S3HsyaJsb9xmRPIxTuSHs4s6QES8igZNxBlRWNXehXehtb5V1DLg0?= =?iso-8859-1?q?ODt+WIUMAvPdEwMgg0R+SJ5uToQsk+kO3ekR4joZ1CbUM3la57axKP3K/F58?= =?iso-8859-1?q?Pf5AtB84b5GZBtS+ksdnSfhUe9/j0TvyA7Henb2+LlcFITUMZn+SS02EMbLo?= =?iso-8859-1?q?zq8+dm84Efd2gf3oQRhvX4DejPmp/+fDW3AnIjxpMzR3aTH+BXAYndEsEK6I?= =?iso-8859-1?q?I6XgFUvdsJz8iGWfb/uTghIgMK2tjTqad4XZZkANqx6/PW/tcpi6lanvsMVR?= =?iso-8859-1?q?+jncmPl2tTRk40Q9jhZqw2/vvdSgRp3EdUXKlUmswYqs7vNB/bzMx6TK+DbL?= =?iso-8859-1?q?J1qF3k75ngFdFn1ynOTt9pPkkLjMk86xM0r8KRwrPh1KN9rOjL9UJP0SMBfQ?= =?iso-8859-1?q?9lHe65pioxv67NH9PMuXkiTEqk0WRcLkfAaVYmb7U=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6634.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?EmgF4MbqXyNZn7jsx4Vlrg5?= =?iso-8859-1?q?r54MQI8oFdufYrSxiWNgc6H6JMg7k0OJsEJ9HW/xEIC/GtNGvXR1RUT24HET?= =?iso-8859-1?q?6/p3HTwKeFk4VXGTo2MNE9ozYnRTZo6wtFCGi3YxV+MgJ9Wef4hcJc6/qT+m?= =?iso-8859-1?q?Uis9vewPuzq5H00lP4MnhdPdheRFZbSgNLIq3XmFC3ABRwwnUxDwec6Vnfzf?= =?iso-8859-1?q?e5uKXc8Xxpk+MDEpXaR9k4aNentzlBdN72jwKW+hi+iUE5fjh6z7+pOLLlu0?= =?iso-8859-1?q?NDN7yfulzwx0HcZpk1xxIi7IKMGL8lhBQoTEP5BPAgzSTjUH/vFTlvTZqOKt?= =?iso-8859-1?q?l4NSpwBKnYTbA/dcO8GY4WUrCSl1sdA6gU+h201dhW6KUvinjQOi3yLGAJml?= =?iso-8859-1?q?UT3XTdQDXYnU6KaX2hARGnGtbzIsWNdLkkK+nByTw70FD50cmOJJOLl9Jxbm?= =?iso-8859-1?q?pX7XaecDu2MgchzH8tdNqpLMpzEtQqBEcB2D1X+dS55Y3dH13t3iHiJW+fTv?= =?iso-8859-1?q?sfvTkF885sPT5XN3jUDV3ju6eygImAZIFVKzrXrfWGpBR+i0Mu5y6AVvFz+3?= =?iso-8859-1?q?gXRtyhi5/xtdk1s7c/ls3zrW/MfIfN+EpgRvnWdzDRyDMxu5tm6Jsr/fQHpC?= =?iso-8859-1?q?03tBW0zf9z5R/hP7DF2NEcBIBQupbX9rGP9VRdGuoRZ1jXwbfsEsOemS0/U+?= =?iso-8859-1?q?s4+cz4PLe9mfpIRS4c/tJS0125dQWsjHt7Ft2FaRZnvV1oUV1dgX1Xc2Ol9e?= =?iso-8859-1?q?cur/wQ81n6wRYkJfOR1B97wB88t0YA57WCdXRPdWJQilqHKaqIjD7OrJPAz0?= =?iso-8859-1?q?sbUYgHSkJtloy/7WN8Rraqz4agK+xn4RPqxg3gIhoR79hYzirsOtcik4hIyi?= =?iso-8859-1?q?NubrzyHFGFMBNEqshm08w1RRZggdfAUyMBTrQLglhK2QnU2rulkBpgWY1oKY?= =?iso-8859-1?q?XhkEfB6gfrh5wOy0QS6516YD8hVqHisMZ30JPU38bU5XGlCxCMyT7lltLgIP?= =?iso-8859-1?q?4NXLMXfXJ0MNSEdtP9htGK8VbKCl3bMp3mH7RifOzTNzQdMppKhjEqZLIW4L?= =?iso-8859-1?q?cE7N4Qm/5umMhwt7rzQnV5E7RRHbTHGWNnz6ZOasexGIuIfts+JuGlUbEmNW?= =?iso-8859-1?q?jnh0K91Zmrh8pb0SuaUPtWGE99HRABbYUmoOcN3RCy0gUCG+5u58+l4Gl3YM?= =?iso-8859-1?q?myQUv0C68lj5pxAKAl3Lk0HSz1+GKHW+vGJjaWA9cZAi10LZ8Lvtsonx3bVo?= =?iso-8859-1?q?iMiJDPhqViVejYdBPeC8Ifi6bz8pubWjddAAXH6nVH09EzoKFhhUGrnIQOtb?= =?iso-8859-1?q?4xhHuy6NQmzxrjEOviOw57iNKPpxG/NrP8V6Ldz7EgTzVVpQ+/zOuV/mhx16?= =?iso-8859-1?q?OOacPCwBBnwHrxnAmsnan2Axc2iMe0Wx21HjT165oCBAkaXBf9uYiT6oM96c?= =?iso-8859-1?q?ghmUhP01fzoN480HIwj2nA2PCCTM/NsKkm7Mx9LyIrARki4DPpRJnaZ8MLSQ?= =?iso-8859-1?q?NXpI0+/Fdre/04shZAue5YjKbcSVga9DzNVLsY+TSnfAt4w7HKASDP0cvQOd?= =?iso-8859-1?q?oHTtlP0P2VkYeVVo6mOnXUXrtdIPuoonZir16Ug16jmIqcOftrH0gQKtGDfl?= =?iso-8859-1?q?NMEChASkjfnO+FLD6?= MIME-Version: 1.0 X-OriginatorOrg: rt-rk.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6634.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd0bf2fe-f5c3-43a4-6b74-08dcd70b7fd4 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Sep 2024 11:25:56.8928 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9bc3ed46-a3ca-43f0-b84e-9a557209a7df X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BWRY2E5hnunOCDKnXGh9zNaqNI9UTDQkMGVs1sho3oGLarvkRP7Hi7Ca+tgB25AfU0dqd4TmAhrcxsYbQLeFUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5519 X-Authority-Analysis: v=2.4 cv=FoBX/Hrq c=1 sm=1 tr=0 ts=66e9674a cx=c_pps a=0ThJW8spbyBE/SYkbaEOqw==:117 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=EaEq8P2WXUwA:10 a=bp5mhLeJ-vUA:10 a=wT45_P3iAAAA:8 a=jXuQHcAsHH7lK8CqaSQA:9 a=wPNLvfGTeEIA:10 a=q-XdOSkUppaEU6zizlkA:9 a=0bXxn9q0MV6snEgNplNhOjQmxlI=:19 a=m-Z_27IZkzAA:10 a=RJRP_u8kRGsxlTjV8B5_:22 X-Proofpoint-ORIG-GUID: MM4JF2GPIKjIExX5-8OByFCNmtcU8jqC X-Proofpoint-GUID: MM4JF2GPIKjIExX5-8OByFCNmtcU8jqC X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The patch optimizes code generated for comparisons of the form x > y ? 2 : 3 (x <= y ? 3 : 2) and x < y ? 2 : 3 (x >= y ? 3 : 2). For the following C code: long f1(long x, long y) { return (x > y) ? 2 : 3; } long f2(long x, long y) { return (x < y) ? 2 : 3; } Before the patch, the generated assembly is: f1(long, long): sgt a0, a0, a1 xori a0, a0, 1 addi a0, a0, 2 ret f2(long, long): slt a0, a0, a1 xori a0, a0, 1 addi a0, a0, 2 ret After the patch, the generated assembly is: f1(long, long): slt a0,a1,a0 xori a0,a0,3 ret f2(long, long): slt a0,a0,a1 xori a0,a0,3 ret If we only consider the first example, during the combine pass, it can match the "le:" pattern (x <= y), but that can only be replaced by the inverse operation x > y (y < x), which requires replacing the following addi instruction with an xori instruction as well, as proposed by the patch. Tested on both RV32 and RV64 with no regressions. 2024-09-17 Jovan Vukic PR target/108038 gcc/ChangeLog: * config/riscv/iterators.md (paired_lt): New code attributes. * config/riscv/riscv.md (*sle__xor): New pattern. (*sge__xor): New pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/slt-1.c: New test. CONFIDENTIALITY: The contents of this e-mail are confidential and intended only for the above addressee(s). If you are not the intended recipient, or the person responsible for delivering it to the intended recipient, copying or delivering it to anyone else or using it in any unauthorized manner is prohibited and may be unlawful. If you receive this e-mail by mistake, please notify the sender and the systems administrator at straymail@rt-rk.com immediately. --- gcc/config/riscv/iterators.md | 4 +++ gcc/config/riscv/riscv.md | 32 +++++++++++++++++++ gcc/testsuite/gcc.target/riscv/slt-1.c | 44 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/slt-1.c diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md index 2844cb02ff0..964d0f24f4c 100644 --- a/gcc/config/riscv/iterators.md +++ b/gcc/config/riscv/iterators.md @@ -234,6 +234,10 @@ (define_code_iterator any_lt [lt ltu]) (define_code_iterator any_le [le leu]) +(define_code_attr paired_lt [(gt "lt") (gtu "ltu") + (ge "lt") (geu "ltu") + (le "lt") (leu "ltu")]) + ; atomics code iterator (define_code_iterator any_atomic [plus ior xor and]) diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 9f94b5aa023..b22a8ac05e0 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -3600,6 +3600,38 @@ [(set_attr "type" "slt") (set_attr "mode" "")]) +(define_insn_and_split "*sle__xor" + [(set (match_operand:GPR 0 "register_operand" "=r") + (plus:GPR (any_le:GPR (match_operand:X 1 "register_operand" " r") + (match_operand:X 2 "register_operand" " r")) + (match_operand 3 "const_arith_operand" "i")))] + "INTVAL (operands[3]) % 2 == 0" + "#" + "&& 1" + [(set (match_dup 0) (:GPR (match_dup 2) (match_dup 1))) + (set (match_dup 0) (xor:GPR (match_dup 0) (match_dup 3)))] +{ + operands[3] = GEN_INT (INTVAL (operands[3]) + 1); +} + [(set_attr "type" "slt") + (set_attr "mode" "")]) + +(define_insn_and_split "*sge__xor" + [(set (match_operand:GPR 0 "register_operand" "=r") + (plus:GPR (any_ge:GPR (match_operand:X 1 "register_operand" " r") + (match_operand:X 2 "register_operand" " r")) + (match_operand 3 "const_arith_operand" "i")))] + "INTVAL (operands[3]) % 2 == 0" + "#" + "&& 1" + [(set (match_dup 0) (:GPR (match_dup 1) (match_dup 2))) + (set (match_dup 0) (xor:GPR (match_dup 0) (match_dup 3)))] +{ + operands[3] = GEN_INT (INTVAL (operands[3]) + 1); +} + [(set_attr "type" "slt") + (set_attr "mode" "")]) + ;; ;; .................... ;; diff --git a/gcc/testsuite/gcc.target/riscv/slt-1.c b/gcc/testsuite/gcc.target/riscv/slt-1.c new file mode 100644 index 00000000000..c672da92acf --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/slt-1.c @@ -0,0 +1,44 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64d" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +#include + +#define COMPARISON(TYPE, OP, OPN, RESULT_TRUE, RESULT_FALSE) \ + TYPE test##OPN(TYPE x, TYPE y) { \ + return (x OP y) ? RESULT_TRUE : RESULT_FALSE; \ + } + +/* Signed comparisons */ +COMPARISON(int64_t, >, GT1, 2, 3) +COMPARISON(int64_t, >, GT3, 5, 6) + +COMPARISON(int64_t, <, LT1, 2, 3) +COMPARISON(int64_t, <, LT3, 5, 6) + +COMPARISON(int64_t, >=, GE2, 3, 2) +COMPARISON(int64_t, >=, GE4, 6, 5) + +COMPARISON(int64_t, <=, LE2, 3, 2) +COMPARISON(int64_t, <=, LE4, 6, 5) + +/* Unsigned comparisons */ +COMPARISON(uint64_t, >, GTU1, 2, 3) +COMPARISON(uint64_t, >, GTU3, 5, 6) + +COMPARISON(uint64_t, <, LTU1, 2, 3) +COMPARISON(uint64_t, <, LTU3, 5, 6) + +COMPARISON(uint64_t, >=, GEU2, 3, 2) +COMPARISON(uint64_t, >=, GEU4, 6, 5) + +COMPARISON(uint64_t, <=, LEU2, 3, 2) +COMPARISON(uint64_t, <=, LEU4, 6, 5) + +/* { dg-final { scan-assembler-times "sgt\\t" 2 } } */ +/* { dg-final { scan-assembler-times "sgtu\\t" 2 } } */ +/* { dg-final { scan-assembler-times "slt\\t" 6 } } */ +/* { dg-final { scan-assembler-times "sltu\\t" 6 } } */ +/* { dg-final { scan-assembler-times "xori\\ta0,a0,1" 8 } } */ +/* { dg-final { scan-assembler-times "xori\\ta0,a0,3" 8 } } */ +