Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2196325/?format=api
{ "id": 2196325, "url": "http://patchwork.ozlabs.org/api/patches/2196325/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260213130600.20251-1-avinashd@linux.ibm.com/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api", "name": "GNU Compiler Collection", "link_name": "gcc", "list_id": "gcc-patches.gcc.gnu.org", "list_email": "gcc-patches@gcc.gnu.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260213130600.20251-1-avinashd@linux.ibm.com>", "list_archive_url": null, "date": "2026-02-13T13:06:00", "name": "rs6000: Add integer spaceship optab for power9 [PR106536]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "10fb53be5f343d67335d08840ea63e48256ca419", "submitter": { "id": 91453, "url": "http://patchwork.ozlabs.org/api/people/91453/?format=api", "name": "Avinash Jayakar", "email": "avinashd@linux.ibm.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260213130600.20251-1-avinashd@linux.ibm.com/mbox/", "series": [ { "id": 492092, "url": "http://patchwork.ozlabs.org/api/series/492092/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=492092", "date": "2026-02-13T13:06:00", "name": "rs6000: Add integer spaceship optab for power9 [PR106536]", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/492092/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2196325/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2196325/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256\n header.s=pp1 header.b=paRJyQUO;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256\n header.s=pp1 header.b=paRJyQUO", "sourceware.org;\n dmarc=none (p=none dis=none) header.from=linux.ibm.com", "sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=148.163.158.5" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fCCCR54KWz1xpl\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 14 Feb 2026 00:08:19 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id C42AD4B9DB70\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 13 Feb 2026 13:08:17 +0000 (GMT)", "from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n [148.163.158.5])\n by sourceware.org (Postfix) with ESMTPS id 926BB4BAD149;\n Fri, 13 Feb 2026 13:06:11 +0000 (GMT)", "from pps.filterd (m0356516.ppops.net [127.0.0.1])\n by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 61DANPRA328612; Fri, 13 Feb 2026 13:06:10 GMT", "from ppma11.dal12v.mail.ibm.com\n (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219])\n by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4c696v828p-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Fri, 13 Feb 2026 13:06:10 +0000 (GMT)", "from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1])\n by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id\n 61D9gcLH001833;\n Fri, 13 Feb 2026 13:06:09 GMT", "from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229])\n by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4c6je2ek5a-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Fri, 13 Feb 2026 13:06:09 +0000", "from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com\n [10.20.54.106])\n by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n 61DD65ix41484608\n (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK);\n Fri, 13 Feb 2026 13:06:05 GMT", "from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 5980120040;\n Fri, 13 Feb 2026 13:06:05 +0000 (GMT)", "from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 795F42004B;\n Fri, 13 Feb 2026 13:06:03 +0000 (GMT)", "from li-4c4c4544-0036-3810-8050-b5c04f423534.ibm.com.com (unknown\n [9.39.24.32]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP;\n Fri, 13 Feb 2026 13:06:03 +0000 (GMT)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org C42AD4B9DB70", "OpenDKIM Filter v2.11.0 sourceware.org 926BB4BAD149" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 926BB4BAD149", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 926BB4BAD149", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770987971; cv=none;\n b=MICurA27k7YuKtViMRKLD095LI1qIwyjbScDd84MrrQy1H8pca5bTRMRxo5v6U8PqUd3YQr6VoHKCZUyNiBAridaxyJbBjWfeg2JlMhRC5ucn9RDXX7/8DmOWwkNL29LJwTSgSvoPaD2Oqj1PvxgYrcSPaCuXC8ncII/TyBVfiA=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1770987971; c=relaxed/simple;\n bh=GHfetetToqIPMvXQxZ2FkDYORym93+HdT2+jzdiFDJA=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=LN6qWpPalj1292UPQOcv5we1KbrOn/s5BriIaf9gfsEpC0FxWWhWmpTGeGuSaggbB3FlUuzqZ0LcOP3sd68ezIP0q0LGc2xWe2xV3PqLn5ulLQmc6Q59bU3yZJcHwaKFd/z5EWVppwLYc4zdiEI4V2jZrnEo63g+pD5H41RfGyU=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc\n :content-transfer-encoding:date:from:message-id:mime-version\n :subject:to; s=pp1; bh=P0LBBDnq40T1SMADr9X06tcrAuipp1ZCmqr7iClQf\n n0=; b=paRJyQUObXWmxQRjUsbIZ0fcLWHsX80x+5tBbYVufPPcxmPwqnq/MJ4tz\n 7OgLuqjdms3YE/eR7F5SKochN8WWbbOCLGNeXk23sdeM0MVw5bcRCFI6TsFS4+BT\n 0eLBqWrkstvjsXJ0DE9DIskhwyvpqwwBJDUUmgDXy04VJbs41N/H98EIsnf0/Jkd\n +iBnSqFo965sPBrir4FB17DirMhQ/3PTO487wjt6FlrGClbklY4o/ZkOzil7xdtj\n zAyjGO+bxgigarQeKYirJav8lLoLuxZrtsMbgLUhehoUwKpQzuNYYWPeHLsx8goF\n oOSk0u42gGyU2U4/zE0ckc4DHgVhQ==", "From": "Avinash Jayakar <avinashd@linux.ibm.com>", "To": "gcc-patches@gcc.gnu.org", "Cc": "segher@kernel.crashing.org, jskumari@linux.ibm.com,\n meissner@linux.ibm.com,\n dje.gcc@gmail.com, linkw@gcc.gnu.org,\n Avinash Jayakar <avinashd@linux.ibm.com>", "Subject": "[PATCH] rs6000: Add integer spaceship optab for power9 [PR106536]", "Date": "Fri, 13 Feb 2026 18:36:00 +0530", "Message-ID": "<20260213130600.20251-1-avinashd@linux.ibm.com>", "X-Mailer": "git-send-email 2.51.0", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-TM-AS-GCONF": "00", "X-Proofpoint-Reinject": "loops=2 maxloops=12", "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjEzMDA5OCBTYWx0ZWRfXwHXLc5iDDTg3\n iW+rDeuFX+EZT0CjTNlljcCPcPYWeIYtyCfPyUSJUiLK4KrYnLnzGNea/tzpZXWpp/pNFCkAwaX\n 2iIBei1eTC6A2mQ/rj1rrCUye2dsq6uvrAoYliKTnC+TQvBXvY3dmvd0/DYnK9WLjZ3MVaq1t1P\n NoZ6oBZAbkuhA42DNqLXx8/hCbRjoWaafy6vl0nv5uacCzIcTNF3f3fv7+LnFx64QmHdLVdo7vV\n GjtJFuoNIalLCLVJiNcOSNkfCy6swuTl4nqBNDjmJqdTjdODguDu3JfzMHyUu3EFcvI7y65c7Rw\n nbM7uGFA8E36VOfMJikCV6KMt+Kd+7kxyOTic9qQr2dJD+XkFQL+qZf45yBwmgLXCd1QTNzcWcf\n Vz+MEHofDK/u4vdJRjUZrRGUE47b1kpPWo3rGW4Z/i0Sd9SuRbuOiocjpYWPyoePo/vd1YKuHvA\n UTKl9zcmnz94beXXu7g==", "X-Proofpoint-ORIG-GUID": "ha-8cbwk2_zRFByEtsb9C5oTc9Na-qsC", "X-Proofpoint-GUID": "f7mtgdwtzbSduezc1_DO1vZw2ZyY6xhQ", "X-Authority-Analysis": "v=2.4 cv=O+Y0fR9W c=1 sm=1 tr=0 ts=698f21c2 cx=c_pps\n a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17\n a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22\n a=GgsMoib0sEa3-_RKJdDe:22 a=VnNF1IyMAAAA:8 a=cm5T32IN8EA0UPwti-0A:9", "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-02-13_02,2026-02-12_03,2025-10-01_01", "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n lowpriorityscore=0 priorityscore=1501 phishscore=0 adultscore=0\n malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1015 spamscore=0\n suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc=\n route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602130098", "X-BeenThere": "gcc-patches@gcc.gnu.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>", "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>", "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>", "List-Post": "<mailto:gcc-patches@gcc.gnu.org>", "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>", "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>", "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org" }, "content": "Hi,\n\nFollowing is a patch proposed to fix PR106536. Investigating it, I found\nthat rs6000 backend did not implement the spaceship operator. So this\npatch implements that for power9+.\n\nBootstrapped and regtested on powerpc64le-linux-gnu with no regressions.\nOk for trunk?\n\nThe other issue from this PR seen was certain patterns like\n(a > b ? 1 : (a < b ? -1 : 0))\nwhich is another variant of spaceship operator were not optimized.\nProbably it has to be canonicalized in match.pd or in the\noptimize_spaceship function.\n\nThanks and regards,\nAvinash Jayakar\n\nThe spaceship optab was missing in rs6000 backend, which could be easily\ndone with setb insn in Power ISA 3.0.\nThis patch adds support for the integer spaceship optab in power9.\nSimple code sequences like\n(x == y) ? 0 : (x < y ? -1 : 1)\ncould be easily done using following insns (only unsigned long shown\nhere):\n\tcmpld 0,3,4\n\tsetb 3,0\nAlso improves code generated for <=> operator introduced in C++20.\n\n2026-02-13 Avinash Jayakar <avinashd@linux.ibm.com>\n\ngcc/ChangeLog:\n\tPR target/106536\n * config/rs6000/rs6000.md (spaceship<mode>4): Add new optab\n\timplementation.\n\ngcc/testsuite/ChangeLog:\n\tPR target/106536\n * gcc.target/powerpc/spaceship-int-p9.c: New test.\n---\n gcc/config/rs6000/rs6000.md | 62 +++++++++++++++++++\n .../gcc.target/powerpc/spaceship-int-p9.c | 34 ++++++++++\n 2 files changed, 96 insertions(+)\n create mode 100644 gcc/testsuite/gcc.target/powerpc/spaceship-int-p9.c", "diff": "diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md\nindex 3089551552c..5f839c49e5f 100644\n--- a/gcc/config/rs6000/rs6000.md\n+++ b/gcc/config/rs6000/rs6000.md\n@@ -15724,6 +15724,68 @@ (define_insn \"setb_unsigned\"\n \"setb %0,%1\"\n [(set_attr \"type\" \"logical\")])\n \n+\n+;; Spaceship operator support for PowerPC\n+;; Implements three-way comparison: (a <=> b)\n+;; Returns: -1 if a < b, 0 if a == b, 1 if a > b\n+\n+(define_mode_iterator SPACESHIP_INT [DI SI HI QI])\n+;; Integer spaceship operator\n+(define_expand \"spaceship<mode>4\"\n+ [(match_operand:SI 0 \"gpc_reg_operand\")\n+ (match_operand:SPACESHIP_INT 1 \"gpc_reg_operand\")\n+ (match_operand:SPACESHIP_INT 2 \"gpc_reg_operand\")\n+ (match_operand:SI 3 \"const_int_operand\")]\n+ \"TARGET_P9_MISC\"\n+{\n+ bool is_unsigned = (operands[3] == const1_rtx);\n+\n+ // Power9+: Use setb instruction for efficient three-way comparison\n+ rtx cc_reg = gen_reg_rtx (is_unsigned ? CCUNSmode : CCmode);\n+ rtx op1, op2;\n+\n+ /* PowerPC only has SI/DI mode comparisons.\n+ For HI/QI modes, we need to extend to SImode first. */\n+ if (<MODE>mode == QImode || <MODE>mode == HImode)\n+ {\n+ // Extend to SImode for comparison\n+ if (is_unsigned)\n+\t{\n+\t op1 = gen_reg_rtx (SImode);\n+\t op2 = gen_reg_rtx (SImode);\n+\t emit_insn (gen_rtx_SET (op1,\n+\t\t\t\t gen_rtx_ZERO_EXTEND (SImode, operands[1])));\n+\t emit_insn (gen_rtx_SET (op2,\n+\t\t\t\t gen_rtx_ZERO_EXTEND (SImode, operands[2])));\n+\t}\n+ else\n+\t{\n+\t op1 = gen_reg_rtx (SImode);\n+\t op2 = gen_reg_rtx (SImode);\n+\t emit_insn (gen_rtx_SET (op1,\n+\t\t\t\t gen_rtx_SIGN_EXTEND (SImode, operands[1])));\n+\t emit_insn (gen_rtx_SET (op2,\n+\t\t\t\t gen_rtx_SIGN_EXTEND (SImode, operands[2])));\n+\t}\n+ }\n+ else\n+ {\n+ // For SI/DI modes, use directly\n+ op1 = operands[1];\n+ op2 = operands[2];\n+ }\n+\n+ emit_insn (gen_rtx_SET (cc_reg,\n+\t\t\t gen_rtx_COMPARE (GET_MODE (cc_reg), op1, op2)));\n+\n+ if (is_unsigned)\n+ emit_insn (gen_setb_unsigned (operands[0], cc_reg));\n+ else\n+ emit_insn (gen_setb_signed (operands[0], cc_reg));\n+\n+ DONE;\n+})\n+\n ;; Test byte within two ranges.\n ;;\n ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx\ndiff --git a/gcc/testsuite/gcc.target/powerpc/spaceship-int-p9.c b/gcc/testsuite/gcc.target/powerpc/spaceship-int-p9.c\nnew file mode 100644\nindex 00000000000..45192fa7918\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/powerpc/spaceship-int-p9.c\n@@ -0,0 +1,34 @@\n+/* { dg-do compile { target powerpc-*-*-* } } */\n+/* { dg-options \"-O2 -mdejagnu-cpu=power9 -fdump-tree-optimized\" } */\n+\n+/* Check if spaceship optimization was done. */\n+/* { dg-final { scan-tree-dump-times {\\.SPACESHIP \\([^,]+, [^,]+, -1\\)} 4 optimized } } */\n+/* { dg-final { scan-tree-dump-times {\\.SPACESHIP \\([^,]+, [^,]+, 1\\)} 5 optimized } } */\n+\n+/* cmplw is generated for uchar, char, ushort and uint*/\n+/* { dg-final { scan-assembler-times \"cmplw\" 4 } } */\n+/* cmpw is generated for schar, sshort and int*/\n+/* { dg-final { scan-assembler-times \"cmpw\" 3 } } */\n+\n+/* cmpld and cmpd generated for ulong and slong respectively. */\n+/* { dg-final { scan-assembler-times \"cmpld\" 1 } } */\n+/* { dg-final { scan-assembler-times \"cmpd\" 1 } } */\n+\n+#define TEST(T, U)\t\t\\\n+ int test_##U (T x, T y)\t\\\n+ {\t\t\t\t\\\n+ return (x == y) ? 0 : (x < y ? -1 : 1); \\\n+ }\n+\n+TEST(signed char, schar)\n+TEST(unsigned char, uchar)\n+TEST(char, char)\n+\n+TEST(short, sshort)\n+TEST(unsigned short, ushort)\n+\n+TEST(int, sint)\n+TEST(unsigned int, uint)\n+\n+TEST(long, slong)\n+TEST(unsigned long, ulong)\n\\ No newline at end of file\n", "prefixes": [] }