ADDR_EXPR and nonnull
authorKugan Vivekanandarajah <kuganv@linaro.org>
Fri, 21 Oct 2016 20:13:55 +0000 (20:13 +0000)
committerKugan Vivekanandarajah <kugan@gcc.gnu.org>
Fri, 21 Oct 2016 20:13:55 +0000 (20:13 +0000)
ADDR_EXPR and nonnull
gcc/ChangeLog:

2016-10-21  Kugan Vivekanandarajah  <kuganv@linaro.org>

* ipa-prop.c (ipa_compute_jump_functions_for_edge): Create nonzero
value range for pointers in more cases.

gcc/testsuite/ChangeLog:

2016-10-21  Kugan Vivekanandarajah  <kuganv@linaro.org>

* gcc.dg/ipa/vrp5.c: New test.
* gcc.dg/ipa/vrp6.c: New test.

From-SVN: r241428

gcc/ChangeLog
gcc/ipa-prop.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/vrp5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/vrp6.c [new file with mode: 0644]

index a2f86411661ea641a269becf425038f0d4a923fe..fd28129e448c5c2b0aa1ae4bad455b6f238eb7d3 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-21  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       * ipa-prop.c (ipa_compute_jump_functions_for_edge): Create nonzero
+       value range for pointers in more cases.
+
 2016-10-21  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_add_constant_internal):
index 353b63821a95384f0c9fcf7fa1e4fdf5f44bc669..16298703fa695e5efc84f45aa5f3d6c1719ec1e9 100644 (file)
@@ -1670,9 +1670,17 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 
       if (POINTER_TYPE_P (TREE_TYPE (arg)))
        {
+         bool addr_nonzero = false;
+         bool strict_overflow = false;
+
          if (TREE_CODE (arg) == SSA_NAME
              && param_type
              && get_ptr_nonnull (arg))
+           addr_nonzero = true;
+         else if (tree_single_nonzero_warnv_p (arg, &strict_overflow))
+           addr_nonzero = true;
+
+         if (addr_nonzero)
            {
              jfunc->vr_known = true;
              jfunc->m_vr.type = VR_ANTI_RANGE;
index 2a67241d4b02a2e9193960a94ec3e6397d629345..62aa521b596e7044c714bec7da2d8b2819706b7c 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-21  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       * gcc.dg/ipa/vrp5.c: New test.
+       * gcc.dg/ipa/vrp6.c: New test.
+
 2016-10-21  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * gcc.target/aarch64/test_frame_17.c: New test.
diff --git a/gcc/testsuite/gcc.dg/ipa/vrp5.c b/gcc/testsuite/gcc.dg/ipa/vrp5.c
new file mode 100644 (file)
index 0000000..571798d
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-cp-details -fdump-tree-vrp1" } */
+
+static __attribute__((noinline, noclone))
+int foo (int *p)
+{
+  if (!p)
+    return 0;
+  *p = 1;
+}
+
+struct st
+{
+  int a;
+  int b;
+};
+
+int arr1[10];
+int a;
+int bar (struct st *s)
+{
+  int arr2[10];
+  int b;
+  if (!s)
+    return 0;
+  foo (&s->a);
+  foo (&a);
+  foo (&b);
+  foo (&arr1[1]);
+  foo (&arr2[1]);
+}
+
+/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */
+/* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/vrp6.c b/gcc/testsuite/gcc.dg/ipa/vrp6.c
new file mode 100644 (file)
index 0000000..971db44
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-cp-details -fdump-tree-vrp1" } */
+
+static __attribute__((noinline, noclone))
+int foo (int *p)
+{
+  if (!p)
+    return 0;
+  *p = 1;
+}
+
+struct st
+{
+  int a;
+  int b;
+};
+
+struct st s2;
+int a;
+int bar (struct st *s)
+{
+  struct st s3;
+  int b;
+  if (!s)
+    return 0;
+  foo (&s->a);
+  foo (&s2.a);
+  foo (&s3.a);
+  foo (&a);
+  foo (&b);
+}
+
+/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */
+/* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */