Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2221644/?format=api
{ "id": 2221644, "url": "http://patchwork.ozlabs.org/api/patches/2221644/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260410030022.10318-1-garthlei@linux.alibaba.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": "<20260410030022.10318-1-garthlei@linux.alibaba.com>", "list_archive_url": null, "date": "2026-04-10T03:00:22", "name": "[v4] simplify-rtx: Simplify (cmp (and/ior x C1) C2)", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "affe4c032c1441bade8929d4dacd8dd99dac0786", "submitter": { "id": 89310, "url": "http://patchwork.ozlabs.org/api/people/89310/?format=api", "name": "Bohan Lei", "email": "garthlei@linux.alibaba.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260410030022.10318-1-garthlei@linux.alibaba.com/mbox/", "series": [ { "id": 499382, "url": "http://patchwork.ozlabs.org/api/series/499382/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=499382", "date": "2026-04-10T03:00:22", "name": "[v4] simplify-rtx: Simplify (cmp (and/ior x C1) C2)", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/499382/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2221644/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2221644/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 (1024-bit key;\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=Kv3dTlUT;\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 (1024-bit key,\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=Kv3dTlUT", "sourceware.org; dmarc=pass (p=none dis=none)\n header.from=linux.alibaba.com", "sourceware.org;\n spf=pass smtp.mailfrom=linux.alibaba.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=115.124.30.124" ], "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 4fsM5J6bx0z1yGb\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 13:01:23 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id DC2BD4BA2E15\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 03:01:21 +0000 (GMT)", "from out30-124.freemail.mail.aliyun.com\n (out30-124.freemail.mail.aliyun.com [115.124.30.124])\n by sourceware.org (Postfix) with ESMTPS id 9AB664BA2E0A\n for <gcc-patches@gcc.gnu.org>; Fri, 10 Apr 2026 03:00:53 +0000 (GMT)", "from localhost(mailfrom:garthlei@linux.alibaba.com\n fp:SMTPD_---0X0jt0YT_1775790041 cluster:ay36) by smtp.aliyun-inc.com;\n Fri, 10 Apr 2026 11:00:49 +0800" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org DC2BD4BA2E15", "OpenDKIM Filter v2.11.0 sourceware.org 9AB664BA2E0A" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 9AB664BA2E0A", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 9AB664BA2E0A", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775790054; cv=none;\n b=sMDw3ZgIqrtbuOtH7ZoRIdpDnX8lK1E2HcHwcL00QOcLfVuwxbJZGDO64BY/8/pwkS8hQf2jL45TnJ4DOlBB8ZsJPM3BK5Hj4e2pZrh8QS8eQosujRK9l/i/lbSmQTUEjeGP1YMvgu3DyZyCvaCtHnIueSRWKBVApR++tt41zko=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775790054; c=relaxed/simple;\n bh=G1ew3rSGfD3s8RocJa3gDNmpQPwnxiUFZ1yVsgnhqWU=;\n h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version;\n b=F0YhpAipQjJ7ElpZW03uvFpPiEVCqvI9uyPy6kwSXxnEbvAhHsJu3WM481WXT+J1APru5RH8qU9BTK/4lsiYbFpaka6EzuYoj+tT8437XDpejbDKTg/DIm/feH4cfC+ra198j2GBCMix6BghXGFpHlzjtfWduvef23ve+uUjlSg=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linux.alibaba.com; s=default;\n t=1775790051; h=From:To:Subject:Date:Message-Id:MIME-Version;\n bh=j1qJQQAp3Wv1hs1F6MkdClgIXUIctM9zKSb7iuZOC+s=;\n b=Kv3dTlUTWbSEtACMZuxD3yQCYc/89Le4C05dUZqTiVu4yrLrqgtVhX0RyNatsTkcaBeaF3Pr+xl80jOZfDKf8g4pdKFIuWhppmj1HxmTpe4/xwIZkvGN9utpCp9OjTfYTcnUB5E8W4xSB0ivr2t0uedCDE0elR5SUqg17rLwrNA=", "X-Alimail-AntiSpam": "AC=PASS; BC=-1|-1; BR=01201311R831e4; CH=green;\n DM=||false|;\n DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam011083073210;\n MF=garthlei@linux.alibaba.com; NM=1; PH=DS; RN=5; SR=0;\n TI=SMTPD_---0X0jt0YT_1775790041;", "From": "Bohan Lei <garthlei@linux.alibaba.com>", "To": "gcc-patches@gcc.gnu.org", "Cc": "jeffrey.law@oss.qualcomm.com, philipp.tomsich@vrull.eu,\n andrew.pinski@oss.qualcomm.com, Bohan Lei <garthlei@linux.alibaba.com>", "Subject": "[PATCH v4] simplify-rtx: Simplify (cmp (and/ior x C1) C2)", "Date": "Fri, 10 Apr 2026 11:00:22 +0800", "Message-Id": "<20260410030022.10318-1-garthlei@linux.alibaba.com>", "X-Mailer": "git-send-email 2.39.3 (Apple Git-146)", "In-Reply-To": "\n <CALvbMcBVoAu9C=KRhKxaKimzTc+s_3rnDE8a38aF_-WRw5JCiw@mail.gmail.com>", "References": "\n <CALvbMcBVoAu9C=KRhKxaKimzTc+s_3rnDE8a38aF_-WRw5JCiw@mail.gmail.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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": "This is v4 of\nhttps://gcc.gnu.org/pipermail/gcc-patches/2026-March/711809.html, fixed\nand enhanced as was suggested by Philipp and Andrew. The previous\nversion:\nhttps://gcc.gnu.org/pipermail/gcc-patches/2026-April/712444.html.\n\nThis patch adds missing simplifications for (cmp (and/ior x C1) C2) in\nspecial cases. In the AND case, when (and C1 C2) is not equal to C1,\nsome bits set in C2 are not set in C1, and thus (eq (and x C1) C2) can\nnever be true. The OR case is similar when (and C1 C2) is not equal to\nC2. As we know that the result of (and x C1) cannot be greater than C1,\nand that that of (or x C1) cannot be less than C1 for unsigned integers,\nLTU, LEU, GTU, GEU cases can be optimized, too.\n\nThe patch is meant to fix an ICE on RISC-V. In a former patch, I tried\nto change the insn condition directly, but Jeff pointed out that it was\nmore reasonable to optimize it out before the split. As was suggested\nby Jeff, this patch tries to simplify the expression in\nsimplify_relational_operation_1.\n\nThe URL for the former patch:\nhttps://patchwork.sourceware.org/project/gcc/patch/20251229024238.15044-1-garthlei@linux.alibaba.com/\n\ngcc/ChangeLog:\n\n\t* simplify-rtx.cc (simplify_context::simplify_relational_operation_1):\n\tAdd simplifications for `(cmp (and/ior x C1) C2)`.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.target/riscv/zbs-if_then_else-02.c: New test.\n---\n gcc/simplify-rtx.cc | 45 +++++++++++++++++++\n .../gcc.target/riscv/zbs-if_then_else-02.c | 32 +++++++++++++\n 2 files changed, 77 insertions(+)\n create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-if_then_else-02.c", "diff": "diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc\nindex 50fc51152ca..f4ad80dd0e5 100644\n--- a/gcc/simplify-rtx.cc\n+++ b/gcc/simplify-rtx.cc\n@@ -6731,6 +6731,51 @@ simplify_context::simplify_relational_operation_1 (rtx_code code,\n \t}\n }\n \n+ /* Optimize (cmp (and/ior x C1) C2) depending on the CMP and C1 and C2's\n+ relationship. */\n+ if ((op0code == AND || op0code == IOR)\n+ && CONST_INT_P (op1)\n+ && CONST_INT_P (XEXP (op0, 1)))\n+ {\n+ unsigned HOST_WIDE_INT c1 = UINTVAL (XEXP (op0, 1));\n+ unsigned HOST_WIDE_INT c2 = UINTVAL (op1);\n+\n+ /* For AND operations:\n+\t - (x & c1) == c2 when some bits are set in c2 but not in c1 -> false\n+\t - (x & c1) != c2 when some bits are set in c2 but not in c1 -> true\n+\t - (x & c1) >= c2 when c1 is less than c2 -> false\n+\t - (x & c1) < c2 when c1 is less than c2 -> true\n+\t - (x & c1) > c2 when c1 is less than or equal to c2 -> false\n+\t - (x & c1) <= c2 when c1 is less than or equal to c2 -> true\n+\t \n+\t For IOR operations:\n+\t - (x | c1) == c2 when some bits are set in c1 but not in c2 -> false\n+\t - (x | c1) != c2 when some bits are set in c1 but not in c2 -> true\n+\t - (x | c1) <= c2 when c1 is greater than c2 -> false\n+\t - (x | c1) > c2 when c1 is greater than c2 -> true\n+\t - (x | c1) < c2 when c1 is greater than or equal to c2 -> false\n+\t - (x | c1) >= c2 when c1 is greater than or equal to c2 -> true */\n+ if ((op0code == AND\n+\t && ((code == EQ && (c1 & c2) != c2)\n+\t || (code == GEU && c1 < c2)\n+\t || (code == GTU && c1 <= c2)))\n+\t || ((op0code == IOR\n+\t && ((code == EQ && (c1 & c2) != c1)\n+\t\t || (code == LEU && c1 > c2)\n+\t\t || (code == LTU && c1 >= c2)))))\n+\treturn const0_rtx;\n+\n+ if ((op0code == AND\n+\t && ((code == NE && (c1 & c2) != c2)\n+\t || (code == LTU && c1 < c2)\n+\t || (code == LEU && c1 <= c2)))\n+\t || ((op0code == IOR\n+\t && ((code == NE && (c1 & c2) != c1)\n+\t\t || (code == GTU && c1 > c2)\n+\t\t || (code == GEU && c1 >= c2)))))\n+\treturn const_true_rtx;\n+ }\n+\n /* (eq/ne (bswap x) C1) simplifies to (eq/ne x C2) with C2 swapped. */\n if ((code == EQ || code == NE)\n && GET_CODE (op0) == BSWAP\ndiff --git a/gcc/testsuite/gcc.target/riscv/zbs-if_then_else-02.c b/gcc/testsuite/gcc.target/riscv/zbs-if_then_else-02.c\nnew file mode 100644\nindex 00000000000..3393bea8898\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/riscv/zbs-if_then_else-02.c\n@@ -0,0 +1,32 @@\n+/* { dg-do link { target { rv64 } } } */\n+/* { dg-options \"-march=rv64gc_zbb_zbs -mabi=lp64d -flto\" } */\n+/* { dg-skip-if \"\" { *-*-* } { \"-O0\" \"-Og\" \"-O1\" } } */\n+\n+struct S {\n+ int a;\n+ char b;\n+ int c;\n+} s;\n+\n+const signed char c = -37;\n+int d;\n+struct S v1[] = {{0, 8}, 0, 0, -108976}, v2[] = {{}, 0, 0, 2804};\n+int a;\n+struct S v3[3];\n+int *p = &a;\n+\n+void foo() {\n+ int a;\n+ if (a)\n+ ;\n+ else if (v1[0].b)\n+ s.a = 0;\n+ else\n+ d = 0;\n+ if (*p)\n+ if (v3[1].c)\n+ if (1 ^ (d & c & v2[1].c & ~v1[1].c | s.a))\n+ v3[2].c = 0;\n+}\n+\n+int main() { foo(); }\n", "prefixes": [ "v4" ] }