Fix shuffle vector calculation for mm_permute_ps. Fixes PR 12401.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153724 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Headers/avxintrin.h b/lib/Headers/avxintrin.h
index 6a2bee5..3fb1b15 100644
--- a/lib/Headers/avxintrin.h
+++ b/lib/Headers/avxintrin.h
@@ -274,7 +274,7 @@
__m128 __A = (A); \
(__m128)__builtin_shufflevector((__v4sf)__A, (__v4sf) _mm_setzero_ps(), \
(C) & 0x3, ((C) & 0xc) >> 2, \
- ((C) & 0x30) >> 4, ((C) & 0xc0) >> 8); })
+ ((C) & 0x30) >> 4, ((C) & 0xc0) >> 6); })
#define _mm256_permute_ps(A, C) __extension__ ({ \
__m256 __A = (A); \
diff --git a/test/CodeGen/avx-shuffle-builtins.c b/test/CodeGen/avx-shuffle-builtins.c
index 18300bf..538ae50 100644
--- a/test/CodeGen/avx-shuffle-builtins.c
+++ b/test/CodeGen/avx-shuffle-builtins.c
@@ -33,6 +33,13 @@
return _mm_permute_ps(a, 0x1b);
}
+// Test case for PR12401
+__m128 test_mm_permute_ps2(__m128 a) {
+ // Check if the mask is correct
+ // CHECK: shufflevector{{.*}}<i32 2, i32 1, i32 2, i32 3>
+ return _mm_permute_ps(a, 0xe6);
+}
+
__m256 test_mm256_permute_ps(__m256 a) {
// Check if the mask is correct
// CHECK: shufflevector{{.*}}<i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4>