---
title: 选项 -fipa-struct-reorg
description: "内存空间布局优化，将结构体成员在内存中的排布进行重新排列组合，以提高cache命中率。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevps/compilation/ug-hgcc/kunpenghgcc_06_0021.html
sourcePath: /source/zh/kunpengdevps/compilation/ug-hgcc/kunpenghgcc_06_0021.html
indexId: d0216d34770be5ab3a2905e314e8fd2f192a8f245e70a5decc11c9b8a356158668
---
# 选项 -fipa-struct-reorg

内存空间布局优化，将结构体成员在内存中的排布进行重新排列组合，以提高cache命中率。

- 结构体拆分：将结构体的冷热成员单独拆分成一个结构体类型
  图1 结构体拆分优化原理示意图


将以下结构体：

```
struct S
{
    type1 field1; // Hot field
    type2 field2;
};
S *v;
```

转化为：

```
struct S_hot
{
    type1 field1;
};
struct S_cold 
{
    type2 field2;
};
S_hot *v_hot;S_cold *v_cold;
```

- 结构体数组优化：将结构体的数组转换为数组的结构体。
  图2 结构体数组优化原理示意图

  将以下结构体：

  1 2 3 4 5 6 struct { type1 field1; type2 field2; type3 field3; } arr[N];

  转化为：

  1 2 3 4 5 6 struct { type1 field1[N]; type2 field2[N]; type3 field3[N]; } arr;


#### 使用方法

在编译选项中加入：

```
-O3 -flto -flto-partition=one -fipa-struct-reorg
```


-fipa-struct-reorg选项，需要在-O3 -flto -flto-partition=one同时开启的基础上才使能。

SPEC性能提升效果：SPEC CPU 2017 intrate 505.mcf子项性能提升20%。
