diff mbox

[21/50] Faster for_each_rtx-like iterators

Message ID 87fvhdacp8.fsf@googlemail.com
State New
Headers show

Commit Message

Richard Sandiford Aug. 3, 2014, 2:07 p.m. UTC
The switch statement in the old code seemed overly cautious.  It's well
established elsewhere that the first operand of an RTX_AUTOINC is the
automodified register.  If anyone wanted to add a new code for which that
wasn't true they should (a) reconsider or (b) go through all RTX_AUTOINCs
as a precaution.


gcc/
	* emit-rtl.c: Include rtl-iter.h.
	(find_auto_inc): Turn from being a for_each_rtx callback to being
	a function that examines each subrtx itself.  Assume the first operand
	to an RTX_AUTOINC is the automodified register.
	(try_split): Update call accordingly.

Comments

Jeff Law Aug. 5, 2014, 9:09 p.m. UTC | #1
On 08/03/14 08:07, Richard Sandiford wrote:
> The switch statement in the old code seemed overly cautious.  It's well
> established elsewhere that the first operand of an RTX_AUTOINC is the
> automodified register.  If anyone wanted to add a new code for which that
> wasn't true they should (a) reconsider or (b) go through all RTX_AUTOINCs
> as a precaution.
>
>
> gcc/
> 	* emit-rtl.c: Include rtl-iter.h.
> 	(find_auto_inc): Turn from being a for_each_rtx callback to being
> 	a function that examines each subrtx itself.  Assume the first operand
> 	to an RTX_AUTOINC is the automodified register.
> 	(try_split): Update call accordingly.
OK.

It seems like we ought to document somewhere that all autoincrement RTXs 
increment their first operand.  If you can find a goodplace, please add 
that little doc update as a pre-approved patch.

jeff
diff mbox

Patch

Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	2014-08-03 11:25:10.047955517 +0100
+++ gcc/emit-rtl.c	2014-08-03 11:25:26.062113842 +0100
@@ -58,6 +58,7 @@  Software Foundation; either version 3, o
 #include "params.h"
 #include "target.h"
 #include "builtins.h"
+#include "rtl-iter.h"
 
 struct target_rtl default_target_rtl;
 #if SWITCHABLE_TARGET
@@ -3485,30 +3486,17 @@  prev_cc0_setter (rtx insn)
 /* Find a RTX_AUTOINC class rtx which matches DATA.  */
 
 static int
-find_auto_inc (rtx *xp, void *data)
+find_auto_inc (const_rtx x, const_rtx reg)
 {
-  rtx x = *xp;
-  rtx reg = (rtx) data;
-
-  if (GET_RTX_CLASS (GET_CODE (x)) != RTX_AUTOINC)
-    return 0;
-
-  switch (GET_CODE (x))
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
     {
-      case PRE_DEC:
-      case PRE_INC:
-      case POST_DEC:
-      case POST_INC:
-      case PRE_MODIFY:
-      case POST_MODIFY:
-	if (rtx_equal_p (reg, XEXP (x, 0)))
-	  return 1;
-	break;
-
-      default:
-	gcc_unreachable ();
+      const_rtx x = *iter;
+      if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC
+	  && rtx_equal_p (reg, XEXP (x, 0)))
+	return true;
     }
-  return -1;
+  return false;
 }
 #endif
 
@@ -3695,7 +3683,7 @@  try_split (rtx pat, rtx trial, int last)
 	    {
 	      rtx reg = XEXP (note, 0);
 	      if (!FIND_REG_INC_NOTE (insn, reg)
-		  && for_each_rtx (&PATTERN (insn), find_auto_inc, reg) > 0)
+		  && find_auto_inc (PATTERN (insn), reg))
 		add_reg_note (insn, REG_INC, reg);
 	    }
 	  break;