diff mbox series

use local range for one more pattern in match.pd

Message ID 20230915013921.1868899-1-guojiufu@linux.ibm.com
State New
Headers show
Series use local range for one more pattern in match.pd | expand

Commit Message

Jiufu Guo Sept. 15, 2023, 1:39 a.m. UTC
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.

ATTRIBUTE_RETURNS_NONNULL inline range_query *
get_range_query (const struct function *fun)
{
  return (fun && fun->x_range_query) ? fun->x_range_query : &global_ranges;
}

So, using "get_range_query" would cover more case.
For example, the test case of "pr111303.c".

Bootstrap &regtest pass on ppc64{,le} and x86_64.
Is this ok for trunk?


BR,
Jeff (Jiufu Guo)


	PR middle-end/111303

gcc/ChangeLog:

	* match.pd ((t * 2) / 2): Update pattern.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr111303.c: New test.

---
 gcc/match.pd                             |  4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/pr111303.c | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr111303.c

Comments

Richard Biener Sept. 15, 2023, 6:28 a.m. UTC | #1
On Fri, 15 Sep 2023, Jiufu Guo wrote:

> 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.
> 
> ATTRIBUTE_RETURNS_NONNULL inline range_query *
> get_range_query (const struct function *fun)
> {
>   return (fun && fun->x_range_query) ? fun->x_range_query : &global_ranges;
> }
> 
> So, using "get_range_query" would cover more case.
> For example, the test case of "pr111303.c".
> 
> Bootstrap &regtest pass on ppc64{,le} and x86_64.
> Is this ok for trunk?

OK.

> 
> BR,
> Jeff (Jiufu Guo)
> 
> 
> 	PR middle-end/111303
> 
> gcc/ChangeLog:
> 
> 	* match.pd ((t * 2) / 2): Update pattern.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/tree-ssa/pr111303.c: New test.
> 
> ---
>  gcc/match.pd                             |  4 ++--
>  gcc/testsuite/gcc.dg/tree-ssa/pr111303.c | 15 +++++++++++++++
>  2 files changed, 17 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 693638f8ca0..6bd72ff4d69 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -931,8 +931,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>         bool overflowed = true;
>         value_range vr0, vr1;
>         if (INTEGRAL_TYPE_P (type)
> -	   && get_global_range_query ()->range_of_expr (vr0, @0)
> -	   && get_global_range_query ()->range_of_expr (vr1, @1)
> +	   && get_range_query (cfun)->range_of_expr (vr0, @0)
> +	   && get_range_query (cfun)->range_of_expr (vr1, @1)
>  	   && !vr0.varying_p () && !vr0.undefined_p ()
>  	   && !vr1.varying_p () && !vr1.undefined_p ())
>  	 {
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
> new file mode 100644
> index 00000000000..b703fe4546d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +typedef unsigned int INT;
> +
> +INT
> +foo (INT x, INT y)
> +{
> +  if (x > 100 || y > 100)
> +    return x;
> +  return (x * y) / y;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "return x_..D." 1 "optimized"} } */
> +/* { dg-final { scan-tree-dump-times " / " 0 "optimized"} } */
>
diff mbox series

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 693638f8ca0..6bd72ff4d69 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -931,8 +931,8 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        bool overflowed = true;
        value_range vr0, vr1;
        if (INTEGRAL_TYPE_P (type)
-	   && get_global_range_query ()->range_of_expr (vr0, @0)
-	   && get_global_range_query ()->range_of_expr (vr1, @1)
+	   && get_range_query (cfun)->range_of_expr (vr0, @0)
+	   && get_range_query (cfun)->range_of_expr (vr1, @1)
 	   && !vr0.varying_p () && !vr0.undefined_p ()
 	   && !vr1.varying_p () && !vr1.undefined_p ())
 	 {
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
new file mode 100644
index 00000000000..b703fe4546d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c
@@ -0,0 +1,15 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+typedef unsigned int INT;
+
+INT
+foo (INT x, INT y)
+{
+  if (x > 100 || y > 100)
+    return x;
+  return (x * y) / y;
+}
+
+/* { dg-final { scan-tree-dump-times "return x_..D." 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times " / " 0 "optimized"} } */