public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110731] [11/12/13/14 Regression] Wrong-code because of wide-int division since r5-424 Date: Wed, 19 Jul 2023 07:56:40 +0000 [thread overview] Message-ID: <bug-110731-4-16kbXTyvgV@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110731-4@http.gcc.gnu.org/bugzilla/> 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.
next prev parent reply other threads:[~2023-07-19 7:56 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-19 7:18 [Bug tree-optimization/110731] New: " jakub at gcc dot gnu.org 2023-07-19 7:19 ` [Bug tree-optimization/110731] " jakub at gcc dot gnu.org 2023-07-19 7:39 ` pinskia at gcc dot gnu.org 2023-07-19 7:56 ` jakub at gcc dot gnu.org [this message] 2023-07-19 11:50 ` cvs-commit at gcc dot gnu.org 2023-07-19 12:24 ` cvs-commit at gcc dot gnu.org 2023-07-19 17:56 ` [Bug tree-optimization/110731] [11/12 " jakub at gcc dot gnu.org 2023-12-16 0:37 ` cvs-commit at gcc dot gnu.org 2023-12-17 13:55 ` cvs-commit at gcc dot gnu.org 2024-06-12 11:58 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110731-4-16kbXTyvgV@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).