Instruction selector optimizes atomic bit tests correctly
Fixes instruction selection for atomic bit test and modify operations with casts and comparisons.
The optimize_atomic_bit_test_and function in the instruction selector (isel) was not correctly handling cases where the left-hand side of an atomic fetch-or/and operation was used in a cast, particularly when combined with comparisons like < 0 or >= 0. This commit adjusts the logic to properly determine the relevant bit mask and handle signedness, ensuring correct code generation for these atomic operations, even with narrowing conversions or when dealing with types like _BitInt.
In Details
This patch refines optimize_atomic_bit_test_and within the GIMPLE instruction selector. The function previously had a condition TYPE_PRECISION (TREE_TYPE (use_lhs)) <= TYPE_PRECISION (TREE_TYPE (use_rhs)) that incorrectly accepted certain casts involving atomic operations. The issue was exacerbated by comparisons like < 0 or >= 0 which test the most significant bit. The fix ensures that for these comparison cases, the code now correctly calculates the bit to test based on the precision of use_lhs and punts if use_lhs is unsigned, preventing incorrect masks and handling for various…
- Instruction Selector (isel)
- A component of the compiler responsible for selecting the best machine instructions to implement the intermediate representation (like GIMPLE).
- GIMPLE
- GCC's internal representation for code during optimization. It's a three-address code form that simplifies analysis and transformation.
- Atomic Operation
- An operation that is guaranteed to execute indivisibly, without interference from other threads or processes. In GCC,
__atomic_fetch_or_...and__atomic_fetch_and_...are examples. - Cast
- The conversion of a value from one data type to another.
- _BitInt
- A C++ language extension supported by GCC for arbitrary-width integers.