aboutsummaryrefslogtreecommitdiff
path: root/gcc/java
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>2001-10-11 16:34:03 -0700
committerPer Bothner <bothner@gcc.gnu.org>2001-10-11 16:34:03 -0700
commitbe98560f314f6940b262501fca7ffdd99b223b04 (patch)
tree01bd063c25f7f684651a3ab1070967f70d165aa8 /gcc/java
parentcfac6e9fb4ea2fc7b05ded85c805501e4d7700b9 (diff)
downloadgcc-be98560f314f6940b262501fca7ffdd99b223b04.zip
gcc-be98560f314f6940b262501fca7ffdd99b223b04.tar.gz
gcc-be98560f314f6940b262501fca7ffdd99b223b04.tar.bz2
parse.y (patch_if_else_statement): If the condition is constant, optimize away the test.
* parse.y (patch_if_else_statement): If the condition is constant, optimize away the test. From-SVN: r46207
Diffstat (limited to 'gcc/java')
-rw-r--r--gcc/java/ChangeLog5
-rw-r--r--gcc/java/parse.y20
2 files changed, 22 insertions, 3 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 0c9c077..634bdc3 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,8 @@
+2001-10-11 Per Bothner <per@bothner.com>
+
+ * parse.y (patch_if_else_statement): If the condition is constant,
+ optimize away the test.
+
2001-10-09 Alexandre Petit-Bianco <apbianco@redhat.com>
* parse.y (patch_cast): Call patch_string on the first operand of
diff --git a/gcc/java/parse.y b/gcc/java/parse.y
index d007b71..a5c9867 100644
--- a/gcc/java/parse.y
+++ b/gcc/java/parse.y
@@ -15016,6 +15016,9 @@ patch_if_else_statement (node)
tree node;
{
tree expression = TREE_OPERAND (node, 0);
+ int can_complete_normally
+ = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
+ | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2)));
TREE_TYPE (node) = error_mark_node;
EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
@@ -15031,11 +15034,22 @@ patch_if_else_statement (node)
return error_mark_node;
}
+ if (TREE_CODE (expression) == INTEGER_CST)
+ {
+ if (integer_zerop (expression))
+ node = TREE_OPERAND (node, 2);
+ else
+ node = TREE_OPERAND (node, 1);
+ if (CAN_COMPLETE_NORMALLY (node) != can_complete_normally)
+ {
+ node = build (COMPOUND_EXPR, void_type_node, node, empty_stmt_node);
+ CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
+ }
+ return node;
+ }
TREE_TYPE (node) = void_type_node;
TREE_SIDE_EFFECTS (node) = 1;
- CAN_COMPLETE_NORMALLY (node)
- = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
- | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
+ CAN_COMPLETE_NORMALLY (node) = can_complete_normally;
return node;
}