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

Joerg Sonnenberger via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 11 12:27:07 PDT 2018


On Wed, Jul 11, 2018 at 05:52:24PM +0100, Jon Chesterfield via llvm-dev wrote:
> 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

Unless the operation explicitly specifies something else (i.e. via
memcpy), the second option is correct. Don't go out of your way to break
unaligned access, esp. if the target CPU can deal with it. But don't go
out of your way to make it work either.

Joerg


More information about the llvm-dev mailing list