Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2232122/?format=api
{ "id": 2232122, "url": "http://patchwork.ozlabs.org/api/patches/2232122/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/013901dcda70$c51fa510$4f5eef30$@nextmovesoftware.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": "<013901dcda70$c51fa510$4f5eef30$@nextmovesoftware.com>", "list_archive_url": null, "date": "2026-05-02T20:17:57", "name": "[x86] Shorter load immediate constants with -Oz", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8729db1ccbe148e85c44f284d7841bb31cb501d9", "submitter": { "id": 68376, "url": "http://patchwork.ozlabs.org/api/people/68376/?format=api", "name": "Roger Sayle", "email": "roger@nextmovesoftware.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/013901dcda70$c51fa510$4f5eef30$@nextmovesoftware.com/mbox/", "series": [ { "id": 502549, "url": "http://patchwork.ozlabs.org/api/series/502549/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=502549", "date": "2026-05-02T20:17:57", "name": "[x86] Shorter load immediate constants with -Oz", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502549/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2232122/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2232122/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=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com\n header.a=rsa-sha256 header.s=default header.b=DrrTN9sC;\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=nextmovesoftware.com header.i=@nextmovesoftware.com\n header.a=rsa-sha256 header.s=default header.b=DrrTN9sC", "sourceware.org; dmarc=pass (p=none dis=none)\n header.from=nextmovesoftware.com", "sourceware.org;\n spf=pass smtp.mailfrom=nextmovesoftware.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=69.48.154.134" ], "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 4g7K3r2HxPz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 03 May 2026 06:18:30 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 0D43B4BB5916\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 2 May 2026 20:18:29 +0000 (GMT)", "from server.nextmovesoftware.com (server.nextmovesoftware.com\n [69.48.154.134])\n by sourceware.org (Postfix) with ESMTPS id 1AC9C4BB3BB9\n for <gcc-patches@gcc.gnu.org>; Sat, 2 May 2026 20:18:00 +0000 (GMT)", "from [168.86.198.7] (port=52060 helo=Dell)\n by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls\n TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.99.1)\n (envelope-from <roger@nextmovesoftware.com>)\n id 1wJGml-00000005yyS-0v1v; Sat, 02 May 2026 16:17:59 -0400" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 0D43B4BB5916", "OpenDKIM Filter v2.11.0 sourceware.org 1AC9C4BB3BB9" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 1AC9C4BB3BB9", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 1AC9C4BB3BB9", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777753080; cv=none;\n b=YDlX0AzcZrvmBLgMutA6tRczKfL3VJNSVgDtUx+Y6gjCyQnFvxR9qMDEhPlhiiXaS/oIyr3MjWID+J/Ukad68+YufC0AHe2+JtPnk8M2Zv8g1pSAtTJ0oejQu7sGNERPCsTIz2qUkIBzLUGeg2WyaGU+HouerdCUMXvy6JaB84k=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777753080; c=relaxed/simple;\n bh=Nwra2cdSLzsZL4EIM5Fx+uQ1dVmlODutxHwKqXuqSO4=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=g0Kt1UAAs5Fj6sf/3vnrBc7YK9PwJ9cxkpZt/eNk3ob8ET5v7Lj/R+iF137B3nFsPcxcF2llk9avWCl7P/qyXzr8bZ7aryacgt/zzrO+kUgvBS6Zv4HS077IBvqgmmb4r6iCHJJLsKYmhUatlH4h1BW6fMe/Xchqg3YdWDc1Rvc=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID:\n Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:\n Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:\n List-Subscribe:List-Post:List-Owner:List-Archive;\n bh=J7G5Y0MG5g99zkBx80jQ47t9xWR7d5qBn75dFg1aVzs=; b=DrrTN9sCz5sayyYx4Ufyq+hzY+\n VKapTLn8cJJmxh1VLWGekGjETPBab1x/oml5u9C5UGi168Unqi5xWIiqZimNd9nhHTvtjEP+xKTuQ\n LCzHa8LBYcWJz3DFP4Xbi7S4uqchmkP/4uy43h9Txrqk1vK65d8Ilen/oQb9Dd21F7SXuCm8hgoMk\n fjzJpgN2yDKZDHtPRI/cAuzcPwn7OZERlcE/BZII0sMUC7NAhAa/wK3AHlKZmFCEpXuPBkHqbqzRi\n cpP4Tjnpjyp3vfTP22t5pPlicuYyshCNjFOBjWrXZ1lgDwc8UOG4XqmUz5aKyCqmrbQm9tyxGVafT\n XYySQrKw==;", "From": "\"Roger Sayle\" <roger@nextmovesoftware.com>", "To": "\"'GCC Patches'\" <gcc-patches@gcc.gnu.org>", "Cc": "\"'Uros Bizjak'\" <ubizjak@gmail.com>", "Subject": "[x86 PATCH] Shorter load immediate constants with -Oz", "Date": "Sat, 2 May 2026 21:17:57 +0100", "Message-ID": "<013901dcda70$c51fa510$4f5eef30$@nextmovesoftware.com>", "MIME-Version": "1.0", "Content-Type": "multipart/mixed;\n boundary=\"----=_NextPart_000_013A_01DCDA79.26E4F770\"", "X-Mailer": "Microsoft Outlook 16.0", "Thread-Index": "Adzab5tQP1X0SRCNRz6V2KtymJqdBw==", "Content-Language": "en-gb", "X-AntiAbuse": [ "This header was added to track abuse,\n please include it with any abuse report", "Primary Hostname - server.nextmovesoftware.com", "Original Domain - gcc.gnu.org", "Originator/Caller UID/GID - [47 12] / [47 12]", "Sender Address Domain - nextmovesoftware.com" ], "X-Get-Message-Sender-Via": "server.nextmovesoftware.com: authenticated_id:\n roger@nextmovesoftware.com", "X-Authenticated-Sender": "server.nextmovesoftware.com:\n roger@nextmovesoftware.com", "X-Source": "", "X-Source-Args": "", "X-Source-Dir": "", "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 patch adds two peephole2 patterns to i386.md to decrease the size\nof some inteer loads. These replace \"movl $const, %eax\" (5 bytes)\nwith \"xorl %eax, %eax\" followed by either \"movb $const,%al\" or\n\"movb $const,%ah\" (together 4 bytes), for suitable constants and\nsuitable genral registers, when the flags register is dead.\n\nIdeally modern Intel and AMD prcoessors can recognize these sequences\nduring instruction decode (avoiding any partial register stall in\nthe same way they avoid the false dependence for the xorl), and\ninternally generate a single uop, treating these bytes like an\nalternate instruction encoding.\n\n\nThis patch has been tested on x86_64-pc-linux-gnu with make bootstrap\nand make -k check, both with and without --target_board=unix{-m32}\nwith no new failures. Ok for mainline?\n\n\n2026-05-02 Roger Sayle <roger@nextmovesoftware.com>\n\ngcc/ChangeLog\n PR target/32803\n * config/i386/i386.md (peephole2): Don't transform xorl;movb into\n movzb with -Oz.\n (peephole2): Convert movl into xorl;movb (strict_low_part) with -Oz.\n (peephole2): Likewise, convert movl into xorl;movb [abcd]h with -Oz.\n\ngcc/testsuite/ChangeLog\n PR target/32803\n * gcc.target/i386/pr32803-2.c: New test case.\n * gcc.target/i386/pr32803-3.c: Likewise.\n\n\nThanks,\nRoger\n--", "diff": "diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md\nindex 648b9b1b951..47dc793505a 100644\n--- a/gcc/config/i386/i386.md\n+++ b/gcc/config/i386/i386.md\n@@ -4948,7 +4948,8 @@\n \"REGNO (operands[0]) == REGNO (operands[1])\n && (<SWI48:MODE>mode != SImode\n || !TARGET_ZERO_EXTEND_WITH_AND\n- || !optimize_function_for_speed_p (cfun))\"\n+ || !optimize_function_for_speed_p (cfun))\n+ && !(optimize_insn_for_size_p () && optimize_size > 1)\"\n [(set (match_dup 0) (zero_extend:SWI48 (match_dup 2)))])\n \n ;; Likewise, but preserving FLAGS_REG.\n@@ -4961,6 +4962,37 @@\n || !TARGET_ZERO_EXTEND_WITH_AND\n || !optimize_function_for_speed_p (cfun))\"\n [(set (match_dup 0) (zero_extend:SWI48 (match_dup 2)))])\n+\n+;; With -Oz, convert mov eax,200 (5 bytes) to xor eax,eax; mov al,200\n+;; (4 bytes) when the flags register is dead.\n+(define_peephole2\n+ [(set (match_operand:SWI48 0 \"general_reg_operand\")\n+\t(match_operand:SWI48 1 \"const_int_operand\"))]\n+ \"optimize_insn_for_size_p () && optimize_size > 1\n+ && IN_RANGE (INTVAL (operands[1]), 128, 255)\n+ && peep2_regno_dead_p (0, FLAGS_REG)\"\n+ [(parallel [(set (match_dup 0) (const_int 0))\n+\t (clobber (reg:CC FLAGS_REG))])\n+ (set (strict_low_part (match_dup 2)) (match_dup 3))]\n+{\n+ operands[2] = gen_lowpart (QImode, operands[0]);\n+ operands[3] = gen_int_mode (INTVAL (operands[1]), QImode);\n+})\n+\n+;; With -Oz, convert mov eax,512 (5 bytes) to xor eax,eax; mov ah,2\n+;; (4 bytes) when the flags register is dead.\n+(define_peephole2\n+ [(set (match_operand:SWI48 0 \"general_reg_operand\")\n+\t(match_operand:SWI48 1 \"const_int_operand\"))]\n+ \"optimize_insn_for_size_p () && optimize_size > 1\n+ && (INTVAL (operands[1]) & ~0xff00) == 0\n+ && QI_REGNO_P (REGNO (operands[0]))\n+ && peep2_regno_dead_p (0, FLAGS_REG)\"\n+ [(parallel [(set (match_dup 0) (const_int 0))\n+\t (clobber (reg:CC FLAGS_REG))])\n+ (set (zero_extract:SWI48 (match_dup 0) (const_int 8) (const_int 8))\n+ (match_dup 2))]\n+ \"operands[2] = gen_int_mode (INTVAL (operands[1]) >> 8, QImode);\")\n \f\n ;; Sign extension instructions\n \ndiff --git a/gcc/testsuite/gcc.target/i386/pr32803-2.c b/gcc/testsuite/gcc.target/i386/pr32803-2.c\nnew file mode 100644\nindex 00000000000..7fc8f5aa18e\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/i386/pr32803-2.c\n@@ -0,0 +1,25 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-Oz\" } */\n+\n+int foo()\n+{\n+ return 200;\n+}\n+\n+long fool()\n+{\n+ return 200;\n+}\n+\n+int bar()\n+{\n+ return 512;\n+}\n+\n+long barl()\n+{\n+ return 512;\n+}\n+/* { dg-final { scan-assembler-times \"xorl\\[ \\t\\]*%eax, %eax\" 4 } } */\n+/* { dg-final { scan-assembler-times \"movb\\[ \\t\\]*\\\\\\$-56, %al\" 2 } } */\n+/* { dg-final { scan-assembler-times \"movb\\[ \\t\\]*\\\\\\$2, %ah\" 2 } } */\ndiff --git a/gcc/testsuite/gcc.target/i386/pr32803-3.c b/gcc/testsuite/gcc.target/i386/pr32803-3.c\nnew file mode 100644\nindex 00000000000..052c7b3c7ed\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/i386/pr32803-3.c\n@@ -0,0 +1,24 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-Os\" } */\n+\n+int foo()\n+{\n+ return 200;\n+}\n+\n+long fool()\n+{\n+ return 200;\n+}\n+\n+int bar()\n+{\n+ return 512;\n+}\n+\n+long barl()\n+{\n+ return 512;\n+}\n+/* { dg-final { scan-assembler-times \"movl\\[\\\\t \\]*\\\\\\$200, %eax\" 2 } } */\n+/* { dg-final { scan-assembler-times \"movl\\[\\\\t \\]*\\\\\\$512, %eax\" 2 } } */\n", "prefixes": [ "x86" ] }