ARM target generates unaligned STRD instruction

Bug #1804004 reported by Michael Johnson on 2018-11-19

This bug report will be marked for expiration in 50 days if no further activity occurs. (find out why)

6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Undecided
Unassigned

Bug Description

Looks like

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82445

has (re)appeared in

GNU Tools ARM Embedded/7 2018-q2-update

I reproduced with -Os -mcpu=cortex-m4

Hi Michael,

I cannot seem to reproduce this issue:

% 7-2018Q2/linux/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc -S -Os -mcpu=cortex-m4 -mno-unaligned-access strd.c -o - | sed -n '/^x:/,/.L3:/p'
x:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr r3, .L2
        ldr r2, .L2+4
        ldr r3, [r3]
        str r2, [r3, #4]
        ldr r2, .L2+8
        str r2, [r3, #8]
        movs r2, #8
        strh r2, [r3, #12] @ movhi
        bx lr
.L3:

Can you please provide more guidance on how to reproduce it?

Best regards,

Thomas

Changed in gcc-arm-embedded:
status: New → Incomplete

Hi Thomas

This is the command line - the code is the same as the original bug report.

"C:\Program Files (x86)\GNU Tools ARM Embedded\7
2018-q2-update\bin\arm-none-eabi-gcc" -c -fmessage-length=0 -I. -DDEBUG
-D__THUMB -MD -MF "C:/Users/mpj/Documents/CrossWorks Projects/strd/strd
THUMB Debug/main.d" -MQ "strd THUMB Debug/main.o" -g -std=gnu99 -Os
-fomit-frame-pointer -ffunction-sections -fdata-sections main.c -o "strd
THUMB Debug/main.o" -mcpu=cortex-m4 -mlittle-endian -mfloat-abi=soft -mthumb

section .text.x
<x>
     4B04        ldr r3, [pc, #16]
     4A05        ldr r2, [pc, #20]
     681B        ldr r3, [r3]
     4905        ldr r1, [pc, #20]
     E9C31201    strd r1, r2, [r3, #4]
     2208        movs r2, #8
     819A        strh r2, [r3, #12]
     4770        bx lr
     BF00        nop
     00000000    .word 0x00000000
     FFFD0000    .word 0xFFFD0000
     00100008    .word 0x00100008

Regards
Michael
> Hi Michael,
>
> I cannot seem to reproduce this issue:
>
> % 7-2018Q2/linux/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc -S -Os -mcpu=cortex-m4 -mno-unaligned-access strd.c -o - | sed -n '/^x:/,/.L3:/p'
> x:
> @ args = 0, pretend = 0, frame = 0
> @ frame_needed = 0, uses_anonymous_args = 0
> @ link register save eliminated.
> ldr r3, .L2
> ldr r2, .L2+4
> ldr r3, [r3]
> str r2, [r3, #4]
> ldr r2, .L2+8
> str r2, [r3, #8]
> movs r2, #8
> strh r2, [r3, #12] @ movhi
> bx lr
> .L3:
>
> Can you please provide more guidance on how to reproduce it?
>
> Best regards,
>
> Thomas
>
> ** Changed in: gcc-arm-embedded
> Status: New => Incomplete
>

Hi Thomas,

Sorry I didn't see/understand the usage of

-mno-unaligned-access

for some reason I didn't think this would affect the optimiser.

Regards
Michael

> Hi Thomas
>
> This is the command line - the code is the same as the original bug
> report.
>
> "C:\Program Files (x86)\GNU Tools ARM Embedded\7
> 2018-q2-update\bin\arm-none-eabi-gcc" -c -fmessage-length=0 -I.
> -DDEBUG -D__THUMB -MD -MF "C:/Users/mpj/Documents/CrossWorks
> Projects/strd/strd THUMB Debug/main.d" -MQ "strd THUMB Debug/main.o"
> -g -std=gnu99 -Os -fomit-frame-pointer -ffunction-sections
> -fdata-sections main.c -o "strd THUMB Debug/main.o" -mcpu=cortex-m4
> -mlittle-endian -mfloat-abi=soft -mthumb
>
> section .text.x
> <x>
>     4B04        ldr r3, [pc, #16]
>     4A05        ldr r2, [pc, #20]
>     681B        ldr r3, [r3]
>     4905        ldr r1, [pc, #20]
>     E9C31201    strd r1, r2, [r3, #4]
>     2208        movs r2, #8
>     819A        strh r2, [r3, #12]
>     4770        bx lr
>     BF00        nop
>     00000000    .word 0x00000000
>     FFFD0000    .word 0xFFFD0000
>     00100008    .word 0x00100008
>
> Regards
> Michael
>> Hi Michael,
>>
>> I cannot seem to reproduce this issue:
>>
>> %
>> 7-2018Q2/linux/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc
>> -S -Os -mcpu=cortex-m4 -mno-unaligned-access strd.c -o - | sed -n
>> '/^x:/,/.L3:/p'
>> x:
>>          @ args = 0, pretend = 0, frame = 0
>>          @ frame_needed = 0, uses_anonymous_args = 0
>>          @ link register save eliminated.
>>          ldr     r3, .L2
>>          ldr     r2, .L2+4
>>          ldr     r3, [r3]
>>          str     r2, [r3, #4]
>>          ldr     r2, .L2+8
>>          str     r2, [r3, #8]
>>          movs    r2, #8
>>          strh    r2, [r3, #12]   @ movhi
>>          bx      lr
>> .L3:
>>
>> Can you please provide more guidance on how to reproduce it?
>>
>> Best regards,
>>
>> Thomas
>>
>> ** Changed in: gcc-arm-embedded
>>         Status: New => Incomplete
>>
>

Hi Thomas,

If it does then I guess that this must always be set for cortex-m devices?

Regards
Michael
> Hi Thomas,
>
> Sorry I didn't see/understand the usage of
>
> -mno-unaligned-access
>
> for some reason I didn't think this would affect the optimiser.
>
> Regards
> Michael
>
>> Hi Thomas
>>
>> This is the command line - the code is the same as the original bug
>> report.
>>
>> "C:\Program Files (x86)\GNU Tools ARM Embedded\7
>> 2018-q2-update\bin\arm-none-eabi-gcc" -c -fmessage-length=0 -I.
>> -DDEBUG -D__THUMB -MD -MF "C:/Users/mpj/Documents/CrossWorks
>> Projects/strd/strd THUMB Debug/main.d" -MQ "strd THUMB Debug/main.o"
>> -g -std=gnu99 -Os -fomit-frame-pointer -ffunction-sections
>> -fdata-sections main.c -o "strd THUMB Debug/main.o" -mcpu=cortex-m4
>> -mlittle-endian -mfloat-abi=soft -mthumb
>>
>> section .text.x
>> <x>
>>     4B04        ldr r3, [pc, #16]
>>     4A05        ldr r2, [pc, #20]
>>     681B        ldr r3, [r3]
>>     4905        ldr r1, [pc, #20]
>>     E9C31201    strd r1, r2, [r3, #4]
>>     2208        movs r2, #8
>>     819A        strh r2, [r3, #12]
>>     4770        bx lr
>>     BF00        nop
>>     00000000    .word 0x00000000
>>     FFFD0000    .word 0xFFFD0000
>>     00100008    .word 0x00100008
>>
>> Regards
>> Michael
>>> Hi Michael,
>>>
>>> I cannot seem to reproduce this issue:
>>>
>>> %
>>> 7-2018Q2/linux/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-gcc
>>> -S -Os -mcpu=cortex-m4 -mno-unaligned-access strd.c -o - | sed -n
>>> '/^x:/,/.L3:/p'
>>> x:
>>>          @ args = 0, pretend = 0, frame = 0
>>>          @ frame_needed = 0, uses_anonymous_args = 0
>>>          @ link register save eliminated.
>>>          ldr     r3, .L2
>>>          ldr     r2, .L2+4
>>>          ldr     r3, [r3]
>>>          str     r2, [r3, #4]
>>>          ldr     r2, .L2+8
>>>          str     r2, [r3, #8]
>>>          movs    r2, #8
>>>          strh    r2, [r3, #12]   @ movhi
>>>          bx      lr
>>> .L3:
>>>
>>> Can you please provide more guidance on how to reproduce it?
>>>
>>> Best regards,
>>>
>>> Thomas
>>>
>>> ** Changed in: gcc-arm-embedded
>>>         Status: New => Incomplete
>>>
>>
>

Hi Michael,

Cortex-M4 does support unaligned access if enabled at startup. GCC thus assumes the most permissive default and expect the user to pass -mno-unaligned-access if unaligned access is not going to be enabled on the target device.

Best regards,

Thomas

Hi Thomas,

Including ldrd/strd?

Regards
Michael
> Hi Michael,
>
> Cortex-M4 does support unaligned access if enabled at startup. GCC thus
> assumes the most permissive default and expect the user to pass -mno-
> unaligned-access if unaligned access is not going to be enabled on the
> target device.
>
> Best regards,
>
> Thomas
>

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers