Handle extended conditional arithmetic in ifcvt.
Conditional arithmetic with sign/zero extensions now handled correctly.
The ifcvt (if-conversion) pass has been improved to handle conditional arithmetic operations that are wrapped in sign or zero extensions. The compiler now correctly identifies when the unchanged value of such an operation already has the necessary extension. This is achieved by directly querying the promoted lowpart, rather than searching for its definition, leading to more robust code generation for conditional arithmetic, particularly on architectures like RISC-V.
In Details
The ifcvt pass performs if-conversion, transforming conditional branches into conditional select operations. This commit adds logic to noce_try_cond_arith to correctly handle conditional arithmetic operations that are operands of sign or zero extension operations. New helper functions noce_operand_known_extended_p and noce_cond_arith_operation are introduced. The key enhancement is querying the promoted_lowpart directly, which is asserted to have the correct extension, rather than performing a potentially expensive search for the definition of the extended value. This improves handl…
- ifcvt
- A compiler optimization pass that converts conditional branches into conditional select (or arithmetic) instructions. This can improve performance by reducing control flow overhead and increasing instruction-level parallelism.
- conditional arithmetic
- Arithmetic operations that are performed only if a certain condition is met, often implemented using conditional select instructions or by masking results.
- sign extension
- A process where a number is converted to a larger data type by copying the most significant bit (the sign bit) to all the new higher-order bits. This preserves the number's signed value.
- zero extension
- A process where a number is converted to a larger data type by padding the new higher-order bits with zeros. This is typically used for unsigned numbers.