diff --git a/lib/Headers/emmintrin.h b/lib/Headers/emmintrin.h index 9ab0a73aad6c50923e17b2c85914abf0fd945a7c..a78eb54c45a97b2929843f3976d44d3980e2b12b 100644 --- a/lib/Headers/emmintrin.h +++ b/lib/Headers/emmintrin.h @@ -1266,7 +1266,7 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__)) _mm_extract_epi16(__m128i __a, int __imm) { __v8hi __b = (__v8hi)__a; - return (unsigned short)__b[__imm]; + return (unsigned short)__b[__imm & 7]; } static __inline__ __m128i __attribute__((__always_inline__, __nodebug__)) diff --git a/test/CodeGen/sse-builtins.c b/test/CodeGen/sse-builtins.c index 559d855547b0605580d5c53a09d8c614992fd146..cee9b3c2a5dfccd094d926c903aff89ae763a887 100644 --- a/test/CodeGen/sse-builtins.c +++ b/test/CodeGen/sse-builtins.c @@ -206,3 +206,10 @@ void test_stream_si128(__m128i x, void *y) { // CHECK: store {{.*}} <2 x i64>* {{.*}}, align 16, !nontemporal _mm_stream_si128(y, x); } + +void test_extract_epi16(__m128i __a) { + // CHECK-LABEL: define void @test_extract_epi16 + // CHECK: [[x:%.*]] = and i32 %{{.*}}, 7 + // CHECK: extractelement <8 x i16> %{{.*}}, i32 [[x]] + _mm_extract_epi16(__a, 8); +}