Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2217388/?format=api
{ "id": 2217388, "url": "http://patchwork.ozlabs.org/api/patches/2217388/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/005a01dcbeb4$0c8cd860$25a68920$@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": "<005a01dcbeb4$0c8cd860$25a68920$@nextmovesoftware.com>", "list_archive_url": null, "date": "2026-03-28T13:09:01", "name": "PR middle-end/122871: Doubleword multiplication improvements", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "e49163b34591d37791bc65b5224ee32019a8648e", "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/005a01dcbeb4$0c8cd860$25a68920$@nextmovesoftware.com/mbox/", "series": [ { "id": 497867, "url": "http://patchwork.ozlabs.org/api/series/497867/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=497867", "date": "2026-03-28T13:09:01", "name": "PR middle-end/122871: Doubleword multiplication improvements", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/497867/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2217388/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2217388/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=B6ArmCmq;\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=B6ArmCmq", "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 4fjdCT39Qlz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 29 Mar 2026 00:09:56 +1100 (AEDT)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id A45534BA23D7\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 28 Mar 2026 13:09:53 +0000 (GMT)", "from server.nextmovesoftware.com (server.nextmovesoftware.com\n [69.48.154.134])\n by sourceware.org (Postfix) with ESMTPS id 5BD234BA23CB\n for <gcc-patches@gcc.gnu.org>; Sat, 28 Mar 2026 13:09:03 +0000 (GMT)", "from [168.86.198.119] (port=56721 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 1w6TPS-00000009Y5a-1zw3 for gcc-patches@gcc.gnu.org;\n Sat, 28 Mar 2026 09:09:02 -0400" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org A45534BA23D7", "OpenDKIM Filter v2.11.0 sourceware.org 5BD234BA23CB" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 5BD234BA23CB", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 5BD234BA23CB", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774703343; cv=none;\n b=AIYwhGNSq4BIB+l5UX30LU0P6k5kyVsnpoj8ffk8E7GH8CqUU5gIkRhw9Zp/xL71u8Mz3+hKuYz/HDjtT4Zj67dY9ORKGnZ6PVBW4HoTXKahiON4AHiSn0yDttQiz5/CDVSCTI9xG7qLbKc4oPXHIHdqsLfzVy9tuLIrE/b0eJg=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1774703343; c=relaxed/simple;\n bh=JKbAlcnO4lPrIusKlV6rc0pYALIrQUI0mZEyLs+NaVw=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=pG5xsx+DwLSDExrKW6CeyEyCtH8dgzLJo+sQyH25CHud66cUL+AyXunNxtlsa+zI84gAfSClgtUhWf0mnujrxMDpEikC7zl/ZpQ3xO1USlvpmrvfmLgOhxqHz08HqGCg4nFrIo5Ab67sXujr3xfpdbIG0qIyolv9J9MfVYh3DqI=", "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:To:From:Sender:Reply-To:Cc: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=LaJ1KUumQ2KfFfI8pWBwuVwauN9CSYUT1HYPae1DvwQ=; b=B6ArmCmq3AXHs0M5C8mSkWV/sC\n ARLc3Lin4x8w2rn1sI4l+/un1k/SO5z0wKicY6+8Fu7Uv+kdwKVcO/RTn0M8dkuwi0eLCOmXt5t/t\n nlN0VkWjc7oX69cdoV8m1gOZTmmbqNmX1imC8FFOi+qh5DK6Gi5990VEubgjKK9mqvPwatPHQZMEM\n /T1g3Rdji68T7ZegrQre/MQiejCPG2FoPLDhdCwR4t08sUMGwpXQlOO6oUPRzk7F/LfsU/f7J4dFD\n EInJSLUU7mf2SVjGC51rxScGUeLXaG6XsdDsZCgzyYx5POPX3/HHueoEAnuxvY2AKQDsRlN9UTJoO\n 47YpClYg==;", "From": "\"Roger Sayle\" <roger@nextmovesoftware.com>", "To": "<gcc-patches@gcc.gnu.org>", "Subject": "[PATCH] PR middle-end/122871: Doubleword multiplication improvements", "Date": "Sat, 28 Mar 2026 13:09:01 -0000", "Message-ID": "<005a01dcbeb4$0c8cd860$25a68920$@nextmovesoftware.com>", "MIME-Version": "1.0", "Content-Type": "multipart/mixed;\n boundary=\"----=_NextPart_000_005B_01DCBEB4.0C8CD860\"", "X-Mailer": "Microsoft Outlook 16.0", "Content-Language": "en-gb", "Thread-Index": "Ady+syCH4C0VS6aSScOMz8BDljxQKg==", "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 resolves PR middle-end/122871 by improving RTL expansion of\ndoubleword multiplications. The main change is to synth_mult adding\nsupport for the case where the constant being multiplied has BITS_PER_WORD\nor more trailing zeros. The shift_cost tables in expmed are only\nparameterized for shifts less than BITS_PER_WORD, so doubleword shifts\nby more than this can't use the usual code path. This patch teaches\nsynth_mult that for scalar doubleword multiplications, a doubleword shift\nby more than BITS_PER_WORD typically requires two instructions; one to\nset the result lowpart to zero, and the other a wordmode shift to\ncalculate the result highpart.\n\nFor the testcase given in the PR:\n\nlong long ashll_fn (long long a)\n{\n long long c;\n\n c = a << 33;\n c += a;\n return c;\n}\n\nGCC for arm-linux-gnueabihf currently generates with -O2:\n\nashll_fn:\n lsl r2, r1, #11\n lsl ip, r0, #11\n subs ip, ip, r0\n orr r2, r2, r0, lsr #21\n sbc r2, r2, r1\n lsl r3, ip, #11\n lsl r2, r2, #11\n adds r3, r3, r0\n orr r2, r2, ip, lsr #21\n adc r1, r1, r2\n lsl r2, r1, #11\n lsl r0, r3, #11\n adds r0, r3, r0\n orr r2, r2, r3, lsr #21\n adc r1, r1, r2\n bx lr\n\nwith this patch, we instead generate:\n\nashll_fn:\n add r1, r1, r0, lsl #1\n bx lr\n\n\nAdditionally, this patch includes a clean-up (identified by Andrew\nPinski) to prevent RTL expansion of doubleword multiplications from\ninitially emitting multiply instructions by immediate constants 0, 1\nor 2. These dubious multiplications eventually get tidied up by later\nRTL optimization passes, but being sensible during RTL expansion\nboth speeds up the compiler and reduces unnecessary memory usage.\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} with\nno new failures. Ok for mainline?\n\n\n2026-03-28 Roger Sayle <roger@nextmovesoftware.com>\n\ngcc/ChangeLog\n PR middle-end/122871\n * expmed.cc (synth_mult): Handle doubleword left shifts by\n BITS_PER_MODE bits or more, for scalar modes.\n * optabs.cc (expand_doubleword_mult): Avoid generating multiply\n instructions by immediate constants 0, 1 or 2.\n\n\nRoger\n--", "diff": "diff --git a/gcc/expmed.cc b/gcc/expmed.cc\nindex d57ea78d6b1..a75e406376a 100644\n--- a/gcc/expmed.cc\n+++ b/gcc/expmed.cc\n@@ -2962,6 +2962,28 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t,\n \t\t}\n \t }\n \t}\n+ else if (GET_MODE_BITSIZE (imode) == 2 * BITS_PER_WORD\n+\t && imode == mode)\n+\t{\n+\t q = t >> m;\n+\t int op1_cost = shift_cost (speed, mode, m - BITS_PER_WORD);\n+\t int op2_cost = zero_cost (speed);\n+\t op_latency = MAX (op1_cost, op2_cost);\n+\t op_cost = op1_cost + op2_cost;\n+\n+\t new_limit.cost = best_cost.cost - op_cost;\n+\t new_limit.latency = best_cost.latency - op_latency;\n+\t synth_mult (alg_in, q, &new_limit, mode);\n+\t alg_in->cost.cost += op_cost;\n+\t alg_in->cost.latency += op_latency;\n+\t if (CHEAPER_MULT_COST (&alg_in->cost, &best_cost))\n+\t {\n+\t best_cost = alg_in->cost;\n+\t std::swap (alg_in, best_alg);\n+\t best_alg->log[best_alg->ops] = m;\n+\t best_alg->op[best_alg->ops] = alg_shift;\n+\t }\n+\t}\n if (cache_hit)\n \tgoto done;\n }\ndiff --git a/gcc/optabs.cc b/gcc/optabs.cc\nindex e813cf9b215..829967ff9af 100644\n--- a/gcc/optabs.cc\n+++ b/gcc/optabs.cc\n@@ -902,8 +902,16 @@ expand_doubleword_mult (machine_mode mode, rtx op0, rtx op1, rtx target,\n \treturn NULL_RTX;\n }\n \n- adjust = expand_binop (word_mode, smul_optab, op0_high, op1_low,\n-\t\t\t NULL_RTX, 0, OPTAB_DIRECT);\n+ if (op1_low == const1_rtx)\n+ adjust = op0_high;\n+ else if (op1_low == const0_rtx)\n+ adjust = const0_rtx;\n+ else if (op1_low == const2_rtx)\n+ adjust = expand_binop (word_mode, add_optab, op0_high, op0_high,\n+\t\t\t NULL_RTX, 0, OPTAB_DIRECT);\n+ else\n+ adjust = expand_binop (word_mode, smul_optab, op0_high, op1_low,\n+\t\t\t NULL_RTX, 0, OPTAB_DIRECT);\n if (!adjust)\n return NULL_RTX;\n \n@@ -931,8 +939,16 @@ expand_doubleword_mult (machine_mode mode, rtx op0, rtx op1, rtx target,\n \treturn NULL_RTX;\n }\n \n- temp = expand_binop (word_mode, smul_optab, op1_high, op0_low,\n-\t\t NULL_RTX, 0, OPTAB_DIRECT);\n+ if (op1_high == const1_rtx)\n+ temp = op0_low;\n+ else if (op1_high == const0_rtx)\n+ temp = const0_rtx;\n+ else if (op1_high == const2_rtx)\n+ temp = expand_binop (word_mode, add_optab, op0_low, op0_low,\n+\t\t\t NULL_RTX, 0, OPTAB_DIRECT);\n+ else\n+ temp = expand_binop (word_mode, smul_optab, op0_low, op1_high,\n+\t\t\t NULL_RTX, 0, OPTAB_DIRECT);\n if (!temp)\n return NULL_RTX;\n \n@@ -949,7 +965,9 @@ expand_doubleword_mult (machine_mode mode, rtx op0, rtx op1, rtx target,\n if (GET_MODE (op0_low) == VOIDmode && GET_MODE (op1_low) == VOIDmode)\n op0_low = force_reg (word_mode, op0_low);\n \n- if (umulp)\n+ if (op1_low == const1_rtx)\n+ product = convert_modes (mode, word_mode, op0_low, umulp);\n+ else if (umulp)\n product = expand_binop (mode, umul_widen_optab, op0_low, op1_low,\n \t\t\t target, 1, OPTAB_DIRECT);\n else\n", "prefixes": [] }