https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127556
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:b6c774e09f6e14c2c07101dfd55428aab6350b02 commit r17-7055-gb6c774e09f6e14c2c07101dfd55428aab6350b02 Author: Jiahao Xu <[email protected]> Date: Wed Dec 2 21:33:31 2026 -0700 [PATCH v2] libgcc: Truncate shift count in double-word shift routines [PR127556] When SHIFT_COUNT_TRUNCATED is nonzero, GCC omits shift-count truncations and relies on shift instructions and library routines to truncate the count. However, the double-word shift routines in libgcc2.c (__lshrdi3, __ashldi3 and __ashrdi3) do not truncate the shift count b, so a count with out-of-range upper bits gives wrong results. As suggested by Jeff and Richard, fix this by unconditionally truncating b in __lshrdi3, __ashldi3, and __ashrdi3, which is also safe when !SHIFT_COUNT_TRUNCATED. PR libgcc/127556 libgcc/ChangeLog: * libgcc2.c (__lshrdi3): Mask shift count with 2 * W_TYPE_SIZE - 1. (__ashldi3): Likewise. (__ashrdi3): Likewise. gcc/testsuite/ChangeLog: * gcc.target/loongarch/pr127556.c: New test.
