[libcxx-commits] [libcxx] aa80388 - [libc++] Ensure that we vectorize algorithms on all Clang-based compilers (#132090)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 24 10:22:43 PDT 2025


Author: Louis Dionne
Date: 2025-03-24T13:22:40-04:00
New Revision: aa80388cf9d2444c82e7a1a8c73ddf14930be318

URL: https://github.com/llvm/llvm-project/commit/aa80388cf9d2444c82e7a1a8c73ddf14930be318
DIFF: https://github.com/llvm/llvm-project/commit/aa80388cf9d2444c82e7a1a8c73ddf14930be318.diff

LOG: [libc++] Ensure that we vectorize algorithms on all Clang-based compilers (#132090)

Otherwise, we wouldn't vectorize on compilers like AppleClang when in
reality we know perfectly well how to do it.

Added: 
    libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp

Modified: 
    libcxx/include/__algorithm/simd_utils.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__algorithm/simd_utils.h b/libcxx/include/__algorithm/simd_utils.h
index 6ee7bd4bcbd96..47942a09e67c5 100644
--- a/libcxx/include/__algorithm/simd_utils.h
+++ b/libcxx/include/__algorithm/simd_utils.h
@@ -26,7 +26,9 @@ _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
 // TODO: Find out how altivec changes things and allow vectorizations there too.
-#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_CLANG_VER) && !defined(__ALTIVEC__)
+// TODO: Simplify this condition once we stop building with AppleClang 15 in the CI.
+#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(__ALTIVEC__) &&                         \
+    !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1600)
 #  define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 1
 #else
 #  define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 0

diff  --git a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
new file mode 100644
index 0000000000000..733a147b80cc3
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// We don't know how to vectorize algorithms on GCC
+// XFAIL: gcc
+
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
+// We don't vectorize algorithms before C++14
+// XFAIL: c++03, c++11
+
+// We don't vectorize algorithms on AIX right now.
+// XFAIL: target={{.+}}-aix{{.*}}
+
+// We don't vectorize on AppleClang 15 since that apparently breaks std::mismatch
+// XFAIL: apple-clang-15
+
+// This test ensures that we enable the vectorization of algorithms on the expected
+// platforms.
+
+#include <algorithm>
+
+#ifndef _LIBCPP_VECTORIZE_ALGORITHMS
+#  error It looks like the test needs to be updated since _LIBCPP_VECTORIZE_ALGORITHMS isn't defined anymore
+#endif
+
+#if !_LIBCPP_VECTORIZE_ALGORITHMS
+#  error Algorithms should be vectorized on this platform
+#endif


        


More information about the libcxx-commits mailing list