[cfe-dev] struct copy

Chris Lattner clattner at apple.com
Mon Sep 22 11:01:03 PDT 2008


On Sep 22, 2008, at 8:30 AM, Argiris Kirtzidis wrote:

> Given this program:
>
> struct S { int x; };
> void f() {
>  struct S q1;
>  struct S q2 = q1;
> }
>
>
> clang emits this:
>
> Would it be better if it produced this instead ?:

Yes, that would be better.  llvm-gcc has logic to do this.  It is  
somewhat tricky, because you only want to do it when the struct is  
small, and can't always do it when you have unions.

> It's simpler and offers higher level information for those that want  
> to
> examine the bitcode.
>
> Isn't the job of the backend to interpret
>    %tmp = load %struct.S* %q1
>    store %struct.S %tmp, %struct.S* %q2
> in an appropriate way according to target, thus not requiring the
> frontend to explicitly encode it as low-level block-of-bytes copy ?

Clang does a block copy right now because it is a) always correct and  
b) required for the large struct copy case.  Improving this code to  
use the same heuristics as llvm-gcc would be useful :)

-Chris 



More information about the cfe-dev mailing list