GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/i386 Performance Win

i386: Use MULX for highpart-only multiplications [PR127900]

Utilize MULX instruction for 64-bit high-part multiplications on i386.

This commit improves the i386 backend by using the MULX instruction for high-part-only 64-bit multiplications, addressing PR127900. Previously, GCC used the MUL instruction, which clobbered registers and flags unnecessarily. MULX writes the high part to any register and avoids flag clobbering, reducing register moves and freeing up the RAX register. The changes involve splitting signed and unsigned multiplication patterns and updating patterns to support the BMI2 instruction set.

In Details

This patch addresses PR127900 by enabling the use of the MULX instruction for high-part-only unsigned 64-bit multiplications on i386. Previously, the MUL instruction was used, which clobbers RAX, RDX, and flags. MULX allows the high part to be written to any register and avoids flag clobbering. The changes split unsigned multiplication patterns from signed ones, introduce define_insn_and_split for BMI2-compatible patterns (umul<mode>3_highpart and umulsi3_highpart_zext), and use register_operand to simplify conditions. This optimization benefits code like `((unsigned __int128) a…

For Context
i386
The architecture of the original Intel 80386 processor, commonly used to refer to the x86 32-bit instruction set architecture. GCC's i386 backend targets this architecture.
MULX
A specific x86 instruction that performs a multiplication of two operands and stores the high 64 bits of the result in a specified destination register, without affecting the flags register.
MUL
An x86 instruction that performs multiplication. For 64-bit operands, it multiplies RAX by the other operand and stores the 128-bit result in RDX:RAX, clobbering RDX and flags.
BMI2
An extension to the x86 instruction set that includes a variety of bit manipulation instructions, such as enhanced multiplication and bit shift operations.
highpart-only multiplication
A multiplication operation where only the most significant bits (the 'high part') of the result are of interest, typically used for calculations involving 128-bit or larger numbers.
register pressure
A metric indicating how many registers are actively in use at a given point in the code. High register pressure can lead to more spilling (storing registers to memory) and reduced performance.
Filed Under: i386optimizationperformance