From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: richard.sandiford@arm.com, Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] tree-optimization/114151 - handle POLY_INT_CST in get_range_pos_neg
Date: Thu, 29 Feb 2024 09:21:02 +0100 (CET) [thread overview]
Message-ID: <20240229082111.024291329E@imap2.dmz-prg2.suse.org> (raw)
The following switches the logic in chrec_fold_multiply to
get_range_pos_neg since handling POLY_INT_CST possibly mixed with
non-poly ranges will make the open-coding awkward and while not
a perfect fit it should work.
In turn the following makes get_range_pos_neg aware of POLY_INT_CSTs.
I couldn't make it work with poly_wide_int since the compares always
fail to build but poly_widest_int works fine and it should be
semantically the same. I've also changed get_range_pos_neg to
use get_range_query (cfun), problematical passes shouldn't have
a range query activated so it shouldn't make a difference there.
This doesn't make a difference for the PR but not considering
POLY_INT_CSTs was a mistake.
Bootstrap and regtest running on x86_64-unknown-linux-gnu, OK?
Thanks,
Richard.
PR tree-optimization/114151
* tree.cc (get_range_pos_neg): Handle POLY_INT_CST, use
the passes range-query if available.
* tree-chre.cc (chrec_fold_multiply): Use get_range_pos_neg
to see if both operands have the same range.
---
gcc/tree-chrec.cc | 14 ++------------
gcc/tree.cc | 12 +++++++-----
2 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/gcc/tree-chrec.cc b/gcc/tree-chrec.cc
index 2e6c7356d3b..450d018ce6f 100644
--- a/gcc/tree-chrec.cc
+++ b/gcc/tree-chrec.cc
@@ -442,18 +442,8 @@ chrec_fold_multiply (tree type,
if (!ANY_INTEGRAL_TYPE_P (type)
|| TYPE_OVERFLOW_WRAPS (type)
|| integer_zerop (CHREC_LEFT (op0))
- || (TREE_CODE (CHREC_LEFT (op0)) == INTEGER_CST
- && TREE_CODE (CHREC_RIGHT (op0)) == INTEGER_CST
- && (tree_int_cst_sgn (CHREC_LEFT (op0))
- == tree_int_cst_sgn (CHREC_RIGHT (op0))))
- || (get_range_query (cfun)->range_of_expr (rl, CHREC_LEFT (op0))
- && !rl.undefined_p ()
- && (rl.nonpositive_p () || rl.nonnegative_p ())
- && get_range_query (cfun)->range_of_expr (rr,
- CHREC_RIGHT (op0))
- && !rr.undefined_p ()
- && ((rl.nonpositive_p () && rr.nonpositive_p ())
- || (rl.nonnegative_p () && rr.nonnegative_p ()))))
+ || (get_range_pos_neg (CHREC_LEFT (op0))
+ | get_range_pos_neg (CHREC_RIGHT (op0))) != 3)
{
tree left = chrec_fold_multiply (type, CHREC_LEFT (op0), op1);
tree right = chrec_fold_multiply (type, CHREC_RIGHT (op0), op1);
diff --git a/gcc/tree.cc b/gcc/tree.cc
index f801712c9dd..fcc914f0f7a 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -14408,13 +14408,15 @@ get_range_pos_neg (tree arg)
int prec = TYPE_PRECISION (TREE_TYPE (arg));
int cnt = 0;
- if (TREE_CODE (arg) == INTEGER_CST)
+ if (poly_int_tree_p (arg))
{
- wide_int w = wi::sext (wi::to_wide (arg), prec);
- if (wi::neg_p (w))
+ poly_widest_int w = wi::sext (wi::to_poly_widest (arg), prec);
+ if (known_lt (w, 0))
return 2;
- else
+ else if (known_ge (w, 0))
return 1;
+ else
+ return 3;
}
while (CONVERT_EXPR_P (arg)
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
@@ -14434,7 +14436,7 @@ get_range_pos_neg (tree arg)
if (TREE_CODE (arg) != SSA_NAME)
return 3;
value_range r;
- while (!get_global_range_query ()->range_of_expr (r, arg)
+ while (!get_range_query (cfun)->range_of_expr (r, arg)
|| r.undefined_p () || r.varying_p ())
{
gimple *g = SSA_NAME_DEF_STMT (arg);
--
2.35.3
next reply other threads:[~2024-02-29 8:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 8:21 Richard Biener [this message]
2024-02-29 10:34 ` Jakub Jelinek
2024-02-29 13:08 ` Richard Biener
2024-02-29 13:28 ` Jakub Jelinek
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=20240229082111.024291329E@imap2.dmz-prg2.suse.org \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=richard.sandiford@arm.com \
/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).