On 7/10/2026 8:29 PM, [email protected] wrote:
From: MITSUNARI Shigeo <[email protected]>
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 <[email protected]>
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