Optimizing

Magnus Fromreide magfr@lysator.liu.se
Sun Jan 30 20:18:00 GMT 2011


Consider the following code:

----
#define SRC "Big blob of text goes here"

extern int foo(int, const void*, int);

void f1(void) {
        foo(1, SRC, sizeof(SRC) - 1);
}

void f2(void) {
        char buf[sizeof(SRC) - 1];
        __builtin_memcpy(buf, SRC, sizeof(SRC)  - 1); 
        foo(1, buf, sizeof(SRC) - 1);
}
----

Is it a valid optimization for the compiler to generate the same
instructions for f2 as it generates for f1?

Would it be hard to make GCC do it?

/MF



More information about the Gcc-help mailing list