鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

选项 -fifcvt-allow-complicated-cmps

说明

增强 If conversion 优化,使用更多的寄存器以减少冲突。

使用说明

本优化是 RTL 优化 if-conversion 的一部分,使用如下编译选项控制优化启用。

  • -param=ifcvt-allow-register-renaming=[0,1,2]默认为0,数字用于控制优化范围。

注:此优化依赖-O2优化等级,并建议与--param=max-rtl-if-conversion-unpredictable-cost=48、--param=max-rtl-if-conversion-predictable-cost=48共同使用。

结果

测试用例如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
typedef unsigned int uint16_t;

uint16_t
foo (uint16_t x, uint16_t y, uint16_t z, uint16_t a,
     uint16_t b, uint16_t c, uint16_t d)
{
    int i = 1;
    int j = 1;
    if (a > b)
    {
        j = x;
        if (b > c)
	    i = y;
        else
	    i = z;
    }
    else
    {
        j = y;
        if (c > d)
	    i = z;
    }
    return i * j;
}

测试命令:

1
gcc -O2 -fifcvt-allow-complicated-cmps --param max-rtl-if-conversion-unpredictable-cost=100 --param max-rtl-if-conversion-predictable-cost=100 --param=ifcvt-allow-register-renaming=2 -S test.c -o test.s
图1 选项未打开
图2 选项已经打开

相比选项未打开时,选项打开后,生成的汇编代码指令消除了分支跳转,并使用了更多的寄存器来减少冲突。