This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH PR c/71699] Handle pointer arithmetic in nonzero tree checks


On Thu, 30 Jun 2016, Manish Goregaokar wrote:

Alright, the following patch was tested and it works

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 3b9500d..0d82018 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -13199,6 +13199,9 @@ tree_binary_nonzero_warnv_p (enum tree_code code,
  switch (code)
    {
    case POINTER_PLUS_EXPR:
+      return flag_delete_null_pointer_checks
+            && (tree_expr_nonzero_warnv_p (op0, strict_overflow_p)
+                || tree_expr_nonzero_warnv_p (op1, strict_overflow_p));
    case PLUS_EXPR:
      if (ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_UNDEFINED (type))
    {

So, what prevents us from deciding that p+(0-p) is nonzero when p is? Not sure if it is strictly legal in all languages, but I wouldn't be surprised if there was at least one language where optimizations could lead to such expressions.

I think this is an exciting optimization, but I was always too scared to try anything like this.

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]