]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
use local range for one more pattern in match.pd
authorJiufu Guo <guojiufu@linux.ibm.com>
Wed, 13 Sep 2023 08:12:05 +0000 (16:12 +0800)
committerguojiufu <guojiufu@linux.ibm.com>
Mon, 18 Sep 2023 02:18:35 +0000 (10:18 +0800)
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.

gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr111303.c [new file with mode: 0644]

index 39c9c81966a7d168ca4958366eb0acc7c207f734..87edf0e75c3d3f2edb736ae5cc54246c433c7a97 100644 (file)
@@ -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 (file)
index 0000000..b703fe4
--- /dev/null
@@ -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"} } */