<div dir="ltr">Hi Ben,<div><br></div><div>I can see that there could be objections to this patch, as LLVM is doing the right thing in the case of default alignment. It's only when the user tries to override the alignment and make it non-strict that a problem could occur.</div>
<div><br></div><div>To me this seems user error and although one way to rectify would be what you've done, another would be to assert. What cases have you seen that caused this to be a problem?</div><div><br></div><div>
Cheers,</div><div><br></div><div>James</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 28 July 2014 10:25, Benjamin Foster <span dir="ltr"><<a href="mailto:benjamin.foster@arm.com" target="_blank">benjamin.foster@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There was a small logic mistake that allowed unaligned accesses to be generated for V6-M targets if they were optionally enabled, although the V6-M ARM says that faults are always generated when unaligned accesses occur.<br>

<br>
<a href="http://reviews.llvm.org/D4693" target="_blank">http://reviews.llvm.org/D4693</a><br>
<br>
Files:<br>
  lib/Target/ARM/ARMSubtarget.cpp<br>
  test/CodeGen/Thumb/cortex-m0-unaligned-access.ll<br>
  test/CodeGen/Thumb/v6m-unaligned-access.ll<br>
<br>
Index: lib/Target/ARM/ARMSubtarget.cpp<br>
===================================================================<br>
--- lib/Target/ARM/ARMSubtarget.cpp<br>
+++ lib/Target/ARM/ARMSubtarget.cpp<br>
@@ -326,19 +326,19 @@<br>
           (hasV7Ops() && (isTargetLinux() || isTargetNaCl() ||<br>
                           isTargetNetBSD())) ||<br>
           (hasV6Ops() && (isTargetMachO() || isTargetNetBSD()));<br>
-      // The one exception is cortex-m0, which despite being v6, does not<br>
-      // support unaligned accesses. Rather than make the above boolean<br>
-      // expression even more obtuse, just override the value here.<br>
-      if (isThumb1Only() && isMClass())<br>
-        AllowsUnalignedMem = false;<br>
       break;<br>
     case StrictAlign:<br>
       AllowsUnalignedMem = false;<br>
       break;<br>
     case NoStrictAlign:<br>
       AllowsUnalignedMem = true;<br>
       break;<br>
   }<br>
+  // The exception is v6m, which does not support unaligned accesses. Rather<br>
+  // than make the above boolean expression even more obtuse, just override the<br>
+  // value here.<br>
+  if (isThumb1Only() && isMClass())<br>
+    AllowsUnalignedMem = false;<br>
<br>
   switch (IT) {<br>
   case DefaultIT:<br>
Index: test/CodeGen/Thumb/cortex-m0-unaligned-access.ll<br>
===================================================================<br>
--- test/CodeGen/Thumb/cortex-m0-unaligned-access.ll<br>
+++ test/CodeGen/Thumb/cortex-m0-unaligned-access.ll<br>
@@ -1,13 +0,0 @@<br>
-; RUN: llc -mtriple=thumbv6m-apple-unknown-macho < %s | FileCheck --check-prefix=V6M %s<br>
-; RUN: llc -mtriple=thumbv7m-apple-unknown-macho < %s | FileCheck --check-prefix=V7M %s<br>
-<br>
-define i32 @split_load(i32* %p) nounwind {<br>
-; V6M-LABEL: split_load<br>
-; V6M: ldrh<br>
-; V6M: ldrh<br>
-; V7M-LABEL: split_load<br>
-; V7M-NOT: ldrh<br>
-; V7M: bx lr<br>
-  %val = load i32* %p, align 2<br>
-  ret i32 %val<br>
-}<br>
Index: test/CodeGen/Thumb/v6m-unaligned-access.ll<br>
===================================================================<br>
--- test/CodeGen/Thumb/v6m-unaligned-access.ll<br>
+++ test/CodeGen/Thumb/v6m-unaligned-access.ll<br>
@@ -0,0 +1,27 @@<br>
+; RUN: llc < %s -O3 -verify-machineinstrs -mtriple=thumbv6m-none-linux-gnueabi -mcpu=cortex-m0 -arm-strict-align | FileCheck %s --check-prefix=V6M<br>
+; RUN: llc < %s -O3 -verify-machineinstrs -mtriple=thumbv6m-none-linux-gnueabi -mcpu=cortex-m0 -arm-no-strict-align | FileCheck %s --check-prefix=V6M<br>
+; RUN: llc < %s -O3 -verify-machineinstrs -mtriple=thumbv7m-none-linux-gnueabi -mcpu=cortex-m3 -arm-strict-align | FileCheck %s --check-prefix=V7M-ALIGNED<br>
+; RUN: llc < %s -O3 -verify-machineinstrs -mtriple=thumbv7m-none-linux-gnueabi -mcpu=cortex-m3 -arm-no-strict-align | FileCheck %s --check-prefix=V7M<br>
+; RUN: llc -O0 -mtriple=thumbv6m-apple-unknown-macho < %s | FileCheck --check-prefix=V6M %s<br>
+; RUN: llc -O0 -mtriple=thumbv7m-apple-unknown-macho < %s | FileCheck --check-prefix=V7M %s<br>
+<br>
+; This test verifies that unaligned accesses are not generated for v6m targets<br>
+<br>
+define i32 @func0(i32* %p) #0 {<br>
+entry:<br>
+  ; V7M-ALIGNED-LABEL: entry<br>
+  ; V7M-ALIGNED: ldrh<br>
+  ; V7M-ALIGNED: ldrh<br>
+<br>
+  ; V6M-LABEL: entry<br>
+  ; V6M: ldrh<br>
+  ; V6M: ldrh<br>
+<br>
+  ; V7M-LABEL: entry<br>
+  ; V7M-NOT: ldrh<br>
+  ; V7M: bx lr<br>
+<br>
+  %0 = load i32* %p, align 2<br>
+<br>
+  ret i32 %0<br>
+}<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>