summaryrefslogtreecommitdiff
path: root/gcc/java
diff options
context:
space:
mode:
authorbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-11 23:34:03 +0000
committerbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>2001-10-11 23:34:03 +0000
commitd74eb70603dddd5e774b066b1d5bb67b54d51bba (patch)
tree01bd063c25f7f684651a3ab1070967f70d165aa8 /gcc/java
parent699d76d2a494aeb2233abbec7450eb8f28591412 (diff)
downloadgcc-d74eb70603dddd5e774b066b1d5bb67b54d51bba.tar.gz
* parse.y (patch_if_else_statement): If the condition is constant,
optimize away the test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@46207 138bc75d-0d04-0410-961f-82ee72b054a4
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 0c9c0779dd9..634bdc36dfe 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 d007b71d2e2..a5c9867e287 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;
}