Fix big-endian separate_ext loop condition for bit integers
Corrects loop bounds for sign extension of bit integers on big-endian systems.
This commit fixes an issue in GCC’s bit-integer lowering pass where the loop condition for sign extension on big-endian architectures was incorrect. The problem, observed on powerpc64-linux, caused the loop to iterate over the wrong set of limbs, leading to incorrect code generation. The fix adjusts the loop’s starting point and increment logic to match the expected behavior for big-endian byte order.
In Details
The separate_ext lowerer for _BitInt types handles sign extension. On big-endian targets, the loop that copies the sign-extended bits to higher-order limbs had an incorrect condition. It used _36 = _35 + 18446744073709551615 (effectively _35 - 1) and compared against 0, intending to iterate downwards from an initial limb index. However, the initial index and the decrement logic were mismatched, causing it to process incorrect limbs. This patch corrects the loop to iterate through the correct range of limbs, ensuring consistent behavior with little-endian targets.
- bit-integer lowering
- The process of converting high-level arbitrary-width integer types (
_BitInt) into sequences of machine-level operations or types. - big-endian
- A computer architecture where the most significant byte of a multi-byte word is stored at the lowest memory address.
- little-endian
- A computer architecture where the least significant byte of a multi-byte word is stored at the lowest memory address.
- sign extension
- The process of filling the most significant bits of a number with copies of the sign bit when converting it to a larger data type. This preserves the sign of the number.