https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129193
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:40a9b7537cb93a7e5265c17597ca751cee182f5d commit r17-7071-g40a9b7537cb93a7e5265c17597ca751cee182f5d Author: Jakub Jelinek <[email protected]> Date: Thu Dec 3 11:22:14 2026 +0100 combine: Fix wrong-code due to force_int_to_mode [PR129193] The following testcase is miscompiled on x86_64-linux when trying to simplify (set (reg:DI 113) (lshiftrt:DI (subreg:DI (not:TI (lshiftrt:TI (reg:TI 106 [ x ]) (const_int 27 [0x1b]))) 0) (const_int 63 [0x3f]))) (note, the not vs. lshiftrt nesting is exchanged already earlier because in the end it doesn't make a difference when we use lowpart subreg). The problem is that force_int_to_mode like most of combine.cc performs everything on HOST_WIDE_INTs. force_int_to_mode is called recursively, on the NOT above with xmode TImode, mask of 0x8000000000000000 (we are testing the sign bit of the DImode subreg), and the NOT case (second hunk) actually verifies that floor_log2 of the mask (63) + the shift count (27) is smaller than precision of xmode (TImode, i.e. 128 bits). It is, great, but because we perform everything in HOST_WIDE_INTs, when the code does temp = gen_int_mode (mask << INTVAL (XEXP (XEXP (x, 0), 1)), xmode); it shits that HOST_WIDE_INT_UC (0x8000000000000000) left by 27 and the only significant bit is shifted away, so the NOT is actually completely ignored because it is turned into XOR with 0. The code was already testing that the shift count must be smaller than HOST_BITS_PER_WIDE_INT, but as this shows, until we rewrite this to work on wide_ints, we need to make sure that the sum of the shift count and floor_log2 (mask) is smaller than xmode precision and also smaller than HOST_BITS_PER_WIDE_INT. The following patch checks that, and also similarly adjusts the IOR/XOR case earlier that the NOT case attempts to match. 2026-12-03 Jakub Jelinek <[email protected]> PR rtl-optimization/129193 * combine.cc (force_int_to_mode) <case XOR>: Make sure for non-HWI_COMPUTABLE_MODE_Ps we don't shift away significant bits. <case NOT>: Likewise. * gcc.dg/pr129193.c: New test. Reviewed-by: Richard Biener <[email protected]>
