[llvm-dev] struct within a struct vs struct with its fields copied

Mike Shah via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 25 10:49:32 PDT 2015

> I'm not familiar with how LLVM will optimize or behave given:
> struct F { int }
> Struct G { int, int }
> Struct H { F, int }
> Is there a difference between G & H w.r.t to optimizations?

%struct.F = type { i32 }
%struct.G = type { i32, i32 }
%struct.H = type { %struct.F, i32 }

Without optimizations you will get something like the above.

It may be worthwhile to cook up a small example using the structs, and then

clang -emit-llvm -S -O0 experiment.cpp -o WithO0.ll
clang -emit-llvm -S -O3 experiment.cpp -o WithO3.ll

(Or you can use opt and -whatever_optimization) to see the output for
specific optimizations.

Then you can compare what the outputs are.
I then like using diff to compare:

diff -y W 80 With WithO0.ll WithO3.ll

If you need more help building an example to see how optimizations
propagate, I can try to make a small example to explore this.
Mike Shah
Ph.D. Student
Tufts University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150825/da5227ab/attachment.html>

More information about the llvm-dev mailing list