Thursday, March 13, 2008

Bug in x64 optimizer in VS 2005, unfixed in VS 2008

I came across a bug in the x64 optimizer yesterday. By the looks of this connect.microsoft.com item, it looks like it's been there since VS 2005, and it has not been fixed in VS 2008.

I don't understand the bug completely, but it seems to involve sign extension (using movsxd) when it should do unsigned extension of 32-bit integers to 64-bit.

In my specific usage case, I was splitting up the 32-bit integers into their upper and lower halves, by adding an offset of 0x80000000 for the upper half. My workaround was simply to use 0x80000000 - 1 instead of 0x80000000 as an offset. The optimizer ends up generating different code, which happens to be correct.

If you have any sway with MSFT, please get them to fix this bug. I don't know if the voting system on that connect.microsoft.com site works, but maybe it's worth a try.