From: Götz Lindenmaier Date: Tue, 13 Mar 2001 07:50:21 +0000 (+0000) Subject: end block can not be optimized away any more. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=9924f5a9ff6902ae3c18d5065b13b676bbf25502;p=libfirm end block can not be optimized away any more. [r130] --- diff --git a/ir/ir/ircons.c b/ir/ir/ircons.c index 09eda5267..5015199b0 100644 --- a/ir/ir/ircons.c +++ b/ir/ir/ircons.c @@ -1227,6 +1227,7 @@ mature_block (ir_node *block) /* turn the dynamic in-array into a static one. */ ins = ARR_LEN (block->in)-1; NEW_ARR_A (ir_node *, nin, ins); + /* @@@ something is strange here... why isn't the array copied? */ /* Traverse a chain of Phi nodes attached to this block and mature these, too. **/ diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 9f4c1a96f..751ad2aa7 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -158,8 +158,10 @@ copy_preds (ir_node *n, void *env) { /* repair the block visited flag from above misuse */ set_Block_block_visited(nn, 0); /* Local optimization could not merge two subsequent blocks if - in array contained Bads. Now it's possible. */ - on = optimize_in_place(nn); + in array contained Bads. Now it's possible, but don't do it for + the end block! */ + if (n != current_ir_graph->end_block) on = optimize_in_place(nn); + else on = nn; if (nn != on) exchange(nn, on); } else if (get_irn_opcode(n) == iro_Phi) { /* Don't copy node if corresponding predecessor in block is Bad. diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index d668c6a1b..6a42358a7 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -270,10 +270,12 @@ equivalent_node (ir_node *n) && get_irn_op(get_Block_cfgpred(n, 0)) == op_Jmp) { n = get_nodes_Block(get_Block_cfgpred(n, 0)); - } else if (n != current_ir_graph->start_block) { + } else if ((n != current_ir_graph->start_block) && + (n != current_ir_graph->end_block) ) { int i; /* If all inputs are dead, this block is dead too, except if it is - the start block. This is a step of unreachable code elimination */ + the start or end block. This is a step of unreachable code + elimination */ for (i = 0; i < get_Block_n_cfgpreds(n); i++) { if (!is_Bad(get_Block_cfgpred(n, i))) break; } diff --git a/testprograms/Makefile.in b/testprograms/Makefile.in index 53cf327e0..f9914d147 100644 --- a/testprograms/Makefile.in +++ b/testprograms/Makefile.in @@ -17,7 +17,7 @@ SOURCES := Makefile.in \ call_str_example.c if_else_example.c memory_example.c \ cond_example.c if_example.c oo_program_example.c \ const_eval_example.c if_while_example.c three_cfpred_example.c \ - dead_block_example.c inheritance_example.c + dead_block_example.c inheritance_example.c while_example.c bin_EXAMPLES = $(CFILES:.c=) run_bin_EXAMPLES = $(CFILES:.c=;) diff --git a/testprograms/if_while_example.c b/testprograms/if_while_example.c index 33991b6e0..a58acba27 100644 --- a/testprograms/if_while_example.c +++ b/testprograms/if_while_example.c @@ -20,7 +20,7 @@ *** if (0 == 0) *** { a = 2; } *** -*** while (0 == 0) loop { // 0 == 0 aborts libfirm: Bad pred of Endblock +*** while (0 == 0) loop { *** h = a; *** a = b; *** b = h; diff --git a/testprograms/while_example.c b/testprograms/while_example.c index e931c3560..3c19927c7 100644 --- a/testprograms/while_example.c +++ b/testprograms/while_example.c @@ -16,7 +16,7 @@ *** int b = 1; // pos 1 *** int h; // pos 2 *** -*** while (0 == 2) loop { // 0 == 0 will abort libfirm!! +*** while (0 == 2) loop { *** h = a; *** a = b; *** b = h; @@ -72,7 +72,7 @@ main(void) r = new_immBlock (); add_in_edge (r, x); x = new_Cond (new_Proj(new_Cmp(new_Const (mode_I, tarval_from_long (mode_i, 0)), - new_Const (mode_I, tarval_from_long (mode_i, 2))), + new_Const (mode_I, tarval_from_long (mode_i, 0))), mode_b, Eq)); f = new_Proj (x, mode_X, 0); t = new_Proj (x, mode_X, 1); @@ -83,9 +83,9 @@ main(void) x = new_Jmp (); add_in_edge (r, x); - /* the code in the loop body, + /* The code in the loop body, as we are dealing with local variables only the dataflow edges - are manipulated */ + are manipulated. */ set_value (2, get_value (0, mode_I)); set_value (0, get_value (1, mode_I)); set_value (1, get_value (2, mode_I));