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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Improve code generation for assigned goto statements


Hi,

This simple patch implements an idea from Roger Sayle.  We currently
produce e.g.

 if (&__label_000020 == next.1) goto next.1; else (void) 0;

but this is probably better written with 

 if (&__label_000020 == next.1) goto goto __label__000020; else (void) 0;

to avoid computed jumps and abnormal edges.
Bootstrapped and tested on x86_64-pc-linux-gnu.

Gr.
Steven


	* trans-stmt.c (gfc_trans_goto): Jump to the known label instead
	of the assigned goto variable.

Index: trans-stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-stmt.c,v
retrieving revision 1.39
diff -u -3 -p -r1.39 trans-stmt.c
--- trans-stmt.c	20 Jul 2005 01:19:33 -0000	1.39
+++ trans-stmt.c	31 Jul 2005 20:33:42 -0000
@@ -163,11 +163,11 @@ gfc_trans_goto (gfc_code * code)
   gfc_trans_runtime_check (tmp, assign_error, &se.pre);
 
   assigned_goto = GFC_DECL_ASSIGN_ADDR (se.expr);
-  target = build1 (GOTO_EXPR, void_type_node, assigned_goto);
 
   code = code->block;
   if (code == NULL)
     {
+      target = build1 (GOTO_EXPR, void_type_node, assigned_goto);
       gfc_add_expr_to_block (&se.pre, target);
       return gfc_finish_block (&se.pre);
     }
@@ -177,10 +177,12 @@ gfc_trans_goto (gfc_code * code)
 
   do
     {
-      tmp = gfc_get_label_decl (code->label);
-      tmp = gfc_build_addr_expr (pvoid_type_node, tmp);
+      target = gfc_get_label_decl (code->label);
+      tmp = gfc_build_addr_expr (pvoid_type_node, target);
       tmp = build2 (EQ_EXPR, boolean_type_node, tmp, assigned_goto);
-      tmp = build3_v (COND_EXPR, tmp, target, build_empty_stmt ());
+      tmp = build3_v (COND_EXPR, tmp,
+		      build1 (GOTO_EXPR, void_type_node, target),
+		      build_empty_stmt ());
       gfc_add_expr_to_block (&se.pre, tmp);
       code = code->block;
     }


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