[libc-commits] [libc] [libc] Keep the SLP vectorizer out of the Cortex-M memcpy and memmove (PR #233428)

Prabhu Rajasekaran via libc-commits libc-commits at lists.llvm.org
Mon Oct 19 09:50:03 PDT 2026


https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/233428

>From aba1aca0adbf73238c4caf6f2a33afa31deefdab Mon Sep 17 00:00:00 2001
From: Prabhu Rajasekaran <prabhukr at google.com>
Date: Mon, 19 Oct 2026 06:09:07 -0700
Subject: [PATCH] [libc] Keep the SLP vectorizer out of the Cortex-M memcpy and
 memmove

Since fa10e634e2be ([SLP] Support runtime alias checks versioning for
blocks in loops, #226955) the Cortex-M55 target memcpy size increased
by about 50%. Since this patch, `memcpy` now also executes MVE
instructions, which fault with a NOCP UsageFault when it is called
before CP10/CP11 are enabled in CPACR. `memmove.cpp` is affected in the
same way: it is built with `-O3` too and inlines `inline_memcpy` for
disjoint buffers, so it carries its own COMDAT copy of
`inline_memcpy_arm_mid_end` (256 -> 398 bytes) and the linker keeps
whichever copy it sees first.

Build the ARM `memcpy` and `memmove` with `-fno-tree-slp-vectorize`.

Fixes #233426

Assisted-by: Gemini
---
 libc/src/string/CMakeLists.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index 0967ae5f83451..853cf78dcdf56 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -499,6 +499,12 @@ elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
     MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
   add_memcpy(memcpy MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_ARM)
+  # Vectorizing the word by word copy only increases code size, disable it.
+  set(LIBC_ARM_MEMCPY_COMPILE_OPTIONS -fno-tree-slp-vectorize)
+  add_memcpy(memcpy_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
+    ${LIBC_ARM_MEMCPY_COMPILE_OPTIONS})
+  add_memcpy(memcpy COMPILE_OPTIONS ${LIBC_ARM_MEMCPY_COMPILE_OPTIONS})
 elseif(LIBC_TARGET_OS_IS_GPU)
   add_memcpy(memcpy)
 else()
@@ -533,6 +539,11 @@ elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
   add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
     MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
   add_memmove(memmove MLLVM_COMPILE_OPTIONS "-tail-merge-threshold=0")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_ARM)
+  # memmove inlines memcpy for disjoint buffers, see memcpy above.
+  add_memmove(memmove_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}
+    ${LIBC_ARM_MEMCPY_COMPILE_OPTIONS})
+  add_memmove(memmove COMPILE_OPTIONS ${LIBC_ARM_MEMCPY_COMPILE_OPTIONS})
 elseif(LIBC_TARGET_OS_IS_GPU)
   add_memmove(memmove)
 else()



More information about the libc-commits mailing list