Re: [PATCH] LoongArch: Improve memory ops

From: Xi Ruoyao
Date: Mon Apr 10 2023 - 10:36:56 EST


On Mon, 2023-04-10 at 22:22 +0800, Rui Wang wrote:
> On Mon, Apr 10, 2023 at 8:54 PM Xi Ruoyao <xry111@xxxxxxxxxxx> wrote:
> > Regarding these functions: we have -ffreestanding which is
> > preventing
> > the compiler from optimizing for e.g. "memcpy(a, b, 8);" into a
> > simple
> > ld.d/st.d pair.  A explicit compiler built-in usage like
> >
> >   #define memcpy(a, b, c) __builtin_memcpy(a, b, c)
> >
> > would allow the compiler to do such kind of optimization.   Will
> > this
> > improve the performance?
>
> That's a good question. IIUC, the current compiler generates
> inefficient code for constant-length memcpy, which may sacrifice
> performance for compatibility, as not all hardware supports unaligned
> memory access. We need a runtime CPU feature dispatch mechanism
> similar to alternatives to improve the compiler. This is indeed a
> problem that needs to be addressed.

Hmm, yep, GCC does not take the advantage of -mstrict-align expanding
memcpy etc. I'll add it into my TODO list for GCC 14.


--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University