[Bug tree-optimization/50417] regression: memcpy with known alignment

olegendo at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 8 12:26:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50417

--- Comment #11 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to rguenther@suse.de from comment #10)
> 
> What makes the parameter type special?  Would
> 
> void test (const int *a, int *b)
> {
>   std::memcpy ((char *)b, (char *)a, t);
> }
> 
> be invalid to optimize to an aligned copy in your eyes?

I think it's perfectly valid to optimize this case.  It could as well be
something like:

void test (const int *a, int *b)
{
  a[100] = 1;
  b[200] = 2;

  std::memcpy ((char *)b, (char *)a, t);
}

where a[100] and b[200] both would result in 32 bit accesses, not 4x1 byte or
something, because the base pointer is assumed to be int aligned.  Why should
memcpy be any different?


More information about the Gcc-bugs mailing list