diff options
author | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-09-15 08:59:02 +0000 |
---|---|---|
committer | ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-09-15 08:59:02 +0000 |
commit | e7cfe3db2d9b23c69eb5e87c5987eb99744fd663 (patch) | |
tree | 4796e47592741b417d93c1f144383dadbfbfbf74 | |
parent | 5c638ac1c71ca92aa58c0790e150d2c043070ffb (diff) | |
download | gcc-e7cfe3db2d9b23c69eb5e87c5987eb99744fd663.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116964 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ada/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/ada/utils.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/ada/acats/norun.lst | 2 |
3 files changed, 22 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 77cf3d315ca..e23e39a32bf 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -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 diff --git a/gcc/ada/utils.c b/gcc/ada/utils.c index c59a33e9b4f..4358547883e 100644 --- a/gcc/ada/utils.c +++ b/gcc/ada/utils.c @@ -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), diff --git a/gcc/testsuite/ada/acats/norun.lst b/gcc/testsuite/ada/acats/norun.lst index 38bf675d234..8441024b241 100644 --- a/gcc/testsuite/ada/acats/norun.lst +++ b/gcc/testsuite/ada/acats/norun.lst @@ -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 |