LoongArch: Optimize 64-bit moves to floating-point registers
LoongArch 64-bit register moves to floating-point registers are optimized, avoiding unnecessary instructions and improving performance.
This commit optimizes the movdi_64bit pattern in LoongArch by removing a wildcard (‘*’) from floating-point register constraints. This change allows the compiler to directly generate the fld.d instruction instead of a more costly sequence of ld.d followed by movgr2fr.d. By preferring fld.d when floating-point and general-purpose register costs are equal, this optimization reduces instruction counts and has shown significant performance improvements in SPEC2017 benchmarks.
In Details
The movdi_64bit pattern in config/loongarch/loongarch.md previously used a '*' constraint on floating-point register classes (f and m). This wildcard implies that the register allocator should consider both floating-point and general-purpose registers, but it introduces an overhead associated with FP_REGS. By removing the '*', the pattern now allows for a more direct selection of floating-point registers. This enables the use of the fld.d instruction for loading 64-bit values directly into floating-point registers, bypassing the need for a load-then-move-between-register-classes s…
- movdi_64bit
- A machine-dependent instruction or pattern in GCC for moving a 64-bit doubleword value. In this context, it specifically refers to moving data into floating-point registers on the LoongArch architecture.
- constraint
- In GCC's machine description files, constraints specify the type of operand (e.g., register, immediate value) that an instruction pattern can accept. A wildcard '*' modifies a constraint, often indicating a broader or more flexible match.
- fld.d
- A LoongArch instruction that loads a 64-bit double-precision floating-point value from memory into a floating-point register.
- ld.d
- A LoongArch instruction that loads a 64-bit doubleword value from memory into a general-purpose register.
- movgr2fr.d
- A LoongArch instruction that moves a 64-bit value from a general-purpose register to a floating-point register.
- FP_REGS
- A symbolic name representing the set of floating-point registers available on the target architecture.
- GR_REGS
- A symbolic name representing the set of general-purpose registers available on the target architecture.