From be98560f314f6940b262501fca7ffdd99b223b04 Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Thu, 11 Oct 2001 16:34:03 -0700 Subject: [PATCH] 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 --- gcc/java/ChangeLog | 5 +++++ gcc/java/parse.y | 20 +++++++++++++++++--- 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 + + * parse.y (patch_if_else_statement): If the condition is constant, + optimize away the test. + 2001-10-09 Alexandre Petit-Bianco * 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; } -- 2.30.2