From: Aldy Hernandez <aldyh@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>,
Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [COMMITTED 03/16] Make some Value_Range's explicitly integer.
Date: Tue, 30 Apr 2024 10:38:38 +0200 [thread overview]
Message-ID: <CAGm3qMV_uF__O+SR+A7ARst830MCap=7Xrq8hdLYCMPt5_hkiA@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc1ETaP4ihkudOy+AQUGS8GmwtyJj933UUODWpNZyh6cgg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5099 bytes --]
Ughhh, you're right. Thanks for spotting this.
I'm testing the attached patch and will commit if it passes tests.
Aldy
On Tue, Apr 30, 2024 at 9:46 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Sun, Apr 28, 2024 at 9:07 PM Aldy Hernandez <aldyh@redhat.com> wrote:
> >
> > Fix some Value_Range's that we know ahead of time will be only
> > integers. This avoids using the polymorphic Value_Range unnecessarily
>
> But isn't Value_Range a variable-size irange but int_range<2> doesn't
> support more than two sub-ranges?
>
> So it doesn't look obvious that this isn't actually a regression?
>
> Richard.
>
> > gcc/ChangeLog:
> >
> > * gimple-ssa-warn-access.cc (check_nul_terminated_array): Make Value_Range an int_range.
> > (memmodel_to_uhwi): Same
> > * tree-ssa-loop-niter.cc (refine_value_range_using_guard): Same.
> > (determine_value_range): Same.
> > (infer_loop_bounds_from_signedness): Same.
> > (scev_var_range_cant_overflow): Same.
> > ---
> > gcc/gimple-ssa-warn-access.cc | 4 ++--
> > gcc/tree-ssa-loop-niter.cc | 12 ++++++------
> > 2 files changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
> > index dedaae27b31..450c1caa765 100644
> > --- a/gcc/gimple-ssa-warn-access.cc
> > +++ b/gcc/gimple-ssa-warn-access.cc
> > @@ -330,7 +330,7 @@ check_nul_terminated_array (GimpleOrTree expr, tree src, tree bound)
> > wide_int bndrng[2];
> > if (bound)
> > {
> > - Value_Range r (TREE_TYPE (bound));
> > + int_range<2> r (TREE_TYPE (bound));
> >
> > get_range_query (cfun)->range_of_expr (r, bound);
> >
> > @@ -2816,7 +2816,7 @@ memmodel_to_uhwi (tree ord, gimple *stmt, unsigned HOST_WIDE_INT *cstval)
> > {
> > /* Use the range query to determine constant values in the absence
> > of constant propagation (such as at -O0). */
> > - Value_Range rng (TREE_TYPE (ord));
> > + int_range<2> rng (TREE_TYPE (ord));
> > if (!get_range_query (cfun)->range_of_expr (rng, ord, stmt)
> > || !rng.singleton_p (&ord))
> > return false;
> > diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
> > index c6d010f6d89..cbc9dbc5a1f 100644
> > --- a/gcc/tree-ssa-loop-niter.cc
> > +++ b/gcc/tree-ssa-loop-niter.cc
> > @@ -214,7 +214,7 @@ refine_value_range_using_guard (tree type, tree var,
> > get_type_static_bounds (type, mint, maxt);
> > mpz_init (minc1);
> > mpz_init (maxc1);
> > - Value_Range r (TREE_TYPE (varc1));
> > + int_range<2> r (TREE_TYPE (varc1));
> > /* Setup range information for varc1. */
> > if (integer_zerop (varc1))
> > {
> > @@ -368,7 +368,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
> > gphi_iterator gsi;
> >
> > /* Either for VAR itself... */
> > - Value_Range var_range (TREE_TYPE (var));
> > + int_range<2> var_range (TREE_TYPE (var));
> > get_range_query (cfun)->range_of_expr (var_range, var);
> > if (var_range.varying_p () || var_range.undefined_p ())
> > rtype = VR_VARYING;
> > @@ -382,7 +382,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
> >
> > /* Or for PHI results in loop->header where VAR is used as
> > PHI argument from the loop preheader edge. */
> > - Value_Range phi_range (TREE_TYPE (var));
> > + int_range<2> phi_range (TREE_TYPE (var));
> > for (gsi = gsi_start_phis (loop->header); !gsi_end_p (gsi); gsi_next (&gsi))
> > {
> > gphi *phi = gsi.phi ();
> > @@ -408,7 +408,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
> > involved. */
> > if (wi::gt_p (minv, maxv, sgn))
> > {
> > - Value_Range vr (TREE_TYPE (var));
> > + int_range<2> vr (TREE_TYPE (var));
> > get_range_query (cfun)->range_of_expr (vr, var);
> > if (vr.varying_p () || vr.undefined_p ())
> > rtype = VR_VARYING;
> > @@ -4367,7 +4367,7 @@ infer_loop_bounds_from_signedness (class loop *loop, gimple *stmt)
> >
> > low = lower_bound_in_type (type, type);
> > high = upper_bound_in_type (type, type);
> > - Value_Range r (TREE_TYPE (def));
> > + int_range<2> r (TREE_TYPE (def));
> > get_range_query (cfun)->range_of_expr (r, def);
> > if (!r.varying_p () && !r.undefined_p ())
> > {
> > @@ -5426,7 +5426,7 @@ scev_var_range_cant_overflow (tree var, tree step, class loop *loop)
> > if (!def_bb || !dominated_by_p (CDI_DOMINATORS, loop->latch, def_bb))
> > return false;
> >
> > - Value_Range r (TREE_TYPE (var));
> > + int_range<2> r (TREE_TYPE (var));
> > get_range_query (cfun)->range_of_expr (r, var);
> > if (r.varying_p () || r.undefined_p ())
> > return false;
> > --
> > 2.44.0
> >
>
[-- Attachment #2: 0001-Change-int_range-2-to-infinite-precision.patch --]
[-- Type: text/x-patch, Size: 4232 bytes --]
From f43749b8381a9b1b0a4f1ab2cb288cb821f04319 Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Tue, 30 Apr 2024 10:36:58 +0200
Subject: [PATCH] Change int_range<2> to infinite precision.
In my previous change I mistakenly changed Value_Range to
int_range<2>. The former has "infinite" precision for integer ranges,
whereas int_range<2> has two sub-ranges. This should have been
int_range_max.
gcc/ChangeLog:
* gimple-ssa-warn-access.cc (check_nul_terminated_array): Change
int_range<2> to int_range_max.
(memmodel_to_uhwi): Same.
* tree-ssa-loop-niter.cc (refine_value_range_using_guard): Same.
(determine_value_range): Same.
(infer_loop_bounds_from_signedness): Same.
(scev_var_range_cant_overflow): Same.
---
gcc/gimple-ssa-warn-access.cc | 4 ++--
gcc/tree-ssa-loop-niter.cc | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 450c1caa765..2c10d19e7f3 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -330,7 +330,7 @@ check_nul_terminated_array (GimpleOrTree expr, tree src, tree bound)
wide_int bndrng[2];
if (bound)
{
- int_range<2> r (TREE_TYPE (bound));
+ int_range_max r (TREE_TYPE (bound));
get_range_query (cfun)->range_of_expr (r, bound);
@@ -2816,7 +2816,7 @@ memmodel_to_uhwi (tree ord, gimple *stmt, unsigned HOST_WIDE_INT *cstval)
{
/* Use the range query to determine constant values in the absence
of constant propagation (such as at -O0). */
- int_range<2> rng (TREE_TYPE (ord));
+ int_range_max rng (TREE_TYPE (ord));
if (!get_range_query (cfun)->range_of_expr (rng, ord, stmt)
|| !rng.singleton_p (&ord))
return false;
diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index adbc1936982..0fde07e626f 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -214,7 +214,7 @@ refine_value_range_using_guard (tree type, tree var,
get_type_static_bounds (type, mint, maxt);
mpz_init (minc1);
mpz_init (maxc1);
- int_range<2> r (TREE_TYPE (varc1));
+ int_range_max r (TREE_TYPE (varc1));
/* Setup range information for varc1. */
if (integer_zerop (varc1))
{
@@ -368,7 +368,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
gphi_iterator gsi;
/* Either for VAR itself... */
- int_range<2> var_range (TREE_TYPE (var));
+ int_range_max var_range (TREE_TYPE (var));
get_range_query (cfun)->range_of_expr (var_range, var);
if (var_range.varying_p () || var_range.undefined_p ())
rtype = VR_VARYING;
@@ -382,7 +382,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
/* Or for PHI results in loop->header where VAR is used as
PHI argument from the loop preheader edge. */
- int_range<2> phi_range (TREE_TYPE (var));
+ int_range_max phi_range (TREE_TYPE (var));
for (gsi = gsi_start_phis (loop->header); !gsi_end_p (gsi); gsi_next (&gsi))
{
gphi *phi = gsi.phi ();
@@ -408,7 +408,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off,
involved. */
if (wi::gt_p (minv, maxv, sgn))
{
- int_range<2> vr (TREE_TYPE (var));
+ int_range_max vr (TREE_TYPE (var));
get_range_query (cfun)->range_of_expr (vr, var);
if (vr.varying_p () || vr.undefined_p ())
rtype = VR_VARYING;
@@ -4367,7 +4367,7 @@ infer_loop_bounds_from_signedness (class loop *loop, gimple *stmt)
low = lower_bound_in_type (type, type);
high = upper_bound_in_type (type, type);
- int_range<2> r (TREE_TYPE (def));
+ int_range_max r (TREE_TYPE (def));
get_range_query (cfun)->range_of_expr (r, def);
if (!r.varying_p () && !r.undefined_p ())
{
@@ -5426,7 +5426,7 @@ scev_var_range_cant_overflow (tree var, tree step, class loop *loop)
if (!def_bb || !dominated_by_p (CDI_DOMINATORS, loop->latch, def_bb))
return false;
- int_range<2> r (TREE_TYPE (var));
+ int_range_max r (TREE_TYPE (var));
get_range_query (cfun)->range_of_expr (r, var);
if (r.varying_p () || r.undefined_p ())
return false;
--
2.44.0
next prev parent reply other threads:[~2024-04-30 8:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 19:05 [PATCH 00/16] prange supporting patchset Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 01/16] Make vrange an abstract class Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 02/16] Add a virtual vrange destructor Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 03/16] Make some Value_Range's explicitly integer Aldy Hernandez
2024-04-30 7:46 ` Richard Biener
2024-04-30 8:38 ` Aldy Hernandez [this message]
2024-04-28 19:05 ` [COMMITTED 04/16] Add tree versions of lower and upper bounds to vrange Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 05/16] Move bitmask routines to vrange base class Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 06/16] Remove GTY support for vrange and derived classes Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 07/16] Make fold_cond_with_ops use a boolean type for range_true/range_false Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 08/16] Change range_includes_zero_p argument to a reference Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 09/16] Verify that reading back from vrange_storage doesn't drop bits Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 10/16] Accept a vrange in get_legacy_range Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 11/16] Move get_bitmask_from_range out of irange class Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 12/16] Make some integer specific ranges generic Value_Range's Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 13/16] Accept any vrange in range_includes_zero_p Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 14/16] Move print_irange_* out of vrange_printer class Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 15/16] Remove range_zero and range_nonzero Aldy Hernandez
2024-04-28 19:05 ` [COMMITTED 16/16] Callers of irange_bitmask must normalize value/mask pairs Aldy Hernandez
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='CAGm3qMV_uF__O+SR+A7ARst830MCap=7Xrq8hdLYCMPt5_hkiA@mail.gmail.com' \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.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).