https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127556

--- Comment #1 from Jiahao Xu <xujiahao at gcc dot gnu.org> ---
Reassigning to middle-end.                                              

The root cause is in expand_shift_1 (gcc/expmed.cc): when
SHIFT_COUNT_TRUNCATED is nonzero, it unconditionally strips a lowpart
SUBREG from the shift count operand (e.g. (subreg:SI (reg:DI b) 0) ->
(reg:DI b)) before trying to expand the shift.

While this is valid for native shift patterns and inline doubleword
shifts (expand_doubleword_shift preserves SHIFT_COUNT_TRUNCATED), it is
invalid when expansion falls back to OPTAB_LIB_WIDEN and emits a libgcc
shift call (e.g. __ashrti3 under -Os).  Libgcc shift helpers do not
truncate their shift count; with the narrowing SUBREG already stripped,
convert_to_mode in expand_binop no longer zero-extends from the original
narrower mode, allowing non-zero upper bits in the inner register to
reach libgcc and cause wrong code.

patch:https://gcc.gnu.org/pipermail/gcc-patches/2026-November/741579.html

Reply via email to