diff mbox

macroize away GET_CLASS_NARROWEST_MODE/GET_MODE_WIDER_MODE loops

Message ID 20101101013510.GH6758@nightcrawler
State New
Headers show

Commit Message

Nathan Froyd Nov. 1, 2010, 1:35 a.m. UTC
The patch below takes a fairly common idiom:

  for (X = GET_CLASS_NARROWEST_MODE (C); X != VOIDmode; X =
       GET_MODE_WIDER_MODE (X))

turns it into a macro and replaces all such uses with the macro.

Comments welcome on the name; FOR_MODE_IN_CLASS might be preferred if
this idiom is the canonical way to iterate through a class's modes.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/
	* emit-rtl.c (init_emit_once): Use FOR_EACH_MODE_IN_CLASS_WIDTHWISE.
	* explow.c (hard_function_value): Likewise.
	* expmed.c (init_expmed, extract_fixed_bit_field): Likewise.
	* expr.c (init_expr_target, move_by_pieces): Likewise.
	(move_by_pieces_ninsns, emit_block_move_via_movmem): Likewise.
	(can_store_by_pieces, store_by_pieces_1): Likewise.
	(set_storage_via_setmem): Likewise.
	* optabs.c (prepare_cmp_insns): Likewise.
	* reg-stack.c (reg_to_stack): Likewise.
	* reginfo.c (choose_hard_reg_mode): Likewise.
	* rtlanal.c (init_num_sign_bit_copies_in_rep): Likewise.
	* stmt.c (expand_return): Likewise.
	* stor-layout.c (mode_for_size, smallest_mode_for_size): Likewise.
	(get_best_mode): Likewise.

gcc/ada/
	* gcc-interface/misc.c (fp_prec_to_size, fp_size_to_prec):
	Use FOR_EACH_MODE_IN_CLASS_WIDTHWISE.
diff mbox

Patch

diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c
index a1b2490..357890a 100644
--- a/gcc/ada/gcc-interface/misc.c
+++ b/gcc/ada/gcc-interface/misc.c
@@ -656,8 +656,7 @@  fp_prec_to_size (int prec)
 {
   enum machine_mode mode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
     if (GET_MODE_PRECISION (mode) == prec)
       return GET_MODE_BITSIZE (mode);
 
@@ -671,8 +670,7 @@  fp_size_to_prec (int size)
 {
   enum machine_mode mode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
     if (GET_MODE_BITSIZE (mode) == size)
       return GET_MODE_PRECISION (mode);
 
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 19d290c..13bf8bf 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -5758,9 +5758,7 @@  init_emit_once (void)
   word_mode = VOIDmode;
   double_mode = VOIDmode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     {
       if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
 	  && byte_mode == VOIDmode)
@@ -5771,9 +5769,7 @@  init_emit_once (void)
 	word_mode = mode;
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
     {
       if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
 	  && double_mode == VOIDmode)
@@ -5819,66 +5815,48 @@  init_emit_once (void)
       const REAL_VALUE_TYPE *const r =
 	(i == 0 ? &dconst0 : i == 1 ? &dconst1 : &dconst2);
 
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
 	const_tiny_rtx[i][(int) mode] =
 	  CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
 
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_DECIMAL_FLOAT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_DECIMAL_FLOAT)
 	const_tiny_rtx[i][(int) mode] =
 	  CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
 
       const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
 
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
 	const_tiny_rtx[i][(int) mode] = GEN_INT (i);
 
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_PARTIAL_INT)
 	const_tiny_rtx[i][(int) mode] = GEN_INT (i);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_INT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_COMPLEX_INT)
     {
       rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
       const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_COMPLEX_FLOAT)
     {
       rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
       const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_INT)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
       const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_FLOAT)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
       const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FRACT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FRACT)
     {
       FCONST0(mode).data.high = 0;
       FCONST0(mode).data.low = 0;
@@ -5887,9 +5865,7 @@  init_emit_once (void)
 				      FCONST0 (mode), mode);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_UFRACT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_UFRACT)
     {
       FCONST0(mode).data.high = 0;
       FCONST0(mode).data.low = 0;
@@ -5898,9 +5874,7 @@  init_emit_once (void)
 				      FCONST0 (mode), mode);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_ACCUM);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_ACCUM)
     {
       FCONST0(mode).data.high = 0;
       FCONST0(mode).data.low = 0;
@@ -5921,9 +5895,7 @@  init_emit_once (void)
 				      FCONST1 (mode), mode);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_UACCUM);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_UACCUM)
     {
       FCONST0(mode).data.high = 0;
       FCONST0(mode).data.low = 0;
@@ -5944,31 +5916,23 @@  init_emit_once (void)
 				      FCONST1 (mode), mode);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FRACT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_FRACT)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UFRACT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_UFRACT)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_ACCUM);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_ACCUM)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
       const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
     }
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UACCUM);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_UACCUM)
     {
       const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
       const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
diff --git a/gcc/explow.c b/gcc/explow.c
index a83c6e8..1b3336a 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -1853,14 +1853,10 @@  hard_function_value (const_tree valtype, const_tree func, const_tree fntype,
 	 since the value of bytes will then be large enough that no
 	 mode will match anyway.  */
 
-      for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmpmode != VOIDmode;
-	   tmpmode = GET_MODE_WIDER_MODE (tmpmode))
-	{
-	  /* Have we found a large enough mode?  */
-	  if (GET_MODE_SIZE (tmpmode) >= bytes)
-	    break;
-	}
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmpmode, MODE_INT)
+	/* Have we found a large enough mode?  */
+	if (GET_MODE_SIZE (tmpmode) >= bytes)
+	  break;
 
       /* No suitable mode found.  */
       gcc_assert (tmpmode != VOIDmode);
diff --git a/gcc/expmed.c b/gcc/expmed.c
index 7ff55e7..43a55a0 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -192,9 +192,7 @@  init_expmed (void)
       crtl->maybe_hot_insn_p = speed;
       zero_cost[speed] = rtx_cost (const0_rtx, SET, speed);
 
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
 	{
 	  PUT_MODE (&all.reg, mode);
 	  PUT_MODE (&all.plus, mode);
@@ -1867,8 +1865,7 @@  extract_fixed_bit_field (enum machine_mode tmode, rtx op0,
 
   /* Find the narrowest integer mode that contains the field.  */
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     if (GET_MODE_BITSIZE (mode) >= bitsize + bitpos)
       {
 	op0 = convert_to_mode (mode, op0, 0);
diff --git a/gcc/expr.c b/gcc/expr.c
index 56f6eda..f74f94e 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -271,8 +271,7 @@  init_expr_target (void)
 
   mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
     {
       enum machine_mode srcmode;
       for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
@@ -880,8 +879,7 @@  move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
       && move_by_pieces_ninsns (len, align, max_size) > 2)
     {
       /* Find the mode of the largest move...  */
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	if (GET_MODE_SIZE (tmode) < max_size)
 	  mode = tmode;
 
@@ -939,8 +937,7 @@  move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
 
   while (max_size > 1)
     {
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	if (GET_MODE_SIZE (tmode) < max_size)
 	  mode = tmode;
 
@@ -1020,8 +1017,7 @@  move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
       enum machine_mode mode = VOIDmode;
       enum insn_code icode;
 
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	if (GET_MODE_SIZE (tmode) < max_size)
 	  mode = tmode;
 
@@ -1266,8 +1262,7 @@  emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
      including more than one in the machine description unless
      the more limited one has some advantage.  */
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     {
       enum insn_code code = direct_optab_handler (movmem_optab, mode);
       insn_operand_predicate_fn pred;
@@ -2300,8 +2295,7 @@  can_store_by_pieces (unsigned HOST_WIDE_INT len,
       max_size = STORE_MAX_PIECES + 1;
       while (max_size > 1)
 	{
-	  for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	       tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+	  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	    if (GET_MODE_SIZE (tmode) < max_size)
 	      mode = tmode;
 
@@ -2466,8 +2460,7 @@  store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
       && move_by_pieces_ninsns (data->len, align, max_size) > 2)
     {
       /* Determine the main mode we'll be using.  */
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	if (GET_MODE_SIZE (tmode) < max_size)
 	  mode = tmode;
 
@@ -2513,8 +2506,7 @@  store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
 
   while (max_size > 1)
     {
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	if (GET_MODE_SIZE (tmode) < max_size)
 	  mode = tmode;
 
@@ -2742,8 +2734,7 @@  set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
   if (expected_align < align)
     expected_align = align;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     {
       enum insn_code code = direct_optab_handler (setmem_optab, mode);
       insn_operand_predicate_fn pred;
diff --git a/gcc/machmode.h b/gcc/machmode.h
index 3ab7a81..198d281 100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -265,6 +265,13 @@  extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
 #define GET_CLASS_NARROWEST_MODE(CLASS) \
   ((enum machine_mode) class_narrowest_mode[CLASS])
 
+/* Convenience macro for iterating over modes in a class from narrowest
+   to widest.  */
+
+#define FOR_EACH_MODE_IN_CLASS_WIDTHWISE(MODE, CLASS)			\
+  for ((MODE) = GET_CLASS_NARROWEST_MODE (CLASS); (MODE) != VOIDmode;	\
+       (MODE) = GET_MODE_WIDER_MODE (MODE))
+
 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
    and the mode whose class is Pmode and whose size is POINTER_SIZE.  */
 
diff --git a/gcc/optabs.c b/gcc/optabs.c
index 5d095c1..597c791 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -4034,9 +4034,7 @@  prepare_cmp_insn (rtx x, rtx y, enum rtx_code comparison, rtx size,
 
       /* Try to use a memory block compare insn - either cmpstr
 	 or cmpmem will do.  */
-      for (cmp_mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	   cmp_mode != VOIDmode;
-	   cmp_mode = GET_MODE_WIDER_MODE (cmp_mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (cmp_mode, MODE_INT)
 	{
 	  cmp_code = direct_optab_handler (cmpmem_optab, cmp_mode);
 	  if (cmp_code == CODE_FOR_nothing)
diff --git a/gcc/reg-stack.c b/gcc/reg-stack.c
index 98c5fce..a2da314 100644
--- a/gcc/reg-stack.c
+++ b/gcc/reg-stack.c
@@ -3228,13 +3228,9 @@  reg_to_stack (void)
   for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
     {
       enum machine_mode mode;
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
 	FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
-      for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
-	   mode != VOIDmode;
-	   mode = GET_MODE_WIDER_MODE (mode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_COMPLEX_FLOAT)
 	FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
     }
 
diff --git a/gcc/reginfo.c b/gcc/reginfo.c
index c8192de..8f8cb2f 100644
--- a/gcc/reginfo.c
+++ b/gcc/reginfo.c
@@ -690,9 +690,7 @@  choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
      held in REGNO.  If none, we look for the largest floating-point mode.
      If we still didn't find a valid mode, try CCmode.  */
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
 	&& HARD_REGNO_MODE_OK (regno, mode)
 	&& (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
@@ -701,9 +699,7 @@  choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
   if (found_mode != VOIDmode)
     return found_mode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_FLOAT)
     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
 	&& HARD_REGNO_MODE_OK (regno, mode)
 	&& (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
@@ -712,9 +708,7 @@  choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
   if (found_mode != VOIDmode)
     return found_mode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_FLOAT)
     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
 	&& HARD_REGNO_MODE_OK (regno, mode)
 	&& (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
@@ -723,9 +717,7 @@  choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
   if (found_mode != VOIDmode)
     return found_mode;
 
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
-       mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_VECTOR_INT)
     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
 	&& HARD_REGNO_MODE_OK (regno, mode)
 	&& (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 930828a..8e8fd08 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -4997,8 +4997,7 @@  init_num_sign_bit_copies_in_rep (void)
 {
   enum machine_mode mode, in_mode;
 
-  for (in_mode = GET_CLASS_NARROWEST_MODE (MODE_INT); in_mode != VOIDmode;
-       in_mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (in_mode, MODE_INT)
     for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != in_mode;
 	 mode = GET_MODE_WIDER_MODE (mode))
       {
diff --git a/gcc/stmt.c b/gcc/stmt.c
index c8f56f5..3ea52bc 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -1753,9 +1753,7 @@  expand_return (tree retval)
 	  /* Find the smallest integer mode large enough to hold the
 	     entire structure and use that mode instead of BLKmode
 	     on the USE insn for the return register.  */
-	  for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
-	       tmpmode != VOIDmode;
-	       tmpmode = GET_MODE_WIDER_MODE (tmpmode))
+	  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmpmode, MODE_INT)
 	    /* Have we found a large enough mode?  */
 	    if (GET_MODE_SIZE (tmpmode) >= bytes)
 	      break;
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 17e4fe5..3965d87 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -411,8 +411,7 @@  mode_for_size (unsigned int size, enum mode_class mclass, int limit)
     return BLKmode;
 
   /* Get the first mode which has this size, in the specified class.  */
-  for (mode = GET_CLASS_NARROWEST_MODE (mclass); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, mclass)
     if (GET_MODE_PRECISION (mode) == size)
       return mode;
 
@@ -446,8 +445,7 @@  smallest_mode_for_size (unsigned int size, enum mode_class mclass)
 
   /* Get the first mode which has at least this size, in the
      specified class.  */
-  for (mode = GET_CLASS_NARROWEST_MODE (mclass); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, mclass)
     if (GET_MODE_PRECISION (mode) >= size)
       return mode;
 
@@ -2463,8 +2461,7 @@  get_best_mode (int bitsize, int bitpos, unsigned int align,
   unsigned int unit = 0;
 
   /* Find the narrowest integer mode that contains the bit field.  */
-  for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
-       mode = GET_MODE_WIDER_MODE (mode))
+  FOR_EACH_MODE_IN_CLASS_WIDTHWISE (mode, MODE_INT)
     {
       unit = GET_MODE_BITSIZE (mode);
       if ((bitpos % unit) + bitsize <= unit)
@@ -2488,8 +2485,7 @@  get_best_mode (int bitsize, int bitpos, unsigned int align,
     {
       enum machine_mode wide_mode = VOIDmode, tmode;
 
-      for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
-	   tmode = GET_MODE_WIDER_MODE (tmode))
+      FOR_EACH_MODE_IN_CLASS_WIDTHWISE (tmode, MODE_INT)
 	{
 	  unit = GET_MODE_BITSIZE (tmode);
 	  if (bitpos / unit == (bitpos + bitsize - 1) / unit