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 middle-end/108365] [9/10/11/12/13 Regression] Wrong code with -O0 Date: Tue, 10 Jan 2023 23:59:14 +0000 [thread overview] Message-ID: <bug-108365-4-MiYOXQU13q@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-108365-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108365 --- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think the bug is in the C++ FE: /* When dividing two signed integers, we have to promote to int. unless we divide by a constant != -1. Note that default conversion will have been performed on the operands at this point, so we have to dig out the original type to find out if it was unsigned. */ tree stripped_op1 = tree_strip_any_location_wrapper (op1); shorten = ((TREE_CODE (op0) == NOP_EXPR && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0)))) || (TREE_CODE (stripped_op1) == INTEGER_CST && ! integer_all_onesp (stripped_op1))); compare that to C FE, which does: /* Although it would be tempting to shorten always here, that loses on some targets, since the modulo instruction is undefined if the quotient can't be represented in the computation mode. We shorten only if unsigned or if dividing by something we know != -1. */ shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0)) || (TREE_CODE (op1) == INTEGER_CST && !integer_all_onesp (op1))); C FE does that only if orig_op0 was unsigned, where orig_op0 is what is passed to the function, where op0 is perhaps later promoted. While the way it is written in C++ FE matches both unsigned {char,short} dividend promoted to int, but also the case in the testcase where orig_op0 is (long long) (unsigned long long) (-__INT_MAX__ - 1) unfolded. If op0 is promoted from unsigned type to wider signed type or if op0 has unsigned type, then shortening is of course possible, but if op0 is converted from unsigned type to same sized signed type or to a narrower type, we don't know if it can't be the signed minimum.
next prev parent reply other threads:[~2023-01-10 23:59 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-01-10 22:47 [Bug tree-optimization/108365] New: " vsevolod.livinskiy at gmail dot com 2023-01-10 22:55 ` [Bug tree-optimization/108365] " pinskia at gcc dot gnu.org 2023-01-10 22:55 ` pinskia at gcc dot gnu.org 2023-01-10 23:07 ` [Bug middle-end/108365] " jakub at gcc dot gnu.org 2023-01-10 23:15 ` pinskia at gcc dot gnu.org 2023-01-10 23:36 ` jakub at gcc dot gnu.org 2023-01-10 23:59 ` jakub at gcc dot gnu.org [this message] 2023-01-11 11:47 ` [Bug c++/108365] " jakub at gcc dot gnu.org 2023-01-11 12:10 ` rguenth at gcc dot gnu.org 2023-01-14 9:18 ` cvs-commit at gcc dot gnu.org 2023-01-14 9:23 ` [Bug c++/108365] [9/10/11/12 " jakub at gcc dot gnu.org 2023-02-10 17:47 ` cvs-commit at gcc dot gnu.org 2023-02-10 18:00 ` [Bug c++/108365] [10/11 " jakub at gcc dot gnu.org 2023-05-02 20:14 ` cvs-commit at gcc dot gnu.org 2023-05-03 9:37 ` [Bug c++/108365] [10 " jakub at gcc dot gnu.org 2023-05-03 15:21 ` cvs-commit at gcc dot gnu.org 2023-05-04 7:23 ` jakub 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-108365-4-MiYOXQU13q@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).