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

mats petersson via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 26 02:25:22 PDT 2015


On 25 August 2015 at 18:49, Mike Shah via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> > 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 run:
>

Note that it's likely quite sensitive exactly how these data structures are
used - for example, the compiler may make quite different optimisations if
you use them from a  pointer or as direct local variables.

[And this is why I asked for more specifics regarding "what type of
optimisations"]

>
> 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
>

For anything but a really trivial example, you'd surely get a lot of
differences that are completely unrelated to the  data structures used,
confusing the changes related to the struct form.

I would, instead, write code that does the same operations using the struct
G and struct H examples in separate files and see what the compiler
generates (with varying optimisation levels).

--
Mats

>
> 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
> http://michaeldshah.net
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150826/864b3234/attachment.html>


More information about the llvm-dev mailing list