PR ada/18817
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 Sep 2006 08:59:02 +0000 (08:59 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 Sep 2006 08:59:02 +0000 (08:59 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116964 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/utils.c
gcc/testsuite/ada/acats/norun.lst

index 77cf3d3..e23e39a 100644 (file)
@@ -1,3 +1,9 @@
+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-13  Olivier Hainque  <hainque@adacore.com>
 
        PR ada/29025
index c59a33e..4358547 100644 (file)
@@ -2072,6 +2072,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 38bf675..8441024 100644 (file)
@@ -1,4 +1,3 @@
-c380004
 c52103x
 c52104x
 c52104y
@@ -7,6 +6,5 @@ cb1010c
 cb1010d
 templat
 # Tests must be sorted in alphabetical order
-# c380004: should be front-end compile time error, PR ada/18817
 # c52103x, c52104x, c52104y: -fstack-check doesn't work, PR middle-end/20548
 # cb1010a, cb1010c, cb1010d: likewise