[{"id":3685357,"web_url":"http://patchwork.ozlabs.org/comment/3685357/","msgid":"<CAMe9rOoCZyHtspRrawVswPOFCsX2FpQO3g=G83gm0GQoKBAUFQ@mail.gmail.com>","list_archive_url":null,"date":"2026-05-03T06:50:16","subject":"Re: [PATCH v2 2/3] i386: Add BMI2 MULX pattern for highpart-only\n multiplication","submitter":{"id":4387,"url":"http://patchwork.ozlabs.org/api/people/4387/","name":"H.J. Lu","email":"hjl.tools@gmail.com"},"content":"On Sun, May 3, 2026 at 1:39 PM <herumi@nifty.com> wrote:\n>\n> From: MITSUNARI Shigeo <herumi@nifty.com>\n>\n> Add a new instruction pattern that uses MULX to compute only the high\n> part of an unsigned multiplication on BMI2 targets.  Previously, when\n> only the high part was needed, GCC would emit MULQ followed by a MOV\n> to retrieve the result from RDX.  With this pattern, MULX writes the\n> high part directly to the destination register, saving one instruction.\n>\n> This benefits unsigned 32-bit integer division by constants that require\n> 33-bit magic multipliers (e.g., division by 7), reducing the sequence\n> from 4 instructions to 3 on BMI2 targets.\n>\n> Before:\n>     movabsq $2635249153617166336, %rcx\n>     movl    %edi, %eax\n>     mulq    %rcx\n>     movl    %edx, %eax\n>\n> After:\n>     movabsq $2635249153617166336, %rax\n>     movl    %edi, %edx\n>     mulx    %rax, %rdx, %rax\n\nPlease add a test with check-function-bodies.\n\nThanks.\n\n> gcc/ChangeLog:\n>\n>         * config/i386/i386.md (*bmi2_umul<mode>3_highpart): New pattern.\n> ---\n>  gcc/config/i386/i386.md | 15 +++++++++++++++\n>  1 file changed, 15 insertions(+)\n>\n> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md\n> index e514809453d..472f9d41332 100644\n> --- a/gcc/config/i386/i386.md\n> +++ b/gcc/config/i386/i386.md\n> @@ -11507,6 +11507,21 @@\n>               (set (match_dup 5)\n>                    (umul_highpart:DWIH (match_dup 2) (match_dup 3)))])])\n>\n> +;; BMI2 MULX highpart-only pattern.  Uses MULX to get only the high part,\n> +;; discarding the low part into a scratch register.  This avoids the\n> +;; mov from rdx after mulq when only the high part is needed.\n> +(define_insn \"*bmi2_umul<mode>3_highpart\"\n> +  [(set (match_operand:DWIH 0 \"register_operand\" \"=r\")\n> +       (umul_highpart:DWIH\n> +         (match_operand:DWIH 1 \"register_operand\" \"d\")\n> +         (match_operand:DWIH 2 \"nonimmediate_operand\" \"rm\")))\n> +   (clobber (match_scratch:DWIH 3 \"=r\"))]\n> +  \"TARGET_BMI2\"\n> +  \"mulx\\t{%2, %3, %0|%0, %3, %2}\"\n> +  [(set_attr \"type\" \"imulx\")\n> +   (set_attr \"prefix\" \"vex\")\n> +   (set_attr \"mode\" \"<MODE>\")])\n> +\n>  ;; Highpart multiplication patterns\n>  (define_insn \"<s>mul<mode>3_highpart\"\n>    [(set (match_operand:DWIH 0 \"register_operand\" \"=d\")\n> --\n> 2.43.0\n>","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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=Oj8B3Kga;\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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=Oj8B3Kga","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=2607:f8b0:4864:20::102c"],"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 4g7b6v40Jpz1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 03 May 2026 16:52:07 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id B88234BAD17A\n\tfor <incoming@patchwork.ozlabs.org>; Sun,  3 May 2026 06:52:05 +0000 (GMT)","from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com\n [IPv6:2607:f8b0:4864:20::102c])\n by sourceware.org (Postfix) with ESMTPS id 957414BB58D8\n for <gcc-patches@gcc.gnu.org>; Sun,  3 May 2026 06:50:53 +0000 (GMT)","by mail-pj1-x102c.google.com with SMTP id\n 98e67ed59e1d1-364e5d895e3so1614000a91.2\n for <gcc-patches@gcc.gnu.org>; Sat, 02 May 2026 23:50:53 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org B88234BAD17A","OpenDKIM Filter v2.11.0 sourceware.org 957414BB58D8"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 957414BB58D8","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 957414BB58D8","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1777791053; cv=pass;\n b=ZT+ma0kFNvHDmhg9FcTJG+HlAjd6dcx29FGYl4yii1rOzmA8D2+++pwCIdu5VT3DkLx8eJdPpH6b29zrnK7Dp9ubU91LTSNFXQ3MlXDi0aRiLXGy/1xxAzqIUFOWyk+GNLcCehIkEuLiWrK+YkA9+r3VNgRJYLDfnPYTm7PFkgM=","i=1; a=rsa-sha256; t=1777791052; cv=none;\n d=google.com; s=arc-20240605;\n b=BNB0u1IN8ZOU/H00v4rXA9YSurm7xN9ayFWwxYKoPGG1fGhTeK1mLP2UYJzgRHonVJ\n Go7lXlBncDoQN/KLoxUh5aExqWci7NIMs0xPdSbN1DXmidyrbQf5m+Qodbkzq7H++lUG\n 4GDKZeDCUJAIGCSB5exgqBIc3rWm+FBgDG4AYpFwjkABBnKsnePhreevL0P1Wxh7bC14\n Fvk1bUYKDVbkUe2YHBqO+rmNwGdb2VMOw4URWT8MfeZqAl2l8nxYvbokxrL5TJI587aY\n FS/oppMjcQhvpWN0JHEIExP9ChSIS7zZ/till+J6hdG4LpempBFDlvk6LPiKmhE+KUI7\n Q98g=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777791053; c=relaxed/simple;\n bh=7Q4Y4NV03W0m8OE8/ATRZMxd4iCme+BtnXFMb+tEDqc=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=bKNWOq/k1r5sf8+NI8ncDDiWI/D902/Ar+7hZtq5DnYMhME9z4JNW5h3cm9Tv2JGwulJXUnN5yVgLx8twRFuNSndeWiV1zHSt3Jw39M+gDSsSYqbEp1u0TcPyr0V7B6c2DeFgr6tVhcC+6q6aNh6iwYPB5fKFMiybLr6EA7A8n8=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=hAkPMt+3i78C2ptwOLYU4evir4utRmi8S/uMrC+TPb8=;\n fh=ElYDoChHlwCPcmV6d0xiiD39Crd8RA+byJy+8mXh/Yc=;\n b=Fvm/1xvcxwi7SYxv7+uczyxz+InO7+bdh+UA4nMrnioWVwv21/BzKb/h5ALLe0zCuv\n +YTYkfOqNkRQEVhIH0T/FJ/s7R+6iq7HsoTRvVm5Uc/FBEGsmDxu5VCCltoYkL9yMyzg\n mSZsxapdrHTubASnaDzmJqaB1rxGE6CGdvG2/QLshHQrtcx6XBvRbfa/CNbgSXNVK3k1\n 9eQueZWNLG2TJZ0QJkpalxh7Cs0ItcfnjZeXW3YzpfuEVkHPO0YjFz6GhD/KFiA9EzS6\n lcmYytoKD0sfaeAanAvGGE65aL9vzr2ahGhkgewXOm5wvvSuK1w7pBgk4uWTecpOCjy3\n IVAA==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1777791052; x=1778395852; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=hAkPMt+3i78C2ptwOLYU4evir4utRmi8S/uMrC+TPb8=;\n b=Oj8B3KgaqKUHvzhX2ZOfjTMhkCfqcaMet/Ct/yYXghCcEJrbu6dMW7ox90ozCdHCL/\n 0N46RZhPGyU2EoTWwNoDvRZyI6C+6nKSaOG2pegdjkRgEzHvdS9E3bLBlD3VqJScCWex\n 3SLqmayUrdM37JqrzfNhP3kU63sPoPhoFIItY6LvDUTrITx65MzE+8PTWJY6V1TlbAak\n 6x35du/RMf1ZNDx8UwDdBjpwV9/idU503a++KPrKPMvumJifnFyrGVz0skZkKAxJB6gz\n vWS6YsMUtmwWrBWdW+0GLC9nVRmj4BlEEI9vmGUBONH2NKJ778D4idipB+18EgUzLHtn\n OOkg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777791052; x=1778395852;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=hAkPMt+3i78C2ptwOLYU4evir4utRmi8S/uMrC+TPb8=;\n b=LgrIBmFK/hXLaj5xcx/p8MstxW++KTQgnoTsJvHid53ZWXBXJhpIxOvuzOxKUr892F\n yQEDzFOMjM7UWJ3WU66LxkIwIoVos/Di6/0csbHooGANHwDQ8Pi6b2AjM/I7xMi+kv5C\n Pi+yeo2txzMWUojCegydJ6dlVlyCcdaCAPfaBTFjC6yn23VEsD3f/B7ZEZ7lY3qhnc7X\n uo0Lfn/pMFi7fUizTZnaufJJPqT6yI7uIgjR80OhBLlmPLrmrSFYkf4N2UuJ8jsFYpaL\n 1nang+Tgq+nYz5k3uZ5r8GLcW743qxYI//o0tV/P5YjTYt/wTCSwUZuRlbGeQrGa8fis\n NYew==","X-Gm-Message-State":"AOJu0YxZSEXGW+xfODnWHibxJ2eU6f/hYVm2gUtK8CjKWOQ0DMHAfUmd\n 0QMwc8AKTgUduG6bIKIc7d8KnpI8vhnuoXJ0ZePd79YvKpVzyCXocvlHEF3XdrAH/FHUEvvtDSa\n gWFlBTaan+ABDkBbzVbRIHdxjvqYlzaM=","X-Gm-Gg":"AeBDiesyGDkNpx/oo+jPdssVw0Jlf9TsUN4B9H7zRoyNs2LCG+pJ2t+HQH27hzyarcb\n QwxkNO49KIhwndg10jG4lT8YuTmTAXoZ7NSbpMxDKYeA9Krd4VQK/6Iv2VhzRyiXWbKdwuWlkkm\n 9DhUyCPlgFjgnA4THdbQ3JpptTlL1Ai2v7Vm/T4NPHEN5ckN/9NvVoNWIvxKBlCExVZ93U50zkP\n r5n5wBDSnwQ1sVfEavnMxSfZS1y5iziYD3zMs1MRvrocjH4P40IbWSb1xkN4Ll9Dkp0x7L80okz\n aJGMxgIXLyVPXxby","X-Received":"by 2002:a05:6a20:7d8b:b0:39b:98e3:6a11 with SMTP id\n adf61e73a8af0-3a7f1c976a3mr5602376637.50.1777791052364; Sat, 02 May 2026\n 23:50:52 -0700 (PDT)","MIME-Version":"1.0","References":"<727728f8-76e5-457b-ab9f-d650550e0702@gmail.com>\n <20260503053451.48504-1-herumi@nifty.com>\n <20260503053451.48504-3-herumi@nifty.com>","In-Reply-To":"<20260503053451.48504-3-herumi@nifty.com>","From":"\"H.J. Lu\" <hjl.tools@gmail.com>","Date":"Sun, 3 May 2026 14:50:16 +0800","X-Gm-Features":"AVHnY4LP9fK5qssu8HPGWOFPYuuzmE8nNkPcuHtiHXH5NVukd4Jc96M7ejhICoQ","Message-ID":"\n <CAMe9rOoCZyHtspRrawVswPOFCsX2FpQO3g=G83gm0GQoKBAUFQ@mail.gmail.com>","Subject":"Re: [PATCH v2 2/3] i386: Add BMI2 MULX pattern for highpart-only\n multiplication","To":"herumi@nifty.com","Cc":"gcc-patches@gcc.gnu.org, rguenther@suse.de, jeffreyalaw@gmail.com,\n ubizjak@gmail.com","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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"}}]