[PATCH] D44660: [libcxx] unroll the loops in <experimental/simd> for Clang, until LLVM bugs are fixed

Tim Shen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 19 17:46:33 PDT 2018


timshen created this revision.
timshen added a reviewer: mclow.lists.
Herald added subscribers: christof, sanjoy.
Herald added a reviewer: EricWF.

https://reviews.llvm.org/D44660

Files:
  libcxx/include/experimental/simd


Index: libcxx/include/experimental/simd
===================================================================
--- libcxx/include/experimental/simd
+++ libcxx/include/experimental/simd
@@ -611,6 +611,13 @@
 #pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_COMPILER_CLANG)
+#define _LIBCPP_UNROLL
+#else
+// See LLVM PR/36359 for context of this workaround.
+#define _LIBCPP_UNROLL _Pragma("unroll")
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD
 
 enum class _StorageKind {
@@ -2109,20 +2116,22 @@
 
 // algorithms [simd.alg]
 template <class _Tp, class _Abi>
-simd<_Tp, _Abi> min(const simd<_Tp, _Abi>& __a,
-                    const simd<_Tp, _Abi>& __b) noexcept {
+// Add `inline` keyword until LLVM PR/36495 is fixed
+inline simd<_Tp, _Abi> min(const simd<_Tp, _Abi>& __a,
+                           const simd<_Tp, _Abi>& __b) noexcept {
   simd<_Tp, _Abi> __v;
-  for (size_t __i = 0; __i < __v.size(); __i++) {
+  _LIBCPP_UNROLL for (size_t __i = 0; __i < __v.size(); __i++) {
     __v[__i] = std::min(__a[__i], __b[__i]);
   }
   return __v;
 }
 
 template <class _Tp, class _Abi>
-simd<_Tp, _Abi> max(const simd<_Tp, _Abi>& __a,
-                    const simd<_Tp, _Abi>& __b) noexcept {
+// Add `inline` keyword until LLVM PR/36495 is fixed
+inline simd<_Tp, _Abi> max(const simd<_Tp, _Abi>& __a,
+                           const simd<_Tp, _Abi>& __b) noexcept {
   simd<_Tp, _Abi> __v;
-  for (size_t __i = 0; __i < __v.size(); __i++) {
+  _LIBCPP_UNROLL for (size_t __i = 0; __i < __v.size(); __i++) {
     __v[__i] = std::max(__a[__i], __b[__i]);
   }
   return __v;
@@ -3060,4 +3069,6 @@
 
 _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD
 
+#undef _LIBCPP_UNROLL
+
 #endif /* _LIBCPP_EXPERIMENTAL_SIMD */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44660.139052.patch
Type: text/x-patch
Size: 1730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180320/821bba98/attachment-0001.bin>


More information about the cfe-commits mailing list