[PATCH] Stop looping in move_by_pieces loops when there's no more data to process

Tom de Vries Tom_deVries@mentor.com
Tue Oct 16 06:53:00 GMT 2012


Jakub,

I've noticed that the move_by_pieces loops keep iterating after there's no more
data to process.

I've added this assert to trigger an example in a gcc build:
...
Index: src/gcc/expr.c
===================================================================
--- src/gcc/expr.c (revision 191792)
+++ src/gcc/expr.c (working copy)
@@ -1031,6 +1031,8 @@ move_by_pieces_ninsns (unsigned HOST_WID
       enum machine_mode mode;
       enum insn_code icode;

+      gcc_assert (l > 0);
+
       mode = widest_int_mode_for_size (max_size);

       if (mode == VOIDmode)
...

It triggers while compiling __gcov_execle. After l is 0, we still enter the loop
until we run out of modes to try:
...
Breakpoint 2, move_by_pieces_ninsns (l=24, align=64, max_size=9) at expr.c:1025
1025	  unsigned HOST_WIDE_INT n_insns = 0;
(gdb) n
1027	  align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
(gdb)
1029	  while (max_size > 1)
(gdb)
1034	      gcc_assert (l > 0);
(gdb)
1036	      mode = widest_int_mode_for_size (max_size);
(gdb)
1038	      if (mode == VOIDmode)
(gdb)
1041	      icode = optab_handler (mov_optab, mode);
(gdb)
1042	      if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
(gdb)
1043		n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
(gdb)
1045	      max_size = GET_MODE_SIZE (mode);
(gdb)
1029	  while (max_size > 1)
(gdb) p l
$3 = 0
(gdb) p max_size
$4 = 8
(gdb) n
1034	      gcc_assert (l > 0);
(gdb)
...

This patch fixes that in this loop, and other move_by_pieces loops.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

2012-10-16  Tom de Vries  <tom@codesourcery.com>

	* expr.c (move_by_pieces, move_by_pieces_ninsns, can_store_by_pieces)
	(store_by_pieces_1): Don't enter loop when no more data is left.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expr.patch
Type: text/x-patch
Size: 1279 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20121016/b3c411c4/attachment.bin>


More information about the Gcc-patches mailing list