RISC-V backend: Fix unsafe INTVAL checks for immediate operands.
RISC-V backend now safely checks for immediate operands, preventing potential issues with non-constant values.
This commit addresses two instances in the RISC-V backend where the [U]INTVAL operand check was used without ensuring the operand was a CONST_INT. This could lead to incorrect code generation when non-constant values were used as immediate operands in certain instructions. The fix restricts the relevant machine definition operands to const_int_operand, ensuring that only constant integers are accepted, thereby improving code generation safety and correctness.
In Details
Two machine definition files for the RISC-V backend, crypto.md and zicond.md, are updated to restrict operand 2 of specific instructions to const_int_operand. This corrects issues where [U]INTVAL was used on an immediate operand without a guarantee that it was a CONST_INT. This change is part of a broader review of RISC-V backend md files, aiming to enhance the safety and correctness of immediate operand handling, particularly outside the bitmanip extension.
- [U]INTVAL
- Likely refers to internal GCC predicates or macros used to check if an operand's value is an unsigned or signed integer, respectively.
- immediate operand
- An operand whose value is directly specified in the instruction, rather than being a reference to a memory location or register.
- CONST_INT
- A GCC internal tree node representing a constant integer value.
- const_int_operand
- A GCC machine mode predicate that matches an operand that is a constant integer.
- md files
- Machine description files used by GCC to define the instruction set and addressing modes for a particular target architecture.