Wrong optimization for following file:===file begin===#include <cstdio>typedef unsigned char GLubyte;#define width 64#define height 64static GLubyte red [height][width][4];static void makeCubeImage(void){ for(GLubyte i=0; i< height; i++){ for(GLubyte j=0; j<width; j++){ red[i][j][0]= ((i<height/4 && j<width/4)? 255:0) + ((i>height/4 && i<(3*height)/4)? ((j>width/4 && j<(3*width)/4)? 255:0):0); } }}void print_array(GLubyte* ptr){ printf("%02x\n", ptr[4420]);}int main(){ makeCubeImage(); print_array(reinterpret_cast<GLubyte*>(red));}===file end===The loop internal is compiled into: red[i][j][0]= ((i<height/4 && j<width/4)? 255:0) + ((i>height/4 && i<(3*height)/4)? ((j>width/4 && j<(3*width)/4)? 255:0):0);00201012 80 FB 10 cmp bl,10h 00201015 73 0C jae makeCubeImage+23h (0201023h) 00201017 80 FA 10 cmp dl,10h 0020101A 73 07 jae makeCubeImage+23h (0201023h) 0020101C B9 FF 00 00 00 mov ecx,0FFh 00201021 EB 02 jmp makeCubeImage+25h (0201025h) 00201023 33 C9 xor ecx,ecx 00201025 8A C3 mov al,bl 00201027 2C 11 sub al,11h 00201029 3C 1E cmp al,1Eh 0020102B 77 15 ja makeCubeImage+42h (0201042h) 0020102D B8 1E 00 00 00 mov eax,1Eh 00201032 3A E0 cmp ah,al 00201034 1B C0 sbb eax,eax 00201036 25 01 FF FF FF and eax,0FFFFFF01h 0020103B 05 FF 00 00 00 add eax,0FFh 00201040 EB 02 jmp makeCubeImage+44h (0201044h) 00201042 33 C0 xor eax,eax 00201044 02 C8 add cl,al 00201046 88 0E mov byte ptr [esi],cl 00201048 FE C2 inc dl 0020104A 83 C6 04 add esi,4 0020104D 80 FA 40 cmp dl,40h 00201050 72 C0 jb makeCubeImage+12h (0201012h) for(GLubyte i=0; i< height; i++){00201052 FE C3 inc bl The internal sequence this is wrong:0020102D B8 1E 00 00 00 mov eax,1Eh 00201032 3A E0 cmp ah,al 00201034 1B C0 sbb eax,eax 00201036 25 01 FF FF FF and eax,0FFFFFF01h 0020103B 05 FF 00 00 00 add eax,0FFh Should be compared with dl, instead of ah cmp with al since it is a constant that just assigned through mov eax,1Eh .Hope to get the fix soon, or tell us a version that the issue has been fixed.Thanks,Tango
Visual Studio/Team Foundation Server/.NET Framework Tooling Version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...