Ensure CONST_INT before extracting INTVAL in simplify-rtx
Prevents RTL checking failures by ensuring operands are CONST_INT.
This commit adds a check to ensure that an operand is a CONST_INT before attempting to extract its INTVAL in the simplify-rtx optimization. This prevents potential RTL checking failures and correctness bugs that could occur when treating non-constant values as integers, especially in compiler versions with RTL checking disabled. The fix ensures that the optimization correctly handles constant values for creating adjusted masks.
In Details
This fix targets the simplify-rtx pass, specifically within simplify_context::simplify_binary_operation_1. It addresses an issue (PR rtl-optimization/128738) where an optimization related to IOR of single-bit bitfields could incorrectly access a register node as a CONST_INT. This is problematic because the optimization relies on the operand being a known constant to create an adjusted mask. By adding a GET_CODE (op1) == CONST_INT check, the compiler ensures that the optimization is only applied when the operand is indeed a constant integer, preventing potential errors.
- RTL
- Register Transfer Language. An intermediate representation used by GCC internally to describe machine code operations before they are translated into final machine instructions.
- CONST_INT
- An RTL construct representing a constant integer value.
- INTVAL
- The integer value extracted from an RTL constant operand.
- Bitfield
- A technique for packing multiple small data items into a larger integer type by allocating specific bit ranges for each item.