struct within a struct vs struct with its fields copied

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:

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.

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