From 6c93f6953f4932f814939d89b4e0fb86b5eefb04 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 22 Jan 2024 11:00:52 -0800 Subject: [PATCH] Really disable auto-vectorization. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous patch was insufficient. Craig Topper explains: -fno-vectorize only disables the loop vectorizer -fno-slp-vectorize only disables the SLP vectorizer The backend can also use vector instructions for memcpy/memset or combining multiple scalar loads and/or stores. That is independent of -fno-vectorize. -mllvm -vector-bits-min=0 will disable any use of fixed vectors. And will make attribute(vector_size) get scalarized. -mno-implicit-float will disable both vectorizers and prevent the backend for using vectors for memcpy/memset oor multiple scalar loads/stores. It will not affect attribute(vector_size). -mno-implicit-float also prevents scalar floating point instructions from being used for anything that didn’t use float/double/_Float16/etc. type in source, but I don’t think that happens on RISC-V today. 32-bit X86 can use a 64-bit x87 FP load as an atomic load for uint64_t, for example. Basically -mno-implicit-float is supposed to prevent the compiler from using FP or vectors when the source doesn’t explicitly use FP or vectors. So -mno-implicit-float was what we were actually looking for here. I've done a clean build with this change, and see only the expected (hand-written assembler) vector code in bionic, and the ART ClassLinker::LoadClass() issue is gone too. As far as I can tell, the remaining vector code is all deliberate in that sense. We may still end up back here again, to change "gcv" to "gc", but that still requires some code changes just to build, and still makes it less obvious that this is just a temporary workaround for a qemu bug (specifically https://gitlab.com/qemu-project/qemu/-/issues/1976). Bug: http://b/320416684 Test: objdump Change-Id: Ibd104e4289d6d1aaf441efa0440fedc90e3da29a --- cc/config/riscv64_device.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cc/config/riscv64_device.go b/cc/config/riscv64_device.go index f76e8c93f..deb922bd2 100644 --- a/cc/config/riscv64_device.go +++ b/cc/config/riscv64_device.go @@ -30,7 +30,7 @@ var ( "-Xclang -target-feature -Xclang +unaligned-scalar-mem", "-Xclang -target-feature -Xclang +unaligned-vector-mem", // Until https://gitlab.com/qemu-project/qemu/-/issues/1976 is fixed... - "-fno-vectorize", + "-mno-implicit-float", // (https://github.com/google/android-riscv64/issues/124) "-mllvm -jump-is-expensive=false", } @@ -43,8 +43,6 @@ var ( // Equivalent to "-munaligned-access", but our clang doesn't have that yet. "-Xclang -target-feature -Xclang +unaligned-scalar-mem", "-Xclang -target-feature -Xclang +unaligned-vector-mem", - // Until https://gitlab.com/qemu-project/qemu/-/issues/1976 is fixed... - "-Wl,-mllvm,-vectorize-loops=false", // We should change the default for this in clang, but for now... // (https://github.com/google/android-riscv64/issues/124) "-Wl,-mllvm -Wl,-jump-is-expensive=false",