public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/112746] Missed optimization for exact division with multi-use addition chain
Date: Tue, 28 Nov 2023 16:28:37 +0000	[thread overview]
Message-ID: <bug-112746-4-yNndSRh0dR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112746-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|Missed optimization for     |Missed optimization for
                   |redundancy computation      |exact division with
                   |elimination (fre1(tree) for |multi-use addition chain
                   |global variable)            |
   Last reconfirmed|                            |2023-11-28

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue with test2 is that with value-numbering we have

(n.3_1 * 2 + n.3_1) / n.3_1

and that does not simplify.  That is, we do not simplify 2 * n + n to
3 * n as in general that wouldn't be profitable if 2 * n is live after
the use is elided (and it is live since it's stored to 'b').

Which means we ask for (n.3_1 * 2 + n.3_1) / n.3_1 which we currently
cannot simplify to a constant.  Handling cases like this in match.pd
feels wrong.

Note that with -fwrapv the optimization wouldn't be valid.

Other passes face the same issue, 'b' keeps n*2 live so an add
looks cheaper than to compute n*3 for the division.  We're not
anticipating the division here.

But:

  _3 = n.3_1 + _2;
  _4 = _3 / n.3_1;

could be simplified to

  _5 = _2 / n.3_1;
  _4 = _5 + 1;

if we know _2 is a multiple of n.3_1 which then could be simplified as well.

Note that all passes doing analyses on addition chains also stop at the
multi-use, so we'd need to improve at that point somehow.

      reply	other threads:[~2023-11-28 16:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 16:10 [Bug tree-optimization/112746] New: Missed optimization for redundancy computation elimination (fre1(tree) for global variable) 652023330028 at smail dot nju.edu.cn
2023-11-28 16:28 ` rguenth at gcc dot gnu.org [this message]

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-112746-4-yNndSRh0dR@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).