This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

--- Comment #16 from npl at chello dot at ---
rguenther: Funny enough, I am using memcpy because thats the only standard
conform way to move data around that might be aliased. And I use this often to
parse binary streams from a network.

I think you are missing some key points, first that gcc readily replaces
functions it knows - which can be disabled at will. On x86, for all those
samples the call WILL BE replaced. (And in C++, RVO is explicitly allowed for
example)
So its pointless to discuss whether or not gcc should provide builtins (atleast
in the context of this bug). Instead talk about the replacing feature that
seems to work inconsistent / suboptimal.


One more sample to demonstrate this (all compiled with O2):

#include <string.h>
int foo_ptr(const int *s)
{
        /* nope */
        int v;
        memcpy(&v, s, sizeof(v));
        return v;
}

int foo_ref(const int &s)
{
        /* nope */
        int v;
        memcpy(&v, &s, sizeof(v));
        return v;
}

int foo_refloc(const int &s)
{
        /* This actually works */
        int b = s;
        int v;
        memcpy(&v, &b, sizeof(v));
        return v;
}

int foo_badalias(const char *s)
{
        /* Nope, but then THIS shouldnt be be replaced by a aligned load */
        int v;
        memcpy(&v, (int *)s, sizeof(v));
        return v;
}

int foo_badalias2(const char *s)
{
        /* That works, but is undefined behaviour (casting from a pointer with
less alignment)! */
        int v = *(int *)s;
        return v;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]