[PATCH v9 2/2] i386: Add BMI2 MULX pattern for highpart-only multiplication
Jeffrey Law
jeffrey.law@oss.qualcomm.com
Sun Jul 12 04:39:51 GMT 2026
On 7/10/2026 8:29 PM, herumi@nifty.com wrote:
> From: MITSUNARI Shigeo <herumi@nifty.com>
>
> Add a new instruction pattern that uses MULX to compute only the high
> part of an unsigned multiplication on BMI2 targets. Previously, when
> only the high part was needed, GCC would emit MULQ followed by a MOV
> to retrieve the result from RDX. With this pattern, MULX writes the
> high part directly to the destination register, saving one instruction.
>
> This benefits unsigned 32-bit integer division by constants that require
> 33-bit magic multipliers (e.g., division by 7), reducing the sequence
> from 4 instructions to 3 on BMI2 targets.
>
> Before:
> movabsq $2635249153617166336, %rcx
> movl %edi, %eax
> mulq %rcx
> movl %edx, %eax
>
> After:
> movabsq $2635249153617166336, %rax
> movl %edi, %edx
> mulx %rax, %rax, %rax
>
> gcc/ChangeLog:
>
> * config/i386/i386.md (*bmi2_umul<mode>3_highpart): New pattern.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/bmi2-mulx-highpart-1.c: New test.
>
> Signed-off-by: MITSUNARI Shigeo <herumi@nifty.com>
I've pushed this too.
Note I forgot to set the author on the first patch. I'll have to update
the ChangeLog manually tomorrow to correct that.
jeff
More information about the Gcc-patches
mailing list