https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112733
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu.org --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- On the fold-const.cc side, we IMHO should either do: --- gcc/fold-const.cc.jj 2023-11-28 08:46:28.345803059 +0100 +++ gcc/fold-const.cc 2023-11-28 15:37:28.252327265 +0100 @@ -14563,7 +14563,7 @@ multiple_of_p (tree type, const_tree top && TREE_CODE (op2) == INTEGER_CST && integer_pow2p (bottom) && wi::multiple_of_p (wi::to_widest (op2), - wi::to_widest (bottom), UNSIGNED)) + wi::to_widest (bottom), SIGNED)) return true; op1 = gimple_assign_rhs1 (stmt); because widest_ints are always signed by definition, or --- gcc/fold-const.cc.jj 2023-11-28 08:46:28.345803059 +0100 +++ gcc/fold-const.cc 2023-11-28 15:43:46.730985893 +0100 @@ -14562,8 +14562,11 @@ multiple_of_p (tree type, const_tree top && (op2 = gimple_assign_rhs2 (stmt)) != NULL_TREE && TREE_CODE (op2) == INTEGER_CST && integer_pow2p (bottom) - && wi::multiple_of_p (wi::to_widest (op2), - wi::to_widest (bottom), UNSIGNED)) + && wi::multiple_of_p (widest_int::from (wi::to_wide (op2), + UNSIGNED), + widest_int::from (wi::to_wide (bottom), + UNSIGNED), + UNSIGNED)) return true; op1 = gimple_assign_rhs1 (stmt); to use widest_int but zero extend there everything, or --- gcc/fold-const.cc.jj 2023-11-28 08:46:28.345803059 +0100 +++ gcc/fold-const.cc 2023-11-28 15:45:35.867445679 +0100 @@ -14562,8 +14562,8 @@ multiple_of_p (tree type, const_tree top && (op2 = gimple_assign_rhs2 (stmt)) != NULL_TREE && TREE_CODE (op2) == INTEGER_CST && integer_pow2p (bottom) - && wi::multiple_of_p (wi::to_widest (op2), - wi::to_widest (bottom), UNSIGNED)) + && wi::multiple_of_p (wi::to_wide (op2), wi::to_wide (bottom), + TYPE_SIGN (TREE_TYPE (bottom)))) return true; op1 = gimple_assign_rhs1 (stmt); The last one has the disadvantage that it would ICE if op2 and bottom don't have same precision (but I'd think it would be caller's screw up if that was the case). Given return wi::multiple_of_p (wi::to_widest (top), wi::to_widest (bottom), SIGNED); a few lines earlier in the same patch, I think my preference is the first patch. Thoughts on this?