<div dir="ltr">Hi All<div><br></div><div>I am trying to analyze the difference between binaries produced using clang -Oz and Opt -Oz. All the binaries produced are using the -c flag. Right off the bat, I can see the difference between the IR file produced by clang -Oz which adds "minsize","optsize" and removes the "no-inline" function attribute. To keep things similar the same is done to the default IR produced for the following code with the optnone attribute removed using the -disable-O0-optnone flag. </div><div><br></div>#include <stdio.h><br>int num[326] = {<br> 1,<br> 2,<br> 3,<br> 4,<br> 6,<br> 8,<br> 9,<br> 12,<br> 16,<br> 18,<br> 24,<br> 27,<br> 32,<br> 36,<br> 48,<br> 54,<br> 64,<br> 72,<br> 81,<br> 96,<br> 108,<br> 128,<br> 144,<br> 162,<br> 192,<br> 216,<br> 243,<br> 256,<br> 288,<br> 324,<br> 384,<br> 432,<br> 486,<br> 512,<br> 576,<br> 648,<br> 729,<br> 768,<br> 864,<br> 972,<br> 1024,<br> 1152,<br> 1296,<br> 1458,<br> 1536,<br> 1728,<br> 1944,<br> 2048,<br> 2187,<br> 2304,<br> 2592,<br> 2916,<br> 3072,<br> 3456,<br> 3888,<br> 4096,<br> 4374,<br> 4608,<br> 5184,<br> 5832,<br> 6144,<br> 6561,<br> 6912,<br> 7776,<br> 8192,<br> 8748,<br> 9216,<br> 10368,<br> 11664,<br> 12288,<br> 13122,<br> 13824,<br> 15552,<br> 16384,<br> 17496,<br> 18432,<br> 19683,<br> 20736,<br> 23328,<br> 24576,<br> 26244,<br> 27648,<br> 31104,<br> 32768,<br> 34992,<br> 36864,<br> 39366,<br> 41472,<br> 46656,<br> 49152,<br> 52488,<br> 55296,<br> 59049,<br> 62208,<br> 65536,<br> 69984,<br> 73728,<br> 78732,<br> 82944,<br> 93312,<br> 98304,<br> 104976,<br> 110592,<br> 118098,<br> 124416,<br> 131072,<br> 139968,<br> 147456,<br> 157464,<br> 165888,<br> 177147,<br> 186624,<br> 196608,<br> 209952,<br> 221184,<br> 236196,<br> 248832,<br> 262144,<br> 279936,<br> 294912,<br> 314928,<br> 331776,<br> 354294,<br> 373248,<br> 393216,<br> 419904,<br> 442368,<br> 472392,<br> 497664,<br> 524288,<br> 531441,<br> 559872,<br> 589824,<br> 629856,<br> 663552,<br> 708588,<br> 746496,<br> 786432,<br> 839808,<br> 884736,<br> 944784,<br> 995328,<br> 1048576,<br> 1062882,<br> 1119744,<br> 1179648,<br> 1259712,<br> 1327104,<br> 1417176,<br> 1492992,<br> 1572864,<br> 1594323,<br> 1679616,<br> 1769472,<br> 1889568,<br> 1990656,<br> 2097152,<br> 2125764,<br> 2239488,<br> 2359296,<br> 2519424,<br> 2654208,<br> 2834352,<br> 2985984,<br> 3145728,<br> 3188646,<br> 3359232,<br> 3538944,<br> 3779136,<br> 3981312,<br> 4194304,<br> 4251528,<br> 4478976,<br> 4718592,<br> 4782969,<br> 5038848,<br> 5308416,<br> 5668704,<br> 5971968,<br> 6291456,<br> 6377292,<br> 6718464,<br> 7077888,<br> 7558272,<br> 7962624,<br> 8388608,<br> 8503056,<br> 8957952,<br> 9437184,<br> 9565938,<br> 10077696,<br> 10616832,<br> 11337408,<br> 11943936,<br> 12582912,<br> 12754584,<br> 13436928,<br> 14155776,<br> 14348907,<br> 15116544,<br> 15925248,<br> 16777216,<br> 17006112,<br> 17915904,<br> 18874368,<br> 19131876,<br> 20155392,<br> 21233664,<br> 22674816,<br> 23887872,<br> 25165824,<br> 25509168,<br> 26873856,<br> 28311552,<br> 28697814,<br> 30233088,<br> 31850496,<br> 33554432,<br> 34012224,<br> 35831808,<br> 37748736,<br> 38263752,<br> 40310784,<br> 42467328,<br> 43046721,<br> 45349632,<br> 47775744,<br> 50331648,<br> 51018336,<br> 53747712,<br> 56623104,<br> 57395628,<br> 60466176,<br> 63700992,<br> 67108864,<br> 68024448,<br> 71663616,<br> 75497472,<br> 76527504,<br> 80621568,<br> 84934656,<br> 86093442,<br> 90699264,<br> 95551488,<br> 100663296,<br> 102036672,<br> 107495424,<br> 113246208,<br> 114791256,<br> 120932352,<br> 127401984,<br> 129140163,<br> 134217728,<br> 136048896,<br> 143327232,<br> 150994944,<br> 153055008,<br> 161243136,<br> 169869312,<br> 172186884,<br> 181398528,<br> 191102976,<br> 201326592,<br> 204073344,<br> 214990848,<br> 226492416,<br> 229582512,<br> 241864704,<br> 254803968,<br> 258280326,<br> 268435456,<br> 272097792,<br> 286654464,<br> 301989888,<br> 306110016,<br> 322486272,<br> 339738624,<br> 344373768,<br> 362797056,<br> 382205952,<br> 387420489,<br> 402653184,<br> 408146688,<br> 429981696,<br> 452984832,<br> 459165024,<br> 483729408,<br> 509607936,<br> 516560652,<br> 536870912,<br> 544195584,<br> 573308928,<br> 603979776,<br> 612220032,<br> 644972544,<br> 679477248,<br> 688747536,<br> 725594112,<br> 764411904,<br> 774840978,<br> 805306368,<br> 816293376,<br> 859963392,<br> 905969664,<br> 918330048,<br> 967458816,<br> 1019215872,<br> 1033121304,<br> 1073741824,<br> 1088391168,<br> 1146617856,<br> 1162261467,<br> 1207959552,<br> 1224440064,<br> 1289945088,<br> 1358954496,<br> 1377495072,<br> 1451188224,<br> 1528823808,<br> 1549681956,<br> 1610612736,<br> 1632586752,<br> 1719926784,<br> 1811939328,<br> 1836660096,<br> 1934917632<br>};<br>int main() {<br> int l, r;<br>    scanf("%d %d", &l, &r);<br> <br> int L = -1, R = 326;<br> for (int i = 0; i < 326; ++i) {<br> if (num[i] < l) {<br>            L = i;<br> }<br> }<br> for (int i = 325; i >= 0; --i) {<br> if (num[i] > r) {<br>            R = i;<br> }<br> }<br>    printf("%d", (R - L - (long long) 1));<br> return 0;<br><div>} </div><div><br></div><div>What follows next is applying opt -S -Oz on the same IR followed by clang -c <Oz_IR_File> -o  binname.out to create the binary </div><div><br></div><div>The binary thus formed has a size of 3072 bytes whereas the binary formed with Clang -Oz on the c file viz clang  -c -Oz filename.c has a size of 2944 bytes and the most interesting part is that the out file produced without any optimization viz clang -c  filename.c is 3040 bytes<br><br>Are there some other attributes that need to be added to get Opt -Oz similar to clang -Oz or am I missing something?</div><div><br></div><div>P.S: Apologies for the huge chunk of code in the middle of the mail. I was not sure if attaching it would be viewable or not.</div><div><br></div><div>P.S.S: This is one file out of a few more files that result in the discrepancy. </div><div><br></div><div>Regards</div><div>Anilava </div></div>

<br>
<span><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap;background-color:yellow">Disclaimer:- </span><span style="background-color:rgb(255,255,255);color:rgb(34,34,34);font-size:small">This </span><span style="background-color:rgb(255,255,255);color:rgb(34,34,34);font-size:small">footer text is to convey that this email is sent by one of the </span><span style="background-color:rgb(255,255,255);color:rgb(34,34,34);font-size:small">users of IITH. So, do not mark it as SPAM.</span></p></span>