通过拆分包含复杂条件的 if 语句块,增强程序间常量传播的能力。
需开启 -O3 或以上优化等级,同时增加编译选项 -fif-split。
测试用例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | static __attribute__ ((noinline)) int foo (int b) { int res = 1; for (int i = 0; i < b; i++) { res*=3; } return res; } int main(int argc, char** argv){ int b = argc; int res = 0; if (b == 5 || b == 52) res = foo (b); return res; } |
测试命令:
1 | gcc -O3 -fif-split test.c -S -o test.s |
选项打开后,main 函数中的 if (b == 5 || b == 52) 被拆分成两个独立条件,各插入了一条跳转指令。