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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 21 07:19:07 PDT 2025


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/132090

>From 1502090fab337042d6bd1ca9e25f841bd463b6b9 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 19 Mar 2025 15:59:13 -0400
Subject: [PATCH 1/4] [libc++] Ensure that we vectorize algorithms on all
 Clang-based compilers

Otherwise, we wouldn't vectorize on compilers like AppleClang when in
reality we know perfectly well how to do it.
---
 libcxx/include/__algorithm/simd_utils.h       |  2 +-
 .../algorithms/vectorization.compile.pass.cpp | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp

diff --git a/libcxx/include/__algorithm/simd_utils.h b/libcxx/include/__algorithm/simd_utils.h
index e3c790998e902..196f02985d89d 100644
--- a/libcxx/include/__algorithm/simd_utils.h
+++ b/libcxx/include/__algorithm/simd_utils.h
@@ -26,7 +26,7 @@ _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__)
+#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(__ALTIVEC__)
 #  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..5954798e75896
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// This test ensures that we enable the vectorization of algorithms on the expected
+// platforms.
+
+#include <algorithm>
+
+#if !_LIBCPP_VECTORIZE_ALGORITHMS
+#  error Algorithms should be vectorized on this platform
+#endif

>From 20e235086b38faa2f2b6a8c45bbf6e64ae661559 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 20 Mar 2025 13:43:15 -0400
Subject: [PATCH 2/4] Add XFAILs

---
 .../test/libcxx/algorithms/vectorization.compile.pass.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
index 5954798e75896..08f42de52a2d7 100644
--- a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
@@ -9,6 +9,14 @@
 // 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{{.*}}
+
 // This test ensures that we enable the vectorization of algorithms on the expected
 // platforms.
 

>From c34e7a2c02e59ceac3aef8fd14f5a8ba6b6aa1b5 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 20 Mar 2025 13:49:58 -0400
Subject: [PATCH 3/4] Test the test

---
 libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
index 08f42de52a2d7..872c49a35dd76 100644
--- a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
@@ -22,6 +22,10 @@
 
 #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

>From 427dd72d685416a7da0f812e24f017a8407a0caf Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 21 Mar 2025 10:18:50 -0400
Subject: [PATCH 4/4] Add temporary workaround for AppleClang 15 until we drop
 CI for it

---
 libcxx/include/__algorithm/simd_utils.h                      | 4 +++-
 libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/simd_utils.h b/libcxx/include/__algorithm/simd_utils.h
index 196f02985d89d..5508cef292a59 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_COMPILER_CLANG_BASED) && !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
index 872c49a35dd76..733a147b80cc3 100644
--- a/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/vectorization.compile.pass.cpp
@@ -17,6 +17,9 @@
 // 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.
 



More information about the libcxx-commits mailing list