This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix a recent warning in reorg.c


On Tue, Apr 26, 2016 at 03:13:32PM +0200, Bernd Schmidt wrote:
> On 04/26/2016 03:08 PM, Jakub Jelinek wrote:
> >        ^
> >../../gcc/reorg.c:1413:25: warning:   matches this âiâ under old rules
> >        for (unsigned int i = len - 1; i < len; i--)
> >                          ^
> 
> Oh, and also - I flagged this while reviewing other parts of Trevor's
> changes, this pattern is too ugly to live, that should be a
> FOR_EACH_VEC_ELT_....

That would be FOR_EACH_VEC_ELT_REVERSE, but unfortunately that doesn't
really work.

The iterate template does:

template<typename T, typename A>
inline bool
vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const
{
  if (ix < m_vecpfx.m_num)
    {
      *ptr = m_vecdata[ix];
      return true;
    }
  else
    {
      *ptr = 0;
      return false;
    }
}

and the element in this case is std::pair <rtx_insn *, bool>, for which
*ptr = 0; doesn't work (maybe *ptr = T (); would work in there instead,
dunno).

So is the following ok if it passes bootstrap/regtest, or shall I do
something about vec.h?

2016-04-26  Jakub Jelinek  <jakub@redhat.com>

	* reorg.c (try_merge_delay_insns): Declare i and j inside the
	for loops rather than one for the whole function.

--- gcc/reorg.c.jj	2016-04-26 08:08:16.000000000 +0200
+++ gcc/reorg.c	2016-04-26 17:32:22.553670734 +0200
@@ -1260,7 +1260,6 @@ try_merge_delay_insns (rtx_insn *insn, r
   rtx next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
   struct resources set, needed, modified;
   auto_vec<std::pair<rtx_insn *, bool>, 10> merged_insns;
-  int i, j;
   int flags;
 
   flags = get_jump_flags (delay_insn, JUMP_LABEL (delay_insn));
@@ -1275,7 +1274,7 @@ try_merge_delay_insns (rtx_insn *insn, r
      will essentially disable this optimization.  This method is somewhat of
      a kludge, but I don't see a better way.)  */
   if (! annul_p)
-    for (i = 1 ; i < num_slots; i++)
+    for (int i = 1; i < num_slots; i++)
       if (XVECEXP (PATTERN (insn), 0, i))
 	mark_referenced_resources (XVECEXP (PATTERN (insn), 0, i), &needed,
 				   true);
@@ -1346,19 +1345,19 @@ try_merge_delay_insns (rtx_insn *insn, r
       mark_set_resources (filled_insn, &set, 0, MARK_SRC_DEST_CALL);
       mark_referenced_resources (filled_insn, &needed, true);
 
-      for (i = 1; i < pat->len (); i++)
+      for (int i = 1; i < pat->len (); i++)
 	{
 	  rtx_insn *dtrial = pat->insn (i);
 
 	  CLEAR_RESOURCE (&modified);
 	  /* Account for resources set by the insn following NEXT_TO_MATCH
 	     inside INSN's delay list. */
-	  for (j = 1; slot_number + j < num_slots; j++)
+	  for (int j = 1; slot_number + j < num_slots; j++)
 	    mark_set_resources (XVECEXP (PATTERN (insn), 0, slot_number + j),
 				&modified, 0, MARK_SRC_DEST_CALL);
 	  /* Account for resources set by the insn before DTRIAL and inside
 	     TRIAL's delay list. */
-	  for (j = 1; j < i; j++)
+	  for (int j = 1; j < i; j++)
 	    mark_set_resources (XVECEXP (pat, 0, j),
 				&modified, 0, MARK_SRC_DEST_CALL); 
 	  if (! insn_references_resource_p (dtrial, &set, true)
@@ -1411,24 +1410,22 @@ try_merge_delay_insns (rtx_insn *insn, r
     {
       unsigned int len = merged_insns.length ();
       for (unsigned int i = len - 1; i < len; i--)
-	{
-	  if (merged_insns[i].second)
-	    {
-	      update_block (merged_insns[i].first, thread);
-	      rtx_insn *new_rtx = delete_from_delay_slot (merged_insns[i].first);
-	      if (thread->deleted ())
-		thread = new_rtx;
-	    }
-	  else
-	    {
-	      update_block (merged_insns[i].first, thread);
-	      delete_related_insns (merged_insns[i].first);
-	    }
-	}
+	if (merged_insns[i].second)
+	  {
+	    update_block (merged_insns[i].first, thread);
+	    rtx_insn *new_rtx = delete_from_delay_slot (merged_insns[i].first);
+	    if (thread->deleted ())
+	      thread = new_rtx;
+	  }
+	else
+	  {
+	    update_block (merged_insns[i].first, thread);
+	    delete_related_insns (merged_insns[i].first);
+	  }
 
       INSN_ANNULLED_BRANCH_P (delay_insn) = 0;
 
-      for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
+      for (int i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
 	INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i)) = 0;
     }
 }


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]