This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Java: help optimizer in build_class_init


I found gcj is producing dead code for methods that have two or more class
initializations.  This patch tweaks the class init tree to help the
backend eliminate the dead code.

Currently, build_class_init generates the equivalent of:

  bool init = (klass->state >= JV_STATE_DONE);
  if (!init)
    {
      _Jv_ClassInit(klass);
      init = 1;
    }
  ...
  if (!init)
    {

After this patch, it becomes:

  bool init = (klass->state >= JV_STATE_DONE);
  if (!init)
    _Jv_ClassInit(klass);
  init = 1;

and the following test can be optimized away, yielding slightly
smaller/faster code.

Tested on 3.0 branch.

2000-05-02  Jeff Sturm  <jsturm@one-point.com>

	* expr.c (build_class_init): Move MODIFY_EXPR
	outside of COND_EXPR.  Remove variable `call'.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.102.2.1
diff -u -p -r1.102.2.1 expr.c
--- expr.c	2001/02/16 22:32:24	1.102.2.1
+++ expr.c	2001/05/02 17:52:59
@@ -1658,7 +1658,7 @@ tree
 build_class_init (clas, expr)
      tree clas, expr;
 {
-  tree init, call;
+  tree init;
   struct init_test_hash_entry *ite;
   if (inherits_from_p (current_class, clas))
     return expr;
@@ -1689,14 +1689,14 @@ build_class_init (clas, expr)
 		    build_tree_list (NULL_TREE, build_class_ref (clas)),
 		    NULL_TREE);
       TREE_SIDE_EFFECTS (init) = 1;
-      call = build (COMPOUND_EXPR, TREE_TYPE (expr), init, 
-		    build (MODIFY_EXPR, boolean_type_node,
-			   ite->init_test_decl, boolean_true_node));
-      TREE_SIDE_EFFECTS (call) = 1;
       init = build (COND_EXPR, void_type_node,
 		    build (EQ_EXPR, boolean_type_node, 
 			   ite->init_test_decl, boolean_false_node),
-		    call, integer_zero_node);
+		    init, integer_zero_node);
+      TREE_SIDE_EFFECTS (init) = 1;
+      init = build (COMPOUND_EXPR, TREE_TYPE (expr), init, 
+		    build (MODIFY_EXPR, boolean_type_node,
+			   ite->init_test_decl, boolean_true_node));
       TREE_SIDE_EFFECTS (init) = 1;
     }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]