parse.y (patch_if_else_statement): If the condition is constant, optimize away the...
authorPer Bothner <per@bothner.com>
Thu, 11 Oct 2001 23:34:03 +0000 (16:34 -0700)
committerPer Bothner <bothner@gcc.gnu.org>
Thu, 11 Oct 2001 23:34:03 +0000 (16:34 -0700)
* parse.y (patch_if_else_statement):  If the condition is constant,
optimize away the test.

From-SVN: r46207

gcc/java/ChangeLog
gcc/java/parse.y

index 0c9c0779dd97a4996c9288ec6c11e2c71746c1f7..634bdc36dfe2b73f346b749ce82f5b5d6440ac0e 100644 (file)
@@ -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
index d007b71d2e2546dc14667f59d54c40aaec1a4ab7..a5c9867e2871b4a2541c956154ef464f1174298f 100644 (file)
@@ -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;
 }