_mm_extract_epi16: use "& 7" when index is out of bound.
This is in line with implementation of _mm_extract_pi16.
rdar://15250497
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193187 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Headers/emmintrin.h b/lib/Headers/emmintrin.h
index 9ab0a73..a78eb54 100644
--- a/lib/Headers/emmintrin.h
+++ b/lib/Headers/emmintrin.h
@@ -1266,7 +1266,7 @@
_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 559d855..cee9b3c 100644
--- a/test/CodeGen/sse-builtins.c
+++ b/test/CodeGen/sse-builtins.c
@@ -206,3 +206,10 @@
// 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);
+}