[PATCH] D109960: [clang] [ARM] Don't set the strict alignment flag for armv7 on Windows

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 17 04:31:26 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: DavidSpickett, simon_tatham.
Herald added subscribers: kristof.beyls, dschuff.
mstorsjo requested review of this revision.
Herald added a project: clang.

Windows on armv7 is as alignment tolerant as Linux.

The alignment considerations in the Windows on ARM ABI are documented
at https://docs.microsoft.com/en-us/cpp/build/overview-of-arm-abi-conventions?view=msvc-160#alignment.

The document doesn't explicitly say in which state the OS configures
the SCTLR.A register (and it's not accessible from user space to
inspect), but in practice, unaligned loads/stores do work and seem
to be as fast as aligned loads and stores. (Unaligned strd also does
seem to work, contrary to Linux, but significantly slower, as they're
handled by the kernel - exactly as the document describes.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109960

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/arm-alignment.c


Index: clang/test/Driver/arm-alignment.c
===================================================================
--- clang/test/Driver/arm-alignment.c
+++ clang/test/Driver/arm-alignment.c
@@ -19,6 +19,9 @@
 // RUN: %clang -target armv7-unknown-nacl-gnueabihf -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-ARM < %t %s
 
+// RUN: %clang -target armv7-windows -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-UNALIGNED-ARM < %t %s
+
 // RUN: %clang -target aarch64-none-gnueabi -munaligned-access -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-AARCH64 < %t %s
 
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -775,7 +775,8 @@
       if (VersionNum < 6 ||
           Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
         Features.push_back("+strict-align");
-    } else if (Triple.isOSLinux() || Triple.isOSNaCl()) {
+    } else if (Triple.isOSLinux() || Triple.isOSNaCl() ||
+               Triple.isOSWindows()) {
       if (VersionNum < 7)
         Features.push_back("+strict-align");
     } else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109960.373192.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210917/cdd5847a/attachment.bin>


More information about the cfe-commits mailing list