[llvm-dev] What is the right lowering for misaligned memory access?

David A. Greene via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 11 10:10:40 PDT 2018


I would say #4: Lower via inefficient code that assumes the alignment
specified by the load or store.  If no alignment is specified, assume
align 1.

As far as UB, it's not just a language issue.  A vector load could be
unaligned even if the original scalar access was aligned.  Whether such
vectorization is legal is target-dependent.  In the worst case, a
backend for a target requiring strict vector alignment would have to
scalarize the load.

The point of all that is that unaligned accesses are not all that
uncommon and it seems wrong to eliminate them or lower them as if they
were aligned.  The target legalizer should convert problematic unaligned
loads to legal code, which is essentially "lower via inefficient code."

                          -David


Jon Chesterfield via llvm-dev <llvm-dev at lists.llvm.org> writes:

> What should a well behaved back end do with a load or store with
> alignment less than the natural alignment of the type?
>
> I believe C++ considers such access to be UB. I'm not sure what the IR
> semantics are.
>
> I think my options are:
> - Delete the operation / use undef
> - Lower as if it is naturally aligned
> - Lower via inefficient code that assumes align 1
>
> Thanks,
>
> Jon
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list