[PATCH] D44662: [libcxx] In <experimental/simd>, optimize masked div and rem.

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


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

This optimization is allowed by the semantics, as users shouldn't pass
in values that may cause undefined behavior even those values are masked.


https://reviews.llvm.org/D44662

Files:
  libcxx/include/experimental/simd
  libcxx/test/std/experimental/simd/simd.whereexpr/where_expression.pass.cpp


Index: libcxx/test/std/experimental/simd/simd.whereexpr/where_expression.pass.cpp
===================================================================
--- libcxx/test/std/experimental/simd/simd.whereexpr/where_expression.pass.cpp
+++ libcxx/test/std/experimental/simd/simd.whereexpr/where_expression.pass.cpp
@@ -123,15 +123,6 @@
     assert(a[2] == 3);
     assert(a[3] == 4);
   }
-  {
-    fixed_size_simd<int, 4> a([](int i) { return i; });
-    where(a % 2 == 1, a) /=
-        fixed_size_simd<int, 4>([](int i) { return i % 2 * 2; });
-    assert(a[0] == 0);
-    assert(a[1] == 0);
-    assert(a[2] == 2);
-    assert(a[3] == 1);
-  }
   {
     fixed_size_simd<int, 4> a([](int i) { return 3 * i; });
     where(a >= 6, a) %= 2;
@@ -148,15 +139,6 @@
     assert(a[2] == 0);
     assert(a[3] == 1);
   }
-  {
-    fixed_size_simd<int, 4> a([](int i) { return i; });
-    where(a % 2 == 1, a) %=
-        fixed_size_simd<int, 4>([](int i) { return i % 2 * 2; });
-    assert(a[0] == 0);
-    assert(a[1] == 1);
-    assert(a[2] == 2);
-    assert(a[3] == 1);
-  }
   {
     fixed_size_simd<int, 4> a([](int i) { return i; });
     where(a > -2, a) &= 1;
Index: libcxx/include/experimental/simd
===================================================================
--- libcxx/include/experimental/simd
+++ libcxx/include/experimental/simd
@@ -2491,8 +2491,7 @@
   }
 
   // binary operators [simd.binary]
-  // TODO: regarding NOTE 9, the implementationn chooses not to SFINAE,
-  // but causes a hard error when the operator can't work on _Tp.
+  // TODO: currently the operators are not SFINAEed. Fix it.
   friend simd operator+(const simd& __a, const simd& __b) {
     return __from_storage(__simd_storage<_Tp, _Abi>::__add(__a.__s_, __b.__s_));
   }
@@ -2999,21 +2998,13 @@
   template <class _Up>
   auto operator/=(_Up&& __u)
       -> decltype(this->__v_ / std::forward<_Up>(__u), void()) {
-    this->__v_ =
-        this->__v_ /
-        __simd_mask_friend::__simd_select(
-            _ValueType(1), _ValueType(std::forward<_Up>(__u)), this->__m_);
+    *this = this->__v_ / std::forward<_Up>(__u);
   }
 
   template <class _Up>
   auto operator%=(_Up&& __u)
       -> decltype(this->__v_ % std::forward<_Up>(__u), void()) {
-    this->__v_ = __simd_mask_friend::__simd_select(
-        this->__v_,
-        this->__v_ %
-            __simd_mask_friend::__simd_select(
-                _ValueType(1), _ValueType(std::forward<_Up>(__u)), this->__m_),
-        this->__m_);
+    *this = this->__v_ % std::forward<_Up>(__u);
   }
 
   template <class _Up>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44662.139054.patch
Type: text/x-patch
Size: 2566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180320/04da7db3/attachment-0001.bin>


More information about the cfe-commits mailing list