I was basically trying to implement a simple vector subtraction with SSE.#include <stdio.h>#include <tchar.h>#include <emmintrin.h>typedef unsigned short ushort;typedef unsigned int uint;void print(__m128i i){ auto& arr = i.m128i_u16; printf("[%d %d %d %d %d %d %d %d]\n", arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]);}int _tmain(int argc, _TCHAR* argv[]){ const int lineSize = 912; ushort input[lineSize]; ushort vals[lineSize];// printf("%X %X\n", input, vals); // note this one for (uint i=0; i<lineSize; i+=8) { __m128i vecinput = _mm_loadu_si128((__m128i*) &input[i]); __m128i vecvals = _mm_loadu_si128((__m128i*) &vals[i]); __m128i output = _mm_subs_epu16(vecinput, vecvals); print(output); printf("===\n"); } return 0;}It optimizes vals away and incorrectly treats it like it was the same as input, so the result is always 0. Note that the arrays are intended to be uninitialized to get "random" values.If that printf is uncommented, correct code is generated.See http://stackoverflow.com/questions/14600413/is-this-a-bug-in-the-vc-optimizer-or-in-my-code for the assembler output.
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...