https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122266
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2025-10-13
CC| |roger at nextmovesoftware dot
com
--- Comment #4 from Roger Sayle <roger at nextmovesoftware dot com> ---
This seems to be a miscompilation of GCC itself.
combine.cc's simplify_shift_const is called (during the simplification of i2src
in try_combine) with:
x = (ashiftrt:TI (reg:TI 107 [ _1 ])
(const_int 1 [0x1]))
rtx_code = ASHIFTRT
result_mode = E_TImode
varop = (reg:TI 107 [ _1 ])
count = 1
yet somehow returns a corrupted value of x [at the bottom of the function]
x = (ashiftrt:TI (reg:TI 107 [ _1 ])
(const_int 127 [0x7f]))
Something bonkers is going on because (according to gdb), the gen_lowpart
on line 11437 is getting called with arguments:
mode = E_TImode
x = (ashiftrt:TI (reg:TI 107 [ _1 ])
(const_int 127 [0x7f]))
i.e. when it shouldn't need to be called.
The reduced testcase I'm using is:
signed __int128 foo(signed __int128 x) {
signed __int128 t = x >> 127;
return ((x^t)>>1)^t;
}
Note this doesn't happen if the type is "unsigned long" and "t = x >> 63", so
it's somehow specific to __int128 [I'd initially suspected nonzero_bits].
Perhaps an register (x argument) is in appropriately getting clobbered.