https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110731
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think the problem is earlier. If I divide the same values unsigned, while the representation of the wide_int values is the same, i.e. val = {0, -18014398509481984}, len = 2, precision = 119 for x, when divmod_internal_2 is called, in the signed case it sees x/4wx b_dividend 0x7fffffffc0b0: 0x00000000 0x00000000 0x00000000 0xffc00000 while in the unsigned one x/4wx b_dividend 0x7fffffffc0b0: 0x00000000 0x00000000 0x00000000 0x00400000 and I think the latter is what should be used in both cases, divmod_internal_2 performs unsigned division. So, I think the right fix is: --- gcc/wide-int.cc.jj 2023-06-12 15:47:22.461502821 +0200 +++ gcc/wide-int.cc 2023-07-19 09:52:40.241661869 +0200 @@ -1911,9 +1911,9 @@ wi::divmod_internal (HOST_WIDE_INT *quot } wi_unpack (b_dividend, dividend.get_val (), dividend.get_len (), - dividend_blocks_needed, dividend_prec, sgn); + dividend_blocks_needed, dividend_prec, UNSIGNED); wi_unpack (b_divisor, divisor.get_val (), divisor.get_len (), - divisor_blocks_needed, divisor_prec, sgn); + divisor_blocks_needed, divisor_prec, UNSIGNED); m = dividend_blocks_needed; b_dividend[m] = 0; because at this point we are after the /* Make the divisor and dividend positive and remember what we did. */ if (sgn == SIGNED) { if (wi::neg_p (dividend)) { neg_dividend = -dividend; dividend = neg_dividend; dividend_neg = true; } if (wi::neg_p (divisor)) { neg_divisor = -divisor; divisor = neg_divisor; divisor_neg = true; } } hunk. Of course, this makes a difference only if either the dividend or divisor are the smallest negative value of a type.