{"id":2229702,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229702/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/62ef3eed-0fba-4400-bc4a-c7fe40189fe9@oss.qualcomm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","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},"msgid":"<62ef3eed-0fba-4400-bc4a-c7fe40189fe9@oss.qualcomm.com>","date":"2026-04-28T16:12:13","name":"[V2,to-be-committed,RISC-V,PR,target/124760] Promote SI to DI in some cases to encourage shNadd insns","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"84eb788e9bbac0099fd3dcc2d9f5c9564eebe8cd","submitter":{"id":92310,"url":"http://patchwork.ozlabs.org/api/1.1/people/92310/?format=json","name":"Jeffrey Law","email":"jeffrey.law@oss.qualcomm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/62ef3eed-0fba-4400-bc4a-c7fe40189fe9@oss.qualcomm.com/mbox/","series":[{"id":501893,"url":"http://patchwork.ozlabs.org/api/1.1/series/501893/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501893","date":"2026-04-28T16:12:13","name":"[V2,to-be-committed,RISC-V,PR,target/124760] Promote SI to DI in some cases to encourage shNadd insns","version":2,"mbox":"http://patchwork.ozlabs.org/series/501893/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229702/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229702/checks/","tags":{},"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=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=TzNQCKvG;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=HgAwM4eL;\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=fail reason=\"signature verification failed\" (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=TzNQCKvG;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=HgAwM4eL","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=205.220.180.131"],"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 4g4lpG3bf7z1yHv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 02:12:51 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 19F0E4BB8F6E\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 16:12:48 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 7BC974B9208D\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 16:12:18 +0000 (GMT)","from pps.filterd (m0279868.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63SFsZeL4070705\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 16:12:17 GMT","from mail-dl1-f70.google.com (mail-dl1-f70.google.com\n [74.125.82.70])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dtttjheu1-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 16:12:17 +0000 (GMT)","by mail-dl1-f70.google.com with SMTP id\n a92af1059eb24-12db37213daso20705929c88.1\n for <gcc-patches@gcc.gnu.org>; Tue, 28 Apr 2026 09:12:17 -0700 (PDT)","from [172.31.0.17] ([136.38.201.137])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2ed0a103542sm3349573eec.21.2026.04.28.09.12.14\n for <gcc-patches@gcc.gnu.org>\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Tue, 28 Apr 2026 09:12:14 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 19F0E4BB8F6E","OpenDKIM Filter v2.11.0 sourceware.org 7BC974B9208D"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 7BC974B9208D","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 7BC974B9208D","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777392738; cv=none;\n b=OqgQF1hWt++BJu9mYwPqQ9MMApKpFBKBCc4j+vkvnVpgLw4WIb89xLbhBM7Qhm6uUxoy5riER79YSAxGWoO7YQ7cMNQ4MZl44rafXAiHLRmQBpuURFJT7tvnBfM6xuy+QhdkugXD9n/dgNdbR1m4IlTlfGJ1hcqCYNiAYlwbf2k=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777392738; c=relaxed/simple;\n bh=DPQQgWby5Aq+1i7d4GtCV9JYByIUAyFRqchBFUW8TQ4=;\n h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:To:\n From:Subject;\n b=GOvDdHwQjCjcyn++ZOMPed+pezNRXDegwHGYH9+nPXVMdqFNYpJ7GO/E00JoFXdC+fnfhucVxceQ7ktTqDo1+sPyWU8KWWNrCjoIITKbA7cYES3pniAGXzF2UZeAwfMj7qwtjkLIch+W0m8T31g/PPMAizWQtvpNvvfqd1AWL4A=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n content-type:date:from:message-id:mime-version:subject:to; s=\n qcppdkim1; bh=r/GQZTsNLBlLcJfOt8a/VkRLuAk/zeucrssGu8PBgyM=; b=Tz\n NQCKvGGUiYtgN0cTz3YG3T5NbWP0wE+xAO2Az/lU53cOXbMoAp7oVSN/ysYRgNQP\n rYWvSwMVrL4fTvreaAHkep/jcodVuGaigsHphtUZDIImQ/ZEjhoGsmU2QETywYMC\n R42a0mcQdmyY1ijESRumnv76r0B6ANWAYquaKaRkNuPElvSRGsHqEEeVJBLjw1t3\n P0xfb6RI4S9XAaEnpXqcQcUt4anOwC0Lb2zNMBR5NdR8PB5+gFRW1/iRj5MJEyeL\n p48YamLjhexkNWzA7wDlnoUrI+hNV3tRd+7QO+CF+hQ35QCIrx1xhAfA1O+gfoGp\n 3HyJPfCLeOSGd589+QiA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1777392736; x=1777997536; darn=gcc.gnu.org;\n h=subject:from:to:content-language:user-agent:mime-version:date\n :message-id:from:to:cc:subject:date:message-id:reply-to;\n bh=r/GQZTsNLBlLcJfOt8a/VkRLuAk/zeucrssGu8PBgyM=;\n b=HgAwM4eLPwnK+lvVGwczB/AXHcNtZqkIU+rdxHxnmJDpBGY8e9Be18RIijuTK9I4pE\n RK8TdO6DqnAhFeUoP5ouFk284AZiM7Rb6DpiT+6yuOwFsOquNqQVUGpEE40ncRdyFB1r\n fhob6RaFMNHs6x5UeS+8oF0Ey5Fnjooxupg4UHHwE9iw77RLHujjnBpd1vrdB4rSHW6S\n QHAhfE/eczWVLWG59a3e2DbXFj5w6p2a54RRD2Tv16vncivRiORDGPGbcjUbFAQfQpM2\n hZxAVHiyAUWEiMr5xh4qbZH1iVHIpYi/+gecK9KQ5nNT8gcYZW+731A6E+eJu2fx/tP4\n qo0w=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777392736; x=1777997536;\n h=subject:from:to:content-language:user-agent:mime-version:date\n :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=r/GQZTsNLBlLcJfOt8a/VkRLuAk/zeucrssGu8PBgyM=;\n b=fayBOlnCi8fUfhwsUd0P6xCBkaFcJV+AvfrpTadC46b24c9M0L9fhBhlCgTS0oAf6U\n f/FYnT1Nms7KvaW4r9vVp3vZSZKs8Oe9gbWVVOB8XdfmNtkzwHibYQ0IpLjcgDWVPqR3\n lPR2NM39L8ITzRMdD0KHL1V7yM2CaUUfV1ePneJHwdzZ/11jLH0ly6Vvnrm7l7OkK6BD\n ukZ7I8Jm7NIj7MTTWIs1beJKiGmfMI6coPPMwx/iW9gKr8nRqgWibQRDhg+Vjn+FCvtN\n fL8YR/O/8ohI5DGbfEPW/g/JeDPEjk9vhyWR4SA8kSufv/ViOmWGBy6eu8hAHhuyrQUB\n tsrA==","X-Gm-Message-State":"AOJu0YwS1Tf5gehbK9X7OUQBubia/o7oI9F5wTbjWEv9lujNFYwVIlDB\n g0KDSkLqmDzFdyU6b+R2D0B665rVTTZJ82aRNEcfTn9BF7g/+4TwEwhV7vHIpZctNHadDlQDoSj\n t1MLqulIQuImtF+XjHofguRNEyXoLh/mr6n62Kf27PriGLIHEk/zAMCmDh72Yhp/1fJ7I","X-Gm-Gg":"AeBDies+L6GcFKnNrcfa1smY1toWXLDYYlnuaPE6/t7kSrTLBe9b7thMrnd6tKlMm2D\n AL8dCmu5xDl/1bIJ9E2kT3oxqzzyQnRQLu6+6nOKfncGN5amO6qxBBvSr/G+YB374LbL2CjVwpw\n 4ihiuj6MNhnqUCuqun9XbXTasVcv3Hh64oBxxokBtwdw2FaWIC4CkfntFzcR+9wph7v31umvVEc\n u9US2jEsz02aq46Y59ZfxZ67KB0VQskQnBo86rDgXl7E4gBRvC7HhB6kAjxFzGskA1LNGdqC4L5\n GcQQn+fRSDiAZTx5sQWQCfHEUGp5m1I6dVQUmZY1KnB/En7YpZ4RctAUB5nqfuVpqUSPepKq04v\n Dh4nGk3MNJzPirMIx8MUNWU6qxjyZyRErabX98MEgDy57V0b2OzHDPVJYm+bt","X-Received":["by 2002:a05:7022:ea26:b0:12d:de3e:52c1 with SMTP id\n a92af1059eb24-12dde3e5310mr1519776c88.37.1777392735873;\n Tue, 28 Apr 2026 09:12:15 -0700 (PDT)","by 2002:a05:7022:ea26:b0:12d:de3e:52c1 with SMTP id\n a92af1059eb24-12dde3e5310mr1519749c88.37.1777392734964;\n Tue, 28 Apr 2026 09:12:14 -0700 (PDT)"],"Content-Type":"multipart/mixed; boundary=\"------------BvpyJ4ZAdrB0GBBCj1zxEc77\"","Message-ID":"<62ef3eed-0fba-4400-bc4a-c7fe40189fe9@oss.qualcomm.com>","Date":"Tue, 28 Apr 2026 10:12:13 -0600","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Content-Language":"en-US","To":"'GCC Patches' <gcc-patches@gcc.gnu.org>","From":"Jeffrey Law <jeffrey.law@oss.qualcomm.com>","Subject":"[V2][to-be-committed][RISC-V][PR target/124760] Promote SI to DI in\n some cases to encourage shNadd insns","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDI4MDE1NSBTYWx0ZWRfXzpOeyAqUNrum\n jEIxpvVZX0l/bCUkhHDnHj+wgwDQafxdUagbIMIFeaqS4wKb9Uphp7DOMoyvi6nnCzw85I6waxB\n iV5ZjlUvJHRTHTf8CP6QhouAyL61er+QxSa46GTNvW58oEyfHMuLlGNiZs2iGYz/6j1K8ayllmi\n d3OZM8dzM70nXoy7zJAg8jNCJCFkNhQ+wkZ+vAOP1o+3tcG5e7VeatuNR/L03mOuy0L4NtQMOAk\n qQBa6/zC+yMjMM3W9+uMg3/tCZVeZgyTdVJ6KaxaaXqZH9GusyJDMamcjWbzVbG/u0fdhiLjRtA\n YTT6pKf0YvyTrZP6f91nlOpA2fk0laI6SAF/h3xvqS/JlX52l+qE83uA3IzKB10eRNkHoFcdP+Q\n 8nWjVVymCYuFJ9p9Q2lfe7Il4KxBBwhhb5M9w59ah7vgVfr1iSLW2wCDKgB97V6y0mbnUwli3mm\n xpS8SaHmpLP0kFr2XCw==","X-Authority-Analysis":"v=2.4 cv=TZKmcxQh c=1 sm=1 tr=0 ts=69f0dc61 cx=c_pps\n a=SvEPeNj+VMjHSW//kvnxuw==:117 a=asGLMfRmzhnGNxaIYohjRg==:17\n a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=r77TgQKjGQsHNAKrUKIA:9\n a=3zepaaOLL7rTLR81kakA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10\n a=hHoaQ_RVztWCwp0LMOMA:9 a=7DkWtjWK4BqEV9Rf:21 a=_W_S_7VecoQA:10\n a=-d7-HylfX6lhVPyK7WUA:9 a=B2y7HmGcmWMA:10 a=Kq8ClHjjuc5pcCNDwlU0:22","X-Proofpoint-GUID":"DbLfdk8-RATUlUKhZqyDz9arOHBrHJQ6","X-Proofpoint-ORIG-GUID":"DbLfdk8-RATUlUKhZqyDz9arOHBrHJQ6","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-28_05,2026-04-28_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n priorityscore=1501 spamscore=0 adultscore=0 phishscore=0 clxscore=1015\n suspectscore=0 bulkscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604280155","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":"No real changes.  Just posting a V2 to see if it'll get picked up by the \npre-commit tester.  Two patches (this being one of them) never started \ntesting yesterday.  No clue why and I haven't heard from Edwin on how to \ndebug the pre-commit tester state.\n\n--\n\n\nSo for this testcase:\n\n\nint foo (int t)\n  {\n    return 3 * t - 1;\n  }\n\nWe currently generate:\n\n\n     slliw    a5,a0,1\n     addw    a0,a5,a0\n     addiw    a0,a0,-1\n     ret\n\n\nIntuitively we can see we're doing a 32->64 sign extension at each step \nand we could drop the intermediate sign extensions.  In fact, not only \ncan we drop the intermediate sign extensions, we can safely \"promote\" \nthe intermediate operations from SI to DI with a final sign extending \nadd.  Conceptually that unlocks combining the first shift+add into a \nshNadd insn resulting in this code:\n\n     sh1add    a0, a0, a0\n     addiw    a0, a0, -1\n     ret\n\nThe patch, but not the testcase, has been in my tree for a while, so \nit's been through bootstrap & regression testing on the BPI and Pioneer \nas well as testing on riscv32-elf and riscv64-elf. Obviously I'll wait \nfor pre-commit CI to do its thing before pushing.\n\nJeff\nPR target/124760\ngcc/\n\t* config/riscv/bitmanip.md (SI->DI promoting shadd pattern): Promote\n\tintermediate SI ops to DI ops when there's a final extending op.\n\ngcc/testsuite\n\n\t* gcc.target/riscv/pr124760.c: New test.","diff":"diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md\nindex 45881994f3ad..4b896b792678 100644\n--- a/gcc/config/riscv/bitmanip.md\n+++ b/gcc/config/riscv/bitmanip.md\n@@ -1368,3 +1368,19 @@ (define_split\n    (set (match_dup 0) (zero_extract:X (match_dup 3)\n \t\t\t\t      (const_int 1)\n \t\t\t\t      (zero_extend:X (match_dup 2))))])\n+\n+(define_split\n+  [(set (match_operand:DI 0 \"register_operand\")\n+\t(sign_extend:DI (plus:SI (plus:SI (ashift:SI (match_operand:SI 1 \"register_operand\")\n+\t\t\t\t\t\t     (match_operand 2 \"imm123_operand\"))\n+\t\t\t\t\t  (match_operand:SI 3 \"register_operand\"))\n+\t\t\t\t (match_operand:SI 4 \"arith_operand\"))))\n+   (clobber (match_operand:DI 5 \"register_operand\"))]\n+  \"TARGET_64BIT && TARGET_ZBA\"\n+  [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))\n+   (set (match_dup 0) (sign_extend:DI (plus:SI (match_dup 6) (match_dup 4))))]\n+  {\n+    operands[1] = gen_lowpart (DImode, operands[1]);\n+    operands[3] = gen_lowpart (DImode, operands[3]);\n+    operands[6] = gen_lowpart (SImode, operands[5]);\n+  })\ndiff --git a/gcc/testsuite/gcc.target/riscv/pr124760.c b/gcc/testsuite/gcc.target/riscv/pr124760.c\nnew file mode 100644\nindex 000000000000..0c4768ff0474\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/riscv/pr124760.c\n@@ -0,0 +1,14 @@\n+/* { dg-do compile { target rv64 } } */\n+/* { dg-additional-options \"-march=rv64gcb_zicond -mabi=lp64d\" } */\n+/* { dg-skip-if \"\" { *-*-* } { \"-O0\" \"-Og\" \"-Os\" \"-Oz\" } } */\n+\n+\n+int foo (int t)\n+{\n+  return 3 * t - 1;\n+}\n+\n+/* { dg-final { scan-assembler-not \"slliw\\t\" } } */\n+/* { dg-final { scan-assembler-not \"addw\\t\" } } */\n+/* { dg-final { scan-assembler-times \"sh1add\\t\" 1 } } */\n+/* { dg-final { scan-assembler-times \"addiw\\t\" 1 } } */\n","prefixes":["V2","to-be-committed","RISC-V","PR","target/124760"]}