diff mbox series

[SFN+LVU+IEPM,v4,1/9,SFN] adjust RTL insn-walking API

Message ID 20171110023448.28164-1-aoliva@redhat.com
State New
Headers show
Series [SFN+LVU+IEPM,v4,1/9,SFN] adjust RTL insn-walking API | expand

Commit Message

Alexandre Oliva Nov. 10, 2017, 2:34 a.m. UTC
This patch removes unused RTL functions, introduces alternate ones for
use in a later SFN patch, and regroups other related functions so that
they appear in a more consistent order.

for  gcc/ChangeLog

	* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
	(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
	(next_nonnote_nondebug_insn_bb): New.
	(prev_nonnote_nondebug_insn_bb): New.
	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
	* rtl.h	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
	(prev_nonnote_nondebug_insn_bb): Declare.
	(next_nonnote_nondebug_insn_bb): Declare.
	* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
	* cfgrtl.c (get_last_bb_insn): Likewise.
	* lra.c (push_insns): Likewise.
---
 gcc/cfgbuild.c |  2 +-
 gcc/cfgrtl.c   |  4 ++--
 gcc/emit-rtl.c | 69 ++++++++++++++++++++++++++++++++--------------------------
 gcc/lra.c      |  2 +-
 gcc/rtl.h      |  4 ++--
 5 files changed, 44 insertions(+), 37 deletions(-)

Comments

Jeff Law Dec. 7, 2017, 10:25 p.m. UTC | #1
On 11/09/2017 07:34 PM, Alexandre Oliva wrote:
> This patch removes unused RTL functions, introduces alternate ones for
> use in a later SFN patch, and regroups other related functions so that
> they appear in a more consistent order.
> 
> for  gcc/ChangeLog
> 
> 	* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
> 	(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
> 	(next_nonnote_nondebug_insn_bb): New.
> 	(prev_nonnote_nondebug_insn_bb): New.
> 	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
> 	* rtl.h	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
> 	(prev_nonnote_nondebug_insn_bb): Declare.
> 	(next_nonnote_nondebug_insn_bb): Declare.
> 	* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
> 	* cfgrtl.c (get_last_bb_insn): Likewise.
> 	* lra.c (push_insns): Likewise.
OK.  Seems like this ought to go in immediately rather than waiting on
the full kit to be ack'd.

jeff
Alexandre Oliva Dec. 12, 2017, 2:26 a.m. UTC | #2
On Dec  7, 2017, Jeff Law <law@redhat.com> wrote:

> On 11/09/2017 07:34 PM, Alexandre Oliva wrote:
>> This patch removes unused RTL functions, introduces alternate ones for
>> use in a later SFN patch, and regroups other related functions so that
>> they appear in a more consistent order.
>> 
>> for  gcc/ChangeLog
>> 
>> * emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
>> (next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
>> (next_nonnote_nondebug_insn_bb): New.
>> (prev_nonnote_nondebug_insn_bb): New.
>> (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
>> * rtl.h	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
>> (prev_nonnote_nondebug_insn_bb): Declare.
>> (next_nonnote_nondebug_insn_bb): Declare.
>> * cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
>> * cfgrtl.c (get_last_bb_insn): Likewise.
>> * lra.c (push_insns): Likewise.
> OK.  Seems like this ought to go in immediately rather than waiting on
> the full kit to be ack'd.

Thanks, FTR, here it is, as installed:

From 18fc635703209d1a4ab2d9544c0f7b946e3c4c04 Mon Sep 17 00:00:00 2001
From: aoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 12 Dec 2017 02:14:39 +0000
Subject: [PATCH 1/7] [SFN] adjust RTL insn-walking API

This patch removes unused RTL functions, introduces alternate ones for
use in a later SFN patch, and regroups other related functions so that
they appear in a more consistent order.

for  gcc/ChangeLog

	* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
	(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
	(next_nonnote_nondebug_insn_bb): New.
	(prev_nonnote_nondebug_insn_bb): New.
	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
	* rtl.h	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
	(prev_nonnote_nondebug_insn_bb): Declare.
	(next_nonnote_nondebug_insn_bb): Declare.
	* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
	* cfgrtl.c (get_last_bb_insn): Likewise.
	* lra.c (push_insns): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255564 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog  | 14 ++++++++++++
 gcc/cfgbuild.c |  2 +-
 gcc/cfgrtl.c   |  4 ++--
 gcc/emit-rtl.c | 69 ++++++++++++++++++++++++++++++++--------------------------
 gcc/lra.c      |  2 +-
 gcc/rtl.h      |  4 ++--
 6 files changed, 58 insertions(+), 37 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 54df8c0ee727..6d0a64e6adcc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,17 @@
+2017-12-12  Alexandre Oliva <aoliva@redhat.com>
+
+	* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
+	(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
+	(next_nonnote_nondebug_insn_bb): New.
+	(prev_nonnote_nondebug_insn_bb): New.
+	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
+	* rtl.h	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
+	(prev_nonnote_nondebug_insn_bb): Declare.
+	(next_nonnote_nondebug_insn_bb): Declare.
+	* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
+	* cfgrtl.c (get_last_bb_insn): Likewise.
+	* lra.c (push_insns): Likewise.
+
 2017-12-11  David Malcolm  <dmalcolm@redhat.com>
 
 	PR c/82050
diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index a0926752143d..77a221de2119 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -511,7 +511,7 @@ find_bb_boundaries (basic_block bb)
 	     the middle of a BB.  We need to split it in the same manner as
 	     if the barrier were preceded by a control_flow_insn_p insn.  */
 	  if (!flow_transfer_insn)
-	    flow_transfer_insn = prev_nonnote_insn_bb (insn);
+	    flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
 	}
 
       if (control_flow_insn_p (insn))
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index a2ad075db85f..eb673a1e0799 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -2285,11 +2285,11 @@ get_last_bb_insn (basic_block bb)
     end = table;
 
   /* Include any barriers that may follow the basic block.  */
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
   while (tmp && BARRIER_P (tmp))
     {
       end = tmp;
-      tmp = next_nonnote_insn_bb (end);
+      tmp = next_nonnote_nondebug_insn_bb (end);
     }
 
   return end;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 428e4743454f..42de598067f4 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3370,20 +3370,17 @@ next_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE, but stop the
-   search before we enter another basic block.  This routine does not
-   look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a DEBUG_INSN.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_insn_bb (rtx_insn *insn)
+next_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
       insn = NEXT_INSN (insn);
-      if (insn == 0 || !NOTE_P (insn))
+      if (insn == 0 || !DEBUG_INSN_P (insn))
 	break;
-      if (NOTE_INSN_BASIC_BLOCK_P (insn))
-	return NULL;
     }
 
   return insn;
@@ -3405,67 +3402,70 @@ prev_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE, but stop
-   the search before we enter another basic block.  This routine does
-   not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn_bb (rtx_insn *insn)
+prev_nondebug_insn (rtx_insn *insn)
 {
-
   while (insn)
     {
       insn = PREV_INSN (insn);
-      if (insn == 0 || !NOTE_P (insn))
+      if (insn == 0 || !DEBUG_INSN_P (insn))
 	break;
-      if (NOTE_INSN_BASIC_BLOCK_P (insn))
-	return NULL;
     }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a DEBUG_INSN.  This
-   routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
       insn = NEXT_INSN (insn);
-      if (insn == 0 || !DEBUG_INSN_P (insn))
+      if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
 	break;
     }
 
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
+   but stop the search before we enter another basic block.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
     {
-      insn = PREV_INSN (insn);
-      if (insn == 0 || !DEBUG_INSN_P (insn))
+      insn = NEXT_INSN (insn);
+      if (insn == 0)
+	break;
+      if (DEBUG_INSN_P (insn))
+	continue;
+      if (!NOTE_P (insn))
 	break;
+      if (NOTE_INSN_BASIC_BLOCK_P (insn))
+	return NULL;
     }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+/* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
    This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_nondebug_insn (rtx_insn *insn)
+prev_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
-      insn = NEXT_INSN (insn);
+      insn = PREV_INSN (insn);
       if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
 	break;
     }
@@ -3473,17 +3473,24 @@ next_nonnote_nondebug_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a NOTE nor
+   DEBUG_INSN, but stop the search before we enter another basic
+   block.  This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_nondebug_insn (rtx_insn *insn)
+prev_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
     {
       insn = PREV_INSN (insn);
-      if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
+      if (insn == 0)
 	break;
+      if (DEBUG_INSN_P (insn))
+	continue;
+      if (!NOTE_P (insn))
+	break;
+      if (NOTE_INSN_BASIC_BLOCK_P (insn))
+	return NULL;
     }
 
   return insn;
diff --git a/gcc/lra.c b/gcc/lra.c
index 3fd15ee57943..f790904ec57f 100644
--- a/gcc/lra.c
+++ b/gcc/lra.c
@@ -1806,7 +1806,7 @@ push_insns (rtx_insn *from, rtx_insn *to)
 static void
 setup_sp_offset (rtx_insn *from, rtx_insn *last)
 {
-  rtx_insn *before = next_nonnote_insn_bb (last);
+  rtx_insn *before = next_nonnote_nondebug_insn_bb (last);
   HOST_WIDE_INT offset = (before == NULL_RTX || ! INSN_P (before)
 			  ? 0 : lra_get_insn_recog_data (before)->sp_offset);
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 8de5a1cada5a..9cc982172f53 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3085,13 +3085,13 @@ extern rtx_call_insn *last_call_insn (void);
 extern rtx_insn *previous_insn (rtx_insn *);
 extern rtx_insn *next_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_insn (rtx_insn *);
-extern rtx_insn *prev_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_insn (rtx_insn *);
-extern rtx_insn *next_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *prev_nondebug_insn (rtx_insn *);
 extern rtx_insn *next_nondebug_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_nondebug_insn (rtx_insn *);
+extern rtx_insn *prev_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_nondebug_insn (rtx_insn *);
+extern rtx_insn *next_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *prev_real_insn (rtx_insn *);
 extern rtx_insn *next_real_insn (rtx);
 extern rtx_insn *prev_active_insn (rtx_insn *);
Alexandre Oliva Dec. 14, 2017, 11:55 a.m. UTC | #3
On Dec 12, 2017, Alexandre Oliva <aoliva@redhat.com> wrote:

> On Dec  7, 2017, Jeff Law <law@redhat.com> wrote:
>> On 11/09/2017 07:34 PM, Alexandre Oliva wrote:
>>> (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
> Thanks, FTR, here it is, as installed:

On Aug 31, 2017, Alexandre Oliva <aoliva@redhat.com> wrote:

> 	(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.

[SFN] next/prev_nonnote_insn_bb are no more, even for ports

The patch that added _nondebug to next_ and prev_nonnote_insn_bb
failed to find and adjust uses within config.  Fixed.

Sanity-checked by cross-building both *-elf targets (with binutils and
newlib) on x86_64-linux-gnu.  I'm going ahead and checking it in
shortly.

for  gcc/ChangeLog

	PR bootstrap/83396
	* config/arc/arc.c (hwloop_optimize): Skip debug insns.
	* config/sh/sh-protos.h (sh_find_set_of_reg): Adjust.
	* config/sh/sh.c: Skip debug insns besides notes.
	* config/sh/sh.md: Likewise.
	* config/sh/sh_treg_combine.cc: Likewise.
	* config/sh/sync.md: Likewise.
---
 gcc/config/arc/arc.c             |    2 +-
 gcc/config/sh/sh-protos.h        |    2 +-
 gcc/config/sh/sh.c               |   10 +++++-----
 gcc/config/sh/sh.md              |   18 +++++++++---------
 gcc/config/sh/sh_treg_combine.cc |    8 ++++----
 gcc/config/sh/sync.md            |    2 +-
 6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index b8eec10086dd..9974a1f999b5 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -7499,7 +7499,7 @@ hwloop_optimize (hwloop_info loop)
                  && NOTE_KIND (entry_after) != NOTE_INSN_CALL_ARG_LOCATION))
         entry_after = NEXT_INSN (entry_after);
 #endif
-      entry_after = next_nonnote_insn_bb (entry_after);
+      entry_after = next_nonnote_nondebug_insn_bb (entry_after);
 
       gcc_assert (entry_after);
       emit_insn_before (seq, entry_after);
diff --git a/gcc/config/sh/sh-protos.h b/gcc/config/sh/sh-protos.h
index e98030d31bd7..0a83fbe17011 100644
--- a/gcc/config/sh/sh-protos.h
+++ b/gcc/config/sh/sh-protos.h
@@ -122,7 +122,7 @@ struct set_of_reg
 
 /* Given a reg rtx and a start insn, try to find the insn that sets the
    specified reg by using the specified insn stepping function, such as 
-   'prev_nonnote_insn_bb'.  When the insn is found, try to extract the rtx
+   'prev_nonnote_nondebug_insn_bb'.  When the insn is found, try to extract the rtx
    of the reg set.  */
 template <typename F> inline set_of_reg
 sh_find_set_of_reg (rtx reg, rtx_insn* insn, F stepfunc,
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 0d7d7bc53ca2..3776415f1589 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -11897,7 +11897,7 @@ sh_is_logical_t_store_expr (rtx op, rtx_insn* insn)
       else
 	{
 	  set_of_reg op_set = sh_find_set_of_reg (ops[i], insn,
-						  prev_nonnote_insn_bb);
+						  prev_nonnote_nondebug_insn_bb);
 	  if (op_set.set_src == NULL_RTX)
 	    continue;
 
@@ -11929,7 +11929,7 @@ sh_try_omit_signzero_extend (rtx extended_op, rtx_insn* insn)
   if (GET_MODE (extended_op) != SImode)
     return NULL_RTX;
 
-  set_of_reg s = sh_find_set_of_reg (extended_op, insn, prev_nonnote_insn_bb);
+  set_of_reg s = sh_find_set_of_reg (extended_op, insn, prev_nonnote_nondebug_insn_bb);
   if (s.set_src == NULL_RTX)
     return NULL_RTX;
 
@@ -11966,9 +11966,9 @@ sh_split_movrt_negc_to_movt_xor (rtx_insn* curr_insn, rtx operands[])
     return false;
 
   set_of_reg t_before_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
-						 prev_nonnote_insn_bb);
+						 prev_nonnote_nondebug_insn_bb);
   set_of_reg t_after_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
-						next_nonnote_insn_bb);
+						next_nonnote_nondebug_insn_bb);
 
   if (t_before_negc.set_rtx != NULL_RTX && t_after_negc.set_rtx != NULL_RTX
       && rtx_equal_p (t_before_negc.set_rtx, t_after_negc.set_rtx)
@@ -12010,7 +12010,7 @@ sh_find_extending_set_of_reg (rtx reg, rtx_insn* curr_insn)
      cases, where a zero_extend is followed an (implicit) sign_extend, and it
      fails to see the sign_extend.  */
   sh_extending_set_of_reg result =
-	sh_find_set_of_reg (reg, curr_insn, prev_nonnote_insn_bb, true);
+	sh_find_set_of_reg (reg, curr_insn, prev_nonnote_nondebug_insn_bb, true);
 
   if (result.set_src != NULL)
     {
diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 840fd922d41e..587af3b25581 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -848,7 +848,7 @@
   /* FIXME: Maybe also search the predecessor basic blocks to catch
      more cases.  */
   set_of_reg op = sh_find_set_of_reg (operands[0], curr_insn,
-				      prev_nonnote_insn_bb);
+				      prev_nonnote_nondebug_insn_bb);
 
   if (op.set_src != NULL && GET_CODE (op.set_src) == AND
       && !sh_insn_operands_modified_between_p (op.insn, op.insn, curr_insn))
@@ -939,7 +939,7 @@
   if (dump_file)
     fprintf (dump_file, "cmpgesi_t: trying to optimize for const_int 0\n");
 
-  rtx_insn* i = next_nonnote_insn_bb (curr_insn);
+  rtx_insn* i = next_nonnote_nondebug_insn_bb (curr_insn);
 
   if (dump_file)
     {
@@ -3094,7 +3094,7 @@
 	  && ! sh_dynamicalize_shift_p (shift_count))
 	{
 	  if (prev_set_t_insn == NULL)
-	    prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
+	    prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
 
 	  /* Skip the nott insn, which was probably inserted by the splitter
 	     of *rotcr_neg_t.  Don't use one of the recog functions
@@ -3106,7 +3106,7 @@
 	      if (GET_CODE (pat) == SET
 		  && t_reg_operand (XEXP (pat, 0), SImode)
 		  && negt_reg_operand (XEXP (pat, 1), SImode))
-	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
+	      prev_set_t_insn = prev_nonnote_nondebug_insn_bb (prev_set_t_insn);
 	    }
 
 	  if (! (prev_set_t_insn != NULL_RTX
@@ -3194,7 +3194,7 @@
       if (sh_ashlsi_clobbers_t_reg_p (shift_count)
 	  && ! sh_dynamicalize_shift_p (shift_count))
 	{
-	  prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
+	  prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
 
 	  /* Skip the nott insn, which was probably inserted by the splitter
 	     of *rotcl_neg_t.  Don't use one of the recog functions
@@ -3206,7 +3206,7 @@
 	      if (GET_CODE (pat) == SET
 		  && t_reg_operand (XEXP (pat, 0), SImode)
 		  && negt_reg_operand (XEXP (pat, 1), SImode))
-	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
+	      prev_set_t_insn = prev_nonnote_nondebug_insn_bb (prev_set_t_insn);
 	    }
 
 	  if (! (prev_set_t_insn != NULL_RTX
@@ -4423,7 +4423,7 @@
    When we're here, the not:SI pattern obviously has been matched already
    and we only have to see whether the following insn is the left shift.  */
 
-  rtx_insn *i = next_nonnote_insn_bb (curr_insn);
+  rtx_insn *i = next_nonnote_nondebug_insn_bb (curr_insn);
   if (i == NULL_RTX || !NONJUMP_INSN_P (i))
     FAIL;
 
@@ -10751,8 +10751,8 @@
 {
   rtx t_reg = get_t_reg_rtx ();
 
-  for (rtx_insn* i = prev_nonnote_insn_bb (curr_insn); i != NULL;
-       i = prev_nonnote_insn_bb (i))
+  for (rtx_insn* i = prev_nonnote_nondebug_insn_bb (curr_insn); i != NULL;
+       i = prev_nonnote_nondebug_insn_bb (i))
     {
       if (!INSN_P (i) || DEBUG_INSN_P (i))
 	continue;
diff --git a/gcc/config/sh/sh_treg_combine.cc b/gcc/config/sh/sh_treg_combine.cc
index cb3a7a85d173..0bbaf415db8f 100644
--- a/gcc/config/sh/sh_treg_combine.cc
+++ b/gcc/config/sh/sh_treg_combine.cc
@@ -291,7 +291,7 @@ find_set_of_reg_bb (rtx reg, rtx_insn *insn)
     return result;
 
   for (result.insn = insn; result.insn != NULL;
-       result.insn = prev_nonnote_insn_bb (result.insn))
+       result.insn = prev_nonnote_nondebug_insn_bb (result.insn))
     {
       if (BARRIER_P (result.insn))
 	return result;
@@ -750,7 +750,7 @@ sh_treg_combine::record_set_of_reg (rtx reg, rtx_insn *start_insn,
       log_msg ("tracing ccreg\n");
       new_entry.setcc =
 	  find_set_of_reg_bb (m_ccreg,
-			      prev_nonnote_insn_bb (new_entry.cstore.insn));
+			      prev_nonnote_nondebug_insn_bb (new_entry.cstore.insn));
 
       // If cstore was found but setcc was not found continue anyway, as
       // for some of the optimization types the setcc is irrelevant.
@@ -1353,7 +1353,7 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
   //   (set (reg ccreg) (eq (reg) (const_int 0)))
   // The testing insn could also be outside of the current basic block, but
   // for now we limit the search to the current basic block.
-  trace.setcc = find_set_of_reg_bb (m_ccreg, prev_nonnote_insn_bb (insn));
+  trace.setcc = find_set_of_reg_bb (m_ccreg, prev_nonnote_nondebug_insn_bb (insn));
 
   if (trace.setcc.set_src () == NULL_RTX)
     log_return_void ("could not find set of ccreg in current BB\n");
@@ -1413,7 +1413,7 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
   trace.bb_entries.push_front (bb_entry (trace.bb ()));
 
   record_return_t res =
-      record_set_of_reg (trace_reg, prev_nonnote_insn_bb (trace.setcc.insn),
+      record_set_of_reg (trace_reg, prev_nonnote_nondebug_insn_bb (trace.setcc.insn),
 			 trace.bb_entries.front ());
 
   if (res == other_set_found)
diff --git a/gcc/config/sh/sync.md b/gcc/config/sh/sync.md
index b46ac3131a8a..9f158bd93533 100644
--- a/gcc/config/sh/sync.md
+++ b/gcc/config/sh/sync.md
@@ -294,7 +294,7 @@
   /* FIXME: Sometimes the 'expected value' operand is not propagated as
      immediate value.  See PR 64974.  */
   set_of_reg op2 = sh_find_set_of_reg (operands[2], curr_insn,
-				       prev_nonnote_insn_bb);
+				       prev_nonnote_nondebug_insn_bb);
   if (op2.set_src != NULL && satisfies_constraint_I08 (op2.set_src))
     {
       rtx* r = &XVECEXP (XEXP (XVECEXP (PATTERN (curr_insn), 0, 0), 1), 0, 1);
Jakub Jelinek Dec. 14, 2017, 12:07 p.m. UTC | #4
On Thu, Dec 14, 2017 at 09:55:30AM -0200, Alexandre Oliva wrote:
> for  gcc/ChangeLog
> 
> 	PR bootstrap/83396
> 	* config/arc/arc.c (hwloop_optimize): Skip debug insns.
> 	* config/sh/sh-protos.h (sh_find_set_of_reg): Adjust.
> 	* config/sh/sh.c: Skip debug insns besides notes.
> 	* config/sh/sh.md: Likewise.
> 	* config/sh/sh_treg_combine.cc: Likewise.
> 	* config/sh/sync.md: Likewise.

Please fix up formatting.  Otherwise LGTM.

> --- a/gcc/config/sh/sh-protos.h
> +++ b/gcc/config/sh/sh-protos.h
> @@ -122,7 +122,7 @@ struct set_of_reg
>  
>  /* Given a reg rtx and a start insn, try to find the insn that sets the
>     specified reg by using the specified insn stepping function, such as 
> -   'prev_nonnote_insn_bb'.  When the insn is found, try to extract the rtx
> +   'prev_nonnote_nondebug_insn_bb'.  When the insn is found, try to extract the rtx

Too long line.

>     of the reg set.  */
>  template <typename F> inline set_of_reg
>  sh_find_set_of_reg (rtx reg, rtx_insn* insn, F stepfunc,
> diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
> index 0d7d7bc53ca2..3776415f1589 100644
> --- a/gcc/config/sh/sh.c
> +++ b/gcc/config/sh/sh.c
> @@ -11897,7 +11897,7 @@ sh_is_logical_t_store_expr (rtx op, rtx_insn* insn)
>        else
>  	{
>  	  set_of_reg op_set = sh_find_set_of_reg (ops[i], insn,
> -						  prev_nonnote_insn_bb);
> +						  prev_nonnote_nondebug_insn_bb);

Likewise.  Just do:
-	  set_of_reg op_set = sh_find_set_of_reg (ops[i], insn,
-						  prev_nonnote_insn_bb);
+	  set_of_reg op_set
+	    = sh_find_set_of_reg (ops[i], insn, prev_nonnote_nondebug_insn_bb);

> @@ -11929,7 +11929,7 @@ sh_try_omit_signzero_extend (rtx extended_op, rtx_insn* insn)
>    if (GET_MODE (extended_op) != SImode)
>      return NULL_RTX;
>  
> -  set_of_reg s = sh_find_set_of_reg (extended_op, insn, prev_nonnote_insn_bb);
> +  set_of_reg s = sh_find_set_of_reg (extended_op, insn, prev_nonnote_nondebug_insn_bb);

Likewise.

>    if (s.set_src == NULL_RTX)
>      return NULL_RTX;
>  
> @@ -11966,9 +11966,9 @@ sh_split_movrt_negc_to_movt_xor (rtx_insn* curr_insn, rtx operands[])
>      return false;
>  
>    set_of_reg t_before_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
> -						 prev_nonnote_insn_bb);
> +						 prev_nonnote_nondebug_insn_bb);
>    set_of_reg t_after_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
> -						next_nonnote_insn_bb);
> +						next_nonnote_nondebug_insn_bb);

2x further.
>  
>    if (t_before_negc.set_rtx != NULL_RTX && t_after_negc.set_rtx != NULL_RTX
>        && rtx_equal_p (t_before_negc.set_rtx, t_after_negc.set_rtx)
> @@ -12010,7 +12010,7 @@ sh_find_extending_set_of_reg (rtx reg, rtx_insn* curr_insn)
>       cases, where a zero_extend is followed an (implicit) sign_extend, and it
>       fails to see the sign_extend.  */
>    sh_extending_set_of_reg result =
> -	sh_find_set_of_reg (reg, curr_insn, prev_nonnote_insn_bb, true);
> +	sh_find_set_of_reg (reg, curr_insn, prev_nonnote_nondebug_insn_bb, true);

Likewise.

> @@ -3106,7 +3106,7 @@
>  	      if (GET_CODE (pat) == SET
>  		  && t_reg_operand (XEXP (pat, 0), SImode)
>  		  && negt_reg_operand (XEXP (pat, 1), SImode))
> -	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
> +	      prev_set_t_insn = prev_nonnote_nondebug_insn_bb (prev_set_t_insn);

Likewise.

> @@ -3206,7 +3206,7 @@
>  	      if (GET_CODE (pat) == SET
>  		  && t_reg_operand (XEXP (pat, 0), SImode)
>  		  && negt_reg_operand (XEXP (pat, 1), SImode))
> -	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
> +	      prev_set_t_insn = prev_nonnote_nondebug_insn_bb (prev_set_t_insn);

Likewise.

> @@ -750,7 +750,7 @@ sh_treg_combine::record_set_of_reg (rtx reg, rtx_insn *start_insn,
>        log_msg ("tracing ccreg\n");
>        new_entry.setcc =
>  	  find_set_of_reg_bb (m_ccreg,
> -			      prev_nonnote_insn_bb (new_entry.cstore.insn));
> +			      prev_nonnote_nondebug_insn_bb (new_entry.cstore.insn));

Likewise.  + = shouldn't be at the end of line.  I'm afraid best will be to
use a temporary here.
>  
>        // If cstore was found but setcc was not found continue anyway, as
>        // for some of the optimization types the setcc is irrelevant.
> @@ -1353,7 +1353,7 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
>    //   (set (reg ccreg) (eq (reg) (const_int 0)))
>    // The testing insn could also be outside of the current basic block, but
>    // for now we limit the search to the current basic block.
> -  trace.setcc = find_set_of_reg_bb (m_ccreg, prev_nonnote_insn_bb (insn));
> +  trace.setcc = find_set_of_reg_bb (m_ccreg, prev_nonnote_nondebug_insn_bb (insn));

Likewise.
>  
>    if (trace.setcc.set_src () == NULL_RTX)
>      log_return_void ("could not find set of ccreg in current BB\n");
> @@ -1413,7 +1413,7 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
>    trace.bb_entries.push_front (bb_entry (trace.bb ()));
>  
>    record_return_t res =
> -      record_set_of_reg (trace_reg, prev_nonnote_insn_bb (trace.setcc.insn),
> +      record_set_of_reg (trace_reg, prev_nonnote_nondebug_insn_bb (trace.setcc.insn),

Likewise.  The indentation and = is wrong.


	Jakub
Alexandre Oliva Dec. 14, 2017, 6:25 p.m. UTC | #5
On Dec 14, 2017, Jakub Jelinek <jakub@redhat.com> wrote:

> On Thu, Dec 14, 2017 at 09:55:30AM -0200, Alexandre Oliva wrote:
>> for  gcc/ChangeLog

> Please fix up formatting.  Otherwise LGTM.

Thanks, here's what I ended up installing (formatting fixes were
slightly different from what you suggested, but to the same effect)

[SFN] next/prev_nonnote_insn_bb are no more, even for ports

The patch that added _nondebug to next_ and prev_nonnote_insn_bb
failed to find and adjust uses within config.  Fixed.

for  gcc/ChangeLog

	PR bootstrap/83396
	* config/arc/arc.c (hwloop_optimize): Skip debug insns.
	* config/sh/sh-protos.h (sh_find_set_of_reg): Adjust.
	* config/sh/sh.c: Skip debug insns besides notes.
	* config/sh/sh.md: Likewise.
	* config/sh/sh_treg_combine.cc: Likewise.
	* config/sh/sync.md: Likewise.
---
 gcc/config/arc/arc.c             |    2 +-
 gcc/config/sh/sh-protos.h        |    8 ++++----
 gcc/config/sh/sh.c               |   19 ++++++++++---------
 gcc/config/sh/sh.md              |   20 +++++++++++---------
 gcc/config/sh/sh_treg_combine.cc |   16 ++++++++--------
 gcc/config/sh/sync.md            |    2 +-
 6 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index b8eec10086dd..9974a1f999b5 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -7499,7 +7499,7 @@ hwloop_optimize (hwloop_info loop)
                  && NOTE_KIND (entry_after) != NOTE_INSN_CALL_ARG_LOCATION))
         entry_after = NEXT_INSN (entry_after);
 #endif
-      entry_after = next_nonnote_insn_bb (entry_after);
+      entry_after = next_nonnote_nondebug_insn_bb (entry_after);
 
       gcc_assert (entry_after);
       emit_insn_before (seq, entry_after);
diff --git a/gcc/config/sh/sh-protos.h b/gcc/config/sh/sh-protos.h
index e98030d31bd7..938487501f30 100644
--- a/gcc/config/sh/sh-protos.h
+++ b/gcc/config/sh/sh-protos.h
@@ -120,10 +120,10 @@ struct set_of_reg
   rtx set_src;
 };
 
-/* Given a reg rtx and a start insn, try to find the insn that sets the
-   specified reg by using the specified insn stepping function, such as 
-   'prev_nonnote_insn_bb'.  When the insn is found, try to extract the rtx
-   of the reg set.  */
+/* Given a reg rtx and a start insn, try to find the insn that sets
+   the specified reg by using the specified insn stepping function,
+   such as 'prev_nonnote_nondebug_insn_bb'.  When the insn is found,
+   try to extract the rtx of the reg set.  */
 template <typename F> inline set_of_reg
 sh_find_set_of_reg (rtx reg, rtx_insn* insn, F stepfunc,
 		    bool ignore_reg_reg_copies = false)
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 0d7d7bc53ca2..85cc77b873a5 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -11896,8 +11896,8 @@ sh_is_logical_t_store_expr (rtx op, rtx_insn* insn)
 
       else
 	{
-	  set_of_reg op_set = sh_find_set_of_reg (ops[i], insn,
-						  prev_nonnote_insn_bb);
+	  set_of_reg op_set = sh_find_set_of_reg
+	    (ops[i], insn, prev_nonnote_nondebug_insn_bb);
 	  if (op_set.set_src == NULL_RTX)
 	    continue;
 
@@ -11929,7 +11929,8 @@ sh_try_omit_signzero_extend (rtx extended_op, rtx_insn* insn)
   if (GET_MODE (extended_op) != SImode)
     return NULL_RTX;
 
-  set_of_reg s = sh_find_set_of_reg (extended_op, insn, prev_nonnote_insn_bb);
+  set_of_reg s = sh_find_set_of_reg (extended_op, insn,
+				     prev_nonnote_nondebug_insn_bb);
   if (s.set_src == NULL_RTX)
     return NULL_RTX;
 
@@ -11965,10 +11966,10 @@ sh_split_movrt_negc_to_movt_xor (rtx_insn* curr_insn, rtx operands[])
   if (!can_create_pseudo_p ())
     return false;
 
-  set_of_reg t_before_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
-						 prev_nonnote_insn_bb);
-  set_of_reg t_after_negc = sh_find_set_of_reg (get_t_reg_rtx (), curr_insn,
-						next_nonnote_insn_bb);
+  set_of_reg t_before_negc = sh_find_set_of_reg
+    (get_t_reg_rtx (), curr_insn, prev_nonnote_nondebug_insn_bb);
+  set_of_reg t_after_negc = sh_find_set_of_reg
+    (get_t_reg_rtx (), curr_insn, next_nonnote_nondebug_insn_bb);
 
   if (t_before_negc.set_rtx != NULL_RTX && t_after_negc.set_rtx != NULL_RTX
       && rtx_equal_p (t_before_negc.set_rtx, t_after_negc.set_rtx)
@@ -12009,8 +12010,8 @@ sh_find_extending_set_of_reg (rtx reg, rtx_insn* curr_insn)
      Also try to look through the first extension that we hit.  There are some
      cases, where a zero_extend is followed an (implicit) sign_extend, and it
      fails to see the sign_extend.  */
-  sh_extending_set_of_reg result =
-	sh_find_set_of_reg (reg, curr_insn, prev_nonnote_insn_bb, true);
+  sh_extending_set_of_reg result = sh_find_set_of_reg
+    (reg, curr_insn, prev_nonnote_nondebug_insn_bb, true);
 
   if (result.set_src != NULL)
     {
diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 840fd922d41e..eb39b24e06da 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -848,7 +848,7 @@
   /* FIXME: Maybe also search the predecessor basic blocks to catch
      more cases.  */
   set_of_reg op = sh_find_set_of_reg (operands[0], curr_insn,
-				      prev_nonnote_insn_bb);
+				      prev_nonnote_nondebug_insn_bb);
 
   if (op.set_src != NULL && GET_CODE (op.set_src) == AND
       && !sh_insn_operands_modified_between_p (op.insn, op.insn, curr_insn))
@@ -939,7 +939,7 @@
   if (dump_file)
     fprintf (dump_file, "cmpgesi_t: trying to optimize for const_int 0\n");
 
-  rtx_insn* i = next_nonnote_insn_bb (curr_insn);
+  rtx_insn* i = next_nonnote_nondebug_insn_bb (curr_insn);
 
   if (dump_file)
     {
@@ -3094,7 +3094,7 @@
 	  && ! sh_dynamicalize_shift_p (shift_count))
 	{
 	  if (prev_set_t_insn == NULL)
-	    prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
+	    prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
 
 	  /* Skip the nott insn, which was probably inserted by the splitter
 	     of *rotcr_neg_t.  Don't use one of the recog functions
@@ -3106,7 +3106,8 @@
 	      if (GET_CODE (pat) == SET
 		  && t_reg_operand (XEXP (pat, 0), SImode)
 		  && negt_reg_operand (XEXP (pat, 1), SImode))
-	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
+		prev_set_t_insn = prev_nonnote_nondebug_insn_bb
+		  (prev_set_t_insn);
 	    }
 
 	  if (! (prev_set_t_insn != NULL_RTX
@@ -3194,7 +3195,7 @@
       if (sh_ashlsi_clobbers_t_reg_p (shift_count)
 	  && ! sh_dynamicalize_shift_p (shift_count))
 	{
-	  prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
+	  prev_set_t_insn = prev_nonnote_nondebug_insn_bb (curr_insn);
 
 	  /* Skip the nott insn, which was probably inserted by the splitter
 	     of *rotcl_neg_t.  Don't use one of the recog functions
@@ -3206,7 +3207,8 @@
 	      if (GET_CODE (pat) == SET
 		  && t_reg_operand (XEXP (pat, 0), SImode)
 		  && negt_reg_operand (XEXP (pat, 1), SImode))
-	      prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
+		prev_set_t_insn = prev_nonnote_nondebug_insn_bb
+		  (prev_set_t_insn);
 	    }
 
 	  if (! (prev_set_t_insn != NULL_RTX
@@ -4423,7 +4425,7 @@
    When we're here, the not:SI pattern obviously has been matched already
    and we only have to see whether the following insn is the left shift.  */
 
-  rtx_insn *i = next_nonnote_insn_bb (curr_insn);
+  rtx_insn *i = next_nonnote_nondebug_insn_bb (curr_insn);
   if (i == NULL_RTX || !NONJUMP_INSN_P (i))
     FAIL;
 
@@ -10751,8 +10753,8 @@
 {
   rtx t_reg = get_t_reg_rtx ();
 
-  for (rtx_insn* i = prev_nonnote_insn_bb (curr_insn); i != NULL;
-       i = prev_nonnote_insn_bb (i))
+  for (rtx_insn* i = prev_nonnote_nondebug_insn_bb (curr_insn); i != NULL;
+       i = prev_nonnote_nondebug_insn_bb (i))
     {
       if (!INSN_P (i) || DEBUG_INSN_P (i))
 	continue;
diff --git a/gcc/config/sh/sh_treg_combine.cc b/gcc/config/sh/sh_treg_combine.cc
index cb3a7a85d173..bae81af3126e 100644
--- a/gcc/config/sh/sh_treg_combine.cc
+++ b/gcc/config/sh/sh_treg_combine.cc
@@ -291,7 +291,7 @@ find_set_of_reg_bb (rtx reg, rtx_insn *insn)
     return result;
 
   for (result.insn = insn; result.insn != NULL;
-       result.insn = prev_nonnote_insn_bb (result.insn))
+       result.insn = prev_nonnote_nondebug_insn_bb (result.insn))
     {
       if (BARRIER_P (result.insn))
 	return result;
@@ -748,9 +748,8 @@ sh_treg_combine::record_set_of_reg (rtx reg, rtx_insn *start_insn,
       // Now see how the ccreg was set.
       // For now it must be in the same BB.
       log_msg ("tracing ccreg\n");
-      new_entry.setcc =
-	  find_set_of_reg_bb (m_ccreg,
-			      prev_nonnote_insn_bb (new_entry.cstore.insn));
+      new_entry.setcc = find_set_of_reg_bb
+	(m_ccreg, prev_nonnote_nondebug_insn_bb (new_entry.cstore.insn));
 
       // If cstore was found but setcc was not found continue anyway, as
       // for some of the optimization types the setcc is irrelevant.
@@ -1353,7 +1352,8 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
   //   (set (reg ccreg) (eq (reg) (const_int 0)))
   // The testing insn could also be outside of the current basic block, but
   // for now we limit the search to the current basic block.
-  trace.setcc = find_set_of_reg_bb (m_ccreg, prev_nonnote_insn_bb (insn));
+  trace.setcc = find_set_of_reg_bb
+    (m_ccreg, prev_nonnote_nondebug_insn_bb (insn));
 
   if (trace.setcc.set_src () == NULL_RTX)
     log_return_void ("could not find set of ccreg in current BB\n");
@@ -1412,9 +1412,9 @@ sh_treg_combine::try_optimize_cbranch (rtx_insn *insn)
   // If we find it here there's no point in checking other BBs.
   trace.bb_entries.push_front (bb_entry (trace.bb ()));
 
-  record_return_t res =
-      record_set_of_reg (trace_reg, prev_nonnote_insn_bb (trace.setcc.insn),
-			 trace.bb_entries.front ());
+  record_return_t res = record_set_of_reg
+    (trace_reg, prev_nonnote_nondebug_insn_bb (trace.setcc.insn),
+     trace.bb_entries.front ());
 
   if (res == other_set_found)
     log_return_void ("other set found - aborting trace\n");
diff --git a/gcc/config/sh/sync.md b/gcc/config/sh/sync.md
index b46ac3131a8a..9f158bd93533 100644
--- a/gcc/config/sh/sync.md
+++ b/gcc/config/sh/sync.md
@@ -294,7 +294,7 @@
   /* FIXME: Sometimes the 'expected value' operand is not propagated as
      immediate value.  See PR 64974.  */
   set_of_reg op2 = sh_find_set_of_reg (operands[2], curr_insn,
-				       prev_nonnote_insn_bb);
+				       prev_nonnote_nondebug_insn_bb);
   if (op2.set_src != NULL && satisfies_constraint_I08 (op2.set_src))
     {
       rtx* r = &XVECEXP (XEXP (XVECEXP (PATTERN (curr_insn), 0, 0), 1), 0, 1);
diff mbox series

Patch

diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index a0926752143d..77a221de2119 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -511,7 +511,7 @@  find_bb_boundaries (basic_block bb)
 	     the middle of a BB.  We need to split it in the same manner as
 	     if the barrier were preceded by a control_flow_insn_p insn.  */
 	  if (!flow_transfer_insn)
-	    flow_transfer_insn = prev_nonnote_insn_bb (insn);
+	    flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
 	}
 
       if (control_flow_insn_p (insn))
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index ae469088eecb..f788334ffb57 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -2281,11 +2281,11 @@  get_last_bb_insn (basic_block bb)
     end = table;
 
   /* Include any barriers that may follow the basic block.  */
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
   while (tmp && BARRIER_P (tmp))
     {
       end = tmp;
-      tmp = next_nonnote_insn_bb (end);
+      tmp = next_nonnote_nondebug_insn_bb (end);
     }
 
   return end;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index a07671164361..2823b2eb5bcd 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3370,20 +3370,17 @@  next_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE, but stop the
-   search before we enter another basic block.  This routine does not
-   look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a DEBUG_INSN.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_insn_bb (rtx_insn *insn)
+next_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
       insn = NEXT_INSN (insn);
-      if (insn == 0 || !NOTE_P (insn))
+      if (insn == 0 || !DEBUG_INSN_P (insn))
 	break;
-      if (NOTE_INSN_BASIC_BLOCK_P (insn))
-	return NULL;
     }
 
   return insn;
@@ -3405,67 +3402,70 @@  prev_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE, but stop
-   the search before we enter another basic block.  This routine does
-   not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn_bb (rtx_insn *insn)
+prev_nondebug_insn (rtx_insn *insn)
 {
-
   while (insn)
     {
       insn = PREV_INSN (insn);
-      if (insn == 0 || !NOTE_P (insn))
+      if (insn == 0 || !DEBUG_INSN_P (insn))
 	break;
-      if (NOTE_INSN_BASIC_BLOCK_P (insn))
-	return NULL;
     }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a DEBUG_INSN.  This
-   routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
       insn = NEXT_INSN (insn);
-      if (insn == 0 || !DEBUG_INSN_P (insn))
+      if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
 	break;
     }
 
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
+   but stop the search before we enter another basic block.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
     {
-      insn = PREV_INSN (insn);
-      if (insn == 0 || !DEBUG_INSN_P (insn))
+      insn = NEXT_INSN (insn);
+      if (insn == 0)
+	break;
+      if (DEBUG_INSN_P (insn))
+	continue;
+      if (!NOTE_P (insn))
 	break;
+      if (NOTE_INSN_BASIC_BLOCK_P (insn))
+	return NULL;
     }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+/* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
    This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_nondebug_insn (rtx_insn *insn)
+prev_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
     {
-      insn = NEXT_INSN (insn);
+      insn = PREV_INSN (insn);
       if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
 	break;
     }
@@ -3473,17 +3473,24 @@  next_nonnote_nondebug_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a NOTE nor
+   DEBUG_INSN, but stop the search before we enter another basic
+   block.  This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_nondebug_insn (rtx_insn *insn)
+prev_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
     {
       insn = PREV_INSN (insn);
-      if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
+      if (insn == 0)
 	break;
+      if (DEBUG_INSN_P (insn))
+	continue;
+      if (!NOTE_P (insn))
+	break;
+      if (NOTE_INSN_BASIC_BLOCK_P (insn))
+	return NULL;
     }
 
   return insn;
diff --git a/gcc/lra.c b/gcc/lra.c
index 66fbfd5477b3..88d75c18e86c 100644
--- a/gcc/lra.c
+++ b/gcc/lra.c
@@ -1805,7 +1805,7 @@  push_insns (rtx_insn *from, rtx_insn *to)
 static void
 setup_sp_offset (rtx_insn *from, rtx_insn *last)
 {
-  rtx_insn *before = next_nonnote_insn_bb (last);
+  rtx_insn *before = next_nonnote_nondebug_insn_bb (last);
   HOST_WIDE_INT offset = (before == NULL_RTX || ! INSN_P (before)
 			  ? 0 : lra_get_insn_recog_data (before)->sp_offset);
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 8de5a1cada5a..9cc982172f53 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3085,13 +3085,13 @@  extern rtx_call_insn *last_call_insn (void);
 extern rtx_insn *previous_insn (rtx_insn *);
 extern rtx_insn *next_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_insn (rtx_insn *);
-extern rtx_insn *prev_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_insn (rtx_insn *);
-extern rtx_insn *next_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *prev_nondebug_insn (rtx_insn *);
 extern rtx_insn *next_nondebug_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_nondebug_insn (rtx_insn *);
+extern rtx_insn *prev_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_nondebug_insn (rtx_insn *);
+extern rtx_insn *next_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *prev_real_insn (rtx_insn *);
 extern rtx_insn *next_real_insn (rtx);
 extern rtx_insn *prev_active_insn (rtx_insn *);