From f773226855968cc652fa6f2b2d9c70d2a5d7acdb Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Wed, 12 Oct 2016 13:54:34 +1100
Subject: [PATCH 2/3] Set-nonnull-range-for-pointer-type
---
gcc/ipa-prop.c | 57 +++++++++++++++++++++++++++++------------
gcc/testsuite/gcc.dg/ipa/vrp4.c | 27 +++++++++++++++++++
2 files changed, 68 insertions(+), 16 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp4.c
@@ -1668,7 +1668,22 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
useful_context = true;
}
- if (!POINTER_TYPE_P (TREE_TYPE (arg)))
+ if (POINTER_TYPE_P (TREE_TYPE (arg)))
+ {
+ if (TREE_CODE (arg) == SSA_NAME
+ && param_type
+ && get_ptr_nonnull (arg))
+ {
+ jfunc->vr_known = true;
+ jfunc->m_vr.type = VR_ANTI_RANGE;
+ jfunc->m_vr.min = build_int_cst (TREE_TYPE (arg), 0);
+ jfunc->m_vr.max = build_int_cst (TREE_TYPE (arg), 0);
+ jfunc->m_vr.equiv = NULL;
+ }
+ else
+ gcc_assert (!jfunc->vr_known);
+ }
+ else
{
wide_int min, max;
value_range_type type;
@@ -5602,27 +5617,37 @@ ipcp_update_vr (struct cgraph_node *node)
continue;
if (vr[i].known
- && INTEGRAL_TYPE_P (TREE_TYPE (ddef))
- && !POINTER_TYPE_P (TREE_TYPE (ddef))
&& (vr[i].type == VR_RANGE || vr[i].type == VR_ANTI_RANGE))
{
tree type = TREE_TYPE (ddef);
unsigned prec = TYPE_PRECISION (type);
- if (dump_file)
+ if (INTEGRAL_TYPE_P (TREE_TYPE (ddef)))
+ {
+ if (dump_file)
+ {
+ fprintf (dump_file, "Setting value range of param %u ", i);
+ fprintf (dump_file, "%s[",
+ (vr[i].type == VR_ANTI_RANGE) ? "~" : "");
+ print_decs (vr[i].min, dump_file);
+ fprintf (dump_file, ", ");
+ print_decs (vr[i].max, dump_file);
+ fprintf (dump_file, "]\n");
+ }
+ set_range_info (ddef, vr[i].type,
+ wide_int_storage::from (vr[i].min, prec,
+ TYPE_SIGN (type)),
+ wide_int_storage::from (vr[i].max, prec,
+ TYPE_SIGN (type)));
+ }
+ else if (POINTER_TYPE_P (TREE_TYPE (ddef))
+ && vr[i].type == VR_ANTI_RANGE
+ && wi::eq_p (vr[i].min, 0)
+ && wi::eq_p (vr[i].max, 0))
{
- fprintf (dump_file, "Setting value range of param %u ", i);
- fprintf (dump_file, "%s[",
- (vr[i].type == VR_ANTI_RANGE) ? "~" : "");
- print_decs (vr[i].min, dump_file);
- fprintf (dump_file, ", ");
- print_decs (vr[i].max, dump_file);
- fprintf (dump_file, "]\n");
+ if (dump_file)
+ fprintf (dump_file, "Setting nonnull for %u\n", i);
+ set_ptr_nonnull (ddef);
}
- set_range_info (ddef, vr[i].type,
- wide_int_storage::from (vr[i].min, prec,
- TYPE_SIGN (type)),
- wide_int_storage::from (vr[i].max, prec,
- TYPE_SIGN (type)));
}
}
}
new file mode 100644
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-cp-details" } */
+
+static __attribute__((noinline, noclone))
+int foo (int *p)
+{
+ if (!p)
+ return 0;
+ *p = 1;
+}
+
+struct st
+{
+ int a;
+ int b;
+};
+
+int bar (struct st *s)
+{
+
+ if (!s)
+ return 0;
+ foo (&s->a);
+ foo (&s->b);
+}
+
+/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */
--
2.7.4