public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4082] use local range for one more pattern in match.pd
@ 2023-09-18  2:19 Jiu Fu Guo
  0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2023-09-18  2:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:55b22a6f630e76a0be913ced8bf1b017eaffd89b

commit r14-4082-g55b22a6f630e76a0be913ced8bf1b017eaffd89b
Author: Jiufu Guo <guojiufu@linux.ibm.com>
Date:   Wed Sep 13 16:12:05 2023 +0800

    use local range for one more pattern in match.pd
    
    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".
    
            PR middle-end/111303
    
    gcc/ChangeLog:
    
            * match.pd ((t * 2) / 2): Update pattern.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/pr111303.c: New test.

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

diff --git a/gcc/match.pd b/gcc/match.pd
index 39c9c81966a..87edf0e75c3 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"} } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-18  2:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18  2:19 [gcc r14-4082] use local range for one more pattern in match.pd Jiu Fu Guo

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).