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/96930] Failure to optimize out arithmetic with bigger size when it can't matter with division transformed into right shift
Date: Sun, 03 Jan 2021 22:51:26 +0000	[thread overview]
Message-ID: <bug-96930-4-FfiNWHKjOl@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96930-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The optimization is there, but just has different conditions:
            /* 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)));
in C, and
              /* 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)));
So, in C++ we only try to shorten divisions (and modulo) if the first operand
has been extended, rather than the second one.
Anyway, if we optimize this in the middle-end, it won't be needed to change the
FE.

  parent reply	other threads:[~2021-01-03 22:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 20:47 [Bug tree-optimization/96930] New: Failure to optimize out 64-bit arithmetic when it can't happen " gabravier at gmail dot com
2020-09-04  6:41 ` [Bug tree-optimization/96930] Failure to optimize out arithmetic with bigger size when it can't matter " rguenth at gcc dot gnu.org
2021-01-02 10:04 ` jakub at gcc dot gnu.org
2021-01-02 10:53 ` jakub at gcc dot gnu.org
2021-01-03 10:24 ` gabravier at gmail dot com
2021-01-03 10:52 ` jakub at gcc dot gnu.org
2021-01-03 12:06 ` gabravier at gmail dot com
2021-01-03 14:17 ` jakub at gcc dot gnu.org
2021-01-03 22:51 ` jakub at gcc dot gnu.org [this message]
2021-01-04 13:31 ` jakub at gcc dot gnu.org
2021-01-05 15:34 ` cvs-commit at gcc dot gnu.org
2023-02-18  2:09 ` gabravier at gmail dot com

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-96930-4-FfiNWHKjOl@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).