get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2232257/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2232257,
    "url": "http://patchwork.ozlabs.org/api/patches/2232257/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/1ea679dc-9e6f-4904-8455-ed688186d2bd@oss.qualcomm.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": "<1ea679dc-9e6f-4904-8455-ed688186d2bd@oss.qualcomm.com>",
    "list_archive_url": null,
    "date": "2026-05-04T04:18:34",
    "name": "[V2,to-be-committed,RISC-V,PR,rtl-optimization/124766] Simplify x + y == y into x == 0",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "3342786a0e51697505a1b3b0f8076c30853398d4",
    "submitter": {
        "id": 92310,
        "url": "http://patchwork.ozlabs.org/api/people/92310/?format=api",
        "name": "Jeffrey Law",
        "email": "jeffrey.law@oss.qualcomm.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/1ea679dc-9e6f-4904-8455-ed688186d2bd@oss.qualcomm.com/mbox/",
    "series": [
        {
            "id": 502611,
            "url": "http://patchwork.ozlabs.org/api/series/502611/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=502611",
            "date": "2026-05-04T04:18:34",
            "name": "[V2,to-be-committed,RISC-V,PR,rtl-optimization/124766] Simplify x + y == y into x == 0",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/502611/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2232257/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2232257/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=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=fQzL0Mi4;\n\tdkim=pass (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=OuUeWA3Z;\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=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=fQzL0Mi4;\n\tdkim=pass (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=OuUeWA3Z",
            "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 4g87gz0Czbz1yJ9\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 14:19:11 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id DD0214BAE7F2\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  4 May 2026 04:19:08 +0000 (GMT)",
            "from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 57BDB4B99F48\n for <gcc-patches@gcc.gnu.org>; Mon,  4 May 2026 04:18:39 +0000 (GMT)",
            "from pps.filterd (m0279871.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 6443nexN4035656\n for <gcc-patches@gcc.gnu.org>; Mon, 4 May 2026 04:18:38 GMT",
            "from mail-dl1-f71.google.com (mail-dl1-f71.google.com\n [74.125.82.71])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dw8uxm7ee-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Mon, 04 May 2026 04:18:38 +0000 (GMT)",
            "by mail-dl1-f71.google.com with SMTP id\n a92af1059eb24-12dfe12d285so4305968c88.0\n for <gcc-patches@gcc.gnu.org>; Sun, 03 May 2026 21:18:38 -0700 (PDT)",
            "from [172.31.0.17] ([136.38.201.137])\n by smtp.gmail.com with ESMTPSA id\n a92af1059eb24-12df827a73fsm12551214c88.1.2026.05.03.21.18.35\n for <gcc-patches@gcc.gnu.org>\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Sun, 03 May 2026 21:18:36 -0700 (PDT)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org DD0214BAE7F2",
            "OpenDKIM Filter v2.11.0 sourceware.org 57BDB4B99F48"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 57BDB4B99F48",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 57BDB4B99F48",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777868319; cv=none;\n b=uwY5s3qjSvk8ZH9kgeiykjvhWPfUE1YavwvyZxBF9siL42ecgZPwyQkZ4fu2VwUt3O6oSOxT3hDDtd4yb0KmtRuOzs37A+cVhTUykbDSjrfnCXWHY9e+6Xf36DE1Jy2/B/kAlAad8DBqGiM6GtqA1H80+sVKadalw6qnhWmyBew=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777868319; c=relaxed/simple;\n bh=ZcX5E0ii6z8yOqLdUoATUycCXFAICjdOqi9chFGv7kU=;\n h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From:\n Subject:To;\n b=GTHu8pyDwViHlQJ/4oKuod4M2Rl/YZ6Sk2zS/JrSn9/uR0XicRu6IIk6QudmOuPUsQP/vrTt2dtLytBtagHlOEY/q3yc5d00cy2BnQjbKMFhUjQgnAPBEOF2/OCBkMUNR1Zs5DXzVhc71FJ4Zks1cJMoDqXPgDKlgtqvNE/ULKY=",
        "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=g7qyIDNu0Ol2BS7J3xzZmbJ/wD08eAZaFlE6yFp5BPU=; b=fQ\n zL0Mi4UyEX8g1aKwmXMksiipXdi7eEWpgrA4zraB+maOIOxr3cyCTqGSVAa8v6JG\n 4HgDiyM3MhePfJ8YpW3i1QZAsxf2vCACa/WQx1GM5ueEjBqzYezlI3Sg2ty8Tu4+\n G8tPD6LCKgFWQ2v8CT6GRTxpHkWU+P9yVs+OQnMUfbMS+iPq1ooxKT0ntatoTx6x\n GwPKcufyr2Pz+irKn56tSR7zSqL+KcUEZOIslFw2mJuMOlE6WkJ/zQUT7WNLAIZM\n IsLr83rq1hJ41dDgY+lD5FXoKwxBnRIUbEmnCO75hzvkGOiMvXk+OX8FeA7N3UdW\n HkuIKC4qeqJLu86nbHhg==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1777868317; x=1778473117; darn=gcc.gnu.org;\n h=to:subject:from:content-language:user-agent:mime-version:date\n :message-id:from:to:cc:subject:date:message-id:reply-to;\n bh=g7qyIDNu0Ol2BS7J3xzZmbJ/wD08eAZaFlE6yFp5BPU=;\n b=OuUeWA3ZScU2746IEjJT/00U2yzlUrJ68SiOb0jCwltP03VFzAOpYbmkZsV9NPUtTO\n dBigJ95vS30zAryM/d1WK6zwuRXqKiwvv9Vrc+ozJ8BxrCudUGA3CRLso+ke/KbPnC91\n OcKpELHEZ4al30W9btQbpGgdTz/46TTdI+bI1qOP8XRDULLfOqWKA/V6D0xpyzXJEg/f\n u14kAGLjpIT+dd5+xyqn9LgKCVv9Dj1Du8fUlES+StnRa8oTJq8Zfl/ca3OeoUF/GsJb\n hPkx4I7nOVj8ecStP0zADVQym9VTCjFh7JDo0Do7i5nKjFdl03yav0cPF0277Hy7DXNY\n lwqQ=="
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777868317; x=1778473117;\n h=to:subject:from: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=g7qyIDNu0Ol2BS7J3xzZmbJ/wD08eAZaFlE6yFp5BPU=;\n b=GV2OS4YyPeVkes7bPGozMMVQGs08mDKUqY1/HJ+czPd6kwyCfgAJ5Uw3bIHxRanY+U\n syqIrnl7/ATWOfUfCoxqE4HQP/Q+Ytuj04PkZLY2nzmuoh18Ulq3PSVWHLDDh0iCLalX\n o8r0dmfb94t3iaRUmH6LYtniaPvIaEuzb9kKqxDflyPPIGFu3Wc9lOtTny777qVbWMQt\n LqL1+rOnvEk+R6NnnR5XVC6h/hXxizgIYfBQuGa0II8NNV4OKhgTPj86nrWVcw9gXB3n\n 2wF+EWlPMMMfIHhG4YAPbVhrE2FvQh7UvzwozstOAfr1aidcYqP5AN/+OgEfcnFkwbNq\n YN+A==",
        "X-Gm-Message-State": "AOJu0YzCqivyCpbe93orQWpfc69gXwP1ZZMcxVJ27HkgXzirihnix4bJ\n rp3uDXgFTHtnbMR4ilxt4Q/6pc7krk7UHIiJOQz0Q2X+x0VGBjVxUMUlowHOUtBylsodqn3/wZR\n VpfV3hX5maKR41w261M8CzvslOrwMC6kq8ti5GMrHhse1kteiQiRevXe9Z+w3B1DC1S52",
        "X-Gm-Gg": "AeBDietkPYHPOfuSItKCBZ2qjorFaOyJB9cgmOhyIXDjlxESq2ri9Gvra1yJXbQM8J2\n kbFmkA9qn/JVD85u1HArYOV+TeCYnnCCdM3JW5tMxAuyO8v9zBK/VWdG6Oyy3anDGIfNt9nMXo2\n AMfLoI326enYgn6giRW1NLWVM4lV/ymOftyV0u4imf3vVMocigeG8640EKtqRfyruiyIbxHdCjL\n v+gz8YF1L1o+9w5WTmXnZn85yDqMkLeU9F0cZSWC8ehMa7o24ngacEP1n56XDMXvMpNVXQ+O1qp\n O4J45OgwKGqY+JuvvrOswbHgGBPrDZm7yyXQ/8yNOSpm01pbhAKW3i50+sLQvRYf8P2FhuIp8Ax\n G30kHqijL3sP49WRcIKm1AZMKn4WJp/tKI9tWYePxxwQ1Y0FOpjF3l27A1Y4f",
        "X-Received": [
            "by 2002:a05:7022:608:b0:11a:4016:44a5 with SMTP id\n a92af1059eb24-12dfd825405mr3626991c88.24.1777868317255;\n Sun, 03 May 2026 21:18:37 -0700 (PDT)",
            "by 2002:a05:7022:608:b0:11a:4016:44a5 with SMTP id\n a92af1059eb24-12dfd825405mr3626981c88.24.1777868316577;\n Sun, 03 May 2026 21:18:36 -0700 (PDT)"
        ],
        "Content-Type": "multipart/mixed; boundary=\"------------AoOpgg6xLVHQghE0Op2NOmDW\"",
        "Message-ID": "<1ea679dc-9e6f-4904-8455-ed688186d2bd@oss.qualcomm.com>",
        "Date": "Sun, 3 May 2026 22:18:34 -0600",
        "MIME-Version": "1.0",
        "User-Agent": "Mozilla Thunderbird",
        "Content-Language": "en-US",
        "From": "Jeffrey Law <jeffrey.law@oss.qualcomm.com>",
        "Subject": "[V2][to-be-committed][RISC-V][PR rtl-optimization/124766] Simplify x\n + y == y into x == 0",
        "To": "'GCC Patches' <gcc-patches@gcc.gnu.org>",
        "X-Proofpoint-ORIG-GUID": "6q7rC3LS91AnQOFEYq7Ge7DSSO8ZpM99",
        "X-Authority-Analysis": "v=2.4 cv=QqxuG1yd c=1 sm=1 tr=0 ts=69f81e1e cx=c_pps\n a=JYo30EpNSr/tUYqK9jHPoA==:117 a=asGLMfRmzhnGNxaIYohjRg==:17\n a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=r77TgQKjGQsHNAKrUKIA:9\n a=Ys_nlTsfSoNbGBeoM8gA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10\n a=F22s-0fX0AYkUdlLRoYA:9 a=B2y7HmGcmWMA:10 a=Fk4IpSoW4aLDllm1B1p-:22",
        "X-Proofpoint-GUID": "6q7rC3LS91AnQOFEYq7Ge7DSSO8ZpM99",
        "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwNTA0MDA0MiBTYWx0ZWRfX3hKs8zrFc0Cn\n 5fue8j/qsUtvifks2TSaO4n1NA9rO0LDrGe2aNsuhkiIsWiEt3H2uWZsQNJcNQQc1fnKOVyT0hT\n iUhC2tYGobxJNH1cPUJ0fjKCaIEKasAyrozg3rZzYxoywlM/lrhaCIPn4qjStW4mmvpkwf2ahjO\n WQIE8AIcgSHywYgRW51g+9WijNkd9ziRjeHDe7MU8tgHkr+b4/xfd/ft6N/ig+dmsAbiuown8wf\n n/sDqd9P4UUrowMtqndbz/85s0/5IBNWTa2ibMExo04TNQEG/7FwyS3AGSeODnVLUjWiTJJ45x7\n k5CqPZAaK6jGct5ZWNQznJcnO0bs/CjyhC70nZtaOB496/3Kx1IDfCzdv5vzCZNKg5Yat+IekSB\n aW7sOXxEg6XfdNSkz2L/cMVT6HxDOYV7wpE7LWCRbFuWzFutyZIZRSrn/Z+ZeY1VQnhpcH4t9HV\n zRDWBJxbiOIiutoby5A==",
        "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-05-04_02,2026-04-30_02,2025-10-01_01",
        "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n impostorscore=0 bulkscore=0 suspectscore=0 clxscore=1015 phishscore=0\n priorityscore=1501 malwarescore=0 spamscore=0 adultscore=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-2605040042",
        "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": "So Richard S. noticed 3 issues in the V1 patch.  Specifically it should \nhave been using rtx_equal_p rather than just testing pointer equality.  \nThat's not a correctness issue, but could potentially allow the pattern \nto apply more often.\n\nSecond we should be checking for !side_effects_p on the operand we're \ndropping.  Easy to fix.\n\nFinally there was a const0_rtx use that should have been CONST0_RTX.  \nGiven how often I mention that one to others, I'm embarrassed I missed it.\n\nBootstrapped on x86 and retested on the various embedded platforms.  \nBootstraps on riscv platforms, aarch64, armv7 and sh4eb are in flight.\n\n--\n\nSo this is derived from S_regmatch in spec2017, so fairly hot.\n\n\n\nlong\nfrob (unsigned short *y, long z)\n{\n   long ret = (*y << 2) + z;\n   if (ret != z)\n     return 0;\n   return ret;\n}\n\nIt generates this code on riscv:\n\n\n         lhu     a5,0(a0)\n         sh2add  a5,a5,a1\n         sub     a1,a1,a5\n         czero.nez       a0,a5,a1\n         ret\n\nThat's not bad, but the sh2add and sub are not actually needed. This may \nlook familiar to a case Daniel was recently discussing, the major \ndifference are the types of the function args which I got wrong the \nfirst time I reduced this case.\n\nczero instructions check their condition for zero/nonzero status. So we \njust need to know if a1 has a zero/nonzero value at the czero \ninstruction.  So working backwards\n\na1 = a1 - a5                // sub instruction\na1 = a1 - ((a5 << 2) + a1)  // substitute from sh2add\na1 = a5 << 2                // a1 terms cancel out\n\nSo we just need the nonzero state of a5 << 2.  Now since a5 was set by \nthe lhu instruction, the upper 48 bits are already known zero, so \ncritically we know the upper 2 bits are zero. Meaning that we can just \ntest a5 as set by the lhu instruction for zero/nonzero.  The net is we \ncan generate this code instead:\n\n         lhu     a0,0(a0)\n         czero.nez       a0,a1,a0\n         ret\n\n\nIt's a small, but visible instruction count savings and likely a small \nperformance improvement on most designs.\n\nSo the trick to get there is a small simplify-rtx improvement. We just \nneed to simplify\n(eq/ne (plus (x) (y)) (y)) ->  (eq/ne (x) (0))\n\nAnd all the right things just happen.  Bootstrapped and regression \ntested on a variety of native platforms including x86, aarch64, riscv \nand tested across the various embedded targets in my tester.  I'll wait \nfor the RISC-V pre-commit CI tester to render a verdict before going \nforward.\n\nJeff\ncommit 13040879a85435edc05bef860cc8530f51a133b5\nAuthor: Jeff Law <jeffrey.law@oss.qualcomm.com>\nDate:   Sun May 3 22:10:59 2026 -0600\n\n    [V2][RISC-V][PR rtl-optimization/124766] Simplify x + y == y into x == 0\n    \n    So Richard S. noticed 3 issues in the V1 patch.  Specifically it should have\n    been using rtx_equal_p rather than just testing pointer equality.  That's not a\n    correctness issue, but could potentially allow the pattern to apply more often.\n    \n    Second we should be checking for !side_effects_p on the operand we're dropping.\n    Easy to fix.\n    \n    Finally there was a const0_rtx use that should have been CONST0_RTX.  Given how\n    often I mention that one to others, I'm embarrassed I missed it.\n    \n    Bootstrapped on x86 and retested on the various embedded platforms.  Bootstraps\n    on riscv platforms, aarch64, armv7 and sh4eb are in flight.\n    \n    --\n    \n    So this is derived from S_regmatch in spec2017, so fairly hot.\n    \n    long\n    frob (unsigned short *y, long z)\n    {\n      long ret = (*y << 2) + z;\n      if (ret != z)\n        return 0;\n      return ret;\n    }\n    \n    It generates this code on riscv:\n    \n            lhu     a5,0(a0)\n            sh2add  a5,a5,a1\n            sub     a1,a1,a5\n            czero.nez       a0,a5,a1\n            ret\n    \n    That's not bad, but the sh2add and sub are not actually needed. This may look\n    familiar to a case Daniel was recently discussing, the major difference are the\n    types of the function args which I got wrong the first time I reduced this\n    case.\n    \n    czero instructions check their condition for zero/nonzero status. So we just\n    need to know if a1 has a zero/nonzero value at the czero instruction.  So\n    working backwards:\n    \n    a1 = a1 - a5                // sub instruction\n    a1 = a1 - ((a5 << 2) + a1)  // substitute from sh2add\n    a1 = a5 << 2                // a1 terms cancel out\n    \n    So we just need the nonzero state of a5 << 2.  Now since a5 was set by the lhu\n    instruction, the upper 48 bits are already known zero, so critically we know\n    the upper 2 bits are zero. Meaning that we can just test a5 as set by the lhu\n    instruction for zero/nonzero.  The net is we can generate this code instead:\n    \n            lhu     a0,0(a0)\n            czero.nez       a0,a1,a0\n            ret\n    \n    It's a small, but visible instruction count savings and likely a small\n    performance improvement on most designs.\n    \n    So the trick to get there is a small simplify-rtx improvement. We just need to\n    simplify\n    (eq/ne (plus (x) (y)) (y)) ->  (eq/ne (x) (0))\n    \n    And all the right things just happen.  Bootstrapped and regression tested on a\n    variety of native platforms including x86, aarch64, riscv and tested across the\n    various embedded targets in my tester.  I'll wait for the RISC-V pre-commit CI\n    tester to render a verdict before going forward.\n    \n            PR rtl-optimization/124766\n    \n    gcc/\n    \n            * simplify-rtx.cc (simplify_context::simplify_relational_operation_1):\n            Simplify x + y == y constructs.\n    \n    gcc/testsuite/\n    \n            * gcc.target/riscv/pr124766.c: New test.",
    "diff": "diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc\nindex a87d91884df..bf625cdaf60 100644\n--- a/gcc/simplify-rtx.cc\n+++ b/gcc/simplify-rtx.cc\n@@ -6665,6 +6665,15 @@ simplify_context::simplify_relational_operation_1 (rtx_code code,\n       return simplify_gen_relational (code, mode, cmp_mode, x, tem);\n     }\n \n+  /* (eq/ne (plus (x) (y)) y) simplifies to (eq/ne x 0).  */\n+  if ((code == EQ || code == NE)\n+      && op0code == PLUS\n+      && rtx_equal_p (XEXP (op0, 1), op1)\n+      && !side_effects_p (op1)\n+      && (INTEGRAL_MODE_P (cmp_mode) || flag_unsafe_math_optimizations))\n+    return simplify_gen_relational (code, mode, cmp_mode,\n+\t\t\t\t    XEXP (op0, 0), CONST0_RTX (cmp_mode));\n+\n   /* (ne:SI (zero_extract:SI FOO (const_int 1) BAR) (const_int 0))) is\n      the same as (zero_extract:SI FOO (const_int 1) BAR).  */\n   scalar_int_mode int_mode, int_cmp_mode;\ndiff --git a/gcc/testsuite/gcc.target/riscv/pr124766.c b/gcc/testsuite/gcc.target/riscv/pr124766.c\nnew file mode 100644\nindex 00000000000..b16c31e8a9b\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/riscv/pr124766.c\n@@ -0,0 +1,17 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-march=rv64gcbv_zicond -mabi=lp64d\" { target rv64 } } */\n+/* { dg-options \"-march=rv32gcbv_zicond -mabi=ilp32\" { target rv32 } } */\n+/* { dg-skip-if \"\" { *-*-* } { \"-O0\" \"-Og\" } } */\n+\n+long\n+frob (unsigned short *y, long z)\n+{\n+  long ret = (*y << 2) + z;\n+  if (ret != z)\n+    return 0;\n+  return ret;\n+}\n+\n+/* { dg-final { scan-assembler-not \"sh2add\" } } */\n+/* { dg-final { scan-assembler-not \"sub\" } } */\n+\n",
    "prefixes": [
        "V2",
        "to-be-committed",
        "RISC-V",
        "PR",
        "rtl-optimization/124766"
    ]
}