Skip to content

[Downstream Change] Add AEABI unaligned helpers to compiler-rt and make LLVM ARM lower unaligned i32/i64 loads/stores to __aeabi_uread/uwrite{4,8} #727

@simpal01

Description

@simpal01

What is the change
When targeting ARM (in particular architectures or variants that do not allow unaligned memory accesses, e.g., with -mno-unaligned-access or older cores like ARMv6-M) the backend currently handles unaligned loads or stores by expanding them into sequences of byte/half-word loads/stores.

This change proposes to detect unaligned loads/stores of size 4 bytes (i32) or 8 bytes (i64) when alignment is insufficient, and instead emit calls to the AEABI helper functions by llvm:

• __aeabi_uread4, __aeabi_uread8 for unaligned reads

• __aeabi_uwrite4, __aeabi_uwrite8 for unaligned writes

By lowering to these functions, code size can be reduced compared to in-lined byte/half-word sequences providing they are invoked more than once across a program. This also needs to add the implementations for the __aeabi_uread and __aeabi_uwrite helper functions to compiler-rt.

Why this change cannot be done upstream
This was committed upstream after the LLVM 22 branch was created. Mostly upstream will not accept it into the 22 branch, as it is not considered critical enough for backporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions