hiraditya created this revision.
hiraditya added reviewers: EricWF, mclow.lists.
hiraditya added a subscriber: cfe-commits.

Worked with Sebastian Pop


https://reviews.llvm.org/D26991

Files:
  libcxx/include/algorithm


Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -1494,42 +1494,46 @@
     if (__len1 < __len2)
         return make_pair(__last1, __last1);
     const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of 
pattern match can't go beyond here
+
+    // Load the first element from __first2 outside the loop because it is 
loop invariant
+    typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+
     while (true)
     {
 #if !_LIBCPP_UNROLL_LOOPS
         while (true)
         {
             if (__first1 == __s)
                 return make_pair(__last1, __last1);
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         }
 #else  // !_LIBCPP_UNROLL_LOOPS
         for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; 
--__loop_unroll)
         {
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
             ++__first1;
         }
         switch (__s - __first1)
         {
         case 3:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         case 2:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         case 1:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
         case 0:
             return make_pair(__last1, __last1);


Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -1494,42 +1494,46 @@
     if (__len1 < __len2)
         return make_pair(__last1, __last1);
     const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
+
+    // Load the first element from __first2 outside the loop because it is loop invariant
+    typename iterator_traits<_RandomAccessIterator1>::value_type __firstElement2 = *__first2;
+
     while (true)
     {
 #if !_LIBCPP_UNROLL_LOOPS
         while (true)
         {
             if (__first1 == __s)
                 return make_pair(__last1, __last1);
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         }
 #else  // !_LIBCPP_UNROLL_LOOPS
         for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll)
         {
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
-            if (__pred(*++__first1, *__first2))
+            if (__pred(*++__first1, __firstElement2))
                 goto __phase2;
             ++__first1;
         }
         switch (__s - __first1)
         {
         case 3:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         case 2:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
             ++__first1;
         case 1:
-            if (__pred(*__first1, *__first2))
+            if (__pred(*__first1, __firstElement2))
                 break;
         case 0:
             return make_pair(__last1, __last1);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to