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/99079] Maybe a wrong code since r6-1462-g4ab1e111ef0669bb
Date: Fri, 12 Feb 2021 18:56:46 +0000	[thread overview]
Message-ID: <bug-99079-4-FAivDg7SaI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99079-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99079

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 50175
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50175&action=edit
gcc11-pr99079.patch

Untested fix.
The problem is that the tree_nop_conversion_p (type, TREE_TYPE (@3))
test actually didn't test what it was meant to test, in
(mod @0 (convert?@3 (...)))
TREE_TYPE (@3) is the type of the second argument of the modulo, so
necessarily compatible with type (compatible also with TREE_TYPE (@0)).
But, I think we actually don't need to require only nop conversions, which are
certainly fine.
If the conversion is narrowing, i.e. TREE_TYPE (@1) is wider than type, then
we know that @1 is some power of two and after the cast, it will be either 0
(but then UB, so we can rule that out), or that power of two.
For widening conversion where TREE_TYPE (@1) is unsigned it is also fine,
@1 will be some power of two (0 being UB) and @1 - 1 is a mask we can use after
widening it to the type of the mod.
The only problematic case is widening conversion where TREE_TYPE (@1) is
signed,
as the testcase shows, if the power of two is negative, i.e. msb set and all
other bits clear, then the widening cast turns that into 0xffffffff80000000
(if type is unsigned) and as that is not a power of two, we can't transform it
into a mask by 0x7fffffff.

  parent reply	other threads:[~2021-02-12 18:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 17:22 [Bug tree-optimization/99079] New: " marxin at gcc dot gnu.org
2021-02-12 17:22 ` [Bug tree-optimization/99079] " marxin at gcc dot gnu.org
2021-02-12 17:51 ` jakub at gcc dot gnu.org
2021-02-12 18:56 ` jakub at gcc dot gnu.org [this message]
2021-02-12 19:09 ` jakub at gcc dot gnu.org
2021-02-12 19:11 ` jakub at gcc dot gnu.org
2021-02-12 19:21 ` jakub at gcc dot gnu.org
2021-02-15  8:17 ` cvs-commit at gcc dot gnu.org
2021-02-15  8:20 ` [Bug tree-optimization/99079] [8/9/10 Regression] " jakub at gcc dot gnu.org
2021-03-19 23:29 ` cvs-commit at gcc dot gnu.org
2021-03-20  8:07 ` [Bug tree-optimization/99079] [8/9 " jakub at gcc dot gnu.org
2021-04-20 23:32 ` cvs-commit at gcc dot gnu.org
2021-04-22 16:50 ` cvs-commit at gcc dot gnu.org
2021-04-22 17:11 ` 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-99079-4-FAivDg7SaI@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: link
Be 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).