Skip to content

Commit

Permalink
use more get_range_query
Browse files Browse the repository at this point in the history
Hi,

For "get_global_range_query" SSA_NAME_RANGE_INFO can be queried.
For "get_range_query", it could get more context-aware range info.
And look at the implementation of "get_range_query",  it returns
global range if no local fun info.

So, if not quering for SSA_NAME and not chaning the IL, it would
be ok to use get_range_query to replace get_global_range_query.

Patch https://gcc.gnu.org/pipermail/gcc-patches/2023-September/630389.html,
Uses get_range_query could handle more cases.

Compare with previous version:
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/632401.html
This patch remove some unsafe replacement.

Pass bootstrap & regtest on ppc64{,le} and x86_64.
Is this ok for trunk.

BR,
Jeff (Jiufu Guo)

gcc/ChangeLog:

	* fold-const.cc (expr_not_equal_to): Replace get_global_range_query
	by get_range_query.
	* gimple-fold.cc (size_must_be_zero_p): Likewise.
	* gimple-range-fold.cc (fur_source::fur_source): Likewise.
	* gimple-ssa-warn-access.cc (check_nul_terminated_array): Likewise.
	* tree-dfa.cc (get_ref_base_and_extent): Likewise.
  • Loading branch information
Jiufu Guo authored and ouuleilei-bot committed Oct 11, 2023
1 parent c2d62cd commit 3eea596
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 17 deletions.
6 changes: 1 addition & 5 deletions gcc/fold-const.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10877,11 +10877,7 @@ expr_not_equal_to (tree t, const wide_int &w)
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
return false;

if (cfun)
get_range_query (cfun)->range_of_expr (vr, t);
else
get_global_range_query ()->range_of_expr (vr, t);

get_range_query (cfun)->range_of_expr (vr, t);
if (!vr.undefined_p () && !vr.contains_p (w))
return true;
/* If T has some known zero bits and W has any of those bits set,
Expand Down
6 changes: 2 additions & 4 deletions gcc/gimple-fold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,8 @@ size_must_be_zero_p (tree size)
wide_int zero = wi::zero (TYPE_PRECISION (type));
value_range valid_range (type, zero, ssize_max);
value_range vr;
if (cfun)
get_range_query (cfun)->range_of_expr (vr, size);
else
get_global_range_query ()->range_of_expr (vr, size);
get_range_query (cfun)->range_of_expr (vr, size);

if (vr.undefined_p ())
vr.set_varying (TREE_TYPE (size));
vr.intersect (valid_range);
Expand Down
4 changes: 1 addition & 3 deletions gcc/gimple-range-fold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ fur_source::fur_source (range_query *q)
{
if (q)
m_query = q;
else if (cfun)
m_query = get_range_query (cfun);
else
m_query = get_global_range_query ();
m_query = get_range_query (cfun);
m_gori = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/gimple-ssa-warn-access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ check_nul_terminated_array (GimpleOrTree expr, tree src, tree bound)
{
Value_Range r (TREE_TYPE (bound));

get_global_range_query ()->range_of_expr (r, bound);
get_range_query (cfun)->range_of_expr (r, bound);

if (r.undefined_p () || r.varying_p ())
return true;
Expand Down
5 changes: 1 addition & 4 deletions gcc/tree-dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,7 @@ get_ref_base_and_extent (tree exp, poly_int64_pod *poffset,

value_range vr;
range_query *query;
if (cfun)
query = get_range_query (cfun);
else
query = get_global_range_query ();
query = get_range_query (cfun);

if (TREE_CODE (index) == SSA_NAME
&& (low_bound = array_ref_low_bound (exp),
Expand Down

0 comments on commit 3eea596

Please sign in to comment.