re PR middle-end/45098 (Missed induction variable optimization)
authorTom de Vries <tom@codesourcery.com>
Thu, 16 Jun 2011 17:57:08 +0000 (17:57 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Thu, 16 Jun 2011 17:57:08 +0000 (17:57 +0000)
2011-06-16  Tom de Vries  <tom@codesourcery.com>

PR target/45098
* tree-ssa-loop-niter.c (infer_loop_bounds_from_pointer_arith): Disallow
NULL pointer for pointer arithmetic.

From-SVN: r175105

gcc/ChangeLog
gcc/tree-ssa-loop-niter.c

index 29d0f27ccabcedc1154d9b4de74bd72f03596f9f..4ea21cf833923d8d9e1e2875f88b0a288897b397 100644 (file)
@@ -1,3 +1,9 @@
+2011-06-16  Tom de Vries  <tom@codesourcery.com>
+
+       PR target/45098
+       * tree-ssa-loop-niter.c (infer_loop_bounds_from_pointer_arith): Disallow
+       NULL pointer for pointer arithmetic.
+
 2011-06-16  Ramana Radhakrishnan  <ramana.radhakrishnan@linaro.org>
 
        PR target/49398
index fa3ccc63f59202e1a7cd9954d12c0aa09e0987be..cf2f4556395b56fe84705a4b7c500854d8851757 100644 (file)
@@ -2875,6 +2875,16 @@ infer_loop_bounds_from_pointer_arith (struct loop *loop, gimple stmt)
   low = lower_bound_in_type (type, type);
   high = upper_bound_in_type (type, type);
 
+  /* In C, pointer arithmetic p + 1 cannot use a NULL pointer, and p - 1 cannot
+     produce a NULL pointer.  The contrary would mean NULL points to an object,
+     while NULL is supposed to compare unequal with the address of all objects.
+     Furthermore, p + 1 cannot produce a NULL pointer and p - 1 cannot use a
+     NULL pointer since that would mean wrapping, which we assume here not to
+     happen.  So, we can exclude NULL from the valid range of pointer
+     arithmetic.  */
+  if (flag_delete_null_pointer_checks && int_cst_value (low) == 0)
+    low = build_int_cstu (TREE_TYPE (low), TYPE_ALIGN_UNIT (TREE_TYPE (type)));
+
   record_nonwrapping_iv (loop, base, step, stmt, low, high, false, true);
 }