From f75036994f9d6945265d02cb29de502d6d7d538d Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Fri, 21 Oct 2016 20:13:55 +0000 Subject: [PATCH] ADDR_EXPR and nonnull ADDR_EXPR and nonnull gcc/ChangeLog: 2016-10-21 Kugan Vivekanandarajah * 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 * gcc.dg/ipa/vrp5.c: New test. * gcc.dg/ipa/vrp6.c: New test. From-SVN: r241428 --- gcc/ChangeLog | 5 +++++ gcc/ipa-prop.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/ipa/vrp5.c | 34 +++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/vrp6.c | 34 +++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp5.c create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a2f86411661..fd28129e448 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-10-21 Kugan Vivekanandarajah + + * ipa-prop.c (ipa_compute_jump_functions_for_edge): Create nonzero + value range for pointers in more cases. + 2016-10-21 Wilco Dijkstra * config/aarch64/aarch64.c (aarch64_add_constant_internal): diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 353b63821a9..16298703fa6 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2a67241d4b0..62aa521b596 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-21 Kugan Vivekanandarajah + + * gcc.dg/ipa/vrp5.c: New test. + * gcc.dg/ipa/vrp6.c: New test. + 2016-10-21 Wilco Dijkstra * 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 index 00000000000..571798dab51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/vrp5.c @@ -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 index 00000000000..971db443442 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/vrp6.c @@ -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" } } */ -- 2.30.2