LoongArch: Add spaceship expanders.
GCC now supports the spaceship operator for LoongArch, enabling better code generation for nested ternary operations.
GCC now supports the spaceship operator (<=> in C++) for the LoongArch architecture. This addition helps optimize nested ternary operations that produce -1, 0, or 1 by translating them into slt[u]-slt[u]-sub instructions. This optimization can improve code efficiency for comparisons and conditional assignments.
In Details
This commit adds spaceship<mode>4 define_expand patterns to config/loongarch/loongarch.md. This allows the compiler to recognize and optimize C++ spaceship operator expressions on the LoongArch architecture. The new test case gcc.target/loongarch/la64/spaceship.c verifies the functionality of the spaceship operator expansion.
For Context
The spaceship operator is a comparison operator that returns -1, 0, or 1 depending on whether the left-hand side is less than, equal to, or greater than the right-hand side. This operator simplifies chained comparisons and is commonly used in C++. The LoongArch architecture now has dedicated support within GCC to translate the spaceship operator into efficient assembly code sequences, improving performance.