-fipa-struct-reorg
This option optimizes the memory space layout. That is, the structure members in the memory are rearranged to improve the cache hit ratio.
- Split the cold and hot members in the structure into two structure types.Figure 1 Structure splitting optimization principle

Change the following structure:
1 2 3 4 5 6 | struct S { type1 field1; // Hot field type2 field2; }; S *v; |
To:
1 2 3 4 5 6 7 8 9 | struct S_hot { type1 field1; }; struct S_cold { type2 field2; }; S_hot *v_hot;S_cold *v_cold; |
- Optimize the structure array. Convert the array with elements of the structure type into the structure with array members.Figure 2 Structure array optimization principle

Change the following structure:
1 2 3 4 5 6
struct { type1 field1; type2 field2; type3 field3; } arr[N];
To:
1 2 3 4 5 6
struct { type1 field1[N]; type2 field2[N]; type3 field3[N]; } arr;
Usage
Add the following content to the option:
1 | -O3 -flto -flto-partition=one -fipa-struct-reorg |
The -fipa-struct-reorg option can be enabled only when -O3 -flto -flto-partition=one is enabled at the same time.
Optimization effect: Up to 20% performance improvement is observed on the SPEC CPU 2017 intrate 505.mcf benchmark.
Parent topic: Static Compilation Optimization