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]

[PATCH] Improve PR30911 and PR31023, Ada and VRP


This improves PR31023 by not folding comparisons as sign-changing
just because we convert from a integral sub-type to its base-type
as this also results in comparisons in a sub-type (similar to
arithmetic in sub-types) and eventually constants that are not in
the range of their types min/max value.

With this fixed we can remove most of the range checking code
that Ada emits for the testcase in PR30911 if we pre-seed
parameter value-ranges in VRP with their types range.  This
should be immune against other bugs in fold and safe as Ada
ensures parameters are in range by checking code at the caller
site.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all
languages including Ada, I'll wait until next week before
applying it.  A testcase for the testsuite would be nice,
but I need Ada volunteers for this.

Thanks,
Richard.

2008-03-28  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/30911
	PR middle-end/31023
	* fold-const.c (fold_sign_changed_comparison): Do leave
	conversions to base-types alone.
	* tree-vrp.c (vrp_initialize): Initialize default SSA_NAMEs
	of parameters with their natural type range.

Index: fold-const.c
===================================================================
--- fold-const.c	(revision 133695)
+++ fold-const.c	(working copy)
@@ -6807,6 +6807,11 @@ fold_sign_changed_comparison (enum tree_
   if (TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
     return NULL_TREE;
 
+  /* If the conversion is from an integral subtype to its basetype
+     leave it alone.  */
+  if (TREE_TYPE (inner_type) == outer_type)
+    return NULL_TREE;
+
   if (TREE_CODE (arg1) != INTEGER_CST
       && !((TREE_CODE (arg1) == NOP_EXPR
 	    || TREE_CODE (arg1) == CONVERT_EXPR)
Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 133695)
--- tree-vrp.c	(working copy)
*************** static void
*** 4808,4813 ****
--- 4808,4814 ----
  vrp_initialize (void)
  {
    basic_block bb;
+   tree param;
  
    vr_value = XCNEWVEC (value_range_t *, num_ssa_names);
    vr_phi_edge_counts = XCNEWVEC (int, num_ssa_names);
*************** vrp_initialize (void)
*** 4847,4852 ****
--- 4848,4872 ----
  	    }
  	}
      }
+ 
+   /* Initialize the value range of default versions of SSA_NAMEs of
+      integral sub-type parameters to their types range.  */
+ 
+   for (param = DECL_ARGUMENTS (current_function_decl);
+        param;
+        param = TREE_CHAIN (param))
+     {
+       tree name = gimple_default_def (cfun, param);
+       if (name
+ 	  && INTEGRAL_TYPE_P (TREE_TYPE (name))
+ 	  && TREE_TYPE (TREE_TYPE (name)))
+ 	{
+ 	  tree type = TREE_TYPE (name);
+ 	  value_range_t *vr = get_value_range (name);
+ 	  set_value_range (vr, VR_RANGE, TYPE_MIN_VALUE (type),
+ 			   TYPE_MAX_VALUE (type), NULL);
+ 	}
+     }
  }
  
  


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