<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 10, 2015 at 8:19 AM, Sanjay Patel <span dir="ltr"><<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: spatel<br>
Date: Tue Mar 10 10:19:26 2015<br>
New Revision: 231792<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=231792&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=231792&view=rev</a><br>
Log:<br>
[X86, AVX] Replace vinsertf128 intrinsics with generic shuffles.<br>
<br>
We want to replace as much custom x86 shuffling via intrinsics<br>
as possible because pushing the code down the generic shuffle<br>
optimization path allows for better codegen and less complexity<br>
in LLVM.<br>
<br>
This is the sibling patch for the LLVM half of this change:<br>
<a href="http://reviews.llvm.org/D8086" target="_blank">http://reviews.llvm.org/D8086</a><br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D8088" target="_blank">http://reviews.llvm.org/D8088</a><br>
<br>
<br>
Modified:<br>
cfe/trunk/include/clang/Basic/BuiltinsX86.def<br>
cfe/trunk/lib/Headers/avxintrin.h<br>
cfe/trunk/lib/Sema/SemaChecking.cpp<br>
cfe/trunk/test/CodeGen/avx-shuffle-builtins.c<br>
cfe/trunk/test/CodeGen/builtins-x86.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=231792&r1=231791&r2=231792&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=231792&r1=231791&r2=231792&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)<br>
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Tue Mar 10 10:19:26 2015<br>
@@ -450,9 +450,6 @@ BUILTIN(__builtin_ia32_cvttps2dq256, "V8<br>
BUILTIN(__builtin_ia32_vperm2f128_pd256, "V4dV4dV4dIc", "")<br>
BUILTIN(__builtin_ia32_vperm2f128_ps256, "V8fV8fV8fIc", "")<br>
BUILTIN(__builtin_ia32_vperm2f128_si256, "V8iV8iV8iIc", "")<br>
-BUILTIN(__builtin_ia32_vinsertf128_pd256, "V4dV4dV2dIc", "")<br>
-BUILTIN(__builtin_ia32_vinsertf128_ps256, "V8fV8fV4fIc", "")<br>
-BUILTIN(__builtin_ia32_vinsertf128_si256, "V8iV8iV4iIc", "")<br>
BUILTIN(__builtin_ia32_sqrtpd256, "V4dV4d", "")<br>
BUILTIN(__builtin_ia32_sqrtps256, "V8fV8f", "")<br>
BUILTIN(__builtin_ia32_rsqrtps256, "V8fV8f", "")<br>
<br>
Modified: cfe/trunk/lib/Headers/avxintrin.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avxintrin.h?rev=231792&r1=231791&r2=231792&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avxintrin.h?rev=231792&r1=231791&r2=231792&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Headers/avxintrin.h (original)<br>
+++ cfe/trunk/lib/Headers/avxintrin.h Tue Mar 10 10:19:26 2015<br>
@@ -472,22 +472,6 @@ _mm256_extract_epi64(__m256i __a, const<br>
}<br>
#endif<br>
<br>
-/* Vector insert */<br>
-#define _mm256_insertf128_pd(V1, V2, O) __extension__ ({ \<br>
- __m256d __V1 = (V1); \<br>
- __m128d __V2 = (V2); \<br>
- (__m256d)__builtin_ia32_vinsertf128_pd256((__v4df)__V1, (__v2df)__V2, (O)); })<br>
-<br>
-#define _mm256_insertf128_ps(V1, V2, O) __extension__ ({ \<br>
- __m256 __V1 = (V1); \<br>
- __m128 __V2 = (V2); \<br>
- (__m256)__builtin_ia32_vinsertf128_ps256((__v8sf)__V1, (__v4sf)__V2, (O)); })<br>
-<br>
-#define _mm256_insertf128_si256(V1, V2, O) __extension__ ({ \<br>
- __m256i __V1 = (V1); \<br>
- __m128i __V2 = (V2); \<br>
- (__m256i)__builtin_ia32_vinsertf128_si256((__v8si)__V1, (__v4si)__V2, (O)); })<br>
-<br>
static __inline __m256i __attribute__((__always_inline__, __nodebug__))<br>
_mm256_insert_epi32(__m256i __a, int __b, int const __imm)<br>
{<br>
@@ -1166,6 +1150,42 @@ _mm256_castsi128_si256(__m128i __a)<br>
return __builtin_shufflevector(__a, __a, 0, 1, -1, -1);<br>
}<br>
<br>
+/*<br>
+ Vector insert.<br>
+ We use macros rather than inlines because we only want to accept<br>
+ invocations where the immediate M is a constant expression.<br>
+*/<br></blockquote><div><br></div><div>I wonder if we could use the enable_if attribute <a href="http://clang.llvm.org/docs/AttributeReference.html#enable-if">http://clang.llvm.org/docs/AttributeReference.html#enable-if</a> together with __builtin_constant_p to get the same effect, but with a more readable implementation.</div><div><br></div><div>-- Sean Silva</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+#define _mm256_insertf128_ps(V1, V2, M) __extension__ ({ \<br>
+ (__m256)__builtin_shufflevector( \<br>
+ (__v8sf)(V1), \<br>
+ (__v8sf)_mm256_castps128_ps256((__m128)(V2)), \<br>
+ (((M) & 1) ? 0 : 8), \<br>
+ (((M) & 1) ? 1 : 9), \<br>
+ (((M) & 1) ? 2 : 10), \<br>
+ (((M) & 1) ? 3 : 11), \<br>
+ (((M) & 1) ? 8 : 4), \<br>
+ (((M) & 1) ? 9 : 5), \<br>
+ (((M) & 1) ? 10 : 6), \<br>
+ (((M) & 1) ? 11 : 7) );})<br>
+<br>
+#define _mm256_insertf128_pd(V1, V2, M) __extension__ ({ \<br>
+ (__m256d)__builtin_shufflevector( \<br>
+ (__v4df)(V1), \<br>
+ (__v4df)_mm256_castpd128_pd256((__m128d)(V2)), \<br>
+ (((M) & 1) ? 0 : 4), \<br>
+ (((M) & 1) ? 1 : 5), \<br>
+ (((M) & 1) ? 4 : 2), \<br>
+ (((M) & 1) ? 5 : 3) );})<br>
+<br>
+#define _mm256_insertf128_si256(V1, V2, M) __extension__ ({ \<br>
+ (__m256i)__builtin_shufflevector( \<br>
+ (__v4di)(V1), \<br>
+ (__v4di)_mm256_castsi128_si256((__m128i)(V2)), \<br>
+ (((M) & 1) ? 0 : 4), \<br>
+ (((M) & 1) ? 1 : 5), \<br>
+ (((M) & 1) ? 4 : 2), \<br>
+ (((M) & 1) ? 5 : 3) );})<br>
+<br>
/* SIMD load ops (unaligned) */<br>
static __inline __m256 __attribute__((__always_inline__, __nodebug__))<br>
_mm256_loadu2_m128(float const *__addr_hi, float const *__addr_lo)<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=231792&r1=231791&r2=231792&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=231792&r1=231791&r2=231792&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 10 10:19:26 2015<br>
@@ -882,9 +882,6 @@ bool Sema::CheckX86BuiltinFunctionCall(u<br>
case X86::BI__builtin_ia32_vextractf128_ps256:<br>
case X86::BI__builtin_ia32_vextractf128_si256:<br>
case X86::BI__builtin_ia32_extract128i256: i = 1, l = 0, u = 1; break;<br>
- case X86::BI__builtin_ia32_vinsertf128_pd256:<br>
- case X86::BI__builtin_ia32_vinsertf128_ps256:<br>
- case X86::BI__builtin_ia32_vinsertf128_si256:<br>
case X86::BI__builtin_ia32_insert128i256: i = 2, l = 0; u = 1; break;<br>
case X86::BI__builtin_ia32_sha1rnds4: i = 2, l = 0; u = 3; break;<br>
case X86::BI__builtin_ia32_vpermil2pd:<br>
<br>
Modified: cfe/trunk/test/CodeGen/avx-shuffle-builtins.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx-shuffle-builtins.c?rev=231792&r1=231791&r2=231792&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx-shuffle-builtins.c?rev=231792&r1=231791&r2=231792&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/avx-shuffle-builtins.c (original)<br>
+++ cfe/trunk/test/CodeGen/avx-shuffle-builtins.c Tue Mar 10 10:19:26 2015<br>
@@ -97,3 +97,42 @@ test_mm256_broadcast_ss(float const *__a<br>
// CHECK: insertelement <8 x float> {{.*}}, i32 7<br>
return _mm256_broadcast_ss(__a);<br>
}<br>
+<br>
+// Make sure we have the correct mask for each insertf128 case.<br>
+<br>
+__m256d test_mm256_insertf128_ps_0(__m256 a, __m128 b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_ps_0<br>
+ // CHECK: shufflevector{{.*}}<i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7><br>
+ return _mm256_insertf128_ps(a, b, 0);<br>
+}<br>
+<br>
+__m256d test_mm256_insertf128_pd_0(__m256d a, __m128d b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_pd_0<br>
+ // CHECK: shufflevector{{.*}}<i32 4, i32 5, i32 2, i32 3><br>
+ return _mm256_insertf128_pd(a, b, 0);<br>
+}<br>
+<br>
+__m256d test_mm256_insertf128_si256_0(__m256i a, __m128i b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_si256_0<br>
+ // CHECK: shufflevector{{.*}}<i32 4, i32 5, i32 2, i32 3><br>
+ return _mm256_insertf128_si256(a, b, 0);<br>
+}<br>
+<br>
+__m256d test_mm256_insertf128_ps_1(__m256 a, __m128 b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_ps_1<br>
+ // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11><br>
+ return _mm256_insertf128_ps(a, b, 1);<br>
+}<br>
+<br>
+__m256d test_mm256_insertf128_pd_1(__m256d a, __m128d b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_pd_1<br>
+ // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5><br>
+ return _mm256_insertf128_pd(a, b, 1);<br>
+}<br>
+<br>
+__m256d test_mm256_insertf128_si256_1(__m256i a, __m128i b) {<br>
+ // CHECK-LABEL: @test_mm256_insertf128_si256_1<br>
+ // CHECK: shufflevector{{.*}}<i32 0, i32 1, i32 4, i32 5><br>
+ return _mm256_insertf128_si256(a, b, 1);<br>
+}<br>
+<br>
<br>
Modified: cfe/trunk/test/CodeGen/builtins-x86.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-x86.c?rev=231792&r1=231791&r2=231792&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-x86.c?rev=231792&r1=231791&r2=231792&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/builtins-x86.c (original)<br>
+++ cfe/trunk/test/CodeGen/builtins-x86.c Tue Mar 10 10:19:26 2015<br>
@@ -419,9 +419,6 @@ void f0() {<br>
tmp_V4d = __builtin_ia32_vperm2f128_pd256(tmp_V4d, tmp_V4d, 0x7);<br>
tmp_V8f = __builtin_ia32_vperm2f128_ps256(tmp_V8f, tmp_V8f, 0x7);<br>
tmp_V8i = __builtin_ia32_vperm2f128_si256(tmp_V8i, tmp_V8i, 0x7);<br>
- tmp_V4d = __builtin_ia32_vinsertf128_pd256(tmp_V4d, tmp_V2d, 0x1);<br>
- tmp_V8f = __builtin_ia32_vinsertf128_ps256(tmp_V8f, tmp_V4f, 0x1);<br>
- tmp_V8i = __builtin_ia32_vinsertf128_si256(tmp_V8i, tmp_V4i, 0x1);<br>
tmp_V4d = __builtin_ia32_sqrtpd256(tmp_V4d);<br>
tmp_V8f = __builtin_ia32_sqrtps256(tmp_V8f);<br>
tmp_V8f = __builtin_ia32_rsqrtps256(tmp_V8f);<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>