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] A few tweaks for Ada


Hi,

this patch is aimed at helping a little the Ada compiler by not generating 
useless trees and simplifying more of them.  For example, the stor-layout.c 
code is obsolete since the Ada front-end already filters out negative sizes.

Tested on i586-suse-linux, OK for mainline?


2009-09-27  Eric Botcazou  <ebotcazou@adacore.com>

	* fold-const.c (maybe_lvalue_p): Return false for M(IN|AX)_EXPR.
	(extract_muldiv_1) <MINUS_EXPR>: Swap operands if necessary.
	* stor-layout.c (layout_type) <ARRAY_TYPE>: Do not take the maximum
	of the length and zero.


-- 
Eric Botcazou
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 152199)
+++ fold-const.c	(working copy)
@@ -2830,8 +2830,6 @@ maybe_lvalue_p (const_tree x)
   case TARGET_EXPR:
   case COND_EXPR:
   case BIND_EXPR:
-  case MIN_EXPR:
-  case MAX_EXPR:
     break;
 
   default:
@@ -6512,7 +6510,19 @@ extract_muldiv_1 (tree t, tree c, enum t
       /* If this was a subtraction, negate OP1 and set it to be an addition.
 	 This simplifies the logic below.  */
       if (tcode == MINUS_EXPR)
-	tcode = PLUS_EXPR, op1 = negate_expr (op1);
+	{
+	  tcode = PLUS_EXPR, op1 = negate_expr (op1);
+	  /* If OP1 was not easily negatable, the constant may be OP0.  */
+	  if (TREE_CODE (op0) == INTEGER_CST)
+	    {
+	      tree tem = op0;
+	      op0 = op1;
+	      op1 = tem;
+	      tem = t1;
+	      t1 = t2;
+	      t2 = tem;
+	    }
+	}
 
       if (TREE_CODE (op1) != INTEGER_CST)
 	break;
Index: stor-layout.c
===================================================================
--- stor-layout.c	(revision 152199)
+++ stor-layout.c	(working copy)
@@ -1968,15 +1968,6 @@ layout_type (tree type)
 							    TREE_TYPE (lb),
 							    ub, lb)));
 
-	    /* If neither bound is a constant and sizetype is signed, make
-	       sure the size is never negative.  We should really do this
-	       if *either* bound is non-constant, but this is the best
-	       compromise between C and Ada.  */
-	    if (!TYPE_UNSIGNED (sizetype)
-		&& TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
-		&& TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
-	      length = size_binop (MAX_EXPR, length, size_zero_node);
-
 	    TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
 					   fold_convert (bitsizetype,
 							 length));

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