From: Richard Biener Date: Wed, 13 Oct 2021 11:42:22 +0000 (+0200) Subject: Add GSI_LAST_NEW_STMT iterator update X-Git-Tag: basepoints/gcc-13~3942 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=489c8f27296362dcfbc967aecef17ba7c5cab0f2;p=thirdparty%2Fgcc.git Add GSI_LAST_NEW_STMT iterator update Currently when adding a sequence before there's no way to get the iterator placed at the last added stmt which results in convoluted code in the if-conversion usecase. The following adds GSI_LAST_NEW_STMT and corrects one obvious mistake in execute_update_addresses_taken as well as tries to avoid the just filed PR102726 by biasing the enum values to be outside of the boolean 0/1 range. 2021-10-13 Richard Biener * gimple-iterator.h (gsi_iterator_update): Add GSI_LAST_NEW_STMT, start at integer value 2. * gimple-iterator.c (gsi_insert_seq_nodes_before): Update the iterator for GSI_LAST_NEW_STMT. (gsi_insert_seq_nodes_after): Likewise. * tree-if-conv.c (predicate_statements): Use GSI_LAST_NEW_STMT. * tree-ssa.c (execute_update_addresses_taken): Correct bogus arguments to gsi_replace. --- diff --git a/gcc/gimple-iterator.c b/gcc/gimple-iterator.c index da8c21297de7..ee4e63a3bd34 100644 --- a/gcc/gimple-iterator.c +++ b/gcc/gimple-iterator.c @@ -162,6 +162,9 @@ gsi_insert_seq_nodes_before (gimple_stmt_iterator *i, case GSI_CONTINUE_LINKING: i->ptr = first; break; + case GSI_LAST_NEW_STMT: + i->ptr = last; + break; case GSI_SAME_STMT: break; default: @@ -271,6 +274,7 @@ gsi_insert_seq_nodes_after (gimple_stmt_iterator *i, case GSI_NEW_STMT: i->ptr = first; break; + case GSI_LAST_NEW_STMT: case GSI_CONTINUE_LINKING: i->ptr = last; break; diff --git a/gcc/gimple-iterator.h b/gcc/gimple-iterator.h index 6047a7393329..0e384f72f94d 100644 --- a/gcc/gimple-iterator.h +++ b/gcc/gimple-iterator.h @@ -46,8 +46,8 @@ struct gphi_iterator : public gimple_stmt_iterator enum gsi_iterator_update { - GSI_NEW_STMT, /* Only valid when single statement is added, move - iterator to it. */ + GSI_NEW_STMT = 2, /* Move the iterator to the first statement added. */ + GSI_LAST_NEW_STMT, /* Move the iterator to the last statement added. */ GSI_SAME_STMT, /* Leave the iterator at the same statement. */ GSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable for linking other statements in the same diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index 6a67acfeaae2..0b6b07cfac62 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -2582,11 +2582,7 @@ predicate_statements (loop_p loop) { gsi_remove (&gsi, true); gsi_insert_seq_before (&gsi, rewrite_to_defined_overflow (stmt), - GSI_SAME_STMT); - if (gsi_end_p (gsi)) - gsi = gsi_last_bb (gimple_bb (stmt)); - else - gsi_prev (&gsi); + GSI_LAST_NEW_STMT); } else if (gimple_vdef (stmt)) { diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 0fba404babe9..fde13defebf7 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -2079,7 +2079,7 @@ execute_update_addresses_taken (void) gcall *call = gimple_build_call_internal (IFN_ASAN_POISON, 0); gimple_call_set_lhs (call, var); - gsi_replace (&gsi, call, GSI_SAME_STMT); + gsi_replace (&gsi, call, true); } else { @@ -2088,7 +2088,7 @@ execute_update_addresses_taken (void) previous out of scope value. */ tree clobber = build_clobber (TREE_TYPE (var)); gimple *g = gimple_build_assign (var, clobber); - gsi_replace (&gsi, g, GSI_SAME_STMT); + gsi_replace (&gsi, g, true); } continue; }