GCCのミドルでの最適化はどんなものなのか
int main(int argc,char **argv) { int base=10,pp=5,ret ; long int long_i_type =10,long_pp=5 ; char char_type =20,char_noset; unsigned int uint_type = 100 ,uint_noset ; unsigned char uchar_type =20,uchar_noset; ret = base+pp; long_pp = base - pp; long_i_type = long_pp + long_i_type + base - pp; char_noset = char_type; char_type = base + char_noset; }
というCをGCCにかける。
ミドルの終了の辺りだと
main (argc, argv) { unsigned char uchar_noset; unsigned char uchar_type; unsigned int uint_noset; unsigned int uint_type; char char_noset; char char_type; long int long_i_type2; long int long_pp; long int long_i_type; int ret; int pp; int base; unsigned char D.1563; unsigned char char_noset.0; unsigned char D.1561; long int D.1560; long int D.1559; # BLOCK 2 # PRED: ENTRY (fallthru) base = 10; pp = 5; long_i_type = 10; long_pp = 5; char_type = 20; uint_type = 100; uchar_type = 20; ret = base + pp; long_i_type2 = base - pp; D.1559 = long_pp + long_i_type; D.1560 = D.1559 + base; long_i_type = D.1560 - pp; long_pp = base - pp; char_noset = char_type; D.1561 = (unsigned char) base; char_noset.0 = (unsigned char) char_noset; D.1563 = D.1561 + char_noset.0; char_type = (char) D.1563; return; # SUCC: EXIT }
となっている。
long_i_type = D.1559 + long_i_type2;
にするとRTL上で1命令減る
こういう交換則による最適化はミドルだって聞いた覚えがあったのだけど
違うのかな