This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: ARM memcpy on unaligned pointers and -O2
- From: Shaun Jackman <sjackman at pathwayconnect dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 13 Dec 2001 09:53:01 -0700
- Subject: Re: ARM memcpy on unaligned pointers and -O2
- Organization: Pathway Connectivity
- References: <200112131024.KAA28446@cam-mail2.cambridge.arm.com>
On December 13, 2001 03:24, you wrote:
> > I believe I've found a bug in GCC 3.0.2 wrt the ARM target and -O2
> > optimisation. I found it when I wrote the following functions to load and
> > store unaligned pointers. This is the objdump -S output.
[ clip ]
> > As you can see this did not have the intended effect. GCC recognised the
> > length of the memcpy as being constant and optimised it away to a simple
> > ldr or str instruction. What it doesn't seem to have taken into account
> > though, is the fact that the pointer it's passed may not be aligned. I
> > believe it's allowed to pass unaligned pointers to memcpy and the
> > compiler should handle it correctly.
>
> No, your pointer is aligned. You declared it to be so in the declarations
> of your functions. Having done this, the compiler can and does use this
> knowledge to optimise the code.
>
> R.
I recognized that afterwords and cast the arguments to memcpy()
uint32
ld32( const uint32* p)
{
uint32 ret;
memcpy( &ret, (uint8*)p, sizeof( ret));
return ret;
}
void
str32( uint32* p, uint32 val)
{
memcpy( (uint8*)p, &val, sizeof( *p));
}
It seems the behaviour persists though. In fact, it has the exact same
behaviour if I change the parameters from uint32* to void*.
Please cc me as I'm not a member of this list,
Thanks,
Shaun