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]

Fix PR ada/18817


It's not really a regression but it's the famous ACATS C380004, which was 
quite delicate to get right.  All the front-end bits are already there and it 
turns out that the missing link (in Gigi) was devised more than 2 years ago 
by Roger: http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01249.html

Bootstrapped/regtested on i586-suse-linux, applied to the mainline.


2006-09-15  Roger Sayle  <roger@eyesopen.com>

	PR ada/18817
	* utils.c (max_size): Perform constant folding of (A ? B : C) - D
	into A ? B - D : C - D when calculating the size of a MINUS_EXPR.


2006-09-15  Eric Botcazou  <ebotcazou@adacore.com>

	* ada/acats/norun.lst: Remove c380004.


-- 
Eric Botcazou
Index: utils.c
===================================================================
RCS file: /gnat.dev/cvs/Dev/gnat/utils.c,v
retrieving revision 1.48.2.120
retrieving revision 1.48.2.121
diff -u -p -r1.48.2.120 -r1.48.2.121
--- utils.c	5 Jun 2006 06:21:15 -0000	1.48.2.120
+++ utils.c	5 Jun 2006 20:34:06 -0000	1.48.2.121
@@ -2216,6 +2216,22 @@ max_size (tree exp, bool max_p)
 	  if (code == COMPOUND_EXPR)
 	    return max_size (TREE_OPERAND (exp, 1), max_p);
 
+	  /* Calculate "(A ? B : C) - D" as "A ? B - D : C - D" which
+	     may provide a tighter bound on max_size.  */
+	  if (code == MINUS_EXPR
+	      && TREE_CODE (TREE_OPERAND (exp, 0)) == COND_EXPR)
+	    {
+	      tree lhs = fold_build2 (MINUS_EXPR, type,
+				      TREE_OPERAND (TREE_OPERAND (exp, 0), 1),
+				      TREE_OPERAND (exp, 1));
+	      tree rhs = fold_build2 (MINUS_EXPR, type,
+				      TREE_OPERAND (TREE_OPERAND (exp, 0), 2),
+				      TREE_OPERAND (exp, 1));
+	      return fold_build2 (max_p ? MAX_EXPR : MIN_EXPR, type,
+				  max_size (lhs, max_p),
+				  max_size (rhs, max_p));
+	    }
+
 	  {
 	    tree lhs = max_size (TREE_OPERAND (exp, 0), max_p);
 	    tree rhs = max_size (TREE_OPERAND (exp, 1),

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