public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/98028] [8/9/10/11 Regression] __builtin_sub_overflow_p not folded to const when some constraints are known
Date: Fri, 12 Feb 2021 14:43:45 +0000	[thread overview]
Message-ID: <bug-98028-4-xwUf84XcpP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98028-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
I would expect in gcc 12 we'll be handling it differently than that.

I have equivalences/relations up and running and will eventually get to
applying those to general statements... which I haven't gotten to yet.

the gimple_fold() routine uses fold_range () via range-ops to calculate a
result. I plan to additionally check if there is a relation between the
operands, and if so, invoke another range_ops routine to see if that relation
makes any further adjustments.

in this case, we'd have VARYING - VARYING, so ranges would resolve as expected
to VARYING.

A query if there is a relation between j_1 and i_2
=========== BB 4 ============
j_1(D)  unsigned int VARYING
i_2(D)  unsigned int VARYING
Equivalence set : [j_1(D), i_2(D)]
    <bb 4> :
    _3 = i_2(D) - j_1(D);
    return _3;
shows they are in an equivalence set, so that would be trivial to fold to 0 for
MINUS_EXPR.

as well, if we see other relations
 if (j > i) __builtin_unreachable();
  return i - j;

=========== BB 4 ============
j_1(D)  unsigned int VARYING
i_2(D)  unsigned int VARYING
Relational : (j_1(D) <= i_2(D))
    <bb 4> :
    _3 = i_2(D) - j_1(D);
    return _3;

it would likewise be pretty straightforward to add the restriction that _3 will
be [0, +INF]  (or [1, +INF] if it were j_1 < i_2)
If the relation is !=, we could also provide ~[0,0]

I'd expect the routine for MINUS_EXPR to simply switch on the possible
relations and intersect the current result with this reduced possible outcome.

I hope to get most of this in early in stage 1 and we can begin
enhancing/finding opportunities.
.

  parent reply	other threads:[~2021-02-12 14:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 10:50 [Bug tree-optimization/98028] New: " denis.campredon at gmail dot com
2020-11-27 11:12 ` [Bug tree-optimization/98028] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2021-01-14  9:49 ` rguenth at gcc dot gnu.org
2021-01-14 14:23 ` amacleod at redhat dot com
2021-02-12 13:41 ` jakub at gcc dot gnu.org
2021-02-12 14:43 ` amacleod at redhat dot com [this message]
2021-05-14  9:54 ` [Bug tree-optimization/98028] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:19 ` rguenth at gcc dot gnu.org
2022-05-27  9:44 ` [Bug tree-optimization/98028] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug tree-optimization/98028] [11/12/13/14 " 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-98028-4-xwUf84XcpP@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).