Add GSI_LAST_NEW_STMT iterator update

Message ID o43n20o4-4445-4884-57p9-or79q6o7516@fhfr.qr
State New
Headers show
Series
  • Add GSI_LAST_NEW_STMT iterator update
Related show

Commit Message

Jeff Law via Gcc-patches Oct. 13, 2021, 12:19 p.m.
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.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Will push once that succeeded.

Richard.

2021-10-13  Richard Biener  <rguenther@suse.de>

	* 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.
---
 gcc/gimple-iterator.c | 4 ++++
 gcc/gimple-iterator.h | 4 ++--
 gcc/tree-if-conv.c    | 6 +-----
 gcc/tree-ssa.c        | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.31.1

Patch

diff --git a/gcc/gimple-iterator.c b/gcc/gimple-iterator.c
index da8c21297de..ee4e63a3bd3 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 6047a739332..0e384f72f94 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 6a67acfeaae..0b6b07cfac6 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 0fba404babe..fde13defebf 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;
 		      }