Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2218053/?format=api
{ "id": 2218053, "url": "http://patchwork.ozlabs.org/api/patches/2218053/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260331101028.10577-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": "<20260331101028.10577-1-garthlei@linux.alibaba.com>", "list_archive_url": null, "date": "2026-03-31T10:10:28", "name": "[v2] simplify-rtx: Simplify (op (and/ior x C1) C2) in special cases", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "1c79150ccce874dbc301daba6527be853c89a573", "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/20260331101028.10577-1-garthlei@linux.alibaba.com/mbox/", "series": [ { "id": 498167, "url": "http://patchwork.ozlabs.org/api/series/498167/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=498167", "date": "2026-03-31T10:10:28", "name": "[v2] simplify-rtx: Simplify (op (and/ior x C1) C2) in special cases", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/498167/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2218053/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2218053/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=YOgsgMUx;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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=YOgsgMUx", "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.131" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 4flP6F03Zfz1yGH\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 31 Mar 2026 21:11:31 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 70F444BB58B4\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 31 Mar 2026 10:11:29 +0000 (GMT)", "from out30-131.freemail.mail.aliyun.com\n (out30-131.freemail.mail.aliyun.com [115.124.30.131])\n by sourceware.org (Postfix) with ESMTPS id CDA274BA2E18\n for <gcc-patches@gcc.gnu.org>; Tue, 31 Mar 2026 10:10:57 +0000 (GMT)", "from localhost(mailfrom:garthlei@linux.alibaba.com\n fp:SMTPD_---0X03zv0i_1774951846 cluster:ay36) by smtp.aliyun-inc.com;\n Tue, 31 Mar 2026 18:10:53 +0800" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 70F444BB58B4", "OpenDKIM Filter v2.11.0 sourceware.org CDA274BA2E18" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org CDA274BA2E18", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org CDA274BA2E18", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774951858; cv=none;\n b=hAfLRIrIQyIhakI2yeihluiUhvd4RudSm9Hl23Lw24rPt0RK5kbzlgI7+h/l3lKTO6Bw9+5OcdrNeLm9I8Lph8vVmFLSoC/wgdb1PeUBNt9HuzjIp4etnlGaiLtXPpzaR2xwarJehPfdAiwq8SFDWhSD8zM1vnee6kPtiAk/Sdc=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1774951858; c=relaxed/simple;\n bh=9d8KIZw1kitdxZ18EnfMO3t0Bh1FopTY0vj7O1e3T60=;\n h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version;\n b=brLxUS5IwupFZ8hP2ZcSig1LYd0gQHjOFKySSkunyaF35esNl8qDH6y3tXgUEG5J3rmHofwnzKoqfJab96JSbUBLKa53LYuIEJNKMdRMtl7o9Bty7oDYhghuh1mQbZuaC9inOmZ7L4reDwvY9Q79vMnB15dGD5OBxE78qMaBhGs=", "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=1774951854; h=From:To:Subject:Date:Message-Id:MIME-Version;\n bh=73yW1JJ7Gf2cDM+iUHq8W+r03TcgntPnA2ZTtNceTEc=;\n b=YOgsgMUxdxjD01wBRt2qrdMZTk2aCgcsV60XoIl22195i0eiBjd5Ep5QfE3V5uvVbYIrjmBJvKiS3nSsGKYtI+7gRUaao8O5fybNJJdPw5Hdxu88Z/tz9coGTRP4BXgMHVqsdpB7GiOaVVCdglVH2ktZdw87FAQqtPDNI2hiMHA=", "X-Alimail-AntiSpam": "AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green;\n DM=||false|;\n DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033045098064;\n MF=garthlei@linux.alibaba.com; NM=1; PH=DS; RN=4; SR=0;\n TI=SMTPD_---0X03zv0i_1774951846;", "From": "Bohan Lei <garthlei@linux.alibaba.com>", "To": "gcc-patches@gcc.gnu.org", "Cc": "jeffrey.law@oss.qualcomm.com, philipp.tomsich@vrull.eu,\n Bohan Lei <garthlei@linux.alibaba.com>", "Subject": "[PATCH v2] simplify-rtx: Simplify (op (and/ior x C1) C2) in special\n cases", "Date": "Tue, 31 Mar 2026 18:10:28 +0800", "Message-Id": "<20260331101028.10577-1-garthlei@linux.alibaba.com>", "X-Mailer": "git-send-email 2.39.3 (Apple Git-146)", "In-Reply-To": "<20260331080542.97649-1-garthlei@linux.alibaba.com>", "References": "<20260331080542.97649-1-garthlei@linux.alibaba.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 v2 of\nhttps://gcc.gnu.org/pipermail/gcc-patches/2026-March/711809.html, fixed\nand enhanced as was suggested by Philipp.\n\nThis patch adds missing simplifications for (op (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):\nAdd simplifications for (op (and/ior x C1) C2) in special cases.\n\ngcc/testsuite/ChangeLog:\n\n\t* gcc.target/riscv/zbs-if_then_else-02.c: New test.\n---\n gcc/simplify-rtx.cc | 30 +++++++++++++++++\n .../gcc.target/riscv/zbs-if_then_else-02.c | 32 +++++++++++++++++++\n 2 files changed, 62 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..abaee2423a7 100644\n--- a/gcc/simplify-rtx.cc\n+++ b/gcc/simplify-rtx.cc\n@@ -6731,6 +6731,36 @@ simplify_context::simplify_relational_operation_1 (rtx_code code,\n \t}\n }\n \n+ /* Several optimizable scenerios of (op (and/ior x C1) C2) */\n+ if ((op0code == AND || op0code == IOR)\n+ && CONST_SCALAR_INT_P (op1)\n+ && CONST_SCALAR_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+ 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+\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": [ "v2" ] }