From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: "hernandez, aldy" <aldyh@redhat.com>
Subject: [COMMITTED] Check if varying may also be non-negative.
Date: Wed, 26 Oct 2022 09:49:36 -0400 [thread overview]
Message-ID: <a4eb1be6-f004-3699-4657-42f98eef6480@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 399 bytes --]
When strict enums are in use, we don't always get ranges reduced
sufficiently thru casts and such. Ranger vrp has been missing the odd
case because I didn't notice that gimple_stmt_nonnegative_warnv_p() use
to be called on all integral results that were varying, not just calls
like it was doing. this corrects that.
Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed.
Andrew
[-- Attachment #2: 0001 --]
[-- Type: text/plain, Size: 1220 bytes --]
commit a87819b8f1b890d36a3f05bd9de80be20e9525dd
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Tue Oct 25 15:16:47 2022 -0400
Check if varying may also be non-negative.
When using strict enums, we can sometimes turn varying into a better
range.
* gimple-range-fold.cc (fold_using_range::fold_stmt): Check if
stmt is non-negative and adjust the range.
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index f91923782dc..a899d8260b3 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -494,6 +494,14 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name)
else if (is_a<gassign *> (s) && gimple_assign_rhs_code (s) == COND_EXPR)
res = range_of_cond_expr (r, as_a<gassign *> (s), src);
+ // If the result is varying, check for basic nonnegativeness.
+ // Specifically this helps for now with strict enum in cases like
+ // g++.dg/warn/pr33738.C.
+ bool so_p;
+ if (res && r.varying_p () && INTEGRAL_TYPE_P (r.type ())
+ && gimple_stmt_nonnegative_warnv_p (s, &so_p))
+ r.set_nonnegative (r.type ());
+
if (!res)
{
// If no name specified or range is unsupported, bail.
reply other threads:[~2022-10-26 13:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=a4eb1be6-f004-3699-4657-42f98eef6480@redhat.com \
--to=amacleod@redhat.com \
--cc=aldyh@redhat.com \
--cc=gcc-patches@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).