From b1d16eff57d17fbab7430d7098ed6ea6144d45f7 Mon Sep 17 00:00:00 2001 From: Zdenek Dvorak Date: Wed, 15 Sep 2004 09:51:33 +0200 Subject: [PATCH] re PR tree-optimization/17468 (Java garbage collector miscompiled at -O1 and higher) PR tree-optimization/17468 * tree-ssa.c (verify_use, verify_phi_args, verify_ssa): Verify that definition inside a block precede uses. * tree-tailcall.c (adjust_return_value): Emit statements in the correct order. From-SVN: r87538 --- gcc/ChangeLog | 8 ++++++ gcc/tree-ssa.c | 59 +++++++++++++++++++++++++++++++++++++++------ gcc/tree-tailcall.c | 4 +-- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 113cda714d2..5432bd55a85 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-09-15 Zdenek Dvorak + + PR tree-optimization/17468 + * tree-ssa.c (verify_use, verify_phi_args, verify_ssa): Verify that + definition inside a block precede uses. + * tree-tailcall.c (adjust_return_value): Emit statements in the + correct order. + 2004-09-15 Richard Sandiford * config/mips/mips.h (POINTERS_EXTEND_UNSIGNED): Delete. diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index c1efa1a1f4e..8e0975570c2 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -207,11 +207,15 @@ err: arguments). IS_VIRTUAL is true if SSA_NAME is created by a V_MAY_DEF or a - V_MUST_DEF. */ + V_MUST_DEF. + + If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names + that are defined before STMT in basic block BB. */ static bool verify_use (basic_block bb, basic_block def_bb, tree ssa_name, - tree stmt, bool check_abnormal, bool is_virtual) + tree stmt, bool check_abnormal, bool is_virtual, + bitmap names_defined_in_bb) { bool err = false; @@ -232,6 +236,13 @@ verify_use (basic_block bb, basic_block def_bb, tree ssa_name, def_bb->index, bb->index); err = true; } + else if (bb == def_bb + && names_defined_in_bb != NULL + && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name))) + { + error ("Definition in block %i follows the use", def_bb->index); + err = true; + } if (check_abnormal && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name)) @@ -281,7 +292,8 @@ verify_phi_args (tree phi, basic_block bb, basic_block *definition_block) if (TREE_CODE (op) == SSA_NAME) err = verify_use (e->src, definition_block[SSA_NAME_VERSION (op)], op, phi, e->flags & EDGE_ABNORMAL, - !is_gimple_reg (PHI_RESULT (phi))); + !is_gimple_reg (PHI_RESULT (phi)), + NULL); if (e->dest != bb) { @@ -506,6 +518,7 @@ verify_ssa (void) ssa_op_iter iter; tree op; enum dom_state orig_dom_state = dom_computed[CDI_DOMINATORS]; + bitmap names_defined_in_bb = BITMAP_XMALLOC (); timevar_push (TV_TREE_SSA_VERIFY); @@ -578,8 +591,12 @@ verify_ssa (void) /* Verify the arguments for every PHI node in the block. */ for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi)) - if (verify_phi_args (phi, bb, definition_block)) - goto err; + { + if (verify_phi_args (phi, bb, definition_block)) + goto err; + bitmap_set_bit (names_defined_in_bb, + SSA_NAME_VERSION (PHI_RESULT (phi))); + } /* Now verify all the uses and vuses in every statement of the block. */ for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) @@ -589,17 +606,44 @@ verify_ssa (void) FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_VIRTUAL_USES) { if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)], - op, stmt, false, true)) + op, stmt, false, true, + names_defined_in_bb)) goto err; } FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) { if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)], - op, stmt, false, false)) + op, stmt, false, false, + names_defined_in_bb)) goto err; } + + FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS) + { + bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op)); + } } + + /* Verify the uses in arguments of PHI nodes at the exits from the + block. */ + for (e = bb->succ; e; e = e->succ_next) + { + for (phi = phi_nodes (e->dest); phi; phi = PHI_CHAIN (phi)) + { + bool virtual = !is_gimple_reg (PHI_RESULT (phi)); + op = PHI_ARG_DEF_FROM_EDGE (phi, e); + if (TREE_CODE (op) != SSA_NAME) + continue; + + if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)], + op, phi, false, virtual, + names_defined_in_bb)) + goto err; + } + } + + bitmap_clear (names_defined_in_bb); } /* Finally, verify alias information. */ @@ -613,6 +657,7 @@ verify_ssa (void) else dom_computed[CDI_DOMINATORS] = orig_dom_state; + BITMAP_XFREE (names_defined_in_bb); timevar_pop (TV_TREE_SSA_VERIFY); return; diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c index d6cfe4c49ed..cfe9dfaacc1 100644 --- a/gcc/tree-tailcall.c +++ b/gcc/tree-tailcall.c @@ -624,7 +624,7 @@ adjust_return_value (basic_block bb, tree m, tree a) var = make_ssa_name (tmp, stmt); TREE_OPERAND (stmt, 0) = var; - bsi_insert_before (&bsi, stmt, BSI_NEW_STMT); + bsi_insert_before (&bsi, stmt, BSI_SAME_STMT); } else var = ret_var; @@ -639,7 +639,7 @@ adjust_return_value (basic_block bb, tree m, tree a) var = make_ssa_name (tmp, stmt); TREE_OPERAND (stmt, 0) = var; - bsi_insert_before (&bsi, stmt, BSI_NEW_STMT); + bsi_insert_before (&bsi, stmt, BSI_SAME_STMT); } TREE_OPERAND (ret_stmt, 0) = var; -- 2.30.2