[PATCH] Fix PR target/34403

Eric Botcazou ebotcazou@libertysurf.fr
Mon Dec 10 20:16:00 GMT 2007


This is a regression present on the mainline.  The ICE triggered by the 
attached C++ testcase can be reproduced with

void foo(char *dest, char *src)
{
  __builtin_memcpy (dest, src, 0xfffffffc);
}

pr34403.c: In function 'foo':
pr34403.c:4: error: verify_flow_info: Wrong frequency of block 7 -1247
pr34403.c:4: error: verify_flow_info: Wrong frequency of block 6 -2248
pr34403.c:4: error: verify_flow_info: Wrong probability of edge 5->5 12499
pr34403.c:4: error: verify_flow_info: Wrong probability of edge 5->6 -2499
pr34403.c:4: internal compiler error: verify_flow_info failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


The problem stems from the new string operation code in the i386 back-end, 
more specifically:

static void
expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
			       rtx destptr, rtx srcptr, rtx value,
			       rtx count, enum machine_mode mode, int unroll,
			       int expected_size)
[...]

  if (expected_size != -1)
    {
      expected_size /= GET_MODE_SIZE (mode) * unroll;
      if (expected_size == 0)
	predict_jump (0);
      else if (expected_size > REG_BR_PROB_BASE)
	predict_jump (REG_BR_PROB_BASE - 1);
      else
        predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 
2) / expected_size);
    }
  else
    predict_jump (REG_BR_PROB_BASE * 80 / 100);

because expected_size is negative here.


We could skip the prediction in this case, but then the compiler emits a loop 
whose counter overflows at runtime, so I think that the safest solution is to 
punt and to emit a call to memcpy instead.

Tested on i586-suse-linux, OK for mainline?


2007-12-10  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR target/34403
	* config/i386/i386.c (ix86_expand_movmem): Punt if the count is large.
	(ix86_expand_setmem): Likewise.


2007-12-10  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* g++.dg/opt/memcpy1.C: New test.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr34403.diff
Type: text/x-diff
Size: 1415 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071210/7cfedb48/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memcpy1.C
Type: text/x-c++src
Size: 1889 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071210/7cfedb48/attachment-0001.bin>


More information about the Gcc-patches mailing list