diff mbox

[ARM] Vectorizer generates unaligned access when -mno-unaligned-access is enabled

Message ID 52EF2C1D.7050207@linaro.org
State Accepted
Headers show

Commit Message

Kugan Vivekanandarajah Feb. 3, 2014, 5:41 a.m. UTC
With the 2013-09-21 version of trunk, attached test case results in bus
error when simultaneously enabling both -mno-unaligned-access and
-ftree-vectorize.
The error is caused by unaligned vector load via two vldr instructions:

 vldr d16, [r3, #-16]
 vldr d17, [r3, #-8]

Cause for this error is, even when -mno-unaligned-access is enabled,
backend will inform vectorizer that it supports misaligned accesses
via TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT.

Attached patch fixes this. Is this OK for trunk?

Thanks,
Kugan

+2014-02-03  Yury Gribov  <tetra2005@gmail.com>
+	     Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+	* config/arm/arm.c (arm_vector_alignment_reachable): Check
+	unaligned_access.
+	* config/arm/arm.c (arm_builtin_support_vector_misalignment): Likewise.
+



+2014-02-03  Yury Gribov  <tetra2005@gmail.com>
+	     Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+	* gcc.target/arm/vect-noalign.c: New file.
+

Comments

Kugan Vivekanandarajah Feb. 6, 2014, 9:20 a.m. UTC | #1
On 06/02/14 01:56, Ramana Radhakrishnan wrote:
> 
> 
>>
>> Ramana wrote:
>>>> Attached patch fixes this. Is this OK for trunk?
>>>
>>> How has it been tested ?
>>
>> I was hoping Linaro people could run their magical cbuild on it...
> 
> Ok if no regressions.
> 

Tested it on qemu for arm-none-linux-gnueabi and there is no new
regressions. I am sorry I didn’t mention it when I posted the patch.


Thanks,
Kugan
Christophe Lyon Feb. 6, 2014, 4:54 p.m. UTC | #2
On 6 February 2014 10:49, Yury Gribov <y.gribov@samsung.com> wrote:
> Kugan wrote:
>>> Ok if no regressions.
>>
>> Tested it on qemu for arm-none-linux-gnueabi and there is no new
>> regressions. I am sorry I didn't mention it when I posted the patch.
>
> Commited in r207533. Thanks!
>

Hi,

As can be seen here:
http://cbuild.validation.linaro.org/build/cross-validation/gcc/207533/report-build-info.html
this has caused some regressions on armv5t targets.

Additionally, are you sure testing this kind of thing on QEMU
sufficient? Does it really handle unaligned accesses as bus errors?

Christophe.
Kugan Vivekanandarajah Feb. 7, 2014, 1:33 a.m. UTC | #3
On 07/02/14 03:54, Christophe Lyon wrote:
> On 6 February 2014 10:49, Yury Gribov <y.gribov@samsung.com> wrote:
>> Kugan wrote:
>>>> Ok if no regressions.
>>>
>>> Tested it on qemu for arm-none-linux-gnueabi and there is no new
>>> regressions. I am sorry I didn't mention it when I posted the patch.
>>
>> Commited in r207533. Thanks!
>>
> 
> Hi,
> 
> As can be seen here:
> http://cbuild.validation.linaro.org/build/cross-validation/gcc/207533/report-build-info.html
> this has caused some regressions on armv5t targets.

Thanks for spotting this. armv5t disables unaligned access by default. I
am looking into it.

> 
> Additionally, are you sure testing this kind of thing on QEMU
> sufficient? Does it really handle unaligned accesses as bus errors?
> 

I did test this patch on a Chromebook where I reproduced the bus error
with an older version of trunk and verified it was fixed. I then tested
the patch for armv7-a with the latest trunk on qemu. I am not sure if
qemu models the bus errors.


Thanks,
Kugan

> Christophe.
>
diff mbox

Patch

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 39d23cc..d7e74de 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -29521,7 +29521,7 @@  arm_vector_alignment_reachable (const_tree type, bool is_packed)
 {
   /* Vectors which aren't in packed structures will not be less aligned than
      the natural alignment of their element type, so this is safe.  */
-  if (TARGET_NEON && !BYTES_BIG_ENDIAN)
+  if (TARGET_NEON && !BYTES_BIG_ENDIAN && unaligned_access)
     return !is_packed;
 
   return default_builtin_vector_alignment_reachable (type, is_packed);
@@ -29532,7 +29532,7 @@  arm_builtin_support_vector_misalignment (enum machine_mode mode,
 					 const_tree type, int misalignment,
 					 bool is_packed)
 {
-  if (TARGET_NEON && !BYTES_BIG_ENDIAN)
+  if (TARGET_NEON && !BYTES_BIG_ENDIAN && unaligned_access)
     {
       HOST_WIDE_INT align = TYPE_ALIGN_UNIT (type);
 
diff --git a/gcc/testsuite/gcc.target/arm/vect-noalign.c b/gcc/testsuite/gcc.target/arm/vect-noalign.c
index e69de29..a934233 100644
--- a/gcc/testsuite/gcc.target/arm/vect-noalign.c
+++ b/gcc/testsuite/gcc.target/arm/vect-noalign.c
@@ -0,0 +1,20 @@ 
+/* { dg-do run } */
+/* { dg-require-effective-target arm_neon_hw } */
+/* { dg-options "-mfpu=neon -ffast-math -ftree-vectorize -fno-common -O2 -mno-unaligned-access" } */
+
+
+/* Test for-mno-unaligned-access and -ftree-vectorize  and results bus error. */
+#define N 128
+
+char ia[N];
+char ib[N+1];
+
+int main() {
+  int i;
+  for(i = 0; i < N; ++i) {
+    ia[i] = ib[i + 1];
+  }
+
+  return 0;
+}
+